//用户登录
function user_login()
{	

	if(document.login_form.user_name.value == "")
	{
		window.alert ("Please enter the user name！")
		document.login_form.user_name.focus();
		return false;
	}

	if (document.login_form.user_pwd.value == "")
	{
		window.alert ("Please enter password！")
		document.login_form.user_pwd.focus();
		return false;
	}
	
	return true;
	
}

//用户注册
function user_reg()
{		
	var reg= /^[\w-]+(\.[\w-]+)*@[\w-]+(\.[\w-]+)+$/;
	var mail=document.action_form.user_mail.value;


	if(document.action_form.user_name.value == "")
	{
		window.alert ("请输入用户名！")
		document.action_form.user_name.focus();
		return false;
	}

	if (document.action_form.user_pwd.value == "")
	{
		window.alert ("请输入密码！")
		document.action_form.user_pwd.focus();
		return false;
	}
	if (document.action_form.user_pwd1.value == "")
	{
		window.alert ("请重复输入密码！")
		document.action_form.user_pwd1.focus();
		return false;
	}
	
	if (document.action_form.user_pwd.value != "" && document.action_form.user_pwd.value.length < 6  )
	{
		window.alert ("输入密码的不能少于6个字节！")
		document.action_form.user_pwd.focus();
		return false;
	}
	
	if (document.action_form.user_pwd.value != document.action_form.user_pwd1.value)
	{
		window.alert ("你2次输入的密码不相同！")
		document.action_form.user_pwd.focus();
		return false;
	}
	

	if (document.action_form.user_true_name.value == "")
	{
		window.alert ("请输入真实姓名！")
		document.action_form.user_true_name.focus();
		return false;
	}	
	
	if (mail != '')
	{
    	if(reg.test(mail) == false)
		{
			window.alert("你输入的E-mail地址不正确,请重新输入！");
			document.action_form.user_mail.focus();
			return false;
		}
	}else
	{
		window.alert ("请输入E-mail地址！")
		document.action_form.user_mail.focus();
		return false;
	}
	
	if (document.action_form.user_mail_bk.value != '')
	{
    	if(reg.test(document.action_form.user_mail_bk.value) == false)
		{
			window.alert("你输入的E-mail地址不正确,请重新输入！");
			document.action_form.user_mail_bk.focus();
			return false;
		}
	}
	
	if (document.action_form.vcode.value == "")
	{
		window.alert ("请输入验证码！")
		document.action_form.vcode.focus();
		return false;
	}
	
	return true;
	
}

//用户修改
function user_edit()
{		
	var reg= /^[\w-]+(\.[\w-]+)*@[\w-]+(\.[\w-]+)+$/;
	var mail=document.action_form.user_mail.value;


	if (document.action_form.check_pwd.value == "")
	{
		window.alert ("请输入原密码！")
		document.action_form.check_pwd.focus();
		return false;
	}

	if (document.action_form.user_pwd.value != "" && document.action_form.user_pwd.value.length < 6  )
	{
		window.alert ("输入密码的不能6个字节！")
		document.action_form.user_pwd.focus();
		return false;
	}
	if (document.action_form.user_pwd.value != document.action_form.user_pwd1.value)
	{
		window.alert ("你2次输入的密码不相同！")
		document.action_form.user_pwd.focus();
		return false;
	}
	
	if (document.action_form.user_true_name.value == "")
	{
		window.alert ("请输入真实姓名！")
		document.action_form.user_true_name.focus();
		return false;
	}	
	
	
	if (mail != '')
	{
    	if(reg.test(mail) == false)
		{
			window.alert("你输入的E-mail地址不正确,请重新输入！");
			document.action_form.user_mail.focus();
			return false;
		}
	}else
	{
		window.alert ("请输入E-mail地址！")
		document.action_form.user_mail.focus();
		return false;
	}
	
	if (document.action_form.user_mail_bk.value != '')
	{
    	if(reg.test(document.action_form.user_mail_bk.value) == false)
		{
			window.alert("你输入的E-mail地址不正确,请重新输入！");
			document.action_form.user_mail_bk.focus();
			return false;
		}
	}
	
	
	return true;
	
}



function search_check(root_url)
{
	if(document.search_form.search_key.value == "")
	{
		window.alert ("请输入要查询的内容！")
		document.search_form.search_key.focus();
		return false;  
	}
	
	if(document.search_form.type.value == "5")
	{
		//文件搜索
		document.search_form.action=root_url+"modules/file_list.php";
		document.search_form.submit();
	}else
	{
		//文章搜索
		document.search_form.action=root_url+"modules/article_list.php";
		document.search_form.submit();
	}
	return true;
}


function reply_check()
{
	if(document.reply_form.reply_title.value == "")
	{
		window.alert ("请输入标题！")
		document.reply_form.reply_title.focus();
		return false;  
	}
	
	if(document.reply_form.reply_user_name.value == "")
	{
		window.alert ("请输入用户名！")
		document.reply_form.reply_user_name.focus();
		return false;  
	}
	
	if(document.reply_form.reply_content.value == "")
	{
		window.alert ("请输入评论内容！")
		document.reply_form.reply_content.focus();
		return false;  
	}
	if (document.reply_form.vcode.value == "")
	{
		window.alert ("请输入验证码！")
		document.reply_form.vcode.focus();
		return false;
	}
	return true;
}

// Add by Samuel 200807
function apply_check()
{
	//alert("xxx");
	//return false;
	if(document.action_form.apply_position.value == "")
	{
		window.alert ("Please input the position！")
		document.action_form.apply_position.focus();
		return false;  
	}
	if(document.action_form.apply_user.value == "")
	{
		window.alert ("Please input your name！")
		document.action_form.apply_user.focus();
		return false;  
	}
	if(document.action_form.apply_school.value == "")
	{
		window.alert ("Please input your graduate academies！")
		document.action_form.apply_school.focus();
		return false;  
	}
	if(document.action_form.apply_degree.value == "")
	{
		window.alert ("Please input your school age！")
		document.action_form.apply_degree.focus();
		return false;  
	}
	if(document.action_form.apply_specialty.value == "")
	{
		window.alert ("Please input your specialty！")
		document.action_form.apply_specialty.focus();
		return false;  
	}
	if(document.action_form.apply_phone.value == "")
	{
		window.alert ("Please input your contact phone！")
		document.action_form.apply_phone.focus();
		return false;  
	}
	
	if(document.action_form.apply_mail.value == "")
	{
		window.alert ("Please input your contact E-mail！")
		document.action_form.apply_mail.focus();
		return false;  
	}
	if(document.action_form.apply_skill.value == "")
	{
		window.alert ("Please input your advantage！")
		document.action_form.apply_skill.focus();
		return false;  
	}
	if(document.action_form.apply_intro.value == "")
	{
		window.alert ("Please input your resume！")
		document.action_form.apply_intro.focus();
		return false;  
	}
	
	return true;
}

function stringEmpty ( address ) {
    // CHECK THAT THE STRING IS NOT EMPTY
    if ( address.length < 1 ) {
        return ( true );
    } else {
        return ( false );
    }
}

function noAtSign ( address ) {
    // CHECK THAT THERE IS AN '@' CHARACTER IN THE STRING
    if ( address.indexOf ( '@', 0 ) == -1 ) {
        return ( true )
    } else {
        return ( false );
    }
}

function nothingBeforeAt ( address ) {
    // CHECK THERE IS AT LEAST ONE CHARACTER BEFORE THE '@' CHARACTER
    if ( address.indexOf ( '@', 0 ) < 1 ) {
        return ( true )
    } else {
        return ( false );
    }
}

function noLeftBracket ( address ) {
    // IF EMAIL ADDRESS IN FORM 'user@[255,255,255,0]', THEN CHECK FOR LEFT BRACKET
    if ( address.indexOf ( '[', 0 ) == -1 && address.charAt ( address.length - 1 ) == ']' ) {
        return ( true )
    } else {
        return ( false );
    }
}

function noRightBracket ( address ) {
    // IF EMAIL ADDRESS IN FORM 'user@[255,255,255,0]', THEN CHECK FOR RIGHT BRACKET
    if ( address.indexOf ( '[', 0 ) > -1 && address.charAt ( address.length - 1 ) != ']' ) {
        return ( true );
    } else {
        return ( false );
    }
}

function noValidPeriod ( address ) {
    // IF EMAIL ADDRESS IN FORM 'user@[255,255,255,0]', THEN WE ARE NOT INTERESTED
    if ( address.indexOf ( '@', 0 ) > 1 && address.charAt ( address.length - 1 ) == ']' )
        return ( false );

    // CHECK THAT THERE IS AT LEAST ONE PERIOD IN THE STRING
    if ( address.indexOf ( '.', 0 ) == -1 )
        return ( true );

    return ( false );
}

function noValidSuffix ( address ) {
    // IF EMAIL ADDRESS IN FORM 'user@[255,255,255,0]', THEN WE ARE NOT INTERESTED
    if ( address.indexOf ( '@', 0 ) > 1 && address.charAt ( address.length - 1 ) == ']' )
        return ( false );

    // CHECK THAT THERE IS A TWO OR THREE CHARACTER SUFFIX AFTER THE LAST PERIOD
    var len = address.length;
    var pos = address.lastIndexOf ( '.', len - 1 ) + 1;
    if ( ( len - pos ) < 2 || ( len - pos ) > 3 ) {
        return ( true );
    } else {
        return ( false );
    }
}

function checkValidation (straddressField) {
	var returnstr ="";
    if ( stringEmpty (straddressField) )
        returnstr = "There is no E-Mail address entered.";
    else if ( noAtSign (straddressField) )
        returnstr = "The E-Mail address does not contain an '@' character.";
    else if ( nothingBeforeAt (straddressField) )
        returnstr = "An E-Mail address must contain at least one character before the '@' character.";
    else if ( noLeftBracket (straddressField) )
        returnstr = "The E-Mail address contains a right square bracket ']',\nbut no corresponding left square bracket '['.";
    else if ( noRightBracket (straddressField) )
        returnstr = "The E-Mail address contains a left square bracket '[',\nbut no corresponding right square bracket ']'.";
    else if ( noValidPeriod (straddressField) )
        returnstr = "An E-Mail address must contain a period ('.') character.";
    else if ( noValidSuffix (straddressField) )
        returnstr = "An E-Mail address must contain a two or three character suffix.";
    else
        returnstr = "";
    return (returnstr);
}
// End of Add by Samuel 200807

function feedback_check()
{
	if(document.action_form.ad_user_firstname.value == "")
	{
		window.alert ("Please enter first name！")
		document.action_form.ad_user_firstname.focus();
		return false;  
	}
	
	if(document.action_form.ad_user_lastname.value == "")
	{
		window.alert ("Please enter last name！")
		document.action_form.ad_user_lastname.focus();
		return false;  
	}
	
	if(document.action_form.ad_user_company.value == "")
	{
		window.alert ("Please enter company！")
		document.action_form.ad_user_company.focus();
		return false;  
	}
	
	if(document.action_form.ad_country.value == "")
	{
		window.alert ("Please select your country！")
		document.action_form.ad_country.focus();
		return false;  
	}
	
	if(document.action_form.ad_mail.value == "")
	{
		window.alert ("Please enter your E-mail！")
		document.action_form.ad_mail.focus();
		return false;  
	}
	else
	{
		var ErrorMessage = '';
		ErrorMessage = checkValidation (document.action_form.ad_mail.value);
		if (ErrorMessage.length > 0) 
		{
			window.alert (ErrorMessage);
			document.action_form.ad_mail.focus();
			return false;  
		}
	}
	if(document.action_form.market.value == "")
	{
		window.alert ("Please select the market！")
		document.action_form.market.focus();
		return false;  
	}

/* 
// Comment by Samuel 200807
	if(document.action_form.ad_user.value == "")
	{
		window.alert ("Please enter your name！")
		document.action_form.ad_user.focus();
		return false;  
	}
	
	//if(document.action_form.ad_phone.value == "")
	//{
		//window.alert ("Please enter your phone！")
		//document.action_form.ad_phone.focus();
		//return false;  
	//}
	
	if(document.action_form.ad_mail.value == "")
	{
		window.alert ("Please enter your E-mail！")
		document.action_form.ad_mail.focus();
		return false;  
	}
	if(document.action_form.ad_content.value == "")
	{
		window.alert ("Please enter the content！")
		document.action_form.ad_content.focus();
		return false;  
	}
*/	
	return true;
}


function distr_check()
{
	if(document.action_form.ad_user.value == "")
	{
		window.alert ("Please enter contact person！")
		document.action_form.ad_user.focus();
		return false;  
	}
	
	if(document.action_form.ad_country.value == "")
	{
		window.alert ("Please select your country！")
		document.action_form.ad_country.focus();
		return false;  
	}
	
	if(document.action_form.ad_mail.value == "")
	{
		window.alert ("Please enter your E-mail！")
		document.action_form.ad_mail.focus();
		return false;  
	}
	if(document.action_form.market.value == "")
	{
		window.alert ("Please select the market！")
		document.action_form.market.focus();
		return false;  
	}

	return true;
}

function contact_check()
{
	if(document.action_form.ad_user.value == "")
	{
		window.alert ("Please enter your name！")
		document.action_form.ad_user.focus();
		return false;  
	}
	
	//if(document.action_form.ad_phone.value == "")
	//{
		//window.alert ("Please enter your phone！")
		//document.action_form.ad_phone.focus();
		//return false;  
	//}
	
	if(document.action_form.ad_mail.value == "")
	{
		window.alert ("Please enter your E-mail！")
		document.action_form.ad_mail.focus();
		return false;  
	}
	if(document.action_form.ad_content.value == "")
	{
		window.alert ("Please enter the content！")
		document.action_form.ad_content.focus();
		return false;  
	}

	return true;
}
