function viz() {
 document.getElementById("less").style.visibility = "hidden";
  document.getElementById("cont").style.visibility = "hidden"; 
  document.getElementById("cont").style.height = "1px"; 
}
function flip(act) {
 if (act == "show") {
  document.getElementById("cont").style.visibility = "visible";
  document.getElementById("more").style.visibility = "hidden";
  document.getElementById("less").style.visibility = "visible";
  document.getElementById("cont").style.height = "auto";
 
 } 
 else {
  document.getElementById("cont").style.visibility = "hidden";
  document.getElementById("more").style.visibility = "visible";
  document.getElementById("less").style.visibility = "hidden";
  document.getElementById("cont").style.height = "1px";
 }
}
function validateSelection() {
	if( document.forms[document.forms.length-2].pickup_date_m.selectedIndex == 0 ) {
		alert( "Please select pick up month" );
		return false;
	}
	if( document.forms[document.forms.length-2].pickup_date_d.selectedIndex == 0 ) {
		alert( "Please select pick up day" );
		return false;
	}
	if( document.forms[document.forms.length-2].pickup_date_y.selectedIndex == 0 ) {
		alert( "Please select pick up year" );
		return false;
	}
	if( document.forms[document.forms.length-2].return_date_m.selectedIndex == 0 ) {
		alert( "Please select return month" );
		return false;
	}
	if( document.forms[document.forms.length-2].return_date_d.selectedIndex == 0 ) {
		alert( "Please select return day" );
		return false;
	}
	if( document.forms[document.forms.length-2].return_date_y.selectedIndex == 0 ) {
		alert( "Please select return year" );
		return false;
	}
	if( document.forms[document.forms.length-2].pickup_location.selectedIndex == 0 ) {
		alert( "Please select pick up location" );
		return false;
	}
	if( document.forms[document.forms.length-2].return_location.selectedIndex == 0 ) {
		alert( "Please select return location" );
		return false;
	}
	if( document.forms[document.forms.length-2].return_date_y.selectedIndex - document.forms[document.forms.length-2].pickup_date_y.selectedIndex < 0 ) {
		alert( "You cannot return a car before you rented it." );
		return false;
	}
	if( document.forms[document.forms.length-2].return_date_m.selectedIndex - document.forms[document.forms.length-2].pickup_date_m.selectedIndex < 0 &&
		document.forms[document.forms.length-2].return_date_y.selectedIndex - document.forms[document.forms.length-2].pickup_date_y.selectedIndex == 0 ) {
		alert( "You cannot return a car before you rented it." );
		return false;
	}
	if( document.forms[document.forms.length-2].return_date_m.selectedIndex - document.forms[document.forms.length-2].pickup_date_m.selectedIndex == 0 &&
		document.forms[document.forms.length-2].return_date_y.selectedIndex - document.forms[document.forms.length-2].pickup_date_y.selectedIndex == 0 &&
		document.forms[document.forms.length-2].return_date_d.selectedIndex - document.forms[document.forms.length-2].pickup_date_d.selectedIndex < 0 ) {
		alert( "You cannot return a car before you rented it." );
		return false;
	}
	if( document.forms[document.forms.length-2].return_date_m.selectedIndex - document.forms[document.forms.length-2].pickup_date_m.selectedIndex == 0 &&
		document.forms[document.forms.length-2].return_date_y.selectedIndex - document.forms[document.forms.length-2].pickup_date_y.selectedIndex == 0 &&
		document.forms[document.forms.length-2].return_date_d.selectedIndex - document.forms[document.forms.length-2].pickup_date_d.selectedIndex == 0 &&
		document.forms[document.forms.length-2].return_time.selectedIndex - document.forms[document.forms.length-2].pickup_time.selectedIndex <= 0 ) {
		alert( "You cannot return a car before you rented it." );
		return false;
	}
	if( document.forms[document.forms.length-2].custdelemail.value == '' ) {
		alert( "Please enter your email address so that we can send this quote to you" );
		return false;
	}
	
	var tt=document.forms[document.forms.length-2].custdelphone;
	if (typeof(tt)!="undefined") {
		if( document.forms[document.forms.length-2].custdelphone.value == '' ) {
			alert( "Please enter your contact phone so that we can send this quote to you" );
			return false;
		}
	}
	
	if (CheckTime(document.forms[document.forms.length-2].elements['pickup_location'])==false) {
		return false;
	}
	if (CheckTime(document.forms[document.forms.length-2].elements['return_location'])==false) {
		return false;
	}
	document.forms[document.forms.length-2].submit();
}
function getEmail(check) {
	if(check.checked == 1) {
		document.getElementById('EEMAIL1').style.display = 'block';
		document.getElementById('EEMAIL2').style.display = 'block';
	} else {
		document.getElementById('EEMAIL1').style.display = 'none';
		document.getElementById('EEMAIL2').style.display = 'none';
	}
}

///////////////////

function CheckLocation(element) {
	if (typeof element=="undefined") return false;
	var form  = element.form;
	var value = element.options[element.selectedIndex].value;
	delete(element);
	var element=form.elements['return_location'];
	for (var i=element.options.length-1;i>0;i--) {
		if (typeof element.options[i].removeNode!="undefined") {
			element.options[i].removeNode();
		} else {
			delete(element.options[i]);
		}
		if (typeof element.options[i]!="undefined") {
//			alert(typeof element.options[i]);
		}
	}
	element.options.length=1;
	for (var i in locations) {
		if (locations[i]['agency']!=locations[value]['agency']) continue;
		if (locations[i]['title']=="") continue;
		element.options[element.options.length]=new Option(locations[i]['title'],i);
		if (i==value) {
			element.selectedIndex=element.options.length-1;
		}
	}
}
function CheckTime(element) {
	if (locations[element.options[element.selectedIndex].value]['hour']!=false) return true;
	var open=locations[element.options[element.selectedIndex].value]['open'].substr(0,5);
	var close=locations[element.options[element.selectedIndex].value]['close'].substr(0,5);
	var title=locations[element.options[element.selectedIndex].value]['title'];
	var sopen=element.form.elements['pickup_time'].options[element.form.elements['pickup_time'].selectedIndex].value;
	var sclose=element.form.elements['return_time'].options[element.form.elements['return_time'].selectedIndex].value;
	var vopen=Math.round(open.substr(0,2))+Math.round(open.substr(3,2))/60;
	var vclose=Math.round(close.substr(0,2))+Math.round(close.substr(3,2))/60;
	sopen=Math.round(sopen.substr(0,2))+Math.round(sopen.substr(3,2))/60;
	sclose=Math.round(sclose.substr(0,2))+Math.round(sclose.substr(3,2))/60;
	if (element.name=='pickup_location') {
		if (vopen<vclose && (sopen>vclose || sopen<vopen)) {
			alert('Branch is open between '+open+' and '+close+' please re-select pickup time');
			element.form.elements['pickup_time'].focus();
			return false;
		} else if (vopen>vclose && (sopen>vclose && sopen<vopen)) {
			alert('Branch is open between '+open+' and '+close+' please re-select pickup time');
			element.form.elements['pickup_time'].focus();
			return false;
		}
	} else if (element.name=='return_location') {
		if (vopen<vclose && (sclose>vclose || sclose<vopen)) {
			alert('Branch is open between '+open+' and '+close+' please re-select return time');
			element.form.elements['return_time'].focus();
			return false;
		} else if (vopen>vclose && (sclose>vclose && sclose<vopen)) {
			alert('Branch is open between '+open+' and '+close+' please re-select return time');
			element.form.elements['return_time'].focus();
			return false;
		}
	}
	return true;
}

function email_me(car_id){
	document.frm.car_type.value=car_id;
	document.frm.quote.value=1;
	document.frm.action.value='quote';
	document.frm.mode.value='popup';
	window.open('','quote','width=690,height=330,menubar=0');
	document.frm.setAttribute('target','quote');
	document.frm.submit();
}

function next_step(car_id,action,mode){
//alert("car_id="+car_id);
//alert("action="+action);
//alert("mode="+mode);
	document.frm.removeAttribute('target');
	document.frm.quote.value=0;
	document.frm.action.value=action;
	document.frm.mode.value=mode;
	document.frm.car_type.value=car_id;
	document.frm.submit();
}


function no_deposit( checkbox, div0, div1 ) {
	_td0 = document.getElementById(div0);
	_td1 = document.getElementById(div1);
	if( checkbox.checked ) {
		_td0.style.display='none';
		_td1.style.display='block';
	} else {
		_td0.style.display='block';
		_td1.style.display='none';
	}
}

function changeFUEL( checkbox, def ) {
	def='[#FUEL_DEPOSIT#]';
	no_deposit( checkbox, 'div0', 'div1' );
	if( checkbox.checked ) {
		document.frm.fuel.value = '0.00';
	} else {
		document.frm.fuel.value = def;
	}
}
