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 clear_f() {
	window.onbeforeunload = function() {
	}
}

function send_feedback_out() {
	var params='';
	clear_f();
	$('#fancybox-inner').find('input[name="params[]"]:checked').each(function () {
		params=params+$(this).val()+"\n";
	})

		
	$.get('/feedback_out.html',{post_in:'1',params:params,other_reason:$('#fancybox-inner').find('textarea[name=other_reason]').val(),your_name:$('#fancybox-inner').find('input[name=your_name]').val(),your_email:$('#fancybox-inner').find('input[name=your_email]').val()},function (data) {
		$('#fancybox-inner').html(data);
	})

}

function try_to_login() {
	var email=$('#fancybox-inner').find('input[name=EMAIL]').val();
	var order_id=$('#fancybox-inner').find('input[name=ORDER_ID]').val();
	$('#fancybox-inner').find('#LOGIN_submit').hide();
	$.post('/index.php?pd=&5051&md=renta&inst=&action=login',{action:'login',pd:'&8718',ajax:1,doit:'ajax_login',EMAIL:email,ORDER_ID:order_id},function (data) {
		if (data==1 || data==2) {
			if (data==1) {
				location="/?pd=&765&md=renta&inst=&action=user_menu";
			} else {
				location="/prestige/?pd=&765&md=renta&inst=&action=user_menu";
			}
		} else {
			$('#fancybox-inner').find('#EMAIL_title').css('color','red');
			$('#fancybox-inner').find('#ORDER_ID_title').css('color','red');
		}
		$('#fancybox-inner').find('#LOGIN_submit').show();
	})
}

function validateSelection() {

	var date_from=$('input[name=pickup_date]').val();
	var date_from_tmp=$('input[name=pickup_date]').val().split('/');
	var date_from_num=date_from_tmp[0]*31*24*60+date_from_tmp[1]*24*60+date_from_tmp[2]*256*31*24*60+$('[name=pickup_time_h]').val()*60+$('[name=pickup_time_m]').val();

	var date_to=$('input[name=return_date]').val();
	var date_to_tmp=$('input[name=return_date]').val().split('/');
	var date_to_num=date_to_tmp[0]*31*24*60+date_to_tmp[1]*24*60+date_to_tmp[2]*256*31*24*60+$('[name=return_time_h]').val()*60+$('[name=return_time_m]').val();
	
	
	if( date_from_num>=date_to_num ) {
		alert( "You cannot return a car before you rented it." );
		return false;
	}

	if ( $('[name=custdelemail]').val() == '' ) {
		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;
		}
	}
	*/
	var pickupObj;
	var returnObj;
	
	if ($('#listpickuplocation').css('display')=='none')
	{
		pickupObj = $('select[id=pickup_location_id]');
		$('input[id=pickup_location_id]').val($('select[id=pickup_location_id]').val());
	}
	else
	{	
		pickupObj = $('input[id=pickup_location_id]');
		$('select[id=pickup_location_id]').val($('input[id=pickup_location_id]').val());
	}	
		
	if ($('#listreturnlocation').css('display')=='none')
	{
		returnObj = $('select[id=return_location_id]');
		$('input[id=return_location_id]').val($('select[id=return_location_id]').val());
	}
	else
	{
		returnObj = $('input[id=return_location_id]');
		$('select[id=return_location_id]').val($('input[id=return_location_id]').val());
	}		
	
	if (pickupObj){
		if (CheckTime(pickupObj)==false) {
			alert( "Please choose your location" );
			return false;
		}
	}
	/*if (returnObj) {
		if (CheckTime(returnObj)==false) {
			return false;
		}
	}*/
	$('#step1_form').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).val();
	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).val()]['hour']!=false) return true;
	var open=locations[$(element).val()]['open'].substr(0,5);
	var close=locations[$(element).val()]['close'].substr(0,5);
	var title=locations[$(element).val()]['title'];
	var sopen=$('[name=pickup_time_h]').val()+':'+$('[name=pickup_time_m]').val();
	var sclose=$('[name=return_time_h]').val()+':'+$('[name=return_time_m]').val();

	
	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=360,menubar=0');
	document.frm.setAttribute('target','quote');
	document.frm.submit();
}

function next_step(car_id,action,mode){
	if (action=='step2') {
		document.frm.payment_type.value=$("[name=payment_type"+car_id+"]:checked").val();
	}
	if (action=='step3') {
		var field_code =document.createElement('input'); 
		var disc_field =document.createElement('input'); 
		field_code.type="hidden";
		field_code.name="TRAVEL_CODE";
		field_code.value= $("[name=TRAVEL_CODE]").val();
		
		disc_field.type="hidden";
		disc_field.name="discount_code";
		disc_field.value= $("[name=discount_code]").val();
		
		document.frm.appendChild(field_code);
		document.frm.appendChild(disc_field);
	}
	
	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;
	//alert("car_id="+car_id+"|action="+action+"|mode="+mode);
	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;
	}
}


