/***********************

JavaScript Library
Ver 1.0.0
Date: May 30, 2001

Author: ASP Group
Email: asp@vn.wide-link.com
Company: Wide Link

***********************/


/***********************/
// variable declarations

var reWhitespace = /^\s+$/

var reAlphabetic = /^[a-zA-Z]+$/

var reRightUsername = /^[a-zA-Z][a-zA-Z0-9_]+$/

var reAlphanumeric = /^[a-zA-Z0-9]+$/

var reNumberLetter = /^\d+$/

var reLetterOrDigit = /^([a-zA-Z]|\d)$/

var reSignedInteger = /^(\+|\-)?\d+$/

var reFloat = /^((\d+(\.\d*)?)|((\d*\.)?\d+))$/

var reInteger = /^\d+$/

//USZipCode = "^(\\d{5})((\\-)?(\\d{4}))?$"
USZipCode = /^(\d{5})((\-)?(\d{4}))?$/

var ZIPCodeDelimiters = "-";

// Cho phep nhap 1231231234, 123-1231234, 123-123-1234, 123123-1234, (123)1231234, (123)-1231234, (123)123-1234,(123)-123-1234
//USPhone = "^(\\d{3}|(\\()\\d{3}\\))(\\d{3}|(\\-)?(\\d{3})(\\-)?|(\\ )?(\\d{3})(\\-)?)(\\d{4})$"
USPhone = /^(\d{3}|(\()\d{3}\))(\d{3}|(\-)?(\d{3})(\-)?|(\ )?(\d{3})(\-)?)(\d{4})$/

//The phone number regular expression accepts phone number in both local format (eg. 02 1234 5678 or 123 123 4567) 
//or international format (eg. +61 (0) 2 1234 5678 or +1 123 123 4567). 
//It also accepts an optional extention of up to five digits prefixed by x or ext (eg. 123 123 4567 x89).
var phoneRe = /^((\+\d{1,3}(-| )?\(?\d\)?(-| )?\d{1,3})|(\(?\d{2,3}\)?))(-| )?(\d{3,4})(-| )?(\d{4})(( x| ext)\d{1,5}){0,1}$/
var mobilePhoneRe = /^(02\d{1,2})(-| )(\d{3,4})(-| )(\d{3,4})$/

var phoneNumberDelimiters = "()- ";

//SSN = "^(\\d{3})(\\-)?\\d{2}(\\-)?\\d{4}$"
SSN = /^(\d{3})(\-)?\d{2}(\-)?\d{4}$/

var SSNDelimiters = "-";


/************************
check empty
*************************/
function checkEmpty(obj, msg)
{
	if (obj.value=="")
	{
		alert(msg);
		obj.focus();
		return false;
	}
	
	return true;
}
/************************
Simple email
*************************/
// check email's format
function CheckEmailFormat(str) 
	{				
		if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)+$/.test(str))
		{
			return (true);
		}
		return (false);
	}
function CheckMultiEmailFormat(str) 
	{
		var arrEmail = str.split(";");
		for (var i=0;i<arrEmail.length;i++ )
		{
			if (!CheckEmailFormat(arrEmail[i]))
			{
				return (false);
			}
		}		
		return (true);
	}
	
function simplecompareDate(d1,d2){
	var i = 0;
	var mm1="",dd1="",yy1="";
	while(i<d1.length && d1.charAt(i)!="/") dd1+=d1.charAt(i++);i++;	
	while(i<d1.length && d1.charAt(i)!="/") mm1+=d1.charAt(i++);i++;	
	while(i<d1.length && d1.charAt(i)!="/") yy1+=d1.charAt(i++);	
	i=0;
	var mm2="",dd2="",yy2="";
	while(i<d2.length && d2.charAt(i)!="/") dd2+=d2.charAt(i++);i++;	
	while(i<d2.length && d2.charAt(i)!="/") mm2+=d2.charAt(i++);i++;	
	while(i<d2.length && d2.charAt(i)!="/") yy2+=d2.charAt(i++);
	if(dd1.charAt(0)=='0'){
		dd1 = "" + dd1.charAt(1);
	}
	if(mm1.charAt(0)=='0'){
		mm1 = "" + mm1.charAt(1);
	}
	if(dd2.charAt(0)=='0'){
		dd2 = "" + dd2.charAt(1);
	}
	if(mm2.charAt(0)=='0'){
		mm2 = "" + mm2.charAt(1);
	}

	if(parseInt(yy1)< parseInt(yy2)) return -1;
	else if(parseInt(yy1)> parseInt(yy2)) return 1;
		 else if(parseInt(mm1)< parseInt(mm2)) return -1;
		 	else if(parseInt(mm1)> parseInt(mm2)) return 1; 
				 else if(parseInt(dd1)< parseInt(dd2)) return -1;
				 	  else if(parseInt(dd1)>parseInt(dd2)) return 1;	
							else return 0;
}


/***********************
String
***********************/
function isEmpty(s){
	return ((s == null) || (s.length == 0))
}

function isAlphabetic(s){
	if (isEmpty(s) == false)
		return reAlphabetic.test(s);
}

function isRightUsername(s){
	if (isEmpty(s) == false)
		return reRightUsername.test(s);
}

function isAlphaNumeric(s){
	if (isEmpty(s) == false)
		return reAlphanumeric.test(s);
}

function isNumberLetter(s){
	if (isEmpty(s) == false)
  		return reNumberLetter.test(s);
}

function isValidChar(s){
	if(isEmpty(s) == false){
		var valid = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_";
		var temp;

		for (var i = 0; i < s.length; i++){
			temp = "" + s.substring(i, i+1);
			if (valid.indexOf(temp) == "-1") return false;
		}
		return true;
	}
}

function CheckLen(s, len, required){
	if ((required == true) && isEmpty(s) == true)
		return false;
	
	if (s.length > len)
		return false;
	
	return true;
}

function isCompanyName(s, len, required){
	if (CheckLen(s, len, required) == false)
		return false;
	else {
		var valid = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_ ";
		var temp;

		for (var i = 0; i < s.length; i++){
			temp = "" + s.substring(i, i+1);
			if (valid.indexOf(temp) == "-1") return false;
		}
	}
	return true;
}

function isName(s, len, required){
	if (CheckLen(s, len, required) == false)
		return false;
	else{
		if(isEmpty(s) == false){
			var valid = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ "
			var temp;
			for (var i = 0; i < s.length; i++) {
				temp = "" + s.substring(i, i + 1);
				if (valid.indexOf(temp) == "-1") 
					return false;
			}
		}
	}

	return true;
}

function isUserName(s, len, required){
	if (CheckLen(s, len, required) == false)
		return false;
	else
		if (isValidChar(s) == false || isAlphabetic(Left(s, 3)) == false)
			return false;
	
	return true;
}

function Left(s, n){
	if (n <= 0)
		return "";
	else if (n > String(s).length)
		return s;
	else
		return String(s).substring(0,n);
}

function Right(s, n){
	if (n <= 0)
		return "";
	else if (n > String(s).length)
		return s;
	else {
		var iLen = String(s).length;
		return String(s).substring(iLen, iLen - n);
	}
}

function LTrim(str){
	var whitespace = new String(" \t\n\r");
	var s = new String(str);

	if (whitespace.indexOf(s.charAt(0)) != -1) {
		var j=0, i = s.length;
		while (j < i && whitespace.indexOf(s.charAt(j)) != -1)
			j++;
		s = s.substring(j, i);
	}

	return s;
}

function RTrim(str){
	var whitespace = new String(" \t\n\r");
	var s = new String(str);

	if (whitespace.indexOf(s.charAt(s.length-1)) != -1) {
		var i = s.length - 1;
		while (i >= 0 && whitespace.indexOf(s.charAt(i)) != -1)
			i--;
		s = s.substring(0, i+1);
	}

	return s;
}

function Trim(s){
	return RTrim(LTrim(s));
}

function RemoveBlank(s){
	s.value = Trim(s.value);
}

function stripCharsInBag(s, bag){
	var i;
	var returnString = "";
	for (i = 0; i < s.length; i++){
		var c = s.charAt(i);
		if (bag.indexOf(c) == -1) returnString += c;
	}
	return returnString;
}

function stripCharsNotInBag(s, bag){
	var i;
	var returnString = "";
	for (i = 0; i < s.length; i++){   
		var c = s.charAt(i);
		if (bag.indexOf(c) != -1) 
			returnString += c;
	}
	return returnString;
}

function reformat(s){
	var arg;
	var sPos = 0;
	var resultString = "";
	for (var i = 1; i < reformat.arguments.length; i++) {
		arg = reformat.arguments[i];
		if (i % 2 == 1) resultString += arg;
		else {
			resultString += s.substring(sPos, sPos + arg);
			sPos += arg;
		}
	}
	return resultString;
}

/***********************
Numeric
***********************/
function issimpleNumeric(s){
	if (isEmpty(s) == false)
		if (isNaN(s))
			return false;
		else
			return true;
}

function isPosFloat(s, required, equal){
	if (required == true && isEmpty(s) == true)
		return false;
	
	if (isEmpty(s) == false){
		var bFloat;
		bFloat = isNaN(s);
		if (bFloat == true)
			return false;
		else{			
			if (equal == 1){//lon hon 0
				//alert(s);
				if (parseFloat(s) <= 0) 
					return false;
			}
			else{ //cho phep bang 0
				if (parseFloat(s) < 0) 
					return false;
			}
		}
	}

	return true;
}

/*
function isInteger(s){
	if (Left(s, 1) == "+")
		s = Right(s, s.length - 1);
	
	if (isEmpty(s) == false)
		return reInteger.test(s);
}
*/

function isPosInteger(s, required, equal){
	if (required == true && isEmpty(s) == true)
		return false;
	
	if (isEmpty(s) == false){
		var bInteger;
		
		if (Left(s, 1) == "+")
			s = Right(s, s.length - 1);
		
		bInteger = reInteger.test(s);

		if (bInteger == false)
			return false;
		else 		
			if (equal == 1)//lon hon 0
				if (parseInt(s) <= 0) return false;
			else //cho phep bang 0
				if (parseInt(s) < 0) return false;
	}

	return true;
}

function FormatNumber(num, decimalNum, bolLeadingZero, bolParens, bolCommas){

	if (isPosFloat(num, false) == false) return num;

	var tmpNum = num;
	var iSign = num < 0 ? -1 : 1;		// Get sign of number
	
	// Adjust number so only the specified number of numbers after
	// the decimal point are shown.
	tmpNum *= Math.pow(10,decimalNum);
	tmpNum = Math.round(Math.abs(tmpNum))	
	tmpNum /= Math.pow(10,decimalNum);
	tmpNum *= iSign;					// Readjust for sign
	
	// Create a string object to do our formatting on
	var tmpNumStr = new String(tmpNum);

	// See if we need to strip out the leading zero or not.
	if (!bolLeadingZero && num < 1 && num > -1 && num != 0)
		if (num > 0)
			tmpNumStr = tmpNumStr.substring(1,tmpNumStr.length);
		else
			tmpNumStr = "-" + tmpNumStr.substring(2,tmpNumStr.length);
		
	// See if we need to put in the commas
	if (bolCommas && (num >= 1000 || num <= -1000)) {
		var iStart = tmpNumStr.indexOf(".");
		if (iStart < 0)
			iStart = tmpNumStr.length;

		iStart -= 3;
		while (iStart > 1) {
			tmpNumStr = tmpNumStr.substring(0,iStart) + "," + tmpNumStr.substring(iStart,tmpNumStr.length)
			iStart -= 3;
		}		
	}

	// See if we need to use parenthesis
	if (bolParens && num < 0)
		tmpNumStr = "(" + tmpNumStr.substring(1,tmpNumStr.length) + ")";

	return tmpNumStr;		// Return our formatted string!
}

/***********************
Date & Time
***********************/

function isDate(s, type, separate, required){
	if (required == true && isEmpty(s) == true){
		return 0;
	}

	if (type > 2) 
		type = 1;

	if (type < 0) 
		type = 0;
	//type:  0: French format: dd/mm/yyyy
	//       1: US format: mm/dd/yyyy

	var i = 0;
	var d, m, y;

	if (type){
		m = s.substr(0,s.indexOf(separate));
		s = s.substr(s.indexOf(separate) + 1);
		d = s.substr(0,s.indexOf(separate));
		y = s.substr(s.indexOf(separate) + 1);
	}
	else{
		d = s.substr(0,s.indexOf(separate));
		s = s.substr(s.indexOf(separate) + 1);
		m = s.substr(0,s.indexOf(separate));
		y = s.substr(s.indexOf(separate) + 1);
	}

	if (isNumberLetter(y) == true && isNumberLetter(m) == true && isNumberLetter(d) == true){
		if (y.length != 4) {
			return 1;
		}

		iDay = parseFloat(d);
		iMon = parseFloat(m);
		iYear = parseFloat(y);

		if (iYear < 1900){
			return 2;
		}

		if ((iDay > 31)||(iDay < 1)){
			return 3;
		}

		if ((iMon > 12)||(iMon < 1)){
			return 4;
		}
	
		if (((iMon == 4)||(iMon == 6)||(iMon == 9)||(iMon == 11))&&(iDay > 30)){
			return 5;
		}

		if (iMon == 2){
			if (iYear%4 == 0){
				if ((iYear%100 != 0)||(iYear%400 == 0)){
					if (iDay > 29){
						return 6;
					}
				}
				else if (iDay > 28){
					return 7;
				}
			}
			else{
				if (iDay > 28){
					return 7;
				}	
			}
		}
	}
	else{
		return 8;
	}

	return -1;
}

/*
function compareDate(d1,d2){
	var i = 0;
	var mm1="",dd1="",yy1="";
	while(i<d1.length && d1.charAt(i)!="/") mm1+=d1.charAt(i++);i++;	
	while(i<d1.length && d1.charAt(i)!="/") dd1+=d1.charAt(i++);i++;	
	while(i<d1.length && d1.charAt(i)!="/") yy1+=d1.charAt(i++);	
	i=0;
	var mm2="",dd2="",yy2="";
	while(i<d2.length && d2.charAt(i)!="/") mm2+=d2.charAt(i++);i++;	
	while(i<d2.length && d2.charAt(i)!="/") dd2+=d2.charAt(i++);i++;	
	while(i<d2.length && d2.charAt(i)!="/") yy2+=d2.charAt(i++);	
	if(parseInt(yy1)< parseInt(yy2)) return -1;
	else if(parseInt(yy1)> parseInt(yy2)) return 1;
		 else if(parseInt(mm1)< parseInt(mm2)) return -1;
		 	else if(parseInt(mm1)> parseInt(mm2)) return 1; 
				 else if(parseInt(dd1)< parseInt(dd2)) return -1;
				 	  else if(parseInt(dd1)> parseInt(dd2)) return 1;	
							else return 0;
}
*/

function compareDate(date1, date2) {
	var d1 = new Date(date1);
	var d2 = new Date(date2);
	
	var timeleft;
	timeleft = d1.getTime() - d2.getTime();

	if (parseFloat(timeleft) > 0)
		return -1;
	else if (parseFloat(timeleft) < 0)
		return 1;
	else
		return 0;
}

/***********************/
//Email

//function CheckEmail (emailStr) {
function isEmail(emailStr, len, required){

	emailStr = emailStr.toLowerCase();

	if (CheckLen(emailStr, len, required) == false){
		return false;
	}

	if (isEmpty(emailStr) == false){
		/* The following variable tells the rest of the function whether or not
		to verify that the address ends in a two-letter country or well-known
		TLD. 1 means check it, 0 means don't. */

		var checkTLD=1;

		/* The following is the list of known TLDs that an e-mail address must end with. */
		var knownDomsPat=/^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum)$/;

		/* 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="\\(\\)><@,;:\\\\\\\"\\.\\[\\]";
		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];

		// Start by checking that only basic ASCII characters are in the strings (0-127).

		for (i=0; i<user.length; i++) {
			if (user.charCodeAt(i)>127) {
				//alert("Ths username contains invalid characters.");
				return false;
			}
		}

		for (i=0; i<domain.length; i++) {
			if (domain.charCodeAt(i)>127) {
				//alert("Ths domain name contains invalid characters.");
				return false;
			}
		}

		// 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.  Check if it's valid.
 
		var atomPat=new RegExp("^" + atom + "$");
		var domArr=domain.split(".");
		var len=domArr.length;
		for (i=0;i<len;i++) {
			if (domArr[i].search(atomPat)==-1) {
				//alert("The domain name does not seem to be valid.");
				return false;
			}
		}

		/* domain name seems valid, but now make sure that it ends in a
		known top-level domain (like com, edu, gov) or a two-letter word,
		representing country (uk, nl), and that there's a hostname preceding 
		the domain or country. */

		if (checkTLD && domArr[domArr.length-1].length!=2 && 
				domArr[domArr.length-1].search(knownDomsPat)==-1) {
			//alert("The address must end in a well-known domain or two letter " + "country.");
			return false;
		}

		// Make sure there's a host name preceding the domain.

		if (len<2) {
			//alert("This address is missing a hostname!");
			return false;
		}

		// If we've gotten this far, everything's valid!
		//return true;
	}

	return true;
}

/***********************
 US ZipCode, Phone, Fax, Social Security Number
***********************/

function isUSZipCode(s, required) {
	if (required == true && isEmpty(s) == true){
		return false;
	}

	if (isEmpty(s) == false){
		//var regex = new RegExp(USZipCode);
		//var bFlag = regex.test(s);
		var bFlag = USZipCode.test(s);
		if (bFlag == false) return false;
	}

	return true;
}

function FormatUSZipCode(s){
	var Zip;

	Zip = s.value;

	if (isEmpty(s.value) == false && s.value.length != 5){
		if (isUSZipCode(Zip, false) == true)
			Zip = reformat(stripCharsInBag(Zip, ZIPCodeDelimiters), "", 5, "-", 4);
	}

	s.value = Zip;
	return true;
}

function isUSPhone(s, required){
	if (required == true && isEmpty(s) == true){
		return false;
	}

	if (isEmpty(s) == false){
		//var regex = new RegExp(USPhone);
		//return reAlphabetic.test(s);
		var bFlag = USPhone.test(s);
		if (bFlag == false) return false;
	}

	return true;
}

function isPhone(s, required){
	if (required == true && isEmpty(s) == true){
		return false;
	}

	if (isEmpty(s) == false){
		//var regex = new RegExp(USPhone);
		//return reAlphabetic.test(s);
		var bFlag = phoneRe.test(s);
		if (bFlag == false) return false;
	}

	return true;
}

function isMobilePhone(s, required){
	if (required == true && isEmpty(s) == true){
		return false;
	}

	if (isEmpty(s) == false){
		//var regex = new RegExp(USPhone);
		//return reAlphabetic.test(s);
		var bFlag = mobilePhoneRe.test(s);
		if (bFlag == false) return false;
	}

	return true;
}


function FormatUSPhone(s){
	var Phone;
	Phone = s.value;
	if (isEmpty(Phone) == false){
		if (isUSPhone(Phone, false) == true)
			Phone = reformat(stripCharsInBag(Phone, phoneNumberDelimiters), "(", 3, ") ", 3, "-", 4);
	}

	s.value = Phone;
	return true;
}

function isSSN(s, required){
	if (required == true && isEmpty(s) == true){
		return 0;
	}

	if (isEmpty(s) == false){
		//var regex = new RegExp(SSN);
		//var bFlag = regex.test(s);
		var bFlag = SSN.test(s);
		
		if (bFlag == false){
			return 1;
		}
		else
			if (Left(s, 3) == "000"){
				return 2;
		}
	}

	return -1;
}

function FormatSSN(s){
	var str;
	str = s.value;
	
	if (isEmpty(str) == false){
		if (isSSN(str, false) == -1)
			str = reformat(stripCharsInBag(str, SSNDelimiters), "", 3, "-", 2, "-", 4)
	}
	
	s.value = str;
	return true;
}

/***********************
         Form
***********************/

function GetRadioButtonValue(param){
	if (param == null)
		return;
	if (param.length >= 2)
		for (i = 0; i < param.length; i++){
			if (param[i].checked)
				return param[i].value;
		}
	else{
		if (param.checked) 
			return param.value;
	}

	return "";
}

/*******************************
Credit Card
*******************************/
/*  ================================================================
    FUNCTION:  CheckCard(st)
    INPUT:     st - a string representing a credit card number
    RETURNS:  true, if the credit card number passes the Luhn Mod-10
		    test.
	      false, otherwise
    ================================================================ */
function CheckCard(st) {
	if (st.length > 19)
		return (false);
	sum = 0; mul = 1; l = st.length;
	for (i = 0; i < l; i++) {
		digit = st.substring(l - i - 1, l - i);
		tproduct = parseInt(digit, 10) * mul;
		if (tproduct >= 10)
			sum += (tproduct % 10) + 1;
		else
			sum += tproduct;
		if (mul == 1)
			mul++;
		else
			mul--;
	}
	// Uncomment the following line to help create credit card numbers
	// 1. Create a dummy number with a 0 as the last digit
	// 2. Examine the sum written out
	// 3. Replace the last digit with the difference between the sum and the next multiple of 10.
	//  document.writeln("<BR>Sum      = ",sum,"<BR>");
	//  alert("Sum      = " + sum);
	if ((sum % 10) == 0)
		return (true);
	else
		return (false);
}

function isCreditCard(s, type){
	switch (type) {
		case 1:

/*  ================================================================
    Visa Card
    Sample number: 4111 1111 1111 1111 (16 digits)
    ================================================================ */
			if (((s.length == 16) || (s.length == 13)) && (s.substring(0,1) == 4))
				return CheckCard(s);
			return false;
			break;

/*  ================================================================
    MasterCard
    Sample number: 5500 0000 0000 0004 (16 digits)
    ================================================================ */
		case 2:
			firstdig = s.substring(0,1);
			seconddig = s.substring(1,2);
			if ((s.length == 16) && (firstdig == 5) && ((seconddig >= 1) && (seconddig <= 5)))
				return CheckCard(s);
			return false;
			break;

/*  ================================================================
		AmericanExpress
    Sample number: 340000000000009 (15 digits)
    ================================================================ */
		case 3:
			firstdig = s.substring(0,1);
			seconddig = s.substring(1,2);
			if ((s.length == 15) && (firstdig == 3) && ((seconddig == 4) || (seconddig == 7)))
				return CheckCard(s);
			return false;
			break;

/*  ================================================================
		DinersClub
    Sample number: 30000000000004 (14 digits)
    ================================================================ */
		case 4:
			firstdig = s.substring(0,1);
			seconddig = s.substring(1,2);
			if ((s.length == 14) && (firstdig == 3) && ((seconddig == 0) || (seconddig == 6) || (seconddig == 8)))
				return CheckCard(s);
			return false;
			break;

/*  ================================================================
		Discover
    Sample number: 6011000000000004 (16 digits)
    ================================================================ */
		case 5:
			first4digs = s.substring(0,4);
			if ((s.length == 16) && (first4digs == "6011"))
				return CheckCard(s);
			return false;

/*  ================================================================
		EnRoute
    Sample number: 201400000000009 (15 digits)
    ================================================================ */
		case 6:
			first4digs = s.substring(0,4);
			if ((s.length == 15) && ((first4digs == "2014") || (first4digs == "2149")))
				return CheckCard(s);
			return false;
			break;
	}
}

function isPDF(filename)
{
	if (filename.toUpperCase().indexOf(".PDF") != -1)
		return true;
	else
		return false;
}

function isJPG(filename)
{
	if (filename.toUpperCase().indexOf(".JPG") != -1)
		return true;
	else
		return false;
}

function isJPE(filename)
{
	if (filename.toUpperCase().indexOf(".JPE") != -1)
		return true;
	else
		return false;
}

function isPNG(filename)
{
	if (filename.toUpperCase().indexOf(".PNG") != -1)
		return true;
	else
		return false;
}

function isBMP(filename)
{
	if (filename.toUpperCase().indexOf(".BMP") != -1)
		return true;
	else
		return false;
}

function isWMF(filename)
{
	if (filename.toUpperCase().indexOf(".WMF") != -1)
		return true;
	else
		return false;
}

function isGIF(filename)
{
	if (filename.toUpperCase().indexOf(".GIF") != -1)
		return true;
	else
		return false;
}

function isTIF(filename)
{
	if (filename.toUpperCase().indexOf(".TIF") != -1)
		return true;
	else
		return false;
}

function isTIFF(filename)
{
	if (filename.toUpperCase().indexOf(".TIFF") != -1)
		return true;
	else
		return false;
}

function isWebImg(f)
{
	if (isGIF(f) || isJPG(f) || isPNG(f) || isBMP(f) || isWMF(f) || isJPE(f) || isTIFF(f) || isTIF(f)) 
		return true;
	else
		return false;
}
function checkUserName(s, min_len)
{
	if (s.length < min_len)
		return false;
	else
		if (isValidChar(s) == false || isRightUsername(s) == false)
			return false;
	
	return true;
}