
function NewImage(arg)
{
	if (document.images)
	{
		rslt = new Image();
		rslt.src = arg;
		return rslt;
	}
	return true;
}

function SwapImage()
{
	if (document.images)
	{
		for (var i = 0; i < SwapImage.arguments.length; i += 2)
		{
			document[SwapImage.arguments[i]].src = SwapImage.arguments[i+1];
		}
	}
}

//
// Cookie Managament
//
function GetCookie(cookieName)
{
	if (document.cookie != "")
	{
		cookieArray = document.cookie.split("; ");
		for(i = 0; i < cookieArray.length; i++)
		{
			if (cookieArray[i].split("=")[0] == cookieName)
				return cookieArray[i].split("=")[1];
		}
	}
	return "";
}

//
// Leave off the third argument completely to set browser cookie
//
function SetCookie(name, value, hours)
{
  var expire = "";
  if(hours != null)
  {
    expire = new Date((new Date()).getTime() + hours * 3600000);
    expire = "; expires=" + expire.toGMTString();
  }
  document.cookie = name + "=" + escape(value) + expire + "; path = /";
}

function SetInnerHtmlValue(objId, txt)
{
	if(document.getElementById)
	{
		var obj = document.getElementById(objId);
		if (obj)
		{
			obj.innerHTML = txt;
			return true;
		}
		else return false;
	}
	else if(document.all)
	{
		obj = document.all[objId]
		if (obj)
		{
			obj.innerHTML = txt;
			return true;
		}
		else return false;
	}
	else if(document.layers)
	{
		obj = document.layers[objId];
		if (obj != null)
		{
			with(obj.document)
			{
				open();
				write(txt);
				close();
				return true;
			}
		}
		else return false;
	}
	else return false;
}

function FlashManager(strFile, intWidth, intHeight, strBackgroundColour)
{
	var strRtn = "";
	strRtn +='<object\n';
	strRtn +='id="RhythmTVvideo"\n';
	strRtn +='classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"\n';
	strRtn +='codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0"\n';
	strRtn +='width="'+intWidth+'"\n';
	strRtn +='height="'+intHeight+'"\n';
	strRtn +='align="middle">\n';
	strRtn +='<param name="allowScriptAccess" value="sameDomain" />\n';
	strRtn +='<param name="movie" value="'+strFile+'" />\n';
	strRtn +='<param name="quality" value="high" />\n';
	strRtn +='<param name="bgcolor" value="'+strBackgroundColour+'" />\n';
	strRtn +='<embed\n';
	strRtn +='src="'+strFile+'"\n';
	strRtn +='quality="high"\n';
	strRtn +='bgcolor="'+strBackgroundColour+'"\n';
	strRtn +='width="'+intWidth+'"\n';
	strRtn +='height="'+intHeight+'"\n';
	strRtn +='name="RhythmTVvideo"\n';
	strRtn +='align="middle"\n';
	strRtn +='allowScriptAccess="sameDomain"\n';
	strRtn +='type="application/x-shockwave-flash"\n';
	strRtn +='pluginspage="http://www.macromedia.com/go/getflashplayer"\n';
	strRtn +='/>\n';
	strRtn +='</object>\n';
	document.write(strRtn);
}

function checkNumberChecked(max){
	var form = document.forms[0];

	var elements = form.getElementsByTagName('input');
	var count = 0;
	var tcount = 0;

	for (var i=0; i < elements.length; i++){
		if (elements[i].checked && elements[i].className == 'bespokePackage'){
			count++;
			tcount++;
		}
		else if(elements[i].checked && elements[i].className == 'packages'){
			tcount++;
		}
	}

	if(tcount ==0 ) { //nothing's been checked, so go back
		return false;
	}
	if (count == max){
		form.submit();
		return true;
	}
	else if (count > max || count < max){
		alert('please select 2 channels to subscribe to the bespoke package');
		return false;
	}

}

function changeDialCode(index){
	//alert(index);

	var form = document.forms[0];

	var cc = form.country_code[index].value;
	var span = document.getElementById('dial_code');

	span.innerHTML = '+'+cc+' - ';
	eraseCookie('country_code');
	createCookie('country_code', cc, 0);
}

//COOKIE FUNCTIONS
//http://www.quirksmode.org/js/cookies.html
function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}