//функция динамической подгрузки
/*
1 - catalog
sender=catalog
1.1 command=getbranch
	param1=pid
	param2=level
1.2 command=editbranch
	param1=pid
	param2=id
1.3 command=delbranch
	param1=pid
	param2=id
1.4 command=addbranch
	param1=pid
	param2=name
 
*/
function hidemenu()
{
  document.getElementById('hmenu').style.display="none"	
 
}
function f(n)
{
//alert(n)
	if(n==1){ name="О компании"; id="44"}
	if(n==2){ name="Сертификаты"; id="68"}
	if(n==3){ name="Награды"; id="104"}
	if(n==4){ name="Потребителю"; id="45"}
	if(n==5){ name="Новости"; id="103"}
	if(n==6){ name="Продукция"; id="74"}
	if(n==7){ name="Контакты"; id="101"}
	
		
	SelMenu2(name)
	  GetPageById(id, "20");
	
	/*else
	if(n==1)
	if(n==1)
	if(n==1)
	if(n==1)
	if(n==1)*/
}	
function SelMenu(cnt,index, parent)
{

//document.getElementById('pname').innerHTML =
	 document.getElementById('pname').innerHTML =document.getElementById(parent+"_menu_"+index).title
 for(i=1; i<=cnt; i++)
 {
 	 if (i==index) 
 	  document.getElementById(parent+"_menu_"+i).className="menu_sel" 
 	 else
      document.getElementById(parent+"_menu_"+i).className="menu" 
  }
  return false;
}
function SelMenu2(name)
{

	document.getElementById('pname').innerHTML = name
  return false;
}

function ShowAll(id)
{
  	 window.open('/show.php?id='+id,'_blank','left='+((document.body.clientWidth-500)/2)+', top=200 width=500px,height=400px,location=no,toolbar=no,menubar=no,status=no'); 

}
function getBranch(sender, command, param1, param2, param3)
{
  doLoad(sender, command, param1, param2, param3)
}
//---------------------------------------------------------------
function GetQuestion()
{
     var name=document.getElementById("name").value
     var mail=document.getElementById("mail").value
     var quest=document.getElementById("question").value
     //alert(name+":"+mail+":"+quest)
    doLoad("menu", "question", name, mail, quest)

}
function ShowGoodAll(id)
{
  	 window.open('/show.php?id='+id,'_blank','left='+((document.body.clientWidth-850)/2)+', top=200, width=850px,height=600px,location=no,toolbar=no,status=no,scrollbars=yes'); 
	// window.open('/show.php?id='+id,'_blank','left='+((document.body.clientWidth-500)/2)+', top=200, width=800px,height=400px,location=no,toolbar=no,menubar=no,status=no'); 

}
function setMainPhoto(path)
{
 document.getElementById("mainphoto").src="/modules/catalog/pictures/3/"+path	
}
function getCatByPage(pid, page, tmpl)
{
	//alert(tmpl)
	 doLoad("catalog", "getpage", pid, page,tmpl)
}
 var rules="[%page%];[%portfshort%];[%newsshort%]";
 function showDiv(id, show)
{
	if(show==0) return
    curDiv=document.getElementById(id)  
   if(show==1)
   {
    if(curDiv.style.display=='none')
  	  curDiv.style.display='block'
    else curDiv.style.display='none'
   }
   if(show==2)
  {
   if(curDiv.style.display=='none')
  	 curDiv.style.display='block'
   }
} 
function GetPageById(id,pid)
{
 var sender = "menu"
 var command = "getpage"
 var param1 = rules
 var param2 = id
 var param3	= pid
 doLoad(sender, command, param1, param2, param3)
}
function GetFullArticles(link)
{
 var sender = "articles"
 var command = "getfullarticles"
 var param1 = rules
 var param2 = link
 var param3	= ""
 doLoad(sender, command, param1, param2, param3)

}	
function GetFullNews(link)
{
//	alert(link)
	//	return;
 var sender = "news"
 var command = "getfullnews"
 var param1 = rules
 var param2 = link
 var param3	= ""
 doLoad(sender, command, param1, param2, param3)

}
function GetMod(link, mod)
{
//	alert(link)
	//	return;
 var sender = mod
 var command = "getfull"+mod
 var param1 = rules
 var param2 = link
 var param3	= ""
 doLoad(sender, command, param1, param2, param3)

}
function doLoad(sender, command, param1, param2, param3)
{
     JsHttpRequest.query(
            '/load.php', // backend
            {
               sender : sender,
               command : command, 
               param1 : param1,
               param2 : param2,
               param3 : param3   
            },
            // Function is called when an answer arrives. 
            function(result, errors) 
           {
             if (result['out1']!=null&&result['out1']!=0&&result['dest1']!=null)
			   { 
			   	  // alert(result['dest1'])
				  document.getElementById(result['dest1']).innerHTML = result['out1']
				  showDiv(result['dest1'],result['show'])
				}   	
			 if (result['out2']!=null&&result['out2']!=0&&result['dest2']!=null)
				{   
				    document.getElementById(result['dest2']).innerHTML = result['out2']	  
				}     
           	 if (result['out3']!=null&&result['out3']!=0&&result['dest3']!=null)
				{   
				    document.getElementById(result['dest3']).innerHTML = result['out3']	  
				}    
           	 if (result['out4']!=null&&result['out4']!=0&&result['dest4']!=null)
				{   
				    document.getElementById(result['dest4']).innerHTML = result['out4']	  
				}     
           	 if (result['rules']!=null)
				{   //alert(rules)
				    rules = result['rules']	  
				    	//alert(rules)
				}     
           
            },
          true
        );    
      
}

