var total=0;
String.prototype.startsWith = function(str) 
{return (this.match(str)!=str)}

function ExcluirCookie(strCookie)
{
    GerarCookie(strCookie, '', -1);
	history.go(0);
}
function GerarCookie(strCookie, strValor, lngDias)
{
    var dtmData = new Date();

    if(lngDias)
    {
        dtmData.setTime(dtmData.getTime() + (lngDias * 24 * 60 * 60 * 1000));
        var strExpires = "; expires=" + dtmData.toGMTString();
    }
    else
    {
        var strExpires = "";
    }
    document.cookie = strCookie + "=" + strValor + strExpires + ";domain=.lojadosom.com.br;path=/";
}
function lerOCookie(a_info)
{
var separacao;
var o_cookie=WM_readCookie("yourplay");
if (o_cookie)
{
 if (o_cookie.indexOf("/") != -1)
{
separacao = o_cookie.split("/");

 for (var loop=0; loop < separacao.length; loop++)
{
 a_info[loop] = separacao[loop];
}
} else {
 a_info[0] = o_cookie;
}
}
}

function WM_readCookie(name) {
if (document.cookie == '') {

// there's no cookie, so go no further
// document.writeln("<BR>não pode ser gravado o cookie<BR>");
return false; //unescape("não há arquivos");
} else {

// there is a cookie

var firstChar, lastChar;
var theBigCookie = document.cookie;
firstChar = theBigCookie.indexOf(name);

// find the start of 'name'

if(firstChar != -1) {

// if you found the cookie

firstChar += name.length + 1;

// skip 'name' and '='

lastChar = theBigCookie.indexOf(';', firstChar);

// Find the end of the value string (i.e. the next ';').

if(lastChar == -1) lastChar = theBigCookie.length;

return unescape(theBigCookie.substring(firstChar, lastChar));

} else {
//document.writeln("<BR>não há cookie com esse nome<BR>");
// If there was no cookie of that name, return false.

return unescape("");// false; //unescape("não há arquivos");
}

}

}

function deleteCookie(nome){
    var exdate = new Date();
    exdate.setTime(exdate.getTime() + (-1 * 24 * 3600 
       * 1000));
    document.cookie = nome + "=" + escape("")+ ((-1 
       == null) ? "" : "; expires=" + exdate);
  } 

function deletamus(name,cod,ban,mus){
var o_cookie=WM_readCookie(name);

strings=cod+":"+ban+":"+mus+"/";
if(o_cookie.startsWith(cod+":"+ban+":"+mus+"/")){
}else{
newcookie=o_cookie.replace(strings, "");
GerarCookie("yourplay",newcookie, 30);
if(newcookie==''){
	ExcluirCookie("yourplay");
}
exibir_musicas();
}
}

function adiciona(name,cod,ban,mus){
if (document.cookie != '') {
if(total < 20){
faltam=20-(total+1);
var o_cookie=WM_readCookie(name);
var d=new Date();
d=new Date(d.getTime() + (34*86400*1000));
if (o_cookie){
	if(o_cookie.startsWith(cod)){
		var cookie_yourplay = escape(o_cookie)+escape(cod+":"+ban+":"+mus+"/");
		GerarCookie("yourplay",cookie_yourplay, 30);
		alert(mus+" foi incluida a sua lista de favoritos!!\n Faltam "+faltam+" para completar sua lista.");
		//document.writeln("verdadeiro");
	}else{
		alert("ja existe essa música");
	}
}else{
	var cookie_yourplay = escape(cod+":"+ban+":"+mus+"/");
	GerarCookie("yourplay",cookie_yourplay, 30);
	
	alert(mus+" foi incluida a sua lista de favoritos!!\n Faltam "+faltam+" para completar sua lista.");
	var o_cookie=cookie_yourplay;
}
exibir_musicas();
}else{
alert("Número excede o máximo permitido de 20 músicas ");
}
}else{
alert("           Seu navegador não permite essa opção!!\n Você deve permitir cookies para que essa opção funcione");
}
}