
function valideaza(str){


		var location1 = window.location.hostname;
      var limba='';
      if(location1.search(/en\./i)!='-1') limba='en';
      else {
      	if(location1.search(/fr\./i)!='-1') limba='fr';
      	else limba='ro';
      }

		var at="@";
		var dot=".";
		var lat=str.indexOf(at);
		var lstr=str.length;
		var ldot=str.indexOf(dot);
		if (str.indexOf(at)==-1){
		   if(limba=='ro') alert("Adresa de E-mail invalida!");
		   else{
				if(limba=='en')alert("Invalid Email address!");
				else alert("Adresse d'email invalide!");
		   }
		   return false;
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   if(limba=='ro') alert("Adresa de E-mail invalida!");
		   else{
				if(limba=='en')alert("Invalid Email address!");
				else alert("Adresse d'email invalide!");
		   }
		   return false;
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr-1){
		    if(limba=='ro') alert("Adresa de E-mail invalida!");
		   else{
				if(limba=='en')alert("Invalid Email address!");
				else alert("Adresse d'email invalide!");
		   }
		    return false;
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    if(limba=='ro') alert("Adresa de E-mail invalida!");
		   else{
				if(limba=='en')alert("Invalid Email address!");
				else alert("Adresse d'email invalide!");
		   }
		    return false;
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    if(limba=='ro') alert("Adresa de E-mail invalida!");
		    else{
				if(limba=='en')alert("Invalid Email address!");
				else alert("Adresse d'email invalide!");
		    }
		    return false;
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    if(limba=='ro') alert("Adresa de E-mail invalida!");
		    else{
				if(limba=='en')alert("Invalid Email address!");
				else alert("Adresse d'email invalide!");
		    }
		    return false;
		 }

		 if (str.indexOf(" ")!=-1){
		    if(limba=='ro') alert("Adresa de E-mail invalida!");
		    else{
				if(limba=='en')alert("Invalid Email address!");
				else alert("Adresse d'email invalide!");
		    }
		    return false;
		 }
                 if(str.substr(lstr-1, 1) == dot){
                    if(limba=='ro') alert("Adresa de E-mail invalida!");
					   else{
							if(limba=='en')alert("Invalid Email address!");
							else alert("Adresse d'email invalide!");
					   }
					    return false;
                 }
                 var ch = new Array("{","}","[","]","*","~","%","&","(",")","+","|","/","\\","'","\"",":",";","<",">",",","`",".."," ","?","!","__");
                 var i=0;
                 while(i<ch.length){
                    if (str.indexOf(ch[i])!=-1){
                        if(limba=='ro') alert("Adresa de E-mail invalida!");
					   else{
							if(limba=='en')alert("Invalid Email address!");
							else alert("Adresse d'email invalide!");
					   }
                        return false;
                    }
                    i++;
                 }
 		 return true;
	}

function ValidateForm(id_oferta){
      var location1 = window.location.hostname;
      var limba='';
      if(location1.search(/en\./i)!='-1') limba='en';
      else {
      	if(location1.search(/fr\./i)!='-1') limba='fr';
      	else limba='ro';
      }


	var nume = document.getElementById("n"+id_oferta);
	var prenume = document.getElementById("p"+id_oferta);
	var email = document.getElementById("em"+id_oferta);
	var tel = document.getElementById("tel"+id_oferta);
	var mesaj = document.getElementById("m"+id_oferta);

	if((nume.value == "") || (prenume.value == "") || (mesaj.value == "")){
		if(limba=='ro')alert("Nu ati completat toate campurile obligatorii sau ati trimis deja un e-mail pentru detalii!");
		else{
			if(limba=='en')alert("You didn't fill all required fields or you have already sent and email for details!");
			else alert("Vous n'avez pas rempli tous les domaines obligatoires ou vous avez deja envoye et e-mail pour plus de details!");
		}
		return false;
	}
	if(isNaN(tel.value)){
		if(limba=='ro') alert("Numar de telefon invalid!");
		else{
			if(limba=='en')alert("Invalid phone number!");
			else alert("Numero de telephone invalide!");
		}
		return false;
	}

	if ((email.value==null)||(email.value=="")){
		if(limba=='ro') alert("Introduce-ti adresa dv. de E-mail");
		else{
			if(limba=='en')alert("Enter your Email address!");
			else alert("Entrez votre adresse d'e-mail!");
		}
		email.focus();
		return false;
	}
	if (valideaza(email.value)==false){

		email.value="";
		email.focus();
		return false;
	}
	//return true;
	if(true){
		//trimitem valorile valide functiei ce trimite mailul
		var result_div = document.getElementById("send_mail"+id_oferta);
		var of_selectate_div = document.getElementById("oferte_selectate");

		if (window.XMLHttpRequest)
		{// code for IE7+, Firefox, Chrome, Opera, Safari
		  xmlhttp=new XMLHttpRequest();
		}
		else
		{// code for IE6, IE5
		  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
		xmlhttp.onreadystatechange=function()
		  {
		  if (xmlhttp.readyState==4 && xmlhttp.status==200)
		    { //alert("ok1");

		    if(xmlhttp.responseText.search("&&&")=="-1"){
                    //alert(xmlhttp.responseText.search("."));
					if(xmlhttp.responseText.search(".")=="0"){
                        result_div.innerHTML=xmlhttp.responseText;
                        //alert(xmlhttp.responseText);
                    }
				    else{
				  	   SetCookie("oferta", "");
				 	   result_div.innerHTML=res[0];
				  	   of_selectate_div.innerHTML=res[1];
				   }
			  }
			  else{

				  var res = xmlhttp.responseText.split("&&&");
				//	alert(res);
				SetCookie("oferta", "");
				  result_div.innerHTML=res[0];
				  of_selectate_div.innerHTML=res[1];

			  }

		  }
		  }
		xmlhttp.open("GET","actions/send_mail.php?n="+nume.value+"&p="+prenume.value+"&mail="+email.value+"&tel="+tel.value+"&msg="+mesaj.value+"&id_oferta="+id_oferta,true);
		xmlhttp.send();
	}
 }

function SetCookie1(cookieName,cookieValue) {
	 var today1 = new Date();
	 var expire1 = new Date();
	 nDays1=0.50;
	 expire1.setTime(today1.getTime() + 3600000*24*nDays1);
	// document.cookie = cookieName+"="+escape(cookieValue) + ";expires="+expire1.toGMTString();
	 document.cookie = cookieName + '=' + escape(cookieValue) + ";expires="+expire1.toGMTString()+',path=/;domain=apartamente-inchirieri.ro';
}


function ValidateFormAdaugaOferta(tip){

	//alert(id_oferta);


		var nume = document.getElementById("nume");

	var prenume = document.getElementById("prenume");

	var email = document.getElementById("email");

	var tel = document.getElementById("telefon");

	var mesaj = document.getElementById("mesaj");

	  var judet = document.getElementById("judet").value;

	if((nume.value == "") || (prenume.value == "") || (mesaj.value == "") ){

		if(limba=='ro') alert("Nu ati completat toate campurile obligatorii sau ati trimis deja un e-mail pentru detalii!");
		else{
			if(limba=='en')alert("You didn't fill all required fields or you have already sent and email for details!");
			else alert("Vous n'avez pas rempli tous les domaines obligatoires ou vous avez deja envoye et e-mail pour plus de details!");
		}
		return false;
	}

	if((judet == "-")){
		if(limba=='ro') alert("Nu ati selectat judetul!");
		else{
			if(limba=='en')alert("You didn't select the county!");
			else alert("Vous n'avez pas selectionne le comte!");
		}
		return false;
	}

	if(isNaN(tel.value)){
		if(limba=='ro') alert("Numar de telefon invalid!");
		else{
			if(limba=='en')alert("Invalid phone number!");
			else alert("Numero de telephone invalide!");
		}
		return false;
	}

	if ((email.value==null)||(email.value=="")){
		if(limba=='ro') alert("Introduce-ti adresa dv. de E-mail");
		else{
			if(limba=='en')alert("Enter your Email address!");
			else alert("Entrez votre adresse d'e-mail!");
		}
		email.focus();
		return false;
	}
	if (valideaza(email.value)==false){

		email.value="";
		email.focus();
		return false;
	}
	//return true;
	if(true){
		//trimitem valorile valide functiei ce trimite mailul
		var result_div = document.getElementById("adauga_oferta");
		var of_selectate_div = document.getElementById("adauga_oferta");

		if (window.XMLHttpRequest)
		{// code for IE7+, Firefox, Chrome, Opera, Safari
		  xmlhttp=new XMLHttpRequest();
		}
		else
		{// code for IE6, IE5
		  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
		xmlhttp.onreadystatechange=function()
		  {
		  if (xmlhttp.readyState==4 && xmlhttp.status==200)
		    {
            //alert(xmlhttp.responseText);
		    result_div.innerHTML=xmlhttp.responseText;

		  }
		  }
		xmlhttp.open("GET","actions/send_mail.php?n="+nume.value+"&p="+prenume.value+"&mail="+email.value+"&tel="+tel.value+"&msg="+mesaj.value+"&judet="+judet+"&tip="+tip,true);
		xmlhttp.send();
	}
 }



