
function trimString (str) {
       str = this != window? this : str;
       return str.replace(/^\s+/g, '').replace(/\s+$/g, '');
}

String.prototype.trim = trimString;

function checkWinc1(form){
	var host = form.numkey.value.trim();
	form.numkey.value = host;

	if( host == "") {
		alert("모바일주소를 입력하여 주십시오.");
		form.numkey.style.backgroundImage = "";
		form.numkey.focus();
		return false;
	}
	
	var tmp = host;

	var result = checkValidWinc(1,tmp.trim(),form);
	if(result == false) return false;

	form.target="_top";
	
	return true;

}

function checkValidWinc(num, host,form)
{
	var strlength = host.length;
	var isHan = false;

	var valid_dom = /^[0-9#]+$/;
	if(!valid_dom.test(host)){
		alert("모바일주소 형식이 맞지 않습니다. \n\n다시 입력해주십시오.");
		form.numkey.focus();
		return false;
	}
	
	// 길이검사시 한글영문의 경우 영문을 1글자로 계산하게되면 안됨.
	// 한글한글자에 대해 영문은 0.5자로 계산하여 17자를 계산하도록함.
	junkyAlphabet = "0123456789#";
	var strlength2 = 0; //한글포함한 경우의 길이계산을 위한 별도의 변수할당.
	for ( var i = 0; i < strlength; i++ ) {
		if ( junkyAlphabet.indexOf( host.charAt(i) ) >= 0 ) {
			strlength2 = strlength2 + 1;
		} else {
			strlength2 = strlength2 + 1;
			isHan = true;
		}
	}
	
	var startLimit = 0;
	var endLimit = 0;
	if(isHan){
		startLimit = 2;
		endLimit = 63;
	}else{
		startLimit = 2;
		endLimit = 31.5;
	}
	
	if( strlength2 < startLimit || strlength2 > endLimit ) {
		alert("모바일주소는 최소 2 자에서 최대 63자 까지만 등록가능합니다. \n다시 입력해주십시오.");
		form.numkey.focus();
		return false;
	}

	//alert(strlength2);

	if (checkLength(host) == false){
		alert("WINC 번호는 대규모번호로 현재 등록이 되지 않습니다.");
		form.numkey.focus();
		return false;
	}
	
	//[1.4] "-"  으로 시작하는 것 금지
	if( host.indexOf("0") == 0) {
		alert("WINC 번호는 0으로 시작할수 없습니다.");
		form.numkey.focus();
		return false;
	}

	//[1.5] "-"  으로 끝나는 것 금지
	if( host.lastIndexOf("-") == (strlength-1) ) {
		alert("하이픈(-)으로 끝나는 모바일주소는 등록하실 수 없습니다. \n다시 입력해주십시오.");
		form.numkey.focus();
		return false;
	}
}

function checkLength(wincnum)
{
	var tmp = wincnum.split("#");

	if (tmp[1]) {
		if (tmp[1].length < 6) {
			return true;
		} else {
			return false;
		}
	} else {
		return true;
	}
}

//숫자와 Back Space만 허용...
function CheckNum() {
	if (event.keyCode == 9 ) { // TAB 키 허용 (박스 이동)
		event.returnValue = true;
		return;
	}
	if (event.keyCode == 8 ) { // BACK SPACE
		event.returnValue = true;
		return;
	}
	// 오른쪽 숫자판
	if (event.keyCode >= 96 && event.keyCode <= 105) {
		event.returnValue = true;
		return;
	}
	if (event.keyCode < 45 || event.keyCode > 57) {
		event.returnValue = false;
		return;
	}
}
	
function chg_opt(elm){
	if(elm ==1) {
		document.form1.domain_type2.options[0].selected = true;
	} else if(elm ==2){
		document.form1.domain_type1.options[0].selected = true;
	}
}

 //한글이 있는지를 검사한다.
function isEnglishString( aString, minLength, maxLength ) {
	var iteration = 0;
	var iteration2 = 0;
	var junkyCounter = 0;

	junkyAlphabet = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-";
	iteration = aString.length;

	if( iteration > maxLength || iteration < minLength ) {
	return false;
	}

	while( iteration-- > 0 ) {
	iteration2 = junkyAlphabet.length;
	while( iteration2-- > 0 ) {
	if( aString.charAt( iteration ) == junkyAlphabet.charAt( iteration2 ) ) {
			 junkyCounter++;
	} else {
	 //alert( aString.charAt( iteration ) );
	}
	}
	}

	if( junkyCounter != aString.length ) {
	return false;
	}

	return true;
}


function MM_openBrWindow(theURL,winName,features) { //v2.0
	window.open(theURL,winName,features);
}

// 도메인과 메치되는 숫자를 입력하는 함수
function check_num(theform)	{
	var str;
	str = theform.domain_name.value;
	str = str.toLowerCase();
	var temp = "";
	var num = "";
   	for(i=0; i<str.length; i++) {
   		temp = str.charAt(i);
   		if(temp == "a" || temp == "c" || temp == "b") {
			 num  += "2";
		} else if(temp == "d" || temp == "e" || temp == "f") {
			 num  += "3";
		} else if( temp == "g" ||  temp == "h" ||  temp == "i") {
			 num  += "4";
		} else if( temp == "j" ||  temp == "k" ||  temp == "l") {
			 num  += "5";
		} else if( temp == "m" ||  temp == "n" ||  temp == "o") {
			 num  += "6";
		} else if( temp == "p" ||  temp == "r" ||  temp == "s") {
			 num += "7";
		} else if( temp == "t" ||  temp == "u" ||  temp == "v") {
			 num  += "8";
		} else if( temp == "x" ||  temp == "w" ||  temp == "y") {
			 num  += "9";
		} else if( temp == "q" ||  temp == "z" || (i==0 && temp == "0" )) {
			 num  += "1";
		} else if( temp == "-" ) {
			 num  += "";
		}else if( 0 <=  temp  &&   temp <10 ) {
			 num +=  temp;
		}
   }
   
   theform.numkey.value = num;	  
}

function check_num1(theform)	{
	var str;
	str = theform.domain_name.value;
	str = str.toLowerCase();
	var temp = "";
	var num = "";
   	for(i=0; i<str.length; i++) {
   		temp = str.charAt(i);
   		if(temp == "a" || temp == "c" || temp == "b") {
			 num  += "2";
		} else if(temp == "d" || temp == "e" || temp == "f") {
			 num  += "3";
		} else if( temp == "g" ||  temp == "h" ||  temp == "i") {
			 num  += "4";
		} else if( temp == "j" ||  temp == "k" ||  temp == "l") {
			 num  += "5";
		} else if( temp == "m" ||  temp == "n" ||  temp == "o") {
			 num  += "6";
		} else if( temp == "p" ||  temp == "r" ||  temp == "s") {
			 num += "7";
		} else if( temp == "t" ||  temp == "u" ||  temp == "v") {
			 num  += "8";
		} else if( temp == "x" ||  temp == "w" ||  temp == "y") {
			 num  += "9";
		} else if( temp == "q" ||  temp == "z" || (i==0 && temp == "0" )) {
			 num  += "1";
		} else if( temp == "-" ) {
			 num  += "";
		}else if( 0 <=  temp  &&   temp <10 ) {
			 num +=  temp;
		}
   }
   
   theform.numkey1.value = num;	  
}


