function selectMenuItem(i)
{
	var menu = document.getElementById('submenu');
	var obj = null;
	g=0; k=-1;
	while(g<menu.childNodes.length)
	{
		obj = menu.childNodes[g];
		if (obj.tagName=='LI')
		{
			k++;
		}
		if (k==i) {obj.className+=" current"; return}
		g++;
	}
	return;
}
function vacancyClick(sender)
{
	var parent = sender.parentElement;
	if (parent==null) parent = sender.parentNode;
	var ul = document.createElement("UL");
	var city=new Array("Москва","Санкт-Петербург","Казань","Пермь","Краснодар","Новосибирск");
	var link=new Array("moscow.html","stpeterburg.html","kazan.html","perm.html","krasnodar.html","novosibirsk.html");
	ul.className = "list2";
	var li = null;
	var ach = null;
	for (i=0;i<city.length;i++)
	{
		li = document.createElement("LI");
		ach = document.createElement("A");
		ach.innerHTML=city[i];
		ach.href = "/job/"+link[i];
		li.appendChild(ach);
		ul.appendChild(li);
	}
	sender.onclick = vacancyClickStub;
	parent.appendChild(document.createElement("BR"));
	parent.appendChild(document.createElement("BR"));
	parent.appendChild(ul);
	ul.id="subsubmenu";
	return false;
}
function vacancyClickStub()
{
	return false;
}
function selectSubMenuItem(i,id)
{
	var menu = document.getElementById(id);
	var obj = null;
	g=0; k=-1;
	while(g<menu.childNodes.length)
	{
		obj = menu.childNodes[g];
		if (obj.tagName=='LI')
		{
			k++;
		}
		if (k==i) {obj.className+=" current"; return}
		g++;
	}
	return;
}
function changeBkg(obj,file)
{
//alert(obj.style.backgroundImage);
	//obj.style.backgroundImage = file;
//	alert(obj.backgroundImage);
}
function ShowGallery(id)
{
	//width=600, height=450, 
	w = window.open( "/gallery/"+id+"/index.html" , "_blank","width=777, height=618, status=0, channelmode=0, directories=0, fullscreen=0, location=0, menubar=0,  toolbar=0");
	return false;
}
function ShowGalleryEx(galID,itemID)
{
	w = window.open( "/gallery/"+galID+"/"+itemID+"/index.html" , "_blank","width=777, height=618, status=0, channelmode=0, directories=0, fullscreen=0, location=0, menubar=0,  toolbar=0");
	return false;
}
function tableChangeClass(obj,className,turn)
{
	if (turn==1) {obj.className = obj.className+" "+className;}
	else if (turn==0){
		str = obj.className;
		ind = str.indexOf(className);
		str = str.substr(0,ind);
		obj.className = str;
		
		//obj.className = " className";
	}
	
}
function prepTables(id)
{
	objs = document.all(id);
	if (objs != null)
	{
		if (objs.length != null)
		{
			for (i = 0; i < objs.length; i++)
			{
				prepOneTable(objs[i]);
			}
		}
		else
		{
			prepOneTable(objs);
		}
	}
}
function prepOneTable(tbl)
{
	for (i = 0; i < tbl.rows.length; i++)
	{
		prepRow(tbl.rows[i]);
	}
}

function prepRow(row)
{
	isOpera=(window.opera)?true:false;
  	isMSIE=(document.all && document.all.item && !isOpera);
	if (isMSIE)
	{
		row.onmouseover = onOver;
		row.onmouseout = onOut;
	}
	else
	{
		attr1 = document.createAttribute('onmouseover');
		attr1.value = "tableChangeClass(this,'over',1);";
		attr2 = document.createAttribute('onmouseout');
		attr2.value = "tableChangeClass(this,'over',0);";
		row.setAttributeNode(attr1);
		row.setAttributeNode(attr2);
	}
}
function onOver()
{
	obj = window.event.srcElement;
	while((obj!=null)&&(obj.tagName!='TR'))
	{
		obj = obj.parentElement;
	}
	if (obj!=null) {tableChangeClass(obj,"over",1)}
}
function onOut()
{
	obj = window.event.srcElement;
	while((obj!=null)&&(obj.tagName!='TR'))
	{
		obj = obj.parentElement;
	}
	if (obj!=null) {tableChangeClass(obj,"over",0)}
}
function LoadGalleryPage()
{
	var index = 0;
		
	if ((window.ImgIndex==null) || (window.ImgExt==null) || (window.CurrentImageInd==null)) close();
	
	if (index==0) 
		pagerStr = "<a id=\"prev\" onclick=\"ImgBack(this)\" class=\"disabled\">предыдущая</a>&nbsp;";
	else
		pagerStr = "<a id=\"prev\" onclick=\"ImgBack(this)\">предыдущая</a>&nbsp;";
	for(i=0;i<window.ImgIndex.length;i++)
	{
		if (i>0) pagerStr += "|&nbsp;";
		if (i==index)
			pagerStr += "<a class=\"sel\" id=\"image"+i+"\" onclick=\"LoadImg("+i+");\">"+(i+1)+"</a> "
		else 
			pagerStr += "<a id=\"image"+i+"\" onclick=\"LoadImg("+i+");\">"+(i+1)+"</a> "
	}
	if (index==(window.ImgIndex.length-1))
		pagerStr += "<a id=\"next\" onclick=\"ImgForward(this)\" class=\"disabled\">следующая</a>";
	else
		pagerStr += "<a id=\"next\" onclick=\"ImgForward(this)\">следующая</a>";
	
	pagerObj = document.all('pager');
	pagerObj.innerHTML = pagerStr;
}
function onLoadImage()
{
	var obj = null;
	if (window.event!=null)
	{
		obj = window.event.srcElement;
	}
	else
	{
		obj = window.document.getElementById('imageContainer');
		if ((obj!=null) && (obj.childNodes.length==1)) obj = obj.childNodes[0]; else obj = null;
	}
	if (obj==null) return;
	if (obj.height > 500)
	{
		k = 500/obj.height;
		obj.width = Math.round(obj.width*k);
		obj.height = 500; //Math.round(obj.height*k);
	}
	image.style.visibility = 'visible';
}
function LoadImg(ind)
{
	if (window.CurrentImageInd == ind) return;
	obj = window.document.getElementById('imageContainer');
	if (obj==null) return;
	obj.innerHTML = "";
	image = window.document.createElement('img');
	image.style.visibility = 'hidden';
	image.onload = onLoadImage;
	//image.width=100;
	//image.height=100;
	image.className="border";
	image.src="/images/gallery/b_"+window.ImgIndex[ind]+"."+window.ImgExt[ind];
	
	obj.appendChild(image);
	window.CurrentImageInd = ind;
	
	obj = window.document.getElementById('pager');
	if (obj!=null)
	{
		for(i=0;i<obj.childNodes.length;i++)
		{
			if (obj.childNodes[i].tagName=='A')
			{
				if (obj.childNodes[i].className=='sel') obj.childNodes[i].className='';
			}
		}
	}
	obj = window.document.getElementById('image'+ind);
	if (obj!=null) obj.className = 'sel';

	obj = window.document.getElementById('prev');
	if (window.CurrentImageInd==0)
	{
		if (obj!=null) obj.className = "disabled";
	}
	else
	{
		if (obj!=null) obj.className = "";
	}
	obj = window.document.getElementById('next');
	if (window.CurrentImageInd==(window.ImgIndex.length-1))
	{
		if (obj!=null) obj.className = "disabled";
	}
	else
	{
		if (obj!=null) obj.className = "";
	}
}
function ImgBack(linkObj)
{
	if (linkObj.className=="disabled") return;
	if (window.CurrentImageInd>0) LoadImg(window.CurrentImageInd-1);
	return false;
}
function ImgForward(linkObj)
{
	if (linkObj.className=="disabled") return;
	if (window.CurrentImageInd<window.ImgIndex.length-1) LoadImg(window.CurrentImageInd+1);
	return false;
}
function ValidateTextField(value,pattern)
{
	re = new RegExp(pattern,"i");
	return value.match(re);
}
function ValidateForm1(frm)
{
	var res = true;
	for (i=0; i <frm.elements.length;i++)
	{
		obj = frm.elements[i];
		if (obj.name!=null)
		{
			if (obj.name=="name") 
			{
				res = ValidateTextField(obj.value,"[a-zа-я]{3,}")==null ? false : true;
				obj.className = res ? "" : "error";
				if (!res) {obj.focus(); return false;}
			}
			if (obj.name=="email") 
			{
				res = ValidateTextField(obj.value,"^[A-Z0-9._%+-]+@[A-Z0-9.-]+\\.[A-Z]{2,4}$")==null ? false : true;
				obj.className = res ? "" : "error";
				if (!res) {obj.focus(); return false;}
			}
			if (obj.name=="question") 
			{
				res = (obj.value=="")? false : true;
				obj.className = res ? "" : "error";
				if (!res) {obj.focus(); return false;}
			}
		}
	}
	
	return res;
}
function ValidateForm2(frm)
{
	var res = true;
	for (i=0; i <frm.elements.length;i++)
	{
		obj = frm.elements[i];
		if (obj.name!=null)
		{
			if (obj.name=="name") 
			{
				res = ValidateTextField(obj.value,"[a-zа-я]{3,}")==null ? false : true;
				obj.className = res ? "" : "error";
				if (!res) {obj.focus(); return false;}
			}
			if ((obj.name=="birth") || (obj.name=="tel") 
				|| (obj.name=="education") || (obj.name=="expirience") || (obj.name=="extinfo"))
			{
				res = (obj.value=="")? false : true;
				obj.className = res ? "" : "error";
				if (!res) {obj.focus(); return false;}
			}
			if (obj.name=="email") 
			{
				res = ValidateTextField(obj.value,"^[A-Z0-9._%+-]+@[A-Z0-9.-]+\\.[A-Z]{2,4}$")==null ? false : true;
				obj.className = res ? "" : "error";
				if (!res) {obj.focus(); return false;}
			}
		}
	}
	
	return res;
}
function ValidateForm3(frm)
{
	var res = true;
	for (i=0; i <frm.elements.length;i++)
	{
		obj = frm.elements[i];
		if (obj.name!=null)
		{
			if (obj.name=="name") 
			{
				res = ValidateTextField(obj.value,"[a-zа-я]{3,}")==null ? false : true;
				obj.className = res ? "" : "error";
				if (!res) {obj.focus(); return false;}
			}
			if ((obj.name=="info") || (obj.name=="question") )
			{
				res = (obj.value=="")? false : true;
				obj.className = res ? "" : "error";
				if (!res) {obj.focus(); return false;}
			}
			if (obj.name=="email") 
			{
				res = ValidateTextField(obj.value,"^[A-Z0-9._%+-]+@[A-Z0-9.-]+\\.[A-Z]{2,4}$")==null ? false : true;
				obj.className = res ? "" : "error";
				if (!res) {obj.focus(); return false;}
			}
		}
	}
	
	return res;
}

function ValidateForm4(frm)
{
	var res = true;
	for (i=0; i <frm.elements.length;i++)
	{
		obj = frm.elements[i];
		if (obj.name!=null)
		{
			if (obj.name=="name") 
			{
				res = ValidateTextField(obj.value,"[a-zа-я]{3,}")==null ? false : true;
				obj.className = res ? "" : "error";
				if (!res) {obj.focus(); return false;}
			}
			if (obj.name=="email") 
			{
				res = ValidateTextField(obj.value,"^[A-Z0-9._%+-]+@[A-Z0-9.-]+\\.[A-Z]{2,4}$")==null ? false : true;
				obj.className = res ? "" : "error";
				if (!res) {obj.focus(); return false;}
			}
			if (obj.name=="question") 
			{
				res = (obj.value=="")? false : true;
				obj.className = res ? "" : "error";
				if (!res) {obj.focus(); return false;}
			}
			if (obj.name=="city") 
			{
				res = (obj.value=="")? false : true;
				obj.className = res ? "" : "error";
				if (!res) {obj.focus(); return false;}
			}
		}
	}
	
	return res;
}
