var callPlayerSuccessURL = location.href;
callPlayerSuccessURL = escape(callPlayerSuccessURL);

function openWin(sURL, sWindowName, w, h, sScroll)
{
	// ex)
	//			openWin("test.asp", "winTest", 400, 300);
	//			openWin("test.asp", "winTest", 400, 300, "yes");
	//			openWin("test.asp", "winTest", 400, 300, "auto");

	var x = (screen.width - w) / 2;
	var y = (screen.height - h) / 2;

	if (sScroll==null) sScroll = "no";

	var sOption = "";
	sOption = sOption + "toolbar=no,channelmode=no,location=no,directories=no,resizable=no,menubar=no";
	sOption = sOption + ",scrollbars=" + sScroll + ",left=" + x + ",top=" + y + ",width=" + w + ",height=" + h;

	var win = window.open(sURL, sWindowName, sOption);
	return win;
}

function openWinFreePos(sURL, sWindowName, w, h, x, y, sScroll)
{
	// ex)
	//			openWin("test.asp", "winTest", 400, 300, 0, 0);
	//			openWin("test.asp", "winTest", 400, 300, 0, 0 "yes");
	//			openWin("test.asp", "winTest", 400, 300, 0, 0 "auto");

	if (sScroll==null) sScroll = "no";

	var sOption = "";
	sOption = sOption + "toolbar=no,channelmode=no,location=no,directories=no,resizable=no,menubar=no";
	sOption = sOption + ",scrollbars=" + sScroll + ",left=" + x + ",top=" + y + ",width=" + w + ",height=" + h;

	var win = window.open(sURL, sWindowName, sOption);
	return win;
}

function prelisten(pid, producttitle) {
	if (pid == null || pid == "") { return; }
	producttitle = encodeURIComponent(producttitle);
	openWin("/music/pplayer/loadPlayer.jsp?productid=" + pid + "&producttitle="+producttitle, "winprelisten", 240, 170, "no");
}

function popdetail(pid) {
	openWin('/music/site/product/productdetails.jsp?pid='+pid,'ProductDetails',500,500,'yes');
}

function setCookie(name, value, expires, path, domain, secure) {
  var nextyear = new Date();
  nextyear.setFullYear(nextyear.getFullYear() +1);
  var curCookie = name + "=" + escape(value) +
      ((expires) ? "; expires=" + expires.toGMTString() : "") +
      //((path) ? "; path=" + path : "") +
      "; path=/music" + 
      ((domain) ? "; domain=" + domain : "") +
      ((secure) ? "; secure" : "");
  document.cookie = curCookie;
}

function getCookie(name) {
  var dc = document.cookie;
  var prefix = name + "=";
  var begin = dc.indexOf("; " + prefix);
  if (begin == -1) {
    begin = dc.indexOf(prefix);
    if (begin != 0) return null;
  } else
    begin += 2;
  var end = document.cookie.indexOf(";", begin);
  if (end == -1)
    end = dc.length;
  return unescape(dc.substring(begin + prefix.length, end));
}

function deleteCookie(name, path, domain) {
  if (getCookie(name)) {
    document.cookie = name + "=" +
    //((path) ? "; path=" + path : "") +
    "; path=/music" +
    ((domain) ? "; domain=" + domain : "") +
    "; expires=Thu, 01-Jan-70 00:00:01 GMT";
  }
}

function popPlaylist(productid,producttitle,artist,producttype,productlength,albumid) {
	if (document.all) {
		var posx = event.clientX;
		var posy = event.clientY+document.body.scrollTop;
	}
	else {
		//document.captureEvents(Event.CLICK | Event.MOUSEDOWN | Event.MOUSEMOVE | Event.MOUSEUP);
		var posx = 400;
		var posx = 400;	
	}
	document.PlaylistForm.productid.value=productid;
	document.PlaylistForm.producttitle.value=producttitle;
	document.PlaylistForm.artist.value=artist;
	document.PlaylistForm.producttype.value=producttype;
	document.PlaylistForm.productlength.value=productlength;
	document.PlaylistForm.albumid.value=albumid;		

	hidden_ipf.location.href="/music/site/common/addtoplaylist_check.jsp?productid="+productid+"&producttitle="+producttitle+"&artist="+artist+"&producttype="+producttype+"&productlength="+productlength+"&albumid="+albumid+"&posx="+posx+"&posy="+posy;
	// openWin("/music/site/common/addtoplaylist.jsp?productid="+productid+"&producttitle="+producttitle+"&artist="+artist+"&producttype="+producttype+"&productlength="+productlength+"&albumid="+albumid,"Addtoplaylist",500,300,"yes");
	return;
}

function popPlaylist2(productid) {
	if (document.all) {
		var posx = event.clientX;
		var posy = event.clientY+document.body.scrollTop;
	}
	else {
		//document.captureEvents(Event.CLICK | Event.MOUSEDOWN | Event.MOUSEMOVE | Event.MOUSEUP);
		var posx = 400;
		var posx = 400;	
	}
	document.PlaylistForm.productid.value=productid;
	document.PlaylistForm.producttitle.value="";
	document.PlaylistForm.artist.value="";
	document.PlaylistForm.producttype.value="";
	document.PlaylistForm.productlength.value="";
	document.PlaylistForm.albumid.value="";

	hidden_ipf.location.href="/music/site/common/addtoplaylist_check.jsp?productid="+productid+"&posx="+posx+"&posy="+posy;
	// openWin("/music/site/common/addtoplaylist.jsp?productid="+productid+"&producttitle="+producttitle+"&artist="+artist+"&producttype="+producttype+"&productlength="+productlength+"&albumid="+albumid,"Addtoplaylist",500,300,"yes");
	return;
}

function addtonewplaylist(playlistname) {
	if (playlistname==null || playlistname=="") {
		alert("請輸入playlist名稱");
		return;
	} else {
		document.PlaylistForm.playlistid.value = "";
		document.PlaylistForm.playlistname.value = playlistname;
		document.PlaylistForm.submit();
	}
}	

function addtoplaylist(playlistid) {
	if (playlistid==null || playlistid=="") {
		alert("請先選擇playlist");
		return;
	} else {
		document.PlaylistForm.playlistname.value = "";
		document.PlaylistForm.playlistid.value = playlistid;
		document.PlaylistForm.submit();
	}
}

function instantplay(pid) {
	document.instantplayForm.instantplay.value=pid;
	document.instantplayForm.oriURL.value=callPlayerSuccessURL;
	document.instantplayForm.submit();
}

function playall(index,playallid,arrayname) {
	var instantplayids = "";
	var playallArray = eval(arrayname.concat(index));
	if (playallArray) {
		if (playallArray.length>0) {
			for (var i=0; i<playallArray.length;i++) {
				if (i==playallArray.length-1) {
					instantplayids += playallArray[i];
				} else {
					instantplayids += playallArray[i] + ",";
				}
			}
			document.instantplayForm.instantplay.value=instantplayids;
			document.instantplayForm.playallid.value=playallid;
			document.instantplayForm.oriURL.value=callPlayerSuccessURL;			
			document.instantplayForm.submit();		
		}
	}
}

function playall2(playallid,productids) {
	document.instantplayForm.instantplay.value=productids;
	document.instantplayForm.playallid.value=playallid;
	document.instantplayForm.oriURL.value=callPlayerSuccessURL;
	document.instantplayForm.submit();
}

function MM_findObj(n, d) { //v4.0
  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 && document.getElementById) x=document.getElementById(n); return x;
}

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 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_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 showPopup(posx,posy) {
	if (document.getElementById('popup')) {
		var H=(document.layers)?window.innerHeight:window.document.body.clientHeight;
		var W=(document.layers)?window.innerWidth:window.document.body.clientWidth;
	
		var obj = document.getElementById('popup');
		if ((obj.style.pixelWidth + posx) > W)
			posx = W - obj.style.pixelWidth;

		if ((obj.style.pixelHeight + posy) > H+document.body.scrollTop)
			posy = H+document.body.scrollTop - obj.style.pixelHeight;

		document.getElementById('popup').style.left = posx;
		document.getElementById('popup').style.top  = posy;	
		document.getElementById('popup').style.visibility="visible";
	}
}

function hidePopup() {
	if (document.getElementById('popup'))
		document.getElementById('popup').style.visibility="hidden";
}

function changURL(loc){
	if (loc != "_") window.location = loc;
}

function goToLive()
{
	document.location.href="http://facup.netvigator.com/sports/facup/index.jsp";
}

function goToVOD()
{
	document.location.href="http://facup.netvigator.com/sports/facup/index_VOD.jsp";
}

function goToSignUp()
{
	document.location.href="http://facup.netvigator.com/sports/static/facup/sign_up.jsp";
}

function goToFAQ()
{
	document.location.href="http://facup.netvigator.com/sports/static/facup/cs_faq.jsp";
}

function goToMyAccount()
{
	document.location.href="http://facup.netvigator.com/sports/facup/site/myaccount/facup_plan.jsp";
}

function goToSchedule()
{
	document.location.href="http://facup.netvigator.com/sports/static/facup/programme_schedule.jsp";
}

function openSchedule()
{
	// openWin("http://facup.netvigator.com/sports/static/facup/iplayer/programme_schedule.jsp", "psch", 200, 200, "yes");
	window.open("http://facup.netvigator.com/sports/facup/index.jsp", "progsch");
}
