function ID_Check(new_id) {
    if (new_id == "") {
        alert("Please enter your User ID.");
        document.form1.new_id.focus();
        document.form1.new_id.select();
        return;
    }
    if (new_id.length < 4) {
        alert("Username should be 4 to 14 characters.");
        document.form1.new_id.focus();
        document.form1.new_id.select();
        return;
    }

	var h;
	h = h_check(new_id)
	if( h == -1) // 한글
	{
	 alert("The username you entered appears to be incorrect. \n\nUsername should be 4 to 14 characters.");
	document.form1.new_id.focus();
	document.form1.new_id.select();
	 return;
	}


    var url = "membership_id_check.html?id="+new_id;

    window.open(url,'check','toolbar=no,directories=no,location=no,status=no,menubar=no,scrollbars=no,resizable=no,width=300,height=150');
}


function h_check(Objectname){
	var intErr
	var strValue = Objectname
	var retCode = 0
	
	for (i = 0; i < strValue.length; i++){
		var retCode = strValue.charCodeAt(i)
		var retChar = strValue.substr(i,1).toUpperCase()
		retCode = parseInt(retCode)
		
		if ((retChar < "0" || retChar > "9") && (retChar < "A" || retChar > "Z") && ((retCode > 255) || (retCode < 0) || (retCode =='32'))){
			intErr = -1;
			break;
		}
	}
	return (intErr);
}


//회원가입시 입력값 check
function Last_Check(form) {

	if (IsEmpty(form.new_id.value)) {
        Error("Please enter your User ID.", form.new_id);
        return false;
    }

    if (IsEmpty(form.id_check_flag.value)) {
		Error("Please click [check availibility].", form.new_id);
		return false;
	}

	if ( form.id_check_flag.value != form.new_id.value)
	{
		Error("Please click [check availibility].", form.new_id);
		return false;
	}

    if (form.new_id.value.length < 4) {
        Error("User ID should be 4 to 14 characters.", form.new_id);
        return false;
    }

    if (! ValidID(form.new_id.value) ) {
        Error("The User ID you entered appears to be incorrect.", form.new_id);
        return false;
    }

    if (IsEmpty(form.passwd1.value)) {
        Error("Please enter password.", form.passwd1);
        return false;
    }

    if (IsEmpty(form.passwd2.value)) {
        Error("Please enter password.", form.passwd2);
        return false;
    }

    if (form.passwd1.value != form.passwd2.value) {
        Error("Passwords do not match.", form.passwd1);
        return false;
    }

	 if (IsEmpty(form.hname.value)) {
        Error("Please enter First Name.", form.hname);
        return false;
    }

    if (IsEmpty(form.hname2.value)) {
        Error("Please enter Last Name.", form.hname2);
        return false;
    }

	if (IsEmpty(form.estreet1.value)) {
        Error("Please enter Address.", form.estreet1);
        return false;
    }

	if (IsEmpty(form.ecity.value)) {
        Error("Please enter City.", form.ecity);
        return false;
    }
	if (IsEmpty(form.state.value)) {
        Error("Please enter State.", form.state);
        return false;
    }
	
	if (IsEmpty(form.zipcode.value)) {
        Error("Please enter Postal Code.", form.zipcode);
        return false;
    }

	if (IsEmpty(form.email.value)) {
        Error("Please enter E-Mail address.", form.email);
        return false;
    }

    if (! EmailCheck(form.email.value)) {
        Error("The e-mail address you entered appears to be incorrect. Please check it.", form.email);
        return false;
    }

	if (IsEmpty(form.email2.value)) {
        Error("Please enter E-Mail address.", form.email2);
        return false;
    }

	if (form.email.value != form.email2.value) {
        Error("E-Mails do not match.", form.email2);
        return false;
    }

	if (IsEmpty(form.create_quest_answer.value)) {
        Error("Please enter Secret question.", form.create_quest_answer);
        return false;
    }
	
    if (form.create_quest_answer.value.length < 4) {
        Error("Answer must be at least 4 characters long.", form.create_quest_answer);
        return false;
    }

	if (form.agreement_registration.checked == false) {
		Error("You must read and agree to our agreement.", form.agreement_registration);		
		return false;
	}


    var msg = "Are you sure to continue?";
    var bool = confirm(msg);
    if(bool)    form.submit();//return true;
    //else  return true;
}

//입력값 check
function IsEmpty(String) {
   return !CheckValid(String, false);
}

function CheckValid(String, SpaceCheck) {

   var retvalue = false;

   for (var i=0; i<String.length; i++) {

      if (SpaceCheck == true) {
         if (String.charAt(i) == ' ') {
            retvalue = true;
            break;
         }
      } else {
         if (String.charAt(i) != ' ') {
            retvalue = true;
            break;
         }
      }
   }
   return retvalue;
}

//error message 출력
function Error(msg, item) {
    alert(msg);
    item.focus();
    item.select();
}

//로그인 아이디 valid check
function ValidID(String) {

   var RetValue = true;
   var Count, Count2, Count3;
   var PermitChar = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_-";
   var no = '!@#$%^&*()-=\\`~_+|[]{};:",.\'/<>?';
   Count = 0, Count3 = 0;

   for (var i = 0; i < String.length; i++) {
      for (var j = 0; j < PermitChar.length; j++) {
         if(String.charAt(i) == PermitChar.charAt(j)) {
            Count++;
         }
         if(String.charAt(i) == no.charAt(j)) {
            Count3++;
         }
      }  
   }

   if (Count == 0) {
       RetValue = false;
   }
   if (Count3 != 0) {
       RetValue = false;
   }

    return RetValue;
}


// 영문 check
//function IsMultilingual(String) {
//    var RetValue = false;
//   if (IsEmpty(String))
//      return false;

//    for(i=0 ; i<String.length ; i++) {
 //       if (String.charCodeAt(i) > 127 || String.charCodeAt(i) < 0) {
 //           RetValue = true;
 //           break;
 //       }
 //   }

//    return RetValue;

//}


//email check
function EmailCheck(String){
   var checkflag = true;
   var retvalue;

   if (IsEmpty(String))
      return false;

   if (window.RegExp) {
      var tempstring = "a";
      var exam = new RegExp(tempstring);
      if (tempstring.match(exam)) {
         var ret1 = new RegExp("(@.*@)|(\\.\\.)|(@\\.)|(^\\.)");
         var ret2 = new RegExp("^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,4}|[0-9]{1,4})(\\]?)$");
         retvalue = (!ret1.test(String) && ret2.test(String));
      } else {
         checkflag = false;
      }
   } else {
      checkflag = false;
   }  
      
   if (!checkflag) {
      retvalue = ( (String != "") && (String.indexOf("@")) > 0 && (String.index.Of(".") > 0) );
   }
   
   return retvalue;
}