function showPage(pageNum){
	currentPage = pageNum
	var x=0
	for(x=0;x<8;x++){
		if(document.getElementById('Page'+x)){
			document.getElementById('Page'+x).style.display='none'
			if(x>0 && x<7)document.getElementById('MMB'+x).className='NotSelected'
		}
	}
	document.getElementById('Page'+pageNum).style.display='block'
	
	if(pageNum>0 && pageNum<7)document.getElementById('MMB'+pageNum).className='Selected'
	updateDebug()
	if(pageNum>0)log_java_clickthrough('MainMenu',pageNum)

	if(pageNum == 1){
		document.getElementById('TopRadio').style.display='block'
		document.getElementById('TopPod').style.display='block'
		document.getElementById('TopNews').style.display='block'
	}
	if(pageNum==2 || pageNum==3){
		document.getElementById('TopRadio').style.display='block'
		document.getElementById('TopPod').style.display='block'
		document.getElementById('TopNews').style.display='none'
	}
	if(pageNum == 4 || pageNum == 5 || pageNum == 6){
		document.getElementById('TopRadio').style.display='none'
		document.getElementById('TopPod').style.display='none'
		document.getElementById('TopNews').style.display='block'
	}
	if(pageNum == 0 ){
		document.getElementById('TopRadio').style.display='block'
		document.getElementById('TopPod').style.display='block'
		document.getElementById('TopNews').style.display='block'
	}
}

function showUPage(pageNum){
	if(registeredUser !=0){
		document.body.style.cursor='wait'
		currentPage = pageNum
		var x=1
		for(x=1;x<7;x++){
			if(x>0)document.getElementById('UMB'+x).className='NotSelected'
		}
		document.getElementById('UMB'+pageNum).className='Selected'

		var date = new Date();
		var timestamp = date.getTime();
		var url=''

		if(pageNum == 1)url="processors/refresh_my_profile.php"
		if(pageNum == 2)url="processors/refresh_my_radio.php"
		if(pageNum == 3)url="processors/refresh_my_podcast.php"
		if(pageNum == 4)url="processors/refresh_my_news.php"
		if(pageNum == 5)url="processors/refresh_my_traffic.php"
		if(pageNum == 6)url="processors/refresh_my_weather.php"
		url=url+"?rpuid="+registeredUser+"&time="+timestamp+"&domain="+domain

		var date = new Date()
		var timestamp = date.getTime()
		xmlHttpUserData=GetXmlHttpObject()
		xmlHttpUserData.onreadystatechange=showUPageData
		xmlHttpUserData.open("GET",url,true)
		xmlHttpUserData.send(null)
		//updateDebug()
	}
}

function showUPageData(){
	if (xmlHttpUserData.readyState==4 || xmlHttpUserData.readyState=="complete"){
		document.getElementById('UserDataWrapper').innerHTML=xmlHttpUserData.responseText
		document.body.style.cursor='default'
	}
}


function setPlayBG(id){
	var playId = 'Play_'+id
	document.getElementById(playId).style.background='#f00;'
}
function unsetPlayBG(id){
	var playId = 'Play_'+id
	document.getElementById(playId).style.background='#fff;'
}

function showEpisodeDescription(newId,currentId){
	//alert('Showing Description')
	var switchOff = 'EDH_'+currentId
	var switchOn = 'EDH_'+newId
	document.getElementById(switchOff).style.display='none'
	document.getElementById(switchOn).style.display='block'
}


function showEpisodeDescription2(newId,count){
	//alert('Showing Description')
	var x = 0
	for(x=1;x<count;x++){
		var switchOff = 'EDH_'+x
		document.getElementById(switchOff).style.display='none'
	}

	var switchOn = 'EDH_'+newId
	document.getElementById(switchOn).style.display='block'
}


function openPodEpisodes(podId){
	var openPodDiv = "PodId_"+podId
	var podDetails = "PodEpisodes_"+podId

	if(expandedPodBox!=podId){
		podListId = podId
		if(document.getElementById(podDetails).innerHTML=='')fetchPodEpisodes()
		if(expandedPodBox!=0){
			shrinkPodBox(expandedPodBox,283)
		}
		expandPodBox(podId,83)
		expandedPodBox = podId
	}else{
		shrinkPodBox(podId,283)
		expandedPodBox = 0
	}

}

function expandPodBox(expandingPodBox,newSize){
	var thisBox = "PodId_"+expandingPodBox
	var newStyle= newSize+'px'
	document.getElementById(thisBox).style.height=newStyle
	newSize = newSize + 10
	if(newSize != 283){
		setTimeout ("expandPodBox("+expandingPodBox+","+newSize+")",1)
	}
}

function shrinkPodBox(shrinkingPodBox,newSize){
	var thisBox = "PodId_"+shrinkingPodBox
	var newStyle= newSize+'px'
	if(document.getElementById(thisBox)){ // Prevents error when calling before page is fully loaded
		document.getElementById(thisBox).style.height=newStyle
		newSize = newSize - 10
		if(newSize != 73){
			setTimeout ("shrinkPodBox("+shrinkingPodBox+","+newSize+")",1)
		}
	}
}

function fadeTickerDown(fadeValue){
	//alert(fadeValue)
	var newFadeValue = fadeValue - 5
	if (newFadeValue > -1){
		var object=document.getElementById('TickerContent').style
		object.opacity = newFadeValue/100
		object.MozOpacity = newFadeValue/100
		object.KhtmlOpacity = newFadeValue/100
		object.filter = "alpha(opacity=" + newFadeValue + ")"
		setTimeout("fadeTickerDown("+newFadeValue+")",30)
	}else{
		document.getElementById('TickerContent').innerHTML=xmlHttpTicker.responseText
		fadeTickerUp(0)
	}
}

function fadeTickerUp(fadeValue){
	//alert(fadeValue)
	var newFadeValue = fadeValue + 5
	if (newFadeValue < 105){
		var object=document.getElementById('TickerContent').style
		object.opacity = newFadeValue/100
		object.MozOpacity = newFadeValue/100
		object.KhtmlOpacity = newFadeValue/100
		object.filter = "alpha(opacity=" + newFadeValue + ")"
		setTimeout("fadeTickerUp("+newFadeValue+")",30)
	}else{
		resetTickerTimer()
	}
}


function switchStream(codec,streamURL,id,type){ // don't forget to register the click!
	streamURL=streamURL.replace('#~#',"'") // Correct the Radionomy apos problem
	streamURL=streamURL.replace('#~~#',"|") // Correct the Sky News Podcast | problem for autoplay
	currentStream = streamURL
	// ensure the plugin is loaded before switching streams
	requiredPlayer = 1
	if(codec=='ra' && raPlayerStatus==0) requiredPlayer=0
	if(codec=='g2' && raPlayerStatus==0) requiredPlayer=0
	if(codec=='wma' && winPlayerStatus==0) requiredPlayer=0
	if(codec=='mp3' && winPlayerStatus==0) requiredPlayer=0
	if(codec=='aac' && winPlayerStatus==0) requiredPlayer=0

	if(requiredPlayer==1){
		stopPlayer()
		if(codec=='wma') currentPlayer='windows'
		if(codec=='mp3') currentPlayer='windows'
		if(codec=='aac') currentPlayer='windows'
		if(codec=='g2') currentPlayer='real'
		if(codec=='ra') currentPlayer='real'
		if(currentPlayer=="windows"){

			if(systemOs=='WIN'){
				streamURL=streamURL.replace('listen.pls','')
				document.WMPlayer.URL = streamURL
			}
			if(systemOs=='MAC'){
				document.QTPlayer.SetURL(streamURL)
			}
		}
		if(currentPlayer=="real"){
			if(systemBrowser != 'CHROME'){
				try{
					document.RAPlayer.SetSource(streamURL)

				}
				catch(err){
					alert('Failed to set RA stream')
				}

			}
		}
		startPlayer()
		if (type=='radio') currentRadioId = id
		if (type=='podcast') currentPodId = id
		if (id > 0) updatePlayerInfo(id,type) // Supress player updates when switching podcast episodes
		registerStreamClick(type,id)
		updateDebug()
	}else{
		// Report missing Plugin
		if(systemOs=='WIN' && systemBrowser!='CHROME'){
			if(codec=='wma' || codec=='mp3' || codec=='aac'){
				alert('Sorry... This content requires the Windows Media Player Plugin.')
			}
			if(codec=='g2' || codec=='ra'){
				alert('Sorry... This content requires the RealAudio Player Plugin.')
			}
		}
		if(systemOs=='MAC' && systemBrowser=='SAFARI'){
			if(codec=='wma' || codec=='mp3' || codec=='aac'){
				alert('Sorry... This content requires the QuickTime and Flip-4-Mac Plugins.')
			}
			if(codec=='g2' || codec=='ra'){
				alert('Sorry... This content requires the RealAudio Player Plugin.')
			}
		}
		
		if(systemOs=='WIN' && systemBrowser=='CHROME'){
			alert('Sorry... this site does not yet support your browser and you will not be able to play back any of the media you discover. Please switch to IE or Firefox and try again.')
		}
		if(systemOs=='MAC' && systemBrowser!='SAFARI'){
			alert('Sorry... this site does not yet support your browser and you will not be able to play back any of the media you discover. Please switch to Safari and try again.')
		}

	}
}

function switchToAlternateStream(data){
	var doStreamSwitch = 'yes'


	// Bug Fix Safari that calls this function when it should not
	if(data == 'My Favourites') doStreamSwitch = 'no'


	if(data == 'showMyPodcasts'){
		doStreamSwitch = 'no'
		showUPage(3)
		showPage(7)
		document.getElementById('MyFavsDropDown').selectedIndex = 0
	}
	if(data == 'showMyStations'){
		doStreamSwitch = 'no'
		showUPage(2)
		showPage(7)
		document.getElementById('MyFavsDropDown').selectedIndex = 0
	}

	if(data == 'showRelatedPodcasts'){
		doStreamSwitch = 'no'
		showPage(3)
		document.getElementById('NetworkContent').selectedIndex = 0
	}

	if(data == 'showNetworkStations'){
		doStreamSwitch = 'no'
		showPage(2)
		document.getElementById('NetworkContent').selectedIndex = 0
	}

	if(doStreamSwitch == 'yes'){
		var bits = new Array()
		bits = data.split('||')
		switchStream(bits[0],bits[1],bits[2],bits[3])
	}
}

function stopPlayer(){
	if(currentPlayer=="windows"){
		if(systemOs=='WIN')document.WMPlayer.controls.stop()
		if(systemOs=='MAC'){
			document.QTPlayer.Stop()
		}
	}
	if(currentPlayer=="real"){
		if(systemBrowser=='CHROME'){
			// KIll RA OBJECT
			// Create RA Object
			document.getElementById('RAPlayerHolder').innerHTML='<object id="RAPlayer"'
			+'type="audio/x-pn-realaudio-plugin"'
			+'width="1"'
			+'height="1">'
			+'<param name="src" value="" />'
			+'<param name="controller" value="false" />'
			+'<param name="autostart" value="false" />'
			+'<param name="enablejavascript" value="true" />'
			+'</object>'
		}else{
			document.RAPlayer.DoStop()
		}
	}
}

function startPlayer(){
	if(currentPlayer=="windows"){
		if(systemOs=='WIN')document.WMPlayer.controls.play()
		if(systemOs=='MAC'){
			//alert('Starting QT Player')
			document.QTPlayer.Play()
		}
	}
	if(currentPlayer=="real"){
		if(systemBrowser=='CHROME'){
			//alert(currentStream)
			// Create RA Object
			document.getElementById('RAPlayerHolder').innerHTML='<object id="RAPlayer"'
			+'type="audio/x-pn-realaudio-plugin"'
			+'width="1"'
			+'height="1">'
			+'<param name="src" value="'+currentStream+'" />'
			+'<param name="controller" value="false" />'
			+'<param name="autostart" value="true" />'
			+'<param name="enablejavascript" value="true" />'
			+'</object>'
		}else{
			document.RAPlayer.DoPlay()
		}
	}
}

function pausePlayer(){
	if(systemOs=='WIN'){
		document.WMPlayer.controls.pause()
	}
	if(systemOs=='MAC'){
		document.QTPlayer.Stop()
	}
}

function fastforwardPlayer() {
	if(systemOs=='WIN'){
		var nowMarker = parseInt(document.WMPlayer.controls.currentPosition)
		var jumpTo = nowMarker + 30
		document.WMPlayer.controls.currentPosition = jumpTo
	}
	if(systemOs=='MAC'){
		var nowMarker = document.QTPlayer.GetTime()
		var timeScale = document.QTPlayer.GetTimeScale()
		var jumpTo = nowMarker + (timeScale * 30)
		document.QTPlayer.SetTime(jumpTo)
	}
	refreshPlayerTimer()
}

function rewindPlayer() {
	if(systemOs=='WIN'){
		var nowMarker = parseInt(document.WMPlayer.controls.currentPosition)
		var jumpTo = nowMarker - 30
		if(jumpTo < 0 ) jumpTo = 0
		document.WMPlayer.controls.currentPosition = jumpTo
	}
	if(systemOs=='MAC'){
		var nowMarker = document.QTPlayer.GetTime()
		var timeScale = document.QTPlayer.GetTimeScale()
		var jumpTo = nowMarker - (timeScale * 30)
		if(jumpTo < 0 ) jumpTo = 0
		document.QTPlayer.SetTime(jumpTo)
	}
	refreshPlayerTimer()
}

function openMoreCopyWrapper(copyWrapperId){
	var wrapperId='MoreCopyWrapper'+copyWrapperId
	var controlId='EBlock'+copyWrapperId
	var newLinkCode='<span onclick="closeMoreCopyWrapper('+copyWrapperId+');">Close...</span>'
	document.getElementById(wrapperId).style.display='block'
	document.getElementById(controlId).innerHTML=newLinkCode
}

function closeMoreCopyWrapper(copyWrapperId){
	var wrapperId='MoreCopyWrapper'+copyWrapperId
	var controlId='EBlock'+copyWrapperId
	var newLinkCode='<span onclick="openMoreCopyWrapper('+copyWrapperId+');">More...</span>'
	document.getElementById(wrapperId).style.display='none'
	document.getElementById(controlId).innerHTML=newLinkCode
}

// New User For Validation and function

function checkDD(data){
	if(data == 'dd')document.getElementById('urbday').value=''
	if(data == '')document.getElementById('urbday').value='dd'
}
function checkMM(data){
	if(data == 'mm')document.getElementById('urbmonth').value=''
	if(data == '')document.getElementById('urbmonth').value='mm'
}
function checkYY(data){
	if(data == 'yyyy')document.getElementById('urbyear').value=''
	if(data == '')document.getElementById('urbyear').value='yyyy'
}



function validateUserRegForm(){
	var dataOK = 0

	if(dataOK==0){
		if(document.getElementById('urname').value.length < 1){
			alert('Please enter your Name.')
			document.getElementById('urname').focus()
			dataOK = 1
		}
	}

	if(dataOK==0){
		if(document.getElementById('uremail').value.length < 1){
			alert('Please enter your email address.')
			document.getElementById('uremail').focus()
			dataOK = 1
		}
	}

	if(dataOK==0){
		if(document.getElementById('uremail2').value.length < 1){
			alert('Please confirm your email address.')
			document.getElementById('uremail2').focus()
			dataOK = 1
		}
	}

	if(dataOK==0){
		var e1 = document.getElementById('uremail').value
		var e2 = document.getElementById('uremail2').value
		if(e1 != e2){
			alert('There is a mismatch on your email and email confirmation.')
			document.getElementById('uremail').focus()
			dataOK = 1
		}
	}

	if(dataOK==0){
		if(document.getElementById('urpass').value.length < 1){
			alert('Please enter a password.')
			document.getElementById('urpass').focus()
			dataOK = 1
		}
	}

	if(dataOK==0){
		return true
	}else{
		return false;
	}

}
// TAF Form Validation

function validateTAFForm(){
	var formValid = 1

	if(document.getElementById('from_name').value==''){
		formValid = 0
		alert('Please enter your name.')
		document.getElementById('from_name').focus()
	}

	if(formValid==1 && document.getElementById('from_email').value==''){
		formValid = 0
		alert('Please enter your email addresss.')
		document.getElementById('from_email').focus()
	}

	if(document.getElementById('taf_name').value==''){
		formValid = 0
		alert('Please enter your friend\'s name.')
		document.getElementById('taf_name').focus()
	}

	if(formValid==1 && document.getElementById('taf_email').value==''){
		formValid = 0
		alert('Please enter your friend\'s email addresss.')
		document.getElementById('taf_email').focus()
	}
	if(formValid==1 && document.getElementById('taf_email2').value==''){
		formValid = 0
		alert('Please  confirm your friend\'s email addresss.')
		document.getElementById('taf_email2').focus()
	}
	if(formValid==1 && document.getElementById('taf_email').value!=document.getElementById('taf_email2').value){
		formValid = 0
		alert('Sorry... but your firnds email and conformation don\'t match.')
		document.getElementById('taf_email2').focus()
	}

	if(formValid == 1){
		sendTAFForm()
	}


}

// Contact Form Validataion
function validateContactForm(formNumber){
	var formValid = 1

	if(document.getElementById('contact_name').value==''){
		formValid = 0
		alert('Please enter your name.')
		document.getElementById('contact_name').focus()
	}

	if(formValid==1 && document.getElementById('contact_email').value==''){
		formValid = 0
		alert('Please enter your email addresss.')
		document.getElementById('contact_email').focus()
	}

	if(formValid==1 && document.getElementById('contact_email2').value==''){
		formValid = 0
		alert('Please confirm your email addresss.')
		document.getElementById('contact_email2').focus()
	}

	if(formValid==1 && document.getElementById('contact_email').value != document.getElementById('contact_email2').value){
		formValid = 0
		alert("Email Mismatch!\n\nPlease confirm your email address.")
		document.getElementById('contact_email1').focus()
	}

	if(formValid==1){
		if(formNumber == 1 || formNumber == 2 || formNumber == 6 || formNumber == 9){			// All forms that REQUIRE comments
			if(document.getElementById('comment').value==''){
				formValid = 0
				alert('Please enter your comments.')
				document.getElementById('comment').focus()
			}
		}
	}

	if(formValid==1){
		if(formNumber == 4){								// All forms that REQUIRE Company
			if(document.getElementById('contact_company').value==''){
				formValid = 0
				alert('Please enter the name of the company your represent.')
				document.getElementById('contact_company').focus()
			}
		}
	}

	if(formValid==1){
		if(formNumber == 4 || formNumber == 10){								// All forms that REQUIRE Role
			if(document.getElementById('contact_role').value==''){
				formValid = 0
				alert('What is your role within the company?')
				document.getElementById('contact_role').focus()
			}
		}
	}

	if(formValid==1){
		if(formNumber == 5){								// All forms that REQUIRE Media
			if(document.getElementById('media_title').value==''){
				formValid = 0
				alert('What is the title of the media you are connected with?')
				document.getElementById('media_title').focus()
			}
		}
	}

	if(formValid==1){
		if(formNumber == 4 || formNumber == 5 || formNumber == 10){				// All forms that REQUIRE Telephone Number
			if(document.getElementById('contact_number').value==''){
				formValid = 0
				alert('Please enter your daytime telephone number.')
				document.getElementById('contact_number').focus()
			}
		}
	}

	if(formValid==1){
		if(formNumber == 8){								// All forms that REQUIRE Website Address
			if(document.getElementById('new_web_address').value==''){
				formValid = 0
				alert('Please enter your web site address.')
				document.getElementById('new_web_address').focus()
			}
		}
	}

	if(formValid==1){
		if(formNumber == 8){								// All forms that REQUIRE Terms Confirmation
			if(!document.getElementById('agree_terms').checked){
				formValid = 0
				alert('Please confrim you have read and you agree with our Licence Terms.')
			}
		}
	}

	if(formValid==1){
		if(formNumber == 9){								// All forms that REQUIRE Station Name
			if(document.getElementById('station_name').value==''){
				formValid = 0
				alert('Please enter your station name.')
				document.getElementById('station_name').focus()
			}
		}
	}


	if(formValid == 1){
		sendContactForm(formNumber)
	}

	return false
}

