// JavaScript Document
function checkID(username,type)
{
	var form = document.dataForm;
	if(username.length < 4 || username.length > 20)
	{
		alert("Member Username must be 4-20 characters.");
		form.username.focus();
		form.username.select();
		return false();
	}
	for(var i = 0; i < username.length; i++)
	{
		if(!((username.charAt(i) >= '0'&&username.charAt(i) <= '9')||(username.charAt(i) >= 'a'&&username.charAt(i) <='z')||(username.charAt(i) == '-')))
		{
			alert("Please use only lowercase letters(a-z) and numbers(0-9) for your Member Username.");
			form.username.focus();
			form.username.select();
			return false();
		}
	}
	if(type == 1)
	{
		window.open("CheckId.asp?username="+username, "newWin", "top=100,left=100,width=320 height=200,scrollbars=no,resizable=no");
	}
}

function categoryPopup(kind) 
{
    window.open("categoryPopup.asp?kind="+kind, "Category", "toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1,width=600,height=500,top=100,left=100");
}

function addCategory(object, code, text) {
    if (object.length > 5) {
        alert("You can choose from 1 to 5 categories.");
        return;
    }

    for (var i=0 ; i<object.length ; i++) {        // ???? ?¡À?? ????
        if (object.options[i].value == code) {
            alert("You have already chosen [" + text + "].");
            return;
        }
    }

    object.options[object.length] = new Option(text, code);
}
function removeCategory(object) {
    for (var i=0 ; i<object.length ; i++) {
        if (object.options[i].selected) object.options[i] = null;
    }
}
function textLimitCheck(thisArea, showArea, maxLength)
    {
        if (thisArea.value.length > maxLength)
        {
            alert(maxLength + ' characters limit. \rExcessive data will be truncated.');
            thisArea.value = thisArea.value.substring(0, maxLength);
            thisArea.focus();
        }
        showArea.innerText = thisArea.value.length;
   }

function is_filled(input_blank){
    while(input_blank.value.indexOf(" ") == 0)
        input_blank.value = input_blank.value.substring(1,input_blank.value.length);
    if((input_blank.value == "") || (input_blank.value == null)){
        return false;
    }
    else{
        return true;
    }
}
function checkForm() {
    var form = document.dataForm;
    var re = /^\s*$|\s{10,}/;
    if (!is_filled(form.pwd)) {
        alert("Sorry, Please input password!");
        form.pwd.focus();
        return false;
    }
    if (checkPasswd(form.pwd.value) == false)
        return false;

    if (!is_filled(form.verify)) {
        alert("Sorry, Input Re-enter password.");
        form.verify.focus();
        return false;
    }
    if (form.pwd.value != form.verify.value) {
        alert("Sorry, Please input same password!");
        form.verify.focus();
        return false;
    }
    
    if (!is_filled(form.username)) {
        alert("Sorry, This Username's length between in 4-20!");
        form.username.focus();
        return false;
    }

    if (checkID(form.username.value, 0) == false)
        return false;

    if (!is_filled(form.corporation)) {
        alert("Sorry, Please input company name!");
        form.corporation.focus();
        return false;
    }
    if (!is_filled(form.address)) {
        alert("Sorry, This Address's length between in 2-30!");
        form.address.focus();
        return false;
    }
    if (!is_filled(form.m_city)) {
        alert("Input City.");
        form.m_city.focus();
        return false;
    }
    if (!is_filled(form.country)) {
        alert("Sorry, Please input Country.");
        form.country.focus();
        return false;
    }
    if (!(is_filled(form.telephone))) {
        alert("Sorry, This Tel's length between in 7-30!");
        form.telephone.focus();
        return false;
    }
    if (!(is_filled(form.fax))) {
        alert("Sorry, Input Fax");
        form.fax.focus();
        return false;
    }
    var re1 = /^[0-9\-]*$/;
    if (!is_filled(form.introduction)) {
        alert("Sorry, Please input Company Descripion.");
        form.introduction.focus();
        return false;
    }
    if (form.introduction.value.length < 50) {
        alert("Descripion must be 50 characters at least.");
        form.introduction.focus();
        return false;
    }
    if (form.introduction.value.length > 2000) {
        form.introduction.value = form.introduction.value.substring(0,2000);
        alert("Descripion must be 2000 characters at most.");
        form.introduction.focus();
        return false;
    }
    if (form.introduction.value.match(re)) {
        alert("Input Description.(Don't input 10 or more blanks consecutively."); 
        form.introduction.focus(); 
        return false;
    }
	if (checkRadio(form.sex)==false){
   	    alert('Sorry, Select Sex.');
   	    return false;
   	}
    if (!is_filled(form.fullname)) {
        alert("Sorry, This Fullname's length between in 1-10!");
        form.fullname.focus();
        return false;
    }
    var re = /^[0-9a-zA-Z\-\.\_]+@[0-9a-zA-Z\-]+\.[0-9a-zA-Z\-\.]+$/;
    if (is_filled(form.email) && !form.email.value.match(re)) {
        alert("Please enter a valid E-mail address.");
        form.email.focus();
        return false;
    }
//    makeCategoryCode(form.m_catalog, form.m_catalogCode);
    form.action = 'member_submit.asp';
    form.submit();
}

function checkPasswd(pwd) {
    var form = document.dataForm;

    if ((pwd.length < 6) || (pwd.length > 20)) {
        alert("Password must be 6-20 characters.");
        form.pwd.focus();
        form.pwd.select();
        return false;
    }
    for (i=0; i<pwd.length; i++) {
        if (!((pwd.charAt(i) >= '0' && pwd.charAt(i) <= '9') ||
              (pwd.charAt(i) >= 'a' && pwd.charAt(i) <= 'z') || (pwd.charAt(i) >= 'A' && pwd.charAt(i) <= 'Z'))) {
            alert("Please use only letters(a-z,A-Z) and numbers(0-9) for your Password.");
            form.pwd.focus();
            form.pwd.select();
            return false;
        }
    }
}
function checkPwd(pwd) {
    var form = document.dataForm;

    if ((pwd.length < 4) || (pwd.length > 8)) {
        alert("Password must be 4-8 characters.");
        form.pwd.focus();
        form.pwd.select();
        return false;
    }
    for (i=0; i<pwd.length; i++) {
        if (!((pwd.charAt(i) >= '0' && pwd.charAt(i) <= '9') ||
              (pwd.charAt(i) >= 'a' && pwd.charAt(i) <= 'z') || (pwd.charAt(i) >= 'A' && pwd.charAt(i) <= 'Z'))) {
            alert("Please use only letters(a-z,A-Z) and numbers(0-9) for your Password.");
            form.username.focus();
            form.username.select();
            return false;
        }
    }
}
function checkRadio(object) {
    for (var i=0; i<object.length; i++) {
        if (object[i].checked)
            return true;
    }
    return false;
}