﻿// JavaScript Document

/****获根据id获得节点****/
function $(id){
	return document.getElementById(id);
}
/****获根据name获得节点****/
function getByName(name){
	return document.getElementByName(name);
}

/*********判断输入法入是否为空并处理********/
function judgeEmpty(inputId, showId, otherId){
	var inputValue = $(inputId).value;
	if(inputValue == ""){		
		changeDisplayState(showId, "true");
		if(otherId != ""){changeDisplayState(otherId, "false");}
		return true;
	}
	return false;
}

/****验证电子邮箱地址****/
function validateEmailAddr(id){
	var emailAddress = $(id).value;
	var pattern = /^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+(.[a-zA-Z0-9_-])+$/;//XXX@XXX.XXX 才是合格的样式
	if(!pattern.test(emailAddress)){
		alert("请输入正确的邮箱地址");
	}
}

/****验证密码****/
function validatePassword(id){
	var inputValue = $(id).value;
	if(inputValue == ""){alert("密码不能为空");}
}

/****验证验证码是否正确****/
function validateCheckCode(id){
	$("checkCodeShowUtil").style.display = "";
	$(id).style.display = "";									
	$(id).onfocus = function b(){
		$("checkCodeShowUtil").style.display = "";
	}
}
/****验证验证码的显示***/
function changeCheckCodeState(inputId, showId){
	var isOverShow = true;
	var isInputBlur = true;						
	$(inputId).onfocus = function a(){
		isInputBlur = false;
		changeDisplayState(showId, "true");
	}
	$(inputId).onblur = function b(){
		isInputBlur = true;
		if(isInputBlur && isOverShow)changeDisplayState(showId, "false");
	} 
	$(showId).onmouseover = function c(){
		isOverShow = false;
	}
	$(showId).onmouseout = function d(){
		isOverShow = true;
		$(inputId).focus();
	}
}
/********根据类名改变样式*********/
function changeStyle(id, clName){
	$(id).className = clName;
}

/********返回空信息*********/
function isValueEmpty(id){
	if($(id) == null) return false;
	var inputValue = $(id).value;
	if(inputValue == ""){
		return true;
	}
	else {
		return false;
	}
}

/**********改变显示状态************/
function changeDisplayState(id, bln){
	if(bln == "true")$(id).style.display = ""; //显示
	else if(bln == "false")$(id).style.display = "none";//消失
	else if(bln == "auto"){ //状态翻转
		var eleState = $(id).style.display;
		if(eleState = "")$(id).style.display = "none";
		if(eleState = "none")$(id).style.display = "";
	}
}

/***buttom上的总开关***/									
function judgeFormEmpty(){
	var b1 = isValueEmpty("emailAddr");
	var b2 = isValueEmpty("registPW");
	var b3 = isValueEmpty('checkCode');
	if(document.getElementById('checkCode') != null) {
		b3 = isValueEmpty('checkCode');
	}else{
		b3 = false;
	}	
	if(b1 || b2 || b3){
		changeDisplayState("cvpwErrorUtil", "true");
		if($("ctl00_ctl00_ContentPlaceHolder_ModuleBody_ContentPlaceHolder1_LoginCtl_cvpwErrorPre") != null)
			changeDisplayState('ctl00_ctl00_ContentPlaceHolder_ModuleBody_ContentPlaceHolder1_LoginCtl_cvpwErrorPre', 'false');
	}else{
		changeDisplayState('cvpwErrorUtil', 'false');
		if($("ctl00_ctl00_ContentPlaceHolder_ModuleBody_ContentPlaceHolder1_LoginCtl_cvpwErrorPre") != null)
			changeDisplayState('ctl00_ctl00_ContentPlaceHolder_ModuleBody_ContentPlaceHolder1_LoginCtl_cvpwErrorPre', 'true'); 
		return false;
	}
	if(b1) {
		changeDisplayState("cvEmailEmptyShow", "true");
		return true;
	} else {
		changeDisplayState("cvEmailEmptyShow", "false");
	}
	if(b2) {
		changeDisplayState("cvPWEmptyShow", "true");
		return true;
	} else {
		changeDisplayState("cvPWEmptyShow", "false");
	}
	if(b3) {
		changeDisplayState('cvCCEmptyShow', 'true');
		return true;
	} else {
		changeDisplayState('cvCCEmptyShow', 'false');
	}
	return false;
}
                                  
function formSubmit(asId) {
	if(asId != "") {
		document.getElementById(asId).submit();
	}
}

function isExist(asId) {
	if(typeof document.getElementById(asId) == "undefined" && document.getElementById(asId) == "null") {
		return false;
	}
	else {
		return true;
	}
}

	var cvsi = 0;
    var secs = 80;
    var url = 'http://signup.myspace.cn/captcha.ashx?SecurityToken=&dl=11';
    //var tb = $('checkCode');//by yu 07.11
    var timerID = 0;
    function Refresh()
    {
	if($('checkCode') == null)return;//by yu 07.11
        $('checkCode').value = '';
        document.getElementById("CAPTCHAImage").src = url + "&r=" + ++cvsi;
        timerID = self.setTimeout("Refresh()", secs * 1000);
    }
     
    function StartTimer()
    {
        timerID = self.setTimeout("Refresh()", secs * 1000);
    }
    if($('checkCode') != null)StartTimer();
	function initTestUser()
	{
	    var testUserContent = $("TestUserContent")
	    testUserContent.style.display = "";	
	}
	var cap=1;
	//-->