/////////////// cookie functions ///////////////////////////

// tests for cookies enabled
var cookieEnabled = false;
if (typeof document.cookie == "string") {
	if (document.cookie.length == 0) {
		setCookie("ctest", "CA14543957437589758584754789574985784758");
		var ctestRead = getCookie("ctest");
		if (ctestRead == "CA14543957437589758584754789574985784758") {
			cookieEnabled = true;
		}
		else {
			cookieEnabled = false;
		}
	}
	else {
		setCookie("ctest", "CA14543957437589758584754789574985784758");
		cookieEnabled = true;
	}
}




function getCookieVal(offset) {
	var endstr = document.cookie.indexOf(";", offset);
	if (endstr == -1) {
		endstr = document.cookie.length;
	}
	return unescape(document.cookie.substring(offset, endstr));
}



function getCookie(name) {
	var arg = name + "=";
	var alen = arg.length;
	var clen = document.cookie.length;
	var i = 0;
	while (i < clen) {
		var j = i + alen;
		if (document.cookie.substring(i, j) == arg) {
			return getCookieVal(j);
		}
		i = document.cookie.indexOf(" ", i) + 1;
		if (i == 0) break;
	}
	return "";
}


function setCookieShort(name, value) {
	var exp = new Date(); // to fix bug with Safari
	exp.setTime(exp.getTime() + 9000000); // 900000 was too short
	var expires = true;
	var path = false;
	var domain = false;
	var secure = false;

	document.cookie = name + "=" + escape (value) +
		((expires) ? "; expires=" + exp.toGMTString() : "") +
		((path) ? "; path=" + path : "") +
		((domain) ? "; domain=" + domain : "") +
		((secure) ? "; secure" : "");
}



function setCookie(name, value) {
	var exp = new Date(); // to fix bug with Safari
	exp.setTime(exp.getTime() + 86400000);
	var expires = true;
	var path = false;
	var domain = false;
	var secure = false;

	document.cookie = name + "=" + escape (value) +
		((expires) ? "; expires=" + exp.toGMTString() : "") +
		((path) ? "; path=" + path : "") +
		((domain) ? "; domain=" + domain : "") +
		((secure) ? "; secure" : "");
}


function setCookieLong(name, value) {
	var exp = new Date(); // to fix bug with Safari
	exp.setTime(exp.getTime() + 995000000);
	var expires = true;
	var path = false;
	var domain = false;
	var secure = false;

	document.cookie = name + "=" + escape (value) +
		((expires) ? "; expires=" + exp.toGMTString() : "") +
		((path) ? "; path=" + path : "") +
		((domain) ? "; domain=" + domain : "") +
		((secure) ? "; secure" : "");
}

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";

	}
}



function cookiesNotOnMessage() {
	// cookies not required
}


/////////////// end cookie functions ///////////////////////////




function getSearchAsArray() {
	var theResults = new Array()
	var input = unescape(location.search.substr(1))
	if (input) {
		var srchArray = input.split("&")
		var tempArray = new Array()
		for (var i = 0; i < srchArray.length; i++) {
			tempArray = srchArray[i].split("=")
			var varForKeyForArray = "'" + tempArray[0] + "'";
			theResults[varForKeyForArray] = tempArray[1]
		}
	}
	return theResults
}

////////// SETS INCOMING VARIABLES //////
var thePhrase = "none";
var theSource = "none";
var tdAccNo = 0;
var tdAddress = "";
var tdOK = "";

var productType = "checkout"
function setVariables() {
	if (location.search) {
		var srchArray = getSearchAsArray();
		if (srchArray["'p'"]) { thePhrase = srchArray["'p'"]; }
		if (srchArray["'s'"]) { theSource = srchArray["'s'"]; }
		if (srchArray["'tdan'"]) { tdAccNo = srchArray["'tdan'"]; }
		if (srchArray["'tdad'"]) { tdAddress = srchArray["'tdad'"]; }
		if (srchArray["'tdOK'"]) { tdOK = srchArray["'tdOK'"]; }
	}
}

setVariables();
if (tdAccNo > 0 && tdAddress != "" && tdOK == "123456") {
		var tradeCus = tdAccNo + '__' +  tdAddress;
		setCookieShort("trdcus2", tradeCus);
}






function makeURLAd(productType) {
	var theDate = new Date()
	var offsetFromGMT = theDate.getTimezoneOffset();

	var theFullUrl = "http://www.minilabels.co.uk/e_index2.htm?offg=" + offsetFromGMT + "&p=" + thePhrase + "&s=" + theSource + "&product=" + productType;
	

	top.location.href = theFullUrl;
}





var idChrome = "no";
var agt2 = new String(navigator.userAgent.toLowerCase());
if (agt2.indexOf("chrome") != -1) {
	idChrome = "yes";
}



function resetStyleSheet() {
	if (idChrome == "yes") {
		winWidth = getInsideWindowWidth();
		winWidth2 = (getInsideWindowWidth() - 1024)*0.5;
		if (winWidth > 1024) { // keep it simple
			winWidth = 1024;
		}
		else if (winWidth < 1000) { // lose rh column
			document.styleSheets[0].rules[14].style.visibility = "hidden";
		}
		var extraWidAv = winWidth - 740 - 20; // 20 is for scrollbars
		if (extraWidAv > 2) { // don't bother for less
			document.styleSheets[0].rules[16].style.width = (440 + extraWidAv) + "px";
			document.styleSheets[0].rules[14].style.left = (480 + extraWidAv + winWidth2) + "px";
		}
	}
	else if (document.styleSheets[0].rules) { // IE
		winWidth = getInsideWindowWidth();
		winWidth2 = (getInsideWindowWidth() - 1024)*0.5;
		if (winWidth > 1024) { // keep it simple
			winWidth = 1024;
		}
		else if (winWidth < 1000) { // lose rh column
			document.styleSheets[0].rules[14].style.visibility = "hidden";
		}
		var extraWidAv = winWidth - 740 - 20; // 20 is for scrollbars
		if (extraWidAv > 2) { // don't bother for less
			document.styleSheets[0].rules[16].style.width = (440 + extraWidAv) + "px";
			document.styleSheets[0].rules[14].style.left = (480 + extraWidAv + winWidth2) + "px";
		}
	}
	else { // MOZILLA
		winWidth = getInsideWindowWidth();
		winWidth2 = (getInsideWindowWidth() - 1024)*0.5;
		if (winWidth > 1024) { // keep it simple
			winWidth = 1024;
		}
		else if (winWidth < 1000) { // lose rh column
			document.styleSheets[0].cssRules[14].style.visibility = "hidden";
		}

		var extraWidAv = winWidth - 740 - 20; // 20 is for scrollbars
		if (extraWidAv > 2) { // don't bother for less
			document.styleSheets[0].cssRules[16].style.width = (440 + extraWidAv) + "px";
			document.styleSheets[0].cssRules[14].style.left = (470 + extraWidAv + winWidth2) + "px";
		}

	}
}







function makeURL(productType) {
		var theDate = new Date()
		var offsetFromGMT = theDate.getTimezoneOffset();
		var theFullUrl = "e_index2.htm?offg=" + offsetFromGMT + "&s=sc01&product=" + productType;
		top.location.href = theFullUrl;
}









function navigate(choice) {
		var url = choice.options[choice.selectedIndex].value;
		document.getElementById("list1").options[0].selected = true;
		document.getElementById("list2").options[0].selected = true;
		if (url != "void") {
			if (url) {
				makeURL(url);
			}
		}
}






///////////////////////// new search records /////////////////////////////////////////

/// keep at end of js file

if ( thePhrase != "none" ) { // ad landing
		var phraseSource = thePhrase + theSource;
		if (getCookie("v1") == "") {
			setCookieLong("v1", phraseSource);
		}
		else if (getCookie("v2") == "") {
			setCookieLong("v2", phraseSource);
		}
		else if (getCookie("v3") == "") {
			setCookieLong("v3", phraseSource);
		}
		else if (getCookie("v4") == "") {
			setCookieLong("v4", phraseSource);
		}	
}

else {  ////non-ad landing 

	var myReferrer = new String(document.referrer);




	if ( (myReferrer.indexOf("uid=") == -1) &&  (myReferrer.indexOf("=") != -1) ) { // i.e. only happens for landing page
		if (getCookie("v1") == "") {
			setCookieLong("v1", myReferrer);
		}
		else if (getCookie("v2") == "") {
			setCookieLong("v2", myReferrer);
		}
		else if (getCookie("v3") == "") {
			setCookieLong("v3", myReferrer);
		}
		else if (getCookie("v4") == "") {
			setCookieLong("v4", myReferrer);
		}	
	}

}





///////////////////////// end search records /////////////////////////////////////////






var simonDecrypt = "jgjdf gjkfhgjfffhd";
