function go()
{
	box = document.forms[0].cat;
	destination = box.options[box.selectedIndex].value;
	if (destination) location.href = destination;
}

function go2()
{
	box = document.forms[0].subcat;
	destination = box.options[box.selectedIndex].value;
	if (destination) location.href = destination;
}

function reload(form)
{
var val=form.cat.options[form.cat.options.selectedIndex].value;
self.location='http://www.bileteavion.com.ro/lista_aeroporturi.php?cat=' + val ;
}

function reload1(form)
{
var val=form.cat.options[form.cat.options.selectedIndex].value;
self.location = val ;
}

function reload2(form)
{
var val=form.subcat.options[form.subcat.options.selectedIndex].value;
self.location = val ;
}

//start verificare email
function isEmail(string) {

/*
if (string.value.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z]{2,4}$/)!= -1 || string.value == "")
	{	
	return true;
	}
else
	{
	alert('Formatul adresei de e-mail este incorect!');
	string.value="";
	string.focus();
	return false;
	}
*/
var RegExp = /^((([a-z]|[0-9]|!|#|$|%|&|'|\*|\+|\-|\/|=|\?|\^|_|`|\{|\||\}|~)+(\.([a-z]|[0-9]|!|#|$|%|&|'|\*|\+|\-|\/|=|\?|\^|_|`|\{|\||\}|~)+)*)@((((([a-z]|[0-9])([a-z]|[0-9]|\-){0,61}([a-z]|[0-9])\.))*([a-z]|[0-9])([a-z]|[0-9]|\-){0,61}([a-z]|[0-9])\.)[\w]{2,4}|(((([0-9]){1,3}\.){3}([0-9]){1,3}))|(\[((([0-9]){1,3}\.){3}([0-9]){1,3})\])))$/
    if(RegExp.test(string)){
        return true;
    }else{
        return false;
    } 
}
//end verificare email


function myisEmail() {
	email=document.getElementById("mail").value;
	var RegExp = /^((([a-z]|[0-9]|!|#|$|%|&|'|\*|\+|\-|\/|=|\?|\^|_|`|\{|\||\}|~)+(\.([a-z]|[0-9]|!|#|$|%|&|'|\*|\+|\-|\/|=|\?|\^|_|`|\{|\||\}|~)+)*)@((((([a-z]|[0-9])([a-z]|[0-9]|\-){0,61}([a-z]|[0-9])\.))*([a-z]|[0-9])([a-z]|[0-9]|\-){0,61}([a-z]|[0-9])\.)[\w]{2,4}|(((([0-9]){1,3}\.){3}([0-9]){1,3}))|(\[((([0-9]){1,3}\.){3}([0-9]){1,3})\])))$/
    if(RegExp.test(email)){
        return true;
    }else{
		alert('Formatul adresei de e-mail este incorect!');
		return false;
    } 


}



function validateForm(form){
	if ( document.getElementById("numee").value == "" ){
		alert ("Nu ati completat numele!" );
		document.getElementById("numee").focus();
		return false;	
	}
	if ( document.getElementById("tell").value == "" ){
		alert ("Nu ati completat numarul de telefon!" );
		document.getElementById("tell").focus();
		return false;	
	}	
	if ( document.getElementById("mesaj").value == "" ){
		alert ("Nu ati completat mesajul!" );
		document.getElementById("mesaj").focus();
		return false;	
	}	
	if ( document.getElementById("tell").value.length < 10 ){
		alert ("Numarul de telefon nu este complet!" );
		document.getElementById("tell").focus();
		return false;	
	}	

//	phoneRegex = /^[0-9]*$/;
//	telefon = document.getElementById("tel").value;
//	 if( !telefon.match( phoneRegex ) ) {
//  		alert( "Please enter a valid phone number" );
//		document.getElementById("tel").focus();
//	 return false;
//	 }
return true
}

function validateFormCerere(form)
{

	if(pos["oras"]>0||pos["orasdest"]>0)
	{
		if(pos["oras"]>0) select_city(document.getElementById("oras-"+pos[targ.name]).innerHTML, "oras");
		if(pos["orasdest"]>0) select_city(document.getElementById("orasdest-"+pos[targ.name]).innerHTML, "orasdest");
		return false;
	}

	if ( document.getElementById("oras").value == "" ){
		alert ("Nu ati completat orasul!" );
		document.getElementById("oras").focus();
		return false;	
	}	
	

	var alphaExp = /^[a-zA-Z- ]+$/;
	var orasid = document.getElementById("oras")
	if(!orasid.value.match(alphaExp)){
		alert ("Nu ati completat corect orasul!" );
		document.getElementById("oras").focus();			
		return false;
	}

		if ( document.getElementById("orasdest").value == "" ){
		alert ("Nu ati completat destinatia!" );
		document.getElementById("orasdest").focus();
		return false;	
	}
	
	var orasid = document.getElementById("orasdest")
	if(!orasid.value.match(alphaExp)){
		alert ("Nu ati completat corect destinatia!" );
		document.getElementById("orasdest").focus();			
		return false;
	}
	
	if ( document.getElementById("dateunu").value == "zz/ll/aaaa" ){
		alert ("Nu ati selectat data de plecare!" );	
		return false;	
	}	




   	  var str1 = document.getElementById("dateunu").value;
      var str2 = document.getElementById("datedoi").value;
      var dt1  = parseInt(str1.substring(0,2),10);
      var mon1 = parseInt(str1.substring(3,5),10);
      var yr1  = parseInt(str1.substring(6,10),10);
      var dt2  = parseInt(str2.substring(0,2),10);
      var mon2 = parseInt(str2.substring(3,5),10);
      var yr2  = parseInt(str2.substring(6,10),10);
      var date1 = new Date(yr1, mon1, dt1);
      var date2 = new Date(yr2, mon2, dt2);
	  var l_dt = new Date();
	  var date3 = Date.UTC( l_dt.getFullYear(), l_dt.getMonth()+1, l_dt.getDate()-1,0,0,0);


	  if(date1 < date3)
		{
		 alert("Nu puteti pleca mai devreme de astazi!");
         return false;
		}	
 
      if(date2 < date1)
      {
          alert("Data sosirii nu poate fi mai devreme decat data plecarii!");
         return false;
      } 

		if ((document.getElementById("datedoi").value == "zz/ll/aaaa") || (document.getElementById("datedoi").value == "")) {
			var rasp = confirm ("Doriti bilet doar dus?");
			if (rasp==true) return true;
			else return false;
				
		}


	
	return true;
}



function echeck(str) {

		var at="@";
		var dot=".";
		var lat=str.indexOf(at);
		var lstr=str.length;
		var ldot=str.indexOf(dot);
		if (str.indexOf(at)==-1){
		   alert("Adresa de e-mail nu este corecta!");
		   return false;
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert("Adresa de e-mail nu este corecta!");
		   return false;
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    alert("Adresa de e-mail nu este corecta!");
		    return false;
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    alert("Adresa de e-mail nu este corecta!");
		    return false;
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    alert("Adresa de e-mail nu este corecta!");
		    return false;
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    alert("Adresa de e-mail nu este corecta!");
		    return false;
		 }
		
		 if (str.indexOf(" ")!=-1){
		    alert("Adresa de e-mail nu este corecta!");
		    return false;
		 }

 		 return true;					
	}




function validateFormCerere2(form)
{

	var emailID=document.getElementById("mail")
	

	if ( document.getElementById("numea").value == "" ){
		alert ("Nu ati completat numele!" );
		document.getElementById("numea").focus();
		return false;	
	}	
	if ( document.getElementById("telefon").value == "" ){
		alert ("Nu ati completat numarul de telefon!" );
		document.getElementById("telefon").focus();
		return false;	
	}
	if ( document.getElementById("telefon").value.length < 10 ){
		alert ("Numarul de telefon nu este complet!" );
		document.getElementById("telefon").focus();
		return false;	
	}	
	phoneRegex = /^[0-9+]*$/;
	telefon = document.getElementById("telefon").value;
	 if( !telefon.match( phoneRegex ) ) {
  		alert( "Numarul de telefon nu este corect!" );
		document.getElementById("telefon").focus();
 	 return false;
	 }


		if ((emailID.value==null)||(emailID.value=="")){
		alert("Nu ai introdus adresa de e-mail!");
		emailID.focus();
		return false;
	}
	if (echeck(emailID.value)==false){
		emailID.value="";
		emailID.focus();
		return false;
	}
	
	return true;
}

function validateFormCerere22(form)
{
	if ( document.getElementById("numea").value == "" ){
		alert ("Nu ati completat numele!" );
		document.getElementById("numea").focus();
		return false;	
	}	
	if ( document.getElementById("telefon").value == "" ){
		alert ("Nu ati completat numarul de telefon!" );
		document.getElementById("telefon").focus();
		return false;	
	}
	if ( document.getElementById("telefon").value.length < 6 ){
		alert ("Numarul de telefon nu este complet!" );
		document.getElementById("telefon").focus();
		return false;	
	}	


	phoneRegex = /^[0-9]*$/;
	telefon = document.getElementById("telefon").value;
	 if( !telefon.match( phoneRegex ) ) {
  		alert( "Introduceti un numar de telefon valid!" );
		document.getElementById("telefon").focus();
 	 return false;
	 }
	return true;
}

function validateAutentif(form)
{
var sir, i, tmp
	if ( document.getElementById("nick").value == "" ){
		alert ("Nu ati completat username-ul!" );
		document.getElementById("nick").focus();
		return false;	
	}	
	if ( document.getElementById("parola").value == "" ){
		alert ("Nu ati completat parola!" );
		document.getElementById("parola").focus();
		return false;	
	}	
	return true;
}

function validateFormFirme(form)
{


    



	if ( document.getElementById("numee").value == "" ){
		alert ("Nu ati completat numele!" );
		document.getElementById("numee").focus();
		return false;	
	}
	if ( document.getElementById("firma").value == "" ){
		alert ("Nu ati completat firma!" );
		document.getElementById("firma").focus();
		return false;	
	}	
	if ( document.getElementById("tell").value == "" ){
		alert ("Nu ati completat numarul de telefon!" );
		document.getElementById("tell").focus();
		return false;	
	}
	if ( document.getElementById("tell").value.length < 10 ){
		alert ("Numarul de telefon nu este complet!" );
		document.getElementById("tell").focus();
		return false;	
	}
	phoneRegex = /^[0-9]*$/;
	telefon = document.getElementById("tell").value;
	 if( !telefon.match( phoneRegex ) ) {
  		alert( "Please enter a valid phone number" );
		document.getElementById("tell").focus();
 	 return false;
	 }

	if ( document.getElementById("mesaj").value == "" ){
		alert ("Nu ati completat mesajul!" );
		document.getElementById("mesaj").focus();
		return false;	
	}	
	return true;
}

	function showHomeLink()
{
	document.write('<a href="http://www.bileteavion.com.ro/" title="bilete avion">&nbsp;&nbsp;&nbsp;Home</a>');
}

var pl_hint_over = false;
var so_hint_over = false;
var click_not_on_calendar=true;
var mouse_over_hidden_div=false;

function pl_in_blur()
{
	if(click_not_on_calendar==true&&mouse_over_hidden_div==false) document.getElementById('plecare_hint').style.display='none';
}

function so_in_blur()
{
	if(click_not_on_calendar==true&&mouse_over_hidden_div==false) document.getElementById('sosire_hint').style.display='none';
}

var pos = new Array();
pos['oras']=0;
pos['orasdest']=0;

var res_size = new Array();
res_size['oras']=0;
res_size['orasdest']=0;

function mouse_out(id)
{
	document.getElementById(id).style.backgroundColor="white";
	document.getElementById(id).style.color="#336699";
}

function mouse_over(id)
{
	document.getElementById(id).style.backgroundColor="#336699";
	document.getElementById(id).style.color="white";
}

function select_city(city_name, din_catre)
{
	document.getElementById(din_catre).value=city_name;
	if(din_catre=="oras") 
	{
		document.getElementById("plecare_hint").style.display='none';
		pos["oras"]=0;
		res_size["oras"]=0;
	}
	if(din_catre=="orasdest") 
	{
		document.getElementById("sosire_hint").style.display='none';
		pos["orasdest"]=0;
		res_size["orasdest"]=0;
	}
}
////////////////AJAX/////////////////////////
var xmlhttp;

function GetXmlHttpObject()
{
if (window.XMLHttpRequest)
  {
  // code for IE7+, Firefox, Chrome, Opera, Safari
  return new XMLHttpRequest();
  }
if (window.ActiveXObject)
  {
  // code for IE6, IE5
  return new ActiveXObject("Microsoft.XMLHTTP");
  }
return null;
}

function showHint(field)
{
	var str = document.getElementById(field.name).value;
	if(str.length>=2)
	{
		xmlhttp=GetXmlHttpObject();
		if (xmlhttp==null)
		  {
		  alert ("Your browser does not support XMLHTTP!");
		  return;
		  }
		
		var rand = parseInt(Math.random()*99999999);  // cache buster
		var url="gethint.php?q="+str+"&field="+field.name+"&rand="+rand;
		xmlhttp.onreadystatechange=stateChanged;
		xmlhttp.open("GET",url,true);
		xmlhttp.send(null);
	}
	else 
	{
		if(field.name=="oras") document.getElementById("plecare_hint").style.display="none";
		if(field.name=="orasdest") document.getElementById("sosire_hint").style.display="none";
		pos["oras"]=0;
	    pos["orasdest"]=0;
		res_size["oras"]=0;
		res_size["orasdest"]=0;
	}
}

function stateChanged()
{
if (xmlhttp.readyState==4)
  {
	  temp = xmlhttp.responseText.split("|");
	  if(temp[1]!="")
	  {
		  if(temp[0]=="oras") 
		  {
			  document.getElementById('plecare_hint').style.display="block";
			  document.getElementById('plecare_hint').innerHTML=temp[1];
			  pos['oras']=0;
			  res_size['oras']=temp[2];
			  if(temp[2]>6) 
			  {
				  document.getElementById('plecare_hint').style.height="100px";
				  document.getElementById('plecare_hint').style.overflowY="scroll";
			  }
			  else 
			  {
				  document.getElementById('plecare_hint').style.height="auto";
				  document.getElementById('plecare_hint').style.overflowY="auto";
			  }
		  }
		  else if(temp[0]=="orasdest")
		  {
			  document.getElementById('sosire_hint').style.display="block";
			  document.getElementById('sosire_hint').innerHTML=temp[1];
			  pos['orasdest']=0;
			  res_size['orasdest']=temp[2];
			  if(temp[2]>4)
			  {
				  document.getElementById('sosire_hint').style.height="66px";
				  document.getElementById('sosire_hint').style.overflowY="scroll";
			  }
			  else 
			  {
				  document.getElementById('sosire_hint').style.height="auto";
				  document.getElementById('sosire_hint').style.overflowY="auto";
			  }
		  }
	  }
	  else 
	  {
		  document.getElementById("plecare_hint").style.display="none";
		  document.getElementById("sosire_hint").style.display="none";
		  res_size["oras"]=0;
		  res_size["orasdest"]=0;
	  }
	  
      //document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
  }
else 
{
	document.getElementById("plecare_hint").style.display="none";
	document.getElementById("sosire_hint").style.display="none";
	res_size["oras"]=0;
	res_size["orasdest"]=0;
}
}


//////////////////////////AJAX///////////////////////////


//////////////////////////ARROW MOVEMENT//////////////////

//document.onkeydown = key_handler;

/*document.getElementById('oras').onkeydown = myKeyUpHandler;
var num = new Array(0,0,0);
var text = "";
var minus = "";*/

var selected_city_name;
function key_handler(e) {
	if (e.keyCode) code = e.keyCode;
	else if (e.which) code = e.which;
	
	if (e.target) targ = e.target;
    else if (e.srcElement) targ = e.srcElement;
    if (targ.nodeType == 3) targ = targ.parentNode;
	if(targ.name=="oras"||targ.name=="orasdest")
	{
		selected_city_name = "no";
		if(code!="38"&&code!="40"&&code!="13")
		{
			showHint(document.getElementById(targ.name));
		}
		else if(res_size[targ.name]>0&&(code=="38"||code=="40"||code=="13"))
		{
			if(code=="38") 
			{
				if(pos[targ.name]>=1) pos[targ.name]--;
				//change_pos(pos[targ.name], targ.name);
			}
			else if(code=="40") 
			{
				if(pos[targ.name]<res_size[targ.name]) pos[targ.name]++;
				//change_pos(pos[targ.name], targ.name);
			}
			else if(code=="13")
			{
				select_city(document.getElementById(targ.name+"-"+pos[targ.name]).innerHTML, targ.name);
				selected_city_name = "yes";
			}
			change_pos(pos[temp[0]],temp[0]);
		}
	}
}

function change_pos(i, city)
{
	for(j=1;j<=res_size[city];j++)
	{
		if(j==i) 
		{
			document.getElementById(city+"-"+j).style.backgroundColor="#336699";
			document.getElementById(city+"-"+j).style.color="#FFFFFF";
		}
		
		else
		{
			document.getElementById(city+"-"+j).style.backgroundColor="#FFFFFF";
			document.getElementById(city+"-"+j).style.color="#336699";
		}
	}
}
//////////////////////////ARROW MOVEMENT//////////////////



function dpl_in_blur()
{
	if(mouse_over_calendar==false) 
	{
		hideCalendars();
		mouse_over_calendar=false;
	}
}

function dso_in_blur()
{
	if(mouse_over_calendar==false) 
	{
		hideCalendars();
		mouse_over_calendar=false;
	}
}

var mouse_over_calendar=false;
