function _hide(el) {

	if ( $(el).css("display") == 'block')
		$(el).hide(0);

}






function showhide(el, speed) {


var off_array = new Array("whoyouare", "big-catalogue", "basket_content");


for (var i=0; i<off_array.length; i++) {

  if ("#"+off_array[i] != el) 
  	_hide("#"+off_array[i]);
  	
  
  //alert(off_array[i]);
  
  //alert(off_array[i]);
}



//alert(off_array);


if ( $(el).css("display") == 'none')
    $(el).show(speed);
else
    $(el).hide(speed);
}







function brightstar(el, id) {
	var parentTag = $(el).parent().get(0).className;
	$(el).attr("src", "/img/onestarbright.gif");
	for ($t = 0; $t < id; $t++ )
		$('div.'+parentTag+' #star'+$t).attr("src", "/img/onestarbright.gif");
}



function lowstar(el, id) {
	$(el).attr("src", "/img/onestar.gif");
}



function setimgsrc(el, pathtoimage) {
	$(el).attr("src", ""+pathtoimage+"");
}

function set_a_href(el, href) {
	$(el).attr("href", ""+href+"");
}

function set_el_html(el, ihtml) {
	$(el).html(ihtml);
}


function redraw_cal(lang, year, month) {


var params = {};


$("input[@type=checkbox][@checked]").each(
	function() {
	//alert( this.name || this.id || this.parentNode.name || this.parentNode.id);
		params[ this.name || this.id || this.parentNode.name || this.parentNode.id ] = this.value;
		//alert(this.value);
	}
);


$.get("/inc/handlers/calendar.php" + "?call=ajax&y="+year+"&m="+month, params, function(ret) {

	if (ret) $("#calendarout").html(ret);
	
	
	$curyear = $("#curyear", ret.responseText).html();
	$curmonth = $("#curmonth", ret.responseText).html();
	

});





}








function savephotodesc(id, lang_id) {

curText = $("#photodesc_"+id).val();

$.ajax ({
   type: "GET",
   url: "/inc/handlers/savephotodesc.php",
   data: "id="+id+"&text="+curText+"&lang_id="+lang_id,
   success: function(ret) {
  
   //if (ret) alert(ret);

   }
 });

}


function savephotosort(id, lang_id) {

curSort = $("#photosort_"+id).val(); //alert(curSort);

$.ajax ({
   type: "GET",
   url: "/inc/handlers/savephotosort.php",
   data: "id="+id+"&sort="+curSort+"&lang_id="+lang_id,
   success: function(ret) {
  
   if (ret) //alert(ret);
		location.reload(true);
   }
 });

}




function addtagstomaterial(id, tagid, lang_id) {

//alert(tagid.options[tagid.selectedIndex].value);

tag_id = tagid.options[tagid.selectedIndex].value;

$.ajax ({
   type: "GET",
   url: "/inc/handlers/addtagstomaterial.php",
   data: "id="+id+"&tag_id="+tag_id+"&lang_id="+lang_id,
   success: function(ret) {
  
   if (ret) {
   		//alert(ret);
	   $("#returnedtags").html(ret);
   }

   }
 });

}

function show_catalogue_first(id, lang_id) {
$.ajax ({
   type: "GET",
   url: "/inc/handlers/show_catalogue_first.php",
   data: "lang_id="+lang_id,
   success: function(ret) {
  
   if (ret) {
   	//alert(ret);
	   $("#"+id).html(ret);
   }

   }
 });

}

function show_catalogue_second(cat_id, id, lang_id) {
$.ajax ({
   type: "GET",
   url: "/inc/handlers/show_catalogue_second.php",
   data: "cat_id="+cat_id+"&lang_id="+lang_id,
   success: function(ret) {
  
   if (ret) {
   	//alert(ret);
	   $("#"+id).html(ret);
   }

   }
 });

}

function show_catalogue_three(cat_id, id, lang_id) {
$.ajax ({
   type: "GET",
   url: "/inc/handlers/show_catalogue_three.php",
   data: "cat_id="+cat_id+"&lang_id="+lang_id,
   success: function(ret) {
  
   if (ret) {
   	//alert(ret);
	   $("#"+id).html(ret);
   }

   }
 });

}

function show_catalogue_four(cat_id, id, lang_id) {
$.ajax ({
   type: "GET",
   url: "/inc/handlers/show_catalogue_four.php",
   data: "cat_id="+cat_id+"&lang_id="+lang_id,
   success: function(ret) {
  
   if (ret) {
   	//alert(ret);
	   $("#"+id).html(ret);
   }

   }
 });

}



function addtagstomaterialfrominput(id, tag_input_id, lang_id) {

$("#okkkkkkkkkey").show();
tag_value = $("#"+tag_input_id).val();


$.ajax ({
   type: "GET",
   url: "/inc/handlers/addtagstomaterialfrominput.php",
   data: "id="+id+"&tag_value="+escape(tag_value)+"&lang_id="+lang_id,
   success: function(ret) {
  
   if (ret) {
   		//alert(ret);
	   $("#returnedtags").html(ret);
	   
	   $("#"+tag_input_id).attr("value", "");
	
		$("#okkkkkkkkkey").html('Сохранено!');
        $("#okkkkkkkkkey").fadeOut(1500);
		
   }

   }
 });

}





function remtagofmaterial(id, tagid, lang_id) {
tag_id = tagid;
$.ajax ({
   type: "GET",
   url: "/inc/handlers/remtagofmaterial.php",
   data: "id="+id+"&tag_id="+tag_id+"&lang_id="+lang_id,
   success: function(ret) {
   if (ret) {
	   $("#returnedtags").html(ret);
   }
   }
 });
}








function loginme(outid, hideid, lang_id) {

cur_cd = $("#login_cd").val();
cur_pen = $("#login_pen").val();

//alert(cur_cd);alert(cur_pen); 

//alert(77);
$.ajax ({
   type: "POST",
   url: "/inc/handlers/loginme.php",
   data: "cd="+cur_cd+"&pen="+cur_pen+"&lang_id="+lang_id,
	   success: function(xml) {
	  //alert(99);

	output = "";
	strError = "";
	strOk = "";

	$(xml).find("out").each(function()
	{ 
	//alert(5);
	//$(id).append($(this).attr("error") + "<br />");

if ($(this).find("error").html())
	strError = $(this).find("error").html();
	
if ($(this).find("ok").html())
	strOk = $(this).find("ok").html();

if ($(this).find("user").html())
	username = $(this).find("user").html();
	
	output += strError;
	output += strOk;
	
	$(outid).html(output);


	if (strOk) {
		$(hideid).fadeOut(200);
		$('#magazine_guest_or_member').html(username);
	}
	


	});

	   
	   }
 });
}





function addtocart(outid, lang_id, prodid, mode) {

$.ajax ({
   type: "GET",
   url: "/inc/handlers/cart.php",
   data: "prodid="+prodid+"&mode="+mode+"&lang_id="+lang_id,
   success: function(ret) {
    
    	var oAuto = eval("(" + ret + ")");
    	  
		var carttotalsumm = "";
		var carttotalsumm = oAuto.carttotalsumm;
		var carttotalquantity = oAuto.carttotalquantity;
		var basketcontent = oAuto.basketcontent;
		var goodadded = oAuto.goodadded;
		
		$('#main_cart_summ').html(carttotalsumm);
		$('#main_cart_count').html(carttotalquantity);
		$('#basket_content_adjust').html(basketcontent);
		$('#goodadded').fadeIn(200);
	
		$("#goodadded").fadeOut(1200);
  	
 }
 });


}









function make_assortment_ready(lang_id, prodid) {

$("#prod_main_image").fadeOut(100);

$.ajax ({
   type: "GET",
   url: "/inc/handlers/make_assortment_ready.php",
   //data: "prodid="+prodid+"&lang_id="+lang_id,
   
   data: { "prodid":  prodid, "lang_id": lang_id, t: (new Date).getTime()},
   
   success: function(ret) {
   
  	var oAuto = eval("(" + ret + ")");
  	  	
  	var update_prod_main_image = oAuto.update_prod_main_image;
  	var update_prod_main_addtocart_href = oAuto.update_prod_main_addtocart_href;
  	var update_prod_main_articul = oAuto.update_prod_main_articul;
	
 
$("#prod_main_image").fadeIn(200).html(update_prod_main_image);

  	
 }
 });


}







