


function MyCookie(){
this.key="";//初始化key。
this.value="";//初始化key's value。
this.expires=31536000000;//初始化cookie的有效时间，单位毫秒。
this.init=function(){//对象初始化
this.key="";
this.value="";
this.expires=0;
}
/**
 * 
 */
this.addFund = function(type,inValue){
	var tempKey,keyName;
	//检查类型是否正确
	if(type == null || type.length<1){
		alert("添加我的基金，基金类型不正确！");
		return false;
	}
	if(type == "05"){
		tempKey="Coin";
		keyName = "货币型";
	}else{
		tempKey="Uncoin";
		keyName = "非货币型";
	}
	//检查基金类型是否已经达到最大数目
	var typeNumber=this.length(tempKey);
	if(typeNumber >=10){
		alert("该类产品已保存超过10只！我的基金栏目可为您保存10只非货币型基金，10只货币型基金！");
		return false;
	}
	
	//检查基金数据是否正确
	if(inValue == null || inValue.length<3){
		alert("添加我的基金，基金代码不正确！");
		return false;
	}
	//再次检查基金代码是否完整正确
	var splitValues=inValue.split("|");
	if(splitValues.length<2){
		alert("添加我的基金，基金代码不正确！");
		return false;
	}
	
	//加入我的基金
	//alert("yuan Add");
	return this.add(tempKey,inValue);

}
this.add=function(key,value){
	

	var v=this.get(key);
	//alert("v-"+v);
	//alert("value-"+value);
	if(v=="undefined"||this.get(key)==false)
	{
		//alert("set");
		this.set(key,value,31536000000);
		return true;
	}
	else{
		if(v.indexOf(value)!=-1)
		{
			alert("您已保存过该基金！");
			return false;
		}
		else{
		//alert("else");
		this.del(key);
		this.set(key,v+','+value,31536000000);
		return true;
		}
	}
}

this.isExist=function(type,values)
{
	var key;
	if(type==05)
	{
		key="Coin";
	}
	else
	{
		key="Uncoin";
	}
	var vv=this.get(key);
	var bool=false;
	if(vv==false)
	{
		return false;
	}
	else
	{
		var ss=values.split(",");
		for(var i=0;i<ss.length;i++)
		{
			if(vv.indexOf(ss[i])!=-1)
			{
				//alert("zzzzzzzzzzzzzzz");
				bool=true;
			}
		}
	}
		//alert(bool);
		return bool;
	
}
	


this.length=function(key){
	if(this.get(key)=="undefined"||this.get(key)==false)
	{
		//alert("return 0");
		return ll=0;
	}
	else
	{
	var vv=this.get(key);
	
	//alert("vv.length-"+vv.length);
	return ll=vv.split(",").length;
	}
}


this.sub=function(key,value){
	var v=this.get(key);
	
	if(v.indexOf(value)!=-1)
	{
		var vv;
		if(v.indexOf(","+value+",")!=-1)
		{
			//alert("1");
			vv=v.replace(","+value+",",",");
		}

		else
		{
			if(v.indexOf(value+",")!=-1)
			{
				//alert("2");
				vv=v.replace(value+",","");
			}
			else if(v.indexOf(","+value)!=-1)
			{
				//alert("3");
				vv=v.replace(","+value,"");
			}
		}
			
		//alert("vv-"+vv);
		this.del(key);
		this.set(key,vv,31536000000);
	}
	else
	{
		alert("该值不存在");
		
	}
}


this.set=function(key,value,expires){//设置cookie
  if(this.key=="")this.key=key;
  if(this.value=="")this.value=escape(value);
  if(this.expires<=0)this.expires=expires;
  if(this.key==""||typeof(this.key)!="string"){
    //alert("请先设置欲保存的cookie名称！");
    this.init();
    return false;
  }

  if(this.key.match(/[,; ]/)){
    //alert("cookie名称中不能包含“,”、“;”或空格！");
    this.init();
    return false;
  }
  if(this.value.toString().match(/[,; ]/)||typeof(this.value)=="undefined"){
    //alert("cookie值中不能包含“,”、“;”或空格！");
    this.init();
    return false;
  }
  if(this.expires<=0||typeof(this.expires)!="number"){
    //alert("请先正确设置cookie的有效时间！");
    this.init();
    return false;
  }
  var cookie=document.cookie;
  //不提醒用户该值是否需要替换
  if(cookie.indexOf(this.key+"=")!=-1){
    /*if(!confirm("欲保存的cookie名称已经存在，是否要进行替换？")){
      this.init();
      return false;
    }*/
  }
  var dt=new Date();
  dt.setTime(dt.getTime()+this.expires);
  //alert(document.cookie);
  document.cookie=this.key+"="+this.value+";path=/;expires="+dt.toGMTString();
//alert(document.cookie+"  "+this.key+' '+this.value);
  this.init();
  return true;
}

this.get=function(key){//取得名为key的cookie的值
if(key==""||key.match(/[,; ]/)){
//alert("请正确设置欲查找的cookie名称！")
return false;
}
var cookie=document.cookie;
var start=cookie.indexOf(key+"=");
if(start==-1){
//alert("欲查找的cookie不存在！")
return false;
}
var end=cookie.indexOf(";",start);
if(end==-1)end=cookie.length;
var getCookie=unescape(cookie.substring(start+key.length+1,end));
//alert("cookie："+key+"的值为"+getCookie);
return getCookie;
}
this.showAll=function(){//显示所有cookie
alert("共有以下cookie对：\n"+document.cookie.split(";").toString().replace(/,/g,"\n"));
}
this.del=function(key){//删除名为key的cookie
if(key==""||key.match(/[,; ]/)){
//alert("请正确设置欲删除的cookie名称！")
return false;
}
var dt=new Date();
dt.setTime(dt.getTime());
document.cookie=key+"=Delete;expires="+dt.toGMTString();
this.init();
return true;
}

this.destroy=function(){//销毁所有cookie
var dt=new Date();
dt.setTime(dt.getTime());

while(document.cookie!=""){

document.cookie=document.cookie+";expires="+dt.toGMTString();
}
this.init();
return true;

}
}
function settest(){

cookieTest.key="test";
cookieTest.value="";
cookieTest.expires=31536000000;
cookieTest.set();
}

function test(){
alert(document.cookie);
}



