
function setCookie(name, value, expires, path, domain, secure) {
  var curCookie = name + "=" + escape(value) +
      ((expires) ? "; expires=" + expires.toGMTString() : "") +
      ((path) ? "; path=" + path : "") +
      ((domain) ? "; domain=" + domain : "") +
      ((secure) ? "; secure" : "");
  document.cookie = curCookie;
}
function getCookie(name) {
  var dc = document.cookie;
  var prefix = name + "=";
  var begin = dc.indexOf("; " + prefix);
  if (begin == -1) {
    begin = dc.indexOf(prefix);
    if (begin != 0) return null;
  } else
    begin += 2;
  var end = document.cookie.indexOf(";", begin);
  if (end == -1)
    end = dc.length;
  return unescape(dc.substring(begin + prefix.length, end));
}
function deleteCookie(name, path, domain) {
  if (getCookie(name)) {
    document.cookie = name + "=" + 
    ((path) ? "; path=" + path : "") +
    ((domain) ? "; domain=" + domain : "") +
    "; expires=Thu, 01-Jan-70 00:00:01 GMT";
  }
}


/*
*******************************************************************
This checks the value of popupdone which is stored in a cookie.
If the cookie does not contain the value it then adds one. if the 
value is = to pageCount it then forces the function to complete.
If the value is not = to paceCount it will increment popupdone on 
each page load untill it = pageCount.

The sub cookie is a catcher to stop the popup from repete poping.

*******************************************************************
*/
function checkCount() {
	var pageCount = 1; //Set to 0 to popup on entering the site . eg set to 2 the popup opens on the 2nd site href click.
	var cCookie = 0;
	var popupdone = 1;
	if (pageCount==0 && !getCookie("sub")){
		setCookie("popupdone", popupdone, 0);
		setCookie("sub", "true", 0);
		return true;
	}
	if(!getCookie("popupdone")){
		setCookie("popupdone", popupdone, 0);
		return false;
	} else {
		cCookie = getCookie("popupdone");
		if (cCookie!=pageCount){
			cCookie++;
			setCookie("popupdone", cCookie, 0);
			return false;
		} else {
			if(!getCookie("sub")){
				setCookie("sub", "true", 0);
				return true;
			} else {
				return false;
			}
		}
	}
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function doPopUp() {
	if(checkCount())
	{
	MM_openBrWindow('popup.html','popup','width=400,height=225');
	}
}


/*
*******************************************************************
Starts the pop behind window if the browser is > ver 4.
This only happens if the above coocie is not set.
*******************************************************************
*/
function windowError(){
	return true;
}


function doPopUpAd(){
	if(checkCount()){
		var gotoUrl='http://www.remortgages-0800.co.uk/popup_3_in_1.html?ourref=claim2us';
		var windowInfo;
		if(parseFloat(navigator.appVersion)>=4){
			windowInfo='width='+(window.screen.availWidth )+',height='+(window.screen.availHeight);
			windowInfo+=',top=0,left=0,status=yes,menubar=yes,toolbar=yes,location=yes,resizable=yes,scrollbars=yes';
			var newWindow = window.open("",'pic0800',windowInfo);
			newWindow.blur();
			if (newWindow.location && newWindow.location.href.indexOf(gotoUrl) == -1){ // Backup if no cookies enabled, only opens new window if the popup window does not = the specified page in gotoUrl
				newWindow.location=gotoUrl;self.focus();
			}
		} else {
			return true;
		}
	}
}

/*
*******************************************************************
This section looks for the AOL browser.
It wont fire the popup if its am AOL browser. 

01/11/2004 Steve

*******************************************************************
*/
window.onerror = windowError;
var sPath = window.location.pathname;
var sPage = sPath.substring(sPath.lastIndexOf('/') + 1);
var agent=navigator.userAgent.toLowerCase();
if ((agent.indexOf("aol") == -1) || (agent.indexOf("aol 5") == -1) ||  (agent.indexOf("aol 6") == -1)){// Checks user agent and fires the function if its not an AOHELL browser
	//doPopUpAd();	
}