// Compaq home page Javascript functions
// Provides Cookie, image preloading and Flash layer functionalities


// START cookie functions

function isNumber(a) {
	if (a.length>1){return false;}
	var string="1234567890";
	if (string.indexOf(a)!=-1){return true;}
	return false;
}

function getCookie(NameOfCookie){
	if (document.cookie.length > 0) {
		begin = document.cookie.indexOf(NameOfCookie+"=");
		if (begin != -1) {
			begin += NameOfCookie.length+1;
			end = document.cookie.indexOf(";", begin);
			if (end == -1) end = document.cookie.length;
			return unescape(document.cookie.substring(begin, end));
		}
	}
	return null;
}

function delCookie (NameOfCookie) {
	if (getCookie(NameOfCookie)) {
		document.cookie = NameOfCookie + "=" + "; expires=Thu, 01-Jan-70 00:00:01 GMT";
	}
}

function setCookie(nCookie, value, expiredays) {

		delCookie(nCookie);
		//var domain = ".compaq.com";
		var path = "/";
		var expireDate = new Date();
		expireDate.setTime(expireDate.getTime() + (expiredays * 24 * 3600 * 1000));
		//document.cookie = NameOfCookie + "=" + escape(value) + ((expiredays) ? "; expires=" + expireDate.toGMTString() : "") + ((domain) ? "; domain=" + domain : "") + ((path) ? "; path=" + path : "");
		document.cookie = nCookie + "=" + escape(value) + ((expiredays) ? "; expires=" + expireDate.toGMTString() : "") + ((path) ? "; path=" + path : "");

}

function flashViewedCookie(nCookie) {
	var viewed=getCookie(nCookie);
	if(viewed!=null && viewed == 'true') {
		return true;
	} else return false;
}


// End Cookie functions


// Begin preloading of rollover images
var active = 0;

var msgImg = new Array();
var imgMsg_array = new Array();

var rollOutDelay = 2000;
var timerID=null;

for(var i in msg_sources){
	imgMsg_array[i] = new Image();
}

function preloadMsg(){
	for(var i in msg_sources){
		imgMsg_array[i].src = msg_sources[i];
		msgImg[i] = imgMsg_array[i].src;
	}     
}

function selectImg(imgID){
	if(timerID) {
		clearTimeout(timerID);
		timerID=null;
	}
	if(active != imgID){
		active = imgID;
		if(!is_ie) document.getElementById("messageArea").src=msgImg[imgID];
		else document.getElementById("messageArea").src=msg_sources[imgID];
	}
}

// on rollout wait 2 seconds and switch back to welcome image
function delay_rollOut() {
	timerID = setTimeout("selectImg(0)",rollOutDelay);
}

// IE will not play preloaded animated GIFs
if(!is_ie) preloadMsg();

// End preloading of rollover images

// Begin layer switching functions

function hideFlash(){
	// Flash was played, set cookie to skip it next time
	if(!flashViewedCookie("cpq_flash_viewed")) setCookie("cpq_flash_viewed", true, 30);
	
	var flashDiv = document.getElementById('flashcontent');
	if (flashDiv && flashDiv.parentNode &&
		flashDiv.parentNode.removeChild) {
			flashDiv.parentNode.removeChild(flashDiv);
	}
}

function clearFlashBground() {
	if(document.getElementById('flashcontent')) document.getElementById('flashcontent').style.background = "transparent";
}

function writeFlash() {
	if(!flashViewedCookie("cpq_flash_viewed")) {
		if(typeof document.getElementById!="undefined"){
			var so = new SWFObject("cq_picto.swf", "cppicto", "630", "425", "8", "#fff");
			so.addParam("wmode", "transparent");
			so.addParam("allowScriptAccess", "sameDomain");
			so.addVariable("xmlfile", cq_home_flash_xml);
			so.write("flashcontent");
		}
	}
	document.getElementById('contentOptions').style.display = 'block';
}

window.onload = writeFlash;

// End layer switching functions


// 20070627