// ----- BEGIN: FOR OPENING POPUP WINDOWS -----
function OpenPopup(URL, width, height) {
	window.self.name = "main";
	var now = new Date();
	var remote = window.open(URL, "popup" + now.getTime(), "width=" + width + ",height=" + height + ",toolbar=0,location=0,directories=0,resizable=1,status=1,menubar=0,scrollbars=0");
}

function OpenScrollingPopup(URL, width, height) {
	window.self.name = "main";
	var now = new Date();
	var remote = window.open(URL, "popup" + now.getTime(), "width=" + width + ",height=" + height + ",toolbar=0,location=0,directories=0,resizable=1,status=1,menubar=0,scrollbars=yes");
}

function openMessenger(agentID,agentScreenName,emailURL,promoURL,ftmlsid,ftmlsalias,fthsid,ftspg,ftsid,ftaid,ftlid,ftctype){
    var url = "http://homestoreimlink.facetime.net/messengerLaunch.html";
      url += "?agentID=" + agentID;
      url += "&agentScreenName=" + escape(agentScreenName);
      url += "&emailURL=\"" + emailURL + "\"" ;
      url += "&promoURL=\"" + promoURL + "\"";
      url += "&mlsid="  + escape(ftmlsid);
      url += "&mlsalias="  + escape(ftmlsalias);
      url += "&HSID=" + escape(fthsid);
      url += "&spg="  + escape(ftspg);
      url += "&sid="  + escape(ftsid);
      url += "&aid="  + escape(ftaid);
      url += "&lid="  + escape(ftlid);
      url += "&ctype="  + escape(ftctype);
      var urlRD = "/redir/redir.asp?target=" + escape(url) ;
      window.open(urlRD,'new','width=3,height=3');
}

// ----- END: FOR OPENING POPUP WINDOWS -----


// ----- BEGIN: FOR HIDING/SHOWING LAYERS -----
function showLayer(strLayerName) {
	if(document.all)
		document.all[strLayerName].style.display = 'inline';
	else if(document.layers)
		document.layers[strLayerName].display = 'inline';
}
function hideLayer(strLayerName) {
	if(document.all)
		document.all[strLayerName].style.display = 'none';
	else if(document.layers)
		document.layers[strLayerName].display = 'none';
}
// ----- END: FOR HIDING/SHOWING LAYERS -----


// ----- BEGIN: FOR GETTING GATEWAY FLAGS -----
function getGateway() {
	var strGate = '';
	var strQS = document.location.search;
	var intStart = strQS.indexOf('gate=');
	if(intStart != -1) {
		var intEnd = strQS.indexOf('&', intStart);
		if(intEnd == -1) intEnd = strQS.length;
		strGate = strQS.substring(intStart+5, intEnd);
	}
	return strGate;
}
function getGatewayQS() {
	var strGate = getGateway();
	if(strGate == '')
		return '';
	else
		return 'gate=' + strGate;
}
// ----- END: FOR GETTING GATEWAY FLAGS -----


// ----- BEGIN: FOR GETTING COOKIES -----
function getCookie(strName) {
	var strCookie = document.cookie;
	if(strCookie.length == 0) return '';
	var strValue = '';
	var intStart = strCookie.indexOf(strName + '=');
	if(intStart > -1) {
		var intEnd = strCookie.indexOf(';', intStart + 1);
		if(intEnd == 0) intEnd = strCookie.length;
		strValue = strCookie.substring(intStart, intEnd);
	}
	return strValue;
}

function setCookie(strName, strValue, strExp) {
	var strNewCookie = strName + '=' + strValue;
	if(strExp != '') strNewCookie += (';expires=' + strExp);
	document.cookie = strNewCookie;
}
// ----- END: FOR GETTING COOKIES -----



// ----- BEGIN: FOR STRING/NUMBER CONVERSIONS -----
function isNumericString (strOrig) {
	if(strOrig.length==0) return false;

	var strChar;
	var strValidChars = "1234567890$,";
	for (var i = 0; i < strOrig.length; i++) {
		strChar = strOrig.substring(i, i+1);
		if (strValidChars.indexOf(strChar, 0) == -1)
			return false;
	}
	return true;
}

function isValidEmail(strEmail) {
	var strBadChars, strChar, strSuffix, intNumBadChars, intCount, intPos, intPosPeriod

	// --- CHECKING FOR BAD CHARACTERS ---
	strBadChars = ' /:,#\'"`$~!%^&*();<>?\\|{}[]';
	intNumBadChars = strBadChars.length
	for(intCount = 0;  intCount < intNumBadChars;  ++intCount) {
		strChar = strBadChars.substring(intCount, 1);
		if(strEmail.indexOf(strChar) > 0)
			return false;
	}

	// --- CHECKING FOR THE @ SIGN ---
	intPos = strEmail.indexOf('@')
	if(intPos == -1)
		return false;

	// --- CHECKING FOR A . AFTER THE @ SIGN ---
	intPosPeriod = strEmail.indexOf('.', intPos);
	if(intPosPeriod == -1)
		return false;

	// --- CHECKING FOR AT LEAST 2 AFTER THE PERIOD ---
	if(strEmail.length - intPosPeriod < 3)
		return false;

	// --- ALL CHECKS OUT - MUST BE OKAY ---
	return true;
}
// ----- END: FOR STRING/NUMBER CONVERSIONS -----




//------BEGIN: SOFTGATE ----------------------------------
function softpop() {
	var strGateway = getGateway();
	if(strGateway ==  "homestore" || strGateway == "realtor" || strGateway == "") {
		var mydate = new Date();
		mydate.setHours(23);
		mydate.setMinutes(59);
		mydate.setSeconds(59);
		var strSoftGateCookie = "HSSoftgate" + "=" + "True" + ";expires=" + mydate.toGMTString() + "; Path=/" ;
		var intMagicnumber;
		intMagicnumber = 100;
		var intRandomNumber;
		var allcookies = document.cookie;
		var intRegUser = allcookies.indexOf("MEMUSER=");
				if (intRegUser == -1) {
					var intSoftGate = allcookies.indexOf("HSSoftgate=");
						if (intSoftGate == -1) {
							intRandomNumber = Math.floor(Math.random() * 100 + 1);
								if (intRandomNumber <= intMagicnumber) {
									document.cookie = strSoftGateCookie;
// 									OpenScrollingPopup("/persplanout/newplannerpop.asp?ASF1=True",500,450); return true; 
									OpenScrollingPopup("/Redir/Redir_CreateProfile.asp?Target=/persplanout/SignUp1Pop.asp?BSF1=True",400,450); return true;
								}
						}
				}
				//------debug script -------  OpenScrollingPopup("http://localhost/soft.asp?RandomNumber=" + intRandomNumber,500,450); return true;
		}
}
//------ END: SOFTGATE ----------------------------------

