/*  ##########################################################################
'	##########################################################################

' 	scripts.js

'	Author(s)
' 	David Dekker, DD, david.dekker@akqa.com
'	Nigel Warson-Hill, NWH
'   Mario Theodorou, MT

' 	Copyright 2006 AKQA.  All rights reserved.

'	Version 1.01
'	Created: 02/10/2006
'	Last modified: 27/04/2007

'	Versions:
' 	1.00 - Initial version - DD
'	1.01 - Removed unused function "activateProgrammeChange" as no longer needed - NWH
'   1.02 - Updates for Sky Sports Comparison

	##########################################################################
	##########################################################################
*/

function hideDiv(pass) {
	var divs = document.getElementsByTagName("div");
	for(i=0;i<divs.length;i++){
		if(divs[i].id.match(pass)){//if they are 'see' divs
			if (document.getElementById) // DOM3 = IE5, NS6
				divs[i].style.display = "none";// show/hide
			else
				if (document.layers) // Netscape 4
					document.layers[divs[i]].display = "none";
				else // IE 4
					document.all.hideshow.divs[i].visibility = "hidden";
		}
	}
}

function showDiv(pass) {
	var divs = document.getElementsByTagName("div");
	for(i=0;i<divs.length;i++){
		if(divs[i].id.match(pass)){
			if (document.getElementById)
				divs[i].style.display = "block";
			else
				if (document.layers) // Netscape 4
					document.layers[divs[i]].display = "block";
				else // IE 4
					document.all.hideshow.divs[i].visibility = "visible";
		}
	}
}

function toggleDiv(pass) {
	showDiv(pass+'Off');
	hideDiv(pass);
}


// detectPlugins - returns all of the currently running plugins
function detectPlugins() {
	navigator.plugins.refresh(false);
	var outstr = "";
	for (var pi=0; pi!= navigator.plugins.length; pi++) {
		var plugin=navigator.plugins[pi];
		outstr += plugin.name + "\n";
	}
	if (navigator.plugins.length) {
		alert(outstr);
	}
	return false;
}


// buildplayer - builds the movie player
// usage: <script language="JavaScript">buildplayer('w','hb',368,277,'http://ms.groovygecko.net/groovyg/clients/akqa/sky/hot_hb.wmv')</script>
//Note: Auto Started added so that the movie only plays once when the user first comes to the site - the play button is now active.
function buildplayer(movieId,w,h,src,autostart) {
	var outstr = "";
	outstr += ('<object id="GGWindowsMediaPlayer" name="GGWindowsMediaPlayer" width="'+w+'" height="'+h+'" classid="CLSID:22D6F312-B0F6-11D0-94AB-0080C74C7E95" standby="Loading Microsoft Windows Media Player components..." type="application/x-oleobject" codebase="http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=6,4,7,1112">');
	outstr += ('<param name="FileName" value="'+src+'" />');
	outstr += ('<param name="ShowControls" value="1" />');
	outstr += ('<param name="AutoStart" value="'+autostart+'" />');
	outstr += ('<param name="InvokeURLs" value="false" />');
	outstr += ('<param name="defaultframe" value="frmGO" />');
	outstr += ('<param name="volume" value="-20" />');
	outstr += ('<param name="ShowPositionControls" value="0" />');
	outstr += ('<param name="SendPlayStateChangeEvents" value="1"/>');
	outstr += ('<param name="ShowStatusBar" value="0" />');
	outstr += ('<embed type="application/x-mplayer2" pluginspage="http://www.microsoft.com/Windows/Downloads/Contents/Products/MediaPlayer/" src="'+src+'" id="GGWindowsMediaPlayer" name="GGWindowsMediaPlayer" ShowControls="1" ShowDisplay="0" AutoStart="'+autostart+'" ShowStatusBar="0" ShowPositionControls="0" width="'+w+'"height="'+h+'" volume="-20" defaultframe="frmGO" SendPlayStateChangeEvents="1"></embed>');
	outstr += ('<noembed>This browser appears to be unable to display clips.</noembed>');
	outstr += ('</object>');
	var player;
	var plugin;
	var playerVersion;
	var hasActiveX = false;
	try {
		if (window.ActiveXObject) {
			hasActiveX = true;
			player = new ActiveXObject("WMPlayer.OCX.7");
		} else if (window.GeckoActiveXObject) {
			hasActiveX = true;
			player = new GeckoActiveXObject("WMPlayer.OCX.7");
		}
		if (player) {
			if (parseFloat(player.versionInfo) >= 9) {
				playerVersion = parseFloat(player.versionInfo);
			}
		}
	} catch (oError) {}
	try {
		if (navigator.mimeTypes) {
			plugin = navigator.mimeTypes['application/x-mplayer2'].enabledPlugin;
		}
	} catch (oError) {}
	/*
	var message = "Your browser "+ (hasActiveX ? "does" : " does not") +" support ActiveX. \n";
	message += "The WMP ActiveX control is"+ ( player ? "" : " not") +" installed. \n";
	message += "The WMP Plugin "+ (plugin ? "is" : "is not") +" installed. \n";
	*/
	if (document.getElementById && ((player && playerVersion) || plugin)) {
		document.getElementById(movieId).innerHTML = outstr;
	} else {
		var outstrelse = "";
		outstrelse += '<p style="padding-top:180px">The Sky High Definition site requires a minimum of Windows Media Player 9 or later to view the streaming Windows media clips. If you do not have the required software, download <a href="http://www.windowsmedia.com/download/" style="color:#88edff;"><strong>Windows Media Player</strong></a> from Microsoft.</p>';
		document.getElementById(movieId).style.background = "url(library/images/bg_windows_media.jpg)";
		document.getElementById(movieId).innerHTML = outstrelse;
	}
	
	return false;
}

// updatebackground - updates the background on the home page movie images.
function updatebackground(divId) {
	if (document.getElementById) {
		document.getElementById("movie1").childNodes[0].style.background = "url(library/images/home_movie1.jpg)";
		document.getElementById("movie2").childNodes[0].style.background = "url(library/images/home_movie2.jpg)";
		document.getElementById("movie3").childNodes[0].style.background = "url(library/images/home_movie3.jpg)";
		document.getElementById(divId).childNodes[0].style.background = "url(library/images/home_"+divId+"_over.jpg)";
	}
	return false;
}

// showFloater - FAQ functions
var theElementStyleOld = null;
var objectOld = null;
function showFloater(objectID,object) {
	if (theElementStyleOld && objectOld) {
		//theElementStyleOld.style.display = "none";
		//objectOld.style.fontWeight = "normal";
		//objectOld.style.textDecoration = "underline";
	}
	if (document.getElementById) {
		var theElementStyle = document.getElementById(objectID);
		if (theElementStyle.style.display == "block") {
			theElementStyle.style.display = "none";
			object.style.fontWeight = "normal";
			object.style.textDecoration = "underline";
		} else {
			theElementStyle.style.display = "block";
			object.style.fontWeight = "bold";
			object.style.textDecoration = "none";
			theElementStyleOld = theElementStyle;
			objectOld = object;
		}
	}
}


//functions taken from validate.js

function validate_radio(field, alerttxt) {
    myOption = -1;
    for (i = field.length - 1; i > -1; i--) {
        if (field[i].checked) {
            myOption = i;
            i = -1;
        }
    }
    if (myOption == -1) {
        return alerttxt;
    } else {
        return "";
    }
}
function validate_required(field, alerttxt, labelName) {
    with (field) {
        if (value == null || value == "" || value == labelName) {
            //focus();
            return alerttxt;
        } else {
            return "";
        }
    }
}
function validate_email(field, alerttxt) {
    with (field) {
        apos = value.indexOf("@");
        dotpos = value.lastIndexOf(".");
        if (apos < 1 || dotpos - apos < 2) {
            //focus();
            return alerttxt;
        } else {
            return "";
        }
    }
}

function validate_checkbox_group(checkBoxArray, alerttxt, thisform){
    var checkCount = 0;
    for(i=0;i < checkBoxArray.length; i++){
        var j = checkBoxArray[i];
        if(document.getElementById(j).checked){
           // alert(j +'is checked');
           checkCount++; 
        }
    }
    if (checkCount == 0){
        return alerttxt;
    } else {
        return "";
    }
}

function validate_contact_form(thisform) {
var aRequiredCheckboxesProducts = new Array('optinHDSportsInformation','optinSportsOnMobileOrPC','optinSportsNews','optinOtherSkyProducts');
var aRequiredCheckboxesData = new Array('optinTerms');

    with (thisform) {
        ReturnUrl.value = 'heroescomeandgo/thankyou.htm';
        var check = "";
        check += validate_required(Firstname, "First name is a required field\n", "First name");
        check += validate_required(Lastname, "Last name is a required field\n", "Last name");
        check += validate_required(Address1, "The first line of address is a required field\n", "First line of address");
        check += validate_required(Postcode, "Postcode is a required field\n", "Postcode");
        check += validate_required(Email, "Email is a required field\n", "Email address");
        check += validate_email(Email, "Please supply a valid email address\n");
        check += validate_checkbox_group(aRequiredCheckboxesProducts, "You must select at least one newsletter option\n", thisform);
        check += validate_checkbox_group(aRequiredCheckboxesData, "You must agree to the terms and conditions\n");
        
        if (check != "") {
            alert(check);
            return false;
        }
        var loc = "";
        var rtn = "";
        loc = String(document.location.href).substring(7);
        loc = loc.substring(0, loc.indexOf("/"));
        //alert(String(ReturnUrl.value));
        //alert(loc);
        if (loc != "sky.com") {
            rtn = "http://" + loc + "/" + String(ReturnUrl.value);
           //alert('loc = ' + loc +'\n rtn = ' + rtn);
            ReturnUrl.value = rtn;
        }
        

    }
}