	
	
	// BUY PRODUCT
	function send_buy_function(product_id, product_name, price, units, article_id, article_text_id, in_stock)
	{
		if (window.parent.buy_product!=undefined){
			window.parent.buy_product(product_id, product_name, price, units, article_id, article_text_id, in_stock);
		} else {
			alert("Failed to register. Please, contact administrator.")
		}

		/*
		top.myFunction('test');	
	
		document.forms['buy_product_form'].prod_id.value = product_id;
		document.forms['buy_product_form'].prod_price.value = price;
		document.forms['buy_product_form'].prod_name.value = product_name;
		document.forms['buy_product_form'].prod_ammount.value = (parseInt(units,10) ? parseInt(units,10) : 1);
		document.forms['buy_product_form'].prod_article_id.value = article_id;
		document.forms['buy_product_form'].prod_in_stock.value = in_stock;
		if (document.getElementById(article_text_id+'_ingress_div'))
			document.forms['buy_product_form'].prod_article_text.value = document.getElementById(article_text_id+'_ingress_div').innerHTML;
		//alert(article_text_id+'_article_text');

		//document.forms['buy_product_form'].prod_article_text.value = document.getElementById(article_text_id).outerHTML;
		//document.forms['buy_product_form'].prod_article_text.value = document.forms['buy_product_form'].prod_article_text.value.replace('id='+article_text_id,'');
		//document.forms['buy_product_form'].prod_article_text.value = document.forms['buy_product_form'].prod_article_text.value.replace('id='+article_text_id+'_buy','style="display:none;"');
		//alert(document.forms['buy_product_form'].prod_article_text.value);

		document.forms['buy_product_form'].submit();
		//alert('Da');
		*/
	}
	
	
	var copynum=0;
	function changeMain(div_name,get_go,get_param1,get_param2,get_param3,get_param4,get_param5) {
		
		var xwidth=$("#"+div_name).width();
		var xheight=$("#"+div_name).height();
		var offset=$("#"+div_name).offset();
		var xleft=offset.left;
		var xtop=offset.top;

		
		$("#"+div_name).attr('disabled','true');
		//div_loading=$("#main_page_loader").clone(true).insertAfter("#main_page_loader");
		
		
		
		copynum++;
		if (copynum>9) copynum=1;
		
		var div_loading="#main_page_loader"+copynum;

		
		
		
		
		
		
		//$(div_loading).fadeTo(0, 0);
		
		//alert('width: '+xwidth+'; xheight: '+xheight+'; xleft: '+xleft+'; xtop: '+xtop);
		
		$(div_loading).css("position","absolute");
		$(div_loading).css("border","0px none");
		$(div_loading).css("display","block");
		$(div_loading).css("z-index","20000");
		

		$(div_loading).css("margin-top",$("#"+div_name).css("margin-top"));
		$(div_loading).css("margin-right",$("#"+div_name).css("margin-right"));
		$(div_loading).css("margin-bottom",$("#"+div_name).css("margin-bottom"));
		$(div_loading).css("margin-left",$("#"+div_name).css("margin-left"));
		
		$(div_loading).css("padding-top",$("#"+div_name).css("padding-top"));
		$(div_loading).css("padding-right",$("#"+div_name).css("padding-right"));
		$(div_loading).css("padding-bottom",$("#"+div_name).css("padding-bottom"));
		$(div_loading).css("padding-left",$("#"+div_name).css("padding-left"));
		
		$(div_loading).css("border-top",$("#"+div_name).css("border-top"));
		$(div_loading).css("border-right",$("#"+div_name).css("border-right"));
		$(div_loading).css("border-bottom",$("#"+div_name).css("border-bottom"));
		$(div_loading).css("border-left",$("#"+div_name).css("border-left"));
		
		
		
		$(div_loading).width(xwidth);
		$(div_loading).height(xheight);	
		$(div_loading).css("top",xtop);
		$(div_loading).css("left",xleft);
		

		
		
		
		$(div_loading).fadeTo("fast", 0.60);
		

		//alert(div_loading);
		//putting empty in variable, if not defined
		//if (lasturl==undefined)	lasturl='{$lasturl}';
		
		if (get_go==undefined)	get_go='';
		if (get_param1==undefined)	get_param1='';
		if (get_param2==undefined)	get_param2='';
		if (get_param3==undefined)	get_param3='';
		if (get_param4==undefined)	get_param4='';
		if (get_param5==undefined)	get_param5='';
		
		//$("#"+div_name).hide(); 
		if (get_go!=''){
			var content_show = $(this).attr("title"); //retrieve title of link so we can compare with php file 
			
			$.ajax({
				method: "get",url: "actions.php",data: "ajax=true&go="+get_go+"&get_param1="+get_param1+"&get_param2="+get_param2+"&get_param3="+get_param3+"&get_param4="+get_param4+"&get_param5="+get_param5+"&lasturl="+lasturl,
				cache: false,
				beforeSend: function(){$(div_loading).show();}, //show loading just when link is clicked 
				complete: function(){ $(div_loading).hide();}, //stop showing loading when the process is complete 
				success: function(html){ //so, if data is retrieved, store it in html 
					$("#"+div_name).show(); //animation 
					
					//$(div_loading).remove();
					$(div_loading).hide();
					$("#"+div_name).html(html); //show the html inside .content div 
					$("#"+div_name).removeAttr("disabled").focus();
					recheck_definitions();
					apply_simpletip();
				}
			}); //close $.ajax( 
			//alert(1);
		} else {
			$(div_loading).fadeOut("slow");
		}
		
	}
	
	function select_page(div_name,get_go,get,sort_dir,table_rnd,page){
		//alert(page);
		//alert(get_go+''+table_rnd+page);
		changeMain(div_name,get_go,get,'',table_rnd,page);
	}	
	

	function select_sortmenu(table_rnd,cell_id,sort_dir,div_name,get_go,get_param1){
		
		//alert(sort_dir);
		//alert("Asked sorting: "+sort_dir);
		//making all TH - passive
		var tmp_th = document.getElementById('sortmenu_'+table_rnd).getElementsByTagName('th');
		
		for(var i = 0; i < tmp_th.length; i++) {
			//taking from all A arrows
			var tmp_but = document.getElementById('sortmenu_'+table_rnd).getElementsByTagName("th")[i].getElementsByTagName('a');
		
			
			if (tmp_th[i].className=='sort_active'){
				tmp_th[i].className='sort_passive';
			}
				
			if (tmp_th[i].className=='sort_passive'){
				for(var i2 = 0; i2 < tmp_but.length; i2++) {
					
					tmp_but[i2].style.backgroundImage='url(design/updown/updown_small.gif)';
					//='url(design/updown/updown_up_solid.gif);';
					//document.getElementById('sortmenu_'+table_rnd).getElementsByTagName("th")[i].getElementsByTagName('a')[i2].title=sort_dir;
					tmp_but[i2].title=sort_dir;
					//alert(tmp_but[i2].title);
					//alert(sort_dir);
 
					if (sort_dir=="ASC"){
							tmp_but[i2].onmouseover=function onmouseover(event) {this.style.backgroundImage='url(design/updown/updown_ASC_trans.gif)'};
							tmp_but[i2].onmouseout=function onmouseout(event) {this.style.backgroundImage='url(design/updown/updown_small.gif)'};
							tmp_but[i2].onmousedown=function onmousedown(event) {this.style.backgroundImage='url(design/updown/updown_ASC_solid.gif)'};
					} else {
							tmp_but[i2].onmouseover=function onmouseover(event) {this.style.backgroundImage='url(design/updown/updown_DESC_trans.gif)'};
							tmp_but[i2].onmouseout=function onmouseout(event) {this.style.backgroundImage='url(design/updown/updown_small.gif)'}; 
							tmp_but[i2].onmousedown=function onmousedown(event) {this.style.backgroundImage='url(design/updown/updown_DESC_solid.gif)'}; 
					}
				}
			}
 
			
		}
		
		
 
		document.getElementById('sortmenu_'+table_rnd+'_'+cell_id+'').className='sort_active';
		
		//making button hoverable
		
		
		
		
		
		//document.getElementById('sortmenu_'+table_rnd+'['+cell_id+'_a]').style.backgroundImage='url(http://prime/cat/design/icons/ajax_sm.png)';		
		
		
		var sel_but = document.getElementById('sortmenu_'+table_rnd+'_'+cell_id+'_a');	
		//alert("Sel but title in the start: "+sel_but.title);
		if (sort_dir=="ASC"){
				sel_but.style.backgroundImage="url(design/updown/updown_ASC_solid.gif)"; 
				
				sel_but.onmouseover=function onmouseover(event) {this.style.backgroundImage='url(design/updown/updown_DESC_ASC_solid.gif)'};
				sel_but.onmouseout=function onmouseout(event) {this.style.backgroundImage='url(design/updown/updown_ASC_solid.gif)'};
				sel_but.onmousedown=function onmousedown(event) {this.style.backgroundImage='url(design/updown/updown_DESC_solid.gif)'};
		} else {
				sel_but.style.backgroundImage="url(design/updown/updown_DESC_solid.gif)";
 
				sel_but.onmouseover=function onmouseover(event) {this.style.backgroundImage='url(design/updown/updown_ASC_DESC_solid.gif)'};				
				sel_but.onmouseout=function onmouseout(event) {this.style.backgroundImage='url(design/updown/updown_DESC_solid.gif)'}; 
				sel_but.onmousedown=function onmousedown(event) {this.style.backgroundImage='url(design/updown/updown_ASC_solid.gif)'}; 
		}
		
		//making this active box title different from others....
		if (sort_dir=="ASC"){
			sort_dir_new='DESC';
			sel_but.title=sort_dir_new;
		} else {
			sort_dir_new='ASC';
			sel_but.title=sort_dir_new;
		}
 
		//alert("Sel but title in the end: "+sel_but.title);
		
		
		changeMain(div_name,get_go,get_param1,sort_dir,table_rnd);
	}
	
	
	
	function select_sortmenu_bms(table_rnd,cell_id,sort_dir,div_name,get_go,get_param1,get_param2){
		
		//alert(sort_dir);
		//alert("Asked sorting: "+sort_dir);
		//making all TH - passive
		var tmp_th = document.getElementById('sortmenu_'+table_rnd).getElementsByTagName('th');
		
		for(var i = 0; i < tmp_th.length; i++) {
			//taking from all A arrows
			var tmp_but = document.getElementById('sortmenu_'+table_rnd).getElementsByTagName("th")[i].getElementsByTagName('a');
		
			
			if (tmp_th[i].className=='sort_active'){
				tmp_th[i].className='sort_passive';
			}
				
			if (tmp_th[i].className=='sort_passive'){
				for(var i2 = 0; i2 < tmp_but.length; i2++) {
					
					tmp_but[i2].style.backgroundImage='url(design/updown/updown_small.gif)';
					//='url(design/updown/updown_up_solid.gif);';
					//document.getElementById('sortmenu_'+table_rnd).getElementsByTagName("th")[i].getElementsByTagName('a')[i2].title=sort_dir;
					tmp_but[i2].title=sort_dir;
					//alert(tmp_but[i2].title);
					//alert(sort_dir);
 
					if (sort_dir=="ASC"){
							tmp_but[i2].onmouseover=function onmouseover(event) {this.style.backgroundImage='url(design/updown/updown_ASC_trans.gif)'};
							tmp_but[i2].onmouseout=function onmouseout(event) {this.style.backgroundImage='url(design/updown/updown_small.gif)'};
							tmp_but[i2].onmousedown=function onmousedown(event) {this.style.backgroundImage='url(design/updown/updown_ASC_solid.gif)'};
					} else {
							tmp_but[i2].onmouseover=function onmouseover(event) {this.style.backgroundImage='url(design/updown/updown_DESC_trans.gif)'};
							tmp_but[i2].onmouseout=function onmouseout(event) {this.style.backgroundImage='url(design/updown/updown_small.gif)'}; 
							tmp_but[i2].onmousedown=function onmousedown(event) {this.style.backgroundImage='url(design/updown/updown_DESC_solid.gif)'}; 
					}
				}
			}
 
			
		}
		
		
 
		document.getElementById('sortmenu_'+table_rnd+'['+cell_id+']').className='sort_active';
		
		//making button hoverable
		
		
		
		
		
		//document.getElementById('sortmenu_'+table_rnd+'['+cell_id+'_a]').style.backgroundImage='url(http://prime/cat/design/icons/ajax_sm.png)';		
		
		
		var sel_but = document.getElementById('sortmenu_'+table_rnd+'['+cell_id+'_a]');	
		//alert("Sel but title in the start: "+sel_but.title);
		if (sort_dir=="ASC"){
				sel_but.style.backgroundImage="url(design/updown/updown_ASC_solid.gif)"; 
				
				sel_but.onmouseover=function onmouseover(event) {this.style.backgroundImage='url(design/updown/updown_DESC_ASC_solid.gif)'};
				sel_but.onmouseout=function onmouseout(event) {this.style.backgroundImage='url(design/updown/updown_ASC_solid.gif)'};
				sel_but.onmousedown=function onmousedown(event) {this.style.backgroundImage='url(design/updown/updown_DESC_solid.gif)'};
		} else {
				sel_but.style.backgroundImage="url(design/updown/updown_DESC_solid.gif)";
 
				sel_but.onmouseover=function onmouseover(event) {this.style.backgroundImage='url(design/updown/updown_ASC_DESC_solid.gif)'};				
				sel_but.onmouseout=function onmouseout(event) {this.style.backgroundImage='url(design/updown/updown_DESC_solid.gif)'}; 
				sel_but.onmousedown=function onmousedown(event) {this.style.backgroundImage='url(design/updown/updown_ASC_solid.gif)'}; 
		}
		
		//making this active box title different from others....
		if (sort_dir=="ASC"){
			sort_dir_new='DESC';
			sel_but.title=sort_dir_new;
		} else {
			sort_dir_new='ASC';
			sel_but.title=sort_dir_new;
		}
 
		//alert("Sel but title in the end: "+sel_but.title);
		
		
		changeMain(div_name,get_go,get_param1,get_param2,sort_dir,table_rnd);
	}
	
	
	
	
	
	
	
	
	
	
	
	
		function transfer_from_fck_to_input(f) {
			//alert(this.form.translation[eng].value);
			//alert(FCKeditorAPI.GetInstance('translation[eng]').GetXHTML());
			
			
			
			// Loop through all the elements in the form
		    for(var i = 0; i < f.elements.length; i++) {
				if (f.elements[i]!=undefined){
					var e = f.elements[i];
					
					if ((e.type=="hidden") && (e.style.display=="none") && (e.name==e.id)){
						//esli eto tot samij tipa
						
						if ($(f).find("input[id='"+e.name+"'][name='"+e.name+"']").val()!=undefined){
							if ($(f).find("input[id='"+e.name+"___Config']").val()!=undefined){
						
								if (FCKeditorAPI.GetInstance(e.name)!=undefined){
									var content=FCKeditorAPI.GetInstance(e.name).GetHTML();
									$(f).find("input[id='"+e.name+"'][name='"+e.name+"']").val(content)
								} else {
									alert("FCKEditor fails: "+e.name);
								}
							}
						}
						//translation[eng]___Config
						
					}
				}
					
				
		    }


		}









		 function SetAjaxForm(this_form,response_div){

				
				
				var options = { 
					target:        '#'+response_div,   // target element(s) to be updated with server response 
					beforeSubmit:  function(){
						$('#'+response_div).show();
						$('#'+response_div).removeClass('error_report');
						$('#'+response_div).addClass('loading_report');
						$('#'+response_div).html("&nbsp;");
						$('#'+response_div).height(50);
						
					},  // pre-submit callback 
					success:       function(){
						$('#'+response_div).removeClass('loading_report');
						$('#'+response_div).addClass('error_report');
						$('#'+response_div).height('auto');
						$('#'+response_div).show();
					}
					// post-submit callback 
					// other available options: 
					//url:       url         // override for form's 'action' attribute 
					//type:      type        // 'get' or 'post', override for form's 'method' attribute 
					//dataType:  null        // 'xml', 'script', or 'json' (expected server response type) 
					//clearForm: true        // clear all form fields after successful submit 
					//resetForm: true        // reset the form after successful submit 

					// $.ajax options can be used here too, for example: 
					//timeout:   3000 
				}; 				
				
				transfer_from_fck_to_input(this_form);				
				$(this_form).ajaxSubmit(options);
				
				//window.opener.document.location.replace(window.opener.document.location.pathname);
				return false;
				
				
			}
	
	
