<!--
// (c) 2008-10 widget
//<![CDATA[


var NeedFPVersion="9";

function checkFlashPlayer() {
	var hasFlash=0;
	var flashVersion=0;
	var isIE=/*@cc_on!@*/0;
	
	if(isIE) {
		var swf = new ActiveXObject('ShockwaveFlash.ShockwaveFlash');
		if(swf) {
			hasFlash=1;
			VSwf=swf.GetVariable("$version");
			flashVersion=VSwf.split(" ")[1];
		}
	} else {
		if (navigator.plugins && navigator.plugins.length > 0) {
			var swf=navigator.plugins["Shockwave Flash"];
		    if (swf) {
		    	hasFlash=1;
		        var words = swf.description.split(" ");
		        for (var i = 0; i < words.length; ++i) {
		            if (isNaN(parseInt(words[i]))) continue;
		            flashVersion = words[i];
		        }
		    }
		}
	}
	
	//alert(flashVersion);
	//return {f:hasFlash,v:flashVersion};
	var msg;
	if(!hasFlash) {
		msg = "Oops!  Cannot find an installed Adobe Flash control.  If you have recently \n" +
		"installed Flash, try closing all browser windows and re-launching the station.\n\n";
		msg +=	"Click OK to return to the Player Selection page to select a \n" +
		"different player or look for the Upgrade Now link to download \n" +
		"the latest version of Flash from Adobe."
		alert(msg);
	}else {
		while(flashVersion.indexOf(",")>0) {
			flashVersion=flashVersion.replace(",",".");
		}
		if (VersionLessThan(flashVersion, NeedFPVersion)) {
			msg = "Oops!  You are running Flash version " + flashVersion + ", but Live365 \n" +
			"requires a more recent version of the Flash control to listen.\n\n";
			msg +=	"Click OK to return to the Player Selection page to select a \n" +
			"different player or look for the Upgrade Now link to download \n" +
			"the latest version of Flash from Adobe."
			alert(msg);
		}
	}
}


function VersionLessThan(target, source, bPlayer365) {
	var Tararr = target.split(/[\.\,]/g);
	var Srcarr = source.split(/[\.\,]/g);
	var imax = Math.min(Tararr.length, Srcarr.length);
	var i = 0;
	
	for (i = 0; i < imax; i++) {
		if (bPlayer365 && i == 2)
			continue;			//skip the MP3Pro identifier (the 3rd number in the 4 value Version string.)

		if (parseInt(Tararr[i]) < parseInt(Srcarr[i]))
			return true;
		else if (parseInt(Tararr[i]) > parseInt(Srcarr[i]))
			return false;
	}

	return false;
}


checkFlashPlayer();



//widget param
var userName;
var webMode;

var proAdsOption;
var startPageOption;
var autoPlayOption;
var styleOption;
var purchaseOption;

var myspaceButton;
var linkButton;
//

function initWidgetConfigOptions() {
	proAdsOption = document.getElementById("setProAds");
	
	proAdsOption.innerHTML="";
	proAdsOption.style.display="none";
	
	startPageOption.innerHTML="";
	startPageOption.style.display="none";
	//
	autoPlayOption.innerHTML="";
	autoPlayOption.style.display="none";
	//
	styleOption.innerHTML="";
	styleOption.style.display="none";
	//
	purchaseOption.innerHTML="";
	purchaseOption.style.display="none";
	//
	jsReady=true;
}

function setWidgetOptions(sCount, authList, isIncluderStation, isShareRevenue) {
	//
	if(sCount==1 && authList && isIncluderStation && isShareRevenue) {
		if(proAdsOption.innerHTML=="") {
			proAdsOption.innerHTML=
				'<div class="SubHead">Ad-Free/Ad-Full Stream</div>'+
				'<input type="radio" name="proAdsOp" value="0" onclick="selProAds(this.value);">Without Ads'+
				'&nbsp;&nbsp;&nbsp;&nbsp;'+
				'<input type="radio" name="proAdsOp" value="1" onclick="selProAds(this.value);" checked="checked" >With Ads, Pro Points Rewards'+
				'<input type="hidden" id="proAds" value="0" >'
			;
			proAdsOption.style.display="";
		}
	} else {
		proAdsOption.innerHTML="";
		proAdsOption.style.display="none";
	}
	//
	if(sCount==1) {
		if(startPageOption.innerHTML=="") {
			startPageOption.innerHTML=
			'<div class="SubHead">Default View</div>'+
			'<div>(for widgets displaying a single station only)</div>'+
				'<input type="radio" name="startPg" value="3" checked="checked" onclick="selStartPage(this.value);">Now Playing'+
				'&nbsp;&nbsp;&nbsp;&nbsp;'+
				'<input type="radio" name="startPg" value="4" onclick="selStartPage(this.value);">Station Info'+
				'<input type="hidden" id="startPage" value="3" >'
			;
			startPageOption.style.display="";
		}
	} else {
		startPageOption.innerHTML="";
		startPageOption.style.display="none";
	}
	//
	if(sCount==1 && authList && isIncluderStation) {
		if(autoPlayOption.innerHTML=="") {
			autoPlayOption.innerHTML=
			'<div class="SubHead">Auto-Play When Page Loads</div>'+
				'<input type="radio" name="autoPly" value="0" checked="checked" onclick="selAutoPlay(this.value);">No, let listener hit play'+
				'&nbsp;&nbsp;&nbsp;&nbsp;'+
				'<input type="radio" name="autoPly" value="1" onclick="selAutoPlay(this.value);">Yes, auto-play station'+
				'<input type="hidden" id="autoPlay" value="0" >'
			;
			autoPlayOption.style.display="";
		}
	} else {
		autoPlayOption.innerHTML="";
		autoPlayOption.style.display="none";
	}
	//
	if(authList && isIncluderStation) {
		if(styleOption.innerHTML=="") {
			styleOption.innerHTML=
			'<div class="SubHead">Footer Selection</div>'+
				'<input type="radio" name="wdgtStyle" value="1" checked="checked" onclick="selWidgetStyle(this.value);">Default'+
				'&nbsp;&nbsp;&nbsp;&nbsp;'+
				'<input type="radio" name="wdgtStyle" value="2" onclick="selWidgetStyle(this.value);">Powered by Live365'+
				'<input type="hidden" id="widgetStyle" value="1" >'
			;
			styleOption.style.display="";
		}
	} else {
		styleOption.innerHTML="";
		styleOption.style.display="none";
	}
	//
	if(authList && isIncluderStation) {
		if(purchaseOption.innerHTML=="") {
			purchaseOption.innerHTML=
			'<div class="SubHead">Purchasing Cart Options</div>'+
				'<input type="radio" name="wdgtPchase" value="1" checked="checked" onclick="selWidgetPurchase(this.value);">Show'+
				'&nbsp;&nbsp;&nbsp;&nbsp;'+
				'<input type="radio" name="wdgtPchase" value="2" onclick="selWidgetPurchase(this.value);">Hide'+
				'<input type="hidden" id="widgetPurchase" value="1" >'
			;
			purchaseOption.style.display="";
		}
	} else {
		purchaseOption.innerHTML="";
		purchaseOption.style.display="none";
	}
	//
	if(authList && isIncluderStation) {
		if(myspaceButton!=null) {
			myspaceButton.style.display="";
		}
	} else {
		if(myspaceButton!=null) {
			myspaceButton.style.display="none";
		}
	}
	//
	if(authList && isIncluderStation) {
		if(linkButton!=null) {
			linkButton.style.display="";
		}
	} else {
		if(linkButton!=null) {
			linkButton.style.display="none";
		}
	}
}








function widgetJSReady() {
	return true;
}


function launchLive365Window(tagetUrl, windowName, windowWidth, windowHeight, windowTop, isDebug) {
	var live365Win;
	
	windowWidth=windowWidth==null?400:windowWidth;
	windowHeight=windowHeight==null?300:windowHeight;
	windowTop=windowTop==null?80:windowTop;
	//live365Win=window.open( tagetUrl,windowName,"directories=no, width="+windowWidth+", height="+windowHeight+", top="+windowTop+", scrollbars="+(isDebug?"yes":"no") );
	if(isDebug) {
		live365Win=window.open( tagetUrl,windowName, "resizable=yes, toolbar=yes, menubar=yes, location=yes, status=yes, width="+windowWidth+", height="+windowHeight+", top="+windowTop+", scrollbars=yes" );
	} else {
		live365Win=window.open( tagetUrl,windowName, "resizable=no, toolbar=no, menubar=no, location=no, status=no, width="+windowWidth+", height="+windowHeight+", top="+windowTop+", scrollbars=no" );
	}
	try {
		live365Win.focus();
		if (live365Win.document.documentElement && live365Win.document.documentElement.scrollLeft) {         
			live365Win.document.documentElement.scrollLeft = 0;
		} else if (live365Win.document.body) {
			live365Win.document.body.scrollLeft = 0;
		}
	} catch (err) {
		//
	}
	if(live365Win==null) {
		return false;
	} else {
		return true;
	}
}



function launchLive365Page(tagetUrl, windowName) {
	var live365Win=window.open(tagetUrl,windowName);
	live365Win.focus();
	return true;
}

//setDomain();

function setDomain() {
	var tDomains=window.location.hostname.split(".");
	if(tDomains.length==3) {
		document.domain=tDomains[1]+"."+tDomains[2];
	} else if (tDomains.length>3) {
		if(isNaN(tDomains[2]) && isNaN(tDomains[3])) {
			document.domain=tDomains[1]+"."+tDomains[2]+"."+tDomains[3];
		} else {
			document.domain=tDomains[0]+"."+tDomains[1]+"."+tDomains[2]+"."+tDomains[3];
		}
	}
	//alert(document.domain);
}

////////////////////////////////////
///////////////////////////////////


/**
 * encode '&', '#' and other lettle
*/			
function htmlEnCode(srcString) {
	var result=srcString;
	while(result.indexOf("&")>=0) {
		result=result.replace("&","/AscII038");
	}
	while(result.indexOf("#")>=0) {
		result=result.replace("#","/AscII035");
	}
	return result;
}

/**
 * if flash is not ready, alert user
*/
var asReady=true;

function AsIsNotReady(rJsValue) {
	alert("Widget is busy, wait a moment!");
	if(rJsValue!=null) {
		var jsParams=rJsValue.split("&");
		var jsParamsValue;
		try {
			for(var i=0;i<jsParams.length;i++) {
				if (jsParams[i].indexOf("mainColor=")>=0) {
					document.getElementById("mainColor").value=getParamsValue(jsParams[i]);
				} else if (jsParams[i].indexOf("a=")>=0) {
					jsParamsValue=getParamsValue(jsParams[i]);
					if(jsParamsValue==null || jsParamsValue=="") {
						jsParamsValue="1";
					}
					var tspg=document.getElementsByName("proAdsOp");
					for(var j=0;j<tspg.length;j++) {
						if(tspg[j].value==jsParamsValue) {
							tspg[j].checked=true;
							break;
						}
					}
					document.getElementById("proAds").value=jsParamsValue;
				} else if (jsParams[i].indexOf("startPage=")>=0) {
					jsParamsValue=getParamsValue(jsParams[i]);
					if(jsParamsValue==null || jsParamsValue=="") {
						jsParamsValue="3";
					}
					var tspg=document.getElementsByName("startPg");
					for(var j=0;j<tspg.length;j++) {
						if(tspg[j].value==jsParamsValue) {
							tspg[j].checked=true;
							break;
						}
					}
					document.getElementById("startPage").value=jsParamsValue;
				} else if (jsParams[i].indexOf("txtColor=")>=0) {
					document.getElementById("txtColor").value=getParamsValue(jsParams[i]);
				} else if (jsParams[i].indexOf("bgPic=")>=0) {
					document.getElementById("bgPic").value=getParamsValue(jsParams[i]);
				} else if (jsParams[i].indexOf("autoPlay=")>=0) {
					jsParamsValue=getParamsValue(jsParams[i]);
					if(jsParamsValue==null || jsParamsValue=="") {
						jsParamsValue="0";
					}
					var tspg=document.getElementsByName("autoPly");
					for(var j=0;j<tspg.length;j++) {
						if(tspg[j].value==jsParamsValue) {
							tspg[j].checked=true;
							break;
						}
					}
					document.getElementById("autoPlay").value=jsParamsValue;
				} else if (jsParams[i].indexOf("style=")>=0) {
					jsParamsValue=getParamsValue(jsParams[i]);
					if(jsParamsValue==null || jsParamsValue=="") {
						jsParamsValue="1";
					}
					var tspg=document.getElementsByName("wdgtStyle");
					for(var j=0;j<tspg.length;j++) {
						if(tspg[j].value==jsParamsValue) {
							tspg[j].checked=true;
							break;
						}
					}
					document.getElementById("widgetStyle").value=jsParamsValue;
				} else if (jsParams[i].indexOf("transparent=")>=0) {
					if(getParamsValue(jsParams[i])=="1") {
						document.getElementById("trans").checked=true;
					} else {
						document.getElementById("trans").checked=false;
					}
				} else if (jsParams[i].indexOf("hasPurchase=")>=0) {
					jsParamsValue=getParamsValue(jsParams[i]);
					if(jsParamsValue==null || jsParamsValue=="") {
						jsParamsValue="1";
					}
					var tspg=document.getElementsByName("wdgtPchase");
					for(var j=0;j<tspg.length;j++) {
						if(tspg[j].value==jsParamsValue) {
							tspg[j].checked=true;
							break;
						}
					}
					document.getElementById("widgetPurchase").value=jsParamsValue;
				}
			
			}
		}catch(e) {
			//alert(e);
		}
	
	}	
}

function getParamsValue(params) {
	var tPs=params.split("=");
	if(tPs!=null && tPs.length==2 && tPs[1]!=null && tPs[1]!="null") {
		return tPs[1];
	}
	return "";
}


function noImageAlert(isAlert) {
	alert("The background that you entered cannot be found!");
	document.getElementById("bgPic").focus();
	document.getElementById("bgPic").select();
}


var jsReady=false;
//test page load complete
function isReady() {
	return jsReady;
}

function thisMovie(movieName) {
	//alert(navigator.appName.indexOf("Microsoft") >= 0);
	try {
		if (navigator.appName.indexOf("Microsoft") >= 0) {
	 		//alert(document.getElementById(movieName));
			return document.getElementById(movieName);
		} else {
			//alert(document[movieName]);
			return document[movieName];
		}
	} catch (e) {
		//alert(e);
		return null;
	}
}
/*
function hidColor() {
	document.getElementById("setMainColor").style.height="25px";
}

function showColor() {
	document.getElementById("setMainColor").style.height="";
}
*/

function setColor(Tcolor){
	try {
		var ctype=document.getElementById("colorType").value;
		if(ctype=="mainColor") {
			
			if(document.getElementById('trans').checked) {
				alert('"Transparent widget background" is checkmarked in "Background Options". \n Unmark that option if you wish to use a custom Background Color.');
				document.getElementById("setMainColor").style.display="none";
			} else {
				document.getElementById("mainColor").value="0x"+Tcolor;
				//alert(document.getElementById("mianColor").value);
				thisMovie("live365Player").jsValue("mainColor=0x"+Tcolor);
			}
		} else {
			document.getElementById("txtColor").value="0x"+Tcolor;
			//alert(document.getElementById("txtColor").value);
			thisMovie("live365Player").jsValue("txtColor=0x"+Tcolor);
		}
	} catch (e) {
		if(jsReady && thisMovie("live365Player")!=null && thisMovie("live365Player").jsValue!=null) {
			alert("Please check widget version!");
		} else {
			alert("Wait a moment, the page is not finished loading!");
		}
	}
}

	
//set background picture
function setBGPic() {
	try {
		var bgPic=document.getElementById("bgPic").value;
		if(bgPic!="" && bgPic!="http://") {
			thisMovie("live365Player").jsValue("bgPic="+htmlEnCode(bgPic));
		}
	} catch (e) {
		if(jsReady && thisMovie("live365Player")!=null && thisMovie("live365Player").jsValue!=null)
			alert("Please check widget version!");
		else
			alert("Wait a moment, the page is not finished loading!");
	}
}

function clearBGPic() {
	try {
		thisMovie("live365Player").jsValue("bgPic=");
		document.getElementById("bgPic").value="http://";
	} catch (e) {
		if(jsReady && thisMovie("live365Player")!=null && thisMovie("live365Player").jsValue!=null)
			alert("Please check widget version!");
		else
			alert("Wait a moment, the page is not finished loading!");
	}
}


function setWidgetMainColor(enable) {
	var ctype=document.getElementById("colorType").value;
	if(!enable) {
		document.getElementById("mainColorSetButton").className = "disabledA";
		document.getElementById("mainColorSetButton").removeAttribute("href");
		if(ctype=="mainColor") {
			document.getElementById("setMainColor").style.display="none";
		}
	} else {
		document.getElementById("mainColorSetButton").className = "";
		document.getElementById("mainColorSetButton").href="javascript:initColor('mainColor');";
		if(ctype=="mainColor") {
			document.getElementById("setMainColor").style.display="";
		}
	}
}

function selProAds(proAdsOpt) {
	try {
		//chkCheckbox("startPg",sPage);
		document.getElementById("proAds").value = proAdsOpt;
		thisMovie("live365Player").jsValue("a=" + proAdsOpt);
	} catch (e) {
		if(jsReady && thisMovie("live365Player")!=null && thisMovie("live365Player").jsValue!=null)
			alert("Please check widget version!");
		else
			alert("Wait a moment, the page is not finished loading!");
	}
}

//color select button event
function initColor(btSetColor) {
	if(btSetColor=="mainColor") {
		if(document.getElementById('trans').checked) {
			//alert('"Transparent widget background" is checkmarked in "Background Options". \n Unmark that option if you wish to use a custom Background Color.');
			//document.getElementById("setMainColor").style.display="none";
		} else {
			document.getElementById("innerMainColor").style.width="0";
			document.getElementById("setMainColor").style.display="";
			document.getElementById("colorType").value=btSetColor;
			thisMovie("setHtmlBackColor").jsValue();
		}
	} else if (btSetColor=="txtColor") {
		document.getElementById("innerMainColor").style.width="140px";
		document.getElementById("setMainColor").style.display="";
		document.getElementById("colorType").value=btSetColor;
		if(thisMovie("setHtmlBackColor").jsValue)
			thisMovie("setHtmlBackColor").jsValue();
	}
}


function selectAllStation () {
	var statCol=document.getElementById("stationControl");
	statCol.checked=true;
	checkAllStation(statCol);
}

function clearAllStation() {
	var statCol=document.getElementById("stationControl");
	statCol.checked=false;
	checkAllStation(statCol);
}



//set stations to widget


function setGenre(tGenre) {
	thisMovie("live365Player").jsValue("genre="+tGenre);
}


function transWidget(isTrans) {
	try {
		if(isTrans) {
			thisMovie("live365Player").jsValue("transparent=1");
			setWidgetMainColor(false);
		} else {
			thisMovie("live365Player").jsValue("transparent=0");
			setWidgetMainColor(true);
		}
	} catch (e) {
		if(jsReady && thisMovie("live365Player")!=null && thisMovie("live365Player").jsValue!=null)
			alert("Please check widget version!");
		else
			alert("Wait a moment, the page is not finished loading!");
	}
}



//util function
function chkCheckbox(chkName,chkValue) {
	var tSP=document.getElementsByName(chkName);
	var testAllUncheck=true;
	var suitChk=0;
	for(var i=0;i<tSP.length;i++) {
		if(tSP[i].value!=chkValue) {
			tSP[i].checked=false;
		} else {
			suitChk=i;
		}
		if(tSP[i].checked) {
			testAllUncheck=false;
		}
	}
	//alert(testAllUncheck);
	if(testAllUncheck) {
		tSP[suitChk].checked=true;
	}
}

//
function selStartPage(sPage) {
	try {
		//chkCheckbox("startPg",sPage);
		document.getElementById("startPage").value=sPage;
		thisMovie("live365Player").jsValue("startPage="+sPage);
	} catch (e) {
		if(jsReady && thisMovie("live365Player")!=null && thisMovie("live365Player").jsValue!=null)
			alert("Please check widget version!");
		else
			alert("Wait a moment, the page is not finished loading!");
	}
}

function selAutoPlay(aPly) {
	try {
		document.getElementById("autoPlay").value=aPly;
		thisMovie("live365Player").jsValue("autoPlay="+aPly+"&startPage="+document.getElementById("startPage").value);
	} catch (e) {
		if(jsReady && thisMovie("live365Player")!=null && thisMovie("live365Player").jsValue!=null)
			alert("Please check widget version!");
		else
			alert("Wait a moment, the page is not finished loading!");
	}
}

function selWidgetStyle(wStyle) {
	try {
		//chkCheckbox("wdgtStyle",wStyle);
		document.getElementById("widgetStyle").value=wStyle;
		//alert(wStyle);
		thisMovie("live365Player").jsValue("style="+wStyle);
	} catch (e) {
		if(jsReady && thisMovie("live365Player")!=null && thisMovie("live365Player").jsValue!=null)
			alert("Please check widget version!");
		else
			alert("Wait a moment, the page is not finished loading!");
	}
}

function selWidgetPurchase(prch) {
	try {
		document.getElementById("widgetPurchase").value=prch;
		thisMovie("live365Player").jsValue("hasPurchase="+prch);
	} catch (e) {
		if(jsReady && thisMovie("live365Player")!=null && thisMovie("live365Player").jsValue!=null)
			alert("Please check widget version!");
		else
			alert("Wait a moment, the page is not finished loading!");
	}
}


function showBlogCode() {
	return showCode(220,293);
}



function selectAllCode() {
	document.getElementById("codeShow").select();
}

function clearAllCode() {
	document.getElementById("codeShow").value="";
}

function showWidgetCode(code) {
	document.getElementById("codeShow").value = code;
}


//



var EXCUTE_GET_HTMLCODE = "excute_get_htmlcode";
var EXCUTE_GET_FACEBOOKCODE = "excute_get_facebookcode";
var EXCUTE_GET_POPUPLINKCODE = "excute_get_popuplinkcode";
var EXCUTE_GET_MYSPACECODE = "excute_get_myspacecode";

function showCode(tWidth, tHeight, codeType) {
	thisMovie("live365Player").jsValue("cmd=" + EXCUTE_GET_HTMLCODE);
}

function showFaceBookCode() {
	thisMovie("live365Player").jsValue("cmd=" + EXCUTE_GET_FACEBOOKCODE);
}

function showLink() {
	thisMovie("live365Player").jsValue("cmd=" + EXCUTE_GET_POPUPLINKCODE);
}

function showMyspaceCode() {
	thisMovie("live365Player").jsValue("cmd=" + EXCUTE_GET_MYSPACECODE);
}




//]]>
// -->
