// JavaScript Document


//** GENERAL functions ----------------------------------------------------------------------------  **//
	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.01
	  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 && d.getElementById) x=d.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];}
	}
	
	function popUp(whatPage, winName, w, h, resize, scroll){
		var winT = (screen.height-h)/ 2;
		var winL = (screen.width-w)/ 2;
		winProps = 'height='+h+',width='+w+',top='+winT+',left='+winL+',toolbar=no ,scrollbars='+resize+',resizable='+resize+',status=no';
		wndw = window.open(whatPage,winName,winProps);
		if (parseInt(navigator.appVersion) >= 4) { wndw.window.focus(); }
		wndw.window.focus(); 
	}



//** GENERAL functions ----------------------------------------------------------------------------  **//
function BrowserInfo(){

		this.agent = navigator.userAgent;
		this.version = navigator.appVersion.substr(0,4);
		this.codename = navigator.appCodeName;
		this.javaYes = navigator.javaEnabled();
		this.screenWidth = screen.width;
		this.screenHeight = screen.height;
		
		
		 //--> this.name // Browser name
		if ( (document.all) && (document.getElementById) ){ 
			if (this.agent.lastIndexOf("Opera") != -1) {
				this.name =  "OP"; // opera 7.0 + 
			}else{
				this.name =  "IE"; // IE 4.0+
			} 
		}else if( (!document.all) && (document.getElementById) ){ 
			if (this.agent.lastIndexOf("Firefox") != -1){
				this.name =  "FF"; // Firefox 1.0 + 
			}else if (this.agent.lastIndexOf("Safari") != -1){
				this.name =  "SF";  // Safari 1.0 + 
			}else{
				this.name =  "NN"; // Netscape 6+
			}
		}else if (document.layers){ // Netscape 4
			this.name = "NN4";
		}else{
			this.name = "other"; // not available
		}
		
		 //--> this.platform // Platform name
		if(navigator.appVersion.indexOf("Win") != -1){
		 this.platform = "PC";
		}else if(navigator.appVersion.indexOf("Mac") != -1){
		 this.platform = "Mac";
		}else{ 
		 this.platform = "other";
		}
	}

	var browser = new BrowserInfo();



//** SHARED --> ABOUT THE CASA, ROOMS SECTION ----------------------------------------------------------------------------  **//

var currSection = "";
var currPicNum = "";
var altTags = new Array();
var descriptions = new Array(); // only if we are in  About the Casa > Features section 

function setInitPicVars(aSection, aNum, anArray){
	currSection = aSection;
	currPicNum = aNum;
	altTags = anArray;
}
function setDescriptions(anArray){
	descriptions = anArray;
}

function togglePics(aPicPath, aPicNum){
	mapMsg = (language == "en")? "Click on map to view enlarged image" : "Cliquez sur la photo pour voir l'agrandissement" ;
	// config old thumbnail
	myContent = "";
	myContent += '<a href="javascript:void(0)" onClick="togglePics(\''+aPicPath+'\',\''+currPicNum+'\');return false;"';
	myContent += 'onMouseOut="MM_swapImgRestore();"';
	myContent += 'onMouseOver="MM_swapImage(\'thumb0'+currPicNum+'\',\'\',\''+aPicPath+currPicNum+'_ov.jpg\',1);">';
	myContent += '<img src="'+aPicPath+currPicNum+'_nm.jpg" alt="" name="thumb0'+currPicNum +'" width="80" height="80" border="0">';
	myContent += '</a><br>';
	myContent += '<div align="left">' + altTags[currPicNum] + '</div>'
	document.getElementById("thumb0" + currPicNum + "ID").innerHTML = myContent;
	//congig new thumbnail
	myContent = '<img src="'+aPicPath+aPicNum+'_ov.jpg" alt="" name="thumb0'+aPicNum +'" width="80" height="80" border="0"><br>';
	myContent += '<div align="left">' + altTags[aPicNum] + '</div>'
	document.getElementById("thumb0" + aPicNum + "ID").innerHTML = myContent;
	// config zoom pic
	if (currSection == "features" && aPicNum == 2){ // we wnat to show a zoomed map
		document.getElementById('zoomPicID').innerHTML = '<iframe width="425" height="350" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="http://maps.google.ca/maps?f=q&amp;source=s_q&amp;hl=en&amp;geocode=&amp;q=casabianca&amp;sll=45.515474,-73.585353&amp;sspn=0.011217,0.014591&amp;ie=UTF8&amp;rq=1&amp;ev=zi&amp;radius=0.35&amp;ll=45.516211,-73.584859&amp;spn=0.011592,0.014591&amp;t=h&amp;output=embed"></iframe><br /><small><a href="http://maps.google.ca/maps?f=q&amp;source=embed&amp;hl=en&amp;geocode=&amp;q=casabianca&amp;sll=45.515474,-73.585353&amp;sspn=0.011217,0.014591&amp;ie=UTF8&amp;rq=1&amp;ev=zi&amp;radius=0.35&amp;ll=45.516211,-73.584859&amp;spn=0.011592,0.014591&amp;t=h" style="color:#0000FF; text-align:left">View Larger Map</a></small>';
	}else{
		document.getElementById('zoomPicID').innerHTML = "<img name='zoomPic' src='" + aPicPath + aPicNum + ".jpg' />" ;
	}
	//config breadcrumb ID and decsription ID (About the Casa > Features section only)
	if (currSection == "features"){ // we wnat to show a zoomed map
		//document.getElementById('breadcrumb').innerHTML= altTags[aPicNum];
		document.getElementById('description').innerHTML= descriptions[aPicNum];
	}
	// set var for next use
	currPicNum = aPicNum;
}


//** AJAX SHARED functions ----------------------------------------------------------------------------  **//
function ajaxObj(){ 

        var myObj = false;

        if (window.XMLHttpRequest) {
            myObj = new XMLHttpRequest();
            if (myObj.overrideMimeType) {
                myObj.overrideMimeType('text/xml'); // See note below about this line
            }
        }else if (window.ActiveXObject) { // PC -> IE 5.0 or 6.0
            try {
                myObj = new ActiveXObject("Msxml2.XMLHTTP");
            } catch (e) {
                try {
                    myObj = new ActiveXObject("Microsoft.XMLHTTP");
                } catch (e) {
				}
            }
        }
		
		if (!myObj) {
            return false;
        } else{
			return myObj;
		}
		
}

var http_request  = ajaxObj();


function doAjaxShared (url, outputFunction){ // shared //actually make the ajax call. Called by various doAjax functions. For example, in doAjaxProvinces()
	if (!http_request){
			alert ( (language == "en") ? "Error: An XMLHttpRequest Object could not be made." : "Erreur: L'objet XMLHttpRequest ne peut être créé." );
		}else{
				
				http_request.open('GET',url, true);
				http_request.onreadystatechange = outputFunction;
				http_request.send(null);
		}
}
	
function ajaxLoadingMsg (anElementId){ // shared
		var myContent = (language == "en") ? "Retrieving data......" : "Téléchargement en cours...";
		if (browser.name != "NN4"){ 
				document.getElementById( anElementId ).innerHTML = myContent;
		}else{
				document.layers[ anElementId ].innerHTML = myContent;
		}
}


//** AJAX Specific Functions and Vars- : CONTACT SECTION ---------------------------------------------------------------------//

//----- CONTACT SECTION ---------------------------------------------------------------------//
var myId = "";
function doAjaxContact(aLanguage, url, nameValue, emailValue, subjectValue, commentsValue, outputFunction, actionMsgElementId) {
	    language = aLanguage;
		myId = actionMsgElementId;

		if (nameValue != "" && emailValue != "" && commentsValue != ""){
				doAjaxShared (url+'?lang='+language+'&name='+nameValue+'&email='+emailValue+'&subject='+subjectValue+'&comments='+commentsValue, outputFunction);
		}else{
			var ref = (browser.name != "NN4") ? document.getElementById(myId) : document.layers[ myId ] ; 
			ref.innerHTML = (language == "en") ? "Please fill-in all fields." : "S.V.P. veuillez remplir tous les champs requis.";
		}
	}
	function outputContact(){
        if (http_request.readyState == 4) { // loading complete
		
            if (http_request.status == 200) { // 200 means "OK", 404 means "Not Found"
			
				var doc = JSON.parse(http_request.responseText);
				var msg = doc.msg;
				var ref = (browser.name != "NN4") ? document.getElementById(myId) : document.layers[ myId ] ; 
				if (doc.success && doc.success == "yes"){
					ref.innerHTML = "<font color='#80463A'>" + msg + "</font>";
				}else{
					ref.innerHTML =  msg ; 
				}
			}
            
        }else if (http_request.readyState == 1){ // loading
			ajaxLoadingMsg (myId);
		}

    }