// JavaScript Document
var val;
var req;


function sub_form(str)
{
	var answer = confirm(str);	
	return answer;
}

/*function dd()
{
		var answer = confirm("Ištrinti darbo skelbimd?");
	if (answer){
				window.location.href = "http://www.google.lt";
	}
		
		//history.go('www.google.com');

//alert('dfdf');
}*/


	/*function check_date(frm)
	{
		var gg = frm;
		var Arr = gg.elements;
		var Mass = new Array();
		var answ = true;
		
		var thedate = new Date( );
		var theyear = thedate.getFullYear();
		//var themonth = thedate.getMonth( ) + 1;
		//var theday = thedate.getDate( );
		var curr_y = theyear - 18;
		
		for (var i=0;i<Arr.length;i++)
		{
			
			if (Arr[i].name == "birth_year")
				Mass[Arr[i].name] = Arr[i].value;
			if (Arr[i].name == "birth_month")
				Mass[Arr[i].name] = Arr[i].value;
			if (Arr[i].name == "birth_day")
				Mass[Arr[i].name] = Arr[i].value;
									
		}
		
			if (Mass['birth_year'] == curr_y && Mass['birth_month'] == "Sausio" && Mass['birth_day'] == "1")
			{			
				var answer = confirm("Ar tikrai Jūsų gimimo data:"+curr_y+" "+"Sausio 1 d.?");
			
				if (answer)
				{
					answ = true;
				
				}
				else
				{
					answ = false;
					
				}
			
			}
			
			return answ
												
	}*/
	
		function pop_game()
		{
				
						
			var img = document.getElementById("show_game");			
			
			img.style.display = 'block';
						
			
		}
	
	
		function check_f()
		{
			var name = document.getElementById('name');
			var comment = document.getElementById('comment');
			var tr = true;
			var er = '';
			
			if (trimAll(comment.value) == '')
			{
				er = er + 'Įrašykite atsiliepimą!\n';
				tr = false;
			}
				
			if (trimAll(name.value) == '')
			{
				er = er + 'Įrašykite vardą!\n';
				tr = false;
			}
			
			
		
			if (tr == false)			
				alert(er);
							
		return tr;
		
		
		}
	
	
	function check_date(frm)
	{
		var gg = frm;
		var Arr = gg.elements;
		var Mass = new Array();
		var answ = true;
						
		for (var i=0;i<Arr.length;i++)
		{
			
			if (Arr[i].name == "birth_year")
				Mass[Arr[i].name] = Arr[i].value;
			if (Arr[i].name == "birth_month")
				Mass[Arr[i].name] = Arr[i].value;
			if (Arr[i].name == "birth_day")
				Mass[Arr[i].name] = Arr[i].value;
									
		}
					
			if (Mass['birth_year'] == "0" || Mass['birth_month'] == "0" || Mass['birth_day'] == "0")
			{								
				answ = false;
				alert("Užpildykite lauką: Gimimo data*");
			
			}
						
			return answ
												
	}	
	
	/*

function save(guid)
{
	alert(guid);	
	
	
}*/

		function alertBox(alertMessage,height,width)
        {
          // This stuff centers the window
         	windowWidth = (width == null) ? 200 : width; // width of the new window
         	windowHeight = (height == null) ? 30 : height; // height of the new window
         	windowLeft = (screen.width / 2) - (windowWidth / 2); // center the window right to left
         	windowTop = (screen.height / 2) - (windowHeight / 2); // center the window top to bottom
         
          	// the values get inserted into the features parameter of the window.open command...
          	var windowLocation = "top=" + windowTop + ",left=" + windowLeft + ",height=" + windowHeight + ",width=" + windowWidth;
          	alertWindow = window.open("","alertWindow",windowLocation);
          	alertWindow.document.write("<html><head><title>Alert!</title><link rel='stylesheet' type='text/css' href='../styles/main.css'></head><body bgcolor='#EBF0F1'>");
          	alertWindow.document.write("<div style='font-size:14px;color:red' align='center'><b>" + alertMessage +  "</b><br><br>");
          	alertWindow.document.write("<form><table align='center'><tr><td><input class='lreg-btn'  type='button' value=' Uždaryti ' onclick='window.close()'></td><td > <input type='button' class='lreg-btn' onClick=\"window.close();window.open('../index.php?empl=61','_blank','fullscreen =yes,location=yes,menubar=yes,resizable=yes,scrollbars=yes,toolbar=yes');\" value='Prisijungti'></td></tr></table></form>");
          	alertWindow.document.write("</div></body></html>");
        }


		function alertBoxKonf(alertMessage,height,width)
        {
          // This stuff centers the window
         	windowWidth = (width == null) ? 200 : width; // width of the new window
         	windowHeight = (height == null) ? 30 : height; // height of the new window
         	windowLeft = (screen.width / 2) - (windowWidth / 2); // center the window right to left
         	windowTop = (screen.height / 2) - (windowHeight / 2); // center the window top to bottom
         
          	// the values get inserted into the features parameter of the window.open command...
          	var windowLocation = "top=" + windowTop + ",left=" + windowLeft + ",height=" + windowHeight + ",width=" + windowWidth;
          	alertWindow = window.open("","alertWindow",windowLocation);
          	alertWindow.document.write("<html><head><title>Alert!</title><link rel='stylesheet' type='text/css' href='../styles/main.css'></head><body bgcolor='#EBF0F1'>");
          	alertWindow.document.write("<div style='font-size:14px;color:red' align='center'><b>" + alertMessage +  "</b><br><br>");
          	alertWindow.document.write("<form><table align='center'><tr><td><input class='lreg-btn'  type='button' value=' Uždaryti ' onclick='window.close()'></td></tr></table></form>");
          	alertWindow.document.write("</div></body></html>");
        }
		
		function alertBoxUser(alertMessage,height,width)
        {
          // This stuff centers the window
         	windowWidth = (width == null) ? 200 : width; // width of the new window
         	windowHeight = (height == null) ? 30 : height; // height of the new window
         	windowLeft = (screen.width / 2) - (windowWidth / 2); // center the window right to left
         	windowTop = (screen.height / 2) - (windowHeight / 2); // center the window top to bottom
         
          	// the values get inserted into the features parameter of the window.open command...
          	var windowLocation = "top=" + windowTop + ",left=" + windowLeft + ",height=" + windowHeight + ",width=" + windowWidth;
          	alertWindow = window.open("","alertWindow",windowLocation);
          	alertWindow.document.write("<html><head><title>Alert!</title><link rel='stylesheet' type='text/css' href='../styles/main.css'></head><body bgcolor='#EBF0F1'>");
          	alertWindow.document.write("<div style='font-size:14px;color:red' align='center'><b>" + alertMessage +  "</b><br><br>");
          	alertWindow.document.write("<form><table align='center'><tr><td><input class='lreg-btn'  type='button' value=' Uždaryti ' onclick='window.close()'></td><td > <input type='button' class='lreg-btn' onClick=\"window.close();window.open('http://www.naujasdarbas.lt/index.php?current=56','_blank','fullscreen =yes,location=yes,menubar=yes,resizable=yes,scrollbars=yes,toolbar=yes');\" value='Registruotis'></td></tr></table></form>");
          	alertWindow.document.write("</div></body></html>");
        }

		function alertBoxNoPas(alertMessage,height,width)
        {
          // This stuff centers the window
         	windowWidth = (width == null) ? 200 : width; // width of the new window
         	windowHeight = (height == null) ? 30 : height; // height of the new window
         	windowLeft = (screen.width / 2) - (windowWidth / 2); // center the window right to left
         	windowTop = (screen.height / 2) - (windowHeight / 2); // center the window top to bottom
         
          	// the values get inserted into the features parameter of the window.open command...
          	var windowLocation = "top=" + windowTop + ",left=" + windowLeft + ",height=" + windowHeight + ",width=" + windowWidth;
          	alertWindow = window.open("","alertWindow",windowLocation);
          	alertWindow.document.write("<html><head><title>Alert!</title><link rel='stylesheet' type='text/css' href='../styles/main.css'></head><body bgcolor='#EBF0F1'>");
          	alertWindow.document.write("<div style='font-size:14px;color:red' align='center'><b>" + alertMessage +  "</b><br><br>");
          	alertWindow.document.write("<form><table align='center'><tr><td><input class='lreg-btn'  type='button' value=' Uždaryti ' onclick='window.close()'></td><td > <input type='button' class='lreg-btn' onClick=\"window.close();window.open('../index.php?empl=55&job_new','_blank','fullscreen =yes,location=yes,menubar=yes,resizable=yes,scrollbars=yes,toolbar=yes');\" value='Užsisakyti paslaugą'></td></tr></table></form>");
          	alertWindow.document.write("</div></body></html>");
        }












function accepts(str,text)
{
	
				
		var answer = confirm(text);
	if (answer){
		
		window.location.href = str;
			
		
	}

	
	
}

function in_array(needle, haystack,values)
{
	var found = false;
	var i;
	
	for (i=0;i<haystack.length;i++)
	{
		if (needle == haystack[i]) 
		{
			val = values[i];
			found = true;
		}
		
	}
	
	
	return found;
}

	
	function trimAll(sString) 
	{
		while (sString.substring(0,1) == ' ')
		{
			sString = sString.substring(1, sString.length);
		}
		while (sString.substring(sString.length-1, sString.length) == ' ')
		{
			sString = sString.substring(0,sString.length-1);
		}
			return sString;
	}
	
	
	function check(frm)
	{
		//alert(frm.id);
		var gg = frm;		
		var Arr = gg.elements;
		var oChk = true;
		var input = new Array();
		var out = new Array();
		var radio_choice = false;
		var mes = null;
		
		var errors = '';
		
		input[0]="password";
		//input[1]="email";
		input[2]="surname";
		input[3]="name";
		input[4]="birth_date";
		input[13]= "sex";
		input[6]="w_job[]";
		input[7]="w_place[]";
		input[8]="title";
		input[9]="status";
		input[10]="code";
		input[11] = "username";
		input[12] = "emp_name";
		input[14] = "mobile";
		input[15] = "w_place"
		input[16] = "wp_area";
		input[17] = "occupation";
		//input[15] = "phone";
		//input[16] = "fax"
		
		out[0] ="Slaptažodis";
		//out[1] = "El. paštas";
		out[2] = "Pavardė";
		out[3] = "Vardas";
		out[4] = "Gimimo data";
		out[13] = "Lytis";
		out[6] = "Veiklos sritis";
		out[7] = "Vieta";
		out[8] = "CV pavadinimas";
		out[9] = "CV statusas"; 
		out[10] = "Įmonės kodas";
		out[11] = "Vartotojo vardas";
		out[12] = "Įmonės pavadinimas";
		out[14] = "Mobilus";
		out[15] = "Darbovietės pavadinimas";
		out[16] = "Darbovietės veiklos sritis arba ūkio šaka";
		out[17] = "Pareigos";
		//out[15] = "Telefonas";
		//out[16] = "Faksas";
		
		for (var i=0;i<Arr.length;i++)
		{
						
			if (Arr[i].value != '' )
			{
				if ((Arr[i].type != 'submit') && (Arr[i].type != 'button') && (Arr[i].type != 'radio') )
				{
					myvalu = new String(Arr[i].value);
												
					myVal = new RegExp("[<>'\"]+", "i");
												//\'\*|\<\*|\>\*
					if (myVal.test(myvalu) == true)
					{										
						if (errors.indexOf("Uždrausti simboliai: < > ' \"\n") == -1)
							errors += "Uždrausti simboliai: < > ' \"\n";
						oChk = false;
					}
						
				}
			}
				
			if (trimAll(Arr[i].value) == "" && frm.id !== "user_info" && frm.id !== "empl_info" && in_array(Arr[i].name,input,out) == true )
			{							
				//alert(Arr[i].name);	
				
				if (Arr[i].name == "occupation")
				{
					//var occ = document.getElementById('new_occ').value;					
					
					var occ = frm.elements['new_occ'].value;
					
					/*if (trimAll(occ) != '' )
					{
						alert(occ);
						oChksss = true;
					
					
					}
					else*/
					if(trimAll(occ) == '')
					{
						if (errors.indexOf("Užpildykite lauką: " + val + "\n") == -1)
							errors += "Užpildykite lauką: "+ val + "\n";
						
						oChk = false;
					}
				
					//alert(oChk);
				}
				else
				{
					//alert('zzzz');
					
					if (errors.indexOf("Užpildykite lauką: " + val + "\n") == -1)
					errors += "Užpildykite lauką: "+ val + "\n";
					
					oChk = false;
				}
			
				//alert(oChk);
			
			}
					
			if (Arr[i].name == "email" && in_array(Arr[i].name,input,out) == true)
			{						
				mymail = new String(Arr[i].value);
											
				myRE = new RegExp("^.+\@.+\\..{2,4}$", "i");
												
				if (myRE.test(mymail) == false)
				{
					if (errors.indexOf("Blogas paštas: " + mymail + "\n") == -1)
						errors += "Blogas paštas: " + mymail + "\n";
					oChk = false;
				}
						
			}
		
			if (Arr[i].name == "password" && frm.id !== "user_info" && frm.id !== "empl_info" && in_array(Arr[i].name,input,out) == true)
			{
				mypass = new String(Arr[i].value);
																	
				myReps = new RegExp(".{6}", "");
							
				if (myReps.test(mypass) == false)
				{
					if (errors.indexOf("Blogas slaptažodis (minimum 6 simboliai)\n") == -1)
						errors += "Blogas slaptažodis (minimum 6 simboliai)\n";
					
					//alert("Blogas slaptažodis (minimum 6 simboliai)");
					oChk = false;
				}
										
			}
		
			if (Arr[i].name == "code" && in_array(Arr[i].name,input,out) == true)
			{
				mycode = new String(Arr[i].value);
																	
				myReco = new RegExp("^[0-9]+$", "");
							
				if (myReco.test(mycode) == false)
				{
					if (errors.indexOf("Blogas įmonės kodas: " + mycode + "\n") == -1)
						errors += "Blogas įmonės kodas: " + mycode + "\n";
					oChk = false;
				}
										
			}
			
			if ((Arr[i].name == "mobile") && in_array(Arr[i].name, input, out) == true) {
				str = new String(Arr[i].value);
				
				if (str.indexOf('+') !== 0 || str.charAt(4)!==' ' || str.charAt(8)!==' ' || str.substr(1, 3)!=370 || !isNumeric(str.substr(5, 3)) || !isNumeric(str.substr(9, 5))) {
					if (errors.indexOf('Netinkamai įvestas mobilaus telefono numeris!\n  (Formatas: +370 6xx xxxxx.)\n') == -1)
						errors += 'Netinkamai įvestas mobilaus telefono numeris!\n  (Formatas: +370 6xx xxxxx.)\n';
					oChk = false;
				}			
			}
		} // for
		
		if (frm.name == 'cv_form3') {
			var fcount = 0;
			var tcount = 0;
		
			var fyear = frm.elements['fyear'].value;
			var fmonth = frm.elements['fmonth'].value;
			//var fday = frm.elements['fday'].value;
			
			if (fyear == '')
				fcount++;
			
			if (fmonth == '')
				fcount++;
			/*
			if (fday == '')
				fcount++;
			*/
		
			if (fcount > 0)
			{
				errors += "Blogai užpildyta data! Nuo:\n";		
				oChk = false;
			}
		
			var tyear = frm.elements['tyear'].value;
			var tmonth = frm.elements['tmonth'].value;
			//var tday = frm.elements['tday'].value;
		
			if (tyear.length == 0)
				tcount++;
			if (tmonth.length == 0)
				tcount++;
			/*
			if (tday.length == 0)
				tcount++;
			*/
			
			if (tcount < 2 && tcount > 0)
			{
				errors += "Blogai užpildyta data! Iki:\n";		
				oChk = false;
			}		
		
		}		
		
		if (errors.length > 0)
		{
			alert(errors);
		}
		else
		{
			/*if ((frm.name == 'cv_form3' || frm.id == 'cv_form7a' ) && !window.opener)
			{
				fin = window.location.href.split("&");				
				
				if (frm.name == 'cv_form3')
				{
					var un = encodeURIComponent(frm.elements['w_place'].value);
				}
				else
				{
					var un = encodeURIComponent(frm.elements['company'].value);
					//alert(un);
				}
				
				if (un == '')
				{
					frm.action="index.php?current=25";
					frm.submit();
				}
				else
				{
					window.open('users/comp.php?comp='+un+'&'+fin[1]+'&form='+frm.id,'_blank','width=500,height=400,menubar=no,resizable=no,scrollbars=yes,toolbar=no,top=100,left=200');
				}
			
			}*/
		}
		
		//var un = frm.elements['w_place'].value;
		//window.open('users/comp.php?comp='+un,'_blank','width=500,height=400,menubar=no,resizable=no,scrollbars=yes,toolbar=no,top=100,left=200');
		
		return oChk;
	} // check
	
	function isNumeric(strString) {
		var strValidChars = "0123456789";
		var strChar;
		var blnResult = true;

		if (strString.length == 0)
			return false;	
		for (i = 0; i < strString.length && blnResult == true; i++) {
			strChar = strString.charAt(i);
			if (strValidChars.indexOf(strChar) == -1) {
				blnResult = false;
			}
		}
		return blnResult;
	} // isNumeric



	function getCv(pvd)
	{
		window.open('reports/'+pvd,'_blank', 'width=820,height=600,menubar=no,resizable=yes,scrollbars=yes,toolbar=no,top=100,left=100');

	}

	function getCvf(un)
	{
		window.open('http://www.naujasdarbas.lt/reports/cv_fin.php?cvs='+un,'_blank', 'width=870,height=600,menubar=no,resizable=yes,scrollbars=yes,toolbar=no,top=100,left=100');

	}
	
	function getJob(jb)
	{
		window.open('reports/generate_job.php?j_job='+jb,'_blank', 'width=850,height=600,menubar=no,resizable=yes,scrollbars=yes,toolbar=no,top=100,left=100');
	}

	function print_window(guid)
	{
		var langas = window.open('generate_cv.php?cvs='+guid,'_blank','width=800,height=600,menubar=yes,resizable=yes,scrollbars=yes,toolbar=no,top=100,left=100');
				
			//langas.setTimeout("window.print()",3000);
			if (navigator.appName == "Netscape")
				langas.setTimeout("window.print()",3000);
			else
				langas.print();
			
			
			//alert(navigator.appName);
	}
	
	
	
	
	
	var id;
	
	function updateObj(obj, data)
	{
  		document.getElementById(obj).innerHTML = data;
	}
	
		
	function get_search()
	{
		if(req.readyState == 4)
		{
   			if(req.status == 200)
			{
     			 out = req.responseText;
      			 updateObj(id,out);  
		
			} 
			else 
			{
     			 alert("AJAX klaida\n" + req.statusText);
    		}
 		}
	
	}

	function loadsearch(url,nr)
	{
     	id = nr;
 		if(window.XMLHttpRequest)
  		{
    		req = new XMLHttpRequest();
    		req.onreadystatechange = get_search;
   			req.open("GET", url, true);
    		req.send(null);
 		} 
 		else if(window.ActiveXObject)
  		{
    		req = new ActiveXObject("Microsoft.XMLHTTP");
  
			if(req)
			{
     	 
				req.onreadystatechange = get_search;
     			req.open("GET", url, true);
     			req.send();
			}
 		}
	}
	
	
	// send req
	
	function alertdata(data)
	{
  		alert(data);
	}
	
		
	function get_req()
	{
		if(req.readyState == 4)
		{
   			if(req.status == 200)
			{
     			 out = req.responseText;
      			 alertdata(out);  
		
			} 
			else 
			{
     			 alert("AJAX klaida\n" + req.statusText);
    		}
 		}
	
	}

	function sendreq(url)
	{
     	
 		if(window.XMLHttpRequest)
  		{
    		req = new XMLHttpRequest();
    		req.onreadystatechange = get_req;
   			req.open("GET", url, true);
    		req.send(null);
 		} 
 		else if(window.ActiveXObject)
  		{
    		req = new ActiveXObject("Microsoft.XMLHTTP");
  
			if(req)
			{
     	 
				req.onreadystatechange = get_req;
     			req.open("GET", url, true);
     			req.send();
			}
 		}
	}



	function save_out()
	{
		if(req.readyState == 4)
		{
   			if(req.status == 200)
			{
     			
      			
				alert('CV išsaugotas!');  
		
			} 
			else
			{
     			 alert("AJAX klaida\n" + req.statusText);
    		}
 		}
	
	}
		
	
	function save_cv(url)
	{
     	
 		if(window.XMLHttpRequest)
  		{
    		req = new XMLHttpRequest();
    		req.onreadystatechange = save_out;
   			req.open("GET", url, true);
    		req.send(null);
 		} 
 		else if(window.ActiveXObject)
  		{
    		req = new ActiveXObject("Microsoft.XMLHTTP");
  
			if(req)
			{     	 
				req.onreadystatechange = save_out;
     			req.open("GET", url, true);
     			req.send();
			}
 		}
	}
		
/*

function change(vis,id)
{
	
		
	switch(vis)
	{
		
		case 'hidden': 
						
		document.getElementById(id).style.visibility= "hidden" ;
		break;
		
		case 'visible':
		
		document.getElementById(id).style.visibility= "visible";
		//curr.style.visibility= "visible" ;
		//document.all[id].style.visibility= "visible" ;
		document.getElementById('dsid').select();
		
		break;
	}
}
*/
function out()
{
			
		var zz = window.setInterval(alert(),1000);
	
}

// -------------------------------------------------------------------------------------
	
	function change_state ($id) {
		document.getElementById($id).disabled = !document.getElementById($id).disabled;
	}
	
	
	function setExp ($sel_id, $t_id) {
		if (document.getElementById($sel_id).disabled)
			document.getElementById($t_id).value = '';
		 else if (document.getElementById($sel_id).value !== 'empty')
			document.getElementById($t_id).value = new Date().getFullYear()-document.getElementById($sel_id).value;
		 else document.getElementById($t_id).value = '';
	}
	
	/*function capitalize(obj) {
		if ((obj.name == 'name' || obj.name == 'surname') && !document.getElementById('cv_form7a'))
			return obj.value.charAt(0).toUpperCase() + obj.value.substr(1).toLowerCase();
			
		 else if (obj.name == 'post' || obj.name == 'title') {
			capitalLetters = 'AĄBCDEĘĖFGHIĮJKLMNOPQRSŠTUVWXYZŽ';
			strArr = obj.value.split(' ');
			
			for (k=0; k<strArr.length; k++) {
				var allCapitalLetters = true;
				
				for (l=0; l<strArr[k].length; l++) {
					if (capitalLetters.indexOf(strArr[k].charAt(l)) == -1) {
						allCapitalLetters = false;
						break;
					}					
				}
				if (allCapitalLetters)
					strArr[k] = strArr[k].charAt(0).toUpperCase() + strArr[k].substr(1).toLowerCase();
			} // for
			return strArr.join(' ');
		 }
		 else return obj.value;
	} */
	
	function capitalize(obj) {
		var z = 0;
		if ((obj.name == 'name' || obj.name == 'surname') && !document.getElementById('cv_form7a'))
			return obj.value.charAt(0).toUpperCase() + obj.value.substr(1).toLowerCase();
			
		 else if (obj.name == 'post' || obj.name == 'title') {
			capitalLetters = 'AĄBCDEĘĖFGHIĮJKLMNOPQRSŠTUVWXYZŽ';
			strArr = obj.value.split(' ');
			
			for (k=0; k<strArr.length; k++) {
				var allCapitalLetters = true;
				
				for (l=0; l<strArr[k].length; l++) {
					if (capitalLetters.indexOf(strArr[k].charAt(l)) == -1) {
						allCapitalLetters = false;
						break;
					}					
				}
				if (allCapitalLetters)
				{					
						z= z+1;
						if (z == 1)
							strArr[k] = strArr[k].charAt(0).toUpperCase() + strArr[k].substr(1).toLowerCase();
						else
							strArr[k] = strArr[k].charAt(0).toLowerCase() + strArr[k].substr(1).toLowerCase();					
				}
				else
				{
					strArr[k] = strArr[k].charAt(0).toUpperCase() + strArr[k].substr(1);
					break;
				}
				
			
			} // for
			return strArr.join(' ');
		 }
		 else return obj.value;
	}
	
	
	function check_edu_type(form) {
		form = "cv_form4";
		if (document.forms[form].type.value == "Aukštasis universitetinis")
			document.forms[form].degree.disabled = false;
		 else document.forms[form].degree.disabled = true;
		 
		if ((document.forms[form].type.value == "Pagrindinis") || (document.forms[form].type.value == "Vidurinis"))
			document.forms[form].qualification.disabled = true;
		 else document.forms[form].qualification.disabled = false;
	}
	
	function change_date_state(form) {
		if (form == "cv_form4")
			document.forms[form].s_to.disabled = !document.forms[form].s_to.disabled;
		 else {
			document.forms[form].tyear.disabled = !document.forms[form].tyear.disabled;
			document.forms[form].tmonth.disabled = !document.forms[form].tmonth.disabled;
			//document.forms[form].tday.disabled = !document.forms[form].tday.disabled;
		}
	}
	
	function changeDay(monthObj, dayID, sel_name) {
		if (isIn30months (monthObj.value))
			document.getElementById(dayID).innerHTML = getDays(sel_name, 30);
		else if (monthObj.value == 'Vasario')
			document.getElementById(dayID).innerHTML = getDays(sel_name, 29);
		else
			document.getElementById(dayID).innerHTML = getDays(sel_name, 31);
	} // changeDay
	
	function isIn30months (mnth) {
		months = new Array("Balandžio", "Birželio", "Rugsėjo", "Lapkričio");
		for (i=0; i<months.length; i++) {
			if (months[i] === mnth)
				return true;
		}
		return false;
	} // isIn30Months
	
	function getDays(sel_name, count) {
		
		
		var url = window.location.href.indexOf("current=6");
		var url_edit = window.location.href.indexOf("current=31");
				
			str = "<select name='" + sel_name + "'>";
		
		if (url != -1 || url_edit != -1)
			str +="<option value=''></option>";
		
		for (i=0; i<count; i++)
			str +="<option value='"+ (i+1) +"'>" + (i+1) + "</option>";
		return str += "</select>";
	} // getDays
	
	function check_jdesign	(rid) {
		document.getElementById(rid).checked = true;
	}
	
	function correctPhone (obj) {
		if (obj.name == 'phone') {
			 if (checkNumbers(obj.value)) {
				if (obj.value.charAt(0).toString() !== '+') {
					if (obj.value.charAt(0) == 8)
						obj.value = '+370 ' + obj.value.substr(1);
					else
						obj.value = '+370 ' + obj.value;
					alert ('Neteisingas telefono numerio formatas!\nFormatas turi atitikti tarptautinį standartą (+370...)');
				}
			} else alert('Įvedėte netinkamus simbolius telefono nr. laukelyje!');
		}
	} // correctPhone
	
	function checkNumbers (str) {
		arr = new Array('0','1','2','3','4','5','6','9','8','9','+');
		for (i=0; i<str.length; i++) {
			if (in_array(str.charAt(i), arr, arr));
			else return false;
		}
		return true;
	} // checkNumbers
	
// ---------------------------------------------------------------------------------------------------
	
	function getMonthIndex(month) {
		months = new Array('Sausio', 'Vasario', 'Kovo', 'Balandžio', 'Gegužės', 'Birželio', 'Liepos', 'Rugpjūčio', 'Rugsėjo', 'Spalio', 'Lapkričio', 'Gruodžio');
		for (i=0; i<months.length; i++)
			if (months[i] == month)
				return i;
		return 404;
	} // getMonthIndex
	
	// -------------- nereikes -----------------
	function getExpDays(sel_name, count) {
		str = "<select name='" + sel_name + "' id='" + sel_name + "'>";
		for (i=count; i>0; i--)
			str +="<option value='"+ i +"'>" + i + "</option>";
		return str += "</select>";
	} // getDays
	
	function changeExpYear(expYear, expMonth) {
		yearDiv = document.getElementById('year');
		
		selMonth = document.forms['job_publish'].elements['exp_month'].value;
		mIndex = getMonthIndex(selMonth);
		
		if (mIndex != 404) {
			if (expMonth == 0 && mIndex != 0) {
				expYear--;
				yearDiv.innerHTML="<select><option value='" + expYear + "'>" + expYear + "</option></select>";
			}
		}
		//alert(expYear);
		//alert(expMonth);
		
	} // changeExpYear
	
	function changeExpDay(expMonth, expDay) {
		dayDiv = document.getElementById('day');
		
		selMonth = document.forms['job_publish'].elements['exp_month'].value;
		mIndex = getMonthIndex(selMonth);
		
		if (mIndex != 404) {
			if (mIndex != expMonth) {
				if (isIn30months (selMonth))
					dayDiv.innerHTML = getExpDays('exp_day', 30);
				else if (selMonth == 'Vasario')
					dayDiv.innerHTML = getExpDays('exp_day', 28);
				else
					dayDiv.innerHTML = getExpDays('exp_day', 31);
			} else
				dayDiv.innerHTML = getExpDays('exp_day', expDay);
		}
		
	} // changeExpDay
	// -------------- nereikes[end] -----------------
	
	function markCvFormMenu() {
		var currentValues = new Array(4, 5, 23, 24, 6, 7, 8, 34, 9, 27, 10, 25, 15, 14);
		
		var currentURL = window.location.href;
		
		var currPos = currentURL.indexOf('current=');
		
		//alert(currentURL.substr(currPos + 'current='.length, 1));
		//alert(currentURL.substr(currPos + 'current='.length, 2));
		
		if (currPos != -1) {
			if (inArray(currentValues, currentURL.substr(currPos + 'current='.length, 1)) && 
				!iSNumeric(currentURL.substr(currPos + 'current='.length+1, 1)))
			{
				markLink('current=', currentURL.substr(currPos + 'current='.length, 1));
			} 
			else if (inArray(currentValues, currentURL.substr(currPos + 'current='.length, 2)))
			{
				//alert(currentURL.substr(currPos + 'current='.length, 2));
				markLink('current=', currentURL.substr(currPos + 'current='.length, 2));
			}
		}
		/*
		if (document.forms['cv_form3']) {
			if (document.forms['cv_form3'].no_w_exp.checked)
				disableForm ('cv_form3', true, 1);
			else
				disableForm ('cv_form3', false, 1);
		}*/
	} // markCVMenu
	
	function inArray(array, item) {
		for (i=0; i<array.length; i++) {
			if (array[i] == item)
				return true;
		}
		return false;
	} // inArray
	
	
	
	
	
	
	
	
	
	function markLink(paramName, paramValue) {
		
		var get = String(paramName + paramValue);
		for (i=0; i<document.links.length; i++) {
			//alert(document.links[i].href.indexOf(paramName + paramValue));
			//alert(paramName + paramValue);
					
			if (document.links[i].href.indexOf(paramName + paramValue) != -1)
			{
				
				document.links[i].style.fontWeight='bold';
				//document.links[i].style.color='blue';
			}
			else
			{
				if (document.links[i].href.indexOf('current=4') != -1 && paramValue == 14)
					document.links[i].style.fontWeight='bold';
				
			}
		
		
		
		}
		
		// scr		
		var lang = window.location.href.indexOf('current=8');
		var check = false;
		if (lang != -1)
		{
			for (var z = 0; z < document.links.length; z++)
			{
				if (document.links[z].id.indexOf('ln_') != -1)
				{			 		
					id = document.links[z].parentNode.id;
					check = true;					
				}
			
			}		
			
		if (check == true)
			document.getElementById(id).scrollIntoView(true);		
		}	
		
	} // markLink
	
	function iSNumeric(sText) {
		var ValidChars = "0123456789.";
		var IsNumber=true;
		var Char;
 
		for (i = 0; i < sText.length && IsNumber == true; i++) { 
			Char = sText.charAt(i); 
			if (ValidChars.indexOf(Char) == -1) {
				IsNumber = false;
			}
		}
		return IsNumber;
	}
	
	function changeExDay(currM, maxM, maxD) {//alert(currM + ' ' + maxM + ' ' + maxD);
		dayDiv = document.getElementById('day');
		
		selMonth = getMonthIndex(document.getElementById('exp_month').value) + 1;
		
		if (selMonth == maxM)
			dayDiv.innerHTML = getExDays('exp_day', maxD, 'crm_select', 1);
		 else if (selMonth == currM)
			dayDiv.innerHTML = getExDays('exp_day', getMonthMaxDay(selMonth), 'crm_select', new Date().getDate());
		 else
			dayDiv.innerHTML = getExDays('exp_day', getMonthMaxDay(selMonth), 'crm_select', 1);
	} // changeContDay
	
	function getExDays(sel_name, count, cssClass, firstDay) {
		str = "&nbsp;<select name='" + sel_name + "' id='" + sel_name + "' class='" + cssClass + "'>";
		for (i=firstDay; i<=count; i++)
			str +="<option value='"+ i +"'>" + i + "</option>";
		return str += "</select>";
	} // getDays
	
	function getMonthMaxDay($month_index) {
		if ($month_index == 4 || $month_index == 6 || $month_index == 9 || $month_index == 11)
			return 30;
		 else if ($month_index == 2)
			return 28;
		 else 
			return 31;
	} // get_month_max_day
	
	function disableForm(fName, boolValue, start) {
		for (i=start; i<document.forms[fName].elements.length; i++ ) {
			elType = document.forms[fName].elements[i].type;
			if (elType !== 'submit' && elType !== 'button' && elType !=='hidden')
				document.forms[fName].elements[i].disabled = boolValue;
		}
	} // disableForm
	
	function uncheckServiceChbxs(status, id) {
		ids = new Array('jad_chbx', 'sp_chbx', 'cm_chbx', 'db_chbx');
		discIds = new Array('jad_disc', 'sp_disc', 'jad_disc', 'jad_disc');
		priceIds = new Array('jad_price', 'sp_price', 'cm_price', 'db_price');
		if (status) {
			for (i=0; i<ids.length; i++) {
				if (ids[i] != id) {
					document.getElementById(ids[i]).checked = false;
					document.getElementById(discIds[i]).value = '';
					document.getElementById(priceIds[i]).value = '';
				}
			}
		} else {
			for (i=0; i<ids.length; i++) {
				if (ids[i] == id)
					document.getElementById(ids[i]).checked = true;
				 else {
					document.getElementById(ids[i]).checked = false;
					document.getElementById(discIds[i]).value = '';
					document.getElementById(priceIds[i]).value = '';
				}
			}
		}
	} // uncheckServiceChbxs
	
	function checkDiscount(val) {
		if (val == 12) {
			showDiv('add_disc', true, 'visibility');
		} else {
			document.getElementById('total_sp_price').checked = false;
			showDiv('add_disc', false, 'visibility');
		}
	} // checkDiscount
	
	function showDiv(id, show, style) {
       if (document.getElementById(id)) {
			if (style == 'display')
			{
				document.getElementById(id).style.display = (show) ? 'block' : 'none';
				if (id == 'new_occ') {
					document.getElementById(id).focus();
					document.getElementById(id).select();
				}
			}
			else
			{
				document.getElementById(id).style.visibility = (show) ? 'visible' : 'hidden';
			}
	   }
    } // showDiv
    
    function confirmCVForm(fName) {
		//alert (fName);
		for (i=0; i<document.forms[fName].elements.length; i++ ) {
			elType = document.forms[fName].elements[i].type;
			
			//alert(elType);
			
			if (((document.forms[fName].elements[i].value.length > 0) && (elType == 'text' || elType == 'textarea')) || (elType == 'select-one' && document.forms[fName].elements[i].options[0].selected == false ) || (elType == 'checkbox' && document.forms[fName].elements[i].checked == true )  )
				return (confirm('Ar tikrai norite tęsti neišsaugoję duomenų? Norėdami išsaugoti spauskite "Cancel" ir tada "Irašyti".'));
		}
		return true;
    } // confirmCVForm3
	
	function infa(id)
	{
		var inputs = document.getElementsByTagName('div');
										
		for (var i = 0; i < inputs.length; i++)
		{
  		
			if (inputs[i].className == 'info_div')
			{
				
				if (inputs[i].id == id )
				{   												
						
						if (inputs[i].style.display == 'none')
						{
		 					
							inputs[i].style.display = 'block';
						}
						else
						{
							inputs[i].style.display = 'none';
			
						}
 												
				}
				else
				{									
						inputs[i].style.display = 'none';									
				}
			}
		
		}						
		
	}
	/*
	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 preload()
	{
		var inputs = document.getElementsByTagName('img');
		var img = new Image();
		img.src = 'images/help.gif';
		
		for (var i = 0; i < inputs.length; i++)
		{
  			if (inputs[i].className == 'zz')
			{
				inputs[i].src = img.src;
			}
		}
	}
	*/
	
	
	function changeLangLevelStates (state,f_name) {
	
		/*document.forms['job_form4in'].lang_level.disabled = state;
		
		document.forms['job_form4in'].listening.disabled = !state;
		document.forms['job_form4in'].reading.disabled = !state;
		document.forms['job_form4in'].intercourse.disabled = !state;
		document.forms['job_form4in'].inf_present.disabled = !state;
		document.forms['job_form4in'].writing.disabled = !state;*/
		
		document.forms[f_name].lang_level.disabled = state;
		
		document.forms[f_name].listening.disabled = !state;
		document.forms[f_name].reading.disabled = !state;
		document.forms[f_name].intercourse.disabled = !state;
		document.forms[f_name].inf_present.disabled = !state;
		document.forms[f_name].writing.disabled = !state;
		
		if (!state)
			changeLangLevels (f_name);
	
	} // changeLangLevelStates
	
	function changeLangLevels (f_name) {
		//var level = document.forms['job_form4in'].lang_level.value;
		var level = document.forms[f_name].lang_level.value;
		
		var combo_array = new Array('listening', 'reading', 'intercourse', 'inf_present', 'writing');
		
		for (i=0; i<combo_array.length; i++) {
			//var combo = document.forms['job_form4in'].elements[combo_array[i]];
			var combo = document.forms[f_name].elements[combo_array[i]];
			
			for (j=0; j<combo.options.length; j++) {
				if (combo.options[j].value == level) {
					combo.options[j].selected = true;
					break;
				}
			}
		}
		
	} // disableLangLevels
	
	function enableForm(formName) {
		for (i=0; i<document.forms[formName].elements.length; i++)
			document.forms[formName].elements[i].disabled = false;
		
		if (formName == 'service_order') {
			return true
		} else {
			return check(document.forms[formName]);
		}
	} // enableForm
	
	// Open a window at a given position on the screen
	function openPositionedWindow(url, name, width, height, x, y, status, scrollbars, moreProperties, openerName) {
	
		// ie 4.5 and 5.0 mac - windows are 2 pixels too short; if a statusbar is used, the window will be an additional 15 pixels short
		var agent = navigator.userAgent.toLowerCase();
		if (agent.indexOf("mac") != -1 && agent.indexOf("msie") != -1 && (agent.indexOf("msie 4") != -1 || agent.indexOf("msie 5.0") != -1) ) {
			height += (status) ? 17 : 2;
		}
		// Adjust width if scrollbars are used (pc places scrollbars inside the content area; mac outside) 
		width += (scrollbars != '' && scrollbars != null && agent.indexOf("mac") == -1) ? 16 : 0;
		var properties = 'width=' + width + ',height=' + height + ',screenX=' + x + ',screenY=' + y + ',left=' + x + ',top=' + y + ((status) ? ',status' : '') + ',scrollbars' + ((scrollbars) ? '' : '=no') + ((moreProperties) ? ',' + moreProperties : '');
		var reference = openWindow(url, name, properties, openerName);
		return reference;
	}
	
	// Core utility function that actually creates the window and gives focus to it
	function openWindow(url, name, properties, openerName) {
		// ie4.x pc can't give focus to windows containing documents from a different domain
		// in this case, initially load a local interstisial page to allow focussing before loading final url
		var agent = navigator.userAgent.toLowerCase();
		if (agent.indexOf("msie") != -1 && parseInt(navigator.appVersion) == 4 && agent.indexOf("msie 5") == -1 && agent.indexOf("msie5") == -1 && agent.indexOf("win") != -1 && url.indexOf('http://') == 0) {
			winReference = window.open('about:blank', name, properties);
	
			setTimeout('if (winReference && !winReference.closed) winReference.location.replace("' + url + '")', 300);
		}
		else {
			winReference = window.open(url, name, properties);
		}
		// ie doesn't like giving focus immediately (to new window in 4.5 on mac; to existing ones in 5 on pc)
		setTimeout('if (winReference && !winReference.closed) winReference.focus()', 200);
	
		if (openerName) self.name = openerName;
		return winReference;
	}
	
	// Open a window at the center of the screen
	function openCenteredWindow(url, name, width, height, status, scrollbars, moreProperties, openerName) {
		var x, y = 0;
		if (screen) {
			x = (screen.availWidth - width) / 2;
			y = (screen.availHeight - height) / 2;
		}
		if (!status) status = '';
		if (!openerName) openerName = '';
		var reference = openPositionedWindow(url, name, width, height, x, y, status, scrollbars, moreProperties, openerName);
		return reference;
	}
	
	function maximum(object,message)
	{
		var array = object.options.length;		
		var max_value = 0;
		var accept = true;
		var last;
		
		//alert(object.value);
		
		for (var i=0;i<array;i++)
		{
			
			if (object.options[i].selected)
			{
				//alert(object.options[i].index);				
				max_value++;				
				//if (max_value == 3)
					//var curr = object.options[i].index;							
				if (max_value >3)
				{
					object.options[i].selected = false;		
					//alert(object.options[i].text);
					var accept = false;
					
				}
			}			
			//alert(object.options[i].text);			
		
			
		}
		
				
		if (accept == false)
			alert(message);
		
	}
	
	function disable(frm)
	{
		var gg = frm;
		var Arr = gg.elements;
		var check = document.getElementById('choose1');
		var links = document.getElementById('pic');
		
		if (check.checked == false)
		{
		
			for (var i=0;i<Arr.length;i++)
			{
			
				if (Arr[i].name != 'choose1' && Arr[i].name != 'submit' ) 
					Arr[i].disabled = false;
			
			//alert(Arr[i].name);
			}
		
		
			links.href='index.php?current=21';
			links.style.color = '#1F5D66';
		
		
		//COLOR="#1F5D66"
		
		}
		else if (check.checked == true)
		{
			for (var i=0;i<Arr.length;i++)
			{
			
				if (Arr[i].name != 'choose1' && Arr[i].name != 'submit' && Arr[i].type != 'hidden' ) 
					Arr[i].disabled = true;
			
			//alert(Arr[i].name);
			}
			
			var links = document.getElementById('pic');
			links.href='javascript:void(0);';
			links.style.color = '#ACA899';
		
		}
	}
	
	function disable_link(frm)
	{
		var gg = frm;
		var Arr = gg.elements;
		var check = document.getElementById('choose1');
		var links = document.getElementById('pic');
		
		if (check.checked == true)
		{
		
			for (var i=0;i<Arr.length;i++)
			{
			
				if (Arr[i].name != 'choose1' && Arr[i].name != 'submit' ) 
					Arr[i].disabled = false;
			
			//alert(Arr[i].name);
			}
		
		
			links.href='index.php?current=21';
			links.style.color = '#1F5D66';
			check.checked = false;
		
		
		//COLOR="#1F5D66"
		
		}
	}
	
	function displayDiv(id, style, status) {
	    var elem = document.getElementById(id);
        if (elem) {
			if (style == 'display') {
				elem.style.display = (elem.style.display == 'none') ? status : 'none';
				
			} else {
				elem.style.visibility = (elem.style.visibility == 'hidden') ? status : 'hidden';
			}
	   }
    } // displayDiv
	
	function comp_sub(form)
	{					
			if (form == 'cv_form3')
			{
				nu = 6;
				
			radioObj = document.forms['add_comp'].elements['compa'];
			for(var i = 0; i < radioObj.length; i++)
			{
				if(radioObj[i].checked)				
					add_val = radioObj[i].value;
			}
				
				if (add_val != 'nera')
					opener.document.forms[form].elements['w_place'].value =
					document.getElementById(add_val).value.replace(/\"/g,"");
							
			}
			else if (form == 'cv_form7a')
			{
				nu = 25;						
				radioObj = document.forms['add_comp'].elements['compa'];
				
				for(var i = 0; i < radioObj.length; i++)
				{
					if(radioObj[i].checked)				
						add_val = radioObj[i].value;
				}
					
					if (add_val != 'nera')
						opener.document.forms[form].elements['company'].value =
						document.getElementById(add_val).value.replace(/\"/g,"");						
			}
			
			if (check(opener.document.forms[form]) == true) 
			{					
					opener.document.forms[form].action="index.php?current="+nu; 
					
					document.forms["add_comp"].submit();
					self.close();
					
					opener.document.forms[form].submit();					
			
			}
				
	}
	
	function checkFormFields(formName, fields) {
		var status = true;
		for (key in fields) {
			if (document.forms[formName].elements[fields[key]].value.length == 0) {
				status = false;
				alert('Užpildykite visus privalomus laukus!');
				break;
			}
		}
		return status;
	} // checkFormFields
	
	function checkAgrBtn() {
		if (document.getElementById('agree_chbx').checked) {
			return true;
		}
		alert('Nesutikus su sutarties sąlygomis, paslaugos užsakymas neįmanomas!');
		return false;
	} // checkAgrBtn
	
	function clear_field(obj,value)
	{
		if (obj.value == value)
			obj.value = '';
		
	}
	
	var ratingDiv_small;
	var showed = false;
	
	function changeTOP6_Div(rate, empl_id) {
		if (!showed) {
			var ratingDiv = "<div style='z-index:1' id='ratig_div'> \
  <table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\
    <tr><td colspan=\"3\" height=\"30\" class=\"empl_28_top center\">TOP 6</td></tr> \
    <tr>\
      <td height=\"40\" class=\"rating\">Lankytojų įvertinimas</td> \
      <td width=\"36\" class=\"rating_bg center\">"+rate+"</td>\
      <td class=\"left\"><img src=\"../images/rate_up.gif\" /></td> \
    </tr>\
    <tr><td colspan=\"3\" height=\"40\"><b><a href=\""+empl_id+"&sec=11\">Žiūrėti įvertinimo detalizavimą</a></b></td></tr> \
    <tr><td colspan=\"3\" height=\"40\" valign=\"bottom\" class=\"center\"><a href=\""+empl_id+"&sec=10\"><img border=\"0\" src=\"../images/rate_btn.gif\" /></a></td></tr> \
  </table> \
</div>";
			var div = document.getElementById('ratig_div_container');
			
			ratingDiv_small = div.innerHTML;
			div.innerHTML = ratingDiv;
		}
		showed = !showed;
	}
	
	function export_value(id, ex_object, button_id)
	{
		var val = ex_object.options[ex_object.selectedIndex].text;	
		var edit = document.getElementById(id);	
		var button = document.getElementById(button_id);
		edit.disabled = true;
		button.disabled = true;
		
		if (val == '-Pasirinkite-')
		{
			edit.disabled = true;
			button.disabled = true;
		}
		else
		{
			button.disabled = false;
			edit.disabled = false;
		}	
		
		edit.value = val;	
	}
	
	function disable(elements)
	{
		var el = elements.split(",");	
		
		for (var i=0;i<el.length; i++) {
			if (document.getElementById(el[i])) {
				document.getElementById(el[i]).disabled = true;	
			}
		}
		
	}
	
	function check_dk_form(obj, str)
	{
		var mass = obj.split("#");
		var message = str.split("#");
		var rez = "";
		var ret = true;
		
		for (var i=0;i<mass.length;i++)
		{
			if (trimAll(document.getElementById(mass[i]).value) == "")
			{
				rez = rez + message[i] + "\n";
				ret = false;
			}
		}
				
		if (ret == false)
			alert(rez);
		
		return ret;
	}
	
	function show_hide(id)
	{
		var inputs = document.getElementsByTagName('div');			
		for (var i = 0; i < inputs.length; i++)
		{  		
			if (inputs[i].className == 'task_div')
			{
				
				if (inputs[i].id == id )
				{   												
						
						if (inputs[i].style.display == 'none')
						{
		 					
							inputs[i].style.display = 'block';
						}
						else
						{
							inputs[i].style.display = 'none';
			
						}
 												
				}
				else
				{									
						inputs[i].style.display = 'none';									
				}
			}
		
		}						
		
	}
	
	function all_fields(form, text)
	{
		var acc = true;
		
		for (var i = 0; i < document.forms[form].elements.length; i++)	
		{
			if (trimAll(document.forms[form].elements[i].value) == "")
			{
				acc = false;
				alert(text);
				break;
			}
			
		}	
		
		return acc;		
	}
	
	function accept_rules(ch)
	{				
		var bt = document.getElementById("start_game_bt");
		if (ch.checked == true)
		{
			bt.disabled	= false;
		}
		else
		{
			bt.disabled	= true;
		}		
	}
	
	function start_game_bt(bt)
	{				
		if (bt.disabled == false){
			window.location.href="&sec=33";
		}		
	}
	