/* ************** FONCTION ROLLOVER ************** */

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

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 MM_findObj(n, d) { //v4.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && document.getElementById) x=document.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}


/* FONCTION D'ECRITURE DE FLASH */

function WriteSWF(path, file, width, height, wmode, bgcolor, id){
var EmbedSWF = "<object classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0\" id=\""+id+"\" width=\""+width+"\" height=\""+height+"\"><param name=\"movie\" value=\""+path+file+"\" /><param name=\"quality\" value=\"high\" /><param name=\"menu\" value=\"false\" /><param name=\"wmode\" value=\""+wmode+"\" /><param name=\"bgcolor\" value=\""+bgcolor+"\" /><param name=\"allowScriptAccess\" value=\"sameDomain\" /><embed src=\""+path+file+"\" bgcolor=\""+bgcolor+"\" wmode=\""+wmode+"\" menu=\"false\" quality=\"high\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" type=\"application/x-shockwave-flash\" id=\""+id+"\" name=\""+id+"\" allowScriptAccess=\"sameDomain\" width=\""+width+"\" height=\""+height+"\"></embed></object>";

document.write(EmbedSWF);
}


/* FONCTION DE DÉFINITION DES CALQUES */
function NameDiv(id){
	if(document.all){ doc = document.all[id]; }
	if(document.getElementById){ doc = document.getElementById(id);}
	return doc;
}

/* FONCTION D'AFFICHAGE/MASQUAGE DES ELEMENTS */
// id : id de l'élement
// prop : propriété du display (none, block, inline)
function SetObjProp(id, prop, value){ 
	//alert(id);
	NameDiv(id);
	doc.style[prop] = value;
}

/* FONCTION D'AFFECTATION DE CLASSE AUX ELEMENTS */
// id : id de l'élement
// cssName : nom de la classe
function SetObjCss(id, cssName){
	NameDiv(id);
	doc.className=cssName;
}

/*FONCTION D'AFFICHAGE FORM/VALID DE CONTACT */
var validForm;
function ShowContact(validForm){
	if(validForm=="1"){
		SetObjProp("ContactForm", "display", "none")
		SetObjProp("ContactValidation", "display", "inline")
	} else{
		SetObjProp("ContactForm", "display", "inline")
		SetObjProp("ContactValidation", "display", "none")
	}
	
}
/* FONCTION DE DIAPORAMA THUMBNAILS */

function HilightThumb(id){
	for(i=0; i<PicsData.length; i++){
		if(id == i){
			//alert("I'm in!");
			SetObjProp("thumb"+i, "border", "2px solid #6d594a");
			
		}else{
			//alert("I'm in!");
			SetObjProp("thumb"+i, "border", "2px solid #51b7d2");
			
		}
	}
}

function ShowArrows(id){
	if(id == 0){
		SetObjProp("Prev", "display", "none");
	} else{
		SetObjProp("Prev", "display", "block");
	}
	if(id == PicsData.length-1){
		SetObjProp("Next", "display", "none");
	} else{
		SetObjProp("Next", "display", "block");
	}
}

var lastId;
function Diapo(id){
	if(id == "prev"){ id =  Math.round(lastId-1); }
	if(id == "next"){ id =  Math.round(lastId+1); }
	
	HilightThumb(id);
	ShowArrows(id);
	MM_swapImage('visual','',PicsData[id],1);
	
	//alert("lastId = "+lastId+" - id = "+id);
	lastId = Math.round(id);
}

/* VERIFICATION DE FORMULAIRES */
function checkMail(str) {
	var verif = /^[a-zA-Z0-9\-\_]{1,}[a-zA-Z0-9\.\-\_]*[a-zA-Z0-9\-\_]{1,}@[a-zA-Z0-9]{1,}[a-zA-Z0-9\.\-\_]*[a-zA-Z0-9]{1,}[.][a-zA-Z]{2,4}$/;
	if(verif.test(str)) return true;
	else return false;
}
function CheckForm(id){
	//alert(id);
	var MsgErrors="";
	if(id=="searchform"){
		if(document[id].bien_type.value=="0" && document[id].prix.value=="0" && document[id].commune.value=="0" && document[id].annonces_id.value=="") {
			MsgErrors +="au moins l'un des critères de recherche avant de valider.";
		}
			
	}
	if(id=="contactform"){
		if(document[id].ref.value=="") {
			MsgErrors +=":\n - la référence du bien";
		}
		if(document[id].nomprenom.value=="") {
			MsgErrors +="\n - vos nom et prénom";
		}
		if(document[id].email.value=="") {
			MsgErrors +="\n - votre adresse e-mail";
		}else if(!checkMail(document[id].email.value)) {
			MsgErrors +="\n - une adresse e-mail valide";
		}
		if(document[id].com.value=="") {
			MsgErrors +="\n - votre question et/ou commentaires";
		}
			
	}
	if(MsgErrors !=""){
		alert("Vous devez renseigner "+MsgErrors);	
		return false;
	}else{
		return true;
	}
	
}
