/*****************************************************
******************************************************

AREG-CSS site
	Template for CSS sites built with the SiteBuilder tool

	A Compilation of all the javascript used on the site

	Created Date:	9/14/07
	Created By:		scott

******************************************************
******************************************************/


//----------------------------------------------------------------------
//	Javascript Functionality for the ELS Login Module in:
//		modules/ incModELSLogin.asp
//
//	NOTE: gfunIsValidEmailAddress From: gbinc/jsfiles/incValidationAPI.js
//
//	-scott 9/29/06
//----------------------------------------------------------------------

function funValMemberNavLogin(objForm) {

	var isOK = true;
	with (objForm) {
		isOK = true;
		if (isOK && (fldUserName.value.length < 1)) {
			alert("Please enter a valid Email Address.");
			fldUserName.focus();
			isOK = false;
		}
		if (isOK && (fldPassword.value.length < 1)) {
			alert("Please enter a valid Password.");
			fldPassword.focus();
			isOK = false;
		}
	}
	return isOK;
}

function funLoginPass() {

	var objForm = g_getRawObject("elsLoginForm");

	if (objForm.fldUserName.value.length < 1) {
		alert("Please enter a valid Email Address to send your password to.");
		objForm.fldUserName.focus();
	}
	else {
		objForm.Action.value = "mailpass";
		objForm.submit();
	}
}

//----------------------------------------------------------------------
//	Javascript Functionality for the Poll Module in:
//		modules/ incMod_Poll.asp
//
//	-scott 6/28/07
//----------------------------------------------------------------------

// Make sure a Choice is selected before submitting the Poll
function funValidatePollMod(objForm) {
	
	var isOK = false;
	var objRadio = objForm.Response;
	
	if (objRadio.length) {
		for (var i = 0; i < objRadio.length; i++) {
			if (objRadio[i].checked) {
				isOK = true;
				break;
			}
		}
	}
	else if (objRadio.checked) isOK = true;
	
	return isOK;
}

//----------------------------------------------------------------------
//	Javascript Functionality for the Search Module in:
//		modules/ incModSearchForm.asp
//
//	Requires: gbinc/jsfiles/incCommonAPI.js
//	-scott 9/29/06
//  Updated 3/26/08 JimB, fixed issues per wo#61504
//----------------------------------------------------------------------

function funValidateSearchForm(sFormID)
{

	var objForm = g_getRawObject(sFormID);

    if (objForm.searchString) {
	    var sSearchFor = objForm.searchString.value;
	    if (sSearchFor.length < 1) {
		    alert("Please enter something to search for.");
		    objForm.searchString.focus();
		    return false;
	    }
	    else if (sSearchFor == "search") {
            alert("Please enter a valid search term.");
		    objForm.searchString.focus();
		    return false;
	    }
	    else {
		    return true;
	    }
	}
}

//----------------------------------------------------------------------
//	Javascript Functionality for the CustomForm page in:
//		customform.asp and customformJS.asp
//
//	NOTE: gfunIsValidEmailAddress From: gbinc/jsfiles/incValidationAPI.js
//
//	-patricia 11/18/06 
//----------------------------------------------------------------------

function ValidateCustomForm(objForm, nSignUpAge)
{
    
	if (objForm == null) objForm = document.customForm;
	if (nSignUpAge == null) nSignUpAge = 13;
	var isOK = true;
	var today = new Date();
	var theYear = today.getFullYear();
	var theMonth = today.getMonth();

	with (objForm) {
	
		//check for required response questions by looping through form elements and find matching form field name
		var sTemp = "";
		var nQID = 0;
		var objAnswer;
		var nQuestionNumber;
		for (i = 0; i < length; i++) {
			if (elements[i].name) {
			    sTemp = elements[i].name;
			    if (sTemp.indexOf("QuestionRequired") > -1) {	
				    if (elements[i].value == "1") {
					    //this question requires response
					    nQID = sTemp.substr(16);
					    if (!isNaN(nQID)) {
						    //get the answer object
						    //use try just in case answer object does not exist
						    nQuestionNumber = parseInt(nQID) + 1;
						    try {
							    objAnswer = eval("Question" + nQID + "answer");
							    //validate based on type of object
							    var nAnswerLen = parseInt(objAnswer.length);
							    if (!isNaN(nAnswerLen)) {
								    //answer object is collection
								    if (objAnswer.type != "select-one") {
									    //dropdown does not need to be validated as first option is selected
									    isOK = false;
									    for (x = 0; x < nAnswerLen; x++) {
										    if (objAnswer[x].checked) {
											    isOK = true;
										    }
									    }
									    if (!isOK) {
										    alert("Please select an answer for question number " + nQuestionNumber);
										    objAnswer[0].focus();
										    break;
									    }
								    }
							    }
							    else {
								    //only one answer to the question
								    //check for type
								    //alert("answer one type: " + objAnswer.type);
								    if (objAnswer.type == "text") {
									    if (objAnswer.value.length < 1) {
										    isOK = false;
										    alert("Please enter an answer for question number " + nQuestionNumber);
										    objAnswer.focus();
										    break;
									    }
								    }
								    if (objAnswer.type == "textarea") {
									    if (objAnswer.value.length < 1) {
										    isOK = false;
										    alert("Please enter an answer for question number " + nQuestionNumber);
										    objAnswer.focus();
										    break;
									    }
								    }
								    if (objAnswer.type == "radio" || objAnswer.type == "checkbox") {
									    //answer type is radio or checkbox and only 1 answer
									    if (!objAnswer.checked) {
										    isOK = false;
										    alert("Please select an answer for question number " + nQuestionNumber);
										    objAnswer.focus();
										    break;
									    }
								    }
								    //dropdown does not need to be validated as first option is selected
							    }
						    }
						    catch(e) {
							    //do nothing
						    }
					    }	
				    }
			    }
			}
		}
			
		
		if (objForm.FirstNameRequired && isOK) {
		    if (isOK && (txtFirstName.value.length < 2)) {
				alert("Please enter your First Name.");
				txtFirstName.focus();
				isOK = false;
			}
		}
		if (objForm.LastNameRequired && isOK) {
			if (isOK && (txtLastName.value.length < 2)) {
				alert("Please enter your Last Name.");
				txtLastName.focus();
				isOK = false;
			}
		}
		if (objForm.AddressRequired && isOK) {
			if (isOK && (txtAddress.value.length < 2)) {
				alert("Please enter your Address.");
				txtAddress.focus();
				isOK = false;
			}
		}
		if (objForm.CityRequired && isOK) {
			if (isOK && (txtCity.value.length < 2)) {
				alert("Please enter the City where you live.");
				txtCity.focus();
				isOK = false;
			}
		}
		if (objForm.StateRequired && isOK) {
			var nStateLen = parseInt(StateSize.value);
			if ( (nStateLen > 0 && txtState.value.length < nStateLen) || (txtState.value.length == 0)	) {
				alert("Please enter your " + StateLabel.value + ".");
				txtState.focus();
				isOK = false;
			}
		}
		if (objForm.PostcodeRequired && isOK) {
			if (txtPostcode.value.length < 2) {
				alert("Please enter your " + PostcodeLabel.value + ".");
				txtPostcode.focus();
				isOK = false;
			}
		}
		if (objForm.CountryCodeRequired) {
			if (isOK && (txtCountry.value.length < 2)) {
				alert("Please enter your Country.");
				txtCountry.focus();
				isOK = false;
			}
		}
		if (objForm.DayPhoneRequired) {
			if (isOK && (txtDayPhone.value.length < 10)) {
				alert("Please enter your Daytime Phone. (Please include your area code.)");
				txtDayPhone.focus();
				isOK = false;
			}
		}
		if (objForm.MobilePhoneRequired) {
			if (isOK && (txtMobilePhone.value.length < 10)) {
				alert("Please enter your Mobile Phone. (Please include your area code.)");
				txtMobilePhone.focus();
				isOK = false;
			}
		}
		if (objForm.EvePhoneRequired) {
			if (isOK && (txtEvePhone.value.length < 10)) {
				alert("Please enter your Evening Phone. (Please include your area code.)");
				txtEvePhone.focus();
				isOK = false;
			}
		}
		
		if (objForm.BirthdateRequired) {
			if (isOK && (BirthMonth.selectedIndex == 0)) {
				alert("Please select the month of your birth.");
				BirthMonth.focus();
				isOK = false;
			}
			if (isOK && (BirthDay.selectedIndex == 0)) {
				alert("Please select the day of your birth.");
				BirthDay.focus();
				isOK = false;
			}
			if (isOK && (BirthYear.selectedIndex == "" || BirthYear.value == "" || isNaN(BirthYear.value)) ) {
				alert("Please enter the Year of your Birthdate.");
				BirthYear.focus();
				isOK = false;
			}
			else if (isOK) { // Validate Age
				//updated 4/26/06 djb, set correct month&day&year, per wo#31757
				var nAge;
				var dBirthDay = new Date(today);
				dBirthDay.setMonth(BirthMonth.options[BirthMonth.selectedIndex].value,BirthDay.options[BirthDay.selectedIndex].value);
				if (BirthYear.options) {
					dBirthDay.setYear(BirthYear.options[BirthYear.selectedIndex].value);
				}
				else {
					dBirthDay.setYear("/19" + BirthYear.value);
				}
	  
				//Define a variable to hold the anniversary of theBirthdate in the current year
				var dBirthdateThisYear = new Date(today);
				dBirthdateThisYear.setDate(dBirthDay.getDate());
				dBirthdateThisYear.setMonth(dBirthDay.getMonth());
	  
				//Compare current date to dBirthdateThisYear
				//Calculate age based on whether or not we have reached dBirthdateThisYear
				if (today < dBirthdateThisYear) {
					nAge = today.getFullYear() - dBirthDay.getFullYear() - 1;
				}
				else {
					nAge = today.getFullYear() - dBirthDay.getFullYear();
				}
				if (nAge < nSignUpAge) {
					alert("Sorry, you must be at least " + nSignUpAge + " to complete this form.");
					BirthYear.focus();
					isOK = false;
				}
			}
		}
		else if (objForm.BirthYear) {
			if (isOK) {
				var nYear = 0;
				if (BirthYear.options) {
					if (BirthYear.selectedIndex > 0) nYear = BirthYear.options[BirthYear.selectedIndex].value;
				}
				else {
					if (BirthYear.value != "" && !isNaN(BirthYear.value)) nYear = parseInt("19" + BirthYear.value);
				}
				
				if ((theYear - nYear) < nSignUpAge) {
					alert("Sorry, you must be at least " + nSignUpAge + " to complete this form.");
					BirthYear.focus();
					isOK = false;
				}
			}
		}
		if (objForm.GenderRequired) {
			if (isOK && !txtGender[0].checked && !txtGender[1].checked) {
				alert("Please select your gender.");
				txtGender[0].focus();
				isOK = false;
			}
		}
		if (objForm.UserTitleRequired) {
			if (isOK && (txtUserTitle.value.length < 1)) {
				alert("Please enter a Title.");
				txtUserTitle.focus();
				isOK = false;
			}
		}
		if (objForm.EmailRequired) {
			if (isOK && !gfunIsValidEmailAddress(txtEmail.value, false)) {
				alert("Please enter a valid Email Address.\n\r A valid email address should look like yourname@yourdomain.com");
				txtEmail.focus();
				isOK = false;
			}
		}
		
		
		if (objForm.AgreeRequired && isOK) {
			if (isOK && (!AgreeCheckBox.checked)) {
				alert(AgreeLabel.value);
				AgreeCheckBox.focus();
				isOK = false;
			}
		}
		
		
		
	}
	return isOK;
}

function funFillForm(objForm) {
//Fill in the Form with the ELS User's Values

	if (objForm == null) objForm = document.customForm;

	with (objForm) {
		if (objForm.FirstName) FirstName.value = sFirstName;
		if (objForm.LastName) LastName.value = sLastName;
		if (objForm.Address) Address.value = sAddress;
		if (objForm.City) City.value = sCity;
		if (objForm.State) State.value = sState;
		if (objForm.PostalCode) PostalCode.value = sPostCode;
		if (objForm.DayPhone) DayPhone.value = sDayPhone;
		if (objForm.EvePhone) EvePhone.value = sEvePhone;
		if (objForm.Country) Country.value = sCountry;
		if (objForm.MobilePhone) {
			MobilePhone.value = sMobilePhone;
			SMSPermission.checked = bSMSPermission;
		}
		if (objForm.EmailFrom) EmailFrom.value = sEmailFrom;
		if (objForm.Gender) {
			if (sGender.toLowerCase() == "m") Gender[1].checked = true;
			else if (sGender.toLowerCase() == "f") Gender[0].checked = true;
		}
		if (sBirthdate != "") {
			//updated 4/26/06 djb, use addition variables, per wo#31757
			var dBirthDate = new Date();
			dBirthDate.setMonth(sBirthdateMonth-1,sBirthdateDay);
			dBirthDate.setYear(sBirthdateYear);
			BirthMonth.selectedIndex = dBirthDate.getMonth()+1;
			BirthDay.selectedIndex = dBirthDate.getDate();
			var TheYear = dBirthDate.getFullYear();
			for (i=0;i<BirthYear.options.length;i++) {
				if (BirthYear.options[i].value == TheYear) {
					BirthYear.selectedIndex = i;
				}
			}
		}
	}
}

//----------------------------------------------------------------------
//	Javascript Functionality for the Email form in:
//		emailformJS.asp
//
//	-patricia 12/05/06 
//----------------------------------------------------------------------

function ValidateEmailForm(sFormID)
{
	var isOK = true;
	var objForm = g_getRawObject(sFormID);
	
	if (objForm != null) {
	  with (objForm) {
		if (isOK && (Name.value.length < 2)) {
			alert("Please enter your Name.");
			Name.focus();
			isOK = false;
		}

		if (isOK && ! (EmailFrom.value.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1)) {
			alert("Please enter a valid Email Address.\n\r A valid email address should look like yourname@yourdomain.com");
			EmailFrom.focus();
			isOK = false;
		}

		if (isOK && (Message.value.length < 2)) {
			alert("Please enter a Message.");
			Message.focus();
			isOK = false;
		}

	  }
	}
	
	return isOK;
}

//----------------------------------------------------------------------
//	Javascript Functionality for the form in:
//		TellAFriend.asp
//
//	-scott 1/18/08
//----------------------------------------------------------------------

function funValidateSendPage(objForm)
{
	
	if (! (objForm.friend_1.value.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1)) {
		alert("Please enter a valid Friend Email Address.\n\r A valid email address should look like yourname@yourdomain.com");
		objForm.friend_1.focus();
		return false;
	}
	
	if (! (objForm.friend_2.value.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1) && objForm.friend_2.value.length>2) {
		alert("Please enter a valid Friend Email Address.\n\r A valid email address should look like yourname@yourdomain.com");
		objForm.friend_2.focus();
		return false;
	}
	
	if (! (objForm.friend_3.value.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1)&& objForm.friend_3.value.length>2) {
		alert("Please enter a valid Friend Email Address.\n\r A valid email address should look like yourname@yourdomain.com");
		objForm.friend_3.focus();
		return false;
	}

	if (objForm.your_name.value.length < 1) {
		alert("Please enter your name.");
		objForm.your_name.focus();
		return false;
	}
	
	if (! (objForm.your_email.value.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1)) {
		alert("Please enter a valid Email Address.\n\r A valid email address should look like yourname@yourdomain.com");
		objForm.your_email.focus();
		return false;
	}

	return true;
}



function fbs_click() {u=location.href;t=document.title;window.open('http://www.facebook.com/sharer.php?u='+encodeURIComponent(u)+'&t='+encodeURIComponent(t),'sharer','toolbar=0,status=0,width=626,height=436');return false;}

//----------------------------------------------------------------------
//	Javascript Functionality for the Region Switch
//
//	-scott 1/22/08
//----------------------------------------------------------------------

function funSetRegion(sRegion, e) {
	var sCurrentURL = document.location.href;
	document.location.href = "/SetRegion.asp?region=" + escape(sRegion) + "&Redirect=" + escape(sCurrentURL);
	return gfunCancelEvent(e);
}

//----------------------------------------------------------------------
//	Javascript Functionality for Now Playing
//
//	-scott 2/5/08
//----------------------------------------------------------------------

function funShowNowPlaying()
{
    var url = "/js/NowPlayingDisplay.aspx?tzc=8"; // gnTimeZoneCorrection = 8
    url += "&f=" + escape(region.now_playing_file);
    url += "&l=" + region.lid;
	url += "&sid=" + Math.random();
	var sMethod = "get";
	var sPostData = null;
	var aryHeaderData = null;
	var sFunctionName = "funGetNowPlayingResponse";
	var bDebug = false;
	var sErrorFunctionName = null;
  
    // Call the AJAX Call [from: gbinc/jsfiles/incJsLibraryMin.js]
	gfunSendRequest(url, sMethod, sPostData, aryHeaderData, sFunctionName, bDebug, sErrorFunctionName);

}

function funGetNowPlayingResponse(sText) {

	var nRefresh = 0;
	var nDefaultReloadSeconds = 180;
	var sTempText = "";
	var nHeaderLengthLimit = 27;
	var nOtherLengthLimit = 80;

    // Get all the span tags
	var arySpans = document.getElementsByTagName('span');
	for (var i=0; i<arySpans.length; i++) {
		var span = arySpans[i];
		// If they have a class of "RcsNowPlaying", then Update the Text
		if (span.className == "RcsNowPlaying") {
		    if (span.innerHTML != null) {
		        sTempText = sText;
		        if (sText.toLowerCase().indexOf("<a") > -1) {
                    // Trim for the Header Now Playing Area
                    var nPos = sText.indexOf(">",sText.toLowerCase().indexOf("<a"));
                    if (span.id == "header_now_playing" && (sText.indexOf("<",nPos) - nPos) > nHeaderLengthLimit) {
                        sTempText = sText.substring(0,nPos+nHeaderLengthLimit) + "..." + sText.substring(sText.indexOf("<",nPos),sText.length);
                    }
    		        else if (span.id == "on_air_dj" && (sText.indexOf("<",nPos) - nPos) > nOtherLengthLimit) {
                        sTempText = sText.substring(0,nPos+nOtherLengthLimit) + "..." + sText.substring(sText.indexOf("<",nPos),sText.length);
                    }
		        }
		        if (sTempText.length > 4) {
		            if (span.id == "on_air_dj") {
		                span.innerHTML = "<em>playing now:</em> " + sTempText;
		            }
		            else {
		                span.innerHTML = "<strong>Now playing</strong>: " + sTempText;
		            }
		        }      
		    }
		    else {
		        if (sTempText == "") {
		            // Massage the String a bit, removing the HTML
    		        sText = gfunTrimString(gfunStripTags(sText));
    		        sText = sText.substring(0,sText.lastIndexOf("\r"));
    		    }
		        sTempText = (span.id == "header_now_playing") ? sText.substring(0,nHeaderLengthLimit) : sText;
		        gfunDynamicTextUpdate(span, sTempText);
            }
            
	    }
	}
	
	if (document.getElementById("RcsNextInSeconds")) {
		nRefresh = document.getElementById("RcsNextInSeconds").innerText;
	}
	
	if (nRefresh == null || isNaN(nRefresh)) {
		nRefresh = nDefaultReloadSeconds;
	}
	else if (nRefresh <= 0 || nRefresh > nDefaultReloadSeconds) {
		nRefresh = nDefaultReloadSeconds;
	}

	//multiple by 1000 to convert to seconds
	nRefresh = (nRefresh*1000)
	
	setTimeout("funShowNowPlaying()", nRefresh);

} 

//call the function to initiate now playing:
funShowNowPlaying();

funShowNowPlayingMan();

funShowNowPlayingLondon();

function funShowNowPlayingMan()
{
    var url = "/js/NowPlayingDisplay.aspx?tzc=8"; // gnTimeZoneCorrection = 8
    url += "&f=" + escape('http://rope.ixfm.fimc.net/Feeds/NowPlaying/GCap_Media/XFM_Manchester/6365.xml');
    url += "&l=6365";
	url += "&sid=" + Math.random();
	var sMethod = "get";
	var sPostData = null;
	var aryHeaderData = null;
	var sFunctionName = "funGetNowPlayingResponseMan";
	var bDebug = false;
	var sErrorFunctionName = null;
  
    // Call the AJAX Call [from: gbinc/jsfiles/incJsLibraryMin.js]
	gfunSendRequest(url, sMethod, sPostData, aryHeaderData, sFunctionName, bDebug, sErrorFunctionName);

}

function funShowNowPlayingLondon()
{
    var url = "/js/NowPlayingDisplay.aspx?tzc=8"; // gnTimeZoneCorrection = 8
    url += "&f=" + escape('http://rope.ixfm.fimc.net/Feeds/NowPlaying/GCap_Media/XFM_London/5893.xml');
    url += "&l=5893";
	url += "&sid=" + Math.random();
	var sMethod = "get";
	var sPostData = null;
	var aryHeaderData = null;
	var sFunctionName = "funGetNowPlayingResponseLondon";
	var bDebug = false;
	var sErrorFunctionName = null;
  
    // Call the AJAX Call [from: gbinc/jsfiles/incJsLibraryMin.js]
	gfunSendRequest(url, sMethod, sPostData, aryHeaderData, sFunctionName, bDebug, sErrorFunctionName);

}

function funGetNowPlayingResponseMan(sText) {

	var nRefresh = 0;
	var nDefaultReloadSeconds = 180;
	var sTempText = "";
	var nHeaderLengthLimit = 27;
	var nOtherLengthLimit = 80;

    // Get all the span tags
	var arySpans = document.getElementsByTagName('span');
	for (var i=0; i<arySpans.length; i++) {
		var span = arySpans[i];
		// If they have a class of "RcsNowPlaying", then Update the Text
		if (span.className == "RcsNowPlayingMan") {
		    if (span.innerHTML != null) {
		        sTempText = sText;
		        if (sText.toLowerCase().indexOf("<a") > -1) {
                    // Trim for the Header Now Playing Area
                    var nPos = sText.indexOf(">",sText.toLowerCase().indexOf("<a"));
                    if (span.id == "header_now_playing" && (sText.indexOf("<",nPos) - nPos) > nHeaderLengthLimit) {
                        sTempText = sText.substring(0,nPos+nHeaderLengthLimit) + "..." + sText.substring(sText.indexOf("<",nPos),sText.length);
                    }
    		        else if (span.id == "on_air_dj" && (sText.indexOf("<",nPos) - nPos) > nOtherLengthLimit) {
                        sTempText = sText.substring(0,nPos+nOtherLengthLimit) + "..." + sText.substring(sText.indexOf("<",nPos),sText.length);
                    }
		        }
		        if (sTempText.length > 4) {
		            if (span.id == "on_air_dj") {
		                span.innerHTML = "<em>playing now:</em> " + sTempText;
		            }
		            else {
		                span.innerHTML = "<strong>Now playing</strong>: " + sTempText;
		            }
		        }      
		    }
		    else {
		        if (sTempText == "") {
		            // Massage the String a bit, removing the HTML
    		        sText = gfunTrimString(gfunStripTags(sText));
    		        sText = sText.substring(0,sText.lastIndexOf("\r"));
    		    }
		        sTempText = (span.id == "header_now_playing") ? sText.substring(0,nHeaderLengthLimit) : sText;
		        gfunDynamicTextUpdate(span, sTempText);
            }
            
	    }
	}
	
	if (document.getElementById("RcsNextInSeconds")) {
		nRefresh = document.getElementById("RcsNextInSeconds").innerText;
	}
	
	if (nRefresh == null || isNaN(nRefresh)) {
		nRefresh = nDefaultReloadSeconds;
	}
	else if (nRefresh <= 0 || nRefresh > nDefaultReloadSeconds) {
		nRefresh = nDefaultReloadSeconds;
	}

	//multiple by 1000 to convert to seconds
	nRefresh = (nRefresh*1000)
	
	setTimeout("funShowNowPlayingMan()", nRefresh);

} 


function funGetNowPlayingResponseLondon(sText) {

	var nRefresh = 0;
	var nDefaultReloadSeconds = 180;
	var sTempText = "";
	var nHeaderLengthLimit = 27;
	var nOtherLengthLimit = 80;

    // Get all the span tags
	var arySpans = document.getElementsByTagName('span');
	for (var i=0; i<arySpans.length; i++) {
		var span = arySpans[i];
		// If they have a class of "RcsNowPlaying", then Update the Text
		if (span.className == "RcsNowPlayingLondon") {
		    if (span.innerHTML != null) {
		        sTempText = sText;
		        if (sText.toLowerCase().indexOf("<a") > -1) {
                    // Trim for the Header Now Playing Area
                    var nPos = sText.indexOf(">",sText.toLowerCase().indexOf("<a"));
                    if (span.id == "header_now_playing" && (sText.indexOf("<",nPos) - nPos) > nHeaderLengthLimit) {
                        sTempText = sText.substring(0,nPos+nHeaderLengthLimit) + "..." + sText.substring(sText.indexOf("<",nPos),sText.length);
                    }
    		        else if (span.id == "on_air_dj" && (sText.indexOf("<",nPos) - nPos) > nOtherLengthLimit) {
                        sTempText = sText.substring(0,nPos+nOtherLengthLimit) + "..." + sText.substring(sText.indexOf("<",nPos),sText.length);
                    }
		        }
		        if (sTempText.length > 4) {
		            if (span.id == "on_air_dj") {
		                span.innerHTML = "<em>playing now:</em> " + sTempText;
		            }
		            else {
		                span.innerHTML = "<strong>Now playing</strong>: " + sTempText;
		            }
		        }      
		    }
		    else {
		        if (sTempText == "") {
		            // Massage the String a bit, removing the HTML
    		        sText = gfunTrimString(gfunStripTags(sText));
    		        sText = sText.substring(0,sText.lastIndexOf("\r"));
    		    }
		        sTempText = (span.id == "header_now_playing") ? sText.substring(0,nHeaderLengthLimit) : sText;
		        gfunDynamicTextUpdate(span, sTempText);
            }
            
	    }
	}
	
	if (document.getElementById("RcsNextInSeconds")) {
		nRefresh = document.getElementById("RcsNextInSeconds").innerText;
	}
	
	if (nRefresh == null || isNaN(nRefresh)) {
		nRefresh = nDefaultReloadSeconds;
	}
	else if (nRefresh <= 0 || nRefresh > nDefaultReloadSeconds) {
		nRefresh = nDefaultReloadSeconds;
	}

	//multiple by 1000 to convert to seconds
	nRefresh = (nRefresh*1000)
	
	setTimeout("funShowNowPlayingLondon()", nRefresh);

} 
