function is_image_filename(the_filename) {
	// check the uploaded file name is an image file 
	var temp_string =the_filename.toLowerCase();
	if ( temp_string.indexOf('.gif') <  0 && temp_string.indexOf('.jpg') < 0 & temp_string.indexOf('.jpeg') <0 ) 
		return false;
	else 
		return true;
}

function is_media_filename(the_filename) {
	// check the uploaded file name is an image file 
	var temp_string=the_filename.toLowerCase();
	if (temp_string.indexOf('.avi') < 0  && temp_string.indexOf('.wav') < 0 && temp_string.indexOf('.mov') < 0 && temp_string.indexOf('.mpg') < 0 && temp_string.indexOf('.mpeg') < 0 && temp_string.indexOf('.aif') < 0) 
		return false;
	else
		return true;
}

function is_integer(TheValue) {
    var lnValue = TheValue + "";	
    
    if (is_empty(lnValue == "")) return false;
    for (var i = 0; i < lnValue.length; i++){
    	if ( lnValue.charAt(i) < "0" || lnValue.charAt(i) > "9" )
    		return false;
	}
    return true;
}

function is_number(TheValue) {
    var lnValue = TheValue + "";	
    
    if ( is_empty(lnValue == "") ) return false;
    for (var i = 0; i < lnValue.length; i++){
    	if ( (lnValue.charAt(i) < "0" || lnValue.charAt(i) > "9") &&
    		(lnValue.charAt(i) != "." && lnValue.charAt(i) != "-")
		)
    		return false;
    	}
    return true;
}

function is_empty(the_string) {
	//check a string is real empty or not, treat a string with spaces as empty
	var temp_string = String(the_string), x=0;
	for(x=0; x < temp_string.length; x++) {
		if(temp_string.charAt(x) != ' ')
			return false;
	}
	return true;
}

function is_ssn(the_string) {
	//check a string is ssn which should all numerics and 9 digits
	if (isNaN(the_string))
		return false;
	if (the_string.length != 9 && the_string.length!=0)
		return false;
	return true;
}


function is_email(the_string) {
	// check the format of given value for email, looking for xx@xxx.xxx
	var temp_string = String(the_string), x=0, number_of_at=0;
	var found_at=false, found_period = false;
	for(x=0; x < temp_string.length; x++) {
		if(temp_string.charAt(x) == ' ' || temp_string.charAt(x) == ';' || temp_string.charAt(x) == ',' || temp_string.charAt(x) == '\'') {
			// found space semicolon, command
			return false;
		}
		if(temp_string.charAt(x) == '@' && temp_string.charAt(x+1) != '') {
			number_of_at = number_of_at +1;
			found_at = true;
		}
		if(temp_string.charAt(x) == '.'  && temp_string.charAt(x+1) != '')
			found_period = true;
	}
	if(number_of_at != 1)
		return false;
	else if(found_at && found_period)
		return true;
	else
		return false;
}


function is_checked(the_element) {
	// the element should be document.formname.elementname
	var x=0;
	if( eval(the_element + ".length") ) {
		for(x=0; x< eval(the_element + ".length"); x++) {
			if(eval(the_element + "[x].checked")) 
				return true;
		}
		return false;
	}
	else {
		if( eval(the_element + ".checked") ) 
			return true;
		else 
			return false;
	}
}

function GetNumOfCheck(the_element) {
	// return the number of checked items, check box
	var x=0, y=0;
	for(x=0; x< eval(the_element + ".length"); x++) {
		if(eval(the_element + "[x].checked")) 
			y = y+1;
	}
	return y;
}

function GetNumOfSelect(the_element) {
	// return the number of selected items , selection box
	var x=0, y=0;
	for(x=0; x< eval(the_element + ".length"); x++) {
		if(eval(the_element + "[x].selected")) 
			y = y+1;
	}
	return y;
}

function is_zipcode(the_value) {
	//"The format for Zip Code is '99999', '99999-5555', or '999995555'
	if(is_empty(the_value))
		return true;
	//get the first 5 char see if digit or not
	var temp_string = String(the_value), x=0;
	var temp_s = "";
	// remove all space
	for(x=0; x < temp_string.length; x++) {
		if(temp_string.charAt(x) != ' ') 
			temp_s = temp_s + temp_string.charAt(x);
	}
	if(temp_s.length !=5 && temp_s.length !=10 && temp_s.length !=9) 
		return false;
	if(temp_s.length == 10 && temp_s.charAt(5) != '-')
		return false;
	if(temp_s.length < 10) {
		// every char must be number
		for(x=0; x <temp_s.length; x++) {
			if( isNaN(temp_s.charAt(x)) )
				return false;
		}
	}
	return true;
}


function is_hintquestion(the_value) {
	// the question should be at least 5 char
	var temp_string = String(the_value);
	if(temp_string.length <5)
		return false;
	return true;
}

function is_hintanswer(the_value) {
	// the question should be at least 5 char
	var temp_string = String(the_value);
	if(temp_string.length <5)
		return false;
	return true;
}

function is_password(the_value) {
	// the user should be 1. no space, 2. at least 4 char
	var temp_string = String(the_value), x=0;
	if(temp_string.length <4)
		return false;
	for(x=0; x < temp_string.length; x++) {
		if(temp_string.charAt(x) == ' ') 
			return false;
	}
	return true;
}

function is_username(the_value) {
	// the user should be 1. no space, 2. at least 6 char
	var temp_string = String(the_value), x=0;
	if(temp_string.length <6)
		return false;
	for(x=0; x < temp_string.length; x++) {
		if( !( (temp_string.charCodeAt(x) >= 48 && temp_string.charCodeAt(x) <= 57) || (temp_string.charCodeAt(x) >= 65 && temp_string.charCodeAt(x) <= 90) || (temp_string.charCodeAt(x) >= 97 && temp_string.charCodeAt(x) <= 122)))
			return false;
	}
	return true;
}

function is_date(the_value) {
	// check if the_value is "MM/DD/YYYY" format
	var temp_string = String(the_value), x=0;
	if(temp_string.length !=10 && temp_string.length !=0) {
		return false;
	}
	for(x=0; x < temp_string.length; x++) {
		if(x!=2 && x!=5) {
			if(isNaN(temp_string.charAt(x)))
				return false;
		}
		else {
			if(temp_string.charAt(x) != '/') 
				return false;	
		}
	}
	if( parseInt(temp_string.substring(0,2),10) == 0 )
		return false;
	if( parseInt(temp_string.substring(3,5),10) == 0 )
		return false;
	if( parseInt(temp_string.substring(6,10),10) == 0 )
		return false;
	if(is_date) {
		var lcTotalDays
		if(parseInt(temp_string.substring(0,2),10) > 12) 
			return false;
		else {
			if(parseInt(temp_string.substring(0,2),10) == 1 || parseInt(temp_string.substring(0,2),10) == 3 ||
				parseInt(temp_string.substring(0,2),10) == 5 || parseInt(temp_string.substring(0,2),10) == 7 ||
				parseInt(temp_string.substring(0,2),10) == 8 || parseInt(temp_string.substring(0,2),10) == 10 ||
				parseInt(temp_string.substring(0,2),10) == 12) 
				lcTotalDays = 31
			if(parseInt(temp_string.substring(0,2),10) == 4 || parseInt(temp_string.substring(0,2),10) == 6 ||
				parseInt(temp_string.substring(0,2),10) == 9 || parseInt(temp_string.substring(0,2),10) == 11) 
				lcTotalDays = 30
			if(parseInt(temp_string.substring(0,2),10) == 2) {
				if( (parseInt(temp_string.substring(6,10),10) % 4) == 0) 
					lcTotalDays = 29
				else
					lcTotalDays = 28
			}
			if(parseInt(temp_string.substring(3,5),10) > lcTotalDays)
				return false;
		}
	}
	return true;
}

