var callPlayerSuccessURL = location.href;
callPlayerSuccessURL = escape(callPlayerSuccessURL);
var searchPosted = false;



function openWin(sURL, sWindowName, w, h, sScroll)
{
	// ex)
	//			openWin("test.asp", "wGinTest", 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,artistid,artist,albumid) {
	if (pid == null || pid == "") { return; }
	//producttitle = encodeURIComponent(producttitle);
	
	//---orginal
	//openWin("/music/pplayer/loadPlayer.jsp?productid=" + pid + "&producttitle="+producttitle, "winprelisten", 240, 170, "no");
	
	//---preview player of MOOV
	//if (navigator.userAgent.match("MSIE")) {
	//	parent.document.frames["PlayerFrame"].location.href = '/music/pplayer/loadPlayer.jsp?productid='+pid+'&producttitle='+producttitle;
	//} else {
	//	parent.window.PlayerFrame.location.href = '/music/pplayer/loadPlayer.jsp?productid='+pid+'&producttitle='+producttitle;
	//}
	//---preview player of Facebook
	if (navigator.userAgent.match("MSIE")) {
		parent.document.frames["PlayerFrame"].addPlayItem(pid,producttitle,null,artistid,artist,albumid);
	} else {
		parent.window.frames["PlayerFrame"].addPlayItem(pid,producttitle,null,artistid,artist,albumid);
	}
	//parent.document.getElementById("muplayer").style.height="340px";
	parent.document.getElementById("PlayerFrame").style.display="";
	parent.player = 1;
	
}

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 saveall(arrayname, index, playlistname, saveallid) {
	var productids = "";
	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) {
					productids += playallArray[i];
				} else {
					productids += playallArray[i] + ",";
				}
			}
			saveAllPopPlaylist(playlistname, productids, saveallid);
		}
	}
}


function previewall (arrayname, previewallid) {
	var playallArray = eval(arrayname);
	previewAllPlaylist(playallArray, previewallid);
}

function previewAllPlaylist(productids, previewallid) {
	//if (navigator.userAgent.match("MSIE")) {
	//	parent.document.frames["PlayerFrame"].newPlayList(productids,productids);
	//} else {
	//	parent.window.frames["PlayerFrame"].newPlayList(productids,productids);
	//}
	document.PreviewAllForm.productids.value=productids.toString();
	if (previewallid) {
		document.PreviewAllForm.previewallid.value=previewallid;
	}
	document.PreviewAllForm.submit();
	
}

function saveall2(productids, playlistname, saveallid) {
	saveAllPopPlaylist(playlistname, productids, saveallid);
}

function previewall2 (productids, previewallid) {
	playallArray = productids.split(",");
	previewAllPlaylist(playallArray, previewallid);
}


function saveall3(productids, playlistname, saveallid) {
	saveAllPopPlaylist3(playlistname, productids, saveallid);
}

function saveAllPopPlaylist3(playlistname,productids, saveallid) {
	var posx = 400;
	var posy = 400;
	document.SaveAllForm.productids.value=productids;
	// document.SaveAllForm.playlistname.value=playlistname;
	var url = "/music/site/common/savealltoplaylist_check.jsp?playlistname="+encodeURIComponent(playlistname)+"&posx="+posx+"&posy="+posy+"&saveallid="+saveallid+"&productids="+productids;
	hidden_ipf.location.href=url;
	// openWin("/music/site/common/addtoplaylist.jsp?productid="+productid+"&producttitle="+producttitle+"&artist="+artist+"&producttype="+producttype+"&productlength="+productlength+"&albumid="+albumid,"Addtoplaylist",500,300,"yes");
	return;
}



function saveAllPopPlaylist(playlistname,productids, saveallid) {
	if (document.all && event!=null && event.clientX !=null) {
		var posx = event.clientX;
		var posy = event.clientY+document.body.scrollTop;
	}
	else { 
		var posx = 400;
		var posy = 400;	
	}
	document.SaveAllForm.productids.value=productids;
	// document.SaveAllForm.playlistname.value=playlistname;
	var url = "/music/site/common/savealltoplaylist_check.jsp?playlistname="+encodeURIComponent(playlistname)+"&posx="+posx+"&posy="+posy+"&saveallid="+saveallid+"&productids="+productids;
	hidden_ipf.location.href=url;
	// openWin("/music/site/common/addtoplaylist.jsp?productid="+productid+"&producttitle="+producttitle+"&artist="+artist+"&producttype="+producttype+"&productlength="+productlength+"&albumid="+albumid,"Addtoplaylist",500,300,"yes");
	return;
}

function saveAllToplaylist(playlistid, playlistname, saveallid) {
	if ((playlistid==null || playlistid=="") && (playlistname == null || playlistname =="") ) {
		alert("playlistid and playlistname are both empty");
		return;
	} else {
		document.SaveAllForm.saveallid.value = saveallid;
		document.SaveAllForm.playlistname.value = playlistname;
		document.SaveAllForm.playlistid.value = playlistid;
		document.SaveAllForm.submit();
	}
}

function playTagRadio(TagID, contributorID, type, language, parentTagID) {
	document.instantplayTagRadioForm.TagID.value=TagID;
	document.instantplayTagRadioForm.contributorID.value=contributorID;
	document.instantplayTagRadioForm.type.value=type;
	document.instantplayTagRadioForm.language.value=language;
	document.instantplayTagRadioForm.parentTagID.value=parentTagID;
	document.instantplayTagRadioForm.oriURL.value="http://moov.netvigator.com/music/tagradio/index.jsp";
	document.instantplayTagRadioForm.submit();	
}

function validPlaylistName (newplaylistname){
	var strlen = newplaylistname.length;
	for(i=0;i<strlen;i++){
		if(newplaylistname.charAt(i)=="\\"){
			return false;
		}
	}
	return true;
}

//lastmod: 3/8/2007 17:24
if(!window.Now){window.Now={};}Now.Flash=new function(){var me=this;var flv=null;var d=document;var w=window;this.Build=function(f,wf,hf,id){if(true){var el='<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="'+wf+'" height="'+hf+'" id="'+id+'"><param name=movie value="'+f+'"><param name=allownetworking value=all><param name=allowscriptaccess value=always><param name=quality value=high><param name=wmode value=transparent><embed src="'+f+'" quality=high pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="'+wf+'" height="'+hf+'" swliveconnect="true" allowwscriptaccess="always" allownetworking="all"></embed></object>';d.write(el);}};return this;};
var alldisabled = 'copyhistory=no,hotkeys=no,status=no,directories=no,location=no,menubar=no,toolbar=no,resizable=no,left=50,top=50,screenX=50,screenY=50,scrollbars=no,';
var pcwgdefault = 'copyhistory=no,hotkeys=no,status=yes,directories=no,location=yes,menubar=no,toolbar=yes,resizable=yes,left=50,top=50,screenX=50,screenY=50,scrollbars=yes,height=180,width=370';

function popupWin(url,name,options){
        newpopWin = window.open(url,name,options);
        setTimeout("newpopWin.focus()",100);
}

function Trim(TRIM_VALUE){
	if(TRIM_VALUE.length < 1){
		return"";
	}
	TRIM_VALUE = RTrim(TRIM_VALUE);
	TRIM_VALUE = LTrim(TRIM_VALUE);
	if(TRIM_VALUE==""){
		return "";
	}
	else{
		return TRIM_VALUE;
	}
} //End Function

function RTrim(VALUE){
	var w_space = String.fromCharCode(32);
	var v_length = VALUE.length;
	var strTemp = "";
	if(v_length < 0){
		return"";
	}
	var iTemp = v_length -1;
	
	while(iTemp > -1){
		if(VALUE.charAt(iTemp) == w_space){
	}
	else{
		strTemp = VALUE.substring(0,iTemp +1);
		break;
	}
	iTemp = iTemp-1;
	
	} //End While
	return strTemp;

} //End Function

function LTrim(VALUE){
	var w_space = String.fromCharCode(32);
	if(v_length < 1){
		return"";
	}
	var v_length = VALUE.length;
	var strTemp = "";
	
	var iTemp = 0;
	
	while(iTemp < v_length){
		if(VALUE.charAt(iTemp) == w_space){
	}
	else{
		strTemp = VALUE.substring(iTemp,v_length);
		break;
	}
		iTemp = iTemp + 1;
	} //End While
	return strTemp;
} //End Function

function stopPvPlayer() {
try {
	if (parent != self){
		parent.stopPvPlayer();
	}
} catch (ee) {
	//alert("stopPvPlayer error!");
}
}

function downloadItem(pid, ptitle, partist, ptype, unitprice, discountprice, dlbitrate, dlfiletype, displayprice, albumid, allowPC, allowDownload, isExplicit, cevent, logid, directRedeem) {
	var posx = 400;
	var posx = 100;
	if (document.all) {
		posx = event.clientX;
		posy = event.clientY+document.body.scrollTop;
	} else if (cevent) {
		if (cevent.client) {
			posx = cevent.client.x;
			posy = cevent.client.y+document.body.scrollTop;
		} else {
			posx = cevent.clientX;
			posy = cevent.clientY+document.body.scrollTop;
		}
	} else {
		//document.captureEvents(Event.CLICK | Event.MOUSEDOWN | Event.MOUSEMOVE | Event.MOUSEUP);
		posx = 400;
		posy = 100;	
	}
	document.downloadItemForm.bundleid.value=pid;
	document.downloadItemForm.oriURL.value=callPlayerSuccessURL;
	document.downloadItemForm.producttype.value=ptype;
	document.downloadItemForm.posX.value=posx;
	document.downloadItemForm.posY.value=posy;
	document.downloadItemForm.producttitle.value = ptitle;
	document.downloadItemForm.productartist.value = partist;
	document.downloadItemForm.unitprice.value = unitprice;
	document.downloadItemForm.discountprice.value = discountprice;
	document.downloadItemForm.downloadbitrate.value = dlbitrate;
	document.downloadItemForm.downloadfiletype.value = dlfiletype;
	document.downloadItemForm.displayprice.value = displayprice;
	document.downloadItemForm.albumid.value = albumid;
	document.downloadItemForm.allowPC.value = (allowPC==true || allowPC=="true")?"true":"false";
	document.downloadItemForm.allowDownload.value = (allowDownload==true || allowDownload=="true")?"true":"false";
	document.downloadItemForm.isExplicit.value = (isExplicit==true || isExplicit=="true")?"true":"false";
	document.downloadItemForm.logID.value = (logid)?logid:"";
	document.downloadItemForm.directRedeem.value = (directRedeem)?directRedeem:"";
	document.downloadItemForm.submit();
}

function mp3DlAll(playlisttype,playlistid,ptype,pLTitle,pLImageUrl,cevent,logid) {
	var posx = 400;
	var posx = 100;
	if (document.all) {
		posx = event.clientX;
		posy = event.clientY+document.body.scrollTop;
	} else if (cevent) {
		if (cevent.client) {
			posx = cevent.client.x;
			posy = cevent.client.y+document.body.scrollTop;
		} else {
			posx = cevent.clientX;
			posy = cevent.clientY+document.body.scrollTop;
		}
	} else {
		//document.captureEvents(Event.CLICK | Event.MOUSEDOWN | Event.MOUSEMOVE | Event.MOUSEUP);
		posx = 400;
		posy = 100;	
	}
	document.downloadItemForm.bundleid.value=playlistid;
	document.downloadItemForm.oriURL.value=callPlayerSuccessURL;
	document.downloadItemForm.producttype.value=playlisttype; //ptype
	document.downloadItemForm.productListTitle.value=pLTitle;
	document.downloadItemForm.productListImageUrl.value=pLImageUrl;
	document.downloadItemForm.posX.value=posx;
	document.downloadItemForm.posY.value=posy;
	document.downloadItemForm.logID.value = (logid)?logid:"";
	document.downloadItemForm.submit();
}
var bugchars = '!#$^&*()+|}{[]?><~%:;/,=`"\'';
function CharsInBag(s)
{   var i;
var lchar="";
    // Search through string's characters one by one.
    // If character is not in bag.
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character isn't whitespace.
        var c = s.charAt(i);
		if(i>0)lchar=s.charAt(i-1)
        if (bugchars.indexOf(c) != -1 || (lchar=="." && c==".")) return false;
    }
    return true;
}
function isInteger(s)
{   var i;
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character is not a number.
        var c = s.charAt(i);
        if ((c >= "0") && (c <= "9") && (c != ".")) return false;
    }
    // All characters are numbers.
    return true;
}
function emailValidation(str) {
	
	var at="@"
	var dot="."
	var lat=str.indexOf(at)
	var lstr=str.length
	var ldot=str.indexOf(dot)
	var lastdot=str.lastIndexOf(dot)
	if (str.indexOf(at)==-1){
	   return false;
	}
	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
	   return false;
	}
	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr || str.substring(lastdot+1)==""){
	    return false;
	}
	 
	 if (str.indexOf(at,(lat+1))!=-1){
	    return false;
	 }

	 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
	    return false;
	 }

	 if (str.indexOf(dot,(lat+2))==-1){
	    return false;
	 }
	
	 if (str.indexOf(" ")!=-1){
	    return false;
	 }
	if(CharsInBag(str)==false){
	    return false;
	 }
	 var arrEmail=str.split("@")
	 var ldot=arrEmail[1].indexOf(".")
	 if(isInteger(arrEmail[1].substring(ldot+1))==false){
	    return false;
	 }
	return true;		
}