function validFields(Fields)
{
	  for (j=1; j<arguments.length; j++)
	  {
		  
		  if(arguments[j].value="")
		  {
			  return false;
		  }		    	
	  }
	  
	  return true;
}

function validField(field)
{
	if (field=="")
	{
		return false;
	}
	return true;
}

function validDate(date)
{
	invalidChars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ:,;";
	
		
	for (i=0; i<invalidChars.length;i++)
	{
		badChar = invalidChars.charAt(i);
		if(date.indexOf(badChar,0) > -1)
		{
			return false;
		}
	}
	return true;
}


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;
}
function isMoney(str){
	var i;
	if (str.length == 0)
		return false;
	for (i=0; i<str.length; i++){
		ch = str.charAt(i);
		if ((ch < '0' || ch > '9') && (ch != '.'))
			return false;
		if (ch == '.')
			break;
	}
	if (i == str.length)
		return true;
	for (++i; i<str.length; i++) {
		ch = str.charAt(i);
		if (ch < '0' || ch > '9')
			return false;
	}
	return true;
}
function round_decimals(original_number, decimals) {
    var result1 = original_number * Math.pow(10, decimals)
    var result2 = Math.round(result1)
    var result3 = result2 / Math.pow(10, decimals)
    return pad_with_zeros(result3, decimals)
}
function pad_with_zeros(rounded_value, decimal_places) {
 
    // 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
        
        // If decimal_places is greater than zero, tack on a decimal point
        value_string += decimal_places > 0 ? "." : ""
    }
    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 = decimal_places - 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 validNum(check, err_msg){
   str=new String(check.value)
   if(isNaN(str) == true ){
      alert(err_msg)
	  check.focus();
	  return false;
   }
   if(check.value<0) {
   	alert(err_msg)
   	check.focus();
   	return false;
   }
 }
function CalculateTotal(frm) {
	var foodamount1=0;
	var otheramount1=0;
	var amount1=0;
	var amount2=0;
	var amount3=0;
	var amount4=0;
	var amount5=0;
	var amount6=0;
	var amount7=0;
	var totalamt = 0;
	if(!isNaN(frm.foodamount1.value) && frm.foodamount1.value!="") {
 		foodamount1 = round_decimals(frm.foodamount1.value, 2);
		frm.foodamount1.value = foodamount1;
	}
	if(!isNaN(frm.otheramount1.value) && frm.otheramount1.value!="") {
 		otheramount1 = round_decimals(frm.otheramount1.value, 2);
		frm.otheramount1.value = otheramount1;
	}
	if(!isNaN(frm.amount1.value) && frm.amount1.value!="") {
		amount1 = round_decimals(frm.amount1.value, 2);
		frm.amount1.value = amount1;
	}
	if(!isNaN(frm.amount2.value) && frm.amount2.value!="") {
		amount2 = round_decimals(frm.amount2.value, 2);
		frm.amount2.value = amount2;
	}
	if(!isNaN(frm.amount3.value) && frm.amount3.value!="") {
		amount3 = round_decimals(frm.amount3.value, 2);
		frm.amount3.value = amount3;
	}
	if(!isNaN(frm.amount4.value) && frm.amount4.value!="") {
		amount4 = round_decimals(frm.amount4.value, 2);
		frm.amount4.value = amount4;
	}
	if(!isNaN(frm.amount5.value) && frm.amount5.value!="") {
		amount5 = round_decimals(frm.amount5.value, 2);
		frm.amount5.value = amount5;
	}
	if(!isNaN(frm.amount6.value) && frm.amount6.value!="") {
		amount6 = round_decimals(frm.amount6.value, 2);
		frm.amount6.value = amount6;
	}
	if(!isNaN(frm.amount7.value) && frm.amount7.value!="") {
		amount7 = round_decimals(frm.amount7.value, 2);
		frm.amount7.value = amount7;
	}
	totalamt = parseFloat(foodamount1) + parseFloat(otheramount1) + parseFloat(amount1)  + parseFloat(amount2) +  parseFloat(amount3) +  parseFloat(amount4) +  parseFloat(amount5) +  parseFloat(amount6) +  parseFloat(amount7);
	frm.totalamount.value = round_decimals(totalamt, 2);
}
function blockNonNumbers(obj, e, allowDecimal, allowNegative)
{
	var key;
	var isCtrl = false;
	var keychar;
	var reg;
		
	if(window.event) {
		key = e.keyCode;
		isCtrl = window.event.ctrlKey
	}
	else if(e.which) {
		key = e.which;
		isCtrl = e.ctrlKey;
	}
	
	if (isNaN(key)) return true;
	
	keychar = String.fromCharCode(key);
	
	// check for backspace or delete, or if Ctrl was pressed
	if (key == 8 || isCtrl)
	{
		return true;
	}

	reg = /\d/;
	var isFirstN = allowNegative ? keychar == '-' && obj.value.indexOf('-') == -1 : false;
	var isFirstD = allowDecimal ? keychar == '.' && obj.value.indexOf('.') == -1 : false;
	
	return isFirstN || isFirstD || reg.test(keychar);
}
