function fnCheckAll()
{
	if (document.frmAlbum.chAll.checked==true)
	{

		if (document.frmAlbum.chkAcc1.length == undefined)
		{

			document.frmAlbum.chkAcc1.checked=true;		
		}
		else
		{
			for (i=0; i<document.frmAlbum.chkAcc1.length;i++)
			{
				document.frmAlbum.chkAcc1[i].checked=true;
			}	
		}
	}
	
	else
	{
		if (document.frmAlbum.chkAcc1.length == undefined)
		{

			document.frmAlbum.chkAcc1.checked=false;		
		}
		else
		{
			for (i=0; i<document.frmAlbum.chkAcc1.length;i++)
			{
				document.frmAlbum.chkAcc1[i].checked=false;
			}
		}
	}
	assignval();
}

function plyall()
{
		for (i=0; i<document.frmAlbum.chkAcc1.length;i++)
		{
			document.frmAlbum.chkAcc1[i].checked=true;
		}	
		assignval();
		var t,l
		l=(screen.width-420)/4
		t=(screen.height-180)/6
		window.open("../tpplayer.asp?sngs="+document.frmAlbum.txtselected.value,"TPPlayer","scrollbars=1,width=560,height=305,resizable=0,top="+t+",left="+l);

}
function plysel()
{
	if (document.frmAlbum.txtselected.value == "")
	{
		alert("Please select tracks to play");
	}
	else
	{
		var t,l
		l=(screen.width-420)/4
		t=(screen.height-180)/6
		window.open("../tpplayer.asp?sngs="+document.frmAlbum.txtselected.value,"TPPlayer","scrollbars=1,width=560,height=305,resizable=0,top="+t+",left="+l);
	}
}
function assignval()
{
		document.frmAlbum.txtselected.value="";
		if (document.frmAlbum.chkAcc1.length == undefined)
		{

			document.frmAlbum.txtselected.value="'"+document.frmAlbum.txtselected.value+document.frmAlbum.chkAcc1.value+"'";		
		}
		else
		{
		for (i=0; i<document.frmAlbum.chkAcc1.length;i++)
		{
			if (document.frmAlbum.chkAcc1[i].checked==true)
			{
				if (i==0)
				{
					document.frmAlbum.txtselected.value="'"+document.frmAlbum.txtselected.value+document.frmAlbum.chkAcc1[i].value+"'";
				}
				else
				{
					document.frmAlbum.txtselected.value=document.frmAlbum.txtselected.value+",'"+document.frmAlbum.chkAcc1[i].value+"'";
				}
			}
		}
		}
		if (document.frmAlbum.txtselected.value.substring(0,1)==",")
		{
			document.frmAlbum.txtselected.value=document.frmAlbum.txtselected.value.substring(1)
		}
		//alert(document.frmAlbum.txtselected.value);
}

function assignval1(obj)
{
    if(obj.checked){
        if(document.frmAlbum.txtselected.value.length==0){
            document.frmAlbum.txtselected.value="'" + obj.value + "'";
        }
        else
            document.frmAlbum.txtselected.value=document.frmAlbum.txtselected.value+",'" + obj.value + "'";
    }
    else{
        if(document.frmAlbum.txtselected.value.indexOf(',')<0){
            document.frmAlbum.txtselected.value=""
        }
        else{
            Bst = (document.frmAlbum.txtselected.value.substring(0,document.frmAlbum.txtselected.value.indexOf(obj.value) - 1));
            POSatF=document.frmAlbum.txtselected.value.indexOf(obj.value);
            Rst = document.frmAlbum.txtselected.value.substring(POSatF,document.frmAlbum.txtselected.value.length);
            DelSt = Rst.substring(document.frmAlbum.txtselected.value.indexOf(','),document.frmAlbum.txtselected.value.length);
            Fst = (Bst + DelSt);
            //alert(Fst.substring(0,Fst.length-2));
            if(Fst.indexOf(',') == Fst.length-1){Fst = Fst.substr(0,Fst.length-1)};
            document.frmAlbum.txtselected.value = Fst;
        }
    }
    //alert(document.frmAlbum.txtselected.value)
}
//For Playlist
function plylst(){
    var curlst
    curlst = getCookie("plst")
    if(document.frmAlbum.txtselected.value==""){
        alert("Please select track(s) to add to playlist")
        return;
    }
    if(curlst==""){
        lstary = document.frmAlbum.txtselected.value.split(",")
        if(lstary.length>20){
            alert("Please select fewer than 20 tracks in a playlist.");
            return;
        }
        setCookie("plst",document.frmAlbum.txtselected.value,1);
    }
    else{
        lstary = curlst.split(",")
		newlst = document.frmAlbum.txtselected.value
		for(j=0;j<lstary.length;j++){
			newlst = newlst.replace(lstary[j],"")
		}
		curlst = newlst +","+curlst
		lstary = curlst.split(",")
		curlst = ""
		for(j=0;j<lstary.length;j++){
			if(lstary[j]!=""){
				curlst = curlst + lstary[j] +","
			}
		}
		curlst = curlst.substr(0,curlst.length-1)
		lstary = curlst.split(",")
		if(lstary.length>20){
            alert("Please select fewer than 20 tracks in a playlist.");
            return;
        }
        setCookie("plst",curlst,1);
    }
    //document.location = document.url
    window.location.reload(false)
}

function plyplylst(){
    //alert(getCookie("plst")) 
    //document.location = "TPplayer.asp?sngs="+getCookie("plst")
    document.frmAlbum.txtselected.value = getCookie("plst")
	var t,l
	l=(screen.width-420)/4
	t=(screen.height-180)/6
	window.open("../tpplayer.asp?sngs="+document.frmAlbum.txtselected.value,"TPPlayer","scrollbars=1,width=560,height=305,resizable=0,top="+t+",left="+l);    
}

function edtlst(){
	var t,l
	l=(screen.width-420)/4
    t=(screen.height-180)/6
    //document.frmAlbum.txtplist.value=getCookie("plst");
    window.open("../editlist.asp?sngs="+getCookie("plst"),"Playlist","scrollbars=1,width=560,height=305,resizable=0,top="+t+",left="+l);
    //document.frmAlbum.submit();
}

function savsel(){
	if (document.frmAlbum.txtselected.value == "" )
	{
		if(!confirm("All tracks will be removed from playlist")){
		    return;
		}
	}
	//else
	//{
	        setCookie("plst",document.frmAlbum.txtselected.value,1);
        	document.location = "editlist.asp?sngs="+getCookie("plst")
        	window.opener.location.reload();
	        //window.location.reload(false)
	//}    
}

function getCookie(c_name){
    if (document.cookie.length>0){
        c_start=document.cookie.indexOf(c_name + "=");
        if (c_start!=-1){ 
            c_start=c_start + c_name.length+1; 
            c_end=document.cookie.indexOf(";",c_start);
            if (c_end==-1) c_end=document.cookie.length;
            return unescape(document.cookie.substring(c_start,c_end));
        } 
    }
    return "";
}

function setCookie(c_name,value,expiredays){
    var exdate=new Date();
    exdate.setDate(exdate.getDate()+expiredays);
    document.cookie=c_name+ "=" +escape(value)+((expiredays==null) ? "" : ";expires="+exdate.toGMTString())+";path=/"
}

function checkCookie(){
    username=getCookie('username');
    if (username!=null && username!=""){
        alert('Welcome again '+username+'!');
    }
    else{
        username=prompt('Please enter your name:',"");
        if (username!=null && username!=""){
            setCookie('username',username,365);
        }
    }
}
//End for playlist