//функция динамической подгрузки
/*
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
 
*/
var onLayer = false

/////////////////////////////////////////////////////////////////////////
function mOutLayerLink(id)
{ 
   if(onLayer===false)
   	   return
   onLayer = false
   setTimeout("check('"+id+"')",200);
} 	
function mOutLayer()
{
	 onLayer = false
} 
function mOnLayer()
{
 onLayer = true; 
 
}
function check(id)
{
	if (onLayer == true) {
	setTimeout("check('"+id+"')",200);}
	else 
	 hidden(id);
		
}
function hidden(id)
{
	document.getElementById(id).style.display='none'
}


function context(obj,id)
{
   onLayer = true
   	   // четкое определение координат
   	   //alert(obj.parentNode.offsetLeft)
	//document.getElementById(id).style.top=obj.offsetTop
	//document.getElementById(id).style.left= obj.parentNode.offsetLeft+10
	document.getElementById(id).style.display='block'// opacity
	
}
function f()
{
	location="/main"
}
function test()
{
alert(document.getElementById('main').offsetHeight)
//document.getElementById('main').offsetHeight=document.getElementById('main').offsetHeight	 	
}
function hide()
{  // нужно подогнать высоту под не IE
   //document.getElementById('hide1').style.height=document.getElementById('main').offsetHeight
  //alert(document.getElementById('hide1').style.height)
   	   document.getElementById('hide1').style.height="100px"
   //alert(document.getElementById('main').offsetHeight)
   fadeOpacity.addRule('oR1', .1, .5, 30);
   document.getElementById('hide1').style.visibility='visible' 
   fadeOpacity('hide1', 'oR1')
     	   
}
function show()
{
   	  fadeOpacity.back('hide1')
      document.getElementById('hide1').style.visibility='hidden' 
}

function SelMenu(cnt,index, parent)
{
	//alert(document.getElementById("menu_"+index).style.color="#000000")
//	document.getElementById("batterfly").src="/img/website_02_06_"+(index-1)+".gif"
 for(i=1; i<=cnt; i++)
 {
 	 if (i==index) 
 	 { 
 	 	 document.getElementById(parent+"_menu_"+i).parentNode.style.backgroundImage="url('/img/iskra_02_02.jpg')"
 	 	 document.getElementById(parent+"_menu_"+i).className="menu_sel" 
 	 	 //document.getElementById(parent+"_menu_"+i).parent.style.backgroundImage="url('/img/iskra_02_02.jpg')"
 	 }
 	 else
 	 {
 	  document.getElementById(parent+"_menu_"+i).parentNode.style.backgroundImage="url('/img/iskra_02_05.jpg')"	 
      document.getElementById(parent+"_menu_"+i).className="menu" 
     }
  }
  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 GetBack(id)
{
   var sender = "catalog"
   var command = "getback"
   var param1 = id
   var param2 = ""
   var param3	= ""

    doLoad(sender, command, param1, param2, param3)
   //getBranch
}
function GetGood(id)
{
 var sender = "menu"
 var command = "getgoods"
 var param1 = id
 var param2 = ""
 var param3	= ""
 doLoad(sender, command, param1, param2, param3)
}
	
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)
{ //hide()
     JsHttpRequest.query(
            'http://www.nmz-iskra.ru/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)
				}     
             //show()
            },
          true
        );    
      
}
