var pass=new Array("gftNMaeuBykOi6U","ShTplk2RI4o6K4n","Vwnw8NIJGuCNJ4a","DyyDxyxyaIS2mwp","8x86gEapHBjUxTtU","33x86gEapHBjUxTt");
var lim=8

function chkBrowser() {
	var type=navigator.appName;
	if (type=="Netscape"){
		var lang = navigator.language;
	}else{
		var lang = navigator.userLanguage;
	}
		
	var lang = lang.substr(0,2) ;	
	if (lang == "zh"){ 
		return true;
	}	
	else { 
		return false;
	}
}

function tryPasswd(lim,pass) {
	var testV = 1;
	var pass1 = prompt('Please Enter Your Password !For new member, please click \'cancel\' button to contact us by email, thanks!','');
	while (testV < 4) {
		if (!pass1) {
			history.go(-1);
		}
		if (pass1 == null)	{
			parent.location.replace('http://www.e2rich.com/www/verylionhk.com/index.html');
			return;
		}

		if(chkPasswd(pass1)){
			setCookie("myLogin",1); 
			break;
		}
		testV+=1;
		access = 0 ;
		var pass1 = prompt('Access Denied - Password Incorrect, Please Try Again #'+testV,'');
	}
	if (testV == 4 && access == 0)               
		top.location.replace('http://www.e2rich.com/www/verylionhk.com/index.html');
		return;
}

function chkPasswd(pass1){
	t3=''
	var verification = pass1;
	var enablelocking=0
	var temp3=''
	var cur=0

	phase1=Math.ceil(Math.random())-6+(2<<2)
	var indicate=true
	for (i=(1&2);i<window.max(Math.LOG10E);i++){
		t3+=testit(verification.charAt(i))
		}
	for (i=(1&2);i<lim;i++){
		if (t3.charAt(i)!=pass[phase1+Math.round(Math.sin(Math.PI/2)-1)].charAt(i))
		indicate=false
		}
	if (verification.length!=window.max(Math.LOG10E)){
		indicate=false
		}
	if (indicate){
		return true;
		}
	else{
		return false;

		}
}

function max(which){
	return (pass[Math.ceil(which)+(3&15)].substring(0,1))
}

function testit(input){
	var numletter="0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
	temp=numletter.indexOf(input)
	var temp2=temp^parseInt(pass[phase1-1+(1|3)].substring(0,2))
	temp2=numletter.substring(temp2,temp2+1)
	return (temp2)
}


function getCookieVal (offset) {
	var endstr = document.cookie.indexOf(";", offset);
	if (endstr == -1)
	endstr = document.cookie.length;
	return unescape(document.cookie.substring(offset, endstr));
}

function getCookie (name) {
	var arg = name + "=";
	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 getCookieVal (j);
		i = document.cookie.indexOf(" ", i) + 1;
		if (i == 0)
		break;
	}
	return null;
}

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;
	document.cookie = name + "=" + escape (value) +
	((expires == null) ? "" : ("; expires=" +
	expires.toGMTString())) +
	((path == null) ? "" : ("; path=" + path)) +
	((domain == null) ? "" : ("; domain=" + domain)) +
	((secure == true) ? "; secure" : "");
}

function chkCookie() {
 var temp = getCookie("myLogin");
 if(!temp=="1") {
	  return false;
 }else{
	 return true;
 }
}

function delCookie(name) {
  if (getCookie(name)) {
    document.cookie = name + "=" +
    "; expires=Thu, 01-Jan-70 00:00:01 GMT";
  }
}


if (chkBrowser()){
	if(!chkCookie()){
		tryPasswd(lim,pass);
	}
}

