function setStatus(msg) {
		 status = msg
		 return true
} 

function upperThis(field) {
		 field.value = field.value.toUpperCase()
}

function phonemask(str,textbox,loc,delim,strcountry){
		 if (strcountry != "") {
		 	var strfield = eval(strcountry);
			var strcountry = strfield.options[strfield.selectedIndex].text;
			strcountry= strcountry.toUpperCase()
			if ((strcountry != "USA") && (strcountry != "-1") && (strcountry != "MEXICO") && (strcountry != "CANADA") && (strcountry != "UNITED STATES")){
			   return true;
			}
			
		 }
    	 var locs = loc.split(',');

		 for (var i = 0; i <= locs.length; i++){
		 	 for (var k = 0; k <= str.length; k++){
	 		 	 if (k == locs[i]){
	  			 	if (str.substring(k, k+1) != delim){
	    			   str = str.substring(0,k) + delim + str.substring(k,str.length)
	  				}
	 			  }
			}
 		 }
		 textbox.value = str
}

function isPhoneFormat(str) {
	while (str.indexOf("/") != -1)  {
		str = replaceString(str,"/","-")
	}		 
	if (str.length != 12) {
	   alert("Invalid Phone/Fax Number.")
	   return false
	}
	var areac = str.substring(0,3)
	var h1 = str.substring(3,4)
	var exc = str.substring(4,7)
	var h2 = str.substring(7,8)
	var nbr = str.substring(8,12)
	
	if (h1 != "-" || h2 != "-") {
	   alert("Invalid Phone/Fax Number Format.")
	   return false
	}
	for (var i = 0; i < areac.length; i++) {
		var theChar = areac.substring(i, i + 1)
		if (theChar < "0" || theChar > "9") {
	   	   alert("Phone/Fax Number Must be Numeric.")
	   	   return false		
		}
	}
	for (var i = 0; i < exc.length; i++) {
		var theChar = exc.substring(i, i + 1)
		if (theChar < "0" || theChar > "9") {
	   	   alert("Phone/Fax Number Must be Numeric.")
	   	   return false		
		}
	}
	for (var i = 0; i < nbr.length; i++) {
		var theChar = nbr.substring(i, i + 1)
		if (theChar < "0" || theChar > "9") {
	   	   alert("Phone/Fax Number Must be Numeric.")
	   	   return false		
		}
	}
	return true
}
function isEmail(str) {

	if (str.length < 5) {
	   alert("Invalid Email Address.")
	   return false
	}
	if (str.indexOf(" ") != -1) {
	   alert("Invalid Email Address.")
	   return false
	}
	if (str.indexOf("@") == -1) {
	   alert("Invalid Email Address.")
	   return false	   
	}
	if (str.indexOf(".") == -1) {
	   alert("Invalid Email Address.")
	   return false	   
	}	
	if (str.indexOf("@") == 0) {
	   alert("Invalid Email Address.")
	   return false	   
	}	
	if (str.indexOf("@") == (str.length-1)) {
	   alert("Invalid Email Address.")
	   return false	   
	}	
	if (str.lastIndexOf(".") < (str.indexOf("@")+2)) {
	   alert("Invalid Email Address.")
	   return false	
	}

 	return true	
}

function format_the_number(expr, decplaces) {
		 var str = "" + Math.round(eval(expr) * Math.pow(10,decplaces))
		 while (str.length <= decplaces) {
		 	   str = "0" + str
		 }
		 var decpoint = str.length - decplaces
		 return str.substring(0,decpoint) + "." + str.substring(decpoint,str.length);
}


// function to check Date Format etc.
function isDate(inputStr) {
		 var minYear = 1900
		 var maxYear = 2100
		 var minDays 
		 var maxDays
		 // convert hyphen delimiters to slashes
		 while (inputStr.indexOf("-") != -1) {
		 	   inputStr = replaceString(inputStr,"-","/")
		 }
		 
		 var delim1 = inputStr.indexOf("/")
		 var delim2 = inputStr.lastIndexOf("/")
		 if (delim1 != -1 && delim1 == delim2) {
		 	alert("The date is not in an acceptable format.\n\nPlease enter the date using as mm/dd/yyyy")
			return false
		 }
		 
		 if (delim1 != -1) {
		 	// there are delimiters; extract component values
			var mm = parseInt(inputStr.substring(0,delim1),10)
			var dd = parseInt(inputStr.substring(delim1 + 1,delim2),10)
			var yyyy = parseInt(inputStr.substring(delim2 + 1,inputStr.length),10)		
		 } else {
		   //there are no delmiters; extract component values
		   var mm = parseInt(inputStr.substring(0,2),10)
		   var dd = parseInt(inputStr.substring(2,4),10)
		   var yyyy = parseInt(inputStr.substring(4,inputStr.length),10)
		 }
		 
		 if (isNaN(mm) || isNaN(dd) || isNaN(yyyy)) {
		 	//there is a non-numeric character in one of the component values
			alert("The date entry is not an acceptable format.\n\nPlease enter the date using as mm/dd/yyyy")
			return false
		 }
		 
		 if (mm < 1 || mm > 12) {
		 	// month value is not 1 to 12
			alert("Month must be between 01 and 12.")
			return false
		 }
		 
		 if (dd < 1 || dd > 31) {
		 	// day value not between 1 and 31
			alert("Day must be between 01 and 31 (depending on month and year).")
			return false
		 }
		 
		 if (yyyy < 100) {
		 	// entered value is two digits; allow 2000 +
			yyyy += 2000
		 }
		 
		 var today = new Date()
		 
		 if (!minYear) {
		 	//function called with specific day range parameters
			var dateStr = new String(monthDateFormat(mm) + "/" + monthDayFormat(dd) + "/" + yyyy)
			var testDate = new Date(dateStr)
			if (testDate.getTime() < (today.getTime()  + (minDays * 24 * 60 * 60 * 1000))) {
			   alert("The most likely range for this entry begins " + minDays + " days from today.")
		
			   return false
			}
			if (testDate.getTime() > (today.getTime() + (maxDays * 24 * 60 * 60 *1000))) {
			   alert("The most likely range for this entry ends " + maxDays + " days from today.")
		   		
			   return false
			}
		 } else if (minYear && maxYear) {
		   //function called with specific year range parameters
		   if (yyyy < minYear || yyyy > maxYear) {
		   	  // entered year is outside of range
			  alert("The most likely range for this entry is between the years " + minYear + " and " + maxYear + ".")	 
		
			  return false
		   }
		 } else {
		   //default year range (now set to (this year - 5) and (this year + 25))
		   var thisYear = today.getYear()
		   if (thisYear < 100) {
		   	  thisYear += 2000
		   }
		   maxYear = parseInt(thisYear) + 25
		   minYear = parseInt(thisYear) - 5 
		   if (yyyy < minYear || yyyy > maxYear) {
		   	  alert("It is unusual for a date entry to be before " + minYear + " or after " + maxYear +". Please verfiy the date.")
			  			   return false 
		   }
		 }
		 
		 if (!checkMonthLength(mm,dd)) {
		 	return false
		 }
		 if (mm == 2) {
		 	if (!checkLeapMonth(mm,dd,yyyy)) {
			   return false
			}
		 }
		 
		 //put it all back together in mm/dd/yyyy fromat
//		 vField.value = monthDayFormat(mm) + "/" + monthDayFormat(dd) + "/" + yyyy
		 return true
}		 
function checkMonthLength(mm,dd) {
	var months = new Array("","January","February","March","April","May","June","July","August","September","October","November","December")
	if ((mm ==4 || mm == 6 || mm ==9 || mm == 11) && dd > 30) {
		alert(months[mm] + " has only 30 days.")
		return false
	} else if (dd > 31) {
		alert (months[mm] + " has only 31 days.")
		return false
	}
	return true
}
function checkLeapMonth(mm,dd,yyyy) {
	if (yyyy % 4 > 0 && dd > 28)  {
		alert("February of "+ yyyy + " has only 28 days.")
		return false
	} else if (dd > 29) {
		alert("February of " +yyyy+ " has only 29 days.")
		return false
	}
	return true
}
function monthDayFormat(ss) {
	if (parseInt(ss) < 10) {	 	 
		ss = "0"+ss
	}
	return ss
}