/* BBC Two - Common JavaScript */

/*----- declare vars -----*/
var PLAYER_PARAMS = 'location=0, statusbar=0, menubar=0, width=724, height=454, resizable=0';
var NEWS_PARAMS = 'toolbar=0,location=0,status=0,menubar=0,scrollbars=0,resizable=0,width=681,height=487';
var browserId = Math.ceil(100000*(Math.random()));
var shortBBCUID;

if(document.cookie && document.cookie.indexOf("BBC-UID")!=-1){
shortBBCUID = document.cookie.substring((document.cookie.indexOf("BBC-UID")+8),(document.cookie.indexOf("BBC-UID")+72));
}


/* Highlight form fields */
function pimpMyForm(parentID){
	// Create an array of elements containing the form textboxes
	var myTxtBoxes = document.getElementById(parentID).getElementsByTagName("input");
	var myTxtBoxesLength = myTxtBoxes.length;

	// Create an array of elements containing the form textareas
	var myTxtAreas = document.getElementById(parentID).getElementsByTagName("textarea");
	var myTxtAreasLength = myTxtAreas.length;
	
	for (i=0;i<myTxtBoxesLength;i++){
			if(myTxtBoxes[i].type == "text"){
				myTxtBoxes[i].onfocus = function() {
					this.className = "active";			
				};
				
				myTxtBoxes[i].onblur = function() {
					this.className = "textbox";			
				};
			}
	}
	
	for (i=0;i<myTxtAreasLength;i++){
			myTxtAreas[i].onfocus = function() {
				this.className = "active";			
			};
			
			myTxtAreas[i].onblur = function() {
				this.className = "textbox";			
			};
	}
	

}

/* Opens Player Windows */
function openPlayerWindow(url) {
    var params = "toolbar=no,scrollbars=no,location=no,status=no,menubar=no,resizable=no,width=200,height=200";
    var popup = window.open(url, "bbctwo", "toolbar=no,scrollbars=no,location=no,status=no,menubar=no,resizable=no");
}

function popupWindow(src, features){
	var popupUrl = src.getAttribute('href');
	var popupTarget = src.getAttribute('target');

	/*
	if(popupUrl.indexOf('mediaselector/check/broadband/mediaplayer') != -1){
		stopFlashVideo();
	}
	*/
	
	var popup = window.open(popupUrl, popupTarget, features);
	popup.focus();
	return popup;
	
	//return false;

}

function newWindow(obj){
	var popupUrl = obj.getAttribute('href');
	var popupTarget = obj.getAttribute('target');
	var features = "";
	
	var popup = window.open(popupUrl, popupTarget, features);
	popup.focus();
	return popup;

}


/* Flash Player Tracking */
function windowIsClosingNow(){
   	var movieName = "embeddedVideo";

	if (navigator.appName.indexOf("Microsoft") != -1) {
        var movieObj = window[movieName];
    } else {
		var movieObj = document[movieName];
    }
	
	//alert(movieObj.width);
	//movieObj.helloWorld();
	movieObj.windowClose();
	//alert('I AM SPARTICUS!');
}