<!--
/*

  --------------------------------------------------------------
 |                                                              |
 |  All Code contained herein and that contained in the same    |
 |  directory location as this file or script including this    |
 |  script is the sole intellectual property of                 |
 |  DigitallyDistint.com. If you wish to use and or copy the    |
 |  above described property in part or in whole, please        |
 |  request permission to do so by sending an e-mail request to |
 |  codeuse@digitallydistinct.com. Wait for a confirmation      |
 |  reply email granting such permission before preceding       |
 |  to use and/or copy the above described property. Use of     |
 |  this code on any public or private web site is unauthorized |
 |  unless this entire copyright notice appears unchanged and   |
 |  you publicly display on the Web page a link to              |
 |  http://www.digitallydistinct.com/.                          |
 |                                                              |
 |  Copyright © 2000-2001 DigitallyDistinct.com. All rights     |
 |  reserved.                                                   |
 |                                                              |
 |  Contact codeuse@digitallydistinct.com for all other uses.   |
 |                                                              |
  --------------------------------------------------------------

 Organization: DigitallyDistinct.com
       Domain: www.troysartwork.com
         Date: December 18, 2001
      Purpose: Date and time functions
 Dependencies: None
   Programmer: B. Roberts
               broberts@digitalldistinct.com

*/

// REMOVES EXTRA SPACE FROM THE BEGINNING, MIDDLE, AND END OF A STRING
function trim(inString){
	var retVal = "";
	var start = 0;
	var space = false;
	var newstr="";
	while ((start < inString.length) && (inString.charAt(start) == ' ')) ++start;
	var end = inString.length;
	while ((end > 0) && (inString.charAt(end - 1) == ' ')) --end;
	retVal = inString.substring(start, end);
	for(var i=0;i<retVal.length;i++){
		if(!space) newstr+=retVal.charAt(i);
		if(retVal.charAt(i)==" " && retVal.charAt(i+1)==" ") space=true;
		else space=false;
	}
	retVal=newstr;
	return retVal;
}

// TAKES A TEXT STRING AND RETURNS THE STRING FORMATTED LIKE A PROPER NOUN SUCH AS A PERSON'S NAME
function toProperCase(str){
	var newstr="";
	str=trim(str);
	if(isSpace(str)) return false;
	for(var i=0;i<str.length;i++){
		if(i==0 || str.charAt(i-1)==" ") newstr+=str.charAt(i).toUpperCase(); 
		else newstr+=str.charAt(i).toLowerCase();
	}
	return newstr;
}

// EVALUATES A TEXT STRING AND TEST TO SEE IF IT IS BLANK OR CONTAINS ONLY BLANK SPACES
function isSpace(str){
	if(str=="") return true;
	if(str.replace(/ /g,"").length==0) return true;
	return false;
}

// DETERMINES WHETHER A STRING IS A VALID POSITIVE INTEGER
function isPosInt(str){
	var validChars = "0123456789";
	var validChar = true;
	if(str=="") return false;
	for(i=0;i<str.length&&validChar;i++){
		validChar = false;
		for(j=0;j<validChars.length&&!validChar;j++){
			if(str.charAt(i)==validChars.charAt(j))
				validChar = true;
		}
	}
	return validChar;
}

//DETERMINE WHETHER A GIVEN YEAR, MONTH, AND DAY FORM A VALID DATE
function isDate(year,month,day){
	month = month - 1;  // javascript month range : 0- 11
  	var tempDate = new Date(year,month,day);
  	if ( (y2kYearFix(tempDate.getYear()) == year) && (month == tempDate.getMonth()) && (day == tempDate.getDate()) )
    	return true;
  	else
		return false;
}

//SPLITS A SUPPOSED DATE STRING BY THE "/" SEPERATOR
function parseDateString(string_val,part){
	var date_array;
	date_array = string_val.split("/");
	return date_array[part]; 
}

//VALIDATES A STRING AS A VALID DATE
function validDate(string_val){
	var month,day,year;
	month = parseDateString(string_val,0);
	day   = parseDateString(string_val,1);
	year  = parseDateString(string_val,2);
	return isDate(year,month,day);
}

//ADDRESSES THE REPORTING OF A DATE'S YEAR AS A 2-DIGIT VS. A 4-DIGIT NUMBER
function y2kYearFix(d){ 
	return (d < 1000) ? d + 1900 : d;
}

//VALIDATES AN SUPPOSED EMAIL STRING
function validEmail(email){
	invalidChars = "/:,;";
	if (email == "") return false;
	for (i=0; i<invalidChars.length; i++){
		badChar = invalidChars.charAt(i);
		if (email.indexOf(badChar,0) > -1) return false;
	}
	atPos = email.indexOf("@",1);
	if (atPos == -1) return false;
	if (email.indexOf("@",atPos+1) > -1) return false;
	periodPos = email.indexOf(".",atPos);
	if (periodPos == -1) return false;
	if (periodPos+3 > email.length) return false;
     return true;
}

// VALIDATES THE FORMAT OF THE PHONE NUMBER	
function valid_phone(phone_number){
	if(isSpace(phone_number)) return false;
	for(var i=0;i<phone_number.length;i++){
		if(i!=3 && i!=7){
			if(isNaN(parseInt(phone_number.charAt(i)))) return false;
		}
		else if(phone_number.charAt(i)!="-") return false;
	}
	return true;
}

//-->