
/* BBCi Weather global javascript functions */


/* 
self submitting dropdown function 
: example - <select name="link" onChange="getURL(this.options[this.selectedIndex].value); return false;">...</select>
*/
function getURL(value) { 
	if (value != "") { self.location=value; } 
}

/* 
pop-up window function 
: example - <a href="popups/photo_popup_01.html" onClick="popWin('popups/photo_popup_01.html', 'photo_popup', '450', '500'); return false;" target="photo_popup">...</a>
*/
function popWin(the_page,the_target,the_width,the_height) {
	window.open(the_page,the_target,"status=yes,menubar=no,scrollbars=yes,resizable=no,width=" + the_width + ",height=" + the_height);
} 

/* 
check for a valid email address 
: example - <form action="whatever" method="post" onsubmit="checkEmail(this); return false">...</form>
*/


function sendIt(form){
ctrl = form.email;
if ((ctrl.value.indexOf('@') == -1) || (ctrl.value.indexOf('.') == -1))
{	alert ('The email address is invalid, please check you have entered it correctly.');
ctrl.select();
return (false); }
form.submit();
return true;
}



function isEmailAddr(email)
{
  var result = false
  var theStr = new String(email)
  var index = theStr.indexOf("@");
  if (index > 0)
  {
    var pindex = theStr.indexOf(".",index);
    if ((pindex > index+1) && (theStr.length > pindex+1))
	result = true;
  }
  return result;
}

function checkEmail(theForm)
{

  if (theForm.email.value == "")
  {
    alert("Please enter a value for the \"email\" field.");
    theForm.email.focus();
    return (false);
  }

  if (!isEmailAddr(theForm.email.value))
  {
    alert("Please enter a complete email address in the form: yourname@yourdomain.ext");
    theForm.email.focus();
    return (false);
  }
   
  if (theForm.email.value.length < 3)
  {
    alert("Please enter at least 3 characters in the \"email\" field.");
    theForm.email.focus();
    return (false);
  }
  return (true);
}

/* 
basic use is for the slim (light weight) version of the weather site 
: references pulling in this function can be found in /weather/slim/
*/
function getForecast(object) {
    window.location.href = "/weather/fiveday/5dayforecast.shtml?" + object.countrySelect.options[object.countrySelect.selectedIndex].value;
}






/* 
BBC News av Console launch pop-up 
: main weather site banner example - <a href="javascript: void request_launch('ukfs');">...</a>
*/
function launch_main_player(site)
{


	
	if (site == null) //no site name passed in - have to leave this check in
	{
		clickmain=window.open("/mediaselector/check/weather/broadband?redirect=console.shtml&nbram=1&bbram=1&nbwm=1&bbwm=1","console","toolbar=0,location=0,status=0,menubar=0,scrollbars=1,resizable=0,top=100,left=100,width=681,height=497");
	}
	else
	{
		if (site == 'ukfs')
		{
			clickmain=window.open("/mediaselector/check/weather/broadband?redirect=console.shtml&nbram=1&bbram=1&nbwm=1&bbwm=1","console","toolbar=0,location=0,status=0,menubar=0,scrollbars=1,resizable=0,top=100,left=100,width=681,height=497");

		}
		else if (site == 'ifs')
		{
			clickmain=window.open("/mediaselector/check/weather/broadband?redirect=console.shtml&nbram=1&bbram=1&nbwm=1&bbwm=1","console","toolbar=0,location=0,status=0,menubar=0,scrollbars=1,resizable=0,top=100,left=100,width=681,height=497");
		}
	}
}

function getPlatform()
{
	var myUserAgent;
	myUserAgent = navigator.userAgent.toLowerCase();

	if ((myUserAgent.indexOf("win") != -1) ||  (myUserAgent.indexOf("16bit") != -1))
	{
		return "win";
	}
	
	if (myUserAgent.indexOf("mac") != -1)
	{
		return "mac";
	}  
	
	if (myUserAgent.indexOf("x11") != -1)
	{
		return "unx";
	}  
	
	return "other";
}

function getBrowserType()
{
	var myUserAgent;

	var myMajor;
	myUserAgent= navigator.userAgent.toLowerCase();
	myMajor= parseInt(navigator.appVersion);
	if( (myUserAgent.indexOf('mozilla')!= -1) &&(myUserAgent.indexOf('spoofer')== -1) &&(myUserAgent.indexOf('compatible') == -1) &&(myUserAgent.indexOf('opera') == -1) &&(myUserAgent.indexOf('webtv')  == -1) )
	{  
		if (myMajor > 3)
		{
			return "nav4";
		}
	
		return "nav";
	}
	
	if (myUserAgent.indexOf("msie")!= -1)
	{  
	
		if (myMajor > 3)
		{
			return "ie4";
  		} 
	
		return "ie";
	}
// dom compliant browsers are allowed
	if(document.body.firstChild) return "domCompliant";
	return "other";
}

function request_launch(site)
{
	if (getPlatform() != "other" &&(getBrowserType() == "ie4" || getBrowserType() == "nav4" || getBrowserType() == "domCompliant"))
	{
		launch_main_player(site);
	} 
	else 
	{
		self.location.href="/1/shared/bsp/hi/services/help/html/av_console_browsers.stm";
	}
	
	return;
}


function openWindow(){
	var mywin = null;var unLoad;
	var surl = "http://news.bbc.co.uk/hi/english/static/business/data_desktop/mardata/ftse.stm";
	if (!mywin){mywin = window.open(surl,'BBCNewsOnline','toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=0,width=370,height=292');
		mywin.location = surl;
		if (mywin.opener == null) mywin.opener = window; 
		mywin.opener.name = "opener";
	}else{
		if (mywin.closed){	
			mywin = null;openWindow();
		}
		if (mywin.focus) mywin.focus();
		mywin.location.href = surl;
	}
}



function popup(url) {
	day = new Date();
	id = day.getTime();
	eval("page" + id + " = window.open(url, '" + id + "', 'toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=0,width=370,height=220');");
} 


function popUp(pageurl,width,height,scroll){
	day = new Date();
	id = day.getTime();
	if (window.screen) {  
		lpos = (screen.width/2)-(width/2);  
		hpos = (screen.height/2)-(height/2);
	}else	{
		lpos = 1;
		hpos = 1;		
	}		 		
	eval("bbcnews"+id+" = window.open('"+pageurl+"','"+id+"','toolbar=0,scrollbars="+scroll+",location=0,status=0,menubar=0,resizable=0,width="+width+",height="+height+",left="+lpos+",top="+hpos+"')");
}


