
/*
	Fonction qui coche toutes les radio d'une zone
*/
function check_all(node_)
{
	for(var i=0; i<node_.childNodes.length; i++) {
		if(node_.childNodes[i].nodeName=="INPUT") {
			node_.childNodes[i].checked=true;
		} else {
			//sinon, on fouille plus bas
			check_all(node_.childNodes[i]);
		}
	}
}

/*
	Fonction qui décoche toutes les radio d'une zone
*/
function uncheck_all(node_)
{
	for(var i=0; i<node_.childNodes.length; i++) {
		if(node_.childNodes[i].nodeName=="INPUT") {
			node_.childNodes[i].checked=false;
		} else {
			//sinon, on fouille plus bas
			uncheck_all(node_.childNodes[i]);
		}
	}
}

/*
Fonction qui permet d'activer un rollOver sur des éléments dont on donne la balise
Actuellement, c'est ligneOver et ligneNormal qu'il faut utiliser
*/
function makeOver(node_, nodeName_) {
	for(var i=0; i<node_.childNodes.length; i++) {
		if(node_.childNodes[i].nodeName==nodeName_) {
			//assignation des actions
			node_.childNodes[i].onmouseover = ligneOver;
			node_.childNodes[i].onmouseout = ligneOut;
		} else {
			//sinon, on fouille plus bas
			makeOver(node_.childNodes[i], nodeName_);
		}
	}
}

/*
Fonction similaire qui utilise les 2 mêmes styles, mais qui permet de faire un talbeau avec les lignes une couleur sur 2
*/
var odd=0;
//variable qui permet de compter les lignes assignées pour faire le décalage des classes

function makeOdd(node_, nodeName_) {

	for(var i=0; i<node_.childNodes.length; i++) {
		if(node_.childNodes[i].nodeName==nodeName_) {
			//assignation des classes
			if(odd%2>0) {
				node_.childNodes[i].className =  "ligneOver";
			} else {
				node_.childNodes[i].className =  "ligneNormal";
			}
			odd++;
		} else {
			//sinon, on fouille plus bas
			makeOdd(node_.childNodes[i], nodeName_);
		}
	}
}

//fonction de rollOver
function ligneOver() {
	this.className = "ligneOver";
}

function ligneOut() {
	this.className = "ligneNormal";
}
//=======================================================================


function my_confirm(text_, url_) {
	rep=confirm(text_);
	if(rep) document.location=url_;
}

function show_hide(obj_) {
	obj = document.getElementById(obj_);
	if(obj.style.display == '') obj.style.display = 'none';
	else obj.style.display = '';
}

var old_obj=null;
function show_hide2(obj_) {
	obj = document.getElementById(obj_);
	if(obj.style.display == '') obj.style.display = 'none';
	else obj.style.display = '';

	//de plus, on change l'ancien objet si on en a un
	if(old_obj && old_obj!=obj) {
		old_obj.style.display='none';
	}

	//mémorisation de l'ancien objet
	old_obj = obj;
}

/*
test de radio bouton
*/
function radiotest(node) {
	for (var i=0; i<node.length;i++) {
		if( node[i].checked )
		{
		var select = node[i].value;
		break;
		}
	}
	return select;
}

function PopupImage(img)
{
    w=open("",'image','toolbar=no,scrollbars=auto,resizable=no');
    w.document.write("<html><head><title></title></head>");
    w.document.write("<SCRIPT language=javascript>function ejs_nodroit() {return(false);}document.oncontextmenu = ejs_nodroit;function checksize()  { if (document.images[0].complete) {  window.resizeTo(document.images[0].width,document.images[0].height+80); window.focus();} else { setTimeout('check()',250) } }</"+"SCRIPT>");
    w.document.write("<body onload='checksize()' leftMargin=0 topMargin=0 marginwidth=0 marginheight=0 scrolling=no><img src='"+img+"' border=0>");
    w.document.write("");
    w.document.write("</body></html>");
    w.document.close();
}


//---------------------------- ZOOM ----------------------
var zoomToCheck;
var zommFen=null;
function openZoom(img_) {
	//si une fenetre zoom est déjà ouverte, on la ferme
	if(zommFen!=null) {
		zommFen.close();
	}

	fen=window.open("", "", "resizable=yes, scrollbars=auto, width=500, height=500");
	if(!fen) {
		alert("Attention, votre navigateur a bloqué la fenêtre, merci d'autoriser les popups pour ce site.");
	} else {
		fen.document.write("<html><body><img src='"+img_+"' ></body></html>");

		zoomFen=fen;
		zoomToCheck = fen.document.images[0]
		checkLoadZoom();
		//fen.document.close();
	}
}

function checkLoadZoom() {
	if(zoomToCheck.complete) {
		zoomFen.resizeTo(zoomToCheck.width+40, zoomToCheck.height+80);
		zoomFen.focus();
	} else {
		setTimeout('checkLoadZoom()',250);
	}
}
//----------------------- <<< ZOOM -----------------------

function run_flash(url,width,height, wmode)
{
	/*
	document.write('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="'+width+'" height="'+height+'" id="home" align="middle">\n');
	document.write('<param name="movie" value="'+url+'">\n');
	document.write('<embed src="'+url+'" width="'+width+'" height="'+height+'" type="application/x-shockwave-flash">\n');
	document.write('</embed>\n');
	document.write('</object>\n');
*/
	document.write('<object type=\"application/x-shockwave-flash\" data=\"'+url+'" width="'+width+'" height="'+height+'">');
	document.write('<param name="movie" value="'+url+'" />');
	document.write('<param name="wmode" value="'+wmode+'" />');
	document.write('</object>');

}

//----------------------- >>> VALIDATION -----------------------

/* Fonction de validation de formulaires */
function validateForm(form_obj_) {

	// Config des formulaires
	var validateFormConf = new Array();
	validateFormConf['form1'] = [
		'd_typeBien1',
		'd_typeBien2',
		'd_nbpieceBien',
		'd_nbchambreBien',
		'd_sufaceBien',
		'd_nbetagesminBien',
		'd_codepostalBien',
		'd_communeBien',
		'd_annonceurType',
		'd_nomAnnonceur',
		'd_prenomAnnonceur',
		'd_telAnnonceur',
		'd_emailAnnonceur',
		'd_prixBien'];
	
		validateFormConf['form2'] = [
			'nom',
			'email' 
		]
		
		
	var validateFormText = new Array();
	validateFormText['d_typeBien1'] = "Type de Bien";
	validateFormText['d_typeBien2'] = "Catégorie de Bien";
	validateFormText['d_nbpieceBien'] = "Nombre de pièces";
	validateFormText['d_nbchambreBien'] = "Nombre de chambres";
	validateFormText['d_sufaceBien'] = "Surface";
	validateFormText['d_nbetagesminBien'] = "Etage";
	validateFormText['d_codepostalBien'] = "Code postal";
	validateFormText['d_communeBien'] = "Ville";
	validateFormText['d_annonceurType'] = "Type de l'annonceur (Particulier ou Professionnel)";
	validateFormText['d_nomAnnonceur'] = "Nom de l'annonceur";
	validateFormText['d_prenomAnnonceur'] = "Prénom de l'annonceur";
	validateFormText['d_telAnnonceur'] = "Téléphone de l'annonceur";
	validateFormText['d_emailAnnonceur'] = "Adresse e-mail de l'annonceur";
	validateFormText['d_prixBien'] = "Prix / Loyer";
	validateFormText['nom'] = "Nom";
	validateFormText['email'] = "Adresse e-mail";

	
	//erreur à 0 au début
	error = 0;
	list_fields = "";
	
	/*
	if (form_obj_['d_typeBien1'].value == ''){
		form_obj_['d_typeBien1'].value = form_obj_['typeBien1b'].value;

		alert("typeBien");
		alert(form_obj_['typeBien1b'].value);
		alert(form_obj_['d_typeBien1'].value);

	}
	*/
	if(form_obj_.name== 'form1'){
		typebienindex = "typeBien1_" + form_obj_['d_transactionType'].value;
		form_obj_['d_typeBien1'].value = form_obj_[typebienindex].value;
	}
	
	for(i=0; i<validateFormConf[form_obj_.name].length; i++) {
		index = validateFormConf[form_obj_.name][i];

		//Vérification des radios
		if(index=='d_annonceurType' && !radiotest(form_obj_[index])) {
			error++;
			list_fields += "- "+validateFormText[index]+"\n";
		}else if(form_obj_[index].value=='') {
			//Vérif des autres champs
			error++;
			list_fields += "- "+validateFormText[index]+"\n";
			//Bonus pour ces champs
			form_obj_[index].className="error";
		} else {
			//Status normal
			form_obj_[index].className="required";
		}
	}
	
	if(error>0) {
		alert("Veuillez remplir tous les champs obligatoires ou bien les formater : \n" + list_fields);
		return false;
	}
	else {
		if (form_obj_['d_prixBien'].value==0){
			alert("Le Prix / Loyer de votre bien doit être différent de 0 !");
			return false;
		}
		else return true;
	}
}

//----------------------- <<< VALIDATION -----------------------
