/* Copyright: Virgin net */
var d=document;
var isKiosk;
var mM = [];
// Page: is an object to create execute a collection of functions on the onload event
function Page(name){
    //name is the property defining the name of the object this property is not used in this object but as an habit of conscistency I like define to have it define
	this.name = name;
	//fn_load: is an array who will contain function to be loaded by the loader method
	this.fn_load = [];
};
//load: is a method who add function name to the fn_load array
Page.prototype.load = function(fn_name){
	this.fn_load[this.fn_load.length] = fn_name;
};
//loader: is a method who is called on the window.onload. This as been unified over the site to be called on the body tag onload properties 
Page.prototype.loader = function(){
	for(var i=0;i<this.fn_load.length;i++){
		eval(this.fn_load[i]);
	}
};
//page: is the instance of the object Page
var page = new Page('page');


/* XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX */
//cursor: is an object who will constantly follow the x and y position of the mouse when the mouseMove function is called 
var cursor = {};
function mouseMove(e) {
	cursor.x = (is.ns)? e.pageX : event.x+document.body.scrollLeft;
	cursor.y = (is.ns)? e.pageY : event.y+document.body.scrollTop
	status = 'x = ' + cursor.x + 'px || y = ' + cursor.y + 'px';
	return true;
};
// to use this function you must use the event document.onmousemove and assign the mousemove view the examples below 
// document.onmousemove = mouseMove;
/* XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX */
//now: is the date of the moment when the file as been loaded
var now = new Date();
//todayDate: is the day number 1-31
var todayDate = now.getDate();
//todayDay: is the day this represent a number 0-6
var todayDay = now.getDay();
//week_days: this are the day of the week this array is to be used in relation with the variable "todayDay" as follow week_days[todayDay] and this return the day of today as string 
var week_days = new Array('Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday');
//week_dayNum_abrev: this array contains the days abbreviation 
var week_dayNum_abrev = new Array('st','nd','rd','th');
//get_week_day_abrev: this function will return the abbreviation you put after the date number like Friday 5th August this function is to be used in relation with the variable "todayDate" as follow get_week_day_abrev(todayDate) and this return the abbreviation for today date
function get_week_day_abrev(dayNum){
	var abrv = (dayNum.toString().match(/1$/))? week_dayNum_abrev[0] :(dayNum.toString().match(/2$/))? week_dayNum_abrev[1] : (dayNum.toString().match(/13$/))? week_dayNum_abrev[3] : (dayNum.toString().match(/3$/))? week_dayNum_abrev[2] : week_dayNum_abrev[3] ;
	return abrv;
};
//addDays: this function will add x number of day to a date if you need the date to be set up 30 days from now just do this addDays(now,30)
function addDays(myDate,days) {
    return new Date(myDate.getTime() + days*24*60*60*1000);
};
function minusDays(myDate,days) {
 return new Date(myDate.getTime() - (days*24*60*60*1000));
};
//todayMonth: is the current month
var todayMonth = now.getMonth();

//Month: is an object to create an array of the month of the calendar 
function Month(name, numOfDay){
    //name = the name of the month
	this.name = name;
	//dayNum: the amount of day in a month "this properties should never be used in your code to get the amount of day in a month but the method numOfDay() should be used"
	this.dayNum = numOfDay;
    //numOfDay: is a method who will return the amount of day for the month instance object
	this.numOfDay = getNumOfDay;
};
//getNumOfDay: the constructor for the method "numOfDay" in the object Month
function getNumOfDay(year){
    //requestedYear: is the year you request the amount of day for the month object
	var requestedYear =(year)? new Year(year) : todayYear;
	if(requestedYear.leapYear && this.dayNum==28){
		return 29;
	}else{
		return this.dayNum;
	}
};
//month: is an array containing the list of month of the calendar this is to be used in relation with the varaible month[todayMonth].name to get the name of the month we are in
var month = new Array();
month[month.length] = new Month('January',31);
month[month.length] = new Month('February',28);
month[month.length] = new Month('March',31);
month[month.length] = new Month('April',30);
month[month.length] = new Month('May',31);
month[month.length] = new Month('June',30);
month[month.length] = new Month('July',31);
month[month.length] = new Month('August',31);
month[month.length] = new Month('September',30);
month[month.length] = new Month('October',31);
month[month.length] = new Month('November',30);
month[month.length] = new Month('December',31);


//Year: is an object to deal with the year 
function Year(yearNum){
    //yearNum: does return the year number we are in this is to be used because it fixe a kind of weird bug in some browser (some browser will return 105 for 2005 I think most of new browser have been fixed now)
	this.yearNum = (yearNum<1900)? yearNum + 1900 : yearNum;
	var leapNum = new Number((this.yearNum-4)/4);
    //leapYear: return true if the year is a leap year and false if not
	this.leapYear = (leapNum.toString().indexOf('.')==-1)? true : false;
};
//todayYear: is the instance of the Year object to get the year num you should call the property "yearNum" as follow "todayYear.yearNum"
var todayYear = new Year(now.getYear());
/* XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX */
//getO: this function will return the htmlElementObject the parameter id must be the id of the html elmenent you wish to get the object for. The css parameter can be any value if omited this function will be equal as "document.getElementById('someId')" otherwise it will return the styleElementObject and equal as "document.getElementById('someId').style" this are just represented as examples it will accordingly the appropriate object in different browser
function getO(id, css){
	var o = (is.ie && is.mac)? d.all[id] : (d.getElementById && css)? d.getElementById(id).style :(d.getElementById)? d.getElementById(id) :(css)? d.all[id].style : d.all[id] ;
	return o;
};
/* XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX */
//flipImg: is really simple function to do image rollover the restriction applied to this function are that it will only work with gif and the naming convention applied to the image who must be as follow "imageName.gif" and "imageName_on.gif"
//<img name="myImage" src="imageName.gif" onmouseover="flipImg(this.name)" onmouseout="flipImg(this.name)">
function flipImg(imgName){
	var obj = createImgObj(imgName);
	var imgSrc = obj.src;
	var iN = imgSrc.split('/');
	var iName = iN[iN.length-1].split('.');
	if (iName[0].indexOf("_sel")==-1){
		var imgOn = (iName[0].indexOf("_on") > -1)? true : false;
		var state = imgSrc.replace('.gif','_on.gif');
			if (imgOn){
			state = imgSrc.replace('_on.gif','.gif');
			}		
		obj.src = state;
		return true;
	}
};
//preloadImg: is a really simple function to preload an image rollover state the restriction of this function are that the image have to be a gif and that the rollover name must contain _on is to be used as described below
//<img name="myImage" src="imageName.gif" onload="preloadImg(this)" onmouseover="flipImg(this.name)" onmouseout="flipImg(this.name)">
var preloadedImg = [];
function preloadImg(imgO){
	if(typeof imgO.preloaded == 'undefined'){
		imgO.preloaded = true;
		var imgSrc = imgO.src;
		pAImgL = preloadedImg.length;
		preloadedImg[pAImgL] = new Image();
		preloadedImg[pAImgL].src = imgSrc.replace('.gif','_on.gif');
	}
};
/* XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX */
//createImgObj & getImgO: return the image object from the image array of the document
function createImgObj(imgId){return d.images[imgId];};
function getImgO(imgId){return d.images[imgId];};
/* XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX */
//writeInO// simply write any piece of html in the referenced object
function writeInO(o,sTxt){
	o.innerHTML = sTxt;
};
/* XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX */
//getWidth: return the actual width of a box element this work best with div
function getWidth(o){return o.offsetWidth;};
//getHeight: return the actual height of a box element this work best with div
function getHeight(o){return o.offsetHeight;};
/* XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX */
//getAbsX: return the absolute top and left position of an element becareful this will however not be consistent on the make
function getAbsX(elt) {return getAbsPos(elt,"Left")};
function getAbsY(elt) {return getAbsPos(elt,"Top")};
function getAbsPos(obj,which) {
	iPos = 0;
	while (obj != null) {
		iPos += obj["offset" + which];
		obj = obj.offsetParent;
	}
	return iPos;
};
/* XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX */
//apply_clip: will apply a clip area to a block element (to be able to apply clip to an element this element must be position absolute)
function apply_clip(obj, top, right, bottom, left){
	obj.clip = 'rect(' + parseInt(top) + 'px ' + parseInt(right) + 'px ' + parseInt(bottom) + 'px ' + parseInt(left) + 'px)';
};
//get_clip: get the clip from an element you must tell the function which value you are interested in 
function get_clip(obj, which){
	var clipArray = new Array();
	var re = /px,/gi;
	var objClip = obj.clip.replace(re, "px");
	var splitClip = objClip.split("rect(")[1].split(")")[0].split("px");
	clipArray['top'] =  splitClip[0];
	clipArray['right'] = splitClip[1];
	clipArray['bottom'] = splitClip[2];
	clipArray['left'] = splitClip[3];
	return parseInt(clipArray[which]);
};
/* XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX */
//apply_opacity: apply the oppacity to an element (to apply an opacity to an element first the css or inline style of this element must be declared as having an oppacity if you try applying the oppacity to an element who didn't have it define you will get an error)
function apply_opacity(obj, opacity){
	if(is.ie){
		if(is.ie5){
			obj.style.filter = 'alpha(opacity=' + opacity + ')';
		}else{
			obj.filters.alpha.opacity = opacity;
		}
		return true;
	}else if(is.dom){
		obj.style.MozOpacity = (opacity/100);
		return true;
	}
};
//get_opacity: this will return the actual oppacity value applyied to an element 
function get_opacity(obj){
	if(is.ie){
		if(is.ie5){
			var ft = obj.style.filter;
			ft = ft.replace(/([\w-_]+\()*([\w-_]+\=)/, '');
			ft = ft.replace(/\)/,'');
			return ft;
		}else{
			return obj.filters.alpha.opacity;
		}
		
	}else if(is.dom){
		return obj.style.MozOpacity*100;	
	}
};
/* XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX */
//get_randomVal: return a random number between 0 and the maxNum specified in the parameter 
function get_randomVal(maxNum){
	return Math.round(Math.random()*(maxNum));
};
/* XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX */
//img: simply return a string representing an image tag the parameter of this function can be inputed freely describe below
//img('src="myImage.gif"', 'width="1"', 'height="1"'... etc)
function img(){
var str = '<img';
var altFlag = true;
	for(var i=0;i<arguments.length;i++){
		str += ' ' + arguments[i];
		if(arguments[i].indexOf('alt=')>-1){
			altFlag = false;
		}
	}
	if(altFlag){
		str += ' alt=""';
	}
	str += '/>';
	return str;
};
//spacer: is the same as the function above "img" except that you don't need to specify the src attribute as it will automaticly default to the transparent gif
function spacer(){
	var str = '<img src="http://www.virgin.net/pix/dot.gif"';
	var altFlag = true;
	for(var i=0;i<arguments.length;i++){
		str += ' ' + arguments[i];
		if(arguments[i].indexOf('alt=')>-1){
			altFlag = false;
		}
	}
	if(altFlag){
		str += ' alt=""';
	}
	str += '/>';
//	alert(str);
	return str;
};
/* XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX */
//All the function below are related to writting style dynamcly with javascript 
function posAbs(){
	return 'position:absolute';
};
function left(L){
	var iMargin = (typeof sMrg == 'undefined')? 0 : sMrg;
	return 'left:' + (iMargin+L);
};
//Top: is written with the first letter uppercase because "top" is a native function in safari (and safari doesn't allow overwriting native function)
function Top(T){
	return 'top:' + T;
};
function width(W){
	return 'width:' + W;
};
function height(H){
	return 'height:' + H;
};
function bgC(hex){
 return 'background-color:#' + hex;
};
function visi(val){
	return 'visibility:' + val;
};

//getDim: will actually return the number value of a width, height, top, left
function getDim(str){
	var a = str.split(':');
	return a[1]; 
};
//writeCss: is a function who will write a css style tag but have a certain particularity the function can be used in 3 different way
//1) start the style tag "writeCss('start')"
//2) write the style you require "writeCss('.myClassOrDivOrTag', as much css style definition as you like )" the first parameter must always be the Class Div Tag
//3) close the the style "writeCss('end')"
// REMEMBER this function return a string that mean that you will need to do your own string concatenation before writing out the style tag
function writeCss(){
	var str = "";
	if(arguments[0]=='start'){
		str = '<style type="text/css">';
		return str;
	}
	if(arguments[0]=='end'){
		str = '</style>';
		return str;
	}
	str = arguments[0] + ' {';
	var W = false;
	var H = false;
	var C = true;
	for(var i=1;i<arguments.length;i++){
		if(arguments[i].indexOf('width')!=-1){
			W=getDim(arguments[i]);
		}
		if(arguments[i].indexOf('height')!=-1){
			H=getDim(arguments[i])
		}
		if(arguments[i].indexOf('clip')!=-1){
			C=false;
		}
		var arg;
		if(arguments[i].toLowerCase().indexOf('opacity')!=-1){
			if(!is.ns4&& !is.ie4){
				arg = arguments[i] + ';';
			}
		}else if(arguments[i].indexOf('background-color')>-1){
			if(is.ns4){
				arg = 'layer-' + arguments[i] + ';' + arguments[i] + ';';
			}else{
				arg = arguments[i] + ';';
			}
		}else{
			arg = arguments[i] + ';';
		}
		str += arg;
	}

	if(W && H && C){
		str += 'clip:rect(0 ' + W + ' ' + H + ' 0);';
	}
	str += '}';
	return str;
};

//writeStyle: this function work kind of the same way as the one above except that it will directly write the style tag into the page when called, the function can be called with as many css attribute as you wish and  the first parameter must always be the Class Div Tag
function writeStyle(){
	var str = "";
	str += '<style type="text/css">' + arguments[0] + ' {';
	for(var i=1;i<arguments.length;i++){
		var arg = (arguments[i].indexOf('background-color')>-1 && is.ns4 )? 'layer-' + arguments[i] + ';' + arguments[i] : arguments[i];
		str += arg + ';';
	}
	str += '}</style>';
	d.write(str);
};

/* XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX */
//QueryString: this function will return the value of a key in the querystring 
// example url : var myUrl = 'myLocation.html?key=value'
// QueryString('key') will return "value" as a string if the function can't find the key it will return false 
function QueryString(param){
	var loca = document.location.href;
	if(loca.indexOf('?' + param + '=')>-1 || loca.indexOf('&' + param + '=')>-1){
		var qString = loca.split('?');
		var keyVal = qString[1].split('&');
		for(var i=0;i<keyVal.length;i++){
			if(keyVal[i].indexOf(param + '=')==0){
				var val = keyVal[i].split('=');
				return val[1];
			}
		}
		return false;
	}else{
		return false;
	}
};
//get_location: is a function who will extract the location from an url (local) stripping out the key and value specified in as the param
function get_location(loca,param){
	var strLocation=(loca)?loca:document.location.href;
	if(strLocation.indexOf('?')>-1){
		var aLocation=strLocation.split('?');
			strLocation=aLocation[0]+'?';
		if(aLocation[1].indexOf("&")>-1){
			aaLoca=aLocation[1].split("&");
			for(var i=0;i<aaLoca.length;i++){
				if(aaLoca[i].indexOf(param)==-1){
					if(i>0){
						strLocation+='&';
					}strLocation+=aaLoca[i];
				}
			}
			strLocation+='&';
		}else{
//			alert(aLocation[1] + '\n' + param + '\n' + strLocation)
			
			if(aLocation[1].indexOf(param)==-1){
				strLocation+=aLocation[1]+'&';
			}
		}
	}else{
		strLocation+='?'
	}
	return strLocation;
};

/* XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX */
//setCookie: will simply set a cookie on the client machine the parameter of the function are cN = cookie name, cV = cookie value, nD = the number of day the cookie will remain on the client machine
function setCookie(cN,cV,nD){
    var exp = new Date();
    if (nD==null || nD==0) nD=1;
    exp.setTime(now.getTime() + 3600000*24*nD);
    d.cookie = cN + "=" + escape(cV) + ";expires="+exp.toGMTString();
};
//getCookie: get a cookie from the client machine and return its value it return false if it can't find the cookie
function getCookie(cN){
	var c = document.cookie;
	if (c.indexOf(cN) != -1){
		var startPos = c.indexOf(cN) + cN.length+1 ;
		var endPos = c.indexOf(";",startPos);
		if (endPos == -1) endPos = c.length;
		return unescape(c.substring(startPos,endPos));
	}else{
		return false; // the cookie couldn't be found! it was never set before, or it expired.
	}
};
/* XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX */
//setCookie: will simply set a cookie on the client machine the parameter of the function are cN = cookie name, cV = cookie value, nD = the number of day the cookie will remain on the client machine
//The above functions clash with sageMetrix tags. Following functions should be independent
function sCookie(cN,cV,nD){
    var exp = new Date();
    if (nD==null || nD==0) nD=1;
    exp.setTime(now.getTime() + 3600000*24*nD);
    d.cookie = cN + "=" + escape(cV) + ";expires="+exp.toGMTString();
};
//getCookie: get a cookie from the client machine and return its value it return false if it can't find the cookie
function gCookie(cN){
	var c = document.cookie;
	if (c.indexOf(cN) != -1){
		var startPos = c.indexOf(cN) + cN.length+1 ;
		var endPos = c.indexOf(";",startPos);
		if (endPos == -1) endPos = c.length;
		return unescape(c.substring(startPos,endPos));
	}else{
		return false; // the cookie couldn't be found! it was never set before, or it expired.
	}
};
/* XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX */
//tab_headline: will write the tab headline this is the headline with 45 degree angle the color of the channel
function tab_headline(label){
	var str = '<table cellpadding="0" cellspacing="0" border="0" width="100%">'
		+ '<tr height="15">'
		+ '<td bgcolor="' + mCol+ '" class="TxtBldFour"><nobr>&nbsp;' + label + '&nbsp;&nbsp;&nbsp;</nobr></td>'
		+ '<td bgcolor="' + mCol+ '">' + img('src="http://www.virgin.net/skins/pix/hdr_45degree.gif"', 'width="20"', 'height="15"') + '</td>'
		+ '<td width="100%">' + spacer('width="1"', 'height="1"') + '</td>'
		+ '</tr>'
		+ '<tr>'
		+ '<td bgcolor="' + mCol+ '" colspan="3">' + spacer('width="1"', 'height="1"') + '</td>'
		+ '</tr>'
		+ '</table>' + spacer('height="10"') + '<br>';
	d.write(str);
}
/* XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX */



