  var cName = "ittCookie";
  var ittNum = "";
  
// Function called from web page which ultimately returns the appropriate telephone number
function getITTNumber() {

var ittParam = getParamValue('itt');

if (ittParam == "") {

ittNum = checkCookie();

	if (ittNum == null) {
	ittNum = getAlternativeNumber();
	} 
	
	else {
	
	if (ittNum == "0845 385 8007") {
	ittNum = "0845 385 core0"
	}
	if (ittNum == "0845 385 8008") {
	ittNum = "0845 385 core1"
	}
	if (ittNum == "0845 385 8009") {
	ittNum = "0845 385 core2"
	}
	
	}

} 

else {

var numArray = new Array();

numArray[0] = "0845 385 8007";
numArray[1] = "0845 385 8008";
numArray[2] = "0845 385 8009";

ittNum = numArray[ittParam];

// If ittParam does not realte to a number then the following if statment will set it to the alternative number
	if (ittNum == null) {

	ittNum = getAlternativeNumber();

	} else {

     setCookie(cName, ittNum, 365);
}
}

return ittNum;

}

function getAlternativeNumber() {

var altNum = "0800 652 3233";
return altNum;
}

// Telephone Tracking: Checks to see if a relevant cookie exists, if there is not then information is passed to the setCookie function. Ultimately returns the tracking number to be displayed on the site.
function checkCookie() {

  var cookieValue = getCookie(cName);
  var cookieNum = cookieValue;
 
  return cookieNum;

}


// Telephone Tracking: Loops through the cookies on the users machine which are related to the website in order to retrieve the cookie related to telephone tracking. Returns this cookie to the checkCookie function.
function getCookie(cookieName) {
	
	//retrieved in the format
	//cookieName4=value; cookieName3=value; cookieName2=value; cookieName1=value
	//only cookies for this domain and path will be retrieved
	var cookieJar = document.cookie.split( "; " );
	for( var x = 0; x < cookieJar.length; x++ ) {
		var oneCookie = cookieJar[x].split( "=" );
		if( oneCookie[0] == escape( cookieName ) ) { return oneCookie[1] ? unescape( oneCookie[1] ) : ''; }
	}
	return null;
}

// Telephone Tracking: Function is called upon if no telephone tracking cookie exists on the user's machine. It creates the telephone tracking cookie and returns the telephone number to be displayed on the users screen to the checkCookie function.
function setCookie(cName, cNumber, cExpire) {

  var myDate = new Date();
  myDate.setDate(myDate.getDate() + cExpire);
  document.cookie = cName + "=" + escape(cNumber) + ";expires=" + myDate + "; path=/";
}

// Telephone Tracking: Function takes in a parameter name from the current URL displayed on the users screen and returns its value to the checkCookie function. 
function getParamValue(paramName) {  

  paramName = paramName.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");  
  var regexS = "[\\?&#_:+!.]"+paramName+"=([^&#_:+?!.]*)";  
  var regex = new RegExp( regexS );  
  var results = regex.exec( window.location.href ); 

  if(results == null) 
    return "";
  else 
   
  return results[1];

}


