﻿// 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(pwd.value)) {
			setIncorrect("Enter the password");
			count++;
		}
		else {
		    if (pwd.value.length<4 || pwd.value.length>12) {
                setIncorrect("Password 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(cafename.value)) {
			setIncorrect("Enter the cafe name");
			count++;
		}
		else {
		    /*if (IsSpecialString(cafename.value)) {
			    setIncorrect("cafe name should only contain letters and numbers.");
			    count++;
		    }*/
		    if (cafename.value.length<4 || cafename.value.length>60) {
                setIncorrect("cafe name must be 4-60 characters long. ");
                count++;
            }
        }    
		
        if (IsEmpty(nick.value)) {
            setIncorrect("Enter your nickname.");
           count++;
        }   
        else {
            if (nick.value.length<2 || nick.value.length>15) {
                setIncorrect("Nickname must be 2-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(ownerfname.value)) {
            setIncorrect("Enter owner first name.");
            count++;
        }
		else {
            if (ownerfname.value.length>25) {
                setIncorrect("Must be less than 25 characters long(owner first name).");
                count++;
            }
        } 
        if (IsEmpty(ownerlname.value)) {
            setIncorrect("Enter owner last name.");
            count++;
        }
		else {
            if (ownerlname.value.length>25) {
                setIncorrect("Must be less than 25 characters long(owner last name).");
                count++;
            }
        } 

        if (IsEmpty(assistfname.value)) {
            setIncorrect("Enter assistant first name.");
            count++;
        }
		else {
            if (assistfname.value.length>25) {
                setIncorrect("Must be less than 25 characters long(assistant first name).");
                count++;
            }
        }  
        if (IsEmpty(assistlname.value)) {
            setIncorrect("Enter assistant last name.");
            count++;
        }
		else {
            if (assistlname.value.length>25) {
                setIncorrect("Must be less than 25 characters long(assistant last name).");
                count++;
            }
        }  
        
        if (IsEmpty(addr.value)) {
            setIncorrect("Enter street address");
            count++;
        }
		else {
            if (addr.value.length>200) {
                setIncorrect("Must be less than 200 characters long(street address).");
                count++;
            }
        }   
        
        if (province.selectedIndex==0 || city.selectedIndex==0)
        {
            setIncorrect("Select Province&City.");
            count++;
        }
         
        if (IsEmpty(phone1.value) || IsEmpty(phone2.value) || IsEmpty(phone3.value)) {
            setIncorrect("Enter the landline number ");
            count++;
        }
        else if (!IsNum(phone1.value) || !IsNum(phone2.value) || !IsNum(phone3.value)) {
                setIncorrect("Land line must be in numbers only.");
                count++;
        }

        if (IsEmpty(mobile1.value) || IsEmpty(mobile2.value) || IsEmpty(mobile3.value)) {
            setIncorrect("Enter the cellphone number ");
            count++;
        }
        else if (!IsNum(mobile1.value) || !IsNum(mobile2.value) || !IsNum(mobile3.value)) {
                setIncorrect("Cell phone must be in numbers only.");
                count++;
        }
       
        if (IsEmpty(mail.value) || selectmail.selectedIndex==0) {
            setIncorrect("Enter your e-mail address.");
            count++;
        }
        else {
            if (selectmail.options[selectmail.selectedIndex].value=="@") {
                if (IsEmpty(inputmail.value)) {
                    setIncorrect("Enter your e-mail address.");
                    count++;
                }
            }
        }   
        
        if (isp.selectedIndex==0)
        {
            setIncorrect("Select ISP.");
            count++;
        }
        if (bandwidth.selectedIndex==0)
        {
            setIncorrect("Select bandwidth.");
            count++;
        }
        
        if (IsEmpty(pccount.value)) {
            setIncorrect("Enter the numbers of PC");
            count++;
        }
        else if (!IsNum(pccount.value)) {
                setIncorrect("Numbers of PC must be in numbers only.");
                count++;
        }

        if (!openfull.checked) {
            if (opentime.selectedIndex==0)
            {
                setIncorrect("Select open time.");
                count++;
            }
            if (closetime.selectedIndex==0)
            {
                setIncorrect("Select close time.");
                count++;
            }
        }
        
        if (price.selectedIndex==0 || (price.options[price.selectedIndex].value=="0" && IsEmpty(inputprice.value))) {
            setIncorrect("Enter hourly gaming rate");
            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;
}


