 function openWindow(where,name) { 
 newWindow=window.open(where,name,"width=470,height=400,toolbar=no,scrollbars=no, location=no,menubar=no,noresizeable=no,status=no"); } 

function setlogoCookie(logono) {
        var d = "logoimg=" + logono + "; " + "expires=Thu, 31 Dec 2099 23:59:59 GMT;path=/;"
        document.cookie = d;
		// fireToPage(logono)
    }
	function setPageCookie(logono) {
        var d = "page=" + logono + "; " + "expires=Thu, 31 Dec 2099 23:59:59 GMT;path=/;"
        document.cookie = d;
		// fireToPage(logono)
    }

    function submitThis(){ 
         // window.location='/SetRegion/tabid/55/Default.aspx';	
	 window.location.reload(); 

    } 
	 function setWeatherCookie(logono) {
        var d = "weather=" + logono + "; " + "expires=Thu, 31 Dec 2099 23:59:59 GMT;path=/;"
        document.cookie = d;
		updateRegion(logono);
		}

function submitWeather(){
//window.location = "http://www.3news.co.nz/News/WeatherNews/WeatherMap/tabid/197/Default.aspx";
}
		function getcookie(logoimg) {
 var cookiestring=""+document.cookie;
 var index1=cookiestring.indexOf(logoimg);
 if (index1==-1 || logoimg=="") return ""; 
 var index2=cookiestring.indexOf(';',index1);
 if (index2==-1) index2=cookiestring.length; 
 return unescape(cookiestring.substring(index1+logoimg.length+1,index2));


}
/* 		  Page ID |  onairCat ID  | Base Portal | Weather 
Auckland:		61			2			0			2
Christchurch:	78			7			2			4
Dunedin:		103			142			4			7
Central Otago:	124			141			3			38
Gisborne:		150			143			23			8
Hawkes Bay:		159			144			5			20
Horowhenua:		165			146			6			17
Kapiti:			171			151			7			17
Manawatu: 		113			152			8			26
Marlborough:	177			153			1			3
Nelson:			183			154			9			21
Northland:		189			155			10			43
Queenstown:		196			156			11			28
Rotorua:		202			157			12			30
Southland:		208			158			13			14
Taranaki:		214			159			14			22
Taupo:			220			160			15			32
Tauranga:		226			161			16			33
Waikato:		93			162			17			13
Wairarapa:		232			163			19			18
Wanganui:		238			164			20			39
Wellington: 	83			165			21			40
*/
function fireToPage(region){
	//alert(region)
	var base="/?tabid="
	if (region==99){setPageCookie(36);setWeatherCookie(2);window.location=base+"36";}//auckland
	if (region==0){setPageCookie(61);setWeatherCookie(2);window.location=base+"61";}//auckland
	if (region==1){setPageCookie(177);setWeatherCookie(3);window.location=base+"177";}//Marlborough
	if (region==2){setPageCookie(78);setWeatherCookie(4);window.location=base+"78";}//christchurch
	if (region==3){setPageCookie(124);setWeatherCookie(0);window.location=base+"124";}//central otago
	if (region==4){setPageCookie(103);setWeatherCookie(7);window.location=base+"103";}//dunedin
	if (region==5){setPageCookie(159);setWeatherCookie(20);window.location=base+"159";}//Hawkes Bay
	if (region==6){setPageCookie(165);setWeatherCookie(17);window.location=base+"165";}//Horowhenua
	if (region==7){setPageCookie(171);setWeatherCookie(17);window.location=base+"171";}//Kapiti
	if (region==8){setPageCookie(113);setWeatherCookie(26);window.location=base+"113";}//Manawatu
	if (region==9){setPageCookie(183);setWeatherCookie(21);window.location=base+"183";}//Nelson
	if (region==10){setPageCookie(189);setWeatherCookie(43);window.location=base+"189";}//Northland
	if (region==11){setPageCookie(196);setWeatherCookie(28);window.location=base+"196";}//Queenstown
	if (region==12){setPageCookie(202);setWeatherCookie(30);window.location=base+"202";}//Rotorua
	if (region==13){setPageCookie(208);setWeatherCookie(14);window.location=base+"208";}//Southland
	if (region==14){setPageCookie(214);setWeatherCookie(22);window.location=base+"214";}//Taranaki
	if (region==15){setPageCookie(220);setWeatherCookie(32);window.location=base+"220";}//Taupo
	if (region==16){setPageCookie(226);setWeatherCookie(33);window.location=base+"226";}//Tauranga
	if (region==17){setPageCookie(93);setWeatherCookie(13);window.location=base+"93";}//Waikato
	if (region==19){setPageCookie(232);setWeatherCookie(18);window.location=base+"232";}//Wairarapa
	if (region==20){setPageCookie(238);setWeatherCookie(39);window.location=base+"238";}//Wanganui
	if (region==21){setPageCookie(83);setWeatherCookie(40);window.location=base+"83";}//Wellington
	if (region==23){setPageCookie(150);setWeatherCookie(8);window.location=base+"150";}//gisborne

	}
	
function showRegion(myRegion){
	
		 if(myRegion=="") {dispRegion = "not set";}
	else if(myRegion=="99"){dispRegion = "generic";}
	else if(myRegion=="0"){dispRegion = "Auckland";}
	else if(myRegion=="1"){dispRegion = "Marlborough";}
	else if(myRegion=="2"){dispRegion = "Christchurch";}
	else if(myRegion=="3"){dispRegion = "Central Otago";}
	else if(myRegion=="4"){dispRegion = "Dunedin";}
	else if(myRegion=="5"){dispRegion = "Hawkes Bay";}
	else if(myRegion=="6"){dispRegion = "Horowhenua";}
	else if(myRegion=="7"){dispRegion = "Kapiti";}
	else if(myRegion=="8"){dispRegion = "Manawatu";}
	else if(myRegion=="9"){dispRegion = "Nelson";}
	else if(myRegion=="10"){dispRegion = "Northland";}
	else if(myRegion=="11"){dispRegion = "Queenstown";}
	else if(myRegion=="12"){dispRegion = "Rotorua";}
	else if(myRegion=="13"){dispRegion = "Southland";}
	else if(myRegion=="14"){dispRegion = "Taranaki";}
	else if(myRegion=="15"){dispRegion = "Taupo";}
	else if(myRegion=="16"){dispRegion = "Tauranga";}
	else if(myRegion=="17"){dispRegion = "Waikato";}
	//else if(myRegion=="18"){dispRegion = "Masterton";}
	else if(myRegion=="19"){dispRegion = "Wairarapa";}
	else if(myRegion=="20"){dispRegion = "Wanganui";}
	else if(myRegion=="21"){dispRegion = "Wellington";}
		else if(myRegion=="23"){dispRegion = "Gisborne";}
  else{dispRegion = "not set";}
return dispRegion;

	}
	

function updateRegion(id) {
if(window.myweathersm) window.document["myweathersm"].SetVariable("where", id);
if(document.myweathersm) document.myweathersm.SetVariable("where", id);


}


	 function findCatRegion(catRegion){
		 
	      if (catRegion =="99"){catRetrieve = "2";}//generic
		   if (catRegion ==""){catRetrieve = "2";}//generic
	else if (catRegion =="0"){catRetrieve = "2";}//auckland
	else if (catRegion =="1"){catRetrieve = "153";}//marl
	else if (catRegion =="2"){catRetrieve = "7";}//chch
	else if (catRegion =="3"){catRetrieve = "141";}//central otago
	else if (catRegion =="4"){catRetrieve = "142";}//dunedin
	else if (catRegion =="5"){catRetrieve = "144";}//hawkes bay
	else if (catRegion =="6"){catRetrieve = "146";}//horowhenua
	else if (catRegion =="7"){catRetrieve = "151";}//Kapiti
	else if (catRegion =="8"){catRetrieve = "152";}//manawatu
	else if (catRegion =="9"){catRetrieve = "154";}//nelson
	else if (catRegion =="10"){catRetrieve = "155";}//northland
	else if (catRegion =="11"){catRetrieve = "156";}//queenstown
	else if (catRegion =="12"){catRetrieve = "157";}//rotorua
	else if (catRegion =="13"){catRetrieve = "158";}//southland
	else if (catRegion =="14"){catRetrieve = "159";}//taranaki
	else if (catRegion =="15"){catRetrieve = "160";}//taupo
	else if (catRegion =="16"){catRetrieve = "161";}//tauranga
	else if (catRegion =="17"){catRetrieve = "162";}//waikato
	else if (catRegion =="18"){catRetrieve = "";}//UNKNOWN
	else if (catRegion =="19"){catRetrieve = "163";}//wairapapa
	else if (catRegion =="20"){catRetrieve = "164";}//wanganui
	else if (catRegion =="21"){catRetrieve = "165";}//wellington
	else if (catRegion =="23"){catRetrieve = "143";}//gisborne
//alert(catRetrieve)
		 return catRetrieve;
		
	 }



	
	
	
	
	function addbookmark() {
var locBrow=wheret;
bookmarkurl=window.location.href;
bookmarktitle=locBrow;

if (document.all) window.external.AddFavorite(bookmarkurl,bookmarktitle);

else if (window.sidebar)
window.sidebar.addPanel(bookmarktitle, bookmarkurl, "")
}

/* set homepage */
	function setHome(siteURL) {
  if (document.all)
{
    document.body.style.behavior = "url(#default#homepage)";
    document.body.setHomePage(siteURL);
}
else
    alert("only works in IE 4.0 or higher! \n \nto add MoreFM as your homepage from other browsers simply go: \n1) tools \n2) options \nand add it here");
}

function openListenWindow(which) { 
mywindow = window.open(which,"ListenOnline","width=470,height=400,toolbar=0,scrollbars=0,location=0,menubar=0,resizeable=0,status=0"); 
} 
	
	
	
	
	
	

      //----------

      function addEvent(obj ,evt, fnc)
      {
        if (obj.addEventListener)
          obj.addEventListener(evt,fnc,false);
        else if (obj.attachEvent)
          obj.attachEvent('on'+evt,fnc);
        else
          return false;
        return true;
      }

      function removeEvent(obj ,evt, fnc)
      {
        if (obj.removeEventListener)
          obj.removeEventListener(evt,fnc,false);
        else if (obj.detachEvent)
          obj.detachEvent('on'+evt,fnc);
        else
          return false;
        return true;
      }

      //----------

      function appendElement(node,tag,id,htm)
      {
        var ne = document.createElement(tag);
        if(id) ne.id = id;
        if(htm) ne.innerHTML = htm;
        node.appendChild(ne);
      }

      //----------

      function showPopup(p)
      {
        greyout(true);
        document.getElementById(p).style.display = 'block';
      }

      function hidePopup(p)
      {
        greyout(false);
        document.getElementById(p).style.display = 'none';
      }

      //----------

      function greyout(d,z)
      {
        var obj = document.getElementById('greyout');
        if(!obj)
        {
          appendElement(document.body,'div','greyout');
          obj = document.getElementById('greyout');
          obj.style.position = 'absolute';
          obj.style.top = '0px';
          obj.style.left = '0px';
          obj.style.background = '#111';
          obj.style.opacity = '.5';
          obj.style.filter = 'alpha(opacity=50)';
        }
        if(d)
        {
          if(!z){ z = 50 ;}
          obj.style.zIndex = z;
          obj.style.height = Math.max(document.body.scrollHeight,document.body.clientHeight)+'px';
          obj.style.width  = Math.max(document.body.scrollWidth,document.body.clientWidth)+'px';
          obj.style.display = 'block';
          addEvent(window,'resize',greyoutResize);
        }
        else
        {
          obj.style.display = 'none';   
          removeEvent(window,'resize',greyoutResize);
        }
      }
     
      function greyoutResize()
      {
        var obj = document.getElementById('greyout');
        obj.style.height = document.body.clientHeight+'px';
        obj.style.width  = document.body.clientWidth+'px';
        obj.style.height = Math.max(document.body.scrollHeight,document.body.clientHeight)+'px';
        obj.style.width  = Math.max(document.body.scrollWidth,document.body.clientWidth)+'px';
      }

      //----------
	function  checkMyRegion(){
	  var myRegion = getcookie('logoimg');
	  if((myRegion=="")||(myRegion=="undefined")){
		  window.onload=function(){
			  
			  showPopup('popup');

		//setTimeout("showPopup('popup')",2000) ;
		  }
		}
	else {//this bit fires the user to thei regino home page if they somehow comeback to the main home
		v1 = "http://www.morefm.co.nz/Home/tabid/36/language/en-US/Default.aspx";
		v2 = "http://www.morefm.co.nz/";
		v3 = "http://www.morefm.co.nz/Home/tabid/36/Default.aspx";
		v4 = "http://morefm.co.nz/Home/tabid/36/language/en-US/Default.aspx";
		v5 = "http://morefm.co.nz/";
		v6 = "http://morefm.co.nz/Home/tabid/36/Default.aspx";
	if((location.href==v1)||(location.href==v2)||(location.href==v3)||(location.href==v4)||(location.href==v5)||(location.href==v6)){
	fireToPage(myRegion);
	}
}}

function  checkMyPage(){
	document.getElementById('headerLogo').innerHTML='';
var myPage = getcookie('page');
if((myPage!="")&&(myPage!="undefined")){
	addImage='<a href="/?tabid='+ myPage+'"><img src="/Portals/0/images/site/logos/logo_'+myPage+'.gif" align="left" alt="home"/><\/a>';
}
else{
	addImage='<a href="/"><img src="/Portals/0/images/site/logo.gif" align="left" alt="home"/><\/a>';

}
document.getElementById('headerLogo').innerHTML=addImage;

}


 

		function openPlayerWindow(site) {
			newWindow=window.open("/Portals/0/nowplaying/player.htm?site="+site+"","blitz","width=530,height=550,toolbar=no,scrollbars=no, location=no,menubar=no,noresizeable=no,status=no")
		}
		
		function launchPlayer(reg){
			//onclick="openWindow('/portals/0/player/akl-playerControl07.htm','akl')";
			if(reg=="2"){//auckland
			newWindow=window.open("/Portals/0/player/akl-playerControl07.htm","blitz","width=470,height=400,toolbar=no,scrollbars=no, location=no,menubar=no,noresizeable=no,status=no")
			}
			else if(reg=="13"){//waikato
			newWindow=window.open("/Portals/0/player/wai-playerControl07.htm","blitz","width=470,height=400,toolbar=no,scrollbars=no, location=no,menubar=no,noresizeable=no,status=no")
		
				
				}
			else if(reg=="20"){//hawkes bay
			newWindow=window.open("/Portals/0/player/haw-playerControl07.htm","blitz","width=470,height=400,toolbar=no,scrollbars=no, location=no,menubar=no,noresizeable=no,status=no")
		
				
				}
			else if(reg=="43"){//northland
			newWindow=window.open("/Portals/0/player/nor-playerControl07.htm","blitz","width=470,height=400,toolbar=no,scrollbars=no, location=no,menubar=no,noresizeable=no,status=no")
		
				
				}
			else if(reg=="26"){//manawatu
			newWindow=window.open("/Portals/0/player/man-playerControl07.htm","blitz","width=470,height=400,toolbar=no,scrollbars=no, location=no,menubar=no,noresizeable=no,status=no")
		
				
				}
			else if(reg=="18"){//wairarapa
			newWindow=window.open("/Portals/0/player/wairarapa-playerControl07.htm","blitz","width=470,height=400,toolbar=no,scrollbars=no, location=no,menubar=no,noresizeable=no,status=no")
		
				
				}
			else if(reg=="40"){//wellington
			newWindow=window.open("/Portals/0/player/well-playerControl07.htm","blitz","width=470,height=400,toolbar=no,scrollbars=no, location=no,menubar=no,noresizeable=no,status=no")
		
				
				}
			else if(reg=="4"){//caterbury
			newWindow=window.open("/Portals/0/player/can-playerControl07.htm","blitz","width=470,height=400,toolbar=no,scrollbars=no, location=no,menubar=no,noresizeable=no,status=no")
		
				
				}
			else if(reg=="7"){//dunedin
			newWindow=window.open("/Portals/0/player/dun-playerControl07.htm","blitz","width=470,height=400,toolbar=no,scrollbars=no, location=no,menubar=no,noresizeable=no,status=no")
		
				
				}
			
			
			else{
				newWindow=window.open("/Portals/0/player/listenOnline.htm","blitz","width=470,height=400,toolbar=no,scrollbars=no, location=no,menubar=no,noresizeable=no,status=no")
		

				}
			
			}


