//PRELOAD NAV HOVER ITEMS
function preloader() {
	if (document.images) {

		var img1 = new Image();
		var img2 = new Image();
		var img3 = new Image();
		var img4 = new Image();
		var img5 = new Image();
		var img6 = new Image();
		var img7 = new Image();

		img1.src = "http://www.tslist.com/imgs/reviews/arrow-down.gif";
		img2.src = "http://www.tslist.com/imgs/reviews/arrow-none.gif";
		img3.src = "http://www.tslist.com/imgs/reviews/arrow-up.gif";
		img4.src = "http://www.tslist.com/imgs/nav-left_hover.gif";
		img5.src = "http://www.tslist.com/imgs/nav-right_hover.gif";
		img6.src = "http://www.tslist.com/imgs/reviews/tab_left_over.gif";
		img7.src = "http://www.tslist.com/imgs/reviews/tab_right_over.gif";
	}
}


//OPEN WINDOWS
function OpenCriteria(URL) {
	day = new Date();
	id = day.getTime();
	eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=650,height=750,left = 0,top = 0');");
}

function OpenXsells(URL) {
	day = new Date();
	id = day.getTime();
	eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=650,height=750,left = 0,top = 0');");
}

function OpenCovers(URL) {
day = new Date();
id = day.getTime();
eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=385,height=545,left = 0,top = 0');");
}

function OpenReport(URL) {
day = new Date();
id = day.getTime();
eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=450,height=225,left = 0,top = 0');");
}


// OPEN LINKS CHOICE
function windowOpen(checkbox) {	
	if (!document.getElementsByTagName) { 
		return;
	}	
	else if(checkbox.checked) {
		var anchors = document.getElementsByTagName("a");
		
		for (var i=0; i < anchors.length; i++) {
		 var anchor = anchors[i];
			 if (anchor.getAttribute("href") && anchor.getAttribute("rel") == "external") {
				anchor.target = "_blank";
			 }
		}	
		var date = new Date();
		date.setTime(date.getTime()+(365*24*60*60*1000));		
		var expires = "expires="+date.toGMTString();
		document.cookie = "windowOpenCookie=true; expires="+expires+"; path=/";
	}
	else {
		var anchors = document.getElementsByTagName("a");
		
		for (var i=0; i < anchors.length; i++) {
		 var anchor = anchors[i];
			 if (anchor.getAttribute("href") && anchor.getAttribute("rel") == "external") {
				anchor.target = "";
			 }
		}	
		var date = new Date();
		date.setTime(date.getTime()-(365*24*60*60*1000));		
		var expires = "expires="+date.toGMTString();
		document.cookie = "windowOpenCookie=blank; expires="+expires+"; path=/";
	}
}

// OPEN LINKS CHOICE COOKIE CHECK
function getCookie(c_name)
{
if (document.cookie.length>0)
  {
  c_start=document.cookie.indexOf(c_name + "=")
  if (c_start!=-1)
    { 
    c_start=c_start + c_name.length+1 
    c_end=document.cookie.indexOf(";",c_start)
    if (c_end==-1) c_end=document.cookie.length
    return unescape(document.cookie.substring(c_start,c_end))
    } 
  }
return ""
}

function windowCookie() {

	var windowOpenCookieValue = getCookie('windowOpenCookie');
	
	if (windowOpenCookieValue !=null && windowOpenCookieValue!="") {
		// Create an array with all of the links on the page.
		var anchors = document.getElementsByTagName("a");

		// Check through each of the links to check it contains rel="external" and if they do change target to _blank
		for (var i=0; i < anchors.length; i++) {
		 var anchor = anchors[i];
			 if (anchor.getAttribute("href") && anchor.getAttribute("rel") == "external") {
				anchor.target = "_blank";
			 }
		}	
		document.getElementById('windowOpen').checked=true;
	}	
}


//COMMENT FORM VALIDATION
    function validateScore(){
        x=document.form_comment
        txt=x.score.value
        if (txt>=1 && txt<=100) {
        hideAllErrors();
            return true;
}else{
	document.getElementById("scoreError").style.display = "inline";
	return false;
        }
}

function hideAllErrors() {
	document.getElementById("scoreError").style.display = "none"
	document.getElementById("FullNameError").style.display = "none"
	document.getElementById("commentError").style.display = "none"
}


//COMMENT CHARACTER COUNTDOWN
function limitText(limitField, limitCount, limitNum) {
	if (limitField.value.length > limitNum) {
	limitField.value = limitField.value.substring(0, limitNum);
	} else {
	limitCount.value = limitNum - limitField.value.length;
	}
}


//COMMENT RECAPTCHA THEME
var RecaptchaOptions = {
	theme : 'clean'
}

