﻿// JScript File

    function AddToPlayList(edition,title){ 
         if(plSelected==1){   
            plSelected=2;
            plid=2;           
            var strHref=window.location.href;
            var hrf=strHref.substring(0,strHref.lastIndexOf('4'));
            hrf=hrf+"4&plid=2" ; 
            var position=strHref.lastIndexOf('editionnr');  
           // alert(position);
            if(position>0)
            {
                var editionNr=strHref.substring(position);
                hrf=hrf+"&"+editionNr;  
            }
   
            window.location=hrf;
            obj=document.getElementById("pl1");           
            obj.outerHTML="<A id=pl1 onmouseover='imgAct(\"playlist1\",2)' onclick='imgSet(\"playlist1\",2)' onmouseout='imgInact(\"playlist1\",2)' href=\"http://localhost/ga01/music.aspx?id=4&amp;plid=1\"><IMG src=\"graphics/playlist1Off.png\" border=0 id=playlist1 name=playlist1 ></A>";
//            alert(obj.outerHTML);
            obj=document.getElementById("playlist2");
            obj.src="graphics/Playlist2Act.png";

            obj=document.getElementById("pl2");  
            obj.outerHTML="<A id=pl2 onmouseover='imgAct(\"playlist2\",2)' onclick='imgSet(\"playlist2\",2)' onmouseout='imgInact(\"playlist2\",2)' href=\"http://localhost/ga01/music.aspx?id=4&amp;plid=2\"><IMG src=\"graphics/playlist2Act.png\" border=0 id=playlist2 name=playlist2 ></A>";

            obj=document.getElementById("recycleBin1");   

            obj.style.visibility	= 'visible';
           
            GetUserPlaylist();

        }
        txtPlaylist = document.getElementById("Playlist1_txtPlayList");
        if(!IsExist(txtPlaylist.value,edition)){
            txtPlaylist.value += edition + ",";            
            lblPlaylist = document.getElementById("Playlist1_lblPlaylist"); 
            lblPlaylist.innerHTML +="<table border=0 cellspacing=0 cellpadding=0><tr><td valign=top width=10 ><img src=graphics/bullet.gif></td><td valign=top style=padding-bottom:3px;FONT-WEIGHT:bold;FONT-SIZE:9;>"+title+ "</td></tr></table>";
                    
        }

        SetPlaylistInCookie();
    }


    function Playall(){
		sItems = document.getElementById("Playlist1_txtPlayList").value;
		sItems = sItems.substring(0,sItems.length-1);
		if(sItems != ""){
		    OpenWindow('listenmusic.aspx?code='+sItems);
		}
		else{
		    alert('Sorry... You have no music in the playlist.\nPlease add music in the playlist');
		}
    }
    /*************************************************
        This function delete music from playlist as
        well as from cookies
    **************************************************/
    function DeletePlaylist(){
        document.getElementById("Playlist1_txtPlayList").value="";
        document.getElementById("Playlist1_lblPlaylist").innerHTML="";
        SetPlaylistInCookie();
    }

    function GetUserPlaylist(){

        editions = GetCookie('editions');
        isNotNull=true;    
        titles  = GetCookie('titles');
        
        if(editions!=null && titles !=null){
            document.getElementById("Playlist1_txtPlayList").value = GetCookie('editions');
            document.getElementById("Playlist1_lblPlaylist").innerHTML = GetCookie('titles');          
            
        }
        else{
            document.getElementById("Playlist1_txtPlayList").value = "";
            document.getElementById("Playlist1_lblPlaylist").innerHTML = "";          
            
        }
    }

  
    function SetPlaylistInCookie(){
        SetCookie('editions',document.getElementById("Playlist1_txtPlayList").value,7);
        SetCookie('titles',document.getElementById("Playlist1_lblPlaylist").innerHTML,7);
    }
    /*************************************************
        Get the value of cookie according to the
        Cookie name
    **************************************************/
    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 null;
    }
    /*************************************************
        We need to add a relative amount of time to
        the current date. The basic unit of JavaScript
        time is milliseconds, so we need to convert the
        days value to Miliseconds.
    **************************************************/
    function SetCookie(cookieName,cookieValue,nDays) {
        var today = new Date();
        var expire = new Date();
        if (nDays==null || nDays==0) nDays=1;
        expire.setTime(today.getTime() + 3600000*24*nDays);
        document.cookie = cookieName+"="+escape(cookieValue)
                         + ";expires="+expire.toGMTString();
    }
    
    /*************************************************
        Check wether a search string is exist or not
        in a large string and returns true if exist
        otherwise false.
    **************************************************/
    function IsExist(largeText,searchText){
        return largeText.indexOf(searchText)==-1?false:true;
    }
    
