/* Basic Functions */
function emptyField(textObj)  /* Check to see if field is empty... */
{
   if (textObj.value.length == 0) return true;
   for (var i=0; i<textObj.value.length; ++i)
	{
		var ch = textObj.value.charAt(i);
		if (ch !=' ' && ch !='\t') return false;
	}
   return true;
}
function dateDiff(input_date, clock_date) {
   //==================================================================
   //MSG #1 - Parameter1 must be in this date format --> "mm/dd/yyyy"
   //==================================================================
   //Debug sample date that will produce float value for Days...
   //
   //Sample #1 ------------------------------------- (Postive #)
   //clockDate = new Date(2005, 03, 01, 00, 00, 00);
   //inputDate = new Date(2004, 07, 08, 00, 00, 00);
   //
   //Sample #2 ------------------------------------- (Negative #)
   //clockDate = new Date(2004, 01, 08, 00, 00, 00);
   //inputDate = new Date(2004, 07, 08, 00, 00, 00);
   //==================================================================
   if (clock_date.length == 0) {
      alert("Missing Clock Date!");
   }

   var UserInput,UserInputMonth,UserInputDay,UserInputYear;
   var UserClock,UserClockMonth,UserClockDay,UserClockYear;
   var Days;

   input_date = String(input_date);
   clock_date = String(clock_date);

   UserInput = input_date.split(/\/|-/);
   UserClock = clock_date.split(/\/|-/);
   
   UserInputMonth = String(UserInput[0]);
   UserInputDay = String(UserInput[1]);
   UserInputYear = String(UserInput[2]);
   UserClockMonth = String(UserClock[0]);
   UserClockDay = String(UserClock[1]);
   UserClockYear = String(UserClock[2]);
   
   clockDate = new Date(UserClockYear, UserClockMonth, UserClockDay, 00, 00, 00);
   inputDate = new Date(UserInputYear, UserInputMonth, UserInputDay, 00, 00, 00);

   input_date = String(input_date);
   clock_date = String(clock_date);

   Days = ((clockDate-inputDate) / (24 * 60 * 60 * 1000));

   if (Days >= 0) {
      if (Days > parseInt(Days,10)) {
         Days = (parseInt(Days,10)+1);
      } else {
         Days = parseInt(Days,10);
      }
   } else {
      //This script is used to avoid a value of 0...
      Days = (Days * -1);
   
      if (Days > parseInt(Days,10)) {
         Days = (parseInt(Days,10)-1);
      } else {
         Days = parseInt(Days,10);
      }
   
      Days = (Days * -1);
   }
   
   return Days;
}
function getRadioValue(radioObj)  /* Get radio object value... */
{
   var val = null;
   for (var i=0; i < radioObj.length; i++)
   {
      if (radioObj[i].checked)
      {
         val = radioObj[i].value;
         break;
      }
   }
   return val;
}
function isAlpha1(textObj)  /* Check to see if field is almost alpha ONLY!!! */
{
   var newValue = textObj.value;
   var newLength = newValue.length;
   var extraChars = " - ";       
   var search;

   for(var i=0; i != newLength; i++)
   {
      aChar = newValue.substring(i,i+1);
      aChar = aChar.toUpperCase();
      search = extraChars.indexOf(aChar);
      if (search == -1 && (aChar < "A" || aChar > "Z") ) return false;
   }
   return true;
}
function isAlpha2(textObj)   /* Check to see if field is somewhat alpha ONLY!!! */
{
   var newValue = textObj.value;
   var newLength = newValue.length;
   var extraChars = ". - ";
   var search;

   for(var i=0; i != newLength; i++)
   {
      aChar = newValue.substring(i,i+1);
      aChar = aChar.toUpperCase();
      search = extraChars.indexOf(aChar);
      if (search == -1 && (aChar < "A" || aChar > "Z") ) return false;
   }
   return true;
}
function isAlphaNumOnly1(textObj)  /* Check to see if field is alphanumeric ONLY!!! */
{
   var newValue = textObj.value;
   var newLength = newValue.length;
      
   for(var i=0; i != newLength; i++)
   {
      aChar = newValue.substring(i,i+1);
      aChar = aChar.toUpperCase();
      if (   (aChar < "A" || aChar > "Z") && !( (aChar >= '0') && (aChar <= '9') )      ) return false;
   }
   return true;
}
function isAlphaNumOnly2(textObj)  /* Check to see if field is almost alphanumeric ONLY!!! */
{
   var newValue = textObj.value;
   var newLength = newValue.length;
   var extraChars = " - ";

   for(var i=0; i != newLength; i++)
   {
      aChar = newValue.substring(i,i+1);
      aChar = aChar.toUpperCase();
      search = extraChars.indexOf(aChar);

      if ((search == -1) && (aChar < "A" || aChar > "Z") && !( (aChar >= '0') && (aChar <= '9') )      ) return false;
   }
   return true;
}
function isMoney(textObj)  /* Check to see if field is dollars and cents in xx.xx format... */
{
   money = textObj.value.split(".");

   if (
       (isNaN(money[0]))                                       ||     // dollars must be numeric
       (textObj.value.charAt(textObj.value.length - 3) != ".") ||     // 3'rd char from back has to be decimal period
       (isNaN(money[1]))                                       ||     // cents must be numeric
       (textObj.value.length < 4)                                     // must be more than 4 characters long (i.e 1.23)
      )  
       {
          return false;
       }

   return true;
}
function isNumeric(textObj)  /* Check to see if field is numeric */
{
   if(textObj.value.length == 0) return true;
   for(var i = 0; i < textObj.value.length; i++)
   {
      var ch = textObj.value.charAt(i);
      if (!((ch >= '0') && (ch <= '9'))) return false;         
   }
   return true;
}
function isZipCode(textObj)  /* Check to see if field is numeric for Zip-Code */
{
   var extraChars = "-";
   var search;

   if(textObj.value.length == 0) return true;
   for(var i = 0; i < textObj.value.length; i++)
   {
      var ch = textObj.value.charAt(i);
      search = extraChars.indexOf(ch);
      if (search == -1 && ( !((ch >= '0') && (ch <= '9')))) return false;         
   }
   return true;
}
function TrimF(jsStrVar)
{
   while(jsStrVar != jsStrVar.replace(" ",""))jsStrVar = jsStrVar.replace(" ","");
   return jsStrVar;
}
function ValidateWebSite(URL)
{
   if (
       //(URL.value.indexOf("http://www.") == -1) ||             // must have standard format
       (URL.value.charAt(URL.value.length - 4) != ".") ||      // 4'rd char from back has to be period .com .org etc,etc
       (URL.value.indexOf(" ") != -1) ||                       // must not have empty spaces
       (URL.value.length < 16)                                 // must be more than 16 characters long
      )  
       {
          alert("Sorry, Company's Web URL is NOT in 'http://host.domain.com' format.");
          URL.focus();
          URL.select();
          return false;
       }
   return true;   
}
function ValidateEmail(MAIL)
{
   if (
       (MAIL.value.indexOf("@") == -1) ||                        // must have @ simbol
       (MAIL.value.charAt(MAIL.value.length - 4) != ".")  ||     // 3'rd char from back has to be period .com .org etc,etc
       (MAIL.value.indexOf(" ") != -1) ||                        // must not have empty spaces
       (MAIL.value.length < 7)                                   // must be at least 7 characters long
      )                                                     
       {
          alert("Sorry, Company's Email Address is NOT in 'user@domain.com' format.");
          MAIL.focus();
          MAIL.select();
          return false;
       }
   return true;   
}
function ValidateEmail2(MAIL)
{
   if (
       (MAIL.value.indexOf("@") == -1) ||                        // must have @ simbol
       (MAIL.value.charAt(MAIL.value.length - 4) != ".")  ||     // 3'rd char from back has to be period .com .org etc,etc
       (MAIL.value.indexOf(" ") != -1) ||                        // must not have empty spaces
       (MAIL.value.length < 7)                                   // must be at least 7 characters long
      )                                                     
       {
          return false;
       }
   return true;   
}

/* AJAX Functions */
function createRequestObject() {
   //The PHP's no-cache header must be present to avoid the caching-related errors...
   var obj;

   if(window.XMLHttpRequest){ 
      // Firefox, Safari, Opera...
      obj = new XMLHttpRequest();
   } else if(window.ActiveXObject) {
      // Internet Explorer 5+...
      obj = new ActiveXObject("Microsoft.XMLHTTP");
   } else {
      // There is an error creating the object, just as an old browser is being used...
      //alert('Problem creating the XMLHttpRequest object');
   }
   return obj;
}
function errorNotifyByEmail(msg, url, linenumber) {
	// Block sending of any further emails if javascript errors is in infinite loop while web events or browser is running...
	if (maxJsErrorEmailCount < 10) {
		var http = createRequestObject();  //Make the XMLHttpRequest object...

		/* 06/12/2006 - Discontinued and is replaced below... */
		/*
       var httpStr = url.substring(0,7);
		 if (httpStr == "http://") { httpStr = "http"; } 
       else if (httpStr == "https:/") { httpStr = "https"; } 
       else { httpStr = "http"; }
		*/ 

		/* httpPort variable exist from the parent's web page... */
		if (httpPort == "80") {
			httpPort = "http";
		} else if (httpPort == "443") {
			httpPort = "https";
		} else {
			httpPort = "http";
		}

      /* alert(window.location.protocol);  //Another option to use ports... */

		/* Do the conversion to a code-name and convert it back in php via javascript_error.php... */
		httpQueryStr = httpQueryStr.replace(/&/g,"**ampersand**");
		httpQueryStr = httpQueryStr.replace(/=/g,"**equal**");

		/* httpHost & httpUrlFile variable exist from the parent's web page... */
		// Open PHP script for requests...
		http.open("get", httpPort+"://"+httpHost+"/javascript_error.php?httpWebFile="+httpWebFile+"&httpQueryStr="+httpQueryStr+"&Url="+url+"&Line="+linenumber+"&Msg="+msg);
		http.send(null);
		maxJsErrorEmailCount++;
		http = null;
	}

	return true;
}

/* General Functions */
function noUglySelection_link(x) {
   x.blur();
}

