﻿/*
            This code is to allow Javascript to communcted to the Server in order to update it
*/
 
//
// Define a list of Microsoft XML HTTP ProgIDs.
//
var XMLHTTPREQUEST_MS_PROGIDS = new Array(
  "Msxml2.XMLHTTP.7.0",
  "Msxml2.XMLHTTP.6.0",
  "Msxml2.XMLHTTP.5.0",
  "Msxml2.XMLHTTP.4.0",
  "MSXML2.XMLHTTP.3.0",
  "MSXML2.XMLHTTP",
  "Microsoft.XMLHTTP"
);
 
//
// Define ready state constants.
//
var XMLHTTPREQUEST_READY_STATE_UNINITIALIZED = 0;
var XMLHTTPREQUEST_READY_STATE_LOADING       = 1;
var XMLHTTPREQUEST_READY_STATE_LOADED        = 2;
var XMLHTTPREQUEST_READY_STATE_INTERACTIVE   = 3;
var XMLHTTPREQUEST_READY_STATE_COMPLETED     = 4;
 
//
// Returns XMLHttpRequest object. 
//
function getXMLHttpRequest()
{
  var httpRequest = null;
 
  // Create the appropriate HttpRequest object for the browser.
  if (window.XMLHttpRequest != null)
    httpRequest = new window.XMLHttpRequest();
  else if (window.ActiveXObject != null)
  {
    // Must be IE, find the right ActiveXObject.
    var success = false;
    for (var i = 0;i < XMLHTTPREQUEST_MS_PROGIDS.length && !success;i++)
    {
      try
      {
        httpRequest = new ActiveXObject(XMLHTTPREQUEST_MS_PROGIDS[i]);
        success = true;
      }
      catch (ex)
      {}
    }
  }
 
  // Display an error if we couldn't create one.
  if (httpRequest == null)
    alert("Error in HttpRequest():\n\n"
      + "Cannot create an XMLHttpRequest object.");
 
  // Return it.
  return httpRequest;
}

// JScript File

//Adds text to any part of the body of a HTML
function addNode(tagParent,strText,boolAddToBack, boolRemoveNode)
{
	var strNode = document.createTextNode(strText);//holds the test which will be added
	 
	//gets the properties of the node
	tagParent = getDocID(tagParent);
  
	//checks if the user whats to replace the node in order to start with a clean slate
	//it also checks if there is a chode node to replace
	if (boolRemoveNode == true && tagParent.childNodes.length > 0)
		//replaces the current node with what the user wants
		tagParent.replaceChild(strNode,tagParent.childNodes[0]);
	else
	{
		//checks if the user whats to added to the back of the id or the front
		if(boolAddToBack == true)
			tagParent.appendChild(strNode);
		else
			//This is a built-in function of Javascript will add text to the beginning of the child
			insertBefore(strNode,tagParent.firstChild);
	}//end of if else
  
	//returns the divParent in order for the user to use it for more uses
	return tagParent;
}//end of addNode()
 
//removes from view all tags in tagContainer with the expection of tagActive
//It assumes the tagActive and tagContiner already have the properties
function classToggleLayer(tagContainer,tagActive,strClassName,strTAGName)
{
	var arrTAG = tagContainer.getElementsByTagName(strTAGName);//holds all strTAGName in tagContainer
	
	//goes around the for each tag that getElementsByTagName found in tagContainter
	for(var intIndex = arrTAG.length - 1; intIndex > -1 ; intIndex--) 
	{
				//checks if the class name is the same as strClassName and it is not active if it is active then change the dispaly to block
				if(arrTAG[intIndex].className == strClassName && arrTAG[intIndex].id != tagActive.id)
							arrTAG[intIndex].style.display = arrTAG[intIndex].style.display? "":"";
				else if(arrTAG[intIndex].id == tagActive.id && tagActive.style.display == "")
							arrTAG[intIndex].style.display = arrTAG[intIndex].style.display? "":"block";
	}//end of for loop
}//end of classToggleLayer()

//changes two images are the beginning and end
function changeTwoImages(tagBeginImage,tagEndImage,strBeginImage,strEndImage)
{
	//gets the properties of the tags
	tagBeginImage = getDocID(tagBeginImage);
	tagEndImage = getDocID(tagEndImage);
	
	//checks if there is a tagTarget on the page
	if(tagBeginImage != null && tagEndImage != null)
	{
		//sets the style to be the new iamge
		if(strBeginImage != "" && strEndImage != "")
		{
			//checks if the tagEndImage is the same as the strBegin meaning that they 
			//have already revised and that it needs to go strEndImage to tagEndImage
			//same goes for tagBeginImage
			if(tagEndImage.src.substring(tagEndImage.src.lastIndexOf("/"),tagEndImage.src.length) == strBeginImage.substring(strBeginImage.lastIndexOf("/"),strBeginImage.length))
			{
				tagEndImage.src = strEndImage;
				tagBeginImage.src = strBeginImage;
			}//end of if
			else
			{			
				tagEndImage.src = strBeginImage;
				tagBeginImage.src = strEndImage;
			}//end of else
		}//end of if
	}//end of if
}//end of changeTwoImages()

//decodes str to be a normal string in order to read it
function decodeURL(strDecode)
{
	return unescape(strDecode.replace(/\+/g, " "));
}//end of decodeURL()

//This is ONLY FOR THIS SITE PLEASE REMOVE
//changes the Toggle1 to be either on or off and tagToggle2 to be off all the time
function detectTriggerLayer(tagToggle1, tagToggle2, tagToggleBG1)
{
    //gets the tagToggle1 and tagToggle2 Properties
    tagToggle1 = getDocID(tagToggle1);
    tagToggle2 = getDocID(tagToggle2);
    tagToggleBG1 = getDocID(tagToggleBG1);
        
    if(tagToggle1 != null && tagToggle2 != null && tagToggleBG1 != null)
    {
        tagToggle1.style.display = tagToggle1.style.display? "":"block";
        //tagToggleBG1.style.display = tagToggleBG1.style.display? "":"block";
        tagToggle2.style.display = "none";  
    }//end of if
}//end of detectTriggerLayer()
 
//does the display the a message in a on the page weather then an alert
function displayMessage(tagMessage,strMessText,boolAddToBack, boolRemoveNode)
{
	//gets the message properties and sets the text furthermore it does the display
	tagMessage = addNode(tagMessage,strMessText,boolAddToBack, boolRemoveNode);
	tagMessage.style.display = "block";        
	
	return tagMessage;
}//end of displayMessage()

//encodes str to a URL so it can be sent over the URL address
function encodeURL(strEncode)
{
	var strResult = "";
	
	for (intIndex = 0; intIndex < strEncode.length; intIndex++) {
				if (strEncode.charAt(intIndex) == " ") strResult += "+";
				else strResult += strEncode.charAt(intIndex);
	}
	
	return escape(strResult);
}//end of encodeURL()

//gives the user the message has been sent or not and changes the pop area
function endMessage(strEndMessage,strID,tagMessage,tagGrayOut,tagEMailBody)
{
	var tagPopUpArea = getDocID(strID);//holds the pop up area
	var arrActullyEndMassage = strEndMessage.split("</head>");//gets the acrtully end message because ASP.NET has alot of useless overhead

	//adds some text to the div tag and then displays it to the user
	displayMessage(tagMessage,arrActullyEndMassage[1],true,true);	
	
	//adds in the new line
	tagPopUpArea.appendChild(document.createElement('br'));
	
	//checks if there is the finction was called by the Contact form which does not have a CSS Pop-Up Window
	if (strID != "")
	{
		var tagDIV = document.createElement('div');//holds the DIV tag
		
		//holds the real time div and give its name and align and the link that will close the pop up
		tagDIV.setAttribute('id', "divClose" + strID);
		tagDIV.setAttribute('align', "center");
		tagPopUpArea.appendChild(tagDIV);
	}//end of if
}//end of endMessage()
  
//gets the document properties in order to use them as there are many types of browers with different versions
function getDocID(tagLayer)
{
	var tagProp = "";//holds the proerties of tagLayer
	
	//gets the whichLayer Properties depending of the differnt bowers the user is using
	if (document.getElementById)//this is the way the standards work
		tagProp = document.getElementById(tagLayer);
	else if (document.all)//this is the way old msie versions work
		tagProp = document.all[tagLayer];
	else if (document.layers)//this is the way nn4 works
		tagProp = document.layers[tagLayer];
				
	return tagProp;
}//end of getDocID()

//removes all new lines and replaces them with a <br/> html tag
function nl2br(strText)
{
	//checks if there is anything inside strText
	if (strText != "")
	{
		var re_nlchar = "";//holds the different newlines that the OS uses
		strText = escape(strText);//in codes strText to be more like a URL to find the newlines
			
		//finds the either \r or \n or both since \r is for Linex and Apple and \n is for MS
		if(strText.indexOf('%0D%0A') > -1)
			re_nlchar = /%0D%0A/g ;
		else if(strText.indexOf('%0A') > -1)
			re_nlchar = /%0A/g ;
		else if(strText.indexOf('%0D') > -1)
			re_nlchar = /%0D/g ;
		
		//checks if there is any new lines in strText
		if (re_nlchar != "")
			//changes the strText back to normal with all of the newlines changes to <br/> tag
			return unescape(strText.replace(re_nlchar,'<br />'));
	}//end of if
	
	return strText;
}//end of nl2br()
 
//set up the form to not be used while sending the message
function preSendEMail(tagMessage,tagEMailBody)
{
	//display to the user their message is beening sent and disables the textbox area
	displayMessage(tagMessage,'Sending Message ...',true,true);
	tagEMailBody.style.display = 'none';
}//end of preSendEMail()
 
//sends an email to a Friend of the user who ment what a book
function sendShareEMail(strFileName,tagGrayOut,tagMessage,strPopUpID,tagEMailBody,tagName,tagEMail,tagToName,tagSendTo,strProductName,strURL,tagSentBody)
{                       
	var strFilter = /^.+@.+\..{2,3}$/;//holds the filtter for the Email
	var htmlJavaServerObject = getXMLHttpRequest();//holds the object of the server
	var arrSendTo = tagSendTo.value.split(';');//holds all of the e-mail address that are going to be sent out
	var errorText = "ERROR! I’m sorry, there is a problem with your request. Please complete/revise fields highlighted below. ";
	var someError = "";
		
	//checks senders Name
	if (tagName.value=="")
	{
	    //errorText = errorText + 'You must have a name entered.';
        someError = "true";
        tagName.style.backgroundColor = "#f8a148";
	}
	else
		tagName.style.backgroundColor = "#c9cbcb";
												
	//checks senders E-Mail
	if (tagEMail.value=="")
	{
	    //errorText = errorText + 'You must have e-mail address.';
        someError = "true";
        tagEMail.style.backgroundColor = "#f8a148";
	}
	else
		tagEMail.style.backgroundColor = "#c9cbcb";

	//checks if there the E-Mail Format is current
	if (strFilter.test(tagEMail.value) == false)
	{
	    //errorText = errorText + 'Please input valid e-mail address, for yourself!';
        someError = "true";
        tagEMail.style.backgroundColor = "#f8a148";
    }
	else if (tagEMail.value.match(/[\(\)\<\>\,\;\:\\\/\"\[\]]/))
	{
	    //errorText = errorText + 'Your e-mail address contains illegal characters.';
        someError = "true";
        tagEMail.style.backgroundColor = "#f8a148";
	}
	else
		tagEMail.style.backgroundColor = "#c9cbcb";

	if (tagToName.value=="")
	{
	    //errorText = errorText + 'You must have your friends name entered.';
        someError = "true";
        tagToName.style.backgroundColor = "#f8a148";
	}
	else
		tagToName.style.backgroundColor = "#c9cbcb";

	//checks recepient E-Mail
	if (tagSendTo.value=="")
	{
	    //errorText = errorText + 'You must have e-mail address, that you are sending to.';
        someError = "true";
        tagSendTo.style.backgroundColor = "#f8a148";
	}
	else
		tagSendTo.style.backgroundColor = "#c9cbcb";



	//goes around each e-mail the user entered
	//for(var intIndex = arrSendTo.length - 1; intIndex > -1;intIndex--)
	//{
		//checks if there the E-Mail Format is current
	//	if (strFilter.test(arrSendTo[intIndex]) == false)
	//	{	    
	//	    errorText = errorText + "Please input Valid e-mail address for. " + arrSendTo[intIndex];
    //       someError = "true";
    //        tagSendTo.style.backgroundColor = "#f8a148";
	//	}
	//	else if (arrSendTo[intIndex].match(/[\(\)\<\>\,\;\:\\\/\"\[\]]/))
	//	{
	//	    errorText = errorText + "The e-mail address, " + arrSendTo[intIndex]  + ", that you are sending to, contains illegal Characters.";
    //       someError = "true";
    //        tagSendTo.style.backgroundColor = "#f8a148";
    //   }

	//}//end of for loop

	//checks if there the E-Mail Format is current
	if (strFilter.test(tagSendTo.value) == false)
	{
	    //errorText = errorText + 'Please input valid e-mail address, for yourself!';
        someError = "true";
        tagSendTo.style.backgroundColor = "#f8a148";
    }
	else if (tagSendTo.value.match(/[\(\)\<\>\,\;\:\\\/\"\[\]]/))
	{
	    //errorText = errorText + 'Your e-mail address contains illegal characters.';
        someError = "true";
        tagSendTo.style.backgroundColor = "#f8a148";
	}
	else
		tagSendTo.style.backgroundColor = "#c9cbcb";

	//checks if some error
	if (someError=="true")
	{
   	    displayMessage(tagMessage,errorText,true,true);
        return false;
    }
		
				
	//Abort any currently active request.
	htmlJavaServerObject.abort();
	
	//prepers the form for sending a e-mail
	preSendEMail(tagMessage,tagEMailBody);
	
	// Makes a request
	htmlJavaServerObject.open("Post", strFileName, true);
	htmlJavaServerObject.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
	
	htmlJavaServerObject.onreadystatechange = function(){
		if(htmlJavaServerObject.readyState == 4 && htmlJavaServerObject.status == 200)
		{
			//closes the pop up and removes the textbox so the user cannot use them again until they refresh the page
			endMessage(htmlJavaServerObject.responseText,strPopUpID,tagMessage,tagGrayOut,tagEMailBody);
			
			//resets the tagMessage
			//displayMessage(tagMessage,'',true,true);
			
			//resets the fields and disables the field area
			tagSendTo.value = "";
			tagName.value = "";
			tagToName.value = "";
			tagEMail.value = "";
			
			//means dispapire
			//tagEMailBody.style.display = "";
			
			//gets the properties of tagSentBody
			//tagSentBody = getDocID(tagSentBody);
			
			//turns on the sent message
			//tagSentBody.style.display = "block";
		}//end of if
		else if(htmlJavaServerObject.readyState == 2 && htmlJavaServerObject.status == 500)
		{
			//closes the pop up and removes the textbox so the user cannot use them again until they refresh the page
			endMessage('<head></head>Unable to Connect to the Server.</head>',strPopUpID,tagMessage,tagGrayOut);
		}//end of else if
	}//end of function()
	
	htmlJavaServerObject.send("txtName=" + encodeURL(tagName.value) + "&txtFromEMail=" + encodeURL(tagEMail.value) + "&txtSendTo=" + encodeURL(tagSendTo.value) + "&ProductName=" + encodeURL(strProductName) + "&ProductURL=" + encodeURL(strURL));
							
	return true;
}//end of sendShareEMail()

//sends an email to a Friend of the user who ment what a book
function sendShareEMailContact(strFileName,tagGrayOut,tagMessage,strPopUpID,tagEMailBody,tagFName,tagLName,tagPhone,tagEMail,strToEmail,tagSentBody)
{
	var strFilter = /^.+@.+\..{2,3}$/;//holds the filtter for the Email
	var htmlJavaServerObject = getXMLHttpRequest();//holds the object of the server
	//var arrSendTo = tagSendTo.value.split(';');//holds all of the e-mail address that are going to be sent out
	
	var errorText = "ERROR! I’m sorry, there is a problem with your request. Please complete/revise fields highlighted below. ";
	var someError = "";

				
	//checks if there is an E-mail to send to
	if (strToEmail =="")
	{strToEmail="info@wilmotcreek.ca";
	}
	
	//checks if there is a Name
	if (tagFName.value=="")
	{
	    errorText = errorText + 'You must have a first name entered.';
	    tagFName.style.backgroundColor = "#f8a148";
	    someError="true";
    }
	else
		tagFName.style.backgroundColor = "#c9cbcb";
							
	 //checks if there is a Name
	if (tagLName.value=="")
	{
	    errorText = errorText + 'You must have a last name entered.';
        tagLName.style.backgroundColor = "#f8a148";
	    someError="true";
    }
    else
		tagLName.style.backgroundColor = "#c9cbcb";                                   

	//checks if there is E-Mail
	if (tagEMail.value=="")
	{
	    errorText = errorText + 'You must have e-mail address.';
        tagEMail.style.backgroundColor = "#f8a148";
	    someError="true";
    }
	else
		tagEMail.style.backgroundColor = "#c9cbcb";      
							
	//checks if there the E-Mail Format is current
	if (strFilter.test(tagEMail.value) == false)
	{
        errorText = errorText + 'Please input valid e-mail address, for yourself!';
        tagEMail.style.backgroundColor = "#f8a148";
	    someError="true";
    }
	else if (tagEMail.value.match(/[\(\)\<\>\,\;\:\\\/\"\[\]]/))
	{
        errorText = errorText + 'Your e-mail address contains illegal characters.';
        tagEMail.style.backgroundColor = "#f8a148";
	    someError="true";
    }
	//checks if some error
	if (someError=="true")
	{
   	    displayMessage(tagMessage,errorText,true,true);
        return false;
    }
				
	//Abort any currently active request.
	htmlJavaServerObject.abort();
	
	//prepers the form for sending a e-mail
	preSendEMail(tagMessage,tagEMailBody);
	
	// Makes a request
	htmlJavaServerObject.open("Post", strFileName, true);
	htmlJavaServerObject.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
	
	htmlJavaServerObject.onreadystatechange = function(){
		if(htmlJavaServerObject.readyState == 4 && htmlJavaServerObject.status == 200)
		{
			//closes the pop up and removes the textbox so the user cannot use them again until they refresh the page
			endMessage(htmlJavaServerObject.responseText,strPopUpID,tagMessage,tagGrayOut,tagEMailBody);
			
			//resets the tagMessage
			//displayMessage(tagMessage,'',true,true);
			
			//resets the fields and disables the field area
			tagFName.value = "";
			tagLName.value = "";
			tagEMail.value = "";
			tagPhone.value = "";
			
			//means dispapire
			//tagEMailBody.style.display = "";
			
			//gets the properties of tagSentBody
			//tagSentBody = getDocID(tagSentBody);
			
			//turns on the sent message
			//tagSentBody.style.display = "block";
		}//end of if
		else if(htmlJavaServerObject.readyState == 2 && htmlJavaServerObject.status == 500)
		{
			//closes the pop up and removes the textbox so the user cannot use them again until they refresh the page
			endMessage('<head></head>Unable to Connect to the Server.</head>',strPopUpID,tagMessage,tagGrayOut);
		}//end of else if
	}//end of function()
	
	htmlJavaServerObject.send("txtLName=" + encodeURL(tagLName.value) + "&txtName=" + encodeURL(tagFName.value) + "&txtFromEMail=" + encodeURL(tagEMail.value) + "&txtPhone=" + encodeURL(tagPhone.value) + "&ToEmail=" + encodeURL(strToEmail));
							
	return true;
}//end of sendShareEMailContact()


//sends an email on survey submit
function sendSurvey(strFileName,tagGrayOut,tagMessage,strPopUpID,tagEMailBody,tagFName,tagLName,tagPhone,tagEMail,strToEmail,tagSentBody)
{
	var strFilter = /^.+@.+\..{2,3}$/;//holds the filtter for the Email
	var htmlJavaServerObject = getXMLHttpRequest();//holds the object of the server
	//var arrSendTo = tagSendTo.value.split(';');//holds all of the e-mail address that are going to be sent out

	var errorText = "ERROR! I’m sorry, there is a problem with your request. Please complete/revise fields highlighted below. ";
	var someError = "";

	//checks if there is an E-mail to send to
	if (strToEmail =="")
	{strToEmail="info@wilmotcreek.ca";
	}
	
	//checks if there is a Name
	if (tagFName.value=="")
	{
        errorText = errorText + 'You must have a first name entered.';
    	tagFName.style.backgroundColor = "#f8a148";
	    someError="true";
    }
	else
		tagFName.style.backgroundColor = "#c9cbcb";
							
	 //checks if there is a Name
	if (tagLName.value=="")
	{
        errorText = errorText + 'You must have a last name entered.';
        tagLName.style.backgroundColor = "#f8a148";
	    someError="true";
    }
    else
		tagLName.style.backgroundColor = "#c9cbcb";                                   

	//checks if there is E-Mail
	if (tagEMail.value=="")
	{
        errorText = errorText + 'You must have e-mail address.';
    	tagEMail.style.backgroundColor = "#f8a148";
	    someError="true";
    }
	else
		tagEMail.style.backgroundColor = "#c9cbcb";      
							
	//checks if there the E-Mail Format is current
	if (strFilter.test(tagEMail.value) == false)
	{
        errorText = errorText + 'Please input valid e-mail address, for yourself!';
        tagEMail.style.backgroundColor = "#f8a148";
	    someError="true";
    }
	else if (tagEMail.value.match(/[\(\)\<\>\,\;\:\\\/\"\[\]]/))
	{
        errorText = errorText + 'Your e-mail address contains illegal characters.';
        tagEMail.style.backgroundColor = "#f8a148";
	    someError="true";
    }
	//checks if some error
	if (someError=="true")
	{
   	    displayMessage(tagMessage,errorText,true,true);
        return false;
    }
	
	//checks if they have a Phone
	//if (tagPhone.value=="")
	//{displayMessage(tagMessage,errorText + 'You must have Phone Number.',true,true);
	//tagPhone.style.backgroundColor = "#f8a148";
	//			return false;}
	//else
	//	tagPhone.style.backgroundColor = "#c9cbcb";
				
	//Abort any currently active request.
	htmlJavaServerObject.abort();
	
	//prepers the form for sending a e-mail
	preSendEMail(tagMessage,tagEMailBody);
	
	// Makes a request
	htmlJavaServerObject.open("Post", strFileName, true);
	htmlJavaServerObject.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
	
	htmlJavaServerObject.onreadystatechange = function(){
		if(htmlJavaServerObject.readyState == 4 && htmlJavaServerObject.status == 200)
		{
			//closes the pop up and removes the textbox so the user cannot use them again until they refresh the page
			endMessage(htmlJavaServerObject.responseText,strPopUpID,tagMessage,tagGrayOut,tagEMailBody);
			
			//resets the tagMessage
			//displayMessage(tagMessage,'',true,true);
			
			//resets the fields and disables the field area
			tagFName.value = "";
			tagLName.value = "";
			tagEMail.value = "";
			tagPhone.value = "";
			
			//means dispapire
			tagEMailBody.style.display = "none";
			
			//gets the properties of tagSentBody
			//tagSentBody = getDocID(tagSentBody);
			
			//turns on the sent message
			//tagSentBody.style.display = "block";
		}//end of if
		else if(htmlJavaServerObject.readyState == 2 && htmlJavaServerObject.status == 500)
		{
			//closes the pop up and removes the textbox so the user cannot use them again until they refresh the page
			endMessage('<head></head>Unable to Connect to the Server.</head>',strPopUpID,tagMessage,tagGrayOut);
		}//end of else if
	}//end of function()
	
	htmlJavaServerObject.send("txtLName=" + encodeURL(tagLName.value)
	  + "&txtName=" + encodeURL(tagFName.value) + "&txtFromEMail=" + encodeURL(tagEMail.value) 
	  + "&txtPhone=" + encodeURL(tagPhone.value) + "&ToEmail=" + encodeURL(strToEmail) 
	  + "&f1=" + encodeURL(getDocID('ctl00_ContentPlaceHolderContent_Survey1_lookingfor').value)
	  + "&f2=" + encodeURL(getDocID('ctl00_ContentPlaceHolderContent_Survey1_proximity').value)
	  + "&f3=" + encodeURL(getDocID('ctl00_ContentPlaceHolderContent_Survey1_fully_retired').value)
	  + "&f4=" + encodeURL(getDocID('ctl00_ContentPlaceHolderContent_Survey1_imp_amenities').value));

	return true;
}//end of sendSurvey()



//sends an email on tour request
function sendTourRequest(strFileName,tagGrayOut,tagMessage,strPopUpID,tagEMailBody,tagFName,tagLName,tagPhone,tagEMail,strToEmail,tagSentBody)
{
	var strFilter = /^.+@.+\..{2,3}$/;//holds the filtter for the Email
	var htmlJavaServerObject = getXMLHttpRequest();//holds the object of the server
	//var arrSendTo = tagSendTo.value.split(';');//holds all of the e-mail address that are going to be sent out

	var errorText = "ERROR! I’m sorry, there is a problem with your request. Please complete/revise fields highlighted below. ";
	var someError = "";

	//checks if there is an E-mail to send to
	if (strToEmail =="")
	{strToEmail="info@wilmotcreek.ca";
	}
	
	//checks if there is a Name
	if (tagFName.value=="")
	{
        errorText = errorText + 'You must have a first name entered.';
    	tagFName.style.backgroundColor = "#f8a148";
	    someError="true";
    }
	else
		tagFName.style.backgroundColor = "#c9cbcb";
							
	 //checks if there is a Name
	if (tagLName.value=="")
	{
        errorText = errorText + 'You must have a last name entered.';
        tagLName.style.backgroundColor = "#f8a148";
	    someError="true";
    }
    else
		tagLName.style.backgroundColor = "#c9cbcb";                                   

	//checks if there is E-Mail
	if (tagEMail.value=="")
	{
        errorText = errorText + 'You must have e-mail address.';
    	tagEMail.style.backgroundColor = "#f8a148";
	    someError="true";
    }
	else
		tagEMail.style.backgroundColor = "#c9cbcb";      
							
	//checks if there the E-Mail Format is current
	if (strFilter.test(tagEMail.value) == false)
	{
        errorText = errorText + 'Please input valid e-mail address, for yourself!';
        tagEMail.style.backgroundColor = "#f8a148";
	    someError="true";
    }
	else if (tagEMail.value.match(/[\(\)\<\>\,\;\:\\\/\"\[\]]/))
	{
        errorText = errorText + 'Your e-mail address contains illegal characters.';
        tagEMail.style.backgroundColor = "#f8a148";
	    someError="true";
    }
	
	//checks if some error
	if (someError=="true")
	{
   	    displayMessage(tagMessage,errorText,true,true);
        return false;
    }

	//checks if they have a Phone
	//if (tagPhone.value=="")
	//{displayMessage(tagMessage,errorText + 'You must have Phone Number.',true,true);
	//tagPhone.style.backgroundColor = "#f8a148";
	//			return false;}
	//else
	//	tagPhone.style.backgroundColor = "#c9cbcb";
				
	//Abort any currently active request.
	htmlJavaServerObject.abort();
	
	//prepers the form for sending a e-mail
	preSendEMail(tagMessage,tagEMailBody);
	
	// Makes a request
	htmlJavaServerObject.open("Post", strFileName, true);
	htmlJavaServerObject.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
	
	htmlJavaServerObject.onreadystatechange = function(){
		if(htmlJavaServerObject.readyState == 4 && htmlJavaServerObject.status == 200)
		{
			//closes the pop up and removes the textbox so the user cannot use them again until they refresh the page
			endMessage(htmlJavaServerObject.responseText,strPopUpID,tagMessage,tagGrayOut,tagEMailBody);
			
			//resets the tagMessage
			//displayMessage(tagMessage,'',true,true);
			
			//resets the fields and disables the field area
			tagFName.value = "";
			tagLName.value = "";
			tagEMail.value = "";
			tagPhone.value = "";
			
			//means dispapire
			//tagEMailBody.style.display = "";
			
			//gets the properties of tagSentBody
			//tagSentBody = getDocID(tagSentBody);
			
			//turns on the sent message
			//tagSentBody.style.display = "block";
		}//end of if
		else if(htmlJavaServerObject.readyState == 2 && htmlJavaServerObject.status == 500)
		{
			//closes the pop up and removes the textbox so the user cannot use them again until they refresh the page
			endMessage('<head></head>Unable to Connect to the Server.</head>',strPopUpID,tagMessage,tagGrayOut);
		}//end of else if
	}//end of function()
	
	htmlJavaServerObject.send("txtLName=" + encodeURL(tagLName.value)
	  + "&txtName=" + encodeURL(tagFName.value) + "&txtFromEMail=" + encodeURL(tagEMail.value) 
	  + "&txtPhone=" + encodeURL(tagPhone.value) + "&ToEmail=" + encodeURL(strToEmail));

	return true;
}//end of sendTourRequest



//sends an email on comments
function sendComments(strFileName,tagGrayOut,tagMessage,strPopUpID,tagEMailBody,tagFName,tagLName,tagPhone,tagEMail,strToEmail,tagSentBody)
{
	var strFilter = /^.+@.+\..{2,3}$/;//holds the filtter for the Email
	var htmlJavaServerObject = getXMLHttpRequest();//holds the object of the server
	//var arrSendTo = tagSendTo.value.split(';');//holds all of the e-mail address that are going to be sent out

	var errorText = "ERROR! I’m sorry, there is a problem with your request. Please complete/revise fields highlighted below. ";
	var someError = "";

	//checks if there is an E-mail to send to
	if (strToEmail =="")
	{strToEmail="info@wilmotcreek.ca";
	}
	
	//checks if there is a Name
	if (tagFName.value=="")
	{
        errorText = errorText + 'You must have a first name entered.';
    	tagFName.style.backgroundColor = "#f8a148";
	    someError="true";
    }
	else
		tagFName.style.backgroundColor = "#c9cbcb";
							
	 //checks if there is a Name
	if (tagLName.value=="")
	{
        errorText = errorText + 'You must have a last name entered.';
        tagLName.style.backgroundColor = "#f8a148";
	    someError="true";
    }
    else
		tagLName.style.backgroundColor = "#c9cbcb";                                   

	//checks if there is E-Mail
	if (tagEMail.value=="")
	{
        errorText = errorText + 'You must have e-mail address.';
    	tagEMail.style.backgroundColor = "#f8a148";
	    someError="true";
    }
	else
		tagEMail.style.backgroundColor = "#c9cbcb";      
							
	//checks if there the E-Mail Format is current
	if (strFilter.test(tagEMail.value) == false)
	{
        errorText = errorText + 'Please input valid e-mail address, for yourself!';
        tagEMail.style.backgroundColor = "#f8a148";
	    someError="true";
    }
	else if (tagEMail.value.match(/[\(\)\<\>\,\;\:\\\/\"\[\]]/))
	{
        errorText = errorText + 'Your e-mail address contains illegal characters.';
        tagEMail.style.backgroundColor = "#f8a148";
	    someError="true";
    }
	
	//checks if some error
	if (someError=="true")
	{
   	    displayMessage(tagMessage,errorText,true,true);
        return false;
    }
	
	//checks if they have a Phone
	//if (tagPhone.value=="")
	//{displayMessage(tagMessage,errorText + 'You must have Phone Number.',true,true);
	//tagPhone.style.backgroundColor = "#f8a148";
	//			return false;}
	//else
	//	tagPhone.style.backgroundColor = "#c9cbcb";
				
	//Abort any currently active request.
	htmlJavaServerObject.abort();
	
	//prepers the form for sending a e-mail
	preSendEMail(tagMessage,tagEMailBody);
	
	// Makes a request
	htmlJavaServerObject.open("Post", strFileName, true);
	htmlJavaServerObject.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
	
	htmlJavaServerObject.onreadystatechange = function(){
		if(htmlJavaServerObject.readyState == 4 && htmlJavaServerObject.status == 200)
		{
			//closes the pop up and removes the textbox so the user cannot use them again until they refresh the page
			endMessage(htmlJavaServerObject.responseText,strPopUpID,tagMessage,tagGrayOut,tagEMailBody);
			
			//resets the tagMessage
			//displayMessage(tagMessage,'',true,true);
			
			//resets the fields and disables the field area
			tagFName.value = "";
			tagLName.value = "";
			tagEMail.value = "";
			tagPhone.value = "";
			
			//means dispapire
			//tagEMailBody.style.display = "";
			
			//gets the properties of tagSentBody
			//tagSentBody = getDocID(tagSentBody);
			
			//turns on the sent message
			//tagSentBody.style.display = "block";
		}//end of if
		else if(htmlJavaServerObject.readyState == 2 && htmlJavaServerObject.status == 500)
		{
			//closes the pop up and removes the textbox so the user cannot use them again until they refresh the page
			endMessage('<head></head>Unable to Connect to the Server.</head>',strPopUpID,tagMessage,tagGrayOut);
		}//end of else if
	}//end of function()
	
	htmlJavaServerObject.send("txtLName=" + encodeURL(tagLName.value)
	  + "&txtName=" + encodeURL(tagFName.value) + "&txtFromEMail=" + encodeURL(tagEMail.value) 
	  + "&txtPhone=" + encodeURL(tagPhone.value) + "&ToEmail=" + encodeURL(strToEmail) 
	  + "&f1=" + encodeURL(getDocID('ctl00_Comments1_comments_txt').value));

	return true;
}//end of sendComments






//sends an email on custom listing request
function sendCustomList(strFileName,tagGrayOut,tagMessage,strPopUpID,tagEMailBody,tagFName,tagLName,tagPhone,tagEMail,strToEmail,tagSentBody)
{
	var strFilter = /^.+@.+\..{2,3}$/;//holds the filtter for the Email
	var htmlJavaServerObject = getXMLHttpRequest();//holds the object of the server
	//var arrSendTo = tagSendTo.value.split(';');//holds all of the e-mail address that are going to be sent out

	var errorText = "ERROR! I’m sorry, there is a problem with your request. Please complete/revise fields highlighted below. ";
    var someError = "";

	//checks if there is an E-mail to send to
	if (strToEmail =="")
	{strToEmail="info@wilmotcreek.ca";
	}
	
	//checks if there is a Name
	if (tagFName.value=="")
	{  
	    errorText = errorText + 'You must have a first name entered.';
	    tagFName.style.backgroundColor = "#f8a148";
	    someError="true";
	}
	else
		tagFName.style.backgroundColor = "#c9cbcb";
							
	 //checks if there is a Name
	if (tagLName.value=="")
	{
	    errorText = errorText + 'You must have a last name entered.';
	    tagLName.style.backgroundColor = "#f8a148";
	    someError="true";
    }
	 else
		tagLName.style.backgroundColor = "#c9cbcb";                                   

	//checks if there is E-Mail
	if (tagEMail.value=="")
	{
	    errorText = errorText + 'You must have e-mail address.';
	    tagEMail.style.backgroundColor = "#f8a148";
	    someError="true";
    }
	else
		tagEMail.style.backgroundColor = "#c9cbcb";      
							
	//checks if there the E-Mail Format is current
	if (strFilter.test(tagEMail.value) == false)
	{
	    errorText = errorText + 'Please input valid e-mail address, for yourself!';
        tagEMail.style.backgroundColor = "#f8a148";
	    someError="true";
	}
	else if (tagEMail.value.match(/[\(\)\<\>\,\;\:\\\/\"\[\]]/))
	{   
	    errorText = errorText + 'Your e-mail address contains illegal characters.';
		tagEMail.style.backgroundColor = "#f8a148";
	    someError="true";
	}
	
	//checks if some error
	if (someError=="true")
	{
   	    displayMessage(tagMessage,errorText,true,true);
        return false;
    }
				
	//Abort any currently active request.
	htmlJavaServerObject.abort();
	
	//prepers the form for sending a e-mail
	preSendEMail(tagMessage,tagEMailBody);
	
	// Makes a request
	htmlJavaServerObject.open("Post", strFileName, true);
	htmlJavaServerObject.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
	
	htmlJavaServerObject.onreadystatechange = function(){
		if(htmlJavaServerObject.readyState == 4 && htmlJavaServerObject.status == 200)
		{
			//closes the pop up and removes the textbox so the user cannot use them again until they refresh the page
			endMessage(htmlJavaServerObject.responseText,strPopUpID,tagMessage,tagGrayOut,tagEMailBody);
			
			//resets the tagMessage
			displayMessage(tagMessage,'',true,true);
			
			//resets the fields and disables the field area
			tagFName.value = "";
			tagLName.value = "";
			tagEMail.value = "";
			tagPhone.value = "";
			
			//means dispapire
			tagEMailBody.style.display = "";
			
			//gets the properties of tagSentBody
			//tagSentBody = getDocID(tagSentBody);
			
			//turns on the sent message
			//tagSentBody.style.display = "block";
		}//end of if
		else if(htmlJavaServerObject.readyState == 2 && htmlJavaServerObject.status == 500)
		{
			//closes the pop up and removes the textbox so the user cannot use them again until they refresh the page
			endMessage('<head></head>Unable to Connect to the Server.</head>',strPopUpID,tagMessage,tagGrayOut);
		}//end of else if
	}//end of function()
	
	var rb1="";
	var rb2="";
	var rb3="";
	var rb4="";
	var rb5="";
	var strPost="";
	
	if (getDocID('ctl00_ContentPlaceHolderContent_cList1_RadioButtonList1_0').checked==true) rb1=getDocID('ctl00_ContentPlaceHolderContent_cList1_RadioButtonList1_0').value;
	if (getDocID('ctl00_ContentPlaceHolderContent_cList1_RadioButtonList1_1').checked==true) rb1=getDocID('ctl00_ContentPlaceHolderContent_cList1_RadioButtonList1_1').value;
	if (getDocID('ctl00_ContentPlaceHolderContent_cList1_RadioButtonList1_2').checked==true) rb1=getDocID('ctl00_ContentPlaceHolderContent_cList1_RadioButtonList1_2').value;

	if (getDocID('ctl00_ContentPlaceHolderContent_cList1_RadioButtonList2_0').checked==true) rb2=getDocID('ctl00_ContentPlaceHolderContent_cList1_RadioButtonList2_0').value;
	if (getDocID('ctl00_ContentPlaceHolderContent_cList1_RadioButtonList2_1').checked==true) rb2=getDocID('ctl00_ContentPlaceHolderContent_cList1_RadioButtonList2_1').value;

	if (getDocID('ctl00_ContentPlaceHolderContent_cList1_RadioButtonList3_0').checked==true) rb3=getDocID('ctl00_ContentPlaceHolderContent_cList1_RadioButtonList3_0').value;
	if (getDocID('ctl00_ContentPlaceHolderContent_cList1_RadioButtonList3_1').checked==true) rb3=getDocID('ctl00_ContentPlaceHolderContent_cList1_RadioButtonList3_1').value;

	if (getDocID('ctl00_ContentPlaceHolderContent_cList1_RadioButtonList4_0').checked==true) rb4=getDocID('ctl00_ContentPlaceHolderContent_cList1_RadioButtonList4_0').value;
	if (getDocID('ctl00_ContentPlaceHolderContent_cList1_RadioButtonList4_1').checked==true) rb4=getDocID('ctl00_ContentPlaceHolderContent_cList1_RadioButtonList4_1').value;
	if (getDocID('ctl00_ContentPlaceHolderContent_cList1_RadioButtonList4_2').checked==true) rb4=getDocID('ctl00_ContentPlaceHolderContent_cList1_RadioButtonList4_2').value;

	if (getDocID('ctl00_ContentPlaceHolderContent_cList1_RadioButtonList5_0').checked==true) rb5=getDocID('ctl00_ContentPlaceHolderContent_cList1_RadioButtonList5_0').value;
	if (getDocID('ctl00_ContentPlaceHolderContent_cList1_RadioButtonList5_1').checked==true) rb5=getDocID('ctl00_ContentPlaceHolderContent_cList1_RadioButtonList5_1').value;
	if (getDocID('ctl00_ContentPlaceHolderContent_cList1_RadioButtonList5_2').checked==true) rb5=getDocID('ctl00_ContentPlaceHolderContent_cList1_RadioButtonList5_2').value;

    strPost="txtLName=" + encodeURL(tagLName.value)+ "&txtName=" + encodeURL(tagFName.value) 
        + "&txtFromEMail=" + encodeURL(tagEMail.value) + "&txtPhone=" + encodeURL(tagPhone.value) 
        + "&ToEmail=" + encodeURL(strToEmail) + "&f1=" + encodeURL(rb1) 
        + "&f2=" + encodeURL(rb2) + "&f3=" + encodeURL(rb3) 
        + "&f4=" + encodeURL(rb4) + "&f5=" + encodeURL(rb5);
	htmlJavaServerObject.send(strPost);

	return true;
}//end of sendCustomList()

function getCheckedValue(radioObj) {
	if(!radioObj)
		return "";
	var radioLength = radioObj.length;
	if(radioLength == undefined)
		if(radioObj.checked)
			return radioObj.value;
		else
			return "";
	for(var i = 0; i < radioLength; i++) {
		if(radioObj[i].checked) {
			return radioObj[i].value;
		}
	}
	return "";
}





//starts up the page
function startUp()
{
	var oldonload=window.onload;//holds any prevs onload function from the js file
	
	//gets the onload window event checks if there is a function that is already in there
	window.onload=function(){
		if(typeof(oldonload)=='function')
					oldonload();
					
		//finds which browser the user is using for Firefox it is the defult
		
		//for IE 
		if (navigator.userAgent.indexOf('MSIE') != -1)
		{                                                                                                           
			var tagtour = getDocID('tour');//holds LogIn Hidden
	
			tagtour.style.marginLeft = "350px";
			tagtour.style.left = "-1px";
			
			 var tagtour = getDocID('divTourBG');//holds LogIn Hidden
	
			tagtour.style.marginLeft = "350px";
			tagtour.style.left = "-1px";
		}//end of if
		//for Safari and Mac
		else if (navigator.userAgent.indexOf('Safari') !=-1 || navigator.platform.indexOf("Mac") > -1)
		{
		}//end of if else
		//for firefox
		else if (navigator.userAgent.indexOf('Firefox') !=-1)
		{
		}//end of if else
		//for Opera
		else if (navigator.userAgent.indexOf('Opera') !=-1)
		{
		}//end of if else               
	}//end of window.onload=function()
}//end of startUp()

//shoes and hides a <div> using display:block/none from the CSS
function toggleLayer(tagLayer,tagGrayOut)
{
	var tagStyle = '';//holds the style of tagLayer
	
	//gets the tagLayer and tagGrayOut Properties
	tagStyle = getDocID(tagLayer);
	tagGrayOut = getDocID(tagGrayOut);
	
	if (tagStyle != null){tagStyle.style.display = tagStyle.style.display? "":"block";}
	if (tagGrayOut != null)
	{
		tagGrayOut.style.display = tagGrayOut.style.display? "":"block";
	
		//for IE
		if (navigator.userAgent.indexOf('MSIE') != -1)
		{
			tagGrayOut.attachEvent('onclick',function () {
				toggleLayer(tagStyle.id,tagGrayOut.id)
			});
		}//end of if
		//for the other browsers
		else
		{
			tagGrayOut.addEventListener('click',function () {
				toggleLayer(tagStyle.id,tagGrayOut.id);
			},false);
		}//end of else
	}//end of if
}//end of toggleLayer()

// set the <div> width/height based on image size (child of <div> spec'd by having the attClass class attribute)
// jquery must be included on the page before JScript.js
function setDivDimensions(tagLayer,attClass)
{
	setTimeout(function() {
		layer = $('#' + tagLayer);
		image = $("#floorplan>div." + attClass).children("img");

		imgHeight = image.attr('height');
	
		heightVal = parseInt(imgHeight) + 40;

		document.getElementById(tagLayer).style.height = heightVal + "px";
	}, 0);

	return false; // allow continued processing
}//end of setDivDimensions


function ShowPrevImg() {
 BigImgArray(0);
}

function ShowNextImg() {
 BigImgArray(1);
}
