function calc_rate(arg){
	var Persons = 0;
	var Nights = 0;
	var RegFee = 0;
	var ExtraFee = 0;
	var NightFee = 0;	
	
	if(eval(arg.Nights.value)<eval(arg.MinNights.value)){
		arg.Nights.value=eval(arg.MinNights.value);
		alert("Please note: less than " +  arg.MinNights.value + " Nights is allowed but you'll be charged for the minimum stay of " +  arg.MinNights.value + " Nights.");
		//return false;
	}else{	
		if(eval(arg.Nights.value)>eval(arg.MaxNights.value)){
			arg.Nights.value=eval(arg.MaxNights.value);
			alert("Please note: " + arg.MaxNights.value + " Nights is the maximum stay.");
			//return false;
		}
	}
	
	Nights = eval(arg.Nights.value);
	
	if(arg.Persons.value<=arg.MaxPersons.value&&arg.Persons.value>=arg.MinPersons.value){
		
	}else{
		alert("Please note: min. # persons "+arg.MinPersons.value+" and max "+arg.MaxPersons.value+".");		
		arg.Persons.value=arg.MinPersons.value;		
		arg.Persons.focus();
		//return false;
	}
	
	Persons=eval(arg.Persons.value);
	
	if (arg.ExtraFee!=null){
		ExtraFee = arg.ExtraFee.value;
	} 
	if (arg.ReservationFee!=null){
		RegFee = arg.ReservationFee.value;
	}else{
		return false;
	}
	if (arg.NightFee!=null){
		NightFee = arg.NightFee.value;
	}else{
		return false;
	}	
	arg.Total.value = (eval(RegFee) + eval(ExtraFee)) +  (eval(NightFee)*eval(Persons)*eval(Nights));
}

function calc_init(){
	frm = document.frmcalculator;
	frm.Nights.value = frm.MinNights.value;
	frm.Persons.value = frm.MinPersons.value;
	calc_rate(frm);
}

function checkNumber(el){		
	// Make sure IE4 by examining createTextRange method
	if (document.body==null) return true
	if (document.body.createTextRange==null) return true
	// Convert key code to character
	var key = String.fromCharCode(event.keyCode), dotRelationship, allowDigit
	var checkDot = false
	var allowDigit = false
	// Check if number of digits following decimal point is cached
	if (el._digits==null) {
	  // Examine default value (initial value attribute)
	  var strNum = "0"  // antes -- el.defaultValue -- el asignaba el value del textbox "0.00"
	  // Find the decimal point
	  var idx = strNum.indexOf(".")
	  // Calculate number of decimal digits
	  if (idx>-1) 
		el._digits = strNum.length - idx - 1
	  else
		el._digits = -1
	}

	// Make sure a digit or a decimal point
	if (!isNaN(key) || key==".") {
	  // Get selection (either insertion point or text selection)
	  var selectionRange = document.selection.createRange()
	  // Store a copy for use in comparisons
	  var tempSel = selectionRange.duplicate()

	  // Variable for the input range 
	  var inputRange = el.createTextRange()

	  // Get index of the dot
	  var dotPos = el.value.indexOf(".")
 
	  // If decimal point, check if new character valid
	  if (dotPos>-1) {
		// Locate existing decimal point 
		inputRange.findText(".")
		// When user types decimal, it is only accepted if
		// replacing existing decimal point
		if ((key==".") && (el._digits>-1)) {
		  if (tempSel.findText("."))
		  // Test if existing decimal in selection
		  checkDot = selectionRange.inRange(tempSel)
		} else {
		  // Determine whether the selection is before or after the decimal point
		  dotRelationship = inputRange.compareEndPoints("EndToStart",selectionRange)
		  // Test if new input is an allowable digit
		  allowDigit = ((dotRelationship<=0 && (el.value.length - dotPos -1 < el._digits || selectionRange.text.length>0)) || (dotRelationship==1 && key!="."))
		}
	  } else {
		// If inserting a decimal, test number of following digits
		if (key==".") 
			tempSel.moveEnd("textEdit",1)          
			allowDigit = (key=="." && (tempSel.text.length - 1 < el._digits)) || !isNaN(key)
	  }
	}
	// Return whether the key is allowed
	return (checkDot || allowDigit);
}
	
window.onload = calc_init;