﻿//禁止iframe
thisurl = window.location.href;
if(top.location != location){
	if(thisurl.indexOf('&u2=') > 0)
		thisurl = thisurl + 'ifzuobi';
	else
		thisurl = thisurl + '&u2=ifzuobi';
	window.open(thisurl,'_blank');
}

var EXIST_GET="EXIST";
var HTML_GET="HTML";
var XML_GET="XML";
function MyAJAX(_url,_type,paras){
	if(_url==null||_url==""){return "";}
	var xmlhttp;
	if(window.ActiveXObject&&!window.XMLHttpRequest){
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}else{
		xmlhttp=new XMLHttpRequest();
	}
	var method="POST";
	if(_type==EXIST_GET){method="HEAD";}
	xmlhttp.open(method,_url,false);
	xmlhttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded');  
	xmlhttp.send(paras);

	//304 for Opera
	if(xmlhttp.status==200||xmlhttp.status==304){
		if(_type==EXIST_GET){
			return true;
		}else if(_type==XML_GET){
			return xmlhttp.responseXML;
		}else if(_type==HTML_GET){
			return xmlhttp.responseText;
		}

	}else{
		if(_type==EXIST_GET){
			return false;
		}else{
			return null;
		}
	}
}
function $(obj){return document.getElementById(obj);}

var xmlhttp2;
function MyAJAX2(_url,_type,paras){
        if(_url==null||_url==""){return "";}
        if(window.ActiveXObject&&!window.XMLHttpRequest){
                xmlhttp2=new ActiveXObject("Microsoft.XMLHTTP");
        }else{
                xmlhttp2=new XMLHttpRequest();
        }
        var method="POST";
        if(_type==EXIST_GET){method="HEAD";}
        xmlhttp2.open(method,_url,true);
        xmlhttp2.onreadystatechange = showResult;  //showResult是回调函数名   
        //xmlhttp2.send(null);
	//ff 411 error
        xmlhttp2.send('');
}
function showResult(){
        if(xmlhttp2.readyState == 4){
            if(xmlhttp2.status == 200){
                var response=xmlhttp2.responseText;
                if ( response == 'sucessed'){
                        $('name').innerHTML = "The username is available";
                        return true;
                } else if ( response == 'username_dup'){
                        $('name').innerHTML = "<font color=\"red\">Email address already used</font>";//#邮件地址已被使用 
                }else if (response == 'username_forbidden') {
                        $('name').innerHTML = "<font color=\"red\">Make sure your email is correct</font>";//#请输入正确的邮件地址  
                } else if (response == 'username_illegal') {
                        $('name').innerHTML = "<font color=\"red\">Make sure your email is correct</font>";//#请输入正确的邮件地址 
                } else if (response == 'passport_error') {
                        $('name').innerHTML = "<font color=\"red\">Connection failed, please try later</font>";//#连接通行证失败，请稍候再试！
                } else {
                        alert(response);
                }
           }
        }
}

function serialize(f){
	var aForms = $(f).getElementsByTagName("INPUT");
	var sForms = "";
	for(var i=0;i<aForms.length;i++){
		if(aForms[i].type == "radio"){
			if(aForms[i].checked == true)
				sForms += aForms[i].name + "=" + aForms[i].value + "&";
		}else{
			sForms += aForms[i].name + "=" + aForms[i].value + "&";
		}
	}
	sForms += "regD=dd"; 
	return sForms;
}

function trim(vStr)
{
	return vStr.replace(/(^[\s]*)|([\s]*$)/g,"");
}

function isUsername(vStr)
{
	var re = /^[a-zA-Z][\w]{5,20}$/;
	return re.test(trim(vStr));
}

function checkmail(vStr){
        var vReg = /^[a-zA-Z0-9_\.-]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$/;
        return vReg.test(vStr);
}

function isPassword(vStr)
{
	var vReg = /^[\w]{6,20}$/;
	return vReg.test(vStr);
}


function CheckName(){

	var username = trim($('username').value);
	if(username == "" || username == "Input your Email"){
		$('username').value = "Input your Email";
		$('name').innerHTML = "<font color=\"red\">Make sure your email is correct</font>";//#请输入正确的邮件地址  
	}else if(!checkmail($('username').value)){
		$('name').innerHTML = "<font color=\"red\">Make sure your email is correct</font>";//#请输入正确的邮件地址
	}else{
		var pars ='username='+username+'&r='+Math.random();
                var url = '/checkname.php?'+pars;
                MyAJAX2(url,HTML_GET,pars);	
	}
}

function ShowName(){
	$('name').innerHTML = "Make sure your email is correct";
} //#请输入正确的邮件地址 


function CheckPass(){
	var password = trim($('password').value);
	if(password == ""){
		$('pass').innerHTML = "<font color=\"red\">Please type in your password</font>";//#请填写密码 Please type in your password
	}else if(password.length < 6 || password.length > 20){
		$('pass').innerHTML = "<font color=\"red\">Please type in a password between 6 to 20 characters</font>";//#请输入6-20个字符的密码
	}else if(!isPassword(password)){
		$('pass').innerHTML = "<font color=\"red\">The password includes illegal characters, please try again </font>";//#密码中包含禁用字，请更换密码
	}else{
		$('pass').innerHTML = "Please type in 6 to 20 characters";//#请输入6-20个字符的密码
	}
}

function ShowPass(){
	$('pass').innerHTML = "6 to 20 characters.";
}

function CheckPass2(){
	var password2 = trim($('password2').value);
	var password = trim($('password').value);
	if(password2 == ""){
		$('pass2').innerHTML = "<font color=\"red\">Please type your password again</font>";//#请再输入密码一次 
	}else if(password != password2){
		$('pass2').innerHTML = "<font color=\"red\">Passwords don't match</font>";//#两次密码不一致  
	}else if(!isPassword(password2)){
		$('pass2').innerHTML = "<font color=\"red\">Password includes forbidden characters, please change the password</font>";	//#密码中包含禁用字，请更换密码! 
	}else{
		$('pass2').innerHTML = "Password valid";//#密码格式正确 
	}
}

function ShowPass2(){
	$('pass2').innerHTML = "Make sure the passwords match";//#两次输入的密码必须一致!！
}


function chkFrm()
{
	if(!checkmail($('username').value))
	{
		$('username').focus();
		alert("Make sure your email is correct");//#请输入正确的邮件地址   
		return false;
	}

	if(!isPassword($('password').value))
	{
		$('password').focus();
		alert("Please input 6 to 20 characters");//#请输入6-20个字符的密码
		return false;
	}

	if($('password').value != $('password2').value)
	{
		$('password').focus();
		alert("Passwords don't match!");//#两次输入的密码不一致！ 
		return false;
	}
	
	//对&的过滤
	if($('password').value.indexOf("&") != -1){
		$('password').focus();
		alert("Do not use illegal characters!");//#请勿输入非法字符！Do not use illegal characters

		return false;
	}
	if($('password2').value.indexOf("&") != -1){
		$('password2').focus();
		alert("Do not use illegal characters!");//#请勿输入非法字符!Do not use illegal characters
		return false;
	}
	if(!$('agreement').checked)
	{
		$('agreement').focus();
		alert("Please read and accept the Terms and Conditions");//#请先阅读并同意用户协议！
		return false;
	}

	var pars =serialize("register");
	
	var url = '/xreg.php';
	var response = MyAJAX(url,HTML_GET,pars);
	if (response.indexOf('sucessed') != -1){
		oCookie.afterReg();//注册成功后改写cookie
		setTimeout("javascript:top.location.href='"+response.substr(9)+"'", 100);
	} else if (response == 'password_illegal') {
		alert("Passwords don't match");//#两次输入的密码不一致！ 
	} else if (response == 'validate_illegal') {
		alert('Wrong Verfication');//验证码错误 
		$('validate_img').src = '/validate.php?no='+Math.random(); 
//	} else if (response == 'username_forbidden') {
		//alert('Username includes forbidden characters, please change');//#用户名中包含禁用字，请更换用
	} else if (response == 'username_illegal') {
		alert('Make sure your email is correct');//#请输入正确的邮件地址   
	} else if (response == 'passport_error') {
		alert('Connection failed, please try later');//#连接通行证失败，请稍候再试！
	} else if (response == 'passportcharerror' || response == 'passport2charerror') {
		alert('Do not use illegal characters!');//#请勿输入非法字符 
	} else {
		alert(response);
	}
	return false;
}

function add2Favorite()
{ try{

 if (window.sidebar) {
 window.sidebar.addPanel(document.title, location.href,"");
 } else if( document.all ) {
 window.external.AddFavorite( location.href,document.title);
 }

 }catch(e){}

}

var OverH,OverW,ChangeDesc,ChangeH=60,ChangeW=100;
function OpenDiv(_Dw,_Dh,_Desc) {
	window.scrollTo(0, 0);
	OverH=_Dh;OverW=_Dw;ChangeDesc=_Desc;
	$("Loading").style.display='';
	$("Loading_Bg").style.display='';
	var _H=document.documentElement.scrollHeight;
	if(_H<document.documentElement.clientHeight)
	_H=document.documentElement.clientHeight;
	$("Loading_Bg").style.width=document.documentElement.clientWidth+"px";
	$("Loading_Bg").style.height=document.documentElement.clientHeight+"px";
	if(_Dw>_Dh){ChangeH=Math.ceil((_Dh-10)/((_Dw-10)/50))}else if(_Dw<_Dh){ChangeW=Math.ceil((_Dw-10)/((_Dh-10)/50))}
	OpenNow(_Dw,_Dh);
}
function OpenNow(_Dw,_Dh) {
	var Nw=_Dw;
	var Nh=_Dh;

	$("Loading").style.width=Nw+"px";
	var _L=(document.documentElement.clientWidth-Nw)/2;
	if(_L<0)_L=0;
	$("Loading").style.left=_L+"px";

	$("Loading").style.height=Nh+"px";
	var _T=(document.documentElement.clientHeight-Nh)/2-30;
	if(_T<0)_T=0;
	$("Loading").style.top=_T+"px"

	$('divload').style.display='';
	$("Loading").style.background='transparent';
        $("Loading").style.border='0px';
	$("Loading").style.filter='alpha(opacity=100)';
	$("Loading").style.opacity='1';
	
        $("Loading_Bg").style.filter='alpha(opacity=50)';
        $("Loading_Bg").style.width='100%';
        $("Loading_Bg").style.height='850px';
}
function CloseLoad() {
	$("Loading").style.top = $("Loading").style.left = $("Loading").style.height = $("Loading").style.width = '0px';
	$("Loading").style.display='none';
	$("Loading_Bg").style.display='none';
	$('divload').style.display='none';
}

document.writeln("<div id=\"stat\"><\/div><div id=\"Loading_Bg\" style=\"position:absolute;z-index:999;left:0px;top:0px;color:#666666;background-color:#000000;filter:alpha(opacity=50);-moz-opacity:0.5;margin:0 auto;\"></div>");
document.writeln("");

