// JavaScript Document
function IsValidEmail(str) 
{
	/*if ( str.indexOf(".") <=2 || str.indexOf("@") <=0  )
		return false;*/
		
	if( str.indexOf(",") >=0 )
		return false;
	if( str.indexOf(";") >=0 )
		return false;
	if( str.indexOf("(") >=0 )
		return false;
	if( str.indexOf(")") >=0 )
		return false;
	if( str.indexOf("+") >=0 )
		return false;
	if( str.indexOf(" ") >=0 )
		return false;
	if( str.indexOf("?") >=0 )
		return false;
	if( str.indexOf("`") >=0 )
		return false;
	if( str.indexOf("#") >=0 )
		return false;
	if( str.indexOf("!") >=0 )
		return false;
	if( str.indexOf("$") >=0 )
		return false;
	if( str.indexOf("%") >=0 )
		return false;
	if( str.indexOf("*") >=0 )
		return false;
	if( str.indexOf("=") >=0 )
		return false;																										
		
		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   //alert("Invalid E-mail ID")
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   //alert("Invalid E-mail ID")
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    //alert("Invalid E-mail ID")
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    //alert("Invalid E-mail ID")
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    //alert("Invalid E-mail ID")
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    //alert("Invalid E-mail ID")
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    //alert("Invalid E-mail ID")
		    return false
		 }

 		 return true					
}
function validate(form)
{
	if (form.fname.value.length == 0 ) 
	{
		alert("Introduceti \"Nume si prenume\".");
		form.fname.focus();
		return (false);
	}
	stremail=document.getElementById("email");
	if (stremail.value.length==0)
	{
		alert("Introduceti \"Adresa de email\".");
		stremail.focus();
		return (false);
	}
	if(!IsValidEmail(stremail.value))
	 {
		alert("Formatul \"Adresa de email\" este incorecta.");
		stremail.focus();
		return(false);
	}
	if (form.mesaj.value.length == 0 ) 
	{
		alert("Introduceti \"Mesaj\".");
		form.mesaj.focus();
		return (false);
	}
}
function validate_contact(form)
{
	if (form.nume.value.length == 0 ) 
	{
		alert("Introduceti \"Nume si prenume\".");
		form.nume.focus();
		return (false);
	}
	if (form.telefon.value.length == 0 ) 
	{
		alert("Introduceti \"Telefon\".");
		form.telefon.focus();
		return (false);
	}
	stremail=document.getElementById("email");
	if (stremail.value.length==0)
	{
		alert("Introduceti \"Adresa de email\".");
		stremail.focus();
		return (false);
	}
	if(!IsValidEmail(stremail.value))
	 {
		alert("Formatul \"Adresa de email\" este incorecta.");
		stremail.focus();
		return(false);
	}
	if (form.mesaj.value.length == 0 ) 
	{
		alert("Introduceti \"Mesaj\".");
		form.mesaj.focus();
		return (false);
	}
}
function validatesearchid(form)
{
	if(isEmpty(form.id.value))
	{
		 alert('Introduceti ID-ul ofertei');
		 form.id.focus();
		 return(false);
	}
	
}
function validatewant(form)
{
	if (form.fname.value.length == 0 ) 
	{
		alert("Introduceti \"Nume si prenume\".");
		form.fname.focus();
		return (false);
	}
	if (form.phone.value.length == 0 ) 
	{
		alert("Introduceti \"Telefon\".");
		form.phone.focus();
		return (false);
	}
	stremail=document.getElementById("email");
	if (stremail.value.length==0)
	{
		alert("Introduceti \"Adresa de email\".");
		stremail.focus();
		return (false);
	}
	if(!IsValidEmail(stremail.value))
	 {
		alert("Formatul \"Adresa de email\" este incorecta.");
		stremail.focus();
		return(false);
	}
}
function isEmpty(s)
{
     return ((s == null) || (s.length == 0))
}
function isDigit (c)
   {
      return ((c >= "0") && (c <= "9"))
   }
function isInteger (s)
   {
      var i;

      if (isEmpty(s))
      if (isInteger.arguments.length == 1) return 0;
      else return (isInteger.arguments[1] == true);

      for (i = 0; i < s.length; i++)
      {
         var c = s.charAt(i);

         if (!isDigit(c)) return false;
      }

      return true;
   }
function show_big_image(image){
	var big_image = document.getElementById('big_image');
	var lightbox = document.getElementById('lx');
	if(big_image){
		big_image.src=image;
		
	}
	if(lightbox)
	{
		
		lightbox.href= image.replace(/bigimage/,'largeimage');
	}
}
function toogle_city(c,id){
	try{
		if(c.checked) document.getElementById(id).className='citychecked';
		else 
		{
			document.getElementById(id).className='cityunchkecked';
			unckeck_wards(document.getElementById(id),0);
			
		}
	}
	catch(e){}
}
function unckeck_wards(parent,level){
	for(var i=0;i<parent.childNodes.length;i++){
		var child = parent.childNodes[i];
		if(child.nodeName=="INPUT" && child.type=='checkbox') child.checked = false;
		if(child.nodeName=='DIV') unckeck_wards(child,level+1); 
	}
}
function toogle_nrrooms(c,id){
	try{
		if(c.checked) document.getElementById(id).className='search_rooms_checked';
		else 
		{
			document.getElementById(id).className='search_rooms_unchecked';
		}
	}
	catch(e){}
}
function toogle_all()
{
	document.getElementById('search_ap').className='search_rooms_unchecked';
	document.getElementById('search_house').className='search_rooms_unchecked';
	document.getElementById('search_teren').className='search_rooms_unchecked';
	document.getElementById('search_spatii').className='search_rooms_unchecked';

}
function addInput() { 
	var parent = document.getElementById('pictures')
	var element = null;
	try { // IE
	    element.innerHTML += '<div class="caption">&nbsp;</div>\n\r<div class="caption_input"><input type="file" name="poza[]" value=""/></div>';
	    } 
	catch (e) { // W3C
	    element = document.createElement("input");
	    element.setAttribute("type", "file");
	    element.setAttribute("name", "poza[]");
	    }
	parent.appendChild(element);
}
