﻿// JScript 파일
function IsSpecialString(str)
{
	var err_cnt=0
	for (var i = 0; i < str.length; i++) {
		var val = str.charAt(i);
		if (!((val >= "0" && val <= "9") || (val >= "a" && val <= "z") || (val >= "A" && val <= "Z")))
		err_cnt ++
		}
	if (err_cnt == 0 ) return false;
		else 	return true;
}

function IsEmpty(str)
{
    var re = /\s/;
    
    while (str.match(re)) {
        str = str.replace(re,"");
    }
    
    if (str=="")
        return true;
    else
        return false;
}

function IsNum(str)
{
    var re = /[^0-9]/;
    
    if (IsEmpty(str)) 
        return false;
    else if (!str.match(re)) 
        return true;
    else
        return false;
    
}

function strReplace(str, re)
{
    while (str.match(re)) {
        str = str.replace(re,"");
    }
    
    return str;
}


//Length check
function getLen(strInput)
{
	var nStrLen, nStrRealLen, nPos, chTmp;

	nStrLen     = strInput.length;
	nStrRealLen = 0;

	for(nPos = 0; nPos < nStrLen; nPos++)
	{
		var nASCII = strInput.charCodeAt(nPos)
		if (nASCII > 0 && nASCII < 255)
			nStrRealLen += 1; 
		else
			nStrRealLen += 2; 
	}
	return nStrRealLen;
}function chkPass(strInput)
{
	var nStrLen, nPos, nCnt, sCnt, nRtn;

	nStrLen     = strInput.length;
    nCnt = 0;
    sCnt = 0;
    
	for(nPos = 0; nPos < nStrLen; nPos++)
	{
		var nChar = strInput.substr(nPos, 1);
	
		if (IsNum(nChar))
			nCnt += 1; 
		else
			sCnt += 1;
	}
	
	if (nCnt>0 && sCnt>0) {
	    nRtn = true;
	}
	else {
	    nRtn = false;   //empty
	}
			
	return nRtn;
}function IsMail(strInput){    var re1 = /^([A-Za-z0-9_.-]+)@([A-Za-z0-9_.-]+)[.]([A-Za-z0-9_.-]+)$/ig;    var re2 = /^([A-Za-z0-9_.-]+)@([A-Za-z0-9_.-]+)[.]([A-Za-z0-9_.-]+)[.]([A-Za-z0-9_.-]+)$/ig;        if (strInput.match(re1)==null && strInput.match(re2)==null)        return false;    else        return true;}

function Confirm_Check()
{
    var str, count;
    
    count = 0;
    
    noAgree(!document.Form1.agree.checked);
    
    incorrectClear("lblIncorrect")
    
    with (document.Form1)
	{
		if (IsEmpty(uid.value)) {
			setIncorrect("Enter the username");
			count++;
		}
		else {
		    if (IsSpecialString(uid.value)) {
			    setIncorrect("Username should only contain letters and numbers.");
			    count++;
		    }
		    if (uid.value.length<6 || uid.value.length>15) {
                setIncorrect("Username must be 6-15 characters long. ");
                count++;
            }
            if (IsNum(uid.value.substring(0,1))) {
                setIncorrect("Numbers are not allowed in front.<br> ");
                count++;
            }
        }    
		if (IsEmpty(pwd.value)) {
			setIncorrect("Enter the password");
			count++;
		}
		else {
		    if (pwd.value.length<4 || pwd.value.length>12) {
                setIncorrect("Nickname must be 4-12 characters long. ");
                count++;
            }
            if (IsSpecialString(pwd.value)) {
			    setIncorrect("Password should only contain letters and numbers.");
			    count++;
		    }
            if (pwd.value!=pwd2.value) {
                setIncorrect("Incorrect password");
                count++;
            }
        }
        if (IsEmpty(nick.value)) {
            setIncorrect("Enter your nickname.");
           count++;
        }   
        else {
            if (nick.value.length<6 || nick.value.length>15) {
                setIncorrect("Nickname must be 6-15 characters long.");
                count++;
            }
            if (IsSpecialString(nick.value)) {
			    setIncorrect("Nickname should only contain letters and numbers.");
			    count++;
		    }
    		 
            /*if (IsNum(nick.value.substring(0,1))) {
                setIncorrect("Nickname are not allowed in front. ");
                count++;
            }*/
        }

        if (IsEmpty(mail1.value) || IsEmpty(mail2.value)) {
            setIncorrect("Enter your e-mail address.");
            count++;
        }
        else {
            var email;
            email = mail1.value+"@"+mail2.value;
            if (!IsMail(email)) {
                setIncorrect("Incorrect email format.");
                count++;
            }
        } 

   		if (IsEmpty(fname.value)) {
			setIncorrect("Enter the first name");
			count++;
		}
		else {
            if (fname.value.length>15) {
                setIncorrect("Must be less than 15 characters long.");
                count++;
            }
        }
		if (IsEmpty(lname.value)) {
			setIncorrect("Enter the last name");
			count++;
		}
        else {
            if (lname.value.length>15) {
                setIncorrect("Must be less than 15 characters long.");
                count++;
            }
        }
       
        if ((iMonth.selectedIndex==0 && iDay.selectedIndex==0 && iYear.selectedIndex==0) || iYear.selectedIndex==0)
        {
            setIncorrect("Select birthday.");
            count++;
        }
        
        if (!IsEmpty(addr.value)) {
			if (addr.value.length>50) {
    			setIncorrect("Must be less than 50 characters long.");
			    count++;
			}
		}

        if (province.selectedIndex==0 || city.selectedIndex==0)
        {
            setIncorrect("Select province & city.");
            count++;
        }
        		
        if (!IsEmpty(mobile1.value) || !IsEmpty(mobile2.value) || !IsEmpty(mobile3.value)) {
            if (!IsNum(mobile1.value) || !IsNum(mobile2.value) || !IsNum(mobile3.value)) {
                setIncorrect("Mobile number must be in numbers only.");
                count++;
            }
        }
        
        if (!IsEmpty(phone1.value) || !IsEmpty(phone2.value) || !IsEmpty(phone3.value)) {
            if (!IsNum(phone1.value) || !IsNum(phone2.value) || !IsNum(phone3.value)) {
                setIncorrect("Home number must be in numbers only.");
                count++;
            }
        } 
        
        if (IsEmpty(question.options[question.selectedIndex].value)) {
            setIncorrect("Select secret question.");
            count++;
        }
       else { 
            if (question.options[question.selectedIndex].value==0) {
                if (IsEmpty(txtQuestion.value)) {
                    setIncorrect("Enter secret question.");
                    count++;
                }
                else {
                    if (txtQuestion.value.length>20) {
                        setIncorrect("Question must be less than 20 characters long.");;
                        count++;
                    }
                } 
            }
        }
        if (IsEmpty(answer.value)) {
            setIncorrect("You will be asked for your secret answer in case you forget your password.");
            count++;            
        }
        else {
            if (answer.value.length>30) {
                    setIncorrect("Answer must be less than 30 characters long.");;
                    count++;
            }
        } 
        
        if (count>0) {
            incorrectWrite("lblIncorrect", msgString);
            return false; 
        } 
        if (!document.Form1.agree.checked) return false; 
	}
	return true;
}


