
function ChampNonVide(ChampNom,message,FormNom) {
 if (document.forms[FormNom].elements[ChampNom].value.length < 1) {
  alert(" "+message);
  document.forms[FormNom].elements[ChampNom].focus();
  return true;
 }
}

function ChampNombre(ChampNom,FormNom,message) {
 var lib = message; 
 var val = document.forms[FormNom].elements[ChampNom].value;
 val = val.replace(/,/g,"\.");	
 val = val.replace(" ","");
 document.forms[FormNom].elements[ChampNom].value = val;
 if ((val.length < 1) || (isNaN(val))) {
  alert(lib);
  document.forms[FormNom].elements[ChampNom].focus();
  return true;
 }
}

function EmailValid (ChampNom,FormNom) {
 var lib = "Your e-mail address is not valid"; 

 adresse = document.forms[FormNom].elements[ChampNom].value;
 var place = adresse.indexOf("@",1);
 var point = adresse.indexOf(".",place+1);
  if ((place > -1)&&(adresse.length >2)&&(point > 1)) {
  return false;
  }
	else {
   alert(lib);
   document.forms[FormNom].elements[ChampNom].focus();
   return true;
  }
}

function validFormContactOffer(FormNom) {
 if (EmailValid ('email' , FormNom)) return false;
 if (ChampNonVide('nom' , 'Please type your name', FormNom)) return false; 
 if (ChampNonVide('tel' , 'Please type your phone number', FormNom)) return false; 
}

function validFormAlert(FormNom) {
 if (ChampNonVide('nom' , 'Please type your name', FormNom)) return false; 
 if (EmailValid ('email' , FormNom)) return false;
 if (document.forms[FormNom].confirm_email.value != document.forms[FormNom].email.value) {
	 alert("Please confirm your e-mail address");
	 document.forms[FormNom].confirm_email.focus();
	 return false;
 }
 
 if (ChampNonVide('townP' , 'Please select a town', FormNom)) return false; 
 if (ChampNonVide('seaviewP' , 'Please select property with sea view or not', FormNom)) return false; 
 if (ChampNombre('bedsP' , FormNom, 'Please type a number of bedrooms' )) return false;
 if (ChampNonVide('poolP' , 'Please select property with pool or not', FormNom)) return false; 
 
  if (document.forms[FormNom].tel.value.length < 1) {
  document.getElementById("popConfirmTel").style.display='block';
  return false;
 }
}

function givePhoneNumber(FormNom) {
	document.getElementById("popConfirmTel").style.display='none';
	document.forms[FormNom].tel.focus();
}


function validFormSendToFriend(FormNom) {
 if (ChampNonVide('nom' , 'Please type your name', FormNom)) return false; 
 if (ChampNonVide('friend_nom' , 'Please type your name', FormNom)) return false; 
 if (EmailValid ('email' , FormNom)) return false;
 if (EmailValid ('friend_email' , FormNom)) return false;
}

function clearFormContact(FormNom) {
	for (i=0, n=document.forms[FormNom].elements.length; i<n; i++){
	       if (document.forms[FormNom].elements[i].type == "text")  { document.forms[FormNom].elements[i].value= ""; } 
		   else if (  (document.forms[FormNom].elements[i].name == "msg") ) 
		   { document.forms[FormNom].elements[i].value= ""; }  
		   else { document.forms[FormNom].elements[i].value= 0; }
	}
}

function validFormContact(FormNom) {
 if (ChampNonVide('nom' , 'Please type your name', FormNom)) return false; 
 if (EmailValid ('email' , FormNom)) return false;
 if (ChampNonVide('msg' , 'Please type your message', FormNom)) return false; 
}
 
function closeConfirm(id) {
	document.getElementById(id).style.display='none';
}



function goPage(FormNom,action) {
	document.forms[FormNom].action = action;
	document.forms[FormNom].submit();
}

function getXhr(){
               var xhr = null; 
				if(window.XMLHttpRequest) // Firefox et autres
				   xhr = new XMLHttpRequest(); 
				else if(window.ActiveXObject){ // Internet Explorer 
				   try {
			                xhr = new ActiveXObject("Msxml2.XMLHTTP");
			            } catch (e) {
			                xhr = new ActiveXObject("Microsoft.XMLHTTP");
			            }
				}
				else { // XMLHttpRequest non supporté par le navigateur 
				   alert("Votre navigateur ne supporte pas les objets XMLHTTPRequest..."); 
				   xhr = false; 
				} 
                return xhr;
}

function goFormOffers(FormNom,url,id,budget,typeB,reference,ville,path) {
	
				var xhr = getXhr();
				
				/*reference = encodeURIComponent(document.forms[FormNom].reference.value);*/
		

			    var params = "path="+path+"&budget="+budget+"&typeB="+typeB+"&reference="+reference+"&ville="+ville;
			    //alert(params);
				
				xhr.open("POST", url, true);
				
	            xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded; charset=utf-8');
			    xhr.setRequestHeader("Content-length", params.length);
                xhr.setRequestHeader("Connection", "close");

				xhr.onreadystatechange = function(){
					//alert(xhr.readyState);
								
					if (xhr.readyState == 4)
				    {
					  if (xhr.status == 200) {
						 //alert(xhr.responseText); 
						 document.getElementById(id).innerHTML = xhr.responseText;
					  }
					  else {
						 //alert("Error code " + xhr.status);
						 }
				    }

				}

				
	            xhr.send(params);
				
			
}


function clearValBudget(){
	document.getElementById('bu1_1').style.color= '#666666';
	document.getElementById('bu2_1').style.color= '#666666';
	document.getElementById('bu3_1').style.color= '#666666';
	document.getElementById('bu4_1').style.color= '#666666';
	document.getElementById('bu5_1').style.color= '#666666';
	document.getElementById('bu6_1').style.color= '#666666';
	
	document.getElementById('bu1_2').style.color= '#666666';
	document.getElementById('bu2_2').style.color= '#666666';
	document.getElementById('bu3_2').style.color= '#666666';
	document.getElementById('bu4_2').style.color= '#666666';
	document.getElementById('bu5_2').style.color= '#666666';
	document.getElementById('bu6_2').style.color= '#666666';
}

function selectValBudget(e){
	clearValBudget();
	clearValType();
	//e.style.color = '#993333';
	document.getElementById(e+'_1').style.color= '#993333';
	document.getElementById(e+'_2').style.color= '#993333';
}

function clearValType(){
	document.getElementById('ty1_1').style.color= '#666666';
	document.getElementById('ty2_1').style.color= '#666666';
	
	document.getElementById('ty1_2').style.color= '#666666';
	document.getElementById('ty2_2').style.color= '#666666';
}

function selectValType(e){
	clearValType();
	clearValBudget();
	//e.style.color = '#993333';
	document.getElementById(e+'_1').style.color= '#993333';
	document.getElementById(e+'_2').style.color= '#993333';
}

function changeImg(img) {
 
 var big_photo = document.getElementById('big_pict') ;
 big_photo.src = img;
 //big_photo.src = 'miniature.php?pic=../images/normal/'+img+'&w_max=500&h_max=300';
}


function changeDpe() {
 document.getElementById("catDPE").style.display='block';
}


function addToFavorites(url_path,meta_title)
{
//var urlAddress = "http://cluster006.ovh.net/~sainttrox/" + url_path;
var urlAddress = "http://www.saint-tropez-home-finders.com/" + url_path;
var pageName = "Saint Tropez Home Finders - Exclusive properties - Professional service - " + meta_title;
if (window.sidebar)
{ window.sidebar.addPanel(pageName,urlAddress,''); }
else if(window.external)
 { window.external.AddFavorite(urlAddress,pageName); }
}


/*
var map = null;
var geocoder = null;
	
    function load() {
      if (GBrowserIsCompatible()) {
        map = new GMap2(document.getElementById("map"));
        map.removeMapType(G_DEFAULT_MAP_TYPES);
        //map.setCenter(new GLatLng(37.4419, -122.1419), 13);
		geocoder = new GClientGeocoder();
		
        map.addControl(new GLargeMapControl());
 
        var mapControl = new GMapTypeControl();
        map.addControl(mapControl);
		
			
      }
    }
	
	 function showAddress(address) {
      if (geocoder) {
        geocoder.getLatLng(
          address,
          function(point) {
            if (!point) {
              alert("Impossible de localiser l'adresse :\n\n" + address);
            } else {
              map.setCenter(point, 15);
              var marker = new GMarker(point);
              map.addOverlay(marker);
              marker.openInfoWindowHtml(address);
            }
          }
        );
      }
    }

*/
