
function checkHeight(){
	//The purpose of this function is to make sure the footer is at the bottom of the window if 
	// the content is shorter than the window height
	var windowHeight=pageHeight();
	var headerHeight=document.getElementById('headerContainer').offsetHeight;
	var menuHeight=document.getElementById('menuContainer').offsetHeight;
	var footerHeight=document.getElementById('footerContainer').offsetHeight;
	var contentHeight=document.getElementById('contentContainer').offsetHeight;
	var minContentHeight;
	//First, take the height of the window subtract the height of the other divs to figure out
	//  what the minimum contentContainer height should be.
	minContentHeight=windowHeight-headerHeight-menuHeight-footerHeight;
	if(contentHeight<minContentHeight){
		if (document.getElementById) {
			document.getElementById('contentContainer').style.height=minContentHeight+'px';
		}
	}
}


   /** constructor 
   
       @param duration integer seconds
       @param <optional> function to run while waiting.
       
    */
   function pause(numberMillis) {
        var now = new Date();
        var exitTime = now.getTime() + numberMillis;
        while (true) {
            now = new Date();
            if (now.getTime() > exitTime)
                return;
        }
    }




function pageHeight(){
	return  window.innerHeight != null? window.innerHeight : document.documentElement && document.documentElement.clientHeight ?  document.documentElement.clientHeight : document.body != null? document.body.clientHeight : null;
} 

// This function is used to blank out the default contents of the text box. Called onFocus of text boxes.
// itemId = the id of the text box
function blankOut(itemId){
	if(document.getElementById){
		document.getElementById(itemId).value="";
	}
}

// This function is used to put back the default contents of the text box if the user has left it blank. Called onBlur of text boxes.
// itemId = the id of the text box; originalVal = the original 'value' contents
function checkBlank(itemId, originalVal){
	if(document.getElementById){
		textbox = document.getElementById(itemId);
		if(textbox.value==""){
			textbox.value=originalVal;
		}
	}
}


// Current Page Reference
// copyright Stephen Chapman, 1st Jan 2005
// you may copy this function but please keep the copyright notice with it
function getURL(uri) {
	uri.dir = location.href.substring(0, location.href.lastIndexOf('\/'));
	uri.dom = uri.dir; if (uri.dom.substr(0,7) == 'http:\/\/') uri.dom = uri.dom.substr(7);
	uri.path = ''; var pos = uri.dom.indexOf('\/'); if (pos > -1) {uri.path = uri.dom.substr(pos+1); uri.dom = uri.dom.substr(0,pos);}
	uri.page = location.href.substring(uri.dir.length+1, location.href.length+1);
	pos = uri.page.indexOf('?');if (pos > -1) {uri.page = uri.page.substring(0, pos);}
	pos = uri.page.indexOf('#');if (pos > -1) {uri.page = uri.page.substring(0, pos);}
	uri.ext = ''; pos = uri.page.indexOf('.');if (pos > -1) {uri.ext =uri.page.substring(pos+1); uri.page = uri.page.substr(0,pos);}
	uri.file = uri.page;
	if (uri.ext != '') uri.file += '.' + uri.ext;
	if (uri.file == '') uri.page = 'index';
	uri.args = location.search.substr(1).split("?");
	return uri;
}


	function checkSearchEnterKey(keyPressed, boxId){
			
		if(keyPressed.which==13 || keyPressed.keyCode==13){
			document.getElementById('cse-search-box').submit();
			return true;
		}else{
			return false;
		}
	}
	
	function checkEnterKey(keyPressed, boxId){
			
		if(keyPressed.which==13 || keyPressed.keyCode==13){
			document.getElementById('frmLogin').submit();
			return true;
		}else{
			return false;
		}
	}
	
	function clearBoxInter(boxId){
		boxId.type = 'text';
		boxId.value="";
		if(boxId.id=='internationalPass' && boxId.type=='text'){
			pwdBox = document.getElementById('passwd');
			pwdBox.innerHTML="<input id='internationalPass' name='internationalPass' type='password' size='20' width='150px' value='' class='loginTextbox' style='margin-left: 0px;' onKeyUp='checkEnterKey(event,this);' >";
			document.getElementById('internationalPass').focus();
			document.getElementById('frmLogin').elements['internationalPass'].focus();
		}
	}
	
	function clearBox(boxId){
		boxId.type = 'text';
		boxId.value="";
		if(boxId.id=='pwd' && boxId.type=='text'){
			pwdBox = document.getElementById('passwd');
			pwdBox.innerHTML="<input id='advisorPass' name='advisorPass' type='password' size='20' width='150px' value='' class='loginTextbox' style='margin-left: 0px;' onKeyUp='checkEnterKey(event,this);' >";
			document.getElementById('advisorPass').focus();
			document.getElementById('frmLogin').elements['advisorPass'].focus();
		}
	}



function clientSideInclude(id, url) {
  var req = false;
  // For Safari, Firefox, and other non-MS browsers
  if (window.XMLHttpRequest) {
    try {
      req = new XMLHttpRequest();
    } catch (e) {
      req = false;
    }
  } else if (window.ActiveXObject) {
    // For Internet Explorer on Windows
    try {
      req = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
      try {
        req = new ActiveXObject("Microsoft.XMLHTTP");
      } catch (e) {
        req = false;
      }
    }
  }
 var element = document.getElementById(id);
 if (!element) {
  alert("Bad id " + id +
   "passed to clientSideInclude." +
   "You need a div or span element " +
   "with this id in your page.");
  return;
 }
  if (req) {
    // Synchronous request, wait till we have it all
    req.open('GET', url, false);
    req.send(null);
    element.innerHTML = req.responseText;
  } else {
    element.innerHTML =
   "Sorry, your browser does not support " +
      "XMLHTTPRequest objects. This page requires " +
      "Internet Explorer 5 or better for Windows, " +
      "or Firefox for any system, or Safari. Other " +
      "compatible browsers may also exist.";
  }
}



/*********************************************************************************************
 	EMAIL VALIDATION BELOW
**********************************************************************************************/
		
	function echeck(str) {

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		
		if (str.indexOf(at)==-1){
		   alert("Please use a valid email address.");
		   return false;
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert("Please use a valid email address.");
		   return false;
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
			alert("Please use a valid email address.");
		   return false;
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    alert("Please use a valid email address.");
		   return false;
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    alert("Please use a valid email address.");
		   return false;
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    alert("Please use a valid email address.");
		   return false;
		 }
		
		 if (str.indexOf(" ")!=-1){
		    alert("Please use a valid email address.");
		   return false;
		 }

 		 return true					
	}

/*********************************************************************************************/

function checkMatch(id1, id2, err, frmId){
	if(document.getElementById(id1).value!=document.getElementById(id2).value){
		alert(err);
		return false;
	}else{
		document.forms[frmId].submit();
	}		
}

function validateAdvisorRegistration(frmId){
	var strErr = "";
	var emailAddress = document.getElementById("txtEmail").value;
	var firstName = document.getElementById("txtFName").value;
	var lastName = document.getElementById("txtLName").value;
	var pass1 = document.getElementById("txtPass1").value;
	var pass2 = document.getElementById("txtPass2").value;
	
	if(!echeck(emailAddress)){
		return false;	
	}
	
	if(emailAddress.length<=0){
		strErr+="\nEmail Address,";
	}
	
	if(firstName.length<=0){
		strErr+="\nFirst Name,";
	}
	
	if(lastName.length<=0){
		strErr+="\nLast Name,";
	}
	
	if(pass1.length<=0){
		strErr+="\nPassword,";
	}
	
	if(pass2.length<=0){
		strErr+="\nConfirm Password,";
	}
	
	if(strErr.length>0){
		alert("The following mandatory fields were not filled in:" + strErr.substr(0, strErr.length-1));
		return false;	
	}
	
	checkMatch("txtPass1", "txtPass2", "Please ensure passwords match before submitting!", frmId);
	
}


function validateAdvisorUpdate(frmId){
	var strErr = "";
	var emailAddress = document.getElementById("txtEmail").value;
	var firstName = document.getElementById("txtFName").value;
	var lastName = document.getElementById("txtLName").value;
	var pass1 = document.getElementById("txtPass1").value;
	var pass2 = document.getElementById("txtPass2").value;
	
	if(!echeck(emailAddress)){
		return false;	
	}
	
	if(emailAddress.length<=0){
		strErr+="\nEmail Address,";
	}
	
	if(firstName.length<=0){
		strErr+="\nFirst Name,";
	}
	
	if(lastName.length<=0){
		strErr+="\nLast Name,";
	}

	if(strErr.length>0){
		alert("The following mandatory fields were not filled in:" + strErr.substr(0, strErr.length-1));
		return false;	
	}
	
	if(pass1.length>0 || pass2.length>0){		
		checkMatch("txtPass1", "txtPass2", "Please ensure passwords match before submitting!", frmId);
	}else{
		document.forms[frmId].submit();
	}
	
	
}


function validateContactForm(frmId){
	var strErr = "";
	var emailAddress = document.getElementById("txtEmail").value;
	var firstName = document.getElementById("txtFName").value;
	var lastName = document.getElementById("txtLName").value;
	
	if(!echeck(emailAddress)){
		return false;	
	}
	
	if(emailAddress.length<=0){
		strErr+="\nEmail Address,";
	}
	
	if(firstName.length<=0){
		strErr+="\nFirst Name,";
	}
	
	if(lastName.length<=0){
		strErr+="\nLast Name,";
	}

	if(strErr.length>0){
		alert("The following mandatory fields were not filled in:" + strErr.substr(0, strErr.length-1));
		return false;	
	}
	

	document.forms[frmId].submit();
	
}

function validateInternationalRegistration(frmId){
	var strErr = "";
	var emailAddress = document.getElementById("txtEmail").value;
	var firstName = document.getElementById("txtFName").value;
	var lastName = document.getElementById("txtLName").value;
	var pass1 = document.getElementById("txtPass1").value;
	var pass2 = document.getElementById("txtPass2").value;
	var webUserFirm = document.getElementById("ddWebUserFirm").value;
	
	if(!echeck(emailAddress)){
		return false;	
	}
	
	if(webUserFirm.length<=0){
		strErr+="\nVisitor Type,";
	}
	
	if(emailAddress.length<=0){
		strErr+="\nEmail Address,";
	}
	
	if(firstName.length<=0){
		strErr+="\nFirst Name,";
	}
	
	if(lastName.length<=0){
		strErr+="\nLast Name,";
	}
	
	if(pass1.length<=0){
		strErr+="\nPassword,";
	}
	
	if(pass2.length<=0){
		strErr+="\nConfirm Password,";
	}
	
	if(strErr.length>0){
		alert("The following mandatory fields were not filled in:" + strErr.substr(0, strErr.length-1));
		return false;	
	}
	
	checkMatch("txtPass1", "txtPass2", "Please ensure passwords match before submitting!", frmId);
}