// 1 for true and 0 for false
CNAME_ID = "china5000ID";
CNAME_Pass = "china5000idpass";
CNAME_SayHello = "china5000sayhello";
CNAME_PublicComputer = "china5000publiccomputer";

IDChecker_CGI = "/china5000idlist.pl?Certify_ID=";
IDChecker_HTML = "/china5000id_check.html";
BBS_HTML = "/mei10.htm";
Hello_HTML = "/index2.html";

function readCookie(cookieName) {
	cookie_array = document.cookie.split ("; ")
	for (x=0; x < cookie_array.length; x++) {
		cookieParts_array = cookie_array[x].split("=")
		if (cookieParts_array[0] == cookieName) {
			return unescape(cookieParts_array[1]);
		}
	}
	return null;
}

function GetPublic()
{
	strPublic = readCookie(CNAME_PublicComputer);
	if ( strPublic )
		return parseInt(strPublic, 10);
	else
		return 1;
}

function GetID()
{
	return readCookie(CNAME_ID);
}

//	china5000id_check.html
function ClearCookies()
{
	expiresday = new Date();
	expiresday.setTime(expiresday.getTime()-1);
	document.cookie = CNAME_ID + "=;expires=" + expiresday.toGMTString();
	document.cookie = CNAME_Pass + "=;expires=" + expiresday.toGMTString();
	document.cookie = CNAME_SayHello + "=;expires=" + expiresday.toGMTString();
	document.cookie = CNAME_PublicComputer + "=;expires=" + expiresday.toGMTString();
}

function WriteID2Cookie(id, lifetime)
{
	expiresday = new Date();
	expiresday.setTime(expiresday.getTime() + lifetime*1000 );
	document.cookie = CNAME_ID + "=" + escape(id) + ";expires=" + expiresday.toGMTString();
}

function WritePass2Cookie(pass, lifetime)
{
	expiresday = new Date();
	expiresday.setTime(expiresday.getTime() + lifetime*1000 );
	document.cookie = CNAME_Pass + "=" + pass + ";expires=" + expiresday.toGMTString();
}

function WritePublic2Cookie(publiccomputer, lifetime)		
{
	expiresday = new Date();
	expiresday.setTime(expiresday.getTime() + lifetime*1000 );
	document.cookie = CNAME_PublicComputer + "=" + publiccomputer + ";expires=" + expiresday.toGMTString();
}

function WriteHello2Cookie(hello, lifetime)		
{
	expiresday = new Date();
	expiresday.setTime(expiresday.getTime() + lifetime*1000 );
	document.cookie = CNAME_SayHello + "=" + hello + ";expires=" + expiresday.toGMTString();
}

//	hello.html
function SayHello()		
{
	china5000netID = readCookie(CNAME_ID);
	if ( china5000netID )
		document.write("»¶Ó­Äã£¬" + china5000netID + "°àµÄÍ¬Ñ§£¡");
}

//  index.html
function ReadCookieAndCheckIt()		
{
	china5000netID = readCookie(CNAME_ID);
	if ( china5000netID )
	{
		nextpage = IDChecker_CGI + china5000netID;
		location = nextpage;
	}
	else
		location = IDChecker_HTML;
}

//	china5000id_error.html
function GoToIDChecker()		
{
	location = IDChecker_HTML;
}

//	index2.htm, called by hello.html
function GoToBBS()		
{
	location = BBS_HTML;
}

//	When ID pass, we should remember something.
function GotoHelloPage() 
{
	hello = readCookie(CNAME_SayHello);
	WriteHello2Cookie(1, 86400*31);	//  one month
	if ( hello )
		location = BBS_HTML;
	else	// first time, let us say hello
		location = Hello_HTML;
}

//  index1992.html, pass id checking.  publiccomputer = 1 or 0
function IDCheckingPass(publiccomputer) 
{
	china5000netID = readCookie(CNAME_ID);
	if ( china5000netID )
	{
		if ( publiccomputer == 1 )	// public computer
		{
			WriteID2Cookie(china5000netID, 3600);	//  one hour
			WritePass2Cookie(1, 86400);		//  one day
			WritePublic2Cookie("1", 86400*365);	//  one year
		}
		else
		{
			WriteID2Cookie(china5000netID, 86400*7);	//  one week
			WritePass2Cookie(1, 86400*31);		//  one month
			WritePublic2Cookie("0", 86400*365);	//  one year
		}
		GotoHelloPage();
	}
	else
		location = IDChecker_HTML;
}

