function toBasket(id, type){
		
		$.get("/ajax.htm", {basket:id, type:type}, function(){
			window.location='/basket.htm';
		});
		return false;
}


function delGood(id, o, type){
	
	if (!confirm('Удалить товар из корзины?')) return false;
	$.get("/ajax.htm", {remove:id, type:type}, function(data){
			if (data=='empty') window.location.reload();
			tr=o.parentNode.parentNode;
			$(tr).fadeOut();
	});
	
}

function comparePass(o, n2){ // typal form function: compare inputed passwords
	if (o.value=="") return;
	$("input").each(function(){
		
		if (this.name==n2) f=this;
		
	});
	
	if (o.value!=f.value) stop_send=function(){setError(f, 'various', '');return true;}
	

}

function setError(o, mode, title){ // typal form function: output error
	
	ers=[];
	ers['empty']='Не заполнено поле: ';
	ers['incorrect']='Некорректное значение: ';
	ers['various']='Введенные пароли не совпадают';
	ers['wrongold']='Неверно введен старый пароль';
	ers['']='';
	
	$(o).css("border",'solid 1px red');
	$('#error').html(ers[mode]+title);
	$('#error').slideDown();
	return false;
}
 
function setDefault(o){ // typal form function: set default style for the field
	
	$(o).css('border', 'inset 1px #a2adb6');
	$('#error').css('display', 'none');
 
}


function checkPasses(o){
	
	id=o.id.replace("2","");
	if (o.value!=$("#"+id)[0].value) {
		stop_send=true;
		setError(o, "various", "");
	}
	
}


function isChecked(o){
	if (typeof(o.length)=='undefined'){
		if (o.checked) return o.value;
		else return false;
	}
	for(i=0;i<o.length;i++){
		if (o[i].checked) return o[i].value;
	}
	return false;
	
}

function capa(o){
	
	nt=document.createElement('span');
	nt.innerHTML='<input type="hidden" name="cap_check" value="cap_check_ok"/>';
	
	
	o.parentNode.appendChild(nt);

}


function validation(){
	e=0;
	$(".required").each(function(){
	setDefault(this);
		if ($(this).attr('type')=='checkbox' && !this.checked) {setError(this, 'empty', $(this).attr('title'));e=1}
		else if (this.value=="") {setError(this, 'empty', $(this).attr('title'));e=1}
		if (this.name.match(/email/) && !this.value.match(/@/)) {setError(this, 'incorrect', $(this).attr('title'));e=1}
		
		if ($(this).attr('type5')=='number') {
			if (this.value.match(/^[0-9]+$/)==null)  {setError(this, 'incorrect', $(this).attr('title'));e=1}
		}
		
	});
	if (e==1) return false;
	
	return true;
}


function typer(o){
	
	max=$(o).attr('ml');
	if (o.value.length<=max) $("#typer").text('Осталось '+(max-o.value.length)+' символов');
	else o.value=o.value.substr(0, max);
	
}

