/************************************************************************************************/
/* Check Parameter Numeric Function                                                             */
/* isNum - Javascript 1.0(Unix only), 1.1, Jscript 1.0 Support                                  */
/************************************************************************************************/
function isNum(sVal) {
	if(isNaN(sVal)) return false;
	return true;
}

function isNum2(sVal) {
	var tempCode;
	for (var i=0; i<sVal.length; i++) {
		tempCode = sVal.charCodeAt(i);
		if (tempCode < 30 && tempCode > 39) {
			return false;
		}
	}
	return true;
}


/************************************************************************************************/
/* Check Parameter AllowCharacter Function                                                      */
/************************************************************************************************/
function isAllowCharacter(sVal) {
	var checkList = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
	for (var i=0; i<sVal.length; i++) {
		if (checkList.indexOf(sVal.charAt(i)) < 0) return false;
	}
	return true;
}


/************************************************************************************************/
/* Count Parameter Character Function                                                           */
/************************************************************************************************/
function numChar(sVal) {
	var cnum = 0;
	for (var i=0; i<sVal.length; i++) {
		if (sVal.charCodeAt(i) > 255) {
			cnum += 2;
		} else {
			cnum ++;
		}
	}
	return cnum;
}


/************************************************************************************************/
/* Check Parameter Unicode Character Function                                                   */
/************************************************************************************************/
function isUnicode(sVal) {
	var strLength = sVal.length;
	var rtnVal = false;
	for (var i=0; i<strLength; i++) {
		if (sVal.charCodeAt(i) > 255) {
			rtnVal = true;
			break;
		}
	}
	return rtnVal;
}


/************************************************************************************************/
/* Trim Parameter String Function                                                               */
/************************************************************************************************/
function trimAll(sVal) {
	var firstChrPosition = 0, lastChrPosition = 0;
	var strLength = sVal.length;
	for (var i=0; i<strLength; i++) {
		if (sVal.charAt(i) != " ") {
			firstChrPosition = i;
			break;
		}
	}
	for (var j=strLength-1; j>0; j--) {
		if (sVal.charAt(j) != " ") {
			lastChrPosition = j;
			break;
		}
	}
	return sVal.substring(firstChrPosition,lastChrPosition+1);
}


/************************************************************************************************/
/* Delete Space Parameter String Function                                                       */
/************************************************************************************************/
function removeSpace(sVal) {
	var tempStr;
	var i;
	tempStr = "";
	for(var i=0; i<sVal.length; i++) {
		if(sVal.charAt(i) != ' ') {
			tempStr = tempStr + (sVal.substring(i,i+1));
		}
	}	
	return tempStr;
}


/************************************************************************************************/
/* Limit Parameter String Length Function                                                       */
/************************************************************************************************/
function isLimitChar(sVal,intVal) {
	var tempCharLength;
	if (numChar(sVal) <= intVal) return true;
	return false;
}


/************************************************************************************************/
/* Check Parameter Blank Function                                                               */
/************************************************************************************************/
function isBlank(sVal) {
	if (trimAll(sVal).length == 0) return true;
	return false;
}


/************************************************************************************************/
/* Check Parameter First, Last Character Blank Forbid Function                                  */
/************************************************************************************************/
function isForbidBlank(sVal) {
	if (sVal.length != trimAll(sVal).length) return true;
	return false;
}


/************************************************************************************************/
/* Alert Message & Focus Function                                                               */
/************************************************************************************************/
function viewMsg(cObj,sVal,vType) {
	alert(sVal);
	if (vType == 1) {
		cObj.focus();
	}
}


/************************************************************************************************/
/* Check Selected Radio Button Function                                                         */
/************************************************************************************************/
function isSelectedRadio(cObj) {
	var radioLength = cObj.length;
	if (radioLength != null || radioLength != undefined) {
		for (var i = 0; i < radioLength; i++) {
			if (cObj[i].checked) return i;
		}
	} else {
		if (cObj.checked) return 1;
	}
	return -1;
}


/************************************************************************************************/
/* Check Selected SelectBox Function                                                            */
/************************************************************************************************/
function isSelectedBox(cObj, idx) {
	if(cObj[idx].selected) return true;
	return false;
}


/************************************************************************************************/
/* Check Forbidden File Function                                                                */
/* ,ÀÇ ±ÝÁö´Â ¾÷·Îµå ÇÑ ÆÄÀÏÀÇ ÆÄÀÏ¸íÀ» ¹è¿­·Î Á¤·ÄÇÒ ¶§ »ç¿ëÇÏ´Â ±¸ºÐ¹®ÀÚ·Î »ç¿ëÇÑ´Ù                         */
/************************************************************************************************/
function checkForbiddenFile(sVal) {
	var arrFobiddenFile = new Array("'", ",", ".asp", ".js", ".inc", ".aspx", ".html", ".htm", ".xml", ".exe", ".com", ".bat", ".vbs");
	var rtnVal = true;
	var tempStr = sVal.toLowerCase();
	for (var i = 0; i < arrFobiddenFile.length; i++) {
		if (sVal.lastIndexOf(arrFobiddenFile[i]) > 0) {
			rtnVal = false;
			break;
		}
	}
	return rtnVal;
}


/************************************************************************************************/
/* Check Parameter Date Format Function                                                         */
/* YYYY-MM-DD (Default)                                                                         */
/* isDate - Javascript 1.1, Jscript 3.0 Support                                                 */
/************************************************************************************************/
function isDate(sVal,sep) {
	var tempSep = (sep != null)?sep:"-";
	var tempArray = sVal.split(tempSep);
	if (tempArray.length != 3) return false;
	if (tempArray[0].length != 4 || !isNum(tempArray[0])) return false;
	if (tempArray[1].length != 2 || !isNum(tempArray[1])) return false;
	if (tempArray[2].length != 2 || !isNum(tempArray[2])) return false;
	return true;
}


function isDate2(sVal,cType) { //sVal: date string, cType: date format
	var arrDateFormat = new Array('YYYYMMDD','YYMMDD');
	var tempYY, tempMM, tempDD;
	var idx = -1, rtnVal = false;
	for (var i = 0; i < arrDateFormat.length; i++) {
		if (arrDateFormat[i] == cType) {
			idx = i;
			break;
		}
	}
	if (idx == -1) return rtnVal;
	if (sVal.length != arrDateFormat[idx].length) return rtnVal;

	rtnVal = true;
	switch(idx) {
		case 0:
			tempYY = sVal.substring(0,4);
			tempMM = sVal.substring(4,6);
			tempDD = sVal.substring(6,8);
			if (paseInt(tempYY) < 999) rtnVal = false;
			break;
		case 1:
			tempYY = sVal.substring(0,2);
			tempMM = sVal.substring(2,4);
			tempDD = sVal.substring(4,6);
			break;
	}
	if (parseFloat(tempMM) == 0 || parseFloat(tempMM) > 12) rtnVal = false;
	if (parseFloat(tempDD) == 0 || parseFloat(tempDD) > 31) rtnVal = false;
	return rtnVal;
}


/************************************************************************************************/
/* Àç¿Ü±¹ÀÎ ¹øÈ£ Ã¼Å©                                                                              */
/************************************************************************************************/
function checkFSSN(ssn1,ssn2) {
	var sum=0;
	var odd=0;
	var fgnno = ssn1+ssn2;
	buf = new Array(13);
	for(i=0; i<13; i++) { buf[i]=parseInt(fgnno.charAt(i)); }
	odd = buf[7]*10 + buf[8];
	if(odd%2 != 0) { return false; }
	if( (buf[11]!=6) && (buf[11]!=7) && (buf[11]!=8) && (buf[11]!=9) ) {
		return false;
	}
	multipliers = [2,3,4,5,6,7,8,9,2,3,4,5];
	for(i=0, sum=0; i<12; i++) { sum += (buf[i] *= multipliers[i]); }
	sum = 11 - (sum%11);
	if(sum >= 10) { sum -= 10; }
	sum += 2;
	if(sum >= 10) { sum -= 10; }
	if(sum != buf[12]) { return false }
	return true;
}


/************************************************************************************************/
/* ÁÖ¹Îµî·Ï ¹øÈ£ Ã¼Å©                                                                              */
/************************************************************************************************/
function checkSSN(ssn1,ssn2) {
	var result=0,i=0;
	var ssn=ssn1+ssn2;

	for(i=2;i<10;i++) result+=(ssn.charAt(i-2)*i);
	for(i=2;i<6;i++) result+=(ssn.charAt(i+6)*i);
	result=result%11;

	if(result==0) {
		if(ssn.charAt(12)==1) return true;
		else return false;
	} else {
		if(result==1) {
			if(ssn.charAt(12)==0) return true;
			else return false;
		} else {
			if(ssn.charAt(12)==(11-result)) return true;
			else return false;
		}
	}
}


//ÀÌ¸ÞÀÏ °Ë»ç 
// Changes:  Sandeep V. Tamhankar (stamhankar@hotmail.com) 
/* 1.1.2: Fixed a bug where trailing . in e-mail address was passing 
					(the bug is actually in the weak regexp engine of the browser; I 
					simplified the regexps to make it work). 
	 1.1.1: Removed restriction that countries must be preceded by a domain, 
					so abc@host.uk is now legal.  However, there's still the 
					restriction that an address must end in a two or three letter 
					word. 
	 1.1: Rewrote most of the function to conform more closely to RFC 822. 
	 1.0: Original  */ 

//Begin 
function emailCheck (emailStr) { 
/* The following pattern is used to check if the entered e-mail address 
	 fits the user@domain format.  It also is used to separate the username 
	 from the domain. */ 
var emailPat=/^(.+)@(.+)$/ 
/* The following string represents the pattern for matching all special 
	 characters.  We don't want to allow special characters in the address. 
	 These characters include ( ) < > @ , ; : \ " . [ ]    */ 
var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]" 
/* The following string represents the range of characters allowed in a 
	 username or domainname.  It really states which chars aren't allowed. */ 
var validChars="\[^\\s" + specialChars + "\]" 
/* The following pattern applies if the "user" is a quoted string (in 
	 which case, there are no rules about which characters are allowed 
	 and which aren't; anything goes).  E.g. "jiminy cricket"@disney.com 
	 is a legal e-mail address. */ 
var quotedUser="(\"[^\"]*\")" 
/* The following pattern applies for domains that are IP addresses, 
	 rather than symbolic names.  E.g. joe@[123.124.233.4] is a legal 
	 e-mail address. NOTE: The square brackets are required. */ 
var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/ 
/* The following string represents an atom (basically a series of 
	 non-special characters.) */ 
var atom=validChars + '+' 
/* The following string represents one word in the typical username. 
	 For example, in john.doe@somewhere.com, john and doe are words. 
	 Basically, a word is either an atom or quoted string. */ 
var word="(" + atom + "|" + quotedUser + ")" 
// The following pattern describes the structure of the user 
var userPat=new RegExp("^" + word + "(\\." + word + ")*$") 
/* The following pattern describes the structure of a normal symbolic 
	 domain, as opposed to ipDomainPat, shown above. */ 
var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$") 


/* Finally, let's start trying to figure out if the supplied address is 
	 valid. */ 

/* Begin with the coarse pattern to simply break up user@domain into 
	 different pieces that are easy to analyze. */ 
var matchArray=emailStr.match(emailPat) 
if (matchArray==null) { 
	/* Too many/few @'s or something; basically, this address doesn't 
		 even fit the general mould of a valid e-mail address. */ 
				//alert("Email address seems incorrect (check @ and .'s)") 
				return false 
} 
var user=matchArray[1] 
var domain=matchArray[2] 

// See if "user" is valid 
if (user.match(userPat)==null) { 
		// user is not valid 
		//alert("The username doesn't seem to be valid.") 
		return false 
} 

/* if the e-mail address is at an IP address (as opposed to a symbolic 
	 host name) make sure the IP address is valid. */ 
var IPArray=domain.match(ipDomainPat) 
if (IPArray!=null) { 
		// this is an IP address 
					for (var i=1;i<=4;i++) { 
						if (IPArray[i]>255) { 
								//alert("Destination IP address is invalid!") 
								return false 
						} 
		} 
		return true 
} 

// Domain is symbolic name 
var domainArray=domain.match(domainPat) 
if (domainArray==null) { 
				//alert("The domain name doesn't seem to be valid.") 
		return false 
} 

/* domain name seems valid, but now make sure that it ends in a 
	 three-letter word (like com, edu, gov) or a two-letter word, 
	 representing country (uk, nl), and that there's a hostname preceding 
	 the domain or country. */ 

/* Now we need to break up the domain to get a count of how many atoms 
	 it consists of. */ 
var atomPat=new RegExp(atom,"g") 
var domArr=domain.match(atomPat) 
var len=domArr.length 
if (domArr[domArr.length-1].length<2 || 
		domArr[domArr.length-1].length>4) { 
	 // the address must end in a two letter or three letter word. 
	 //alert("The address must end in a three-letter domain, or two letter country.") 
	 return false 
} 

// Make sure there's a host name preceding the domain. 
if (len<2) { 
	 var errStr="This address is missing a hostname!" 
	 //alert(errStr) 
	 return false 
} 

// If we've gotten this far, everything's valid! 
return true; 
} 
//  End 



