  
function isDate(adate) {
	if (adate != null && adate != "") {
		var thedate = adate;
		
		//Find the position of each / and check to see if there are
		//more than 2 /'s.
		var slash1 = thedate.indexOf("/");
		var slash2 = thedate.indexOf("/", (slash1+1));
		var slash3 = thedate.indexOf("/", (slash2+1));
		var datelength = thedate.length;
		//Test for the following criteria:
		// 1.  There are 2 slahses
		// 2.  There are not 3 slashes
		// 3.  The middle number (the day) has at least one number
		// 4.  The year is 4 digits long
		// 5.  The date parses correctly
		if (slash1 == -1 || slash2 == -1 || slash3 != -1 ||
			slash1 > 2 || slash2 > 5 || slash1 == 0 ||
			(slash2 - slash1 < 2) || (slash2 - slash1 > 3) ||
			(datelength - slash2 != 5) || isNaN(Date.parse(thedate))) {
			return false;
		}
		else {
			//Split the Date to ensure the values are numbers
			var DateParts = thedate.split('/');
			var mm = isNaN(DateParts[0]);
			var dd = isNaN(DateParts[1]);
			var yyyy = isNaN(DateParts[2]);
			if (mm || dd || yyyy) {
				return false;
			}
			//if ((mm > 12 )||(dd > 31)){
			//	return false;
			//}
		}
	}
	else {
		return false;
	}
	// would only get to this point if everything passed.
	return true;
}

//Function to use jquery ajax retrieval
//Provide the url to request and where to stuff the returned HTML
//Any form tags have their data sent automatically. 
function retrieveAjax(url, htmlRecv)
{
	
	$.post(url,$('form').serialize(),function(data){ async:false, 
		document.getElementById(htmlRecv).innerHTML=data;
	}); 
}
function retrieveAjaxForm(url, htmlRecv, form)
{
	//alert($(form).serialize());
	 

	$.ajax({
		  type: 'POST',
		  url: url,
		  data: $(form).serialize(),
		  success: function(data){document.getElementById(htmlRecv).innerHTML=data;},
		  async:false,
		  error: function(XMLHttpRequest, textStatus, errorThrown) { 
			    if (XMLHttpRequest.status == 0) {
			      alert(' Check Your Network.');
			    } else if (XMLHttpRequest.status == 404) {
			      alert('Requested URL not found.');
			    } else if (XMLHttpRequest.status == 500) {
			      alert('Internel Server Error.');
			    }  else {
			       alert('Unknow Error.\n' + XMLHttpRequest.responseText);
			    }     
			  }
		});
}


function retrieveAjaxSync(url, htmlRecv)
{
	$.ajax({
		  type: 'POST',
		  url: url,
		  data: $('form').serialize(),
		  success: function(data){document.getElementById(htmlRecv).innerHTML=data;},
		  async:false,
		  error: function(XmlHttpRequest, textStatus, errorThrown) { 
			    if (XMLHttpRequest.status == 0) {
			      alert(' Check Your Network.');
			    } else if (XMLHttpRequest.status == 404) {
			      alert('Requested URL not found.');
			    } else if (XMLHttpRequest.status == 500) {
			      alert('Internel Server Error.');
			    }  else {
			       alert('Unknow Error.\n' + XMLHttpRequest.responseText);
			    }     
			  }
		});
}

function countLength(updateField, lengthField, maxLength)
	{
		document.getElementById(updateField).innerHTML = maxLength - trim11(document.getElementById(lengthField).value).length;
	}

function trim11 (str) {
	str = str.replace(/^\s+/, '');
	for (var i = str.length - 1; i >= 0; i--) {
		if (/\S/.test(str.charAt(i))) {
			str = str.substring(0, i + 1);
			break;
		}
	}
	return str;
}


// Removes leading and trailing spaces from the passed string. Also removes
// consecutive spaces and replaces it with one space. If something besides
// a string is passed in (null, custom object, etc.) then return the input.
function trim(inputString) {
   if (typeof inputString != "string") { return inputString; }
   var retValue = inputString;
   var ch = retValue.substring(0, 1);
   while (ch == " ") { // Check for spaces at the beginning of the string
      retValue = retValue.substring(1, retValue.length);
      ch = retValue.substring(0, 1);
   }
   ch = retValue.substring(retValue.length-1, retValue.length);
   while (ch == " ") { // Check for spaces at the end of the string
      retValue = retValue.substring(0, retValue.length-1);
      ch = retValue.substring(retValue.length-1, retValue.length);
   }
   while (retValue.indexOf("  ") != -1) { // Note that there are two spaces in the string - look for multiple spaces within the string
      retValue = retValue.substring(0, retValue.indexOf("  ")) + retValue.substring(retValue.indexOf("  ")+1, retValue.length); // Again, there are two spaces in each of the strings
   }
   return retValue; // Return the trimmed string back to the user
} // Ends the "trim" function


var CurrentTangItemNum = 1;

function toggleBoxes(box)
{
	tbl = document.frmMain.tItems;
	rows = tbl.rows;

	for(i = 0; i < rows.length; i++)
	{			
		//alert('Row ' + i + ': ' + rows[i].all.chkDel.checked);
		rows[i].all.chkDel.checked = box.checked;
	}	
}

function toggleBoxes2(box)
{
	tbl = document.frmMain.tItems;
	rows = tbl.rows;

	for(i = 0; i < rows.length; i = i+2)
	{			
		//alert('Row ' + i + ': ' + rows[i].all.chkDel.checked);
		rows[i].all.chkDel.checked = box.checked;
	}	
}

function removeSelOwner() {
	var ids = '';
	var y = false;
	var chkArray = document.frmMain.chkDel;
	var i, length;
	
	length = chkArray.length;
	if (length == null) {
		length = 1;
		ids = chkArray.value;
		y = true;
	}
	else {
		for(i = 0; i < length; i++) {
			if(chkArray[i].checked) {
				ids += chkArray[i].value + ",";
				y = true;
			}
		}
	}
		
	if(!y) return false;
	 	
	if (length > 1) {
		ids = ids.substring(0, ids.length - 1);
	}
		
	document.frmMain.OwnerID.value = ids;
	document.frmMain.Action.value = 'DeleteOwner';
	document.frmMain.ActionForm.value = 'HolderReportItemDetail';
	document.frmMain.submit();
}

function removeSelItem() {
	var ids = '';
	var y = false;
	var chkArray = document.frmMain.chkDel;
	var i, length;
	
	length = chkArray.length;
	if (length == null) {
		length = 1;
		ids = chkArray.value;
		y = true;
	}
	else {
		for(i = 0; i < length; i++) {
			if(chkArray[i].checked) {
				ids += chkArray[i].value + ",";
				y = true;
			}
		}
	}

	
	if(!y) return false;
	 	
	if (length > 1) {
		ids = ids.substring(0, ids.length - 1);
	}
	
	document.frmMain.ItemDetailID.value = ids;
	document.frmMain.Action.value = 'DeleteItem';
	document.frmMain.ActionForm.value = 'HolderReportDetail';
	document.frmMain.submit();
}

function removeSelReport() {
	var ids = '';
	var y = false;
	var chkArray = document.frmMain.chkDel;
	var i, length;

	length = chkArray.length;
	if (length == null) {
		length = 1;
		ids = chkArray.value;
		y = true;
	}
	else {
		for(i = 0; i < length; i++) {
			if(chkArray[i].checked) {
				ids += chkArray[i].value + ",";
				y = true;
			}
		}
	}
	
	if(!y) return false;
	 	
	if (length > 1) {
		ids = ids.substring(0, ids.length - 1);
	}
	
	document.frmMain.ItemDetailID.value = ids;
	document.frmMain.Action.value = 'DeleteItem';
	document.frmMain.ActionForm.value = 'HolderMain';
	document.frmMain.submit();
}

function addTang(id)
{
	var sel = eval("document.frmMain.TCode" + id);
	//alert(sel[sel.selectedIndex].value);
	
	if(!checkTangItemValid())
	{
		alert('Please select a valid Tangible Type');
		return false;
	}
	
	document.frmMain.TangCode.value = sel[sel.selectedIndex].value;	
	document.frmMain.TangCount.value = row.all.TCountNew.value;	
	document.frmMain.TangDesc.value = row.all.TDescNew.value;	
	document.frmMain.TangComment.value = row.all.TCommentNew.innerText;	
			
	if(document.frmMain.TangCode.value == 'None')
	{
		alert('Please select a Catagory Type');
		return false;
	}
	
	if(document.frmMain.TangCount.value == '')
	{
		alert('Please enter a Count');
		return false;
	}
		
	document.frmMain.TangTaxID.value = row.tid;
	document.frmMain.TangTaxEXT.value = row.text;
	document.frmMain.TangTaxType.value = row.ttype;
	document.frmMain.TangReportSeqNum.value = row.rseq;
	document.frmMain.TangReportYear.value = row.ryear;	
	
	document.frmMain.TangItemSeqNum.value = row.iseq;
	document.frmMain.TangID.value = row.tangid;
			
	document.frmMain.Action.value = 'AddTangItem';
	document.frmMain.ActionForm.value = "HolderReportItemDetail";
	document.frmMain.submit();
}

function checkTangItemValid()
{
	t = document.frmMain.TangType;
	var itemValue = t[t.selectedIndex].value;

	if(itemValue == 'None') return false;

	return true;
}

function removeTang(id)
{
	var tbl = document.frmMain.tList;
	var row = tbl.rows[parseInt(id) + 1];
	var sel = row.all("TCode" + id);
	document.frmMain.TangID.value = row.tangid;
	
		
	document.frmMain.Action.value = 'DeleteTangItem';
	document.frmMain.ActionForm.value = "HolderReportItemDetail";
	document.frmMain.frmItemDetail.submit();	
}
function isValidIncDate(dateStr) {
	// Checks for the following valid date formats:
	// MM/DD/YY   MM/DD/YYYY   MM-DD-YY   MM-DD-YYYY
	// Also separates date into month, day, and year variables
	
	//var datePat = /^(\d{1,2})(\/|-)(\d{1,2})\2(\d{2}|\d{4})$/;
	
	// To require a 4 digit year entry, use this line instead:
	var datePat = /^(\d{1,2})(\/|-)(\d{1,2})\2(\d{4})$/;
	var fieldName = "";
	var errmsg = "";
	if(isValidIncDate.arguments.length == 2)  fieldName = isValidIncDate.arguments[1]; //.toUpperCase();
	var matchArray = dateStr.match(datePat); // is the format ok?
	if (matchArray == null) {
		errmsg = fieldName + " Date is not in a valid date format. The valid date format is MM/DD/YYYY.\n";
		return errmsg;
	}
	month = matchArray[1]; // parse date into variables
	day = matchArray[3];
	year = matchArray[4];
	if (month < 1 || month > 12) { // check month range
		errmsg = "Invalid " + fieldName + " Date : month must be between 1 and 12.\n";
		return errmsg;
	}
	if (day < 1 || day > 31) {
		errmsg = "Invalid " + fieldName + " Date : day must be between 1 and 31.\n";
		return errmsg;
	}
	if ((month==4 || month==6 || month==9 || month==11) && day==31) {
		errmsg = "Invalid " + fieldName + " Date : month " + month + " doesn't have 31 days!\n";
		return errmsg;
	}
	if(year.length == 4 && year < "1800"){
		errmsg = "Invalid " + fieldName + " Date : year has to be greater than 1800\n";
        return errmsg;  
	}
	if (month == 2) { // check for february 29th
		var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
	if (day>29 || (day==29 && !isleap)) {
		errmsg = "Invalid " + fieldName + " Date : February " + year + " does not have " + day + " days!\n";
		return errmsg;
	   }
	}
	return errmsg;  // date is valid

}


function isValidDate(dateStr) {

	// Checks for the following valid date formats:
	// MM/DD/YY   MM/DD/YYYY   MM-DD-YY   MM-DD-YYYY
	// Also separates date into month, day, and year variables
	
	//var datePat = /^(\d{1,2})(\/|-)(\d{1,2})\2(\d{2}|\d{4})$/;
	
	// To require a 4 digit year entry, use this line instead:
	var datePat = /^(\d{1,2})(\/|-)(\d{1,2})\2(\d{4})$/;
	var fieldName = "";
	var errmsg = "";
	if(isValidDate.arguments.length == 2)  fieldName = isValidDate.arguments[1]; //.toUpperCase();
	var matchArray = dateStr.match(datePat); // is the format ok?
	if (matchArray == null) {
		errmsg = fieldName + " Date is not in a valid date format. The valid date format is MM/DD/YYYY.\n";
		return errmsg;
	}
	month = matchArray[1]; // parse date into variables
	day = matchArray[3];
	year = matchArray[4];
	if (month < 1 || month > 12) { // check month range
		errmsg = "Invalid " + fieldName + " Date : month must be between 1 and 12.\n";
		return errmsg;
	}
	if (day < 1 || day > 31) {
		errmsg = "Invalid " + fieldName + " Date : day must be between 1 and 31.\n";
		return errmsg;
	}
	if ((month==4 || month==6 || month==9 || month==11) && day==31) {
		errmsg = "Invalid " + fieldName + " Date : month " + month + " doesn't have 31 days!\n";
		return errmsg;
	}
	if(year.length == 4 && year < "1900"){
		errmsg = "Invalid " + fieldName + " Date : year has to be greater than 1900\n";
        return errmsg;  
	}
	if (month == 2) { // check for february 29th
		var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
	if (day>29 || (day==29 && !isleap)) {
		errmsg = "Invalid " + fieldName + " Date : February " + year + " does not have " + day + " days!\n";
		return errmsg;
	   }
	}
	return errmsg;  // date is valid
}

// no MM-DD-YY
function isValidDate1(dateStr,fieldName) {

	// Checks for the following valid date formats:
	// MM/DD/YY   MM/DD/YYYY      MM-DD-YYYY
	// Also separates date into month, day, and year variables
	
	//var datePat = /^(\d{1,2})(\/|)(\d{1,2})\2(\d{2}|\d{4})$/;
	
	// To require a 4 digit year entry, use this line instead:
	var datePat = /^(\d{1,2})(\/|)(\d{1,2})\2(\d{4})$/;
	
	var errmsg = "";
	if(isValidDate1.arguments.length == 2)  fieldName = isValidDate1.arguments[1]; //.toUpperCase();
	var matchArray = dateStr.match(datePat); // is the format ok?
	if (matchArray == null) {
		errmsg = fieldName + " is not in a valid date format.\n The valid date format must be MM/DD/YYYY.\n";
		return errmsg;
	}
	month = matchArray[1]; // parse date into variables
	day = matchArray[3];
	year = matchArray[4];
	if (month < 1 || month > 12) { // check month range
		errmsg = "Invalid " + fieldName + ", month must be between 1 and 12.\n";
		return errmsg;
	}
	if (day < 1 || day > 31) {
		errmsg = "Invalid " + fieldName + ", day must be between 1 and 31.\n";
		return errmsg;
	}
	if ((month==4 || month==6 || month==9 || month==11) && day==31) {
		errmsg = "Invalid " + fieldName + ", month " + month + " doesn't have 31 days!\n";
		return errmsg;
	}
	if(year.length == 4 && year < "1900"){
		errmsg = "Invalid " + fieldName + ", year has to be greater than 1900\n";
        return errmsg;  
	}
	if (month == 2) { // check for february 29th
		var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
	if (day>29 || (day==29 && !isleap)) {
		errmsg = "Invalid " + fieldName + ", February " + year + " does not have " + day + " days!\n";
		return errmsg;
	   }
	}
	return errmsg;  // date is valid
}


function isValidDateYYYYMMDD(dateStr) {

	// Checks for the following valid date formats:
	// MM/DD/YY   MM/DD/YYYY   MM-DD-YY   MM-DD-YYYY
	// Also separates date into month, day, and year variables
	
	//var datePat = /^(\d{1,2})(\/|-)(\d{1,2})\2(\d{2}|\d{4})$/;
	
	// To require a 4 digit year entry, use this line instead:
	var datePat = /^(\d{1,4})(\/|-)(\d{1,2})\2(\d{1,2})$/;
	var fieldName = "";
	var errmsg = "";
	if(isValidDateYYYYMMDD.arguments.length == 2)  fieldName = isValidDateYYYYMMDD.arguments[1].toUpperCase();
	var matchArray = dateStr.match(datePat); // is the format ok?
	if (matchArray == null) {
		errmsg = fieldName + " Date is not in a valid date format. The valid date format is YYYY-MM-DD." ;
		return errmsg;
	}
	year = matchArray[1]; // parse date into variables
	month = matchArray[3];
	day = matchArray[4];
	if (month < 1 || month > 12) { // check month range
		errmsg = "Invalid " + fieldName + " Date : Month must be between 1 and 12." ;
		return errmsg;
	}
	if (day < 1 || day > 31) {
		errmsg = "Invalid " + fieldName + " Date : Day must be between 1 and 31.";
		return errmsg;
	}
	if ((month==4 || month==6 || month==9 || month==11) && day==31) {
		errmsg = "Invalid " + fieldName + " Date : Month "+month+" Doesn't have 31 Days!"
		return errmsg;
	}
	if(year.length == 4 && year < "1900"){
		errmsg = "Invalid " + fieldName + " Date : Year has to be greater than 1900.";
	        return errmsg ;  
	}
	if (month == 2) { // check for february 29th
		var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
	if (day>29 || (day==29 && !isleap)) {
		errmsg = "Invalid " + fieldName + " Date : February " + year + " Doesn't have " + day + " Days!";
		return errmsg;
	   }
	}
	return errmsg;  // date is valid
}



function isBlank(inputString) {
    var len = inputString.length ;
    if (len == 0)
        return true;
        
    var idx = 0;
    while(idx < len)
    {
        if (inputString.charAt(idx) != ' ')
             return false;
        idx++;
    }
    return true;     
}      
function getCurrentDate(){
	cdate = new Date();
	yyyy = cdate.getYear();
	mm = cdate.getMonth() + 1;
	dd = cdate.getDate();
	return cdate = new Date(mm + "/" + dd + "/" + yyyy);
}

function isDateGreaterYYYYMMDD(argDate1, argDate2){

	var datePat = /^(\d{1,4})(\/|-)(\d{1,2})\2(\d{1,2})$/;
	var matchArray = argDate1.match(datePat);
	
	year1 = matchArray[1]; // parse date into variables
	month1 = matchArray[3];
	day1 = matchArray[4];
	var date1 = month1 + "/" + day1 + "/" + year1;
	
	matchArray = argDate2.match(datePat);

	year2 = matchArray[1]; // parse date into variables
	month2 = matchArray[3];
	day2 = matchArray[4];
	
	var date2 = month2 + "/" + day2 + "/" + year2;
	
	var date1 = new Date(date1);
	var date2 = new Date(date2);
	if(date1 > date2){
	   return true;
	}
	return false;

}

function isDateGreaterYYYYMMDDThanCurrentDate(argDate1){

	var datePat = /^(\d{1,4})(\/|-)(\d{1,2})\2(\d{1,2})$/;
	var matchArray = argDate1.match(datePat);
	
	year1 = matchArray[1]; // parse date into variables
	month1 = matchArray[3]; 
	day1 = matchArray[4];
//	var date1 = month1 + "/" + day1 + "/" + year1;
	var date1 = year1+ "/"+ month1 + "/" + day1;
	
	var date1 = new Date(date1);
	if(date1 < getCurrentDate()){
	   return false;
	}else{
		return true;
	}
}

function isDateGreater(argDate1, argDate2){

	var date1 = new Date(argDate1);
	var date2 = new Date(argDate2);
	if(date2 < date1){
	   return false;
	}
	return true;

}


function isDateLesserOrEqual(argDate1, argDate2){

	var date1 = new Date(argDate1);
	var date2 = new Date(argDate2);
	var msg = "";
	if(date2 >= date1){
	   return true;
	}
	return false;

}

function isDateGreaterOrEqual(argDate1, argDate2){

	var date1 = new Date(argDate1);
	var date2 = new Date(argDate2);
	if(date2 < date1){
	   return true;
	}
	return false;
}

function getYearFromDate(argDate) {
	
		var datePat = /^(\d{1,2})(\/|-)(\d{1,2})\2(\d{4})$/;
		var matchArray = argDate.match(datePat); // is the format ok?
		
		return matchArray[4];
}

function isFutureDate(dateStr) {
	var now = new Date();
	return isDateLesserOrEqual(now.toString(), dateStr);
}

function isValidYear(fieldValue, fieldLabel) {


	var errmsg = "";
	var num=0;
	var now = new Date();
    if (!isNum(fieldValue)) {
		errmsg = "Invalid " + fieldLabel + ". Year has to be numeric.\n" ;	          
		return errmsg;
    } 
	else{
	   	  
		if(fieldValue.length != 4){
	    	errmsg = "Invalid " + fieldLabel + ". Year has to be four digits.\n" ;
		    return errmsg;	
	    }		
	    num = parseInt(fieldValue);
	    if (num < 1900) {
	        errmsg = "Invalid " + fieldLabel + ". Year has to be greater than 1900.\n" ;
	   		return errmsg;	
        }
		var tYear = now.getYear()+1900;	
		//alert("Current Year"+tYear);
		if (num > (now.getYear()+1900)) {
	        errmsg = "Invalid " + fieldLabel + ". Year can not be greater than current year.\n" ;
	   	   	return errmsg;	
        }
	}
    return errmsg;
}

function checkNumericField(canBeBlank, fieldValue, checkForLength, fieldLabel) {

	var errmsg = "";
	if (isBlank(fieldValue)) {
	
		if (!canBeBlank) {
			errmsg = fieldLabel + " cannot be Blank. Enter a valid numeric value of length " + checkForLength + " characters for " + fieldLabel + "\n";
		}
		return errmsg; 
	}
	if (!isNum(fieldValue)) {
	
		errmsg = "Invalid " + fieldLabel + ". " + fieldLabel + " can contain only Numbers.\n";
		return errmsg;
	}
	if (fieldValue.length < checkForLength) {
	
		errmsg = "Invalid " + fieldLabel + ". " + fieldLabel + " should be a numeric value of " + checkForLength + " characters in length.\n";
		return errmsg;
	}
	return errmsg;
} 

function checkNonNumericField(canBeBlank, fieldValue, checkForLength, fieldLabel) {

	var errmsg = "";
	if (isBlank(fieldValue)) {
	
		if (!canBeBlank) {
			errmsg = fieldLabel + " cannot be Blank. Enter a valid value of length " + checkForLength + " characters for " + fieldLabel;
		}
		return errmsg; 
	}
	if (fieldValue.length < checkForLength) {
	
		errmsg = "Invalid " + fieldLabel + ". " + fieldLabel + " should be " + checkForLength + " characters in length";
		return errmsg;
	}
	return errmsg;
} 

function checkAlphaField(fieldValue, fieldLabel, canBeBlank, hasMinLength, minLength) {

	var errmsg = "";
	if (isBlank(trim(fieldValue))) {
	
		if (!canBeBlank) {
			errmsg = fieldLabel + " cannot be Blank. Enter a valid " + fieldLabel + ".";
		}
		return errmsg; 
	}
	if (hasMinLength) {
		if (fieldValue.length < minLength) {
	
			errmsg = "Invalid " + fieldLabel + ". " + fieldLabel + " should be " + minLength + " characters in length";
			return errmsg;
		}
	}
	return errmsg;
}

function isNum(argStr) {

 	for (var i = 0, n = argStr.length; i < n; i++) {
  		
  		var ch = argStr.charAt(i);
  		if (!isDigit(ch))
		 	return false;	
 	}
 	return true;
}

function isNonNegNum(argStr){
	return inValidCharSet(argStr,"0123456789");
}

function isNonNegDecimalNum(argStr){
	return inValidCharSet(argStr,"0123456789.");
}

function inValidCharSet(str,charset)
{
	var result = false;
	
	for (var i=0;i<str.length;i++)
		if (charset.indexOf(str.substr(i,1))<0)
		{
			result = true;
			break;
		}
	
	return result;
}

function isDecimalNumber(argStr) {

	for (var i = 0, n = argStr.length; i < n; i++) {
  		
  		var ch = argStr.charAt(i);
  		if (!isDigit(ch) && ch != ".")
		 	return false;	
 	}
 	return true;
}

function containsZerosOnly(argStr){

	for (var i = 0, n = argStr.length; i < n; i++) {
  		var ch = argStr.charAt(i);
  		if (ch != "0" && ch != "."){
			return false;
  		}
 	}
 	return true;
}

function isDigit (c) {   

	return ((c >= "0") && (c <= "9"));
}

function round_decimals(original_number, precision) {

	var prec = 2;
	if (round_decimals.arguments.length == 2)
		prec = precision;
	var result1 = original_number * Math.pow(10, prec);
    var result2 = Math.round(result1);
    var result3 = result2 / Math.pow(10, prec);
    return pad_with_zeros(result3, prec);
}

function pad_with_zeros(rounded_value, precision) {

	var prec = 2;
	if (round_decimals.arguments.length == 2)
		prec = precision;
		
    // Convert the number to a string
    var value_string = rounded_value.toString();
    
    // Locate the decimal point
    var decimal_location = value_string.indexOf(".");

    // Is there a decimal point?
    if (decimal_location == -1) {
        
        // If no, then all decimal places will be padded with 0s
        decimal_part_length = 0;
        
        value_string += ".";
    }
    else {

        // If yes, then only the extra decimal places will be padded with 0s
        decimal_part_length = value_string.length - decimal_location - 1;
    }
    
    // Calculate the number of decimal places that need to be padded with 0s
    var pad_total = prec - decimal_part_length;
    
    if (pad_total > 0) {
        
        // Pad the string with 0s
        for (var counter = 1; counter <= pad_total; counter++) 
            value_string += "0";
        }
    return value_string;
}



function subpop(s) {

 	addWindow = window.open(s,"cal","width=287,height=237,resizable=0,status=0,menubar=0,scrollbars=0,fullscreen=0");
	addWindow.focus();
}

function getFocus(elementName) {
	document.getElementById(elementName).focus();
}

function isArray(obj) {
	
return(typeof(obj.length)=="undefined")?false:true;

}

function isCheckBoxSelected(checkBoxName) {

	var isChecked = false;
	
	if (isArray(checkBoxName)) {
	
		for (var i = 0; i < checkBoxName.length; i++) {
			
			if (checkBoxName[i].checked) {
			
				isChecked = true;
				break;	
			}
		}
	}
	else {
	
		if (checkBoxName.checked) 
			isChecked = true;
	}
	
	return isChecked;
}

function countOfCheckedCheckBoxes(checkBoxName) {

	var cnt = 0;
	
	if (isArray(checkBoxName)) {
		
		for (var i = 0; i < checkBoxName.length; i++) {
			
			if (checkBoxName[i].checked) {
			
				cnt = cnt + 1;
			}
		}
	}
	else {
	
		if (checkBoxName.checked) 
			cnt = cnt + 1;
	}
	
	return cnt;
}

function isRadioSelected(radioName) {

	var isSelected = false;
	
	if (isArray(radioName)) {
	
		for (var i = 0; i < radioName.length; i++) {
			
			if (radioName[i].checked) {
			
				isSelected = true;
				break;	
			}
		}
	}
	else {
	
		if (radioName.checked) 
			isSelected = true;
	}
	
	return isSelected;
}

function collapse(which, imageName){
	if (document.getElementById && document.createTextNode){
		m=document.getElementById("main");
		trig=m.getElementsByTagName("div").item(which).style.display;
		if (trig=="none") {
			trig="block";
			if (imageName != "")
				document.getElementById(imageName).src="/Images/minus.gif";
		}
		else if (trig=="" || trig=="block") {
			trig="none";
			if (imageName != "")
				document.getElementById(imageName).src="/Images/plus.gif";	
		}	
		m.getElementsByTagName("div").item(which).style.display=trig;
	}
} 

function collapseAll(totalNbr){
	for (i=0;i<totalNbr;i++){
		if (document.getElementById && document.createTextNode){
			m=document.getElementById("main");
			trig=m.getElementsByTagName("div").item(i).style.display;
			if (trig=="none") trig="block";
			else if (trig=="" || trig=="block") trig="none";
			m.getElementsByTagName("div").item(i).style.display=trig;
	 }//end of if
	}//end of for
} //end of method - collapseAll


function showSection(which) {
	document.getElementById(which).style.display = 'block';
}

function hideSection(which) {
	document.getElementById(which).style.display = 'none';
}

function checkAll(field)
{
	if (isArray(field)) {
		for (i = 0; i < field.length; i++)
			field[i].checked = true ;
	}
	else {
		field.checked = true ;
	}
}
	
function uncheckAll(field)
{
	if (isArray(field)) {
		for (i = 0; i < field.length; i++)
			field[i].checked = false ;
	}
	else {
		field.checked = false ;
	}
}

function getElementsForm(f) {
		var el, e = 0 ;
		while (el = f.elements[e++]) {				 
		   alert("Type is  is "+ el.type);
		   alert("Name is  is "+ el.name);		 
		}
		return false;
	}

function isValidPassword(inputPW) {
	var strLength = inputPW.length;
	
	for (var i = 0; i < strLength; i++) {
  		var ch = inputPW.charAt(i);
  		if (!isNum(ch) && !isCharacter(ch) && !isValidPWCharacter(ch)) {
		 	return false;
  		}
 	}
 	return true;
}

function hasAnyUpperCaseChar(inputPW) {
	var strLength = inputPW.length;
	for (var i = 0; i < strLength; i++) {
		var ch = inputPW.charAt(i);
		if (ch >= "A" && ch <= "Z") {
			return true;
		}
	}//end of for
  	return false;
}

function hasAnyNum(inputPW) {
	var strLength = inputPW.length;
 	for (var i = 0; i < strLength; i++) {  		
  		var ch = inputPW.charAt(i);
  		if (isDigit(ch))
		 	return true;	
 	}
 	return false;
}

function hasAnyLowerCaseChar(inputPW) {
	var strLength = inputPW.length;
	for (var i = 0; i < strLength; i++) {
		var ch = inputPW.charAt(i);
		if (ch >= "a" && ch <= "z") {
			return true;
		}
	}//end of for
	return false;
}

function hasAnySpecialChar(inputPW) {
	var iChars = "~!@#$%^&*()_+{}|][:';?><,./'" ;
	var strLength = inputPW.length;
	for (var i = 0; i < strLength; i++) {
		var ch = inputPW.charAt(i);
		if (iChars.indexOf(ch)> -1) 	{  		
			return true;
		}	
	}//end of for
	return false;
}

function hasAnySpecialCharForPassword(inputPW) {
	var iChars = "#$@" ;
	var strLength = inputPW.length;
	for (var i = 0; i < strLength; i++) {
		var ch = inputPW.charAt(i);
		if (iChars.indexOf(ch)> -1) 	{  		
			return true;
		}	
	}//end of for
	return false;
}

function isCharacter(ch) {
	return ((ch >= "A" && ch <= "Z") || (ch >= "a" && ch <= "z"));
}

function isValidPWCharacter(ch) {
	var iChars = "#$@" ;
	if (iChars.indexOf(ch)== -1) 	{  		
	  	return false;
  }
	return true;
}

function isDateLaterThanToday(argDate1){

	var datePat = /^(\d{1,4})(\/|-)(\d{1,2})\2(\d{1,2})$/;
	var matchArray = argDate1.match(datePat);
	year = matchArray[1]; // parse date into variables
	month = matchArray[3]; 
	day = matchArray[4];

	var dateToCheck = new Date();
	dateToCheck.setYear(year);
	dateToCheck.setMonth(month-1);
	dateToCheck.setDate(day);
	var checkDate = dateToCheck.getTime();
	var now = new Date();
	now = now.getTime(); //NN3
	
	var futureDate = (now < checkDate);
	var pastDate = (now > checkDate);

	if(futureDate){
	   return true;
	}else{
		return false;
	}
}

function selectAll(formObj, isInverse) 
{
   for (var i=0;i < formObj.length;i++) 
   {
      fldObj = formObj.elements[i]; 
      if (fldObj.type == 'checkbox')
      { 
         if(isInverse)
	         fldObj.checked = false;
            //fldObj.checked = (fldObj.checked) ? false : true;
         else fldObj.checked = true; 
       }
   }
}

var letters="abcdefghijklmnopqrstuvwxyz ";//include space too
var LETTERS="ABCDEFGHIJKLMNOPQRSTUVWXYZ";

  function isAlpha(c) {
   c= trim(c);
    // is c a String or a character?
    if(c.length>1) {
      for(j=0;j<c.length;j++) {
        // call isAlpha recursively for each character
        alpha=isAlpha(c.substring(j,j+1));
        if(!alpha) return alpha;
      }
      return alpha;
    }
    else {
      // if c is alpha return true
      if(letters.indexOf(c)>=0 || LETTERS.indexOf(c)>=0) return true;
      return false;
    }
  }  

var NOS="0123456789";
  function isAlphaNumeric(c) {
   c= trim(c);
    // is c a String or a character?
    if(c.length>1) {
      for(j=0;j<c.length;j++) {
        // call isAlpha recursively for each character
        alpha=isAlphaNumeric(c.substring(j,j+1));
        if(!alpha) return alpha;
      }
      return alpha;
    }
    else {
      // if c is alpha return true
      if(letters.indexOf(c)>=0 || LETTERS.indexOf(c)>=0 || NOS.indexOf(c)>=0) return true;
      return false;
    }
  }

/*[0]-Street Address
  [1]-City
  [2]-State
  [3]-Zip
  */
function validateAddress(arryAddress)
{
	var problems="";
	if(arryAddress.length!=4)
	{
		alert("Address info must be fully filled out!");
		return false; 
	} 
	if(arryAddress[0]==null)
		problems=+"Street address must be entered\n"; 
	if(arryAddress[1]==null)
		problems+="City must be entered\n"; 
	if(arryAddress[2]==null|| /[^a-zA-Z]{2}$/.test(arryAddress[2]))
		problems+="State must be entered and only two characters\n";
	if(arryaddress[3]==null|| /^\d{5}([\-]\d{4})?$/.test(arryAddress[3]))
		problems+="Zip code must only be 5 or 9 digit format(ie-23142 or 23142-3923)"; 
	if(problems!="")
	{
		alert(problems); 
		return false; 
	}
	return true; 
}
  
  
function isEmailAddr(email)
{

  return (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(email));
  //var result = false
  //var theStr = new String(email)
  //var index = theStr.indexOf("@");
  //if (index > 0)
  //{
  //  var pindex = theStr.indexOf(".",index);
  //  if ((pindex > index+1) && (theStr.length > pindex+1))
  //	result = true;
  //}
  //return result;
}

function clearForm(frmObj) {
	var i;
	for (i = 0; i < frmObj.length; i++) {
		var itemType = frmObj.elements[i].type;
		if (itemType == "text") {
			frmObj.elements[i].value = "";
		}
		else if (itemType == "checkbox") {
			frmObj.elements[i].checked = false;
		}		
	}
}

// raje- radio button function to check if the user has selected a radio button
function getSelectedRadio(buttonGroup) {
	   // returns the array number of the selected radio button or -1 if no button is selected
	   if (buttonGroup[0]) { // if the button group is an array (one button is not an array)
		  for (var i=0; i<buttonGroup.length; i++) {
			 if (buttonGroup[i].checked) {
				return i;
			 }
		  }
	   } else {
		  if (buttonGroup.checked) { return 0; } // if the one button is checked, return zero
	   }
	   // if we get to this point, no radio button is selected
	   return -1;
} // Ends the "getSelectedRadio" 

function getSelectedRadioValue(buttonGroup) {
   // returns the value of the selected radio button or "" if no button is selected
   var i = getSelectedRadio(buttonGroup);
   if (i == -1) {
      return "";
   } else {
      if (buttonGroup[i]) { // Make sure the button group is an array (not just one button)
         return buttonGroup[i].value;
      } else { // The button group is just the one button, and it is checked
         return buttonGroup.value;
      }
   }
} // Ends the "getSelectedRadioValue" function

function getSelectedCheckbox(buttonGroup) {
   // Go through all the check boxes. return an array of all the ones
   // that are selected (their position numbers). if no boxes were checked,
   // returned array will be empty (length will be zero)
   var retArr = new Array();
   var lastElement = 0;
   if (buttonGroup[0]) { // if the button group is an array (one check box is not an array)
      for (var i=0; i<buttonGroup.length; i++) {
         if (buttonGroup[i].checked) {
            retArr.length = lastElement;
            retArr[lastElement] = i;
            lastElement++;
         }
      }
   } else { // There is only one check box (it's not an array)
      if (buttonGroup.checked) { // if the one check box is checked
         retArr.length = lastElement;
         retArr[lastElement] = 0; // return zero as the only array value
      }
   }
   return retArr;
} // Ends the "getSelectedCheckbox" function

function getSelectedCheckboxValue(buttonGroup) {
   // return an array of values selected in the check box group. if no boxes
   // were checked, returned array will be empty (length will be zero)
   var retArr = new Array(); // set up empty array for the return values
   var selectedItems = getSelectedCheckbox(buttonGroup);
   if (selectedItems.length != 0) { // if there was something selected
      retArr.length = selectedItems.length;
      for (var i=0; i<selectedItems.length; i++) {
         if (buttonGroup[selectedItems[i]]) { // Make sure it's an array
            retArr[i] = buttonGroup[selectedItems[i]].value;
         } else { // It's not an array (there's just one check box and it's selected)
            retArr[i] = buttonGroup.value;// return that value
         }
      }
   }
   return retArr;
} // Ends the "getSelectedCheckBoxValue" function


function validateDecimalNumRule(decimalNum, mask) {

	mask = trim(mask);
	var beforeDotNum = mask.indexOf(".");
	var afterDotNum = mask.length - beforeDotNum - 1;
	
	var decimalPattern = new RegExp();
	
	if (beforeDotNum <= 9) {
	 	decimalPattern = new RegExp("^[0-9]{1," + beforeDotNum + "}\.[0-9]{" + afterDotNum + "}$");
	}
	else {
		decimalPattern = new RegExp("(^[0-9]{1,9}[0-9]{" + (beforeDotNum - 9) + "}\.[0-9]{" + afterDotNum + "}$)|(^[0-9]{1}\.[0-9]{" + afterDotNum + "}$)");
	}
	
	if (decimalPattern.test(decimalNum)) 
		return true;
	else 
		return false;
}

	function validateDate(dateStr)
    {
        var re;
        // Rules for the date regular expression:
        // The format of the date is:
        // dd/mm/yyyy
        // Days: Valid between 1 and 31
        // The first digit may either be a 3 followed by a 0 or a 1 
        // or it could be a 0 followed by 1 to 9, or a 1 or 2, 
        // followed by any digit.
        // Then follows a backslash
        // Months: Valid between 1 and 12
        // The month may be a 0 followed by 1 to 9, or a 1 followed by 
        // either a 0, 1 or 2. 
        // Then follows a backslash
        // The year must comprise of any 4 digits.
        re = /^(3[01]|0[1-9]|[12]\d)\/(0[1-9]|1[012])\/\d{4}/;
        return re.test(dateStr);
	}
	
	function disableAllButtons(doc) {
	
		var e = doc.getElementsByTagName("input");
		for (i = 0; i < e.length; i++) 
			if (e[i].type == 'button' || e[i].type == 'submit' || e[i].type == 'reset')
				e[i].disabled = true;
	}
