
//Variable which allows pages to control the blur and focus events on form fields
var createFocusAndBlurEvents = true;

//Check Browser has cookies enabled

try
{
	var cookieEnabled = (navigator.cookieEnabled) ? true : false;

	if (typeof(navigator.cookieEnabled) == "undefined" && !cookieEnabled)
	{ 
		document.cookie = "testcookie";
		cookieEnabled = (document.cookie.indexOf("testcookie") != -1) ? true : false;
	}

	if (!cookieEnabled && window.location.toString().indexOf("CookiesDisabled") == -1) 
	{
		window.location.replace("/Help/~h9120/CookiesDisabled/");
	}
}
catch(e){}

function RunLoadEvents()
{  
	for(var i = 0;i < onloadFunctions.length;i++) 
	{   
	    try
	    {
		    eval(onloadFunctions[i]);
		}
	    catch(e){}    
	}
}
		
function AttachLoadEvent(func)
{  
	onloadFunctions[onloadFunctions.length] = func;
}

var onloadFunctions = new Array();

function LoadImage(imageCtrl, imageSrc, altText, screenshotContainer, VideoInfoContainer)
{
	var image = document.getElementById(imageCtrl);
	var screenshotImageHolder = document.getElementById(screenshotContainer);
	var VideoPlayerContainer = document.getElementById(VideoInfoContainer);
	if(image && screenshotImageHolder && VideoPlayerContainer)
	{
        image.src = imageSrc;
		image.alt = altText;
		
		screenshotImageHolder.style.display = 'block';
		VideoPlayerContainer.style.display = 'none';
		//stops video.
		setplayerURL ("");
		screenshotImageHolder.removeClassName("progress");
	}
}

//function is used to attach the click event to a button
//which firefox does not recognise, this enabled the enter key 
//to fire events using the DefaultButton
function attachClickEvent(btn)
{
	if (btn && typeof(btn.click) == 'undefined') 
	{
		btn.click = function() 
		{  
			var result = true;
			if (btn.onclick) result = btn.onclick();
			if (typeof(result) == 'undefined' || result) 
			{
				eval(btn.href);
			}
		}
	}
}

// added to support links to external sites in /gadgets
function popitup(url) {
	newwindow=window.open(url,'name','height=500,width=750,resizable=yes,status=yes,menubar=yes,toolbar=yes,location=yes,scrollbars=yes,copyhistory=yes' );
	if (window.focus) 
	{
		newwindow.focus();
	}
	return false;
}

// ** added IE specific function to emulate the :focus pseudo-class which is supported in all other browsers.
// ** input pseudo-class:focus hack 
// ** fyi - implemented this technique http://www.htmldog.com/articles/suckerfish/focus/ 

function doFocus(type, tag, parentId) 
{
	if(createFocusAndBlurEvents)
	{
		var sfEls = (parentId==null)?document.getElementsByTagName(tag):document.getElementById(parentId).getElementsByTagName(tag);
		type(sfEls);
	}
}

sfFocus = function(sfEls) 
{
	if(createFocusAndBlurEvents)
	{
		for (var i=0; i<sfEls.length; i++) {
			sfEls[i].onfocus=function() {
				this.className+=" sffocus";
			}
			sfEls[i].onblur=function() {
				this.className=this.className.replace(new RegExp(" sffocus\\b"), "");
			}
		}
	}
}

function bookmarkPage(pageTitle,url)
{
    if (window.sidebar) // Firefox
	    window.sidebar.addPanel(pageTitle, url, "");
    else if(window.opera && window.print)
    { // Opera
	    var element = document.createElement('a');
	    element.setAttribute('href',url);
	    element.setAttribute('title',pageTitle);
	    element.setAttribute('rel','sidebar');
	    element.click();
    } 
    else if(document.all)// Internet Explorer
	    window.external.AddFavorite(url, pageTitle);
}

// attach event to specific HTML elements
AttachLoadEvent('doFocus(sfFocus, "INPUT")');
AttachLoadEvent('doFocus(sfFocus, "TEXTAREA")');
AttachLoadEvent('doFocus(sfFocus, "SELECT")');

//THIS MUST BE THE ONLY PLACE IN THE SITE WHICH ASSIGNS A FUNCTION TO THE ONLOAD EVENT
//OTHERWISE COREMETRICS WILL NOT LOAD CORRECTLY, IF YOU WANT TO ADD ONLOAD FUNCTION CALLS
//CALL THE AttachLoadEvent() FUNCTION PASSING IN THE FUNCTION REFERENCE
//I.E. AttachLoadEvent("attachClickEvent(document.getElementById('ControlId'));")
window.onload = RunLoadEvents;

//the below empty function is required for the ajax tab control for function. Please do not remove this function
function ActiveTabChanged(sender, e) {
}


// tracking and cookie

function setTrackingCookie() {
    setCookie( 'tracking', true, 1 );
};
function getTrackingCookie() {
    return getCookie( 'tracking' );
};
function deleteTrackingCookie() {
    setCookie( 'tracking', '', 0 );
};
function insertTrackingImg( src, id ) {
    var img = new Image();
    img.src = src;
    img.width = 1;
    img.height = 1;
    $( id ).insert ( img );
};

function setCookie( name, value, days ) {
    var date = new Date();
    date.setDate( date.getDate() + days );
    document.cookie = name + '=' + escape( value ) + ( ( days == null ) ? '' : ';expires=' + date.toGMTString() );
};

function getCookie( name ) {
    if ( document.cookie.length > 0 ) {
        var start = document.cookie.indexOf( name + '=' );
        if ( start != -1 ) {
            start = start + name.length + 1;
            var end = document.cookie.indexOf( ';', start );
            if ( end == -1 ) {
                end=document.cookie.length;
            };
            return unescape( document.cookie.substring( start, end ) );
        }
    }
    return '';
}; 


//Dynamically change the style of any class 
function changeCSSProperty(theClass,element,value) 
{
     var indexRule;
     if (document.all) 
     {
      indexRule = 'rules';
     }
     else if (document.getElementById)
     {
      indexRule = 'cssRules';
     }
    
     var added = false;
     for (var ssIndex = 0; ssIndex < document.styleSheets.length; ssIndex++)
     {      
         for (var cssIndex = 0; cssIndex < document.styleSheets[ssIndex][indexRule].length; cssIndex++) 
         {      
         
               if (document.styleSheets[ssIndex][indexRule][cssIndex].selectorText == theClass)
               {
                        if(document.styleSheets[ssIndex][indexRule][cssIndex].style[element])
                        {
                            document.styleSheets[ssIndex][indexRule][cssIndex].style[element] = value;
                            added=true;        
                            break;
                        }
               }
           
         }
         if(!added)
         {
              if(document.styleSheets[ssIndex].insertRule)
              {
                 document.styleSheets[ssIndex].insertRule(theClass+' { '+element+': '+value+'; }',document.styleSheets[ssIndex][indexRule].length);
              } 
              else if (document.styleSheets[ssIndex].addRule) 
              {    
                 document.styleSheets[ssIndex].addRule(theClass,element+': '+value+';');
              }
         }
         
     }
   
}