function changeVideo(theVideoURL){
	window.document.videoMaster.SetVariable("globalVideoName", theVideoURL);
	window.document.videoMaster.SetVariable("globalAction", "play");
	window.document.videoMaster.GotoFrame(2);
	window.document.videoMaster.Play();	
}

function stopVideo(){
	window.document.videoMaster.SetVariable("globalAction", "stop");
	window.document.videoMaster.GotoFrame(4);
	window.document.videoMaster.Play();	
}

function printPage() 
{
	if (window.print)
    	window.print();
	else
    	alert("Sorry, your browser doesn't support this feature.");
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function MM_showHideLayers() { //v6.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
    obj.visibility=v; }
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function jump(sel) {
	var url = sel.options[sel.selectedIndex].value;
	if ( url != '#' ) top.location = url;
}

function openWindow(theURL,winName,features) {
  	window.open(theURL,winName,features).focus();
}

function keywordFocus() {
	if (document.tvnz_search.search.value == " Keyword / Search ") {
	document.tvnz_search.search.value = "";
	}
}

function keywordBlur() {
	if (document.tvnz_search.search.value == "") {
	document.tvnz_search.search.value = " Keyword / Search ";
	}
}

// Initialisies array for date
function isnArray() { 
	argnr = isnArray.arguments.length;
	for (var i = 0; i < argnr; i++) {
		this[i] = isnArray.arguments[i];
	}
}

// Function to display the date
function displayDate(wantYear) {
	//var months = new isnArray("","January","February","March","April","May","June","July","August","September","October","November","December");
	var months = new isnArray("","Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec");
	//var days = new isnArray("","Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday");				
	var days = new isnArray("","Sun","Mon","Tue","Wed","Thu","Fri","Sat");
	var dateObj = new Date(); // todays date
	//var hour = dateObj.getHours();
	//var min = ((dateObj.getMinutes() < 10) ? "0" : "") + dateObj.getMinutes();
	//var min = dateObj.getMinutes();
	//var sec = dateObj.getSeconds();
	var hour = dateObj.getHours()
	var min = dateObj.getMinutes()
	var sec = dateObj.getSeconds()
	var time = ((hour < 10) ? "0" : "") + hour + ":" + ((min < 10) ? "0" : "") + min
	// add this to the line above for seconds + ":" + ((sec < 10) ? "0" : "") + sec
	var wday = days[dateObj.getDay() + 1];
	var lmonth = months[dateObj.getMonth() + 1];
	var date = dateObj.getDate();
	var fyear = dateObj.getYear();
	if (fyear < 2000) {
		fyear = fyear + 1900;
	}
	if(wantYear=='noyear'){
		return(wday + " " + lmonth + " " + date +" " + time);
	}
	else if(wantYear=='timeonly'){
		return(time);
	}
	else if(wantYear=='houronly'){
		return(hour);
	}
	else{
		return(wday + ", " + lmonth + " " + date + ", " + fyear);
	}
}

function displayLayer( id, value )
{
    if ( document.getElementById )
    {
        document.getElementById( id ).style.display = value;
    }
    else if ( document.all )
    {
        document.all[ id ].style.display = value;
    }
}

function hide( id )
{
    displayLayer( id, 'none' );
}

function show( id )
{
    displayLayer( id, 'block' );
}

//This function is used by the news_search_include in the archive page
//The five search parameters are collected from the combo boxes and text box and appended to the url for Cocoon to process
function search( ) 
{
    //This searches for all item types i.e. news, video, photogaller, comment and livescoring
    if (keyword.value == '' || keyword.value == null)
        //If no keyword is specified search for ALL items in the date range i.e. all items have 'rwc' as a keyword
        window.location='/archive/all/rwc/'+from_year.value+'/'+from_month.value+'/'+to_year.value+'/'+to_month.value+'(1)';
    else
        window.location='/archive/all/'+keyword.value+'/'+from_year.value+'/'+from_month.value+'/'+to_year.value+'/'+to_month.value+'(1)';
}

//This function is used to track click-throughs on flash:
function launchClickthruFromFlash(urlToOpen) {
	//DUMB DUMB DUMTake in the URL that we've been passed by the flash banner and open the new 
	//URL, passing through spinbox
	//first we'll check the urlToOpen - if it contains an "http://" then 
	//we'll open that, otherwise, we'll open SBURL
	var realURLToOpen;
	if(urlToOpen.indexOf("http")!= -1) {
		realURLToOpen = urlToOpen;
	} else {
		realURLToOpen = SBURL;		
	}
	
	open("http://factotum.tvnz.co.nz/?RC=" + RCNumber + "&AI=" + AINumber + "&RL=" + realURLToOpen, "_TOP");
}

//This function is used to track click-throughs on flash:
function launchClickthruFromFlashBanner(urlToOpen) {
	//DUMB DUMB DUMTake in the URL that we've been passed by the flash banner and open the new 
	//URL, passing through spinbox
	//first we'll check the urlToOpen - if it contains an "http://" then 
	//we'll open that, otherwise, we'll open SBURL
	var realURLToOpen;
	if(urlToOpen.indexOf("http")!= -1) {
		realURLToOpen = urlToOpen;
	} else {
		realURLToOpen = SBURL;		
	}
	
	open("http://factotum.tvnz.co.nz/?RC=" + RCBannerNumber + "&AI=" + AIBannerNumber + "&RL=" + realURLToOpen, "_TOP");
}

//This function is used to track click-throughs on flash:
function launchClickthruFromFlashSmallBanner(urlToOpen) {
	//DUMB DUMB DUMTake in the URL that we've been passed by the flash banner and open the new 
	//URL, passing through spinbox
	//first we'll check the urlToOpen - if it contains an "http://" then 
	//we'll open that, otherwise, we'll open SBURL
	var realURLToOpen;
	if(urlToOpen.indexOf("http")!= -1) {
		realURLToOpen = urlToOpen;
	} else {
		realURLToOpen = SBURL;		
	}
	
	open("http://factotum.tvnz.co.nz/?RC=" + RCSmallBannerNumber + "&AI=" + AISmallBannerNumber + "&RL=" + realURLToOpen, "_TOP");
}

var origWidth, origHeight;
	if (document.layers) {
		origWidth = window.innerWidth; origHeight = window.innerHeight;
		window.onresize = function() { if (window.innerWidth != origWidth || window.innerHeight != origHeight) history.go(0); }
}
		
var cur_lyr;
	function swapLayers(id) {
	 if (cur_lyr) hideLayer(cur_lyr);
		showLayer(id);
		cur_lyr = id;
}
		
function showLayer(id) {
	var lyr = getElemRefs(id);
	if (lyr && lyr.css) lyr.css.visibility = "visible";
}
		
function hideLayer(id) {
  var lyr = getElemRefs(id);
  if (lyr && lyr.css) lyr.css.visibility = "hidden";
}

function getElemRefs(id) {
	var el = (document.getElementById)? document.getElementById(id): (document.all)? document.all[id]: (document.layers)? document.layers[id]: null;
	if (el) el.css = (el.style)? el.style: el;
	return el;
}

function ResetForm(which){
var pass=true
var first=-1
if (document.images){
for (i=0;i<which.length;i++){
var tempobj=which.elements[i]
 if (tempobj.type=="text"){
  eval(tempobj.value="")
  if (first==-1) {first=i}
 }
 else if (tempobj.type=="checkbox") {
  eval(tempobj.checked=0)
  if (first==-1) {first=i}
 }
 else if (tempobj.col!="") {
  eval(tempobj.value="")
  if (first==-1) {first=i}
 }
}
}
which.elements[first].focus()
return false
}

var MaxAllowed = 500;
function CheckChars(theElement,count){
	var LengthCheck = count.length;
	if(LengthCheck > MaxAllowed)
	{
	count=count.substring(0,MaxAllowed);
	theElement.value = count;
	alert("Maximum Message Length Exceeded");
	}
}

function CharsRemaining(theElement,count){
	var LengthCheck = count.length;
	if(LengthCheck <= MaxAllowed)
	{
	count=count.substring(0,MaxAllowed);
	theElement.value = count;
	document.msg_board.chars_left.value = (MaxAllowed - LengthCheck);
	}
}
	
function update_hidden(myForm){

  var nickname = new String(document.forms[0].nickname.value);
  document.forms[1].nickname.value=nickname;
  
  
  if(nickname.length > 1 && nickname.length < 13 ){
  
    myForm.submit();
  }
  else{
    if (nickname ==1){
      alert('This nickname has 1 character. Please enter a nickname between 2 and 12 characters');
      }
    else{
      alert('This nickname has '+ nickname.length +' characters. Please enter a nickname between 2 and 12 characters');
    }  
  }
}

function checkForm(){
	if (document.msg_board.message_text.value == "") {
		alert("Please enter your comments"); 
		document.msg_board.message_text.focus();
		return false;
	}
	return true;
}

function checkKeyword()
{
	// replacing all spaces with no spaces
  	var str = new String(document.tvnz_search.search.value);
  	var arrTemp = str.split(" ");
  	var strUnderscore = arrTemp.join("");
	// alert (strUnderscore);
	if (strUnderscore.toLowerCase() == "nzidol") {
	document.location = "http://tvnz.co.nz/view/page/500880";
	}
	else if (strUnderscore.toLowerCase() == "2tube") {
	window.open("http://www.2tube.co.nz");
	}
	else if (strUnderscore.toLowerCase() == "twotube") {
	window.open("http://www.2tube.co.nz");
	}
	else if (strUnderscore.toLowerCase() == "shortlandstcompetition") {
	document.location = "http://shortlandst.tvnz.co.nz";
	}
	else if (strUnderscore.toLowerCase() == "shortlandstreetcompetition") {
	document.location = "http://shortlandst.tvnz.co.nz";
	}
	else if (strUnderscore.toLowerCase() == "christmaspacks") {
	document.location = "http://christmaspacks.tvnz.co.nz";
	}
	else if (strUnderscore.toLowerCase() == "idol") {
	document.location = "http://nzidol.tvnz.co.nz";
	}
	else if (strUnderscore.toLowerCase() == "noughttofive") {
	document.location = "http://tvnz.co.nz/view/page/809804";
	}
	else if (strUnderscore.toLowerCase() == "yourview") {
	document.location = "http://tvnz.co.nz/view/page/786360";
	}
	else if (strUnderscore.toLowerCase() == "worldcup") {
	document.location = "http://tvnz.co.nz/view/sport_minisite_index_skin/sport_world_cup_group";
	}
	else if (strUnderscore.toLowerCase() == "yourcam") {
	document.location = "http://tvnz.co.nz/view/page/411368/625221";
	}
	else if (strUnderscore.toLowerCase() == "maitime") {
	document.location = "http://tvnz.co.nz/view/tv2_minisite_index_skin/tv2_mai_time_group";
	}
	else if (strUnderscore.toLowerCase() == "teletext") {
	document.location = "http://tvnz.co.nz/view/tvnz_story_skin/413580?format=html";
	}
	else if (strUnderscore.toLowerCase() == "narnia") {
	document.location = "http://tvnz.co.nz/view/page/488120/620430";
	}
	else if (strUnderscore.toLowerCase() == "aslan") {
	document.location = "http://tvnz.co.nz/view/page/488120/620430";
	}
	else if (strUnderscore.toLowerCase() == "lucy") {
	document.location = "http://tvnz.co.nz/view/page/488120/620430";
	}
	else if (strUnderscore.toLowerCase() == "wardrobe") {
	document.location = "http://tvnz.co.nz/view/page/488120/620430";
	}
	else if (strUnderscore.toLowerCase() == "witch") {
	document.location = "http://tvnz.co.nz/view/page/488120/620430";
	}
	else if (strUnderscore.toLowerCase() == "lion") {
	document.location = "http://tvnz.co.nz/view/page/488120/620430";
	}
	else if (strUnderscore.toLowerCase() == "snow") {
	document.location = "http://tvnz.co.nz/view/page/488120/620430";
	}
	else if (strUnderscore.toLowerCase() == "edmund") {
	document.location = "http://tvnz.co.nz/view/page/488120/620430";
	}
	else if (strUnderscore.toLowerCase() == "avalontv30") {
	document.location = "http://corporate.tvnz.co.nz/tvnz_detail/0,2406,294860-314-498,00.html";
	}
	// uncomment the following lines when The OC competition goes live
	else if (strUnderscore.toLowerCase() == "watch2win") {
	document.location = "http://tvnz.co.nz/view/tv2_story_skin/560220?format=html";
	}
	else if (strUnderscore.toLowerCase() == "watchtowin") {
	document.location = "http://tvnz.co.nz/view/tv2_story_skin/560220?format=html";
	}
	else if (strUnderscore.toLowerCase() == "tv2updates") {
	window.open('http://www.lateralnz.com/tvnzalerts/index.py','sms_popup','width=410,height=510,top=20,left=20').focus();
	document.tvnz_search.reset();
	}
	else if (strUnderscore.toLowerCase() == "smsupdates") {
	window.open('http://www.lateralnz.com/tvnzalerts/index.py','sms_popup','width=410,height=510,top=20,left=20').focus();
	document.tvnz_search.reset();
	}
	else if (strUnderscore.toLowerCase() == "election") {
	document.location = "http://tvnz.co.nz/view/news_minisite_index_skin/news_election_08_group";
	}
	else if (strUnderscore.toLowerCase() == "elections") {
	document.location = "http://tvnz.co.nz/view/news_minisite_index_skin/news_election_08_group";
	}
	else if (strUnderscore.toLowerCase() == "drtom") {
	document.location = "http://tvnz.co.nz/view/tv2_story_skin/473382%3fformat=html";
	}
	else if (strUnderscore.toLowerCase() == "2020") {
	document.location = "http://tvnz.co.nz/view/tv2_minisite_index_skin/tv2_2020_group";
	}
	else if (strUnderscore.toLowerCase() == "20/20") {
	document.location = "http://tvnz.co.nz/view/tv2_minisite_index_skin/tv2_2020_group";
	}
	else if (strUnderscore.toLowerCase() == "20-20") {
	document.location = "http://tvnz.co.nz/view/tv2_minisite_index_skin/tv2_2020_group";
	}
	else if (strUnderscore.toLowerCase() == "bigsister") {
	document.location = "http://tvnz.co.nz/view/tv2_story_skin/473387?format=html";
	}
	else if (strUnderscore.toLowerCase() == "songstar") {
	document.location = "http://tvnz.co.nz/view/tv2_story_skin/474366?format=html";
	}
	else if (strUnderscore.toLowerCase() == "spooks") {
	document.location = "http://tvnz.co.nz/view/tvone_story_skin/473879%3fformat=html";
	}
	else if (strUnderscore.toLowerCase() == "fairgo") {
	document.location = "http://tvnz.co.nz/view/tvone_minisite_index_skin/tvone_fair_go_group";
	}
	else if (strUnderscore.toLowerCase() == "queernation") {
	document.location = "http://tvnz.co.nz/view/tv2_story_skin/418959%3fformat=html";
	}
	else if (strUnderscore.toLowerCase() == "studio2") {
	document.location = "http://tvnz.co.nz/view/2kids_studio2_skin/tv2_studio2_group";
	}
	else if (strUnderscore.toLowerCase() == "arts") {
	document.location = "http://tvnz.co.nz/view/tvone_story_skin/438557?format=html";
	}
	else if (strUnderscore.toLowerCase() == "flipside") {
	document.location = "http://flipside.tvnz.co.nz";
	}
	else if (strUnderscore.toLowerCase() == "myschooliscool") {
	document.location = "http://www.tvnz.co.nz/view/2kids_story_skin/443722?format=html";
	}
	else if (strUnderscore.toLowerCase() == "testthenation") {
	document.location = "http://tvnz.co.nz/view/page/410965/819238";
	}
	else if (strUnderscore.toLowerCase() == "test") {
	document.location = "http://tvnz.co.nz/view/page/410965/819238";
	}
	else if (strUnderscore.toLowerCase() == "text") {
	document.location = "http://tvnz.co.nz/view/page/410965/819238";
	}
	else if (strUnderscore.toLowerCase() == "testanation") {
	document.location = "http://tvnz.co.nz/view/page/410965/819238";
	}
	else if (strUnderscore.toLowerCase() == "allblacks") {
	document.location = "http://tvnz.co.nz/view/sport_minisite_index_skin/sport_all_blacks_group";
	}
	//else if (strUnderscore.toLowerCase() == "olympics") {
	//document.location = "http://tvnz.co.nz/view/sport_sub_cat_skin/sport_olympics_index_group";
	//}
	else if (strUnderscore.toLowerCase() == "motorsport") {
	document.location = "http://tvnz.co.nz/view/sport_sub_cat_skin/sport_motorsport_index_group";
	}	
	else if (strUnderscore.toLowerCase() == "shellhelixmotorsport") {
	document.location = "http://tvnz.co.nz/view/sport_sub_cat_skin/sport_motorsport_index_group";
	}		
	else if (strUnderscore.toLowerCase() == "hungerforthewild") {
	document.location = "http://tvnz.co.nz/view/tvone_minisite_index_skin/tvone_hunger_group";
	}	
	else if (strUnderscore.toLowerCase() == "onesport") {
	document.location = "http://tvnz.co.nz/view/sport_index_skin/sport_index_group";
	}
	else if (strUnderscore.toLowerCase() == "tvone") {
	document.location = "http://tvnz.co.nz/view/tvone_index_skin/tvone_index_group";
	}
	else if (strUnderscore.toLowerCase() == "tv2") {
	document.location = "http://tvnz.co.nz/view/tv2_index_skin/tv2_index_group";
	}
	else if (strUnderscore.toLowerCase() == "sport") {
	document.location = "http://tvnz.co.nz/view/sport_index_skin/sport_index_group";
	}		
	else if (strUnderscore.toLowerCase() == "onenews") {
	document.location = "http://tvnz.co.nz/view/news_index_skin/news_index_group";
	}		
	else if (strUnderscore.toLowerCase() == "news") {
	document.location = "http://tvnz.co.nz/view/news_index_skin/news_index_group";
	}			
	else if (strUnderscore.toLowerCase() == "national") {
	document.location = "http://tvnz.co.nz/view/news_sub_cat_skin/news_national_index_group";
	}			
	else if (strUnderscore.toLowerCase() == "business") {
	document.location = "http://tvnz.co.nz/view/news_minisite_index_skin/news_nzi_business_index_group";
	}			
	else if (strUnderscore.toLowerCase() == "entertainment") {
	document.location = "http://tvnz.co.nz/view/news_sub_cat_skin/news_entertainment_index_group";
	}			
	else if (strUnderscore.toLowerCase() == "politics") {
	document.location = "http://tvnz.co.nz/view/news_sub_cat_skin/news_politics_index_group";
	}
	else if (strUnderscore.toLowerCase() == "parliamentlive") {
	document.location = "http://tvnz.co.nz/view/news_sub_cat_skin/news_politics_index_group";
	}		
	else if (strUnderscore.toLowerCase() == "health") {
	document.location = "http://tvnz.co.nz/view/news_sub_cat_skin/news_health_index_group";
	}			
	else if (strUnderscore.toLowerCase() == "world") {
	document.location = "http://tvnz.co.nz/view/news_sub_cat_skin/news_world_index_group";
	}			
	else if (strUnderscore.toLowerCase() == "rural") {
	document.location = "http://tvnz.co.nz/view/news_sub_cat_skin/news_rural_index_group";
	}			
	else if (strUnderscore.toLowerCase() == "travel") {
	document.location = "http://tvnz.co.nz/view/news_sub_cat_skin/news_travel_index_group";
	}			
	else if (strUnderscore.toLowerCase() == "weather") {
	document.location = "http://tvnz.co.nz/cda/tvnz/weather_index_skin";
	}
	else if (strUnderscore.toLowerCase() == "hum") {
	document.location = "http://tvnz.co.nz/view/tvone_story_skin/442586?format=html";
	}
	else if (strUnderscore.toLowerCase() == "avalon30") {
	document.location = "http://corporate.tvnz.co.nz/tvnz_detail/0,2406,294860-314-498,00.html";
	}
	else if (strUnderscore.toLowerCase() == "readysteadycook") {
	document.location = "http://tvnz.co.nz/view/tv2_story_skin/502700%3fformat=html";
	}
	else if (strUnderscore.toLowerCase() == "cashbattle") {
	document.location = "http://www.cashbattle.co.nz";
	}
	else if (strUnderscore.toLowerCase() == "ak05") {
	document.location = "http://www.ak05.co.nz";
	}
	else if (strUnderscore.toLowerCase() == "theaatorqueshow") {
	document.location = "http://tvnz.co.nz/view/tvone_minisite_index_skin/tvone_the_torque_show_group";
	}
	else if (strUnderscore.toLowerCase() == "aatorqueshow") {
	document.location = "http://tvnz.co.nz/view/tvone_minisite_index_skin/tvone_the_torque_show_group";
	}
	else if (strUnderscore.toLowerCase() == "goodmorning") {
	document.location = "http://tvnz.co.nz/view/tvone_minisite_index_skin/tvone_good_morning_group";
	}
	else if (strUnderscore.toLowerCase() == "normal") {
	document.location = "https://app.touchdowntv.com/shows/hownormal/";
	}
	else if (strUnderscore.toLowerCase() == "talentsearch") {
	document.location = "http://tvnz.co.nz/view/tvnz_story_skin/478125?format=html";
	}
	else if (strUnderscore.toLowerCase() == "mitre10dreamhome") {
	document.location = "http://tvnz.co.nz/view/tv2_story_skin/469186%3fformat=html";
	}
	else if (strUnderscore.toLowerCase() == "squirt") {
	document.location = "http://tvnz.co.nz/view/2kids_story_skin/135343%3fformat=html";
	}
	else if (strUnderscore.toLowerCase() == "headliners") {
	document.location = "http://tvnz.co.nz/view/tvone_minisite_index_skin/tvone_headliners_group";
	}
	else if (strUnderscore.toLowerCase() == "diyrescue") {
	document.location = "http://tvnz.co.nz/view/tv2_story_skin/425490%3fformat=html";
	}
	else if (strUnderscore.toLowerCase() == "mitre10diyrescue") {
	document.location = "http://tvnz.co.nz/view/tv2_story_skin/425490%3fformat=html";
	}
	else if (strUnderscore.toLowerCase() == "f&pcompetition") {
	document.location = "http://tvnz.co.nz/view/page/488121/594782/";
	}
	else if (strUnderscore.toLowerCase() == "") {
	document.location = "/";
	}
	/*else {
	alert ("Sorry this function is currently disabled")
	}*/				
	else {
	//document.tvnz_search.action="http://tvnz.co.nz/cda/tvnz/search/";
	document.tvnz_search.action="http://tvnz.co.nz/" + str;
	document.tvnz_search.submit();
	}
}

// prevent double form submissions
var searchcount=0;   

function checkSearch() {
if (searchcount == 0) { 
	if (document.tvnz_search.search.value == ' Keyword/Search') {
		document.tvnz_search.search.value = ''; return false; 
	}
	searchcount++; return true;
} else { 
	alert('This search has already been submitted.' ); return false; 
	}
}

function SelectAllText(id)
{
    document.getElementById(id).focus();
    document.getElementById(id).select();
}

function onChangeSectionCloseUp() {
	var Current =
   	document.close_up_contact.subject.selectedIndex;
	if (document.close_up_contact.subject.options[Current].text == "Send Feedback about Close Up") {
		show( 'feedback' );
		hide( 'suggest' );
		hide( 'share' );
	}
	else if (document.close_up_contact.subject.options[Current].text == "Suggest a story idea for Close Up") {
		hide( 'feedback' );
		show( 'suggest' );
		hide( 'share' );
	}
	else if (document.close_up_contact.subject.options[Current].text == "Share my own story with Close Up") {
		hide( 'feedback' );
		hide( 'suggest' );
		show( 'share' );
	}
	else {
		hide( 'feedback' );
		hide( 'suggest' );
		hide( 'share' );
	}
}

function onChangeSectionFairGo() {
	var Current =
   	document.tv_one_fair_go_feedback.subject.selectedIndex;
	if (document.tv_one_fair_go_feedback.subject.options[Current].text == "Send Feedback about Fair Go") {
		show( 'feedback' );
		hide( 'suggest' );
	}
	else if (document.tv_one_fair_go_feedback.subject.options[Current].text == "Suggest or Share a Story Idea for Fair Go") {
		hide( 'feedback' );
		show( 'suggest' );
	}
	else {
		hide( 'feedback' );
		hide( 'suggest' );
	}
}

function onChangeSectionTwenty() {
	var Current =
   	document.twenty_contact.subject.selectedIndex;
	if (document.twenty_contact.subject.options[Current].text == "Send Feedback about 20/20") {
		show( 'feedback' );
		hide( 'suggest' );
		hide( 'share' );
	}
	else if (document.twenty_contact.subject.options[Current].text == "Suggest a story idea for 20/20") {
		hide( 'feedback' );
		show( 'suggest' );
		hide( 'share' );
	}
	else if (document.twenty_contact.subject.options[Current].text == "Share my own story with 20/20") {
		hide( 'feedback' );
		hide( 'suggest' );
		show( 'share' );
	}
	else {
		hide( 'feedback' );
		hide( 'suggest' );
		hide( 'share' );
	}
}

function onChangeSectionSunday() {
	var Current =
   	document.sunday_contact.subject.selectedIndex;
	if (document.sunday_contact.subject.options[Current].text == "Send Feedback about Sunday") {
		show( 'feedback' );
		hide( 'suggest' );
		hide( 'share' );
	}
	else if (document.sunday_contact.subject.options[Current].text == "Suggest a story idea for Sunday") {
		hide( 'feedback' );
		show( 'suggest' );
		hide( 'share' );
	}
	else if (document.sunday_contact.subject.options[Current].text == "Share my own story with Sunday") {
		hide( 'feedback' );
		hide( 'suggest' );
		show( 'share' );
	}
	else {
		hide( 'feedback' );
		hide( 'suggest' );
		hide( 'share' );
	}
}

function onChangeSection() {
 		var Current =
   	document.tvnz_contact.submit_to.selectedIndex;
 		document.tvnz_contact.subject.value = document.tvnz_contact.submit_to.options[Current].text;
	if (document.tvnz_contact.submit_to.options[Current].text == "A Programme") {
		show( 'programme_row' );
		hide( 'transmission_feedback' );
	}
	else if (document.tvnz_contact.submit_to.options[Current].text == "TV reception (transmission)") {
		show( 'transmission_feedback' );
		hide( 'programme_row' );
	}
	else {
		hide( 'programme_row' );
		hide( 'transmission_feedback' );
	}
}

function onChangeSectionSuperSquad() {
	var Current =
   	document.super_squad_contact.region.selectedIndex;
	if (document.super_squad_contact.region.options[Current].text == "Auckland") {
		show( 'auckland' );
		hide( 'tauranga' );
		hide( 'new_plymouth' );
		hide( 'wellington' );
		hide( 'nelson' );
		hide( 'christchurch' );
		hide( 'dunedin' );
		hide( 'invercargill' );
	}
	else if (document.super_squad_contact.region.options[Current].text == "Tauranga") {
		hide( 'auckland' );
		show( 'tauranga' );
		hide( 'new_plymouth' );
		hide( 'wellington' );
		hide( 'nelson' );
		hide( 'christchurch' );
		hide( 'dunedin' );
		hide( 'invercargill' );
	}
	else if (document.super_squad_contact.region.options[Current].text == "New Plymouth") {
		hide( 'auckland' );
		hide( 'tauranga' );
		show( 'new_plymouth' );
		hide( 'wellington' );
		hide( 'nelson' );
		hide( 'christchurch' );
		hide( 'dunedin' );
		hide( 'invercargill' );
	}
	else if (document.super_squad_contact.region.options[Current].text == "Wellington") {
		hide( 'auckland' );
		hide( 'tauranga' );
		hide( 'new_plymouth' );
		show( 'wellington' );
		hide( 'nelson' );
		hide( 'christchurch' );
		hide( 'dunedin' );
		hide( 'invercargill' );
	}
	else if (document.super_squad_contact.region.options[Current].text == "Nelson") {
		hide( 'auckland' );
		hide( 'tauranga' );
		hide( 'new_plymouth' );
		hide( 'wellington' );
		show( 'nelson' );
		hide( 'christchurch' );
		hide( 'dunedin' );
		hide( 'invercargill' );
	}
	else if (document.super_squad_contact.region.options[Current].text == "Christchurch") {
		hide( 'auckland' );
		hide( 'tauranga' );
		hide( 'new_plymouth' );
		hide( 'wellington' );
		hide( 'nelson' );
		show( 'christchurch' );
		hide( 'dunedin' );
		hide( 'invercargill' );
	}
	else if (document.super_squad_contact.region.options[Current].text == "Dunedin") {
		hide( 'auckland' );
		hide( 'tauranga' );
		hide( 'new_plymouth' );
		hide( 'wellington' );
		hide( 'nelson' );
		hide( 'christchurch' );
		show( 'dunedin' );
		hide( 'invercargill' );
	}
	else if (document.super_squad_contact.region.options[Current].text == "Invercargill") {
		hide( 'auckland' );
		hide( 'tauranga' );
		hide( 'new_plymouth' );
		hide( 'wellington' );
		hide( 'nelson' );
		hide( 'christchurch' );
		hide( 'dunedin' );
		show( 'invercargill' );
	}
	else {
		hide( 'auckland' );
		hide( 'tauranga' );
		hide( 'new_plymouth' );
		hide( 'wellington' );
		hide( 'nelson' );
		hide( 'christchurch' );
		hide( 'dunedin' );
		hide( 'invercargill' );
	}
}

function onChangeSectionSuperSquadAbility() {
	var Current =
   	document.super_squad_contact.ability.selectedIndex;
	if (document.super_squad_contact.ability.options[Current].text == "Sports Billy") {
		show( 'sports' );
		hide( 'performer' );
		hide( 'brain' );
		hide( 'devil' );
	}
	else if (document.super_squad_contact.ability.options[Current].text == "Star Performer") {
		hide( 'sports' );
		show( 'performer' );
		hide( 'brain' );
		hide( 'devil' );
	}
	else if (document.super_squad_contact.ability.options[Current].text == "Brain Box") {
		hide( 'sports' );
		hide( 'performer' );
		show( 'brain' );
		hide( 'devil' );
	}
	else if (document.super_squad_contact.ability.options[Current].text == "Dare Devil") {
		hide( 'sports' );
		hide( 'performer' );
		hide( 'brain' );
		show( 'devil' );
	}
	else {
		hide( 'sports' );
		hide( 'performer' );
		hide( 'brain' );
		hide( 'devil' );
	}
}

function onChangeSectionNZIBusiness() {
	var Current =
   	document.nzi_business_contact.subject.selectedIndex;
	if (document.nzi_business_contact.subject.options[Current].text == "Send Feedback about NZI Business") {
		show( 'feedback' );
		hide( 'suggest' );
		hide( 'share' );
	}
	else if (document.nzi_business_contact.subject.options[Current].text == "Suggest a story idea for NZI Business") {
		hide( 'feedback' );
		show( 'suggest' );
		hide( 'share' );
	}
	else if (document.nzi_business_contact.subject.options[Current].text == "Share my own story with NZI Business") {
		hide( 'feedback' );
		hide( 'suggest' );
		show( 'share' );
	}
	else {
		hide( 'feedback' );
		hide( 'suggest' );
		hide( 'share' );
	}
}

function ValidateContactForm()
{
	var first_name = document.election_08_upload.first_name;
	var last_name = document.election_08_upload.last_name;
	var email = document.election_08_upload.email;
	var file_1 = document.election_08_upload.file_1;
	var caption_1 = document.election_08_upload.caption_1;
	var t_and_c = document.election_08_upload.t_and_c;
	
	if (first_name.value == "")
	{
		window.alert("Please enter your first name.");
		first_name.focus();
		return false;
	}
	if (last_name.value == "")
	{
		window.alert("Please enter your last name.");
		last_name.focus();
		return false;
	}
	if (email.value == "")
	{
		window.alert("Please enter a valid e-mail address.");
		email.focus();
		return false;
	}
	if (email.value.indexOf("@", 0) < 0)
	{
		window.alert("Please enter a valid e-mail address.");
		email.focus();
		return false;
	}
	if (email.value.indexOf(".", 0) < 0)
	{
		window.alert("Please enter a valid e-mail address.");
		email.focus();
		return false;
	}
	if (file_1.value == "")
	{
		window.alert("Please attach your video.");
		file_1.focus();
		return false;
	}
	if (caption_1.value == "")
	{
		window.alert("Please enter a title for your video.");
		caption_1.focus();
		return false;
	}
	if ( t_and_c.checked == false )
    {
		window.alert("Please check you have read and accept the terms and conditions.");
		email.focus();
		return false;
    }
	show( 'upload_progress' );
	return true;
}

function ismaxlength(obj){
var mlength=obj.getAttribute? parseInt(obj.getAttribute("maxlength")) : ""
if (obj.getAttribute && obj.value.length>mlength)
obj.value=obj.value.substring(0,mlength)
}

// Selena's title case function
function titleCase(str){
   // empty string
   if(!str){
      return "";
   }
   var new_str = "";
   var strLength = str.length;
   var upperCaseNext = false;
   new_str += str.charAt(0).toUpperCase();
   for (var i=1; i < strLength; i++) {
      if(upperCaseNext == true){
         new_str += str.charAt(i).toUpperCase();
      } else{
         new_str += str.charAt(i).toLowerCase();
      }
      var currentCharCode = str.charCodeAt(i);
      // if current character is a space, dash or fullstop
      // then upper case the next character
      if(currentCharCode == 32 || currentCharCode == 45 || currentCharCode == 46){
         upperCaseNext = true;
      } else {
         upperCaseNext = false
      }
   }
   return new_str;
}

// Selena's weather name function
function weatherDisplayName(str) {
  if (str) {
     switch (str) {
        case "PAIHIA": return "Paihia/Russell";  break;
        case "GREYMOUTH": return "Greymouth/Hokitika";  break;
        default:return titleCase(str.replace('_',' '));
     }
  } else {
     return "";
  }
}

// Fix for Microsoft's "Eolas patch" with Flash and other object embed tags
function createParam(name, value) {
  var p = document.createElement("param");
  p.name=name;
  p.value=value;
  return p;
 }

function flash( url, parentId, width, height, color, flashvars, name) {

	var o, e;
	
	// setup the object element
	o = document.createElement("object");
	o.codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0"
	o.width=width;
	o.height=height;
	o.id=name;
	document.getElementById(parentId).appendChild(o);
	
	// setup the object's param element(s)
	o.appendChild(createParam("movie", url));
	o.appendChild(createParam("allowScriptAccess", "always"));
	o.appendChild(createParam("wmode", "transparent"));
	o.appendChild(createParam("menu", "false"));
	o.appendChild(createParam("bgcolor", color));
	o.appendChild(createParam("FlashVars", flashvars));

	// try and setup the embed element
	try {
		e = document.createElement("embed");
		e.setAttribute("src", url);
		e.setAttribute("width", width);
		e.setAttribute("height", height);
		e.setAttribute("wmode", "transparent");
		e.setAttribute("type", "application/x-shockwave-flash");
		e.setAttribute("pluginspage", "http://www.macromedia.com/go/getflashplayer");
		e.setAttribute("FlashVars", flashvars);
		e.setAttribute("menu", "false");
		e.setAttribute("bgcolor", color);
		e.setAttribute("allowScriptAccess", "Always");
		o.appendChild(e);
	} catch (e) {
		// nothing - IE borks at the embed tag for some reason (it sucks?)
	}

	// this line MUST be last
	o.classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"; 
}

// Fix for Microsoft's "Eolas patch" and Windows Media
function video( url, width, height, autostart, loop ) {

document.write('<object id="MediaPlayer" width="'+width+'" height="'+height+'" classid="CLSID:22D6F312-B0F6-11D0-94AB-0080C74C7E95" codebase="http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=6,4,5,715" standby="Loading Microsoft Windows Media Player components..." type="application/x-oleobject">\n');
document.write('<param name="FileName" value="'+url+'">\n');
document.write('<param name="ShowStatusBar" value="True">\n');
document.write('<param name="AutoStart" value="'+autostart+'">\n');
document.write('<param name="Loop" value="'+loop+'">\n');
document.write('<embed type="application/x-mplayer2" pluginspage="http://www.microsoft.com/Windows/Downloads/Contents/Products/MediaPlayer/" src="'+url+'" showcontrols="1" showstatusbar="1" autostart="1" width="'+width+'" height="'+height+'"></embed>\n');
document.write('</object>\n');
}

// random number to be added to the DoubleClick URLs to prevent caching
var ord=Math.random()*10000000000000000;

function WMP4DC(url, width, height, name) {
	document.write(
		'<object '+
		'id="'+name+'" width="'+width+'" height="'+height+'" '+
		// DC needs both classid and type and these particular values (even the case!)
		'type="application/x-oleobject" '+
		'classid="CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6" '+ 
		'name="'+name+'" '+
		'>'+
		'<param name="URL" value="'+url+'"/>'+
		'<param name="ShowStatusBar" value="True"/>'+
		'<param name="AutoStart" value="True"/>'+
/*
<embed id="VideoPlayer1" name="VideoPlayer1" src="..." type="application/x-mplayer2"
showtracker="1" showstatusbar="0" autosize="1" loop="0"
autostart="1" EnableContextMenu="0"
pluginspage="http://www.microsoft.com/Windows/Downloads/
Contents/Products/MediaPlayer/" width="400" height="300"/>
*/
		'<embed id="'+name+'" name="'+name+'" src="'+url+'" type="application/x-mplayer2" '+
		'showtracker="1" showstatusbar="1" autosize="1" loop="0" '+
		'autostart="1" EnableContextMenu="0" '+
		'pluginspage="http://www.microsoft.com/Windows/Downloads/Contents/Products/MediaPlayer/" '+
		'width="'+width+'" height="'+height+'">'+
		'</object>'
	);
}
                     
function insertIframe(src, width, height) {
	document.write('<iframe src="' + src + '" width="' + width + '" height="' + height + '" frameBorder="0" ></iframe>');
}

var winNew;
function launch_win(sURL, sName, sFeatures) {
	while (true) {
		var i = sURL.indexOf('&amp;');
		if (i < 0) {
			break;
		}
		sURL = sURL.substring(0, i) + '&' + sURL.substring(i + 5, sURL.length);
	}
	winNew = window.open(sURL,sName,sFeatures);
	if (setTimeout) {
 		setTimeout('winNew.focus();',250);
	}
}