// ----- 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 OpenPopupWindow(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=1,directories=0,resizable=1,status=1,menubar=1,scrollbars=0");
}

function OpenStaticPopup(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=0,menubar=0,scrollbars=0");
}

// ----- END: FOR OPENING POPUP WINDOWS -----


// ----- BEGIN: FOR HIDING/SHOWING LAYERS -----
function showLayer(strLayerName) {
	if(document.all)
		document.all[strLayerName].style.display = 'block';
	else if(document.layers)
		document.layers[strLayerName].display = 'block';
}
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);
	}
	strGate = strGate.toLowerCase()
	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 == -1) 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 == "" || strGateway.substring(0, 2) == "go" || strGateway.substring(0, 3) == "aol" || strGateway.substring(0, 6) == "excite") {
		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("/Redir/Redir_CreateProfile.asp?Target=/persplanout/SignUp1Pop.asp?DSF1=True&gate=" + strGateway,400,450); return true;
								}
						}
				}
		}
}
//------ END: SOFTGATE ----------------------------------





//------BEGIN: Consumer Opt-In FAH -------------------
function consumerOptIn() {
	var today = new Date();
	var expires = new Date(today.getTime() + (3650 * 24 * 60 * 60 * 1000));
	if(frmSearch.optInRadio[0].checked)
		document.cookie = "ChaperoneOpt=NextV;path=/";
	else {
		document.cookie = "ChaperoneOpt=Never;expires=" + expires.toGMTString() + ";path=/";
		document.cookie = "DeleteProspect=Yes;path=/";
	}
}
//------END: Consumer Opt-In FAH --------------------
