<!--
/* ***************************************************************
	MISC FUNCTIONS

	Copyright (c) 2002 - 2003 Nequalsone, LLC.  All rights reserved.

    Author: Hollie Buffington
    Version: $Id: global.js,v 2.2 2003/11/10 16:31:54 hollie Exp $
****************************************************************** */
	var IE6, IE5_6, IE5_5, IE5, N4, N5, NS6, NS6_1, MOZ, MAC_IE5;  //users current browser

//*****Browser Detection*****
	function browserDetect(){
	/*	var ua= navigator.userAgent;
		var OPERA= (ua.indexOf("Opera") > 0);
		var OMNI= (ua.indexOf("Omni") > 0);
		var MAC= (navigator.platform.indexOf("PPC") > 0);
		var WIN= (navigator.platform=="Win32");

		if(!OPERA && !OMNI){

		   IE6= (ua.indexOf("MSIE 6") > 0);

		   // IE 5.5 and IE 5.6 are similar. IE 5.6 is released on WindowsXP
		   IE5_6= (ua.indexOf("MSIE 5.6") > 0);
		   IE5_5= (ua.indexOf("MSIE 5.5") > 0 || IE5_6);

		   // IE5 is true for IE5.5, IE5.6, and IE6.
		   IE5= (ua.indexOf("MSIE 5") > 0  || IE6 || IE5_5);

		   N4= (document.layers);
		   NS6= N5= (ua.indexOf("Gecko") > 0);
		   NS6_1= (N5 && ua.indexOf("6.1") != -1);
		   MOZ= N5 && !(ua.indexOf("Netscape") > 0);
		   MAC_IE5= (MAC && IE5);
		}

		if(!IE6 && !IE5_5 && !IE5_6){
		   var yesDownload = confirm("This application is optimized for use with Internet Explorer 6.\nSome componets may not look or function in the desired manner with your current browser.\n Click OK to download Internet Explorer 6.")
		   if(yesDownload){
			location.href = 'http://www.microsoft.com/windows/ie/downloads/ie6/download.asp'
		   }else { location.href = 'http://www.nequalsone.com';}
		} */
	}
//browserDetect();
//*****Image Preloading
	function preloadImages(imgArr){
		//to use this function create an array containing the src string of all images you want preloaded.
		//Pass that array in to the function by adding the "onload='preloadImages(imgArray)'" to the body tag.
		var imgs = new Array()
		for(n=0; n<imgArr.length; n++){
		   	imgs[n] = new Image();
   			imgs[n].src = imgArr[n]
		}
	}
//*****Submit a form on enter - call onKeyPress event of form
      	function checkEnter(event,theForm, act){
//alert("theForm is " + theForm);
        	var code = 0;
          	if (document.layers) code = event.which;
          	else code = event.keyCode;
          	if (code==13){
          		if(act != "") document.theForm.action = act;
          		eval("document."+theForm+".submit()");
			
		}
      	}
//data input and search navigation functions

//******************************************************************************************
//*****Linking Functions*****************************************************************
//******************************************************************************************



//******************************************************************************************
//*****Validation Functions*****************************************************************
//******************************************************************************************

//*****Has a date passed -pass in a formatted string date
	function hasDatePassed(dte){
		var d, mo, yr;
		var objRegExp = /\d{1,2}(\/)\d{1,2}\1\d{4}$/

		if(objRegExp.test(dte)){
			var dteArr = dte.split('/');
			var dteNow = new Date();
			if(dteNow.getFullYear() > dteArr[2]) return true; //year has passed
			else if(dteNow.getFullYear() < dteArr[2]) return false; //year has not passed
			else{ //if year entered is this year
				if((dteNow.getMonth()+1) > dteArr[0]) return true; //month has passed
				else if((dteNow.getMonth()+1) < dteArr[0]) return false; //month has not passed
				else{ //if month entered is this month
					if(dteNow.getDate() > dteArr[1]) return true; //day has passed
					else if(dteNow.getDate() < dteArr[1]) return false; //day has not passed
					else return false; //day is today
				}
			}
		} else return false;
	}
//*****Is string a number
	function isNumber(str){
		var inputStr = str.toString()
		for(var i=0;i<inputStr.length; i++){
			var oneChar = inputStr.charAt(i);
			if(i==0 && oneChar == "-") continue;
			if(oneChar == ".") continue;
			if(oneChar < "0" || oneChar > "9") return false;
		}
		return true;
	}
//******************************************************************************************
//*****Formatting Functions*****************************************************************
//******************************************************************************************

//*****format oracle date and return date string to caller
	function formatDate(dte){
		//translates an oracle date to mm/dd/yyyy and returns the new date to the caller
	          if(dte != ""){
			var yr, mo, d
			yr = dte.substring(0, 4);
			mo = dte.substring(5, 7);
			d = dte.substring(8,10);
			return stripSpaces(mo + "/" + d + "/" + yr);
	          }
	}
//*****format java.util.date.toString() date and returns date (mm/dd/yyyy) string to caller
   function formatJavaDate(dte, fmt){
      if(dte != ""){
	 if(fmt == "") fmt = "/"

	 var hldDte = dte.toString();
	 if(dte.length < 10) return "";

         mos = new Array("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec")
         var yr, hmo, mo = "", d
         yr = dte.substring((dte.length-4), dte.length);
         hmo = dte.substring(4,7);
         d = dte.substring(8,10);
         for(i=0; i<mos.length; i++){
            if(hmo==mos[i]){
               mo = i+1;
            }
         }

         var hldMo = mo.toString();
	 if(hldMo.length == 1) mo = "0" + mo;

	 if(!isNumber(yr)) return "";
	 if(!isNumber(d)) return "";
	 if(!isNumber(mo)) return "";

         return stripSpaces(mo + fmt + d + fmt + yr);
      }else{ return "";}
   }
//*****format currency with dollar sign, decimal and commas and return to caller
	function formatCurrency(curr){
		if (!isNumber(curr)) return curr;

		if(curr.indexOf(".") > -1){
			var cents = curr.substring((curr.indexOf(".")+1), curr.length);
			var dlrs = curr.substring(0,curr.indexOf("."));
		}else{
			dlrs = curr
			cents = "00"
		};
		var rpl;
		for(n=dlrs.length; n>0; n=n-3){
			if(n==dlrs.length){ rpl = ".";}
			else {rpl = ",";}
			dlrs = dlrs.substring(0,n) + rpl + dlrs.substring(n, dlrs.length);
		}
		return '$'+dlrs+cents;
	}

//*****format a number with commas and return to caller
      	function rtnfmtNumber(srcNumber) {
      		var txtNumber = '' + srcNumber;
                	if (!isNaN(txtNumber) && txtNumber != "") {
                        	var rxSplit = new RegExp('([0-9])([0-9][0-9][0-9][,.])');
                            	var arrNumber = txtNumber.split('.');
                            	arrNumber[0] += '.';
                            	do { arrNumber[0] = arrNumber[0].replace(rxSplit, '$1,$2');}
                            	while (rxSplit.test(arrNumber[0]));
      					if (arrNumber.length > 1) return arrNumber.join('');
      				  	else return arrNumber[0].split('.')[0];
                    	}
      	}
//*****Strip spaces from a string
      	function stripSpaces(SA) {
		var Str = '';
		for(x=0; x<SA.length; x++) if(SA.charAt(x) != " ") Str += SA.charAt(x);
  		return Str;
	}
//******************************************************************************************
//*****AUTO Formatting Functions*****************************************************************
//******************************************************************************************
//These functions are attached to text inputs and format as the user types.
//To use add onKeyPress="return(functionName(this,event))" to the input tag

//*****Auto Format Currency field
	function autoFormatCurrency(fld, e) {
		var key = '';
		var len = len2 = 0;
		var aux = aux2 = '';
		var whichCode = (window.Event) ? e.which : e.keyCode;

		if (whichCode == 13) return false;  // Key pressed was Enter
		key = String.fromCharCode(whichCode);  // Get key value from key code
		if(isNaN(key)){fld.value = fld.value; return false;}; //key is not a number

		len = fld.value.length;
		aux = '';
		for(i=0; i < len; i++) if(!isNaN(fld.value.charAt(i)) && !(i==0 && fld.value.charAt(0)=="0")) aux += fld.value.charAt(i);

		aux += key;
		len = aux.length;
		if (len == 0) fld.value = '';
		if (len == 1) fld.value = '0'+ '.' + '0' + aux;
		if (len == 2) fld.value = '0'+ '.' + aux;
		if (len > 2) {
			aux2 = '';
			for (j = 0, i = len - 3; i >= 0; i--) {
				if (j == 3) { aux2 += ','; j = 0;}
				aux2 += aux.charAt(i);
				j++;
			}
			fld.value = '';
			len2 = aux2.length;
			for (i = len2 - 1; i >= 0; i--)	fld.value += aux2.charAt(i);
			fld.value += '.' + aux.substr(len - 2, len);
		}
		return false;
	}
//*****Auto Format Social Security field
      	function autoFormatSSN(fld, e){
		var key = '';
		var len = len2 = 0;
		var aux = aux2 = '';

		var whichCode = (window.Event) ? e.which : e.keyCode;
		if (whichCode == 13) return false;  // Key pressed was Enter
		key = String.fromCharCode(whichCode);  // Get key value from key code
			if(isNaN(key)){fld.value = fld.value; return false;}; //key is not a number

		len = fld.value.length;
		aux = '';
		for(i=0; i < len; i++) if(!isNaN(fld.value.charAt(i))) aux += fld.value.charAt(i);

		aux+=key;
		for(i=0; i<12; i++){
			if(len<i){fld.value = aux2;	return false;}
			aux2 += aux.charAt(i);
			if(i == 2 || i == 4) aux2 += '-'
		}
		return false;
      	}
//*****Auto Format Phone Number field
      	function autoFormatPhone(fld, e){
		var key = '';
		var len = len2 = 0;
		var aux = aux2 = '';

		var whichCode = (window.Event) ? e.which : e.keyCode;
		if (whichCode == 13) return false;  // Key pressed was Enter
		key = String.fromCharCode(whichCode);  // Get key value from key code
			if(isNaN(key)){fld.value = fld.value; return false;}; //key is not a number

		len = fld.value.length;
		aux = '';
		for(i=0; i < len; i++) if(!isNaN(fld.value.charAt(i))) aux += fld.value.charAt(i);

		aux+=key;
		for(i=0; i<14; i++){
			if(len<i){fld.value = aux2; return false;}
			if(i == 0) aux2 += '('
			aux2 += aux.charAt(i);
			if(i == 2) aux2 += ')'
			if(i == 5) aux2 += '-'
		}
		return false;
      	}

//validate date entry
	var dtCh= "/";
	var minYear=1900;
	var now = new Date;
	var maxYear=parseInt(now.getYear());

	function isInteger(s){
		var i;
    		for (i = 0; i < s.length; i++){   
        		// Check that current character is number.
        		var c = s.charAt(i);
        		if (((c < "0") || (c > "9"))) return false;
    		}
    		// All characters are numbers.
   		 return true;
	}



	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 stripCharsInBag(s, bag){
		var i;
    		var returnString = "";
    		// Search through string's characters one by one.
    		// If character is not in bag, append to returnString.
    		for (i = 0; i < s.length; i++){   
        		var c = s.charAt(i);
        		if (bag.indexOf(c) == -1) returnString += c;
    		}
    		return returnString;
	}

	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 isDate(dtStr){
		var daysInMonth = DaysArray(12);
		var pos1=dtStr.indexOf(dtCh);
		var pos2=dtStr.indexOf(dtCh,pos1+1);
		var strMonth=dtStr.substring(0,pos1);
		var strDay=dtStr.substring(pos1+1,pos2);
		var strYear=dtStr.substring(pos2+1);
		strYr=strYear;
		if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1);
		if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1);
		for (var i = 1; i <= 3; i++) {
			if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1);
		}
		month=parseInt(strMonth);
		day=parseInt(strDay);
		year=parseInt(strYr);
		if (pos1==-1 || pos2==-1){
			alert("The date format should be : mm/dd/yyyy");
			return false;
		}
		if (strMonth.length<1 || month<1 || month>12){
			alert("Please enter a valid month");
			return false;
		}
		if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
			alert("Please enter a valid day");
			return false;
		}
		if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
			alert("Please enter a valid 4 digit year between "+minYear+" and "+maxYear);
			return false;
		}
		if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
			alert("Please enter a valid date");
			return false;
		}
		return true;
	}

	function dateValidation(datevalue){
	
		if (!isDate(datevalue)){
			//dt.focus()
			return false;
		}
    	return true;
 	}
//-->