//функция динамической подгрузки
/*
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 addVacancy(what)
{
  
	
	var job_contact=document.getElementById('job_contact').value
	var job_type=document.getElementById('job_type').value
	var job_id=document.getElementById('row_id').value
	var job_name=document.getElementById('job_name').value
	var job_title=document.getElementById('job_title').value
	var job_treb=document.getElementById('job_treb').value
	var job_uslov=document.getElementById('job_usl').value
	var job_instrukt=document.getElementById('job_instrukt').value
	var job_pay=document.getElementById('job_pay').value
	var job_pol=document.getElementById('job_pol').value
	var job_staj=document.getElementById('job_staj').value
	var job_obr=document.getElementById('job_obr').value
	var job_graf=document.getElementById('job_graf').value
	var job_gorod=document.getElementById('job_gorod').value
	var job_old1=document.getElementById('job_old1').value
	var job_old2=document.getElementById('job_old2').value

	var	job_visible=0

	
	var names="job_contact%|%job_name%|%job_title%|%job_treb%|%job_uslov%|%job_instrukt%|%job_pay%|%job_pol%|%job_staj%|%job_obr%|%job_graf%|%job_gorod%|%job_old1%|%job_old2%|%job_visible"
	var content=job_contact+"%|%"+job_name+"%|%"+job_title+"%|%"+job_treb+"%|%"+job_uslov+"%|%"+job_instrukt+"%|%"+job_pay+"%|%"+job_pol+"%|%"+job_staj+"%|%"+job_obr+"%|%"+job_graf+"%|%"+job_gorod+"%|%"+job_old1+"%|%"+job_old2+"%|%"+job_visible
	var lnk=""
	var t=0;
	obj=document.getElementById("job_rub")
	for(i=0;i<obj.options.length;i++)
	{
		if(obj.options[i].selected)
		{
			if(t!=0)
				lnk=lnk+"%|%"	
			lnk=lnk+obj.options[i].value
			t=1;
		}
	}
	//alert( what+"||"+names+"%|||%"+content+"%|||%"+lnk)
	//	return

	doLoad("menu", what+"Vacancy", names+"%|||%"+content+"%|||%"+lnk, job_id, job_type) 
}
function show(id, displ)
{
	document.getElementById(id).style.display=displ
}
function tellAbout()
{
	var vs_name=document.getElementById("s_name").value
		
	var io_name=document.getElementById("io_name").value
	var day=document.getElementById("day").value
	var month=document.getElementById("month").value
	var year=document.getElementById("year").value
	var adress=document.getElementById("adress").value
	var tel=document.getElementById("tel").value
	var mail=document.getElementById("mail").value
		
	var education=document.getElementById("education").value
	var experience =document.getElementById("experience").value
	var skills  =document.getElementById("skills").value
	var projects=document.getElementById("projects").value
	var english=document.getElementById("english").options[document.getElementById("english").value].text   //document.getElementById("english").value
	var deutch=document.getElementById("deutch").options[document.getElementById("deutch").value].text 
	var	languages=document.getElementById("languages").value
		
	var pc_excel=document.getElementById("pc_excel").checked
		if(pc_excel)
		 	pc_excel="да"
		else
		    pc_excel="нет"
		
	var pc_project=document.getElementById("pc_project").checked
		if(pc_project)
		 	pc_project="да"
		else
		    pc_project="нет"
		
	
	var pc_powerpoint=document.getElementById("pc_powerpoint").checked
		if(pc_powerpoint)
		 	pc_powerpoint="да"
		else
		    pc_powerpoint="нет"
	
	var pc_inet=document.getElementById("pc_inet").checked
		if(pc_inet)
		 	pc_inet="да"
		else
		    pc_inet="нет"
		
	
	var ozp =document.getElementById("ozp").checked
		if(ozp)
		 	ozp="да"
		else
		    ozp="нет"
	
	var pub =document.getElementById("pub").checked
		if(pub)
		 	pub="да"
		else
		    pub="нет"

	var vacancy  =document.getElementById("vacancy").value
	var salary  =document.getElementById("salary").value
	var comments =document.getElementById("comments").value
		
	var str="Фамилия: "+ vs_name+"<br>Имя Отчество: "+ io_name+"<br>Дата рождения: "+	day+"/"+month+"/"+year+" <br>Адрес: "+	adress +"<br>Телефон: "+	tel +"<br>e-mail: "+	mail +"<br>	Обучение: "+ education	+"<br>Опыт: "+ experience	+"<br>Навыки и их уровень: "+	skills+"<br>Оконченные проекты: "+	projects+"<br><b>Знание языков</b> <br>	Английский: "+	english+"<br>Немецкий: "+	deutch+"<br>Другие: "+	languages +"<br><b>Знание компьютера</b> <br>MS Excel: "+	pc_excel +"<br>	MS Project: "+	pc_project +"<br>Power Point: "+	pc_powerpoint +"<br>Internet: "+	pc_inet +"<br>Загранпаспорт: "+	ozp +"<br>Навыки публичных выступлений: "+	pub +"<br>Должность: "+	vacancy +"<br>Желаемый уровень зарплаты: "+	salary +"<br>Дополнительные сведения: "+	comments +"<br>	"
		//alert(str)
		doLoad("menu", "tellabout", str, document.getElementById("resume"),document.getElementById("photo") )	
		//	return false
		//alert(str)
		
	/*  формируем письмо полностью здесь и отправляем на mail
s_name
io_name
	day
	month
	year
	adress
	
	
	
	tel
	mail
	education
	experience опыт
	skills  навыки и их уровень
	projects
	english
	deutch
	pc_excel
	pc_project
	pc_powerpoint
	pc_inet
	ozp загранпаспорт
	pub публичные выступления
	vacancy  название вакансии
	salary  // зп
	comments
		
	resume
	photo
	
alert("123")*/
}
function ShowSub(id, cnt, pid)
{
  
   //if(pid==103 ||pid==104 ||pid==105 ||pid==44 || id=="n20_menu_4")
   	 //  return
   	  //alert(id) 
   	if(pid==113 ||pid==114 || pid==104 ||pid==105 ||pid==44)
   	   return
       var i
  	 for (i=1;i<=cnt;  i++)
  	  {
  	  	  document.getElementById("n"+pid+"_menu_"+i).style.display ='none'
  	  	//alert("n"+pid+"_menu_"+i)
  	  }
  /*if (document.getElementById(id).style.display=='block')
  	  document.getElementById(id).style.display='none'
  	 else*/
  document.getElementById(id).style.display='block'
  	  	  
  	 
}
function SelMenu(cnt,index, parent)
{	
	//alert("cnt="+ cnt +" index="+ index + " pid=" + parent)
 if(parent==45) 
 		return
 if(parent==20)
 for(i=1; i<=cnt; i++)
 {
 	 if (i==index) 
 	 {
 	 	 	document.getElementById(parent+"_menu_"+i).className="menu_sel" 
			//document.getElementById(parent+"_menu_"+i).parentNode.firstChild.src="/img/sel.jpg"
 	 }
 	 else
 	 {
      document.getElementById(parent+"_menu_"+i).className="menu" 
      //document.getElementById(parent+"_menu_"+i).parentNode.firstChild.src="/img/nsel.jpg"
     }
  }
  else if(parent==45)
  	   for(i=1; i<=cnt; i++)
 {
 	 if (i==index) 
 	  document.getElementById(parent+"_menu_"+i).className="menu_sel2" 
 	 else
      document.getElementById(parent+"_menu_"+i).className="menu2" 
  }

}
function ShowAll(id)
{
  	 window.open('/show.php?id='+id,'_blank','left='+((document.body.clientWidth-500)/2)+', top=100 width=500,height=400,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 setFull(type)
{
	if(document.getElementById("rez").style.display!="none" || document.getElementById("vac").style.display!="none")
 	{
 		 if(type==1)
 		{
 			document.getElementById("rez").style.display="block"
 			document.getElementById("vac").style.display="none"
 		}
 		else 
 		{
 			document.getElementById("rez").style.display="none"
 			document.getElementById("vac").style.display="block"
 			
 		}
 			
 	}
}
function getFull(obj)
{
 if(document.getElementById("rez").style.display=="none" && document.getElementById("vac").style.display=="none")
 	 obj.innerText="простой поиск"
 else
 	 	obj.innerText="расширенный поиск"
 if(document.getElementById("tn").checked) // резюме
 {
 	
 		if(document.getElementById("rez").style.display=="none")
 			document.getElementById("rez").style.display="block"
 		else
 			document.getElementById("rez").style.display="none"
 			
 		document.getElementById("vac").style.display="none"
 }
  else
 {
 	
 		if(document.getElementById("vac").style.display=="none")
 			document.getElementById("vac").style.display="block"
 		else
 			document.getElementById("vac").style.display="none"
 			
 		document.getElementById("rez").style.display="none"
 		
 }
 

}
function sendSearch()
{
/*	if(document.getElementById("tn").checked)
		doLoad("catalog", "search", document.getElementById('f1'), "тест11", "тест22")
	else
		doLoad("catalog", "search", document.getElementById('f2'), "тест1", "тест2")

	return
	*/
	var parent=""
	
	/*if(document.getElementById("rub_r")[0].value!=null)
			parent=" and pid='"+document.getElementById("rub_r")[0].value+"' "
	if(document.getElementById("rub_r")[1].value!=null)
			parent=parent+" or pid='"+document.getElementById("rub_r")[1].value+"' "
*/

//		alert(parent)
//	return	false
var zp_def
if(document.getElementById("tn").checked)
{
   type=1
   obj=document.getElementById("rub_r")
   zp_def=document.getElementById("zp_def_r").checked
   
}
else
{
	type=0
	obj=document.getElementById("rub_v")
	zp_def=document.getElementById("zp_def_v").checked
   
}
	var i=0
	var t=0
	

	
for(i=0;i<obj.options.length;i++)
	{
		if(obj.options[i].selected)
		{
			if(t==0)
			{
				parent=" and link_pid='"+obj.options[i].value+"' "
				t=1
			}
			else
			   parent=parent+" or link_pid='"+obj.options[i].value+"' "
			
		}

	}

		
 var s=document.getElementById("search").value
 
if(document.getElementById("rez").style.display=="none" && document.getElementById("vac").style.display=="none")
{
	 doLoad("catalog", "search", s, type, "")	 
}
else
{
	var str
//	alert(document.getElementById("old1_r").value+"||"+document.getElementById("old2_r").value+"||"+document.getElementById("zp_r").value+"||"+document.getElementById("staj_r").value+"||"+document.getElementById("pol_r").value+"||"+document.getElementById("graf_r").value+"||"+document.getElementById("obr_r").value+"||"+parent+"||"+document.getElementById("gorod_r").value)
	
//	return		
	if(type==1)
	{
			str=document.getElementById("old1_r").value+"||"+document.getElementById("old2_r").value+"||"+document.getElementById("zp_r").value+"||"+document.getElementById("staj_r").value+"||"+document.getElementById("pol_r").value+"||"+document.getElementById("graf_r").value+"||"+document.getElementById("obr_r").value+"||"+parent+"||"+document.getElementById("gorod_r").value+"||"+zp_def
		//	alert(str)
		//	return
	}
	else
	{
		str=document.getElementById("old1_v").value+"||"+document.getElementById("zp_v").value+"||"+document.getElementById("staj_v").value+"||"+document.getElementById("pol_v").value+"||"+document.getElementById("graf_v").value+"||"+document.getElementById("obr_v").value+"||"+parent+"||"+document.getElementById("gorod_v").value+"||"+zp_def
		//alert(str)
		//return
	}

	
	 doLoad("catalog", "search", s, type, str)

}    
 
     
}
function ShowGoodAll(id, type)
{
  	 window.open('/show.php?id='+id+'&t='+type,'_blank','left='+((document.body.clientWidth-650)/2)+', top=200, width=650px,height=500px,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)
{ //hide()
	self.scroll(0,0)
     JsHttpRequest.query(
            'http://www.capitalresource.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
        );    
      
}

