
// *** Globals
var dateNow = new Date();


// *** Functions


function doLoad() {
	
// hide the "now" option if the office is closed.


// declare variables
var dateNow = new Date()
var day = dateNow.getDay();
var hour = dateNow.getHours(); 
var shownow = "y";




// Mon to Thurs 9 - 8
if (day >= 1 && day <= 4) {
	if (hour >= 9 && hour <= 20) shownow = "y";
	else shownow = "n";
}

// Fri  9 - 8
else if  (day == 5 || day == 6) {
if (hour >= 9 && hour <= 17) shownow = "y";
	else shownow = "n";}
	
// Mon to Thurs 9 - 8
else if  (day == 7) {
if (hour >= 10 && hour <= 16) shownow = "y";
	else shownow = "n";
	}



var hmm = document.getElementById('CallTime')[0].value;
if (shownow == "n") 
{
sel = document.getElementById('CallTime');
sel.options[0] = null;
sel.options.selectedIndex = 0;
}

}



function checkRequiredFields() {
	var fOK = true;
	var theForm = document.forms[0];
	
	// check required fields are filled in
	if (theForm.keywords.value == "") {
			fOK = false;
			alert("Are you sure you want to search for nothing?");
			theForm.keywords.focus();
		}
	return fOK;
}





function checkForm(objForm) {
	var strErrors = "";
	var objErrorField = null;
	var strDateText = "";
	var strICID;
		
		strICID = getParamFA("icid");

if (strICID.length == 0) { strICID = getCookieFA("icid")}

		
		if (strICID.length == 0) {
			if (window.location.pathname.indexOf("simply-switch") > -1) {
				strICID = "D176-2195336-058D";}
				else if (window.location.pathname.indexOf("lincoln") > -1) {
				strICID = "D190-2199780-113H";}
				else if (window.location.pathname.indexOf("telegraph") > -1) {
				strICID = "J017-5417236-098D";}
				else if (window.location.pathname.indexOf("team") > -1) {
				strICID = "M040-6697108-002N";}
				else if (window.location.pathname.indexOf("tesco") > -1) {
				strICID = "tesco";}
				else if (window.location.pathname.indexOf("find") > -1) {
				strICID = "M148-2515304-141J";}
				else if (window.location.pathname.indexOf("magpie") > -1) {
				strICID = "Money-Magpie";}
				else if (window.location.pathname.indexOf("MMBBFrame") > -1) {
				strICID = "Money-Magpie";}
				else if (window.location.pathname.indexOf("beat_that_quote/direct") > -1) {
				strICID = "BTQ-D";}
				else if (window.location.pathname.indexOf("beat_that_quote/intermediary") > -1) {
				strICID = "BTQ-I";}
				else if (window.location.pathname.indexOf("groupdirect") > -1) {
				strICID = "group_direct";}
				else if (window.location.pathname.indexOf("this_is_your_mortgage") > -1) {
				strICID = "TIYM";}
				else if (window.location.pathname.indexOf("this-is-your-mortgage") > -1) {
				strICID = "TIYM";}
				else if (window.location.pathname.indexOf("aol") > -1) {
				strICID = "aol";}	
				else if (window.location.pathname.indexOf("moneymattersBB") > -1) {
				strICID = "money-matters";}
				else if (window.location.pathname.indexOf("lower_my_bills") > -1) {
				strICID = "LowermyBills";}
				else if (window.location.pathname.indexOf("source=lcplc2") > -1) {
				strICID = "lcplc2";}
				else if (window.location.pathname.indexOf("emarketing") > -1) {
				strICID = "emarketing";}
				else if (window.location.pathname.indexOf("newcastle") > -1) {
				strICID = "newcastle";}
				else if (window.location.pathname.indexOf("netmovers") > -1) {
				strICID = "netmovers";}
				
				else if (window.location.pathname.indexOf("emailHNW") > -1) {
				strICID = "emailHNW";}
					else if (window.location.pathname.indexOf("teamps") > -1) {
				strICID = "teamps";}
				else if (window.location.pathname.indexOf("RICS") > -1) {
				strICID = "RICS";}
				else if (window.location.pathname.indexOf("rics") > -1) {
				strICID = "RICS";}
							
				else {strICID = "lcplc";}
		}
		
		objForm.elements["icid"].value = strICID;
		return true;
	
}

function windowname(){
alert("1");
var windowname = window.location.pathname;
alert(windowname);

}

function getParamFA(strParam) {

	var iStart, iEnd, iLen;
	var strValue = "";
	var strURL = window.location.href + "&";
	iStart = strURL.toLowerCase().indexOf("&" + strParam + "=");

	if (iStart < 0) {
		iStart = strURL.toLowerCase().indexOf("?" + strParam + "=");
	}

	if (iStart > -1) {
		iStart += strParam.length + 2;
		strURL = strURL.substr(iStart);
		iEnd = strURL.toLowerCase().indexOf("&");
		if (iEnd > 0) {
			strValue = strURL.substr(0, iEnd);
		}

	}

	if (strValue != "") {
		setCookieFA(strParam.toLowerCase(), strValue);
	} else {
		strValue = getCookieFA(strParam.toLowerCase());
	}

	return strValue;
}

function getCookieFA(name) {

	var start = document.cookie.indexOf(name+"=");
	var len = start+name.length+1;
	if ((!start) && (name != document.cookie.substring(0,name.length))) return "";
	if (start == -1) return "";
	var end = document.cookie.indexOf(";",len);
	if (end == -1) end = document.cookie.length;
	return unescape(document.cookie.substring(len,end));
}

	

function setCookieFA(name,value,expires,path,domain,secure) {
	var cookie;
	cookie = name + "=" + escape(value);
	cookie += ((expires) ? ";expires=" + new Date(expires).toGMTString() : "");
	cookie += ((path) ? ";path=" + path : "");
	cookie += ((domain) ? ";domain=" + domain : "");
	cookie += ((secure) ? ";secure" : "");
	document.cookie = cookie;
}




