/*
 * Author: Charles Lauzon
 * Name:   Functions_Maison.js
 * Date:   11 Janvier, 2008
 */
 
/********************************************************************
 * 																	*
 *							   MAISON                               *
 *																	*
 ********************************************************************/

//PreloadImage
var arrPreloadImage = new Array();
arrPreloadImage["btn_google"] = new Array(2);
arrPreloadImage["btn_google"][0] = new Image(); arrPreloadImage["btn_google"][0].src = "images/boutton/btnGoogleMap.gif";
arrPreloadImage["btn_google"][1] = new Image(); arrPreloadImage["btn_google"][1].src = "images/boutton/btnGoogleMapOver.gif";

arrPreloadImage["btn_voir_piece"] = new Array(2);
arrPreloadImage["btn_voir_piece"][0] = new Image(); arrPreloadImage["btn_voir_piece"][0].src = "images/boutton/btnVoirDim.gif";
arrPreloadImage["btn_voir_piece"][1] = new Image(); arrPreloadImage["btn_voir_piece"][1].src = "images/boutton/btnVoirDimOver.gif";
arrPreloadImage["btn_voir_photo"] = new Array(2);
arrPreloadImage["btn_voir_photo"][0] = new Image(); arrPreloadImage["btn_voir_photo"][0].src = "images/boutton/btnRetPhoto.gif";
arrPreloadImage["btn_voir_photo"][1] = new Image(); arrPreloadImage["btn_voir_photo"][1].src = "images/boutton/btnRetPhotoOver.gif";

arrPreloadImage["btn_coupdecoeur"] = new Array(2);
arrPreloadImage["btn_coupdecoeur"][0] = new Image(); arrPreloadImage["btn_coupdecoeur"][0].src = "images/boutton/btnCoupsDcoeur.gif";
arrPreloadImage["btn_coupdecoeur"][1] = new Image(); arrPreloadImage["btn_coupdecoeur"][1].src = "images/boutton/btnCoupsDcoeurOver.gif";
arrPreloadImage["btn_imprime_offre"] = new Array(2);
arrPreloadImage["btn_imprime_offre"][0] = new Image(); arrPreloadImage["btn_imprime_offre"][0].src = "images/boutton/btnOffre.gif";
arrPreloadImage["btn_imprime_offre"][1] = new Image(); arrPreloadImage["btn_imprime_offre"][1].src = "images/boutton/btnOffreOver.gif";
arrPreloadImage["btn_imprime_contre_offre"] = new Array(2);
arrPreloadImage["btn_imprime_contre_offre"][0] = new Image(); arrPreloadImage["btn_imprime_contre_offre"][0].src = "images/boutton/btnContreOffre.gif";
arrPreloadImage["btn_imprime_contre_offre"][1] = new Image(); arrPreloadImage["btn_imprime_contre_offre"][1].src = "images/boutton/btnContreOffreOver.gif";
arrPreloadImage["btn_imprime_fiche"] = new Array(2);
arrPreloadImage["btn_imprime_fiche"][0] = new Image(); arrPreloadImage["btn_imprime_fiche"][0].src = "images/boutton/btnFiche.gif";
arrPreloadImage["btn_imprime_fiche"][1] = new Image(); arrPreloadImage["btn_imprime_fiche"][1].src = "images/boutton/btnFicheOver.gif";

arrPreloadImage["btn_fiche_precedent"] = new Array(2);
arrPreloadImage["btn_fiche_precedent"][0] = new Image(); arrPreloadImage["btn_fiche_precedent"][0].src = "images/boutton/btnFichePrecedent.gif";
arrPreloadImage["btn_fiche_precedent"][1] = new Image(); arrPreloadImage["btn_fiche_precedent"][1].src = "images/boutton/btnFichePrecedentOver.gif";
arrPreloadImage["btn_fiche_suivant"] = new Array(2);
arrPreloadImage["btn_fiche_suivant"][0] = new Image(); arrPreloadImage["btn_fiche_suivant"][0].src = "images/boutton/btnFicheSuivant.gif";
arrPreloadImage["btn_fiche_suivant"][1] = new Image(); arrPreloadImage["btn_fiche_suivant"][1].src = "images/boutton/btnFicheSuivantOver.gif";

arrPreloadImage["btn_retour_recherche"] = new Array(2);
arrPreloadImage["btn_retour_recherche"][0] = new Image(); arrPreloadImage["btn_retour_recherche"][0].src = "images/boutton/btnRetourResultat.gif";
arrPreloadImage["btn_retour_recherche"][1] = new Image(); arrPreloadImage["btn_retour_recherche"][1].src = "images/boutton/btnRetourResultatOver.gif";
arrPreloadImage["btn_retour_inscription"] = new Array(2);
arrPreloadImage["btn_retour_inscription"][0] = new Image(); arrPreloadImage["btn_retour_inscription"][0].src = "images/boutton/btnRetourInscription.gif";
arrPreloadImage["btn_retour_inscription"][1] = new Image(); arrPreloadImage["btn_retour_inscription"][1].src = "images/boutton/btnRetourInscriptionOver.gif";

arrPreloadImage["ajaxloading_system_photo"] = new Image(); arrPreloadImage["ajaxloading_system_photo"].src = "images/ajaxloader.gif";

function swapImage(obj, value){
	obj.style.background = "url("+arrPreloadImage[value][1].src+")";
	obj.src = arrPreloadImage[value][1].src;
}

function restoreImage(obj, value){
	obj.style.background = "url("+arrPreloadImage[value][0].src+")";
	obj.src = arrPreloadImage[value][0].src;
}


//Variable Declaration Picture Viewer
var pvOK = false;
var arrPhotoURL_Normal = new Array();
var arrPhotoTitre = new Array();
var tHidePV;

//Afficher les photos
function imgHouseDisplay_onClick(HousePictureId, PhotoIndex, PhotoURL_Normal){
	//Update Photo Description
	document.getElementById("HousePictureDisplay").src = document.getElementById(HousePictureId).src;
	//Update Picture Index
	if(document.getElementById("hPictureIndex")){ document.getElementById("hPictureIndex").value = PhotoIndex; }
	if(document.getElementById("hPictureNormalIndex")){ document.getElementById("hPictureNormalIndex").value = PhotoIndex; }
	//Update Picture [hidden]
	if(document.getElementById("hPictureNormal")){ document.getElementById("hPictureNormal").value = PhotoIndex; }
}
function pictureViewer_Create(p, t){
	//Assignment Array PhotoURL_Normal
	arrPhotoURL_Normal = p.split("|");
	arrPhotoTitre = t.split("|69|");
	//Find wich index the PhotoPrincipaleURL is
	for(var i=0; i < arrPhotoURL_Normal.length; i++){
		if(arrPhotoURL_Normal[i] == document.getElementById("hPictureNormal").value){
			document.getElementById("hPictureIndex").value = i;
			document.getElementById("hPictureNormalIndex").value = i;
		}
	}
	//Update Position
	pictureViewer_UpdatePosition();
	//Picture Viewer is Ready
	pvOK = true;
}
function pictureViewer_Open(){
	//Open Picture Viewer
	if(pvOK){ //Check if pv is Ready
		//Update Picture [Normal]
		document.getElementById("pv_p").src = "http://www.casavisit.com/photos/"+document.fMaison.MaisonId.value+"/"+arrPhotoURL_Normal[document.getElementById("hPictureNormalIndex").value];
		//Update Picture Title
		document.getElementById("pv_p_t").innerHTML = arrPhotoTitre[document.getElementById("hPictureNormalIndex").value];
		//Update Picture Index
		document.getElementById("hPictureIndex").value = document.getElementById("hPictureNormalIndex").value;
		//Show Picture Viewer
		document.getElementById("pv_shadow").style.visibility = "visible"; //Shadow
		document.getElementById("pv").style.visibility = "visible"; //Box
		//Update Position
		pictureViewer_UpdatePosition();
	}
}
function pictureViewer_Close(){
	if(tHidePV){
		//Update Picture [Loading]
		document.getElementById("pv_p").src = arrPreloadImage["ajaxloading_system_photo"].src;
		document.getElementById("pv_p").src = document.getElementById("pv_p").src;
		//Hide Picture Viewer
		document.getElementById("pv_shadow").style.visibility = "hidden"; //Shadow
		document.getElementById("pv").style.visibility = "hidden"; //Box
		document.getElementById("pv_n_b").style.visibility = "hidden"; //Navi Back
		document.getElementById("pv_n_n").style.visibility = "hidden"; //Navi Next
	}
}
function pictureViewer_Back(){
	//Update Picture [Loading]
	document.getElementById("pv_p").src = arrPreloadImage["ajaxloading_system_photo"].src;
	document.getElementById("pv_p").src = document.getElementById("pv_p").src;
	//Update Picture [hidden]
	document.getElementById("hPictureNormal").value = arrPhotoURL_Normal[document.getElementById("hPictureBack").value];
	//Update Picture [Normal]
	document.getElementById("pv_p").src = "http://www.casavisit.com/photos/"+document.fMaison.MaisonId.value+"/"+document.getElementById("hPictureNormal").value;
	//Update Picture Title
	document.getElementById("pv_p_t").innerHTML = arrPhotoTitre[document.getElementById("hPictureBack").value];
	//Update Position
	document.getElementById("hPictureIndex").value = document.getElementById("hPictureBack").value;
	pictureViewer_UpdatePosition();
}
function pictureViewer_Next(){
	//Update Picture [Loading]
	document.getElementById("pv_p").src = arrPreloadImage["ajaxloading_system_photo"].src;
	document.getElementById("pv_p").src = document.getElementById("pv_p").src;
	//Update Picture [hidden]
	document.getElementById("hPictureNormal").value = arrPhotoURL_Normal[document.getElementById("hPictureNext").value];
	//Update Picture [Normal]
	document.getElementById("pv_p").src = "http://www.casavisit.com/photos/"+document.fMaison.MaisonId.value+"/"+document.getElementById("hPictureNormal").value;	
	//Update Picture Title
	document.getElementById("pv_p_t").innerHTML = arrPhotoTitre[document.getElementById("hPictureNext").value];	
	//Update Position
	document.getElementById("hPictureIndex").value = document.getElementById("hPictureNext").value;
	pictureViewer_UpdatePosition();
}
function pictureViewer_UpdatePosition(){
	//Hide Navi
	document.getElementById("pv_n_b").style.visibility = "hidden"; //Navi Back
	document.getElementById("pv_n_n").style.visibility = "hidden"; //Navi Next
	//Check for Position [Update]
	if(document.getElementById("hPictureIndex").value == 0){ //First Place
		//Set Variable
		document.getElementById("hPictureBack").value = -1;
		document.getElementById("hPictureNext").value = 1;
		//Show Next
		if(arrPhotoURL_Normal.length > 1){
			document.getElementById("pv_n_n").style.visibility = "visible";
		}
	}else if(document.getElementById("hPictureIndex").value == arrPhotoURL_Normal.length -1){ //Last Place
		//Set Variable
		document.getElementById("hPictureBack").value = arrPhotoURL_Normal.length - 2;
		document.getElementById("hPictureNext").value = -1;
		//Show Back
		document.getElementById("pv_n_b").style.visibility = "visible";
	}else{ //Dans le Milieu
		//Set Variable
		document.getElementById("hPictureBack").value = (parseInt(document.getElementById("hPictureIndex").value) - 1);
		document.getElementById("hPictureNext").value = (parseInt(document.getElementById("hPictureIndex").value) + 1);
		//Show Back & Next
		document.getElementById("pv_n_b").style.visibility = "visible";
		document.getElementById("pv_n_n").style.visibility = "visible";
	}
	//Update Status
	document.getElementById("pic_viewer_status").innerHTML = (parseInt(document.getElementById("hPictureIndex").value) + 1) + " / " + arrPhotoURL_Normal.length;
}
function pictureViewerShadow_Resize(){
	var theWidth, theHeight;
	var obj = document.getElementById('pv_shadow');
	//Window Dimensions: 
	if(window.innerWidth){ theWidth=window.innerWidth; }
	else if(document.documentElement && document.documentElement.clientWidth){ theWidth=document.documentElement.clientWidth; }
	else if(document.body){	theWidth=document.body.clientWidth; }
	if(window.innerHeight){ theHeight=window.innerHeight; }
	else if(document.documentElement && document.documentElement.clientHeight){ theHeight=document.documentElement.clientHeight; }
	else if(document.body){ theHeight=document.body.clientHeight; }
	obj.style.height = Math.max(document.body.scrollHeight,theHeight)+'px';
	//obj.style.width  = Math.max(document.body.scrollWidth,theWidth)+'px';
	obj.style.width  = Math.max(1024,theWidth)+'px';
}
//timer pour partir la fermeture du menu
function startTimer_hidePV(){
	tHidePV = setTimeout("pictureViewer_Close()", 100);
}
//arrete le timer
function stopTimer_hidePV(){
	tHidePV = null;
}


//House voir les dimensions de la maison
function btnVoirDimension_onClick(){
	document.getElementById("ModePhoto").style.display = "none";
	document.getElementById("ModeDimension").style.display = "block";	
	document.getElementById("txtTitrePhoto").innerHTML = "Dimension des pièces";
}
//House voir les photos de la maison
function btnRetourPhoto_onClick(){
	document.getElementById("ModePhoto").style.display = "block";
	document.getElementById("ModeDimension").style.display = "none";
	document.getElementById("txtTitrePhoto").innerHTML = "Cliquez et visionnez";
}

/* COUP DE COEUR */
//btnCoupDeCoeur Add onClick ajoute un coup de coeur
function btnCoupDeCoeur_Add_onClick(MembreId, MaisonId){
	if(MembreId != 0){
		Initialize();

		var url="../includes/coupdecoeur_modifier.php?MaisonId="+MaisonId+"&Action=ADD&DATE="+d;
		if(req!=null){
			req.onreadystatechange = Process_CoupDeCoeur_Add;
			req.open("GET", url, true);
			req.send(null);
		}	
	}
	else{
		//alert("C\'est option est pour les MEMBRES SEULEMENT. Veuillez vous enregistrer, c\'est GRATUIT et surtout PRATIQUE!");
		if(confirm("C\'est option est pour les MEMBRES SEULEMENT. Cliquer sur OK pour vous connectez sinon, cliquer sur Annuler pour vous inscrire, c\'est GRATUIT et surtout PRATIQUE!")){
			document.getElementById("ls").style.visibility = "visible";
			//Put Focus
			if(document.fLogin_System.txtMembreId.value == "Adresse courriel" || document.fLogin_System.txtMembreId.value == ""){
				document.fLogin_System.txtMembreId.focus();
			}else{
				document.fLogin_System.txtPassword.focus();
			}
		}else{
			window.location = "inscription.php";
		}
	}
}
function Process_CoupDeCoeur_Add(){
    if (req.readyState == 4){
    // only if "OK"
        if (req.status == 200){
            if(req.responseText==""){
				//HideDiv("spokland_account_account_info");
			}
            else{
				var Msg = req.responseText;
				if(Msg == "ADD"){
					alert("Cette demeure est AJOUTÉE à vos coups d\'coeurs.");
				}else if(Msg == "ALLREADY"){
					alert("Cette maison est DÉJÀ AJOUTÉE à vos coups d\'coeurs!");
				}
            }
        }
        else{
            document.getElementById("lblErreur").innerHTML = "There was a problem retrieving data: " + req.statusText;
        }
    }
}

function btnFiche_onClick(MaisonId){
	var pageURL = "includes/imprimer_la_fiche.php?MaisonId=" + MaisonId;
	pageImprimerMaFiche = window.open(pageURL, "pageImprimerMaFiche", "width=1000, height=1000, top=0, left=0 toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no");
}

function btnEnveloppe_onClick(MembreId, MaisonId, ProprioEmail, ProprioName, NoMaison, Ville, Style){
	if(MembreId != 0){
		var pageURL = "includes/courriel_membre.php?MaisonId=" + MaisonId + "&ProprioEmail=" + ProprioEmail + "&ProprioName=" + ProprioName + "&NoMaison=" + NoMaison + "&Ville=" + Ville + "&Style=" + Style;
		pageCourrielMembre = window.open(pageURL, "pageCourrielMembre", "width=625, height=310, toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no");
	}else{
		//alert("Vous devez être MEMBRE pour utiliser cette option... C\'est pratique et TOTALEMENT GRATUIT!");			
		if(confirm("Vous devez être connecté pour faire parvenir un courriel.\nVeuillez appuyer sur OK pour vous connecter en tant que membre ou cliquer sur CANCEL pour vous inscrire; C\'est gratuit et surtout pratique!")){
			document.getElementById("ls").style.visibility = "visible";
			//Put Focus
			if(document.fLogin_System.txtMembreId.value == "Adresse courriel" || document.fLogin_System.txtMembreId.value == ""){
				document.fLogin_System.txtMembreId.focus();
			}else{
				document.fLogin_System.txtPassword.focus();
			}
		}else{
			window.location = "inscription.php";
		}
	}
}	

function btnOffre_onClick(){
	window.location = "formulaire.php";
}

function btnNext1_onClick(){
	document.fMaison.hFiche.value = (parseInt(document.fMaison.hFiche.value) - 1);
	document.fMaison.action = "recherche_resultat.php";
	document.fMaison.submit();
}

function btnNext2_onClick(){
	document.fMaison.hFiche.value = (parseInt(document.fMaison.hFiche.value) + 1);
	document.fMaison.action = "recherche_resultat.php";
	document.fMaison.submit();
}

function btnRetourResultat_onClick(){
	document.fMaison.hFiche.value = -1;
	document.fMaison.action = "recherche_resultat.php";
	document.fMaison.submit();
}

function btnRetourProfil_onClick(){
	document.fMaison.action = "profil.php";
	document.fMaison.submit();
}

function btnCalculatrice_onClick(VariableCoder){
	var pageURL = "http://www.casavisite.com/calculatrice.php?X="+VariableCoder;
	//alert(pageURL);
	pageCalculatrice = window.open(pageURL, "pageCalculatrice", "left=200, top=100, width=280, height=390, fullscreen=no, status=no, toolbar=no, location=no, directories=no, menubar=no, scrollbars=no, resizable=yes, titlebar=no");
}