<!--

// ############################################################################	//
// ###	GENERAL FUNCTIONS													###	//
// ############################################################################ //

function trim(str) {
	// remove the space of head and tail
	return ((str.replace(/^\W+/,'')).replace(/\W+$/,''));
}

// is it an integer?
function isInteger(s) {
	var i;
    for (i = 0; i < s.length; i++) {
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    return true;
}

// is it a word?
function isWord(sWord) {
//	var sRegular = /^([a-zA-Z])+([a-zA-Z0-9])*$/;
	var sRegular = /^[a-zA-Z]{1}[a-zA-Z0-9]*$/;
	if (!sRegular.test(sWord))  {
		return false;
	} else {
		return true;
	}
}


// ############################################################################	//
// ###	DATE VALIDATION														###	//
// ############################################################################ //

function daysInFebruary (year){
	// February has 29 days in any year evenly divisible by four,
    // EXCEPT for centurial years which are not also divisible by 400.
    return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}
function DaysArray(n) {
	for (var i = 1; i <= n; i++) {
		this[i] = 31
		if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
		if (i==2) {this[i] = 29}
   } 
   return this
}

function isDate(strYear, strMonth, strDay) {
	
	var daysInMonth	= DaysArray(12);

	// check the year
	if (isInteger(strYear) && (strYear.length==4)) {
		intYear = parseInt(strYear, 10);
		if (intYear<1900 || intYear>2100) {
//			alert("Please enter a valid year.");
			return false;
		}
	} else {
//		alert("Please enter a valid year.");
		return false;
	}

	// check the month
	if (isInteger(strMonth) && (strMonth.length>0)) {
		intMonth = parseInt(strMonth, 10);
		if (intMonth<1 || intMonth>12) {
//			alert("Please enter a valid month.");
			return false;
		}
	} else {
//		alert("Please enter a valid month.");
		return false;
	}
	
	// check the day
	intDay = parseInt(strDay, 10);
	if (isInteger(strDay) && (strDay.length>0)) {
		intDay = parseInt(strDay, 10);
		if (intDay<1 || intDay>31 || (intMonth==2 && intDay>daysInFebruary(intYear)) || (intDay>daysInMonth[intMonth])) {
//			alert("Please enter a valid day.");
			return false;
		}
	} else {
//		alert("Please enter a valid day.");
		return false;
	}
	
	return true;
}

function isMinimumAge(sMonth,sDay,sYear,iOver) {
	var today = new Date();
	var bday = new Date(parseInt(sYear, 10) + parseInt(iOver, 10), parseInt(sMonth, 10) - 1, parseInt(sDay, 10));
	if ((today.getTime() - bday.getTime())<=0) {
		return false;
	} else {
		return true;
	}
}


// ############################################################################	//
// ###	ADDRESS FUNCTIONS													###	//
// ############################################################################ //

// check the zipcode 
function isValidZip(sZIP,sCountry) {
//	alert("wtf");
	if (sCountry=="US") {
		var sRegular = /^[\d]{5}(-*[\d]{4})*$/;
//	} else if (sCountry=="CA") {
//		var sRegular = /^[a-zA-Z][\d][a-zA-Z][\s-]*[\d][a-zA-Z][\d]$/;
	} else {
		var sRegular = /[\w_\-\.]{3,}/;
		return true;
	}
	if (!sRegular.test(sZIP)) {
		return false;
	} else {
		return true;
	}
}

// check city
function isValidCity(sCity) {
	var sRegular = /^([a-zA-Z])+([a-z A-Z])+([a-zA-Z0-9])*/;
	if(!sRegular.test(sCity)) {
		return false;
	} else {
		return true;
	}
}

// check email
function isValidEmail(sEmail) {
	var sRegular = /^\w(([-._\w]*\w)|)@\w[-._\w]*\w\.\w{2,6}$/;
	if (sRegular.test(sEmail)) {
		return true;
	} else {
		return false;
	}
}

// check domain
function isValidDomain(sDomain) {
	var sRegular = /^([a-zA-Z0-9]([a-zA-Z0-9\-]{0,61}[a-zA-Z0-9])?\.)+[a-zA-Z]{2,6}$/;
	if (sRegular.test(sDomain)) {
		return true;
	} else {
		return false;
	}
}
//-->