function checkbox_check_all(check_class){
	$("."+check_class+"[type='checkbox']").attr('checked', true); 
}

function checkbox_uncheck_all(check_class){
	$("."+check_class+"[type='checkbox']").attr('checked', false); 
}	

function hide_register_forgot(){
	$('#users_signup_register_forgot').slideUp();
}

function users_show_signup_screen(){
	if ($('#users_signup_register_forgot').is(':visible')){
		$('#users_signup_register_forgot').slideDown();
		$('#users_signup_screen').slideDown();
		$('#users_forgot_password_screen').slideUp();
	} else {
		$('#users_signup_screen').show();
		$('#users_forgot_password_screen').hide();							
		$('#users_signup_register_forgot').slideDown();
	}
}

function users_show_forgot_password_screen(){
	if ($('#users_signup_register_forgot').is(':visible')){
		$('#users_signup_register_forgot').slideDown();
		$('#users_forgot_password_screen').slideDown();
		$('#users_signup_screen').slideUp();	
	} else {
		$('#users_forgot_password_screen').show();
		$('#users_signup_screen').hide();	
		$('#users_signup_register_forgot').slideDown();
	}					
}





//otslezhivajem nahozhdenije mishki!
//koordinati mishki
var xc1;
var yc1;
var xc2;
var yc2;

//scrollLeft & scrollTop
var xs1 = 0;
var ys1 = 0;


//document width i document height
var dw1 = 0;
var dh1 = 0;
//visible area (window) - width i height
var vw1 = 0;
var vh1 = 0;

$().mousemove(function(e){
	xc1=e.pageX;
	yc1=e.pageY;
	xc2=e.clientX;
	yc2=e.clientY;
	//alert(xc1);
});



function getScrollXY() {


	
	ys1 = $(document).scrollTop();
	xs1 = $(document).scrollLeft();
	
}





function  getPageSize(){
       var xScroll, yScroll;

       if (window.innerHeight && window.scrollMaxY) {
               xScroll = document.body.scrollWidth;
               yScroll = window.innerHeight + window.scrollMaxY;
       } else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
               xScroll = document.body.scrollWidth;
               yScroll = document.body.scrollHeight;
       } else if (document.documentElement && document.documentElement.scrollHeight > document.documentElement.offsetHeight){ // Explorer 6 strict mode
               xScroll = document.documentElement.scrollWidth;
               yScroll = document.documentElement.scrollHeight;
       } else { // Explorer Mac...would also work in Mozilla and Safari
               xScroll = document.body.offsetWidth;
               yScroll = document.body.offsetHeight;
       }

       var windowWidth, windowHeight;
       if (self.innerHeight) { // all except Explorer
               windowWidth = self.innerWidth;
               windowHeight = self.innerHeight;
       } else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
               windowWidth = document.documentElement.clientWidth;
               windowHeight = document.documentElement.clientHeight;
       } else if (document.body) { // other Explorers
               windowWidth = document.body.clientWidth;
               windowHeight = document.body.clientHeight;
       }

       // for small pages with total height less then height of the viewport
       if(yScroll < windowHeight){
               pageHeight = windowHeight;
       } else {
               pageHeight = yScroll;
       }

       // for small pages with total width less then width of the viewport
       if(xScroll < windowWidth){
               pageWidth = windowWidth;
       } else {
               pageWidth = xScroll;
       }

	   
	pageWidth=$(document).width();
	pageHeight=$(document).height();
	windowWidth=$(window).width();
	windowHeight=$(window).height();
	   
	   
	   
	   
	   
	   
	return [pageWidth,pageHeight,windowWidth,windowHeight];
}





	function get_this_style(curobj){
		if(document.getElementById(curobj)){
			fcurobj=document.getElementById(curobj).style;
		}else{
			if(ns6==1||operaaa==true){
				fcurobj=curobj.nextSibling.nextSibling.style;
			}else{
				fcurobj=document.all[curobj.sourceIndex+1].style;
			}
		}
		
		return fcurobj;
	}


	function get_this(curobj){
		if(document.getElementById(curobj)){
			fcurobj=document.getElementById(curobj);
		}else{
			if(ns6==1||operaaa==true){
				fcurobj=curobj.nextSibling.nextSibling;
			}else{
				fcurobj=document.all[curobj.sourceIndex+1];
			}
		}
		
		return fcurobj;
	}




function str_replace(search, replace, subject) {
    return subject.split(search).join(replace);
}



function recheck_definitions(){
	if (getCookie("hidden_defenitions")=="1"){
		show_definitions();
	} else {
		hide_definitions();
	}

}





function hide_definitions() {
	//showing all OFF lamps and hiding ON lamps
	$('.bulb_vista_off').show();
	$('.bulb_vista_on').hide();

	
	//hiding all definitions
	var a = document.getElementsByTagName('dfn');
	for(var i = 0; i < a.length; i++) {
		document.getElementsByTagName("dfn")[i].style.display = "none";
	}
	
	//hiding all Advanced settings and inputs
	$(".forform_adv").css("visibility","collapse");
	$(".forform_adv").css("display","none");
	$(".advanced").css("visibility","collapse");
	$(".advanced").css("display","none");
	$("code").css("visibility","collapse");
	$("code").css("display","none");
	 
	
	setCookie("hidden_defenitions", "0");
}


function show_definitions() {
	//showing all ON lamps and hiding OFF lamps
	$('.bulb_vista_off').hide();
	$('.bulb_vista_on').show();
	
	//showing all definitions
	var a = document.getElementsByTagName('dfn');
	for(var i = 0; i < a.length; i++) {
		document.getElementsByTagName("dfn")[i].style.display = "";  
	}
	
	
	//showing all Advanced settings and inputs
	$(".forform_adv").css("visibility","visible");
	$(".forform_adv").css("display","");
	$(".advanced").css("visibility","visible");
	$(".advanced").css("display","");	
	$("code").css("visibility","visible");
	$("code").css("display","");	
	
	setCookie("hidden_defenitions", "1");
} 




	function center_position(curobj){

		vistafolder=get_this_style(curobj);
		
		var page_size=getPageSize();

		var docw=page_size[2];
		var doch=page_size[3];
		var winw=parseInt('0'+vistafolder.width,10);
		var winh=parseInt('0'+vistafolder.height,10);
		if (winw==0) winw=docw;
		if (winh==0) winh=doch;
		
		
		getScrollXY();
		random_num = (Math.round((Math.random()*9)+1));
		
		
		if (curobj=="vistafade"){
			vistafolder.width=docw+"px";
			vistafolder.height=doch+"px";
			winw=docw;
			winh=doch;
			vistafolder.left=xs1+"px";
			vistafolder.top=ys1+"px";
			//document.title="Doc W: "+docw+"; Doc H: "+doch+"; Win W: "+winw+"; Win H: "+winh+"; D Left: "+xs1+"; D Top: "+ys1+"   Rand: "+random_num;
		} else {
			vistafolder.left=((docw-winw)/2-(-xs1))+"px";
			vistafolder.top=((doch-winh)/2-(-ys1))+"px";		
		}
		
		//timerID  = setTimeout("center_position('"+curobj+"');", 1000);
		

	}


	

	function cursor_position(curobj){

		vistafolder=get_this_style(curobj);
		
		var page_size=getPageSize();

		var docw=page_size[2];
		var doch=page_size[3];		
		var winw=parseInt('0'+vistafolder.width,10);
		var winh=parseInt('0'+vistafolder.height,10);
		

		
		vistafolder.left=xc1+"px";
		vistafolder.top=yc1+"px";

	}


	function adjust_size(curobj,default_window_width,default_window_height,default_window_margin){

		vistafolder=get_this_style(curobj);
		
		
		var page_size=getPageSize();

		
		var docw=page_size[2]-(default_window_margin*2);
		var doch=page_size[3]-(default_window_margin*2);
		var winw=parseInt('0'+vistafolder.width,10);
		var winh=parseInt('0'+vistafolder.height,10);
		
		if (docw<winw){
			vistafolder.width=docw+'px';
		} else {
			if (docw<default_window_width){
				vistafolder.width=docw+'px';
			} else {
				vistafolder.width=default_window_width+'px';
			}
		}
		
		if (doch<winh){
			vistafolder.height=doch+'px';
		} else {
			if (doch<default_window_height){
				vistafolder.height=doch+'px';
			} else {
				vistafolder.height=default_window_height+'px';
			}
		}


	}
	
	
	
	
	
	


	function only_int(evt) {
	    evt = (evt) ? evt : event;
	    var charCode = (evt.charCode) ? evt.charCode : ((evt.keyCode) ? evt.keyCode : ((evt.which) ? evt.which : 0));
		

		if ((charCode > 31 && (charCode < 48 || charCode > 57)) && (charCode!=46) && (charCode!=44)
		&& (charCode!=99)
		&& (charCode!=118)
		&& (charCode!=67)
		&& (charCode!=86)
		&& (charCode!=1089)
		&& (charCode!=1084)
		&& (charCode!=1052)
		&& (charCode!=1057)
		) return false;
	    return true;
	}

	
	
	
	

	
	
	
	function openit(curobj,curobjbut1,curobjbut2){
		

		
		if ((curobj!= undefined) && (curobj!='')){
		


	
			fcurobj=get_this_style(curobj);
			//$("#"+curobj).slideDown("fast");
			$('#'+curobj).show();
			//fcurobj.display="";
			setCookie(curobj, "1");
			
			
			if ((curobjbut1!= undefined) && (curobjbut1!='')){
				openit(curobjbut1);
			}

			if ((curobjbut2!= undefined) && (curobjbut2!='')){
				openit(curobjbut2);
			}
		

		}
		
		
		
	}

	
	
	function closeit(curobj,curobjbut1,curobjbut2){
		

		
		if ((curobj!= undefined) && (curobj!='')){
		


			
			fcurobj=get_this_style(curobj);

				//fcurobj.display="none";
				//$("#"+curobj).slideUp("fast");
				$("#"+curobj).hide();
				
				setCookie(curobj, "0");

			
			
			if ((curobjbut1!= undefined) && (curobjbut1!='')){
				expandit(curobjbut1);
			}

			if ((curobjbut2!= undefined) && (curobjbut2!='')){
				expandit(curobjbut2);
			}
		

		}
		
		
		
	}

	
	
	
	function leftexpandit(curobj,rekime){
		

		
		if ((curobj!= undefined) && (curobj!='')){
			
			

			fcurobj=get_this_style(curobj);
			if (fcurobj.display=="none"){
				//$('#'+curobj).slideDown("fast");
				$('#'+curobj).show();
				setCookie(curobj, "1");
				$(rekime).removeClass('closed');
				$(rekime).addClass('opened');
			}else{
				//$('#'+curobj).slideUp("fast");
				$('#'+curobj).hide();
				
				setCookie(curobj, "0");
				$(rekime).removeClass('opened');
				$(rekime).addClass('closed');
			}
			
	

		}
		
		
		
	}


	function leftexpanditmenu(){
			if (main_left_section_opened==false) {
				leftexpanditmenu_show();
			} else {
				leftexpanditmenu_hide();
			}
	}

	
	function leftexpanditmenu_show(){
		//$('#main_left_section .ls_section_span_closed_tmp').show().removeClass('ls_section_span_closed_tmp');
		$('#main_left_section').css("overflow","auto");
		$('#main_left_section_closed').hide();
		$('#main_left_section_opened').show();
		
		$('#main_right_section').css("left",max_left_section_width);
		$('#main_left_section').css("width",max_left_section_width);
		
		
		if ($.browser.msie){
			$('body').css("padding-left",max_left_section_width);
		}		
		
		setCookie("main_left_section", "1");
		main_left_section_opened=true;			
		
		return false;

	}	
	
	function leftexpanditmenu_hide(){
		//$('#main_left_section .ls_section_span:visible').hide().addClass('ls_section_span_closed_tmp');
		$('#main_left_section').css("overflow","hidden");
		$('#main_left_section_opened').hide();
		$('#main_left_section_closed').show();
		
		$('#main_right_section').css("left",min_left_section_width);
		$('#main_left_section').css("width",min_left_section_width);
		
		if ($.browser.msie){
			$('body').css("padding-left",min_left_section_width);
		}
		
		setCookie("main_left_section", "0");
		main_left_section_opened=false;
		return false;
	}	
	
	function expandit(curobj,curobjbut1,curobjbut2){
		

		
		if ((curobj!= undefined) && (curobj!='')){
		

			fcurobj=get_this_style(curobj);
			if (fcurobj.display=="none"){
				fcurobj.display="";
				//$('#'+curobj).slideRight("slow");
				setCookie(curobj, "1");
				
			}else{
				fcurobj.display="none";
				//$('#'+curobj).slideLeft("slow");
				setCookie(curobj, "0");
			}
			
			
			if ((curobjbut1!= undefined) && (curobjbut1!='')){
				expandit(curobjbut1);
			}

			if ((curobjbut2!= undefined) && (curobjbut2!='')){
				expandit(curobjbut2);
			}
		

		}
		return false;
		
		
	}


	
	function expandheight(curobj,newheight){
		

		
		if ((curobj!= undefined) && (curobj!='')){
		


			fcurobj=get_this_style(curobj);
			if (fcurobj.height=="0px"){
				fcurobj.height=newheight;
				fcurobj.width="100%";
				fcurobj.overflow="visible";
				setCookie(curobj, "1");
			}else{
				fcurobj.height="0px";
				fcurobj.width="0px";
				fcurobj.overflow="hidden";
				setCookie(curobj, "0");
			}
			
			//alert(fcurobj.height);


		}
		
		
		
	}


	
	function setCookie (name, value, expires, path, domain, secure) {
	path='/';
	      document.cookie = name + "=" + escape(value) +
	        ((expires) ? "; expires=" + expires : "") +
	        ((path) ? "; path=" + path : "") +
	        ((domain) ? "; domain=" + domain : "") +
	        ((secure) ? "; secure" : "");
	}

	function getCookie(name)
	{
		var start = document.cookie.indexOf(name+"=");
		var len = start + name.length + 1;
		if ((!start) && (name != document.cookie.substring(0,name.length))) return null;
		if (start == -1) return null;
		var end = document.cookie.indexOf(";",len);
		if (end == -1) end = document.cookie.length;
		return unescape(document.cookie.substring(len,end));
	}
	
	function showit(curobj,lbutton){
		
		folder=get_this_style(curobj);
		folder.display="";
		document.getElementById(lbutton).className='active';
		setCookie(curobj, "1");
	}

	function hideit(curobj,lbutton){

		folder=get_this_style(curobj);
		folder.display="none";
		document.getElementById(lbutton).className='passive';
		setCookie(curobj, "0");
	}





	function changeImages(curobj,imageurl){
		folder=get_this_style(curobj);
		folder.background = "url("+imageurl+") no-repeat 50% 50%;";
	};


	

	
	
	
	function select_view_product_row(table_rnd,mainid,get){
		
		$('#contents_ajax_table_body_'+table_rnd).find('tr.odd_selected').removeClass('odd_selected').addClass('odd');
		$('#contents_ajax_table_body_'+table_rnd).find('tr.even_selected').removeClass('even_selected').addClass('even');
		
		
		if ($('#contents_ajax_row_'+table_rnd+'_'+mainid).attr("class")=="odd"){
			$('#contents_ajax_row_'+table_rnd+'_'+mainid).removeClass('odd').addClass('odd_selected');
		} else {
			$('#contents_ajax_row_'+table_rnd+'_'+mainid).removeClass('even').addClass('even_selected');
		}
		
	
	
	
	
	
		$('.contents_ajax_single_row_div').hide();
		$('.contents_ajax_single_rows_tr').hide();		
	
		$('#contents_ajax_single_row_'+table_rnd+'_'+mainid).html('<br>');
		//$('#contents_ajax_single_row_'+table_rnd+'_'+mainid).css('height','100px');
		$('#contents_ajax_single_row_'+table_rnd+'_'+mainid).show();
		$('#contents_ajax_single_row_tr_'+table_rnd+'_'+mainid).show();
		
		
		
		//pod strokoj
		changeMain('contents_ajax_single_row_'+table_rnd+'_'+mainid,'product.get_ajax_single_product',mainid,get,table_rnd);
			
	
		return false;
	}
	
	
	function select_view_bms_row(id,table_rnd,mainid,get){
		
		var open_row=true;
		if 
		(
			($('#contents_ajax_table_body_'+table_rnd).find('tr.odd_selected').attr('id')=='contents_ajax_row_'+table_rnd+'_'+mainid)
			||
			($('#contents_ajax_table_body_'+table_rnd).find('tr.even_selected').attr('id')=='contents_ajax_row_'+table_rnd+'_'+mainid)
		)
		{
			open_row=false;
			
			
			
			
		}
		
		
		$('#contents_ajax_table_body_'+table_rnd).find('tr.odd_selected').removeClass('odd_selected').addClass('odd');
		$('#contents_ajax_table_body_'+table_rnd).find('tr.even_selected').removeClass('even_selected').addClass('even');
		
		
		if (open_row){
			if ($('#contents_ajax_row_'+table_rnd+'_'+mainid).attr("class")=="odd"){
				$('#contents_ajax_row_'+table_rnd+'_'+mainid).removeClass('odd').addClass('odd_selected');
			} else {
				$('#contents_ajax_row_'+table_rnd+'_'+mainid).removeClass('even').addClass('even_selected');
			}
		}
		

		
			
		if (open_row){
			$('.contents_ajax_single_row_div').hide();
			$('.contents_ajax_single_rows_tr').hide();		
		
			$('#contents_ajax_single_row_'+table_rnd+'_'+mainid).html('<br>');
			//$('#contents_ajax_single_row_'+table_rnd+'_'+mainid).css('height','100px');
			$('#contents_ajax_single_row_'+table_rnd+'_'+mainid).show();
			$('#contents_ajax_single_row_tr_'+table_rnd+'_'+mainid).show();
			
			
			
			//pod strokoj
			changeMain('contents_ajax_single_row_'+table_rnd+'_'+mainid,'bms.get_ajax_single_bms',id,mainid,get,table_rnd);
			
			//nad tablicej
			//changeMain('contents_ajax_single_bms_'+table_rnd,'bms.get_ajax_single_bms',id,mainid,get,table_rnd);
			
			//v tablice
			//changeMain('contents_ajax_full_table_'+table_rnd,'bms.get_ajax_single_bms',id,mainid,get,table_rnd);
		} else {
			$('.contents_ajax_single_row_div').hide();
			$('.contents_ajax_single_rows_tr').hide();				
		}
		return false;
	}
	
	
	
	
	function select_translation(trans_id,trans_type,lang_id,this_trans){
		//changeMain('get_ajax_edit_translation_main','translations.get_ajax_edit_translation',trans_id,lang_id);
		trans_mouse_out();
		//opendark('','translations.get_ajax_edit_translation',trans_id,lang_id);
		window.open(basehref+"editor.php?go=translations.get_ajax_edit_translation&get_param1="+trans_id+"&get_param2="+lang_id,"Editor","100,100,width=850,height=620,toolbars=no,scrollbars=yes,resizable=yes");	
		return false;
	}	
	
	

	
	function select_itranslation(itrans_id,itrans_type,lang_id,this_itrans){
		//changeMain('get_ajax_edit_itranslation_main','itranslations.get_ajax_edit_itranslation',itrans_id,lang_id);
		itrans_mouse_out();
		//opendark('','itranslations.get_ajax_edit_itranslation',itrans_id,lang_id);
		window.open(basehref+"editor.php?go=itranslations.get_ajax_edit_itranslation&get_param1="+itrans_id+"&get_param2="+lang_id,"Editor","100,100,width=850,height=620,toolbars=no,scrollbars=yes,resizable=yes");
		return false;
	}		
	
	



	var translation_types_names = new Array();
	translation_types_names['-1'] = "text";
	translation_types_names['0'] = "text";
	translation_types_names['1'] = "text";
	translation_types_names['2'] = "text";
	translation_types_names['3'] = "text";
	translation_types_names['4'] = "text";
	translation_types_names['5'] = "text";
	translation_types_names['6'] = "text";
	translation_types_names['7'] = "text";



	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	function trans_mouse_out() {
		if ($("#agb_context_menu").css('display')=="none"){
			$("#agb_context_menu #trans_edit_button").hide();
			$("#agb_context_menu #trans_edit_button a").unbind('click');
		}
	}
	

	function trans_mouse_move(trans_id,trans_type,lang_id,this_trans){
		//$("#agb_context_menu").hide();

		$("#agb_context_menu #trans_edit_button").show();
		$("#agb_context_menu #trans_edit_button a").html("Edit "+translation_types_names[trans_type]);
		
		$("#agb_context_menu #trans_edit_button a").unbind('click');
		$("#agb_context_menu #trans_edit_button a").bind('click', function() {
			select_translation(trans_id,trans_type,lang_id,this_trans);
			return false;
			$("#agb_context_menu").hide();			
		});
		
	}	
		


	function itrans_mouse_out() {
		if ($("#agb_context_menu").css('display')=="none"){
			$("#agb_context_menu #trans_edit_button").hide();
			$("#agb_context_menu #trans_edit_button a").unbind('click');
		}
	}
		
	function itrans_mouse_move(itrans_id,itrans_type,lang_id,this_itrans){
		//$("#agb_context_menu").hide();
		
		$("#agb_context_menu #trans_edit_button").show();
		$("#agb_context_menu #trans_edit_button a").html("Edit "+translation_types_names[itrans_type]);
		
		$("#agb_context_menu #trans_edit_button a").unbind('click');
		$("#agb_context_menu #trans_edit_button a").bind('click', function() {
			select_itranslation(itrans_id,itrans_type,lang_id,this_itrans);
			return false;
			$("#agb_context_menu").hide();
		});
		

		return false;
	}	
	
	
	function change_curr(curr){
		setCookie("cur_curr", curr);
		$('.price').hide();
		$(".currency_id_"+curr).show();	
		
		$(".currency_radio_id_"+curr).attr('checked','checked');	
		
		
		
		
		
	}
	
	
	var price_types_names = new Array();
	price_types_names['-1'] = "price";
	price_types_names['0'] = "price";
	price_types_names['1'] = "price";
	price_types_names['2'] = "price";
	price_types_names['3'] = "price";
	price_types_names['4'] = "price";
	price_types_names['5'] = "price";
	price_types_names['6'] = "price";
	price_types_names['7'] = "price";


	
	function price_mouse_out() {
		if ($("#agb_context_menu").css('display')=="none"){
			$("#agb_context_menu #price_edit_button").hide();
			$("#agb_context_menu #price_edit_button a").unbind('click');
		}
	}
	

	function price_mouse_move(price_id,price_type,curr_id,this_price){
		//$("#agb_context_menu").hide();

		$("#agb_context_menu #price_edit_button").show();
		$("#agb_context_menu #price_edit_button a").html("Edit "+price_types_names[price_type]);
		
		$("#agb_context_menu #price_edit_button a").unbind('click');
		$("#agb_context_menu #price_edit_button a").bind('click', function() {
			select_price(price_id,price_type,curr_id,this_price);
			return false;
			$("#agb_context_menu").hide();			
		});
		
	}
	
	
	
	function select_price(price_id,price_type,curr_id,this_price){
		//changeMain('get_ajax_edit_translation_main','translations.get_ajax_edit_translation',price_id,curr_id);
		price_mouse_out();
		//opendark('','prices.get_ajax_edit_prices',price_id,curr_id);
		
		window.open("editor.php?go=prices.get_ajax_edit_prices&get_param1="+price_id+"&get_param2="+curr_id,"Editor","100,100,width=540,height=220,toolbars=no,scrollbars=no,resizable=no");	
		return false;
	}	
	
	

