DOM = (document.getElementById) ? 1 : 0;
NS4 = (document.layers) ? 1 : 0;

var e=function(i){return document.getElementById(i);}

function getOffsetLeft(object)
{
	var value = 0;
	if (DOM){  // Mozilla, Konqueror >= 2.2, Opera >= 5, IE
		value = object.offsetLeft;
		while (object.tagName != 'BODY' && object.offsetParent) {
			object = object.offsetParent;
			value += object.offsetLeft;
		}
	} else if (NS4) {
		value = document.object.pageX;
	} else { // IE4 IS SIMPLY A BASTARD !!!
		value = object.offsetLeft;
		while (object.tagName != 'BODY') {
			object = object.offsetParent;
			value += object.offsetLeft;
		}
	}
	return (value);
}

function getOffsetTop(object)
{
	var value = 0;
	if (DOM) {
		value = object.offsetTop;
		while (object.tagName != 'BODY' && object.offsetParent) {
			object = object.offsetParent;
			value += object.offsetTop;
		}
	} else if (NS4) {
		value = document.object.pageY;
	} else { // IE4 IS SIMPLY A BASTARD !!!
		value = object.offsetTop;
		while (object.tagName != 'BODY') {
			object = object.offsetParent;
			value += object.offsetTop;
		}
	}
	return (value);
}

function isAtMax(e, object, m)
{
    if(object.value.length > m)
	{
        object.value = object.value.substr(0, m);
		alert('Длинна поля должна быть не менее '+m+' символов!');
    }
	var top = getOffsetTop(object);
	var left = getOffsetLeft(object)+object.offsetWidth;
    return overlib(m - object.value.length, WIDTH, 80, CAPTION, 'Symbols left', FIXX, left, FIXY, top);
}

function DisplayDiv(id)
{
	var obj = e(id);
	if (obj.style.display == 'none')
	{
		obj.style.display = '';
	}
	else
	{
		obj.style.display = 'none';
	}
}

function popUp (sURL, sName, x, y, dx, dy) {
	window.open(sURL, sName, 'left='+x+', top='+y+', width='+dx+', height='+dy+', scrollbars=1, resizable=1');
}

function SetValueAndSubmit(form_name,var_name,var_value)
{
    document.forms[form_name].elements[var_name].value=var_value;
    document.forms[form_name].submit();
}

function ShowHelp(message, title)
{
	return overlib(message, CAPTION, title);
}

function ToggleControl(id)
{
	var obj = e(id);
	var obj2 = e(id+'_info');
	if (obj.style.display == 'none')
	{
		obj.style.display = '';
		if (obj2 != null)
		{
			obj2.style.display = 'none';
		}
	}
	else
	{
		obj.style.display = 'none';
		if (obj2 != null)
		{
			obj2.style.display = '';
		}
	}
}

function ShowItem(id)
{
	for (var i = 1; i < 6; i++)
	{
		var obj = e('info'+i);
		var objF = e('first'+i);
		if (obj)
		{
			if(i == id)
			{
				if (obj.style.display == '')
				{
					obj.style.display = 'none';
					objF.style.display = '';
				}
				else
				{
					obj.style.display = '';
					objF.style.display = 'none';
				}
			}
			else
			{
				obj.style.display = 'none'
				objF.style.display = ''
			}
		}
	}
}

function ShowArticle(id, number)
{
	for (var i = 1; i < number+1; i++)
	{
		var obj = e('info'+i);
		var objF = e('first'+i);
		if (obj)
		{
			if(i == id)
			{
				if (obj.style.display == '')
				{
					obj.style.display = 'none';
					objF.style.display = '';
				}
				else
				{
					obj.style.display = '';
					objF.style.display = 'none';
				}
			}
			else
			{
				obj.style.display = 'none'
				objF.style.display = ''
			}
		}
	}
}

function ShowMen(menu, i)
{
	for (var j = 0; j < menu.links.length; j++)
	{
		if (menu.links[j]['link_level'] == 1)
		{
			var obj = e('link_'+menu.links[j].link_id);
			if (obj)
			{
				obj.style.display='none';
			}
		}
	}

	var obj = e('link_'+i.link_id);
	if (obj)
	{
		obj.style.display='';
	}
	return false;
}

function ShowMen2(i)
{
if (!documents.all)
{
  for (var j = 0; j < menu.length; j++)
  {
	 var obj = e('link_'+menu[j].link_id);
	 if (obj)
	 {
		 obj.style.display='none';
	 }
  }
 var obj = e('link_'+i);
 if (obj)
 {
	 obj.style.display='';
 }
 return false;
}
}


function HideMen(menu)
{
	for (var j = 0; j < menu.links.length; j++)
	{
		if (menu.links[j]['link_level'] == 1)
		{
			var obj = e('link_'+menu.links[j].link_id);
			if (obj)
			{
				obj.style.display='none';
			}
		}
	}
	return false;
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function addEvent(obj, evType, fn){
 if (obj.addEventListener){
   obj.addEventListener(evType, fn, false);
   return true;
 } else if (obj.attachEvent){
   var r = obj.attachEvent("on"+evType, fn);
   return r;
 } else {
   return false;
 }
}
function displaystyle(id, display)
{
	var obj = e(id);
	obj.style.display = display;
}
var doCity=function(i,j){
document.search_form.citys.value=i.innerHTML;
document.search_form.city.value=j;
e('citySelectPopup').style.display='none';
}
var doCateg=function(i,j){
document.search_form.categories.value=i.innerHTML;
document.search_form.category.value=j;
e('catSelectPopup').style.display='none';
}

function switchSearchForms(type)
{
	if(type=='job')
	{
	e('search_head_reg').className='';
	e('search_head_reg').blur();
		e('search_head_job').className='red';
		e('search_head_job').blur();
		e('search_head_cv').className='';
//		e('registration_link').href = '/register.jobseeker.html';
		document.search_form.action = '/jobs/list.html';
//		e('block_recr').style.display='none';
//		e('block_jobseek').style.display='';
		e('subnav_menu_cv').style.display='none';
		e('subnav_menu_job').style.display='';
		if(typeof(tsp_asw)!=='undefined'){tsp_asw(0);}
	}
	else
	{
	e('search_head_reg').className='';
	e('search_head_reg').blur();
		e('search_head_job').className='';
		e('search_head_cv').className='red';
		e('search_head_cv').blur();
//		e('registration_link').href = '/register.employer.html';
		document.search_form.action = 'search.cv/results.html';
//		e('block_recr').style.display='';
//		e('block_jobseek').style.display='none';
		e('subnav_menu_cv').style.display='';
		e('subnav_menu_job').style.display='none';
		if(typeof(tsp_asw)!=='undefined'){tsp_asw(1);}
	}
}

function openComments(url){
	window.open(url, "Link", 'width=700,height=400,left=100,top=100,resizable=1,scrollbars=1,menubar=0,status=0');
}
function setHover(el){
el.className='hover';
el.getElementsByTagName('ul')[0].style.width=el.clientWidth+'px';
}
function zoom(url){
    MsgURL=url;
    MsgWinNAME="zoomWin";
    w=650;
    h=500;
    MsgWinParams="width="+w+",height="+h+",status=no,location=no,toolbar=no,resizable=yes,scrollbars=yes,menubar=no";
    var zoomw = window.open(MsgURL,MsgWinNAME,MsgWinParams);
}
function isInt(x) { 
   var y=parseInt(x); 
   if (isNaN(y)) return false; 
   return x==y && x.toString()==y.toString(); 
}
function isFloat(x) { 
   var y=parseFloat(x); 
   if (isNaN(y)) return false; 
   return x==y && x.toString()==y.toString(); 
}
function Ref(){
	window.location=window.location.href;
}
function f(u){
	if(u)document.location.href = u;
}
