//********************* Remove spaces at the beginning & at the end *********************
function trim(strText) { 
    // this will get rid of leading spaces 
    while (strText.substring(0,1) == ' ') 
        strText = strText.substring(1, strText.length);

    // this will get rid of trailing spaces 
    while (strText.substring(strText.length-1,strText.length) == ' ')
        strText = strText.substring(0, strText.length-1);

   return strText;
} 

function checkPhone(theString)
{
	len=theString.length;
	chars="0123456789-,()";
	for(i=0; i<len; i++)
	{
		if (chars.indexOf(theString.charAt(i))<0)
   		{
   			return false;
		}
	}
	return true;
}

var whitespace = " \t\n\r";

function isEmpty(s) {   
	return ((s == null) || (s.length == 0))
}

function isWhitespace (s) {   
	var i;

    if (isEmpty(s)) 
		return true;
    for (i = 0; i < s.length; i++) {   
        var c = s.charAt(i);
        if (whitespace.indexOf(c) == -1) 
			return false;
    }
    return true;
}

function charInString (c, s) {   
	for (i = 0; i < s.length; i++) {   
		if (s.charAt(i) == c) 
			return true;
    }
    return false
}

function stripInitialWhitespace (s) {   
	var i = 0;

    while ((i < s.length) && charInString (s.charAt(i), whitespace))
       i++;
    
    return s.substring (i, s.length);
}

function isEmail (s) {   
	if (isEmpty(s)) {
		return false;
	}

    if (isWhitespace(s)) {
		return false;
	}
    
    var i = 1;
    var sLength = s.length;

    while ((i < sLength) && (s.charAt(i) != "@")) { 
		i++;
    }

    if ((i >= sLength) || (s.charAt(i) != "@")) {
		return false;
    } else 
		i += 2;

    while ((i < sLength) && (s.charAt(i) != ".")) { 
		i++;
    }

    if ((i >= sLength - 1) || (s.charAt(i) != ".")) {
		return false;
    } else 
		return true;
}

function checkNum(theString)
{
	len=theString.length;
	chars="0123456789";
	for(i=0; i<len; i++)
	{
		if (chars.indexOf(theString.charAt(i))<0)
   		{
   			return false;
		}
	}
	return true;
}

function checkDescription(theString){
	len=theString.length;
	if (len > 255) {
		return false;
	} else {
		return true;
	}
}

function search_win(php, win_name) {
	vWinCal = window.open(php, win_name, 
		"width=620,height=500,status=no,resizable=no,top=200,left=200,scrollbars=yes");
	vWinCal.opener = self;
	ggWinCal = vWinCal;
}//********************* Remove spaces at the beginning & at the end *********************
function trim(strText) { 
    // this will get rid of leading spaces 
    while (strText.substring(0,1) == ' ') 
        strText = strText.substring(1, strText.length);

    // this will get rid of trailing spaces 
    while (strText.substring(strText.length-1,strText.length) == ' ')
        strText = strText.substring(0, strText.length-1);

   return strText;
} 

function replaceSpace(theString) {
	out = " ";
	add = "%20";

	while (theString.indexOf(out)>-1) {
		pos = theString.indexOf(out);
		theString = "" + (theString.substring(0, pos) + add + theString.substring((pos + out.length), theString.length));
	}
	return(theString);
}
//********************* Input must in 'A' - 'Z' or 1 - 9 *********************
function checkChar(theString)
{
	len=theString.length;
	chars="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz.\\:_- ";
	for(i=0; i<len; i++)
	{
		if (chars.indexOf(theString.charAt(i))<0)
   		{
			return false;
		}
	}
	return true;
}

function checkNum(theString)
{
	len=theString.length;
	chars="0123456789";
	for(i=0; i<len; i++)
	{
		if (chars.indexOf(theString.charAt(i))<0)
   		{
   			return false;
		}
	}
	return true;
}

function checkPhone(theString)
{
	len=theString.length;
	chars="0123456789-,()";
	for(i=0; i<len; i++)
	{
		if (chars.indexOf(theString.charAt(i))<0)
   		{
   			return false;
		}
	}
	return true;
}

//********************* Check valid date input *********************
function isDate (year, month, day) {
	DaysInMonthArr = [31,29,31,30,31,30,31,31,30,31,30,31]
	if (isNaN(month) || isNaN(day) || isNaN(year) || month>12 || day>31 || month<1 || day<1 || year < 1)
		return false;
	
	// February has 29 days in any year evenly divisible by four,
    // EXCEPT for centurial years which are not also divisible by 400.
    if ((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0) ) )
		DaysInMonthArr[1] = 29
	else
		DaysInMonthArr[1] = 28;
	if (day > DaysInMonthArr[month-1]) return false;
	return true;
}

function checkDate(theString) {
	chars="0123456789";
	c = "-";
	for (i=0; i<4; i++)
	{
		if (chars.indexOf(theString.charAt(i))<0)
		{
			return false;
		}
	}
	if (c.indexOf(theString.charAt(4))<0)
	{
		return false;
	}
	for (i=5; i<7 ; i++)
	{
		if (chars.indexOf(theString.charAt(i))<0)
		{
			return false;
		}
	}
	if (c.indexOf(theString.charAt(7))<0)
	{
		return false;
	}
	for (i=8; i<10 ; i++)
	{
		if (chars.indexOf(theString.charAt(i))<0)
		{
			return false;
		}
	}
	return true;
}

var whitespace = " \t\n\r";

function isEmpty(s) {   
	return ((s == null) || (s.length == 0))
}

function isWhitespace (s) {   
	var i;

    if (isEmpty(s)) 
		return true;
    for (i = 0; i < s.length; i++) {   
        var c = s.charAt(i);
        if (whitespace.indexOf(c) == -1) 
			return false;
    }
    return true;
}

function charInString (c, s) {   
	for (i = 0; i < s.length; i++) {   
		if (s.charAt(i) == c) 
			return true;
    }
    return false
}

function stripInitialWhitespace (s) {   
	var i = 0;

    while ((i < s.length) && charInString (s.charAt(i), whitespace))
       i++;
    
    return s.substring (i, s.length);
}

function isEmail (s) {   
	if (isEmpty(s)) {
		return false;
	}

    if (isWhitespace(s)) {
		return false;
	}
    
    var i = 1;
    var sLength = s.length;

    while ((i < sLength) && (s.charAt(i) != "@")) { 
		i++;
    }

    if ((i >= sLength) || (s.charAt(i) != "@")) {
		return false;
    } else 
		i += 2;

    while ((i < sLength) && (s.charAt(i) != ".")) { 
		i++;
    }

    if ((i >= sLength - 1) || (s.charAt(i) != ".")) {
		return false;
    } else 
		return true;
}

function checkID(theString)
{
	len=theString.length;
	chars="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
	for(i=0; i<len; i++)
	{
		if (chars.indexOf(theString.charAt(i))<0)
   		{
   			return false;
		}
	}
return true;
}

function checkFloat(theString)
{
	len=theString.length;
	chars="0123456789.";
	for(i=0; i<len; i++)
	{
		if (chars.indexOf(theString.charAt(i))<0)
   		{
   			return false;
		}
	}
return true;
}

function checkGrade(theString)
{
	len=theString.length;
	chars="ABCDEF+-";
	for(i=0; i<len; i++)
	{
		if (chars.indexOf(theString.charAt(i))<0)
   		{
   			return false;
		}
	}
return true;
}

function checkPass(theString)
{
	len=theString.length;
	chars="PF";
	for(i=0; i<len; i++)
	{
		if (chars.indexOf(theString.charAt(i))<0)
   		{
   			return false;
		}
	}
return true;
}

function checkURL(theString)
{
	len=7;
	chars="http://";
	for(i=0; i<len; i++)
	{
		if (chars.indexOf(theString.charAt(i))<0)
   		{
   			return false;
		}
	}
	return true;
}

function isInteger(num){
	if (num != parseInt(num))
	{
		return false
	} else {
		return true;
	}
}

function checkText(theString){
	len=theString.length;
	if (len > 120) {
		return false;
	} else {
		return true;
	}
}

function checkReason(theString){
	len=theString.length;
	if (len > 255) {
		return false;
	} else {
		return true;
	}
}

function checkaddress(theString){
	len=theString.length;
	if (len > 24) {
		return false;
	} else {
		return true;
	}
}