/* 
	JAVASCRIPT FOR LINK ROTATION

 	Created by: Richard A. Muscat / richardam@uniblue.net
	On:			24th November 2007
	Modified:	 6th March	  2008
	Modified:	25th March	  2008 - Sharon Zahra
*/

var rules_home = 3;
var box_home_1 = new Array();
	box_home_1[0] = "<img src='/assets/graphics/hp/rotation/banner-0.jpg' border='0' usemap='#banner-0' class='banner-fix' />";
	box_home_1[1] = "<img src='/assets/graphics/hp/rotation/banner-1.jpg' border='0' usemap='#banner-1' class='banner-fix' />";
	box_home_1[2] = "<img src='/assets/graphics/hp/rotation/banner-2.jpg' border='0' usemap='#banner-2' class='banner-fix' />";

var rules_plib = 5;
var box_plib_1 = new Array();
	box_plib_1[0] = "0: Default (RB)";
	box_plib_1[1] = "1: Change Link (RB)";
	box_plib_1[2] = "2: Change Product (SP)";
	box_plib_1[3] = "3: Change Link (SP)";
	box_plib_1[4] = "4: Change Link (SP 2)";
	
var box_plib_2 = new Array();
	box_plib_2[0] = "2nd variation - 0: Default (RB)";
	box_plib_2[1] = "2nd variation - 1: Change Link (RB)";
	box_plib_2[2] = "2nd variation - 2: Change Product (SP)";
	box_plib_2[3] = "2nd variation - 3: Change Link (SP)";
	box_plib_2[4] = "2nd variation - 4: Change Link (SP 2)";
	

	if (location.href != '') {
		var url = location.href;
		var ext = url.split("/");
		var theNewVar = ext[7];
	}

// Variation 1 for file-extension.com on Liutilities.com

var rules_fextli = 5;
var box_fextli_1 = new Array();

	box_fextli_1[0] = "<a href='/products/campaigns/filext/rb'>Click here to run a free scan for ." + theNewVar + " errors </a>";
	box_fextli_1[1] = "<h3 style='font-size:12px; color:#A70000;'>Recommendation for ." + theNewVar + " file users:</h3> <a href='/products/campaigns/filext/rb/lr'>Scan for ." + theNewVar + " errors</a> to make your system more stable";
	box_fextli_1[2] = "<a href='/products/campaigns/filext/sp/lr'>Run a scan for ." + theNewVar + " performance errors</a>";
	box_fextli_1[3] = "<span style='font-size:12px; color:#A70000; font-weight:bold;'>NOTE:</span> " + theNewVar + " files may be affecting your PC's performance. <a href='/products/campaigns/filext/sp/lr'>Click here to scan your PC.</a>";
	box_fextli_1[4] = "<a href='/products/campaigns/filext/rb/lr'>Click here to run a free scan for ." + theNewVar + " errors</a>";

  
// Variation 2 for file-extension.com on Liutilities.com

var box_fextli_2 = new Array();

	box_fextli_2[0] = "We strongly recommend that you <a href='/products/campaigns/filext/rb'>run a free registry scan</a> to identify ." + theNewVar + " related errors.";
	box_fextli_2[1] = "We strongly recommend that you <a href='/products/campaigns/filext/rb/lr'> download RegistryBooster 2</a> to identify ." + theNewVar + " related errors.";
	box_fextli_2[2] = "<br /><br /><font style='color:#A70000; font-weight:bold; font-size:12px;'>Recommendation:</font><br /> We strongly recommend that you <a href='/products/campaigns/filext/sp/lr'>run a free performance scan</a> for ." + theNewVar + " related errors.";
	box_fextli_2[3] = "We strongly recommend that you <a href='/products/campaigns/filext/rb'>run a free performance scan</a> for ." + theNewVar + " related errors.";
	box_fextli_2[4] = "We strongly recommend that you <a href='/products/campaigns/filext/rb/lr'>run a free registry scan</a> for ." + theNewVar + " related errors";
	
	
	
/* ======================================================================= */

	if (location.href != '') {
		var url = location.href;
		var ext = url.split("/");
		var theNewVar1 = ext[6];
	}

// Variation 1 for processlibrary on Liutilities.com
http://www.liutilities.com/products/campaigns/plib/rbplib
var rules_plibli = 5;
var box_plibli_1 = new Array();
	box_plibli_1[0] = "<a href='/products/campaigns/plib/rbplib'>Click here to run a free scan for ." + theNewVar1 + " errors </a>";
	box_plibli_1[1] = "<span style='font-size:12px; color:#A70000; font-weight:bold;'>Recommendation for ." + theNewVar1 + " file users:</span><br /> <a href='/products/campaigns/plib/rbplib/lr'>Scan for ." + theNewVar1 + " errors</a> to make your system more stable";
	box_plibli_1[2] = "<a href='/products/campaigns/plib/spplib/lr'>Run a scan for ." + theNewVar1 + " performance errors</a>";
	box_plibli_1[3] = "<span style='font-size:12px; color:#A70000; font-weight:bold;'>NOTE:</span> " + theNewVar1 + " files may be affecting your PC's performance. <a href='/products/campaigns/plib/spplib/lr' style='display:inline;'>Click here to scan your PC.</a>";
	box_plibli_1[4] = "<a href='/products/campaigns/plib/rbplib/lr'>Click here to run a free scan for ." + theNewVar1 + " errors</a>";

  
// Variation 2 for processlibrary on Liutilities.com

var box_plibli_2 = new Array();

	box_plibli_2[0] = "We strongly recommend that you <a href='/products/campaigns/plib/rbplib'>run a free registry scan</a> to identify ." + theNewVar1 + " related errors.";
	box_plibli_2[1] = "We strongly recommend that you <a href='/products/campaigns/plib/rbplib/lr'> download RegistryBooster 2</a> to identify ." + theNewVar1 + " related errors.";
	box_plibli_2[2] = "<br /><br /><font style='color:#A70000; font-weight:bold; font-size:12px;'>Recommendation:</font><br /> We strongly recommend that you <a href='/products/campaigns/plib/spplib/lr'>run a free performance scan</a> for ." + theNewVar + " related errors.";
	box_plibli_2[3] = "We strongly recommend that you <a href='/products/campaigns/plib/spplib/lr'>run a free performance scan</a> for ." + theNewVar1 + " related errors.";
	box_plibli_2[4] = "We strongly recommend that you <a href='/products/campaigns/plib/rbplib/lr'>run a free registry scan</a> for ." + theNewVar1 + " related errors";



var rules = 3;
var section_1 = new Array();
var section_2 = new Array();
var active    = new Array();

// Main link rotation functions
function rotateLinks(section) {
	var count;
	
	switch (section) {
		case "home" : 									// home page
			rules = rules_home;
			section_1 = box_home_1;
			
			active[0] = beenThere('psp');				// ps purchase page
			active[1] = beenThere('spp');				// sp purchase page
			active[2] = beenThere('rbp');				// rb purchase page
			
			count = parseInt(getCookie("__ubhome"));
			
			break;
			
		case "plibli" :									// process library
			rules = rules_plibli;
			section_1 = box_plibli_1;
			section_2 = box_plibli_2;
			
			active[0] = beenThere('rbd');				// rb download page
			active[1] = beenThere('rbd');
			active[2] = beenThere('spd');				// sp download page
			active[3] = beenThere('spd');
			active[4] = beenThere('spd');
			
			count = parseInt(getCookie("__ubplibli"));
			
			break;
			
		case "fextli" :									// file-ext library
			rules = rules_fextli;
			section_1 = box_fextli_1;
			section_2 = box_fextli_2;
			
			active[0] = beenThere('rbd');				// rb download page
			active[1] = beenThere('rbd');
			active[2] = beenThere('spd');				// sp download page
			active[3] = beenThere('spd');
			active[4] = beenThere('spd');
			
			count = parseInt(getCookie("__ubfextli"));
			
			break;
			
	}
	
	doRotation(section, count);	
}

function doRotation(section, index) {
	var i = 0;
	
	while(active[index]==true && index <= rules) {
		index++;
	}
		
	if (index<0||index==null||index>=rules) {index=0;}
			
	switch (section) {
		case "home" :
			document.getElementById("section-1").innerHTML = section_1[index];
			break;
			
		case "plib" :
			document.getElementById("section-1").innerHTML = section_1[index];
			document.getElementById("section-2").innerHTML = section_2[index];
			break;

		case "fextli" :
			document.getElementById("section-1").innerHTML = section_1[index];
			document.getElementById("section-2").innerHTML = section_2[index];
			break;
			
		case "plibli" :
			document.getElementById("section-1").innerHTML = section_1[index];
			document.getElementById("section-2").innerHTML = section_2[index];
			break;

	}
}


// Function to update page-count and pages-visited cookies
function uniblueTracker(section, flag) {
	switch (section) {
		case "home" : 
			setCookieCount("__ubhome");		// set home count cookie
			break;
	
		case "fextli" : 
			setCookieCount("__ubfextli");		// set file ext on liutilites count cookie
			break;
			
		case "plibli" : 
			setCookieCount("__ubplibli");		// set process on liutilites count cookie
			break;
	}
	
	setCookieValue("__ubpage", section);	// set page cookie
	setCookieCount("__ubcnt", 100);			// set total page count
}




/*	===========================
	ADDITIONAL HELPER FUNCTIONS
	===========================	 */

// Checks whether 'string' is in cookie '__ubpage'
function beenThere(string) {
	var oldCookie = getCookie("__ubpage");
	if (oldCookie.indexOf(string)>-1) {return true;} else {return false;}
	return false;
}

// Returns a count of the number of boolean true values in 'list'
function countTrue(list) {
	var i=0;
	for (var x=0;x<list.length-1;x++) {if (list[x]==true) {i++;}}
	return i;
}

// Set a cookie on the client's browser. 
function setCookie(cookieName, cookieValue) {
	nDays=90;
	var today=new Date();
	var expire=new Date();
 	if (nDays==null||nDays==0) nDays=1;
	expire.setTime(today.getTime()+3600000*24*nDays);
	document.cookie=cookieName+"="+escape(cookieValue)+";path=/;expires="+expire.toGMTString();
}

// Get the value of 'cookieName' from client's browser.
function getCookie(cookieName) {
	if (document.cookie) {
		index=document.cookie.indexOf(cookieName);
		if (index!=-1) {
			cookie_start=(document.cookie.indexOf("=", index) + 1);
			cookie_end=document.cookie.indexOf(";", index);
			if (cookie_end==-1) {cookie_end=document.cookie.length;}
			return document.cookie.substring(cookie_start, cookie_end);
		}
	}
	return "undefined";
}

// Increment a cookie counter
function setCookieCount(cookieName, limit) {
	var oldCookie = getCookie(cookieName);
	if (oldCookie==null||oldCookie=="undefined") {newCookie=0;} else {
		var oldValue = parseInt(oldCookie);
		if (oldValue>=limit) {newCookie=0;} else {newCookie=oldValue+1;}
	}
	setCookie(cookieName, newCookie);
}

function setCookieCount(cookieName) {
	var oldCookie = getCookie(cookieName);
	if (oldCookie==null||oldCookie=="undefined") {newCookie=0;} else {newCookie = parseInt(oldCookie) + 1;}
	setCookie(cookieName, newCookie);
}

// Check if 'cookieValue' exists in 'cookieName', and if not adds it to cookie
function setCookieValue(cookieName, cookieValue) {
	var oldCookie = getCookie(cookieName);
	if (oldCookie==null||oldCookie=="undefined") {newCookie=cookieValue;} else {if (oldCookie.indexOf(cookieValue)==-1) {newCookie=oldCookie+"-"+cookieValue;} else {newCookie=oldCookie;}}
	setCookie(cookieName, newCookie);
}