mywin = null;
var unLoad;
var surl;
function openwindow(url, width, height, scrollableBoolean) {
									 if (height==375) scrollableBoolean=1; // FORCE SCROLLBAR FOR E-SURVEY 
	surl = url;
	(scrollableBoolean==0) ? scrollable="no": scrollable="yes";
	if (url != "") {
		if (!mywin) {
			mywin = window.open(url,"mywin", "status=no, scrollbars=" + scrollable + ", resizable=yes, width=" + width + ", height=" + height + ",screenX=10,screenY=10,top=10,left=10");
			unLoad = (function () {mywin = null;});
			mywin.onunload = unLoad;
		}
		else {
			if (mywin.closed) {
				mywin = null;
				openwindow(surl, width, height, scrollableBoolean);
			}
			mywin.focus();
			mywin.location.href = url;
		}
	} 					
}
function popmailwin(x, y) {
  window.open(x,y,'status=no,scrollbars=no,resizable=yes,width=370,height=450');
}

function launchAVConsoleStory(storyid, pathtoconsole,pathtostory)
{
	if(bbcV2Tst())
	{
	
		consoleurl = "http://www.bbc.co.uk/mediaselector/check"+pathtoconsole+"?redirect=fs.shtml&nbram=1&nbwm=1&ws_storyid=" + storyid +"&ws_pathtostory="+pathtostory;

		if( 
		(pathtoconsole.indexOf('urdu') == -1) 
		&& (pathtoconsole.indexOf('portuguese') == -1)
		&& (pathtoconsole.indexOf('arabic') == -1)
		&& (pathtoconsole.indexOf('persian') == -1)
		&& (pathtoconsole.indexOf('spanish') == -1)
		) {
		
		} else {
			var resetStr = resetMediaSelectorPref(pathtoconsole);
			consoleurl = consoleurl+'&bbram=1&bbwm=1' + resetStr;
		}
		clickmain=window.open(consoleurl,"console","toolbar=0,location=0,status=0,menubar=0,scrollbars=1,resizable=0,width=681,height=387");

		clickmain.focus();

	}
	else
	{
		self.location.href="http://news.bbc.co.uk/2/hi/help/3681938.stm";
	}
}

function launchAVConsoleV3(pathtosection,pathtoconsole)
{
	if(bbcV2Tst())
	{	
	
		var url = "http://www.bbc.co.uk/mediaselector/check"+pathtoconsole+"?redirect=fs.shtml&nbram=1&nbwm=1";	

		if(
		(pathtosection.indexOf('urdu') == -1)
		&&(pathtosection.indexOf('portuguese') == -1)
		&& (pathtosection.indexOf('arabic') == -1)
		&& (pathtosection.indexOf('persian') == -1)
		&& (pathtosection.indexOf('spanish') == -1)
		) {
		
		} else {
		    var resetStr = resetMediaSelectorPref(pathtosection);
			url = url+'&bbram=1&bbwm=1' + resetStr;
		}

		if (pathtosection)
		{
			url = url + "&ws_pathtostory=" + pathtosection;
		}
		clickmain=window.open(url,"console","toolbar=0,location=0,status=0,menubar=0,scrollbars=1,resizable=0,width=681,height=387");


clickmain.focus();

	}
	else
	{
		self.location.href="http://news.bbc.co.uk/2/hi/help/3681938.stm";
	}
}


function bbcV2Tst(){

	var type = getBrowserType();
	
	return (type  != "other" &&(type == "ie5" || type == "nav6" || type == "domCompliant"));
}

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 > 4 )
			{
				return "nav6";
			} 
		else if ((myMajor == 4 ) || (myMajor == 5 ))
			{
				return "nav4";
			}
	}
	
	if (myUserAgent.indexOf("msie") == 4)
		{
			return "ie4";
			
	}
	else if (myUserAgent.indexOf("msie") == 5)
		{
			return "ie5";
		}	
// dom compliant browsers are allowed
	if(document.body.firstChild) 
	return "domCompliant";
	return "other";
}


function getBrowserVersion() //this is for the ticker to identify between mac IE4 and IE5
{
	var s = navigator.appVersion;
	s = s.substr(s.indexOf("("),s.length);
	while (isNaN(parseInt(s)))
	{
		s = s.substr(1,s.length);
	}
	return parseInt(s);
}

// for specials resizing
function resizePopup(width,height)
{
var agent = navigator.userAgent.toLowerCase();
var major  = parseInt(navigator.appVersion);
var isIE     = ((agent.indexOf("msie")!= -1) &&
                (agent.indexOf("opera")== -1));
var ie7    = (isIE && (major == 4) && (agent.indexOf("msie 7.0")    != -1));

var theWidth = width+8;
var theHeight = height;

if(document.all) { 
theHeight = document.all.pointa.offsetHeight+40; 
if(ie7) { theHeight += 50;}
}
else { theHeight = document.height+55; }
window.resizeTo(theWidth,theHeight);

} //  end of function

    function makeCrumb(n,v,d) {
        var expires = '';
    	if (d) {
    		var date = new Date();
    		date.setTime(date.getTime()+(d*24*60*60*1000));
    		expires = "expires=" + date.toGMTString() + ";";
    	}

    	document.cookie = n + "=" + v + ";" + 
    	                  expires + " path=/; domain=.bbc.co.uk;";
    }

    function readCrumb(n) {
    	var nm = n + "=";
    	var cc = document.cookie.split(';');
    	for(var i=0;i<cc.length;i++) {
    		var c = cc[i];
    		while (c.charAt(0)==' ') c = c.substring(1,c.length);
    		if (c.indexOf(nm) == 0) return c.substring(nm.length,c.length);
    	}
    	return null;
    }

    function eraseCrumb(n) {
    	makeCrumb(n,"",-1);
    }

    function resetMediaSelectorPref(pathtoconsole) {
        var pref = readCrumb('BBCMediaSelector');
        var touch = readCrumb('mstouch');
        pref = unescape(pref);
        // Checks for "broadband" option in Media Selector cookie v2.
        var bb = /^.{7}bb/;

            if ( (pref && !touch) && (pref.search(bb) != 1 && touch != 1) ) {
                eraseCrumb('BBCMediaSelector');
                makeCrumb('mstouch',1,90); //expires the cookie in 90 days
                
                return '&prefs=1' + passMSLang(pathtoconsole);;
            }
         return passMSLang(pathtoconsole);
    }
    
    
    function passMSLang(url) {
                    if (url.indexOf('portuguese') != -1) {
                        return "&lang=pt-br";
                    } else if (url.indexOf('urdu') != -1) {
                        return "&lang=ur";
                    } else if (url.indexOf('persian') != -1) {
                        return "&lang=fa";
                    } else if (url.indexOf('spanish') != -1) {
                        return "&lang=es";
                    } else if (url.indexOf('russian') != -1) {
                        return "&lang=ru";
                    } else if (url.indexOf('arabic') != -1) {
                        return "&lang=ar";
                    }   
    }