function random() {
    rannum = Math.round(Math.random()*10);
    return rannum;
}

function setCookie(name, value) {
	var expire = new Date();
	var today = new Date();
	expire.setTime(today.getTime() + 1000*60*60*24*4);
	document.cookie = name + "=" + escape(value) + "; path=/"   + ((expire == null) ? "" : ("; expires=" + expire.toGMTString()))
}

function getCookie(Name) {
	var search = Name + "="
	if (document.cookie.length > 0) {// if there are any cookies
		offset = document.cookie.indexOf(search)
		if (offset != -1) { // if cookie exists
			offset += search.length;
			// set index of beginning of value
			end = document.cookie.indexOf(";", offset)
			// set index of end of cookie value
			if (end == -1)
				end = document.cookie.length
			return unescape(document.cookie.substring(offset, end))
		}
	}
}

function getMemberName(x) {
	start = (x.indexOf(";") + 1);
	end = x.indexOf(";", start);
	var name = x.substr(start, (end - start));
	return name
}
function OpenEmailArticleWindow(querystring)
{
	LeftPosition = (screen.width) ? (screen.width)/10 : 0;
	TopPosition = (screen.height) ? (screen.height)/10 : 0;
	settings = 'menubar=no,height=575,width=365,resizable=yes,scrollbars=yes'
	hWin = window.open(querystring,"SaveArticle",settings,true);
	hWin.focus();
	if (hWin.opener == null) hWin.opener = self;
}

function RedirectToSearch(siteRoot){
	//QB ID = 3192
	//var siteID = (document.searchForm.searchsite[0].checked) ? document.searchForm.searchsite[0].value : document.searchForm.searchsite[1].value;
	var siteID = document.searchForm.hidsearchsite.value;
	if (siteID == "")
	{
		siteID = 0
	}
	window.location = siteRoot + "pages/search_results.aspx?qry=" + escape(document.searchForm.txtSearch.value) + "&searchsite=" + escape(siteID);
}

function RedirectToShopSearch(siteRoot){
	var qry = siteRoot + "pages/search_controller.aspx?qry=";
	qry += escape(document.shopSearchForm.txtShopSearch.value);
	
	for(var i = 0; i < 2; i++) {
		if(document.shopSearchForm.searchSection[i].checked) {
			qry += "&shopSearchType=" + escape(document.shopSearchForm.searchSection[i].value);
	}}

	//alert(qry);
	
	window.location = qry;
}
///////////////////////////////////////////////////////////////////////////////
function performZipDisplay()
{
	performZipDisplayUnStruc();
}

function performZipDisplayUnStruc()
{
	if (zipcode())
	{ 
		var newUrl = window.location.href;
		var beforeZip = "";
		var afterZip = "";
		var zipPos = newUrl.indexOf("ZC");
		if (zipPos == -1)
			zipPos = newUrl.indexOf("zc");
		var queryPar = "?";
		if ( zipPos != -1)
		{
			//get the url string before zip code
			beforeZip = newUrl.substring(0, zipPos);
			//get the url string after zip code. Assuming that zip code is of 5 characters long
			afterZip = newUrl.substring(zipPos + 8, newUrl.length); 
			
			//check to see if the character ending before "ZC" is "&" or "?"
			//If any, do not add a new character. 
			//example: *.aspx?SB=6&SO=2&ZC=12345          *.aspx?ZC=12345			
			if (newUrl.charAt(zipPos-1) == "&" || newUrl.charAt(zipPos-1) == "?")
			{
				queryPar = "";
			}			
			//redirect with proper zip code
			window.location.href = beforeZip + queryPar + "ZC=" + document.forms[1].inputbox.value + afterZip;
		}
		else
		{
			//If there is no Zip code in the URL
			//Check to see if there are any "&", if so add zip code with an "&" - example: *.aspx?SB=6&SO=2
			//else if there are any "?", add zip code with nothing - example: *.aspx?
			//if none true then add with "?" - example: *.aspx
			if (newUrl.indexOf("&") != -1)
			{
				queryPar = "&";
			}
			else if (newUrl.indexOf("?") != -1)
			{
				if((newUrl.indexOf("?") + 1) == newUrl.length)
					queryPar = "";
				else
					queryPar = "&";					
			}
			//redirect with proper zip code
			window.location.href =  newUrl + queryPar + "ZC=" + document.forms[1].inputbox.value;
		}
		
		
	}
}


function openwindow(site)
{	
	popup=window.open(site,'popup','scrollbars=1,width=350,height=500');
}
function openwindow1(site, windowName, windowAttributes)
{
	popup=window.open(site, windowName, windowAttributes);
}
function openurl(URL)
{
  	window.location.href=URL;
}
function TextResult(inputbox)
{
            return(inputbox.value);
}
function zipcode()
{
	var zip_code=document.forms[1].inputbox;

	if  (isNaN(zip_code.value))
	{
		alert("Please enter a 5 digit ZipCode !");
		return false;
	}
	if((Trim(zip_code.value)).length !=5)
	{
		alert("Please enter a 5 digit ZipCode !");
		return false;
	}
    return true;
}

function Trim(TRIM_VALUE)
{
	if(TRIM_VALUE.length < 1){
		return"";
	}
	TRIM_VALUE = RTrim(TRIM_VALUE);
	TRIM_VALUE = LTrim(TRIM_VALUE);
	if(TRIM_VALUE==""){
		return "";
	}
	else{
		return TRIM_VALUE;
	}
} //End Function

function RTrim(VALUE)
{
	var w_space = String.fromCharCode(32);
	var v_length = VALUE.length;
	var strTemp = "";
	if(v_length < 0){
		return"";
	}
	var iTemp = v_length -1;

	while(iTemp > -1){
		if(VALUE.charAt(iTemp) == w_space){
		}
		else{
			strTemp = VALUE.substring(0,iTemp +1);
			break;
		}
		iTemp = iTemp-1;

	} //End While
	return strTemp;

} //End Function

function LTrim(VALUE){
	var w_space = String.fromCharCode(32);
	if(v_length < 1){
		return"";
	}
	var v_length = VALUE.length;
	var strTemp = "";

	var iTemp = 0;

	while(iTemp < v_length){
		if(VALUE.charAt(iTemp) == w_space){
		}
		else{
			strTemp = VALUE.substring(iTemp,v_length);
			break;
			}
		iTemp = iTemp + 1;
	} //End While
	return strTemp;
} //End Function


//
// This function switches an elements visibility on or off
// depending upon its current state. It is used to show or hide 
// content via a "collapsible" region.  The id passed in is the
// the id of the (usually) <div></div> region or object id to hide.
// 
// Author: L. Chevres 
//
function showHideContent(id)
{
    var elem = document.getElementById(id);
	if (elem) 
   	{
      	if (elem.style.display == 'none')
      	{
       		elem.style.display = 'block';
        	elem.style.visibility = 'visible';
      	} 
      	else
	    {
        	elem.style.display = 'none';
        	elem.style.visibility = 'hidden';
      	}
	}
	return false;
}    

/****************** PCMAG 2 Header javascript ******************************/
var HeaderMoreLink_clearTimer;
function HeaderMoreLink_hideAdSpace(){
	// Set a timer to clear
	HeaderMoreLink_clearTimer = window.setTimeout('HeaderMoreLink_hideAdSpaceDo()', 375);
}
function HeaderMoreLink_resetAdTimer(){
	// User has moused over the adspace, so set the clear the timer
	window.clearTimeout(HeaderMoreLink_clearTimer);
}
function HeaderMoreLink_hideAdSpaceDo(){
	document.getElementById("HeaderMoreLink_AdSpace").style.visibility = "hidden";
	document.getElementById("HeaderMoreLink_AdSpace").style.display = "none";
}
function HeaderMoreLink_showAd(){
	HeaderMoreLink_resetAdTimer();
	// Unhide the parent div so we see the whole thing
	document.getElementById("HeaderMoreLink_AdSpace").style.visibility = "visible";
	document.getElementById("HeaderMoreLink_AdSpace").style.display = "block";
}

//////////////////////////////////////////////////////////////////////////////////


var browsers = "mozilla msie gecko firefox "
browsers += "konqueror safari netscape navigator opera ";
browsers += "mosaic lynx amaya omniweb";

var nav, ver, browsers = browsers.split(" ");
var nua = navigator.userAgent.toLowerCase();
var l = nua.length;
for (var i=0; i<browsers.length; i++){
  var browser = browsers[i];
  var n = nua.indexOf(browser);
  if(n>-1){
    ver = ""; nav = browser;
    for (var j=(n+nav.length+1); j<=l; j++){
      s = nua.substring(j,j+1)
      if(isNaN(ver+s)) break; else ver += s;
    }
  }
}

function loadContentFromUrl( url , handler ) {
  if(window.XMLHttpRequest) {
    try { xmlhttp = new XMLHttpRequest();
    } catch(e) { xmlhttp = false; }
  } else if(window.ActiveXObject) {
    try { xmlhttp = new ActiveXObject('Msxml2.XMLHTTP');
    } catch(e) {
    try { xmlhttp = new ActiveXObject('Microsoft.XMLHTTP');
    } catch(e) { req = false; }
  } }
  if(xmlhttp) {
    xmlhttp.onreadystatechange = handler;
    xmlhttp.open('GET', url, true);
    xmlhttp.send('');
  }
}




