var whichProd = "";
var tmpVal = "";
var cat = "";
var fromCookie = 0;
var metas = document.getElementsByTagName("meta");
var tmp = null;
var tmpVal = null;

	
function trimAll(sString) {
	if (sString != null){
		while (sString.substring(0,1) == ' ') {
			sString = sString.substring(1, sString.length);
		}
		while (sString.substring(sString.length-1, sString.length) == ' ') {
			sString = sString.substring(0,sString.length-1);
		}
	}
	return sString;
}


function Get_Cookie( name ) {
		
	var start = document.cookie.indexOf( name + "=" );
	var len = start + name.length + 1;
	
	if ( ( !start ) && ( name != document.cookie.substring( 0, name.length ) ) ) {
		return null;
	}
	if ( start == -1 ) {
		return null;
	}
	
	var end = document.cookie.indexOf( ";", len );
	
	if ( end == -1 ) end = document.cookie.length;
	
	return unescape( trimAll(document.cookie.substring( len, end ) ));
}


for (var i = 0; i < metas.length; i++) {

	if (metas[i].name == "product_service_name"){
		if ( Get_Cookie('smbRMcookie') ) {
			tmp = Get_Cookie('smbRMcookie');
		} else {
			tmp = null;
		}
		
		if (tmp != null){
			tmp = trimAll(tmp);
			tmp = tmp.replace(/\_/g,' ');
			//alert(tmp);
			metas[i].content = tmp;
			//alert(metas[i].content);
			i = metas.length;
			fromCookie = 1;
		}
		
	}
	
}

//alert(fromCookie);
if (fromCookie == 1) {
	document.write("<scr"+"ipt language=\"JavaScript\" type=\"text\/javascript\" src=\"http:\/\/www.hp.com\/country\/js\/hpweb_syn_con.js\"><\/scr"+"ipt>");
}


var urlString = document.location.href;
var urlString = urlString.toLowerCase();

var myDate = new Date;
myDate.setDate(myDate.getDate()+28);
//alert(myDate);

if (urlString.indexOf('topiccode=psg') > 0) { 
	whichProd='PSG';
	if (tmp == null) {
		document.cookie = 'smbRMcookie=notebooks_tablet_pcs/notebook_pcs; expires='+myDate+'; path=/'; 
	}
} else if (urlString.indexOf('topiccode=ipg') > 0) { 
	whichProd='IPG';
	if (tmp == null) {
		document.cookie = 'smbRMcookie=printing_and_multifunction; expires='+myDate+'; path=/'; 
	}
} else if (urlString.indexOf('topiccode=tsg') > 0) {     
	whichProd='TSG';
	if (tmp == null) {
		document.cookie = 'smbRMcookie=servers; expires='+myDate+'; path=/';
	}
}

if ( tmp != null && tmp != "null" && tmp != "" ) {
	tmpVal = tmp.toLowerCase();
}


if (whichProd == "") {     
	if (tmpVal) {    
		if (tmpVal.indexOf("printing") > 0 || tmpVal.indexOf("multifunction") > 0 || tmpVal.indexOf("supplies") > 0 || tmpVal.indexOf("accessories") > 0 || tmpVal.indexOf("fax") > 0 || tmpVal.indexOf("copiers") > 0 || tmpVal.indexOf("scanners") > 0 || tmpVal.indexOf("photo studios") > 0 ) {
			whichProd='IPG';
		} else if (tmpVal.indexOf("handhelds") > 0 || tmpVal.indexOf("calculators") > 0 || tmpVal.indexOf("handheld") > 0 || tmpVal.indexOf("pcs") > 0 || tmpVal.indexOf("desktops") > 0 || tmpVal.indexOf("workstations") > 0 || tmpVal.indexOf("desktop") > 0 || tmpVal.indexOf("notebooks") > 0 || tmpVal.indexOf("tablet") > 0 || tmpVal.indexOf("notebook") > 0 || tmpVal.indexOf("workstation") > 0) {
			whichProd='PSG';
		} else if (tmpVal.indexOf("servers") > 0 || tmpVal.indexOf("storage") > 0) {
			whichProd='TSG';
		}
	}
}

if ( tmpVal == "" || tmpVal == null || tmpVal == 'null' || tmpVal == undefined || tmpVal == 'undefined' ) {
	tmpVal = "";
}

if ( tmpVal.indexOf("accessories") >= 0 || tmpVal.indexOf("suppl") >= 0 ) {
	cat = "supplies";
} else if ( tmpVal.indexOf("calculator") >= 0 || tmpVal.indexOf("handheld") >= 0 ) {
	cat = "handhelds";
} else if ( tmpVal.indexOf("large") >= 0 ) {
	cat = "large";
} else if ( tmpVal.indexOf("photo printer") >= 0 || tmpVal.indexOf("inkjet") >= 0 || tmpVal.indexOf("color laserjet") >= 0 || tmpVal.indexOf("color hp laserjet") >= 0 ) {
	cat = "color_printers";
} else if ( tmpVal.indexOf("black and white multifunction") >= 0 || tmpVal.indexOf("all-in-one") >= 0 || tmpVal.indexOf("all in one") >= 0 ) {
	cat = "multifunction";
} else if ( tmpVal.indexOf("black and white") >= 0 ) {
	cat = "bw_printers";
} else if ( tmpVal.indexOf("multifunction") >= 0 ) {
	cat = "multifunction";
} else if ( tmpVal.indexOf("scanner") >= 0 ) {
	cat = "scanners";
} else if ( tmpVal.indexOf("server") >= 0 ) {
	cat = "servers";
} else if ( tmpVal.indexOf("storage") >= 0 ) {
	cat = "storage";
} else if ( tmpVal.indexOf("bw") >= 0 || tmpVal.indexOf("black") >= 0 ) {
	cat = "bw_printers";
} else if ( tmpVal.indexOf("color") >= 0 ) {
	cat = "color_printers";
} else if ( tmpVal.indexOf("monitor") >= 0 ) {
	cat = "monitors";
} else if ( tmpVal.indexOf("service") >= 0 ) {
	cat = "services";
} else if ( tmpVal.indexOf("services") >= 0 ) {
	cat = "services";
} else if ( tmpVal.indexOf("multifunction") >= 0 || tmpVal.indexOf("copiers") >= 0 || tmpVal.indexOf("fax") >= 0 ) {
	cat = "multifunction";
} else if ( tmpVal.indexOf("desktop pc") >= 0 ) {
	cat = "desktops";
} else if ( tmpVal.indexOf("workstation") >= 0 ) {
	cat = "workstations";
} else if ( tmpVal.indexOf("notebook") >= 0 || tmpVal.indexOf("tablet") >= 0) {
	cat = "notebooks";
} else if ( tmpVal.indexOf("desktop") >= 0 || tmpVal.indexOf("pc") >= 0 ) {
	cat = "desktops";
} else if ( tmpVal.indexOf("printing") >= 0 ) {
	cat = "ipg";
}
else
  	cat == "";

if ( cat == "" || cat == null || cat == 'null' || cat == undefined || cat == 'undefined' ) {
	cat = "dayspecial";
} else {
	recCookie = true;
}


var currentTime = new Date();
var day = currentTime.getDate();

var url="/cgi-bin/sbso/special/smb_specials.cgi?site=sbso&cat="+cat+"&day="+day;

//alert("Testing Information:\n\nCookieVal: "+tmpVal+"\nCategory: "+cat+"\nDay of Month: "+day+"\nURL Passed: "+url);



	
