window.addEvent('domready', function() {
    updateTotal;
});


function doAdd(el){
    var extras = 0;
    if($(el).id == 'child' || $(el).id == 'baby'){
        $($(el).id+'_cnt').setProperties({'disabled':'','value':1})
    }
    if($('driver').checked == true){
        extras += (5*$('totaldays').value);
    }
    if($('rack').checked == true){
        var rack = (3*$('totaldays').value);
        if(rack > 42) rack = 42;
        extras += rack;
    }
    if($('nav').checked == true){
        extras += (9.5*$('totaldays').value);
    }
    if($('cell').checked == true){
        extras += (3*$('totaldays').value);
    }
    if($('gas').checked == true){
        extras += $('gasdb').value.toInt();
    }
    if($('baby').checked == true){
        var baby =  ($('baby_cnt').value*$('totaldays').value)*3;
        if(baby > 42) baby = 42;
        extras += baby;
    }
    if($('child').checked == true){
        var child =  ($('child_cnt').value*$('totaldays').value)*3;
        if(child > 42) child = 42;
        extras += child;
    }
	if($('baby').checked == false){
		$($('baby').id+'_cnt').setProperties({'disabled':'true','value': ''})
	}
	if($('child').checked == false){
		$($('child').id+'_cnt').setProperties({'disabled':'true','value': ''})
	}
    var currentE = $('extras').value;
    value =  extras*1
    $('extrasf').setProperty('html','US$ '+value.toFixed(2));
	$('extrasf').highlight('#ff0')
   $('extras').value = extras;
   updateTotal();
}
 var sliset;
 var sldwset;
 var vacset;
 
 
function doAddI(el){
    var ins = 0;
	if($('ldwf').checked == true){
		ins += basic_i * $('totaldays').value;

	}
    if($('sli').checked == true)
    {        
		if($('ldwf').checked == true)
		{
			ins += (8 * $('totaldays').value);
		}
		else
		{
			alert('You must also purchase LDW with SLI, I will add it for you.');
         	$('ldwf').setProperty('checked','checked');
         	ins += (8 * $('totaldays').value);
			ins += basic_i * $('totaldays').value;
		}
		
        
        
    }
    
    if($('sldw').checked == true )
    {
        if($('sli').checked == true && $('ldwf').checked == true)
        {
            ins += (15 * $('totaldays').value);
        }
        else
        {
			if($('sli').checked == false){
				alert('You must also purchase SLI with SLDW, I will add it for you.');
         		$('sli').setProperty('checked','checked');
         		ins += (23 * $('totaldays').value);
			}
			if($('ldwf').checked == false){
				alert('You must also purchase LDW with SLDW, I will add it for you.');
         		$('ldwf').setProperty('checked','checked');
         		ins += (basic_i * $('totaldays').value);
			}

        }
        
    }
    
    if($('vac').checked == true )
    {
        ins += (4 * $('totaldays').value);      
    }
    var currentI =  ins*1;
   $('insurancef').setProperty('html','US$ '+currentI+'.00');
   $('insurance').value = currentI;
   $('insurancef').highlight('#ff0')
   updateTotal();
}
   
function updateTotal(){
    var total = 0;
    var basic = $('basic').value; 
    var insurance = $('insurance').value; 
    var extras = $('extras').value;
    total = basic*1+insurance*1+extras*1;
   // $('totaltotal').value = total;
    $('totaltotalf').setProperty('html','US$ '+ total.toFixed(2));
	$('totaltotalf').highlight('#ff0')
}

function addInput(box){
    alert(box.id)
  $(box.id+'-input').setStyle('display','block');
}

function checkForm(){
    if($('surname').value.length == 0){
        $('surname').setStyle('border','1px solid red')
        alert('We need your last name');
        $('surname').focus();
        return false;
    }
    else{
        $('surname').setStyle('border','none')
    }
    var tfld = $('email').value.replace(/^\s+|\s+$/, '');                        // value of field with whitespace trimmed off
    var emailFilter = /^[^@]+@[^@.]+\.[^@]*\w\w$/ ;
    var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/ ;
    if ($('email').value.length == 0) {
        $('email').setStyle('border','1px solid red');
        alert("You didn't enter an email address.") ;
        $('email').focus();
        return false
    } else if (!emailFilter.test(tfld)) {              //test email for illegal characters
        $('email').setStyle('border','1px solid red');
        alert("Please enter a valid email address.\n");
        $('email').focus();
        return false
    } else if ($('email').value.match(illegalChars)) {
        $('email').setStyle('border','1px solid red');
        alert("The email address contains illegal characters.\n");
        $('email').focus();
        return false;
    } else {
        $('email').setStyle('border','none');
    }
    if($('phone').value.length == 0){
        $('phone').setStyle('border','1px solid red')
        alert('We need your day time phone number');
        $('phone').focus();
        return false;
    }
    if($('flight').value.length == 0){
            $('flight').setStyle('border','1px solid red')
            alert('We need your flight number or enter none');
            $('flight').focus();
            return false;
     }
        

 
    return ;
}


