/*Date: 2009-03-13
**Author:zhangqulin
**Description:验证用户的company name
**Where To Use: about_company.html.erb页面
*/
var check_company_name_state=true;
function check_company_name(){
    var company_name = trim($F('company_name'))
    if(isNull(company_name)==true){
        $('company_name_isNull').className="display"
        $('company_label').addClassName('errorLabel');
        $('company_name_char_check').className="hide"
        $('company_name_length_check').className="hide"
        $('company_name_registered').className="hide"
        $('company_name_unregistered').className="hide"
        display_top_notice();
        return check_company_name_state=false;
    }
    if($F('company_name').length != company_name.length){
        $('company_name_char_check').className="display"
        $('company_name_registered').className="hide"
        $('company_name_unregistered').className="hide"
        $('company_name_isNull').className="hide"
        $('company_name_length_check').className="hide"
        $('company_label').addClassName('errorLabel');
        display_top_notice();
        return check_company_name_state=false;
    }
    for(var i=0;i<company_name.length;i++){
        var c = company_name.substr(i,1);
        var ts = escape(c);
        if(ts.substring(0,2) == "%u"){
            $F('company_name').value = "";
            $('company_name_char_check').className="display"
            $('company_name_registered').className="hide"
            $('company_name_unregistered').className="hide"
            $('company_name_isNull').className="hide"
            $('company_name_length_check').className="hide"
            $('company_label').addClassName('errorLabel');
            display_top_notice();
            return check_company_name_state=false;
        }
    }
    if(company_name.length <4 || company_name.length >100){
        $('company_name_length_check').className="display"
        $('company_name_registered').className="hide"
        $('company_name_char_check').className="hide"
        $('company_name_unregistered').className="hide"
        $('company_name_isNull').className="hide"
        $('company_label').addClassName('errorLabel');
        display_top_notice();
        return check_company_name_state=false;
    }
    var reg = /^[\w\d][\-\.\#\@\&\w\d\s]{2,}[\w\d\.]$/
    if(reg.test($F('company_name')) == false){
        $('company_name_char_check').className="display"
        $('company_name_registered').className="hide"
        $('company_name_unregistered').className="hide"
        $('company_name_isNull').className="hide"
        $('company_name_length_check').className="hide"
        $('company_label').addClassName('errorLabel');
        display_top_notice();
        return check_company_name_state=false;
    }

    $('company_name_char_check').className="hide"
    $('company_name_registered').className="hide"
    $('company_name_unregistered').className="hide"
    $('company_name_isNull').className="hide"
    $('company_label').removeClassName('errorLabel');
    $('company_name_length_check').className="hide"
    check_company_name_state = true;
    check_error_info();
    return check_company_name_state;
}
/*Date: 2009-03-13
**Author:zhangqulin
**Description:验证用户的company name
**Where To Use: about_company.html.erb页面
*/
function check_company_name_info(state){
    if (state){
        $('company_name_registered').className="display"
        $('company_name_unregistered').className="hide"
        $('company_name_length_check').className="hide"
        $('company_name_isNull').className="hide"
        $('company_name_char_check').className="hide"
        display_top_notice();
        check_company_name_state=false;
    }else{
        $('company_name_registered').className="hide"
        $('company_name_unregistered').className="display"
        $('company_name_length_check').className="hide"
        $('company_name_isNull').className="hide"
        $('company_name_char_check').className="hide"
        display_top_info_right();
        check_error_info();
        check_company_name_state=true;
    }
}

/*Date: 2009-03-13
**Author:zhangqulin
**Description:验证用户的address name
**Where To Use: about_company.html.erb页面
*/
function address_onblur(){
    var company_address = trim($F('company_address'))
    if(isNull($F('company_address'))== false && $F('company_address').length != company_address.length)
    {
        $('company_address_isNull').className="hide"
        $('company_address_char_check').className="display"
        $('address_label').addClassName('errorLabel');
        display_top_notice();
        return false;
    }
    $('company_address_isNull').className="hide"
    $('company_address_char_check').className="hide"
    $('address_label').removeClassName('errorLabel');
    check_error_info();
    return true;
}

/*Date: 2009-03-13
**Author:zhangqulin
**Description:验证用户的city
**Where To Use: about_company.html.erb页面
*/
function city_onblur(){
    return true;
}

/*Date: 2009-03-13
**Author:zhangqulin
**Description:验证用户填入的country
**Where To Use: about_company.html.erb页面
*/
function country_onblur(){
    var company_country = trim($F('company_country'))
    if(isNull(company_country)==true){
        $('country_isNull').className="display"
        $('country_label').addClassName('errorLabel');
        display_top_notice();
        return false;
    }
    $('country_isNull').className="hide"
    $('country_label').removeClassName('errorLabel');
    check_error_info();
    return true;
}

/*Date: 2009-03-13
**Author:zhangqulin
**Description:验证phone中用户填入的country code
**Where To Use: about_company.html.erb页面
*/
function country_code_onblur(){
    if(isNumber($F('phone_country_code')) == false )
    {
        $('phone_error_info').className ="display";
        $('error_info_by_country_code').className="hide"
        $('phone_country_code_label').addClassName('errorLabel');
        $('phone_country_code_label').removeClassName('white_font');
        $('phone_country_code').value = "";
        display_top_notice();
        return false;
    }
    phone_info_clear();
    $('phone_country_code_label').removeClassName('errorLabel');
    $('phone_country_code_label').addClassName('white_font');
    check_error_info();
    return true;
}

/*Date: 2009-03-13
**Author:zhangqulin
**Description:验证phone中用户填入的area code
**Where To Use: about_company.html.erb页面
*/
function area_code_onblur(){
    if(country_code_onblur()==false){
        return false;
    }
    if(isNumber($F('phone_area_code')) == false){
        $('phone_error_info').className ="display";
        $('error_info_by_area_code').className="hide"
        $('phone_area_code_label').addClassName('errorLabel');
        $('phone_area_code_label').removeClassName('white_font');
        $('phone_area_code').value = "";
        display_top_notice();
        return false;
    }
    phone_info_clear();
    $('phone_area_code_label').removeClassName('errorLabel');
    $('phone_area_code_label').addClassName('white_font');
    check_error_info();
    return true;
}

/*Date: 2009-03-13
**Author:zhangqulin
**Description:验证phone中用户填入的phone_number
**Where To Use: about_company.html.erb页面
*/
function phone_number_onblur(){
    if(country_code_onblur()==false){
        return false;
    }
    if(area_code_onblur()==false){
        return false;
    }
    if( isNumber($F('phone_telephone')) == false){
        $('phone_error_info').className ="display";
        $('error_info_by_phone_number').className="hide"
        $('phone_number_label').addClassName('errorLabel');
        $('phone_number_label').removeClassName('white_font');
        $('phone_telephone').value = "";
        display_top_notice();
        return false;
    }

    phone_info_clear();
    $('phone_number_label').removeClassName('errorLabel');
    $('phone_number_label').addClassName('white_font');
    check_error_info();
    return true;
}

/*Date: 2009-03-13
**Author:zhangqulin
**Description:验证phone后的清理
**Where To Use: about_company.html.erb页面
*/
function phone_info_clear(){
    $('error_info_by_country_code').className="hide"
    $('error_info_by_area_code').className="hide";
    $('error_info_by_phone_number').className="hide";
    $('phone_error_info').className ="hide";
}

/*Date: 2009-03-13
**Author:zhangqulin
**Description:验证用户填入的postal
**Where To Use: about_company.html.erb页面
*/
function postal_onblur(){
    if( isNumber($F('company_postal_code')) == false){
        $('error_info_for_postal').className="display";
        $('postal_label').addClassName('errorLabel');
        $('company_postal_code').value = "";
        display_top_notice();
        return false;
    }
    else{
        $('error_info_for_postal').className="hide";
    }

    $('error_info_for_postal').className="hide";
    $('postal_label').removeClassName('errorLabel');
    check_error_info();
    return true;
}

/*Date: 2009-03-13
**Author:zhangqulin
**Description:验证fax中用户填入的country code
**Where To Use: about_company.html.erb页面
*/
function fax_onblur_country(){
    if( isNumber($F('fax_country_code')) == false){
        $('error_info_for_fax').className="display";
        $('fax_label').addClassName('errorLabel');
        $('fax_country_code').value = "";
        display_top_notice();
        return false;
    }
    $('error_info_for_fax').className="hide";
    $('fax_label').removeClassName('errorLabel');
    check_error_info();
    return true;
}

/*Date: 2009-03-13
**Author:zhangqulin
**Description:验证fax中用户填入的area code
**Where To Use: about_company.html.erb页面
*/
function fax_onblur_area(){
    if(fax_onblur_country()==false)return false;
    if(isNumber($F('fax_area_code')) == false){
        $('error_info_for_fax').className="display";
        $('fax_label').addClassName('errorLabel');
        $('fax_area_code').value = "";
        display_top_notice();
        return false;
    }
    $('error_info_for_fax').className="hide";
    $('fax_label').removeClassName('errorLabel');
    check_error_info();
    return true;
}

/*Date: 2009-03-13
**Author:zhangqulin
**Description:验证fax中用户填入的number
**Where To Use: about_company.html.erb页面
*/
function fax_onblur_register(){
    if(fax_onblur_country()==false)return false;
    if(fax_onblur_area()==false)return false;
    if(isNumber($F('fax_telephone')) == false){
        $('error_info_for_fax').className="display";
        $('fax_label').addClassName('errorLabel');
        $('fax_telephone').value = "";
        display_top_notice();
        return false;
    }
    $('error_info_for_fax').className="hide";
    $('fax_label').removeClassName('errorLabel');
    check_error_info();
    return true;
}

/*Date: 2009-03-13
**Author:zhangqulin
**Description:check all
**Where To Use: about_company.html.erb页面
*/
var checkSubmitFlg = false;
function checkAll(){
    if(!checkSubmitFlg){
        if( check_company_name()== true && address_onblur()== true &&country_onblur()== true&&country_code_onblur()== true &&
            area_code_onblur()==true && phone_number_onblur()==true && postal_onblur() == true &&
            fax_onblur_register() == true &&check_user_id()==true && pwd_onblur()==true &&
            pwd_confirm_onblur()==true && firstname_onblur()==true&& lastname_onblur()==true&& email_onblur()==true)
            {
            checkSubmitFlg = true;
            $('loading').className = "display";
            $('company_country').style.background = "#DBDBDB";
            $('user_title').disabled="true";
            $('user_title').style.background = "#DBDBDB";
            $('register_submit').style.color = "Gray";
            $('register_back').style.color = "Gray";
            $('top_info_right').className="hide"
            return true;
        }else{
            window.scrollTo(0, 185)
            $('loading').className = "hide";
            return false;
        }
    }else{
        return false;
    }
}
