

function AreCookiesEnabled() {
	var cookieEnabled=(document.cookie.indexOf("EthiscoreTestCookie")!=-1)? true : false;
	if (!cookieEnabled) {
		document.cookie="EthiscoreTestCookie=ok; ";
		cookieEnabled=(document.cookie.indexOf("EthiscoreTestCookie")!=-1)? true : false;
		}
	return cookieEnabled;
}
	
function GoTo(psHRef) {
	if (AreCookiesEnabled()){
		window.location.href = psHRef;
		}
	else {
		alert('Please enable Cookies in your browser to view this link.');
	}
}

function getcookie(cookiename) {
 var cookiestring=""+document.cookie;
 var index1=cookiestring.indexOf(cookiename);
 if (index1==-1 || cookiename=="") return ""; 
 var index2=cookiestring.indexOf(';',index1);
 if (index2==-1) index2=cookiestring.length; 
 return unescape(cookiestring.substring(index1+cookiename.length+1,index2));
}

function getcustomcachecookievalue(valuename) {
var cookiestring=getcookie("Ethiscore.CustomCache");
 var index1=cookiestring.indexOf(valuename);
 if (index1==-1 || valuename=="") return ""; 
 var index2=cookiestring.indexOf('&',index1);
 if (index2==-1) index2=cookiestring.length; 
 return cookiestring.substring(index1+valuename.length+1,index2);
}

function getSegmentName() {
 var lp = getcustomcachecookievalue("landingPage");
 if (lp && lp !="0") return "landing " + lp;
 var ug= getcustomcachecookievalue("userWebGroupID");
 if (ug && ug=="88") return "standard login";
 if (ug && ug=="87") return "customised free trial login";
 if (ug && ug=="89") return "institional login";
 return "not logged in/free trial login"
}

// Determine browser and version.
function Browser() {
  var ua, s, i;

  this.isIE    = false;
  this.isNS    = false;
  this.version = null;

  ua = navigator.userAgent;

  s = "MSIE";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isIE = true;
    this.version = parseFloat(ua.substr(i + s.length));
    return;
  }

  s = "Netscape6/";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isNS = true;
    this.version = parseFloat(ua.substr(i + s.length));
    return;
  }

  // Treat any other "Gecko" browser as NS 6.1.

  s = "Gecko";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isNS = true;
    this.version = 6.1;
    return;
  }
}


// Rather than do any browser sniffing, we'll first just check to see if the object 
// implements the EventListener interface. If so, we'll just use that and call it a day. 
// This will keep our code compatible if IE implements the same interface in the future.
//function addEvent(pObj, psEventType, psFunction, pbCapture){
//  if (pObj.addEventListener){
//    pObj.addEventListener(psEventType, psFunction, pbCapture);
//    return true;
//  } else if (pObj.attachEvent){
//    var r = pObj.attachEvent("on" + psEventType, psFunction);
//    return r;
//  } else {
//    alert("Handler could not be attached");
//  }
//}

function addEvent(pObj, psEventType, psFunction, pbCapture){
	var browser = new Browser();
	if (browser.isNS) {
    pObj.addEventListener(psEventType, psFunction, pbCapture);
    return true;
  } else if (browser.isIE) {
    var r = pObj.attachEvent("on" + psEventType, psFunction);
    return r;
  } else {
    //alert("Handler could not be attached");
  }
}

function removeEvent(pObj, psEventType, psFunction, pbCapture){
  if (pObj.removeEventListener){
    pObj.removeEventListener(psEventType, psFunction, pbCapture);
    return true;
  } else if (pObj.detachEvent){
    var r = pObj.detachEvent("on" + psEventType, psFunction);
    return r;
  } else {
    alert("Handler could not be removed");
  }
} 

