
ref = new Array(
"www.google.com/search",                  	//01
"www.google.co.jp/search",                	//02
"www.overture.com/d/search", 			//03
"www.kaihatsuku.com",				//04
"www.chinatomy.com",				//05
"blog.livedoor.jp/max_squash",			//06
"blog.webcrew.cn",				//07
"www.explore.ne.jp/sh.phtml",			//08
"www.explore.ne.jp/info/search/search2.php3",	//09
"www.shwalker.com/real_estate/index.html",	//10
"www.bizchina.info/jp/index.php"		//11
);

ref_id = new Array(
"01","02","03",
"04","05","06","07","08",
"09","10","11");

pass_id_list = new Array(
"","","","","","","","",
"","","");

fix_id = new Array("");

clear_cookie_id = new Array("01","02","03","04","05","06","07","08",
"09","10","11");



//window.alert ( document.cookie);
function SetIDCookie(){        
        //var pid = GetCookie("pid");
        //if(pid && pid!="00"){
        //	return false;
        //}
        
        
        var ID = "00";
        var pass_id = "";
        var ourl = document.referrer; //alert(ourl);
		//var ourl="www.overture.com/d/search?hl=ja&q=%E4%B8%A";
        var fix_id_flg = 0; // 0:URL??ID?????f 1:URL??ID???????f
		
        for ( i in ref ) {
            if ( ourl.indexOf(ref[i]) > -1 ) {
                ID = ref_id[i];
                pass_id = pass_id_list[i];
                break;
            }
        }

    for ( i in fix_id ) {
        if ( ID ==  fix_id[i] ) {
            fix_id_flg = 1;
            break;
        }
    }
	//alert(ourl+";"+ID+";"+fix_id_flg+";"+pass_id);

	SetBanCookie(ourl,ID,fix_id_flg,pass_id);		
	

//window.alert ( document.cookie);
}

function SetBanCookie(PreURL,ID,fix_id_flg,pass_id){
        var args                = new Array();
        var location    = document.location.toString();
        var temp_args   = location.substring(location.indexOf("?") + 1, location.length);
//        var ID                  = "00";
        var expires             = new Date();
        var SID                  = "";
		//alert(location+"\r\n"+temp_args);
        if (GetCookie("id") && ID == "00") ID = GetCookie("id");
        for ( i in clear_cookie_id )
        {
          if (ID == clear_cookie_id[i] && PreURL.indexOf(document.domain,0) == -1 ) ID = "00";
        }
		//alert(temp_args);
        args = temp_args.split("&");
        for (i = 0; i < args.length && !fix_id_flg; i++){
                targs = args[i].toString();
                KEY = targs.substring(0, targs.indexOf("="));
                VAL = targs.substring(targs.indexOf("=")+1, targs.length);
                if (!fix_id_flg || pass_id.indexOf(VAL) > -1 ) {
                  if (KEY == "PID")  { ID = VAL; }
                  else if (KEY == "pid")  { ID = VAL; }
                  if (KEY == "SID")  { SID = VAL; }
                  else if (KEY == "sid")  { SID = VAL; }

                }
        }

		//window.alert ( document.domain );
		
//		alert(ID);
		if(ID!="00"){
//			alert("set");
	        expireDate = GetExpireDay();
	        SetCookie("pid", ID, expireDate,"/",document.domain);
        }
        if (PreURL.indexOf(document.domain,0) == -1 ) {
//          SetCookie("PreURL", PreURL, expireDate,"/",document.domain);
        }
}

function GetExpireDay(){
        expiredays = 30;
        var expireDate = new Date();
        expireDate.setTime (expireDate.getTime() + 24 * 60 * 60 * 1000 * expiredays);
        return expireDate.toGMTString();
}

function SetCookie(name, value){
        var argv        = SetCookie.arguments;
        var argc        = SetCookie.arguments.length;
        var expires     = (argc > 2) ? argv[2] : null;
        var path        = (argc > 3) ? argv[3] : null;
        var domain      = (argc > 4) ? argv[4] : null;
        var secure      = (argc > 5) ? argv[5] : false;
		//alert(name+";"+escape(value)+";"+expires+";"+path+";"+domain+";"+secure);
        document.cookie = name + "=" + escape(value)
                + ((expires     == null) ? "" : ("; expires="   + expires))
                + ((path        == null) ? "" : ("; path="    + escape(path)));
                + ((domain      == null) ? "" : ("; domain="  + escape(domain)))
                + ((secure      == true) ? "; secure" : "");
		//alert(document.cookie);

}

function GetCookie(name){
        var arg  = name + "=";
        //alert(arg);
        var alen = arg.length;
        var clen = document.cookie.length;
        var i = 0;

        while (i < clen){
                var j = i + alen;
                if (document.cookie.substring(i, j) == arg) return GetCookieValue (j);
                i = document.cookie.indexOf(" ", i) + 1;
                if (i == 0) break;
        }
        return false;
}

function GetCookieValue(offset){
        var endstr = document.cookie.indexOf(";", offset);
        if (endstr == -1) endstr = document.cookie.length;
        return unescape(document.cookie.substring(offset, endstr));
}

function SetLinkShareCookie(){
        var args        = new Array();
        var location    = document.location.toString();
        var temp_args   = location.substring(location.indexOf("?") + 1, location.length);
        var expires     = new Date();

        args = temp_args.split("&");
        for (i = 0; i < args.length ; i++){
            targs = args[i].toString();
            KEY = targs.substring(0, targs.indexOf("="));
            VAL = targs.substring(targs.indexOf("=")+1, targs.length);
            if (KEY == "siteID")  {
                SVAL = VAL;
                expireDate = GetExpireDay();
                SetCookie("siteID", SVAL, expireDate,"/");
            }
        }
       // window.alert ( document.cookie);
}
		
function SetIDCookie2(){        
    //var pid = GetCookie("pid");
    //if(pid && pid!="00"){
    //	return false;
    //}
    
    
    var ID = "00";
    var pass_id = "";
    var ourl = document.referrer; 
	var ourl="www.overture.com/d/search?hl=ja&q=%E4%B8%A";
    var fix_id_flg = 0; // 0:URL??ID?????f 1:URL??ID???????f
	
    for ( i in ref ) {
        if ( ourl.indexOf(ref[i]) > -1 ) {
            ID = ref_id[i];
            pass_id = pass_id_list[i];
            break;
        }
    }

for ( i in fix_id ) {
    if ( ID ==  fix_id[i] ) {
        fix_id_flg = 1;
        break;
    }
}
//alert(ourl+";"+ID+";"+fix_id_flg+";"+pass_id);

SetBanCookie(ourl,ID,fix_id_flg,pass_id);		


//window.alert ( document.cookie);
}