// JavaScript Document
//универсальная функция ajax
function doajax(u,object,pos){
	$('#preloader').css("display","");
	
	if(pos){
		var offset = $("#"+pos).offset();	
		var left   = offset.left;
		var top    = offset.top;		
		$("#preloader").css("position","absolute");
		$("#preloader").css("zIndex","9999");
		$("#preloader").css("top",top-25);
		$("#preloader").css("left",left);
	}
	
	$.ajax({
		   type: "GET",
		   url: u,
		   cache: false,
		   success: function (html){		
		   	   if(object=="price" && html != ""){
				   $("#"+object).hide("normal",
									  function(){
										 if(object=="price"){	
										 	$("#"+object).html(html);
				    						$("#"+object).show("normal");
			   							 }  
									  });
			   }else{
			   	    $("#"+object).html(html);
			   }
			  			  
			  $("#preloader").css("display","none");
		   }
	});
}


function show_sub_cat(m_id){
   /* document.getElementById("down_cat").innerHTML = "";
	document.getElementById("down_cat_2").innerHTML = "";
	document.getElementById("down_cat_3").innerHTML = "";
	var A = new AJAX();
	A.Send("sub_cat.php?m_id="+m_id+"&tmp="+Math.random(),document.getElementById("sub_cat"));*/	
	
	$("#down_cat").html("");
	$("#down_cat_2").html("");
	$("#down_cat_3").html("");
	doajax("./sub_cat.php?m_id="+m_id, "sub_cat","m_id");
	
}
function show_down_cat(s_id){
	/*document.getElementById("down_cat_2").innerHTML = "";
	document.getElementById("down_cat_3").innerHTML = "";
	var A = new AJAX();
	A.Send("down_cat.php?s_id="+s_id+"&tmp="+Math.random(),document.getElementById("down_cat"));*/
	$("#down_cat_2").html("");
	$("#down_cat_3").html("");
	doajax("./down_cat.php?s_id="+s_id, "down_cat","sub_cat");	
}

function show_down_cat_2(d_id){
	/*document.getElementById("down_cat_3").innerHTML = "";
	var A = new AJAX();
	A.Send("down_cat_2.php?d_id="+d_id+"&tmp="+Math.random(),document.getElementById("down_cat_2"));*/
	$("#down_cat_3").html("");
	doajax("./down_cat_2.php?d_id="+d_id, "down_cat_2","down_cat");
}

function show_down_cat_3(d_id_2){
	/*var A = new AJAX();
	A.Send("down_cat_3.php?d_id_2="+d_id_2+"&tmp="+Math.random(),document.getElementById("down_cat_3"));*/
	doajax("./down_cat_3.php?d_id_2="+d_id_2, "down_cat_3","down_cat_2");
}



function show_price(m_id){
	/*var A = new AJAX();
	A.Send("_price.php?m_id="+m_id+"&tmp="+Math.random(),document.getElementById("price"));*/
	doajax("_price.php?m_id="+m_id,"price");
}
function show_price_s_id(m_id,s_id){
	var A = new AJAX();
	//A.Send("_price.php?m_id="+m_id+"&s_id="+s_id+"&tmp="+Math.random(),document.getElementById("price"));
	doajax("_price.php?m_id="+m_id+"&s_id="+s_id,"price");
}
function show_price_d_id(m_id,s_id,d_id){
	/*var A = new AJAX();
	A.Send("_price.php?m_id="+m_id+"&s_id="+s_id+"&d_id="+d_id+"&tmp="+Math.random(),document.getElementById("price"));*/
	doajax("_price.php?m_id="+m_id+"&s_id="+s_id+"&d_id="+d_id,"price");
}

function show_price_d_id_2(m_id,s_id,d_id,d_id_2){
	/*var A = new AJAX();
	A.Send("_price.php?m_id="+m_id+"&s_id="+s_id+"&d_id="+d_id+"&d_id_2="+d_id_2+"&tmp="+Math.random(),document.getElementById("price"));*/
	doajax("_price.php?m_id="+m_id+"&s_id="+s_id+"&d_id="+d_id+"&d_id_2="+d_id_2,"price");
}

function show_price_d_id_3(m_id,s_id,d_id,d_id_2,d_id_3){
	/*var A = new AJAX();
	A.Send("_price.php?m_id="+m_id+"&s_id="+s_id+"&d_id="+d_id+"&d_id_2="+d_id_2+"&d_id_3="+d_id_3+"&tmp="+Math.random(),document.getElementById("price"));*/
	doajax("_price.php?m_id="+m_id+"&s_id="+s_id+"&d_id="+d_id+"&d_id_2="+d_id_2+"&d_id_3="+d_id_3,"price");
}

function price_search(){
	var s_text = document.getElementById("s_text").value;
	if(s_text.length != 0){
		/*var A = new AJAX();
		A.Send("_price.php?s_t="+ s_text +"&tmp="+Math.random(),document.getElementById("price"));*/
		doajax("_price.php?s_t="+ $("#s_text").attr("value"),"price");
	}
}

function onPressEnter(){
	with(event){
		if(keyCode == 13){
			price_search();
		}
	}
}

function sendmessage(){
	var mail  = document.getElementById("mail");
    var theme = document.getElementById("theme");
	var from  = document.getElementById("from");
	var com   = document.getElementById("com");
	var msg   = document.getElementById("msg");
	
	var e = 0;
	
	if(msg.value.length<10){
		msg.style.border = '1px solid #DB0202';
		e = 1;
	}else{
		msg.style.border = '1px solid #000000';
	}
	if(from.value.length == 0){
		from.style.border = '1px solid #DB0202';
		e = 1;
	}else{
		from.style.border = '1px solid #000000';
	}
	
	if(!mail.value.match("[a-zA-Z\-_0-9]+@[a-zA-Z\-_0-9\.]+\.([a-zA-Z]{2,})$")){
		mail.style.border = '1px solid #DB0202';
		e = 1;
	}else{
		mail.style.border = '1px solid #000000';
	}
	
	if(!e){
		document.getElementById("sending").style.display = "";
		document.getElementById("sbtn").disabled = true;
		document.forms['msg_form'].submit();
		theme.value = '';
		msg.value   = '';
		from.value  = '';
		mail.value  = '';
		com.value   = ''; 
	}
}

function select_td(o,c){
	if(c){
		document.getElementById(o).style.borderColor = "#333333";
	}else{
		document.getElementById(o).style.borderColor = "#999999";
	}
}
