function getAjaxRequestVariable() { 
	try { netscape.security.PrivilegeManager.enablePrivilege("UniversalBrowserRead");} 
	catch (e) {} 
	try {                     ajaxRequest = new XMLHttpRequest();}                // Opera 8.0+, Firefox, Safari
	catch (e) { try {         ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");} // Internet Explorer Browsers
	        catch (e) { try { ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");} 
	                catch (e) {alert("Your browser broke!"); return false;        // Something went wrong
	}       }       }
	return ajaxRequest; 
} 
function turnVisibilityOff() {
	document.getElementById("addressID").style.visibility='hidden'; 
	document.getElementById("addressID").style.display="none"; 
	document.getElementById("propertyID").style.visibility='hidden'; 
	document.getElementById("propertyID").style.display="none"; 
	document.getElementById("reviewID").style.visibility='hidden'; 
	document.getElementById("reviewID").style.display="none"; 
	if (1) { //this turns on and off the data values for debugging 1=live, 0=debug
    document.getElementById("dataID").style.visibility='hidden'; 
    document.getElementById("dataID").style.display="none"; 
  } else {
    document.getElementById("dataID").style.visibility='visible'; 
    document.getElementById("dataID").style.display="block"; 
  }
	document.getElementById("step4Graph").style.visibility='hidden'; 
	document.getElementById("step4Graph").style.display="none"; 
}
function turnVisibilityOn(aControl) {
	document.getElementById(aControl).style.visibility='visible'; 
	document.getElementById(aControl).style.display="block"; 
}
function setVisability(aControl) {
	turnVisibilityOff();
	turnVisibilityOn(aControl);
}

function setVisibilityStep1() { 
  setVisability("addressID");
  document.getElementById("DATA_location").value = ""; 
  document.getElementById("DATA_asa").value = "";
  document.getElementById("DATA_domXML").value = "";
  document.getElementById("DATA_chartXML").value = "";
  document.getElementById("PROP_address_status").value = 0;
  setStep2Button(0);
  
} 
function setVisibilityStep2() { 
  if (isStep1Complete()) {
    isValidAddress(); 
    setVisability("propertyID");
  } 
}
function setVisibilityStep3() {
  if (isStep2Complete() == 1) {
    setVisability("reviewID");
    mnsShowReview();
  }
} 
function setVisibilityStep4() { 
  setVisability("step4Graph"); 
  buildDataFromASA();
  //adjustCredits(0);
} 

function setBackground(aControlID,aColor) {
	document.getElementById(aControlID).style.background=getColorNumber(aColor);
}

function setStatus(aControlID,aColor) {
	switch (aColor.toLowerCase()) {
		case 'red': 	value = -1; break;
		case 'yellow':	value =  0; break;
		case 'green':	value =  1; break;
		default:	value = -1;
	}
	lControlID = aControlID + '_status';
	document.getElementById(lControlID).value=value;
	lControlID = aControlID + '_img';
	setStatusButton(lControlID,aColor);
}

function validateField(aControlID) {
	var curString = document.getElementById(aControlID).value;
//	var r = new RegExp("[<|>|"|'|%|;|(|)|&|+|-]", "i"); 
	var isValid = 1;
	var testExp = 1;
	var curPage;
	var expString;
	switch (aControlID) {
		case 'AD_email':        curPage = 'AD';   expString = /.+@.+\.[a-z]{2}([a-z]?)$/; break;
		case 'AD_address':      curPage = 'AD';   expString = /^\d+ .+$/;                 break;
		case 'AD_city':         curPage = 'AD';   expString = /.+/;                       break;
		case 'AD_state':        curPage = 'AD';   expString = /.+/;                       break;
		case 'AD_zip':          curPage = 'AD';   expString = /^\d{5}$/;                  break;
		case 'PROP_acres':      curPage = 'PROP'; expString = /^(\d*)(\.?)(\d*)$/;        break;
		case 'PROP_sqfeet':     curPage = 'PROP'; expString = /^\d+$/;                    break;
		case 'PROP_beds':       curPage = 'PROP'; expString = /^\d+$/;                    break;
		case 'PROP_baths':      curPage = 'PROP'; expString = /^(\d*)(\.?)(\d*)$/;        break;
		case 'PROP_age':        curPage = 'PROP'; expString = /^[12][890][0-9][0-9]$/;    break;
		case 'ACNT_name':       curPage = 'ACNT'; expString = /.+/;                       break;
		case 'ACNT_username':   curPage = 'ACNT'; expString = /.+/;                       break;
		case 'ACNT_email':      curPage = 'ACNT'; expString = /.+@.+\.[a-z]{2}([a-z]?)$/; break;
		case 'ACNT_brokerage':  curPage = 'ACNT'; expString = /.+/;                       break;
		case 'ACNT_password':   curPage = 'ACNT'; expString = /.+/;                       break;
		case 'ACNT_password2':  curPage = 'ACNT'; expString = new RegExp('^' + document.getElementById("ACNT_password").value + '$'); break;
		case 'ACNT_license':    curPage = 'ACNT'; expString = /.+/;                       break;
		case 'ACNT_licensetype':curPage = 'ACNT'; expString = 'droplist';                 break;
		case 'ACNT_eula':       curPage = 'ACNT'; expString = 'checkbox';                 break;
		case 'RMD_email':       curPage = 'RMD';  expString = /.+@.+\.[a-z]{2}([a-z]?)$/; break;
		case 'PREF_name':       curPage = 'PREF'; expString = /.+/;                       break;
		case 'PREF_username':   curPage = 'PREF'; expString = /.+/;                       break;
		case 'PREF_email':      curPage = 'PREF'; expString = /.+@.+\.[a-z]{2}([a-z]?)$/; break;
		case 'PREF_brokerage':  curPage = 'PREF'; expString = /.+/;                       break;
		case 'PREF_password':   curPage = 'PREF'; expString = /.+/;                       break;
		case 'PREF_password1':  curPage = 'PREF'; expString = /.+/;                       break;
		case 'PREF_password2':  curPage = 'PREF'; expString = new RegExp('^' + document.getElementById("PREF_password1").value + '$'); break;
		case 'PREF_license':    curPage = 'PREF'; expString = /.+/;                       break;
		case 'PREF_licensetype':curPage = 'PREF'; expString = 'droplist';                 break;
		default:	    expString = /.+/;
	}
  switch (expString) {
    case 'checkbox':
      if (document.getElementById(aControlID).value == 0) {
        isValid = 'green';
        document.getElementById(aControlID).value = 1;
      } else {
        isValid = 'red';
        document.getElementById(aControlID).value = 0;
      }
      break;
    case 'droplist':
      if (document.getElementById(aControlID).value == 0) {isValid = 'red';} 
      else                                                {isValid = 'green';}
      break;
    default:
    	if (curString.search(expString) == -1) {isValid = 'red';} 
    	else                                   {isValid = 'green';}
    	break;
  }

  setStatus(aControlID, isValid);
	switch (curPage) {
		case 'AD':
			lControlID_status = 'AD_go2step2_status';
			lControlID = 'AD_go2step2';
			if (isStep1Complete()) {
				document.getElementById(lControlID_status).value = 1;
				document.getElementById(lControlID).src = "/images/greenButton1.png";
			} else {
				document.getElementById(lControlID_status).value = -1;
				document.getElementById(lControlID).src = "/images/yellowButton3.png";
				//setStatus(lControlID, 'red');
			}
			break;
		case 'PROP':
      setStep2Button(isStep2Complete());	break;
		case 'ACNT':
      if (aControlID == 'ACNT_password') { validateField('ACNT_password2') }
      if (isRegistrationComplete()) { document.getElementById("ACNT_registration_button").style.visibility='visible'; } 
      else                          { document.getElementById("ACNT_registration_button").style.visibility='hidden'; } 
      break;
		case 'RMD':
      if (isRemindMeComplete()) { document.getElementById("RMD_submitButton").style.visibility='visible'; } 
      else                      { document.getElementById("RMD_submitButton").style.visibility='hidden'; }
      break; 
		case 'PREF':
  		if (aControlID == 'PREF_password') {
        document.getElementById('PREF_password1').value = document.getElementById('PREF_password').value; 
        document.getElementById('PREF_password2').value = document.getElementById('PREF_password').value; 
      }
      break; 
		default:	break;
	}
}

function setStep2Button(aFlag) {
  switch (aFlag) {
    case 0: document.getElementById('PROP_go2step3').src = "/images/yellowButton3.png"; break;
    case 1: document.getElementById('PROP_go2step3').src = "/images/greenButton1.png";  break;
    case 2: document.getElementById('PROP_go2step3').src = "/images/yellowButton1.png"; break;
  }	
}

function isRemindMeComplete() {
  if (document.getElementById('RMD_email_status').value == 1) 
       { return 1; } 
  else { return 0; }
}

function isRegistrationComplete() {
  if (document.getElementById('ACNT_name_status').value      == 1 && 
	    document.getElementById('ACNT_username_status').value  == 1 &&
	    document.getElementById('ACNT_email_status').value     == 1 &&
	    document.getElementById('ACNT_password_status').value  == 1 &&
	    document.getElementById('ACNT_password2_status').value == 1 && 
	    document.getElementById('ACNT_eula_status').value      == 1) 
       { return 1; } 
  else { return 0; }
}

function isProfessionalRegistrationComplete() {
  if (document.getElementById('ACNT_name_status').value        == 1 && 
	    document.getElementById('ACNT_username_status').value    == 1 &&
	    document.getElementById('ACNT_email_status').value       == 1 &&
	    document.getElementById('ACNT_password_status').value    == 1 &&
	    document.getElementById('ACNT_password2_status').value   == 1 && 
	    document.getElementById('ACNT_brokerage_status').value   == 1 &&
	    document.getElementById('ACNT_license_status').value     == 1 &&
	    document.getElementById('ACNT_licensetype_status').value == 1 &&
	    document.getElementById('ACNT_eula_status').value        == 1) 
       { return 1; } 
  else { return 0; }
}

function isStep1Complete() {
  if (document.getElementById('AD_email_status').value   == 1 && 
      document.getElementById('AD_address_status').value == 1 &&
	    document.getElementById('AD_city_status').value    == 1 &&
	    document.getElementById('AD_state_status').value   == 1 &&
	    document.getElementById('AD_zip_status').value     == 1) 
       { return 1; } 
  else { return 0; }
}

function isStep2Complete() {
  if (document.getElementById('PROP_acres_status').value  == 1 && 
	    document.getElementById('PROP_sqfeet_status').value == 1 &&
			document.getElementById('PROP_beds_status').value   == 1 &&
			document.getElementById('PROP_baths_status').value  == 1 &&
			document.getElementById('PROP_age_status').value    == 1) {
    if (document.getElementById('PROP_address_status').value== 1) return 1;
    else                                                          return 2;
  }
  else return 0;
}

function setStatusButton(aControlID,aColor) {
	switch (aColor.toLowerCase()) {
		case 'red': 	 value = "/images/redDot.png"; break;
		case 'green':	 value = "/images/greenDot.png"; break;
		case 'yellow': value = "/images/yellowDot.png"; break;
		default:	     value = "/images/redDot.png";
	}
	document.getElementById(aControlID).src = value;
}
function getColorNumber(aColor) {
	switch (aColor.toLowerCase()) {
		case 'red': 	 value = '#FFc0c0'; break;
		case 'green':	 value = '#c0ffc0'; break;
		case 'blue':	 value = '#0000FF'; break;
		case 'yellow': value = '#FFFFC0'; break;
		case 'white':	 value = '#FFFFFF'; break;
		case 'black':	 value = '#000000'; break;
		default:	value = '#FFFFFF';
	}
	return value;
}
function setBackgroundForValidation(aControlID, aValid) {
	document.getElementById("DATA_location").value=aControlID;
	if (aValid) { document.getElementById(aControlID).style.background=getColorNumber('green'); }
	else        { document.getElementById(aControlID).style.background=getColorNumber('red');   }
}

function getAllDataQuery() {
	var pairs = new Array(); 
	var userID       = getCookie("mnsStatic");
	var emailID      = document.getElementById("AD_email");
	var addressID    = document.getElementById("AD_address");
	var cityID       = document.getElementById("AD_city");
	var stateID      = document.getElementById("AD_state");
	var zipID        = document.getElementById("AD_zip");
	var acresID      = document.getElementById("PROP_acres");
	var sqfeetID     = document.getElementById("PROP_sqfeet");
	var bedsID       = document.getElementById("PROP_beds");
	var bathsID      = document.getElementById("PROP_baths");
	var ageID        = document.getElementById("PROP_age");
  var locationID   = document.getElementById("DATA_location");
	var asaID        = document.getElementById("DATA_asa");
  var domID        = document.getElementById("DATA_domXML");
  var xmlID        = document.getElementById("DATA_chartXML");
  var startdateID  = document.getElementById("DATA_startdate");
  var enddateID    = document.getElementById("DATA_enddate");
  var latID        = document.getElementById("DATA_lat");
  var longID       = document.getElementById("DATA_long");
  var guidID       = document.getElementById("DATA_guid");
  var lSetActive   = 0;
  if (isCreditSufficient()) { lSetActive = 1; }

	pairs.push("userID"          + "=" + userID); 
	pairs.push("isPaid"          + "=" + lSetActive); 
	pairs.push(emailID.name      + "=" + emailID.value); 
	pairs.push(addressID.name    + "=" + addressID.value); 
	pairs.push(cityID.name       + "=" + cityID.value); 
	pairs.push(stateID.name      + "=" + stateID.value); 
	pairs.push(zipID.name        + "=" + zipID.value); 
	pairs.push(acresID.name      + "=" + acresID.value); 
	pairs.push(sqfeetID.name     + "=" + sqfeetID.value); 
	pairs.push(bedsID.name       + "=" + bedsID.value); 
	pairs.push(bathsID.name      + "=" + bathsID.value); 
	pairs.push(ageID.name        + "=" + ageID.value); 
	pairs.push(startdateID.name  + "=" + startdateID.value); 
	pairs.push(enddateID.name    + "=" + enddateID.value); 
	pairs.push(guidID.name       + "=" + guidID.value); 
	pairs.push(latID.name        + "=" + latID.value); 
	pairs.push(longID.name       + "=" + longID.value); 
	pairs.push(locationID.value);
	pairs.push(domID.name        + "=" + domID.value);
	pairs.push(xmlID.name        + "=" + xmlID.value);
	pairs.push(asaID.name        + "=" + asaID.value);
   
	return pairs.join("&"); 
}

function S4() {
   return (((1+Math.random())*0x10000)|0).toString(16).substring(1);
}
function mnsGUID() {
   return (S4()+"-"+S4()+"-"+S4());
}

function getPropertyStatusFromGUID(aGUID) {
  var ajaxVar = getAjaxRequestVariable(); 
	var query = ("GUID=" + aGUID); 

	ajaxVar.onreadystatechange = function(){} 
	ajaxVar.open("POST", "cgi-bin/mnsGetPropertyStatusFromGUID.cgi", false); 
	ajaxVar.setRequestHeader("Content-type", "application/x-www-form-urlencoded");  
	ajaxVar.setRequestHeader("Content-length", query.length);
	ajaxVar.setRequestHeader("Connection", "close");
 
	try       {ajaxVar.send(query);
             return ajaxVar.responseText} 
	catch (e) {alert(e);} 
}

function getUserID() {
  var ajaxVar = getAjaxRequestVariable(); 
	var query = ("GUID=" + getCookie("mnsVisitGuid")); 

	ajaxVar.onreadystatechange = function(){} 
	ajaxVar.open("POST", "cgi-bin/mnsGetUserID.cgi", true); 
	ajaxVar.setRequestHeader("Content-type", "application/x-www-form-urlencoded");  
	ajaxVar.setRequestHeader("Content-length", query.length);
	ajaxVar.setRequestHeader("Connection", "close");
 
	try       {ajaxVar.send(query);} 
	catch (e) {alert(e);} 
}

function storeLoginInfo(aLoginID,aGUID) {
	var ajaxVar = getAjaxRequestVariable(); 
	var query = ("ID=" + aLoginID + "&GUID=" + aGUID); 

	ajaxVar.onreadystatechange = function(){} 
	ajaxVar.open("POST", "cgi-bin/mnsStoreLoginInfo.cgi", false); 
	ajaxVar.setRequestHeader("Content-type", "application/x-www-form-urlencoded");  
	ajaxVar.setRequestHeader("Content-length", query.length);
	ajaxVar.setRequestHeader("Connection", "close");
 
	try       {ajaxVar.send(query);
             return ajaxVar.responseText} 
	catch (e) {alert(e);} 
} 

function setDefaultDateFields() {
  var endDate     = new Date();
  endDate = endDate.add('d',-1);
  var monthnumber = endDate.getMonth()+1;
  var monthday    = endDate.getDate();
  var year        = endDate.getYear();
  if(year < 2000) { year = year + 1900; }

  var lDate = monthnumber + '/' + monthday + '/' + year;
  document.getElementById("DATA_enddate").value = lDate;
  
  //default is today minus 2.5 years
  var startDate     = new Date();
  startDate = endDate.add('M',-6);
  startDate = endDate.add('d',0);
  startDate = endDate.add('y',-2);
  monthnumber = startDate.getMonth()+1;
  monthday    = startDate.getDate();
  year        = startDate.getYear();
  if(year < 2000) { year = year + 1900; }
  lDate = monthnumber + '/' + monthday + '/' + year;
  document.getElementById("DATA_startdate").value = lDate;
}

Date.prototype.add = function(interval, number) {
  if (typeof(interval)=="undefined" || interval==null || typeof(number)=="undefined" || number==null) { 
    return this; 
  }
  number = +number;
  if (interval=='y') { // year
    this.setFullYear(this.getFullYear()+number);
  }
  else if (interval=='M') { // Month
    this.setMonth(this.getMonth()+number);
  }
  else if (interval=='d') { // Day
    this.setDate(this.getDate()+number);
  }
  else if (interval=='w') { // Weekday
    var step = (number>0)?1:-1;
    while (number!=0) {
      this.add('d',step);
      while(this.getDay()==0 || this.getDay()==6) { 
        this.add('d',step);
      }
      number -= step;
    }
  }
  else if (interval=='h') { // Hour
    this.setHours(this.getHours() + number);
  }
  else if (interval=='m') { // Minute
    this.setMinutes(this.getMinutes() + number);
  }
  else if (interval=='s') { // Second
    this.setSeconds(this.getSeconds() + number);
  }
  return this;
};

function getCalendarDate()
{
   var months = new Array(13);
   months[0]  = "January";
   months[1]  = "February";
   months[2]  = "March";
   months[3]  = "April";
   months[4]  = "May";
   months[5]  = "June";
   months[6]  = "July";
   months[7]  = "August";
   months[8]  = "September";
   months[9]  = "October";
   months[10] = "November";
   months[11] = "December";
   var now         = new Date();
   var monthnumber = now.getMonth();
   var monthname   = months[monthnumber];
   var monthday    = now.getDate();
   var year        = now.getYear();
   if(year < 2000) { year = year + 1900; }
   monthnumber = monthnumber + 1;
   var dateString = monthnumber +
                    '/' +
                    monthday +
                    '/' +
                    year;
   return dateString;
} 

function mnsLogout() {
  setCookie("mnsVisitGuid","",-1);
  setCookie("mnsStatic","",-1);
  setCookie("mnsUserName","",-1); 
  setCookie("mnsCredits","",-1); 
  setCookie("mnsPropertyGuid","",-1); 
  window.location = "http://www.compraiser.com/"
}

function printChart(aGUID) {
	window.location.href="/printGraph.php?id=" + aGUID;
//	window.location.href="http://www.compraiser.com/php-bin/printerFriendly.php";

//	var chartToPrint = getChartFromId("chartID");
//	chartToPrint.print();
}

function getCredits() {
//  	if( !getCookie("mnsCredits") ) {
      var ajaxVar = getAjaxRequestVariable(); 
    	var query = ("userID=" + getCookie("mnsStatic")); 
    
    	ajaxVar.open("POST", "cgi-bin/mnsGetCredits.cgi", false); 
    	ajaxVar.setRequestHeader("Content-type", "application/x-www-form-urlencoded");  
    	ajaxVar.setRequestHeader("Content-length", query.length);
    	ajaxVar.setRequestHeader("Connection", "close");
     
    	try       {ajaxVar.send(query);
            		 var numCredits = ajaxVar.responseText;
            		 setCookie("mnsCredits",numCredits,0);
                 return ajaxVar.responseText;} 
    	catch (e) {alert(e);}
//  } else {
//    return getCookie('mnsCredits');
//  }
}

function getUserName() {
  	if( !getCookie("mnsUserName") ) {
      var ajaxVar = getAjaxRequestVariable(); 
    	var query = ("GUID=" + getCookie("mnsVisitGuid")); 
    
    	ajaxVar.open("POST", "cgi-bin/mnsGetUserName.cgi", false); 
    	ajaxVar.setRequestHeader("Content-type", "application/x-www-form-urlencoded");  
    	ajaxVar.setRequestHeader("Content-length", query.length);
    	ajaxVar.setRequestHeader("Connection", "close");
     
    	try       {ajaxVar.send(query);
          		   var userName = ajaxVar.responseText;
          		   setCookie("mnsUserName",userName,0);
                 return ajaxVar.responseText;} 
    	catch (e) {alert(e);}
  } else {
    return getCookie('mnsUserName');
  }
}

function loadAccuracyPage(aKey) {}
function loadActivatePage(aKey) {}
function loadIndexPage() {}
function loadBuySellPage() {}
function loadBuyPage() {}
function loadSellPage() {}
function loadCommunitiesPage() {}
function loadContactUsPage() {}
function loadCreditsPage(){
  if(!getCookie("mnsStatic")) {
    window.location = "http://www.compraiser.com/"
  } else {
    document.getElementById("CREDIT_onemonth").value = 0;
    document.getElementById("CREDIT_twomonths").value = 0;
    document.getElementById("CREDIT_threemonths").value = 0;
    setCookie("mnsCredits","",-1);
    updatePurchaseScreen();
  }
}
function loadFAQPage() {}
function loadFraudPage() {}
function loadGraphPage(){
  var lCredits = getCredits();  
  setVisibilityStep1();
  setDefaultDateFields();
}
function loadGraphPageExpidite(aAddress,aCity,aState,aZip,aAcres,aSqFeet,aBeds,aBaths,aYear,aLat,aLong){
  var lCredits = getCredits();  
  setAllGraphFields(aAddress,aCity,aState,aZip,aAcres,aSqFeet,aBeds,aBaths,aYear,aLat,aLong);
  isValidAddressExpidite();
  setVisability("reviewID");
  mnsShowReview();
}
function loadSinglePurchasePage(aGUID){
  if(aGUID.length == 14) {
    var lParts = new Array();
    lParts = aGUID.split('-');
    document.getElementById('CREDIT_part1').value = lParts[0];
    document.getElementById('CREDIT_part2').value = lParts[1];
    document.getElementById('CREDIT_part3').value = lParts[2];
    checkGraphCode(3);
  }
  updateSinglePurchaseScreen();
}
function setAllGraphFields(aAddress,aCity,aState,aZip,aAcres,aSqFeet,aBeds,aBaths,aYear,aLat,aLong) {
  setDefaultDateFields();
  document.getElementById("AD_address").value    = aAddress;
  document.getElementById("AD_city").value       = aCity;
  document.getElementById("AD_state").value      = aState;
  document.getElementById("AD_zip").value        = aZip;
  document.getElementById("PROP_acres").value    = aAcres;
  document.getElementById("PROP_sqfeet").value   = aSqFeet;
  document.getElementById("PROP_beds").value     = aBeds;
  document.getElementById("PROP_baths").value    = aBaths;
  document.getElementById("PROP_age").value      = aYear;
  document.getElementById("DATA_lat").value      = aLat;
  document.getElementById("DATA_long").value     = aLong;
  document.getElementById("DATA_location").value = ""; 
  document.getElementById("DATA_asa").value      = "";
  document.getElementById("DATA_domXML").value   = "";
  document.getElementById("DATA_chartXML").value = "";
}
function loadInvestPage() {}
function loadRegisterPage() {}
function loadLoginPage() {}
function loadPODPage(aGUID) { setCookie("mnsPropertyGuid",aGUID,0); }
function loadPrefsPage() {}
function loadPrivacyPolicyPage() {}
function loadRefundPolicyPage() {}
function loadRealtorPage() {}
function loadRemindPage() {}
function loadSearchPage() {}
function loadTaxesPage() {}
function loadThankYouPage() {}
function loadViewPage(aGUID) { setCookie("mnsPropertyGuid",aGUID,0); }
function isCreditSufficient() {
  retval = 0;
  if (getCookie("mnsCredits") > 1) retval = 1;
  return retval;
}

// calculate the ASCII code of the given character
function CalcKeyCode(aChar) {
  var character = aChar.substring(0,1);
  var code = aChar.charCodeAt(0);
  return code;
}

function checkNumber(val) {
  var strPass = val.value;
  var strLength = strPass.length;
  var lchar = val.value.charAt((strLength) - 1);
  var cCode = CalcKeyCode(lchar);

  /* Check if the keyed in character is a number
     do you want alphabetic UPPERCASE only ?
     or lower case only just check their respective
     codes and replace the 48 and 57 */

  if (cCode < 48 || cCode > 57 ) {
    var myNumber = val.value.substring(0, (strLength) - 1);
    val.value = myNumber;
  }
  return false;
}

function checkEnter(e){ //e is event object passed from function invocation
  var characterCode; //literal character code will be stored in this variable

  if(e && e.which){ //if which property of event object is supported (NN4)
    e = e;
    characterCode = e.which; //character code is contained in NN4's which property
  } else {
    e = event;
    characterCode = e.keyCode; //character code is contained in IE's keyCode property
  }

  if(characterCode == 13){ //if generated character code is equal to ascii 13 (if enter key)
    document.forms[0].submit(); //submit the form
    return false; 
  } else {
  return true;
  }
}

function addProperty(aGUID,aUserID) {
	var ajaxVar = getAjaxRequestVariable();
	
	var query = "guid=" + aGUID + "&userID=" + aUserID + "&newguid=" + mnsGUID(); 
	ajaxVar.onreadystatechange = function() { 
		if(ajaxVar.readyState == 4) { 
      alert('This property has been added to your account.');
		} 
	} 
	ajaxVar.open("POST", "php-bin/mnsAddProperty.php", true); 
	ajaxVar.setRequestHeader("Content-type", "application/x-www-form-urlencoded");  
	ajaxVar.setRequestHeader("Content-length", query.length);
	ajaxVar.setRequestHeader("Connection", "close");
 
	try { ajaxVar.send(query); } 
	catch (e) { alert(e); } 
}

function updateProperty(aGUID,aUserID) {
	var ajaxVar = getAjaxRequestVariable();

	var query = "guid=" + aGUID + "&userID=" + aUserID; 
	ajaxVar.onreadystatechange = function() { 
		if(ajaxVar.readyState == 4) {
      var newGUID = ajaxRequest.responseText; 
      alert('This Compraiser report has been updated.');
      window.location = "http://www.compraiser.com/view.php?GUID=" + newGUID;
		} 
	} 
	ajaxVar.open("POST", "php-bin/mnsUpdateProperty.php", true); 
	ajaxVar.setRequestHeader("Content-type", "application/x-www-form-urlencoded");  
	ajaxVar.setRequestHeader("Content-length", query.length);
	ajaxVar.setRequestHeader("Connection", "close");
 
	try { ajaxVar.send(query); } 
	catch (e) { alert(e); } 
}

function questionsBuy(aValue) {
  lURLExplain = '#graphExplain';
	switch (aValue) {
		case '1': lText = 'Before you spend tons of money on a property, make sure you know what you are getting!<br /><br />Are you buying something that will drop in price shortly?<br />Will the home increase in value soon?<br /><a href='+lURLExplain+'>Learn how to use Compraiser Market Graph and Compraiser Days on Market Graph together to understand market value of the property you would like to buy.</a><br /><a href=\'Register.php\'>Sign up Today!</a>'; break;
		case '2': lText = 'Make Compraiser.com your friend in <strong>finding your dream home</strong> – and for the right price!<br /><br />Save time by understanding the asking price before you even look at the home.<br />Run as many reports as you like with a premium subscription.<br /><a href=\'Register.php\'>Sign up Today!</a>'; break;
		case '3': lText = 'Buy low, sell high. Everyone wants to but few know how to do it.<br /><br />With Compraiser graphs, you will be able to <strong>target market trends to specific properties</strong>.<br /><a href='+lURLExplain+'>Learn how to use Compraiser information like the pros.</a><br />Run as many Compraiser reports as you like with a Premium subscription! '; break;
		case '4': lText = 'Each property is unique.<br /><br />Use Compraiser to <strong>minimize the sales price of each property</strong>.<a href='+lURLExplain+'>Learn how to use market trends and days on market trends to help time the market.</a><br />Run as many Compraiser reports as often as you like with a Premium subscription.'; break;
	}
	document.getElementById("questionSectionBuy").innerHTML = lText;
}

function questionsContest(aValue) {
  lURLExplain = '#graphExplain';
	switch (aValue) {
		case '1': lText = 'Make sure that you are only paying your fair share – not more!<br /><br />There are two ways to use compraiser to strengthen your case.<br />Use dollar amounts or use percentage increases.<br />Make sure that you understand how your County does assessments. Usually, the assessment is done on the same day of each year. This means that you should look at the percentage change from a specific date to the same date one year later. (e.g. January 1, 2008 and January 1, 2009) <br />If you taxes are not assessed properly, the extra amount you pay will carry over from year to year!'; break;
	}
	document.getElementById("questionSectionContest").innerHTML = lText;
}

function questionsFraud(aValue) {
  lURLExplain = '#graphExplain';
	switch (aValue) {
		case '1': lText = 'High volatility in the Compraiser Market Graph may indicate that homes in an area are not uniform.<br />This could pose a problem when either buying or selling.<br />If Compraiser Market Graph shows too much variance, consider it a red flag and proceed cautiously.'; break;
		case '2': lText = 'Compraiser.com wants to help <strong>eliminate mortgage fraud</strong>!<br /><br />High volatility in the market place MAY indicate that some properties have been artificially inflated.<br />Instability could also indicate that homes in an area vary considerably in price.<br />Either way, you would then need to be very careful about the comparables that are being used.<br /><a href='+lURLExplain+'>Click here for an explanation about using the Market Graph and the Days on Market Graph together to determine the stability of the market in an area</a>.'; break;
	}
	document.getElementById("questionSectionFraud").innerHTML = lText;
}

function questionsInvest(aValue) {
  lURLExplain = '#graphExplain';
	switch (aValue) {
		case '1': lText = 'Proper research is the key to successful property investing.<br /><br />Buying and selling at the right time is critical to making money off of real estate.<br />You need to <strong>buy low and sell high<strong>.<br /><a href='+lURLExplain+'>Read the explanation about how to use the market graph and days on market graph together to understand the market.</a>'; break;
		case '2': lText = 'Proper research is the key to successful property investing.<br /><br />Buying and selling at the right time is critical to making money off of real estate.<br />You need to buy low and sell high.<br /><a href='+lURLExplain+'>Read this explanation about how to use the Market Graph and Days on Market Graph together to understand the market highs and the market lows.</a><br />Since you plan to look at many properties, sign up for a premium subscription to run as many reports as you would like!'; break;
	}
	document.getElementById("questionSectionInvest").innerHTML = lText;
}

function questionsSell(aValue) {
  lURLExplain = '#graphExplain';
	switch (aValue) {
		case '1': lText = 'Pricing your home to sell is the ONLY way to sell your home fast. But don\'t give it away! <br /><br />Price your home just below market value to ensure that when potential buyers are comparing properties, <strong>yours will stand out as the best value</strong>.<br />Compraiser graphs will show you what the trends are in the market for YOUR specific property. <br /><a href='+lURLExplain+'>Use market trends and days on market trends from Compraiser</a> to help you sell your home fast and get a fair price.'; break;
		case '2': lText = 'In a down market, it is difficult to know what \"top dollar\" means.<br /><br />Many people price their home too high and it sits on the market wasting time while the market continues to drop.<br />Compraiser can help you know what <strong>\"top dollar\"</strong> is for your property.<br /><a href='+lURLExplain+'>Using market trends and days on market trends</a>, you will be able to better time the market to get the highest price for your property.'; break;
		case '3': lText = 'Buy low, sell high. Everyone wants to but few know how to do it.<br /><br />With Compraiser graphs, you will be able to <strong>target market trends to specific properties</strong>.<br /><a href='+lURLExplain+'>Learn how to use Compraiser information like the pros.</a><br />Run as many Compraiser reports as you like with a Premium subscription!'; break;
		case '4': lText = 'Each property is unique.<br /><br />Use Compraiser to <strong>maximize the sales price of each property</strong>.<br /><a href='+lURLExplain+'>Learn how to use market trends and days on market trends to help time the market.</a><br />Run as many Compraiser reports as often as you like with a Premium subscription.'; break;
	}
	document.getElementById("questionSectionSell").innerHTML = lText;
}

function questionsRealtor(aValue) {
  lURLExplain = '#graphExplain';
	switch (aValue) {
		case '1': lText = 'You can save a lot of money by selling without paying commissions! But you need to make sure that you do your homework. <br /><br />Understanding market value is more than just getting a comparable market analysis (CMA). You need to understand <strong>where the market is going</strong>. <br />Compraiser provides you with information that no other system knows how to do.<br />With market trending and days on market trending, you can get information that will help you time the market and maximize your $$$$.<br /><a href='+lURLExplain+'>To understand how to use these graphs to benefit you, please click here.</a>'; break;
		case '2': lText = 'Finding the right real estate agent will make selling your home more pleasant experience.<br /><br />Not all real estate agents are the same.<br />Our Compraiser affiliated real estate agents are screened to make sure that you receive the highest <strong>quality service and professionalism</strong> that you expect.<br /><a href=\'needARealtor.php\'>To have a Compraiser certified agent contact you, please click here.</a>'; break; 
		case '3': lText = 'Ask your real estate agent if she is using Compraiser.<br /><br />If she is, she can generate and show you reports for an <strong>unlimited number of properties</strong>.<br /><a href=\'findARealtor.php\'>To find out if your agent is a Compraiser certified agent, click here.</a>'; break; 
		case '4': lText = 'As a real estate agent, you know that service and expertise are what set you apart.<br /><br />By providing ALL of your clients with  Compraiser reports for ONE low monthly rate, you will increase your <strong>visibility</strong>, increase your <strong>professionalism</strong>, and increase your <strong>service</strong> to your clients.<br /><a href=\'\'>Sign up today!</a><br />To become a certified Compraiser real estate agent, please <a href=\'Contact-Us.php\'>contact us</a>.'; break;
	}
	document.getElementById("questionSectionRealtor").innerHTML = lText;
}

