function openp(s)
{
var width=668;
var height=418;
var left =(screen.width - width) / 2;
var top = (screen.height - height) / 2; 
var ourl=web_url+"Music/dj_mp.htm?w="+s+"|f=1";
window.open(ourl,'huaxiang','width='+width+',height='+height+',top='+top+',left='+left+',scrollbars=0,resizable=0');
}

function getCookieVal(offset)
{
	var s=unescape(document.cookie);
	var endstr=s.indexOf("#",offset);
	if(endstr==-1)
		endstr=s.length;
	return s.substring(offset,endstr);
}

function GetCookie(name)
{
	var arg=name+"=";
//	alert(arg);
	var alen=arg.length;
//	alert(alen);
	var i=0;
	var ss=unescape(document.cookie);
//	alert(ss);
	var clen=ss.length;
//	alert(clen);
	while(i<clen)
	{
		var j=i+alen;
		
//		alert(i);
//		alert(j);
//		alert(ss.substring(i,j));
		if(ss.substring(i,j)==arg)
		{
			return getCookieVal(j);
		}
		i=ss.indexOf(";",i)+1;
		if(i==0)
			break;
	}
	return null;
}

function SetCookie(name,value,expires, path, domain, secure)
{
	var argv=SetCookie.arguments;
	var argc=SetCookie.arguments.length;
		var expires=(2<argc)?argv[2]:null;
	var path=(3<argc)?argv[3]:null;
	var domain=(4<argc)?argv[4]:null;
	var secure=(5<argc)?argv[5]:false;

	var expdate=new Date();
	if(expires != null)
	{
		expdate.setTime(expdate.getTime()+expires);
	}
	else
	{
		expdate.setTime(expdate.getTime()+(24*60*60*1000*1));
	}
	var tmp = name+"="+escape(value)+((expires==null)?"":("; expires="+expdate.toGMTString()))+((path==null)?"/":("; path="+path))+((secure==true)?"; secure":"");
	document.cookie= tmp;
}
/*var Cookies = {
	GetCookie : function(name)
	{
		var start = document.cookie.indexOf(name + "=");
		if (start<0) return null; else start += name.length+1;
		var end = document.cookie.indexOf (";", start);
		if (end < 0) end = document.cookie.length;
		return decodeURIComponent(document.cookie.substring(start, end));
	},
	GetCookies : function()
	{
		var cookies = [];
		pairs = document.cookie.split('; ');
		var pair = null;
		for (var i=0; i<pairs.length; i++)
		{
			pair = pairs[i].split('=');
			cookies.push(pair[0],pair[1]);
		}
		return cookies;
	},
	// expires 单位为秒
	SetCookie : function(name, value, expires, path, domain, secure)
	{
		var expdate = new Date();expdate.setTime(expdate.getTime());
		if(valid(expires)) expdate.setTime(expdate.getTime() + ( expires * 1000 ));
		document.cookie = name + "=" + encodeURIComponent (value) + (valid(expires)?("; expires="+ expdate.toGMTString()):"")+(valid(path)?("; path=" + path):"")+(valid(domain)?("; domain=" + domain):"")+((valid(secure)&&secure) ? "; secure" : "");
	},
	DelCookie : function(name, path, domain)
	{
		var val = this.GetCookie(name);
		if (val==null) return;
		var exp = new Date();
		exp.setTime (exp.getTime() - 1);
		document.cookie = name + "=; expires="+ exp.toGMTString()+(valid(domain)?("; domain=" + domain):"")+(valid(path)?("; path=" + path):"");
	}
}*/

function fav()
{
	var number=document.ls1.elements.length;
	var ids="";
	var newstr;
	var j;
	j=0;
	newstr="F=";
	for(var i=0;i<number;i++)
	{
		if(document.ls1.elements[i].type=="checkbox")
		{
			if(document.ls1.elements[i].checked&&document.ls1.elements[i].value!="")
			{
				if(j==0)
				{
					j++;
					ids+=document.ls1.elements[i].value;
				}
				else
				{
					j++;
					ids+="|";
					ids+=document.ls1.elements[i].value;					
				}
			}
		}
	}
	alert("j:"+eval(j));
	newstr=ids;
	//GetCookie

	var ostr=GetCookie("F");
	var onum=GetCookie(" Fn");
	var lss;
	var nls;
	var k;
	nls=0;

	if(ostr!=null && ostr!="")
	{
		lss=ostr.split("|");
		nls=lss.length;
	}
	if((j+nls)>=10)
	    k=10-j;
	else
	    k=nls;
	for(var i=0;i<k;i++)
	{
	  newstr +="|";
	  newstr +=lss[i];
	}
	newstr +="#";
	SetCookie("F",newstr,24*60*60*1000*365,"/",null,false);
	SetCookie("Fn",eval(j+k)+"#",24*60*60*1000*365,"/",null,false);
}

function clear_all(name)
{
	var start = 0;
	 while(document.getElementById(name+start)!=null)
  	 {
 	   document.getElementById(name+start).checked=false;
       start++;
 	 }
}

function set_all(flag,name)
{
	
  var start=0;
  var setflag;
  if(document.getElementById(name+start)!=null)
  {
	  if(flag)
	  {
	      setflag=!document.getElementById(name+start).checked;
	  }
	  else
	  {
	      setflag=document.getElementById(name+start).checked;
	  }
  }
//  start++;
  
  while(document.getElementById(name+start)!=null)
  {
//     if(!flag) document.getElementById(name+start).checked=!document.getElementById(name+start).checked;
 //    else document.getElementById(name+start).checked=flag;
 	   document.getElementById(name+start).checked=setflag;
       start++;
  }

}

function  chkpinfo(name,formname)
{
	//alert(formname);
	//var obj = eval("document.form"+formname);
	//alert(obj);
  var nums=document.all.item(formname).elements.length;//.elements.length;


  var url_add='';
  var url_add_all='';
  var start=1;
  var icount=0;
  var i=0;
  
  while(i<nums)
  {
     if(document.all.item(formname).elements[i].value!='0')
     {
        if(document.all.item(formname).elements[i].checked) 
		{
        	url_add+=document.all.item(formname).elements[i].value;
			url_add+="|";
			icount++;
		}
		
        url_add_all+=document.all.item(formname).elements[i].value;
		url_add_all+="|";
		
     }
	 
     start++;
	 i++;
  }
  
// alert(url_add);
 if(url_add=='')
  {
     set_all(true,name);
     var temstr = url_add_all;
	 	 var temstrlen =  url_add_all.length;
	 	 url_add_all = temstr.substring(0,temstrlen);
	   setpinfo(url_add_all,start-1);
  }
  else
  {
	   var temstr = url_add;
	 	 var temstrlen =  url_add.length;
	 	 url_add = temstr.substring(0,temstrlen);
     setpinfo(url_add,icount);
  }
  clear_all(name);
  var width=668;
  var height=418;
  var left = ( screen.width - width ) / 2;
  var top = ( screen.height - height ) / 2;
  window.open(web_url+"Music/dj_mp.htm",'huaxiang','width='+width+',height='+height+',top='+top+',left='+left+',scrollbars=0,resizable=0');
}

function setpinfo(strinfo,lcount)
{
	var i;
	i=strinfo.length-1;
	var bakstr=strinfo.substring(0,i);
	var maxnum=300;
	home.load("BoxList");
 	var oldliststr = home.getAttribute("list");
 	var oldlistnum= home.getAttribute("listcount");
	var curlistnum=lcount;
//	alert(oldlistnum);
//	alert(curlistnum);
//	alert(oldliststr);
	var oldstrlen=0;
	
	if(oldliststr)
	{
		oldliststr = oldliststr + "|";
		oldstrlen=oldliststr.length;
	}
	
	var sfind;
	var tempstr;
	var temstr2;
//	alert(strinfo);
	
	if(lcount>=maxnum)
	{
//		SetCookie("P",strinfo,24*60*60*1000*365,"/",null,false);
		
//		SetCookie("Pn",eval(maxnum)+"#",24*60*60*1000*365,"/",null,false);
	}
	else
	{
		if(oldstrlen>0)//cookie
		{
			i=0;
			while(curlistnum<maxnum)
			{
//				alert(i); 
				if(i==oldlistnum+1)
				{
//					alert("break");
					break;
				}
				
				sfind=oldliststr.indexOf('|') ;
				tempstr=oldliststr.substring(0,sfind);
				temstr2=GetCertainStr(tempstr,2,3,",");//
				
				if(strinfo.indexOf(temstr2)>=0)
				{
//					alert("find");
					oldliststr=oldliststr.substring(sfind+1,oldstrlen);
//					alert(oldliststr);
					i++;
				}
				else
				{
//					alert("not find");
					bakstr+="|";
					bakstr+=tempstr;			
					oldliststr=oldliststr.substring(sfind+1,oldstrlen);
//					alert(oldliststr);
					curlistnum+=1;
					i++;
				}
//				alert(curlistnum);
			}
			
			
		}
		
/*		bakstr+="#";
//		alert(bakstr);
		SetCookie("P",bakstr,24*60*60*1000*365,"/",null,false);
		SetCookie("Pn",eval(curlistnum)+"#",24*60*60*1000*365,"/",null,false);*/
		saveUserList(bakstr,curlistnum);
		
	}
	
}

function GetCertainStr(str,start,end,cflag)
{
	var temstr=str;
	var i;
	var spos=0;
	var epos=0;
	var strlen=str.length;
	var strtem;
	var sumtem=0;
	
	for(i=0;i<start;i++)
	{
		strtem=temstr.indexOf(cflag);
		strtem+=1;
		sumtem+=strtem;
		strtem=temstr.substring(strtem,strlen);
		temstr=strtem;
	}
	spos=sumtem;
	
	temstr=str;
	sumtem=0;
	for(i=0;i<end;i++)
	{
		strtem=temstr.indexOf(cflag);
		strtem+=1;
		sumtem+=strtem;
		strtem=temstr.substring(strtem,strlen);
		temstr=strtem;
	}
	epos=sumtem-1;

	return str.substring(spos,epos);
}
function getStrActualLen(sChars)
{
    return sChars.replace(/[^\x00-\xff]/g,"xx").length;
}
function saveUserList(writebuff,pcount)	//writebuff为要存储的数据串,pcount为存储的数据个数
{
  var sstt = writebuff;
  home.setAttribute("list",sstt);
  home.setAttribute("listcount",pcount);
  home.save("BoxList");
  home.removeAttribute("list");
  home.removeAttribute("listcount");
}
