var agt = navigator.userAgent.toLowerCase();
var is_ie = (agt.indexOf("msie") != -1);
var is_ie5 = (agt.indexOf("msie 5") != -1);
var is_opera = (agt.indexOf("opera") != -1);
var is_mac = (agt.indexOf("mac") != -1);
var is_gecko = (agt.indexOf("gecko") != -1);
var is_safari = (agt.indexOf("safari") != -1);

function CreateXmlHttpReq(handler) {

var xmlhttp = null;
if (is_ie) {
// Guaranteed to be ie5 or ie6
var control = (is_ie5) ? "Microsoft.XMLHTTP" : "Msxml2.XMLHTTP";

try {
xmlhttp = new ActiveXObject(control);
xmlhttp.onreadystatechange = handler;
} catch (ex) {
// TODO: better help message
alert("You need to enable active scripting and activeX controls");
}

} else {

// Mozilla
xmlhttp = new XMLHttpRequest();
xmlhttp.onload = handler;
xmlhttp.onerror = handler;

}

return xmlhttp;
}

function XmlHttpPOST(xmlhttp, url, data) {
try {
xmlhttp.open("POST", url, true);
xmlhttp.send(data);

} catch (ex) {
}
}

// XMLHttp send GEt request
function XmlHttpGET(xmlhttp, url) {
try {
xmlhttp.open("GET", url, true);
xmlhttp.send(null);

} catch (ex) {
// do nothing
}
}

function parseResponseHeader(key, header) {

var lines = header.split("\n");
var re = new RegExp("^" + key + ":\\s");

for (var i in lines) {
if (re.exec(lines[i])) {
var returnValue = trim(RegExp.rightContext);
return returnValue;
}
}
return "";
}

function trim(value) {
var temp = value;
var obj = /^(\s*)([\W\w]*)(\b\s*$)/;
if (obj.test(temp)) {
temp = temp.replace(obj, '$2');
}
return temp;
}

function getAvailableNames(param) {
 var t_t;
 var atr;
 atr = "";
 qwe = document.s_vacancy.slova.checked;
 if(document.s_vacancy.slova.checked) atr = "`";
 t_t = document.s_vacancy.razdel_input.value;
 if(t_t.length <4) {
	if(t_t.length == 0) {
 		alert('Vous n\'avez pas rempli le champ "Classificateur des professions/des postes"');
 	}else{
 		alert('Dans le champ "Classificateur des professions/des postes" il y a moins de 4 symboles');
 	}
 }else{ 	
 t_t=escape(t_t);
 if(param==0) var url = "popup/razdel/index.php?text="+t_t+"&atr="+atr;
 if(param==1) var url = "popup/razdel/index.php?sr_text="+t_t+"&atr="+atr;
myxmlhttp = CreateXmlHttpReq(CheckAvailXmlHttpHandler);
XmlHttpGET(myxmlhttp, url);

 }
}
function classificator(param) { 
 var url = "popup/razdel/classificator.php?id="+document.s_vacancy.razdel.value+"&param="+param;
myxmlhttp = CreateXmlHttpReq(CheckAvailXmlHttpHandler1);
XmlHttpGET(myxmlhttp, url);
}
function catalogd() { 
 var url = "popup/catalog/index.php?id="+document.cat.catalog.value;
myxmlhttp = CreateXmlHttpReq(CheckAvailXmlHttpHandler);
XmlHttpGET(myxmlhttp, url);
}

function CheckAvailXmlHttpHandler() {
if (myxmlhttp.readyState != 4 || myxmlhttp.status != 200) {
return;
}
var responseHeader = myxmlhttp.getAllResponseHeaders();
var nextIndex = parseResponseHeader("NextIndex", responseHeader);

document.getElementById("raz").innerHTML=myxmlhttp.responseText;

}

function CheckAvailXmlHttpHandler1() {
if (myxmlhttp.readyState != 4 || myxmlhttp.status != 200) {
return;
}
var responseHeader = myxmlhttp.getAllResponseHeaders();
var nextIndex = parseResponseHeader("NextIndex", responseHeader);

document.getElementById("raz1").innerHTML=myxmlhttp.responseText;

}

function reg(elm,reg,forma) {
	var s = '';
	var pole = document.forms[forma].elements[elm];
	var len = pole.value.length;
	var error = 0;
	for(i=0;i<len;i++) {
		if(reg.test(pole.value)) {
			error = 1;
			pole.value = pole.value.substring(0,len - (i+1));
		}
	}
	if(error == 1) {
		alert('Il y a des symboles incorrects. \nFaites attention à la répartition du clavier.');
		pole.focus();
	}
}


function change_rus_eng(elm,reg,forma) {
	symb = new Array();
	
	//Заглавные
	symb[1040] = "F";
	symb[1041] = " ";
	symb[1042] = "D";
	symb[1043] = "U";
	symb[1044] = "L";
	symb[1045] = "T";
	symb[1046] = " ";
	symb[1047] = "P";
	symb[1048] = "B";
	symb[1049] = "Q";
	symb[1050] = "R";
	symb[1051] = "K";
	symb[1052] = "V";
	symb[1053] = "Y";
	symb[1054] = "J";
	symb[1055] = "G";
	symb[1056] = "H";
	symb[1057] = "C";
	symb[1058] = "N";
	symb[1059] = "E";
	symb[1060] = "A";
	symb[1061] = " ";
	symb[1062] = "W";
	symb[1063] = "X";
	symb[1064] = "I";
	symb[1065] = "O";
	symb[1066] = " ";
	symb[1067] = "S";
	symb[1068] = "M";
	symb[168] = "@";
	symb[1070] = " ";
	symb[1071] = "Z";
	
	symb[1072] = "f";
	symb[1073] = " ";
	symb[1074] = "d";
	symb[1075] = "u";
	symb[1076] = "l";
	symb[1077] = "t";
	symb[1078] = " ";
	symb[1079] = "p";
	symb[1080] = "b";
	symb[1081] = "q";
	symb[1082] = "r";
	symb[1083] = "k";
	symb[1084] = "v";
	symb[1085] = "y";
	symb[1086] = "j";
	symb[1087] = "g";
	symb[1088] = "h";
	symb[1089] = "c";
	symb[1090] = "n";
	symb[1091] = "e";
	symb[1092] = "a";
	symb[1093] = " ";
	symb[1094] = "w";
	symb[1095] = "x";
	symb[1096] = "i";
	symb[1097] = "o";
	symb[1098] = " ";
	symb[1099] = "s";
	symb[1100] = "m";
	symb[1101] = " ";
	symb[1102] = ".";
	symb[1103] = "z";
	
	//Знаки пунктуации
	symb[35] = " ";
	symb[36] = " ";
	symb[37] = " ";
	symb[38] = "&";
	symb[39] = " ";
	symb[42] = " ";
	symb[43] = " ";
	symb[46] = ".";
	symb[47] = "/";
	symb[58] = ":";
	symb[59] = " ";
	symb[60] = " ";
	symb[61] = " ";
	symb[62] = " ";
	symb[91] = " ";
	symb[92] = " ";
	symb[93] = " ";
	symb[94] = " ";
	symb[95] = "_";
	symb[96] = " ";
	symb[123] = " ";
	symb[124] = " ";
	symb[125] = " ";
	symb[126] = " ";
	symb[34] = "@";
	
	var pole = document.forms[forma].elements[elm];
	var bro = navigator.appName;


	var len = pole.value.length;
		var error = 0;
		for(i=0;i<len;i++) {
			if(reg.test(pole.value)) {
				error = 1;
				pole.value = pole.value.substring(0,len - (i+1));
			}
		}
		if(error == 1) {
			alert('Il y a des symboles incorrects. \nFaites attention à la répartition du clavier.');
			pole.focus();
		}
	}

function reg_area1(elm,forma,num) {	
	var pole = document.forms[forma].elements[elm];
	var pole_sym = document.forms[forma].elements[elm+'_sym'];
	var len = pole.value.length;
	var num_sym = num - pole.value.length
	pole_sym.value = num_sym;	
	if(num_sym < 0) {			
			pole.value = pole.value.substring(0,num);
			pole_sym.value = '0';
		}
}

function reg_area(elm,reg,forma,num) {
	var s = '';
	var pole = document.forms[forma].elements[elm];
	var pole_sym = document.forms[forma].elements[elm+'_sym'];
	var len = pole.value.length;
	var error = 0;
	var num_sym = num - pole.value.length
	pole_sym.value = num_sym;
	for(i=0;i<len;i++) {
		if(reg.test(pole.value)) {
			error = 1;
			pole.value = pole.value.substring(0,len - (i+1));
		}
	}
	if(num_sym < 0) {
			pole.value = pole.value.substring(0,num);
			pole_sym.value = '0';
		}
	if(error == 1) {
		alert('Il y a des symboles incorrects. \nFaites attention à la répartition du clavier.');
		pole.focus();
	}
}
function null_str(elm,forma,name) {
	var pole = document.forms[forma].elements[elm];
	if(pole.value == '') {
		alert('Vous n\'avez pas rempli le champ'+name);
		pole.focus();
	}
	if(pole.value.length < 4 && pole.value != '') {
		alert('Vous avez entré moins de 4 symboles dans le champ '+name);
		pole.focus();
	}
}

function submit_form(forma) {
	
	if(forma == "s_vacancy") {
		var er = 0;
		var pole = document.forms['s_vacancy'].elements['razdel_input'];
		if(pole.value.length == 0) {
			var er = 1;
			alert('Vous n\'avez pas rempli le champ "Classificateur des professions/des postes');
			pole.focus();
		}
		if(pole.value.length < 4 && pole.value.length > 0 && er == 0) {
			var er = 1;
			alert('Dans le champ "Classificateur des professions/des postes" il y a moins de 4 symboles');
			pole.focus();
		}
		
	}
}
function check1(obj)
{
	tr1 = window.parent.document.getElementById(obj);
	if(tr1.className=="TABLE_nv")
	tr1.className="TABLE_v";
	else
	tr1.className="TABLE_nv";
}


function profs(i){	
	document.s_vacancy.prof_i.value=i;
}
function ans(text)
{
if(confirm(text)) return true
else return false;
}
function ansb(text,forma)
{
if(confirm(text)){
	document.forms[forma].check.value=1;
	document.forms[forma].submit();	
}
else return false;
}

function AllChecked(check){
	var len = document.forms['s_vacancy'].elements.length;
	for( var i=0; i < len-2; i++ ) {
		var chbox = document.s_vacancy.elements[i];
		if( chbox.type == "checkbox" && chbox.id!="slovo" && chbox.id!="full" && chbox.name!="convert_currency" && chbox.id!="seen_photo")	chbox.checked = check;		
	}
}

function popup_region() {
 window.open("popup/region/index.php?zahod=0","","channel mode=0,toolbar=0,location=0,menubar=0,status=0,height=500,width=400,scrollbars=1,top=150,left=150");
}
function write_mail(param1,param2) {
 window.open("popup/mail/index.php?to="+param1+"&mail="+param2,"","channel mode=0,toolbar=0,location=0,menubar=0,status=0,height=500,width=420,scrollbars=1,top=150,left=150");
}
function write_mail1(param1) {	
	str="";
	len = document.forms['search'].elements.length;
	for(i=0;i<len;i++){
		s = document.forms['search'].elements[i];		
		if( s.name == "pid[]" && s.checked==true)	str+="&pid[]="+s.value;				
	}	
 window.open("popup/mail/index.php?to="+param1+str,"","channel mode=0,toolbar=0,location=0,menubar=0,status=0,height=500,width=420,scrollbars=1,top=150,left=150");
}
function popup_region1() {
 window.open("popup/region1/index.php?zahod=0","","channel mode=0,toolbar=0,location=0,menubar=0,status=0,height=500,width=400,scrollbars=1,top=150,left=150");
}
function popup_region_agency() {
 window.open("popup/region_agency/index.php?zahod=0","","channel mode=0,toolbar=0,location=0,menubar=0,status=0,height=500,width=400,scrollbars=1,top=150,left=150");
}

function AddOpt(vtext,vvalue) {
// Добавляет Ooption выбранного в дочернем окне
 flink=document.forms.s_vacancy.elements.select_razdel;
 flen=flink.length;
 fcount=flen-1;
 document.forms.s_vacancy.elements.select_razdel[fcount].selected=true;
 flink.options[fcount].text=vtext;
 flink.options[fcount].value=vvalue;
 flink.options[fcount+1].text='';
 flink.options[fcount+1].value='';
}

function AddOpt1(vtext,vvalue) {
 document.forms.s_vacancy.elements.f_region.value=vtext;
 document.forms.s_vacancy.elements.f_region.size=vtext.length;
 document.forms.s_vacancy.elements.select_region.value=vvalue;
}
function AddOpt2(vtext,vvalue) {
 document.forms.fast.f_region.options[0].text=vtext;
 document.forms.fast.elements.select_region.value=vvalue;
}
function ShowHelp(atr2) {
window.open("help/index.php?f="+atr2,"","toolbar=0,location=0,menubar=0,status=0,height=400,width=400,scrollbars=1,top=150,left=150");
}


function print_resume(pid) {	
	window.open("module/center/search_resume/print.php?pid="+pid,"","top=10,left=100,width=700,height=1000,toolbar=0,scrollbars=1,menubar=0,location=0,status=0,resizeable=0");		
}
function print_vacancy(pid) {	
	window.open("module/center/search_vacancy/print.php?pid="+pid,"","top=10,left=100,width=700,height=1000,toolbar=0,scrollbars=1,menubar=0,location=0,status=0,resizeable=0");		
}
function add_prof() {	
	window.open("popup/razdel/add_new_prof.php","","top=10,left=100,width=400,height=400,toolbar=0,scrollbars=0,menubar=0,location=0,status=0,resizeable=0");		
}

	
	function regp(elm,forma,num)
{    zapr = new Array();
    var s = '';
	var pole = document.forms[forma].elements[elm];
	var pole_sym = document.forms[forma].elements[elm+'_sym'];
	var len = pole.value.length;
	var error = 0;
	var str,result;
	
	var num_sym = num - pole.value.length
	pole_sym.value = num_sym;
	  str=pole.value;
      re=new RegExp ("\\%|{|}|<|>|\\?|\\*","i");
      if (result=str.match(re))

	  {
	  	pole.value = pole.value.substring(0,pole.value.length-1);
	  	alert("symbole interdit");
	  }
	
    if(num_sym < 0) {
			//pole.value = pole.value.substring(0,len - (num - num_sym));
			pole.value = pole.value.substring(0,num);
			pole_sym.value = '0';
			alert("Le nombre de symboles est dépassé")
		}
}