var dteTomorrow = new Date(new Date().getTime() + 86400000);
var dteDayAfterTomorrow = new Date(new Date().getTime() + (2*86400000));	
var reservation_page_url = "https://www.abel.com.au/reservations.php?pickup_loc=000400&pickup_day=" + ('0' + dteTomorrow.getDate()).slice(-2) + "&pickup_month=" + ('0' + (dteTomorrow.getMonth() + 1)).slice(-2) + "&pickup_year=" + dteTomorrow.getFullYear() + "&pickup_time=12:00&return_loc=000400&return_day=" + ('0' + dteDayAfterTomorrow.getDate()).slice(-2) + "&return_month=" + ('0' + (dteDayAfterTomorrow.getMonth() + 1)).slice(-2) + "&return_year=" + dteDayAfterTomorrow.getFullYear() + "&return_time=12:00&renter_age_range=25|75&vehicle_class=CCMR";


function homepage_select_vehicle(vehicle_name, vehicle_code, vehicle_desc, large_passengers, small_passengers, large_luggage, small_luggage, fuel, price)
{
	var vehicle_info = "";
	reservation_page_url = "https://www.abel.com.au/reservations.php?pickup_loc=000400&pickup_day=" + ('0' + dteTomorrow.getDate()).slice(-2) + "&pickup_month=" + ('0' + (dteTomorrow.getMonth() + 1)).slice(-2) + "&pickup_year=" + dteTomorrow.getFullYear() + "&pickup_time=12:00&return_loc=000400&return_day=" + ('0' + dteDayAfterTomorrow.getDate()).slice(-2) + "&return_month=" + ('0' + (dteDayAfterTomorrow.getMonth() + 1)).slice(-2) + "&return_year=" + dteDayAfterTomorrow.getFullYear() + "&return_time=12:00&renter_age_range=25|75&vehicle_class=" + vehicle_code;
	document.getElementById('homepage-vehicle-name').innerHTML = vehicle_name;
	document.getElementById('homepage-vehicle-description').innerHTML = vehicle_desc;
	document.getElementById('homepage-selected-vehicle-image').innerHTML = '<img src="images-shared/vehicles/homepage-'+ vehicle_code.toLowerCase() +'.png">';
	document.getElementById('homepage-vehicle-price').innerHTML = '<img src="images-shared/prices/homepage-price-' + price + '.png">';
	document.getElementById('homepage-vehicle-logo').innerHTML = '<img src="images-shared/vehicles/homepage-logo-' + vehicle_code.toLowerCase() + '.png">';
	
	//show or hide 7 day special tag
	/*
	if ((vehicle_code=="CCMR") || (vehicle_code=="DGMR") || (vehicle_code=="EGAR"))
		document.getElementById('homepage-special-tag').innerHTML = '';
	else
		document.getElementById('homepage-special-tag').innerHTML = '<img src="images/homepage-7day-price.png">';
	*/
	
	//vehicle information
	//hide the luggage heading if there is no vehicle luggage
	if ((large_luggage == 0) && (small_luggage == 0))
	{
		document.getElementById('homepage-luggage-title').innerHTML = '';
		document.getElementById('homepage-fuel-title').style.left = document.getElementById('homepage-luggage-title').style.left;
		document.getElementById('homepage-fuel').style.left = document.getElementById('homepage-luggage-title').style.left;
	}else  //there is luggage so show the heading
	{
		document.getElementById('homepage-luggage-title').innerHTML = 'Luggage';
		document.getElementById('homepage-fuel-title').style.left = '240px';
		document.getElementById('homepage-fuel').style.left = '239px';
	}
	
	for (var x = 0; x < large_passengers; x++)
		vehicle_info += '<img src="images/human_large.gif">&nbsp;';
		
	for (var x = 0; x < small_passengers; x++)
		vehicle_info += '<img src="images/human_small.gif">&nbsp;';
	
	document.getElementById('homepage-passengers').innerHTML = vehicle_info;
	vehicle_info = ""; //reset variable	
	
	for (var x = 0; x < large_luggage; x++)
		vehicle_info += '<img src="images/luggage_large.gif">&nbsp;';
	
	for (var x = 0; x < small_luggage; x++)
		vehicle_info += '<img src="images/luggage_small.gif">&nbsp;';
	
	document.getElementById('homepage-luggage').innerHTML = vehicle_info;
	vehicle_info = ""; //reset variable		
	
	vehicle_info += "<img src='images/fuel.gif'>&nbsp;";
	vehicle_info += fuel + " L/100 Ks";
	
	document.getElementById('homepage-fuel').innerHTML = vehicle_info;
}

function franchise_form() 
{
	var franchiseWindow = Ext.create('Ext.window.Window', {
		height: 498,
		width: 500,
		modal: true,
		resizable: false,
		frameHeader: false,
		title: 'Fill out this form and a member of our team will contact you shortly...',
		items: [
			{
				xtype: 'form',
				items: [
				{
					xtype: 'textfield',
					name: 'first_name',
					id: 'first_name',
					margin: '40px 60px 0px 60px;',
					fieldLabel: 'First Name',
					allowBlank: false,
					anchor: '100%'
				},
				{
					xtype: 'textfield',
					name: 'last_name',
					id: 'last_name',
					margin: '20px 60px 0px 60px;',
					fieldLabel: 'Surname',
					allowBlank: false,
					anchor: '100%'
				},
				{
					xtype: 'textfield',
					name: 'email',
					id: 'email',
					margin: '20px 60px 0px 60px;',
					fieldLabel: 'Email Address',
					allowBlank: false,
					anchor: '100%'
				},
				{
					xtype: 'textfield',
					name: 'phone',
					id: 'phone',
					margin: '20px 60px 0px 60px;',
					fieldLabel: 'Contact Number',
					allowBlank: false,
					anchor: '100%'
				},
				{
					xtype: 'textfield',
					name: 'location',
					id: 'location',
					margin: '20px 60px 0px 60px;',
					fieldLabel: 'Location Of Interest',
					allowBlank: false,
					anchor: '100%'
				}, {
					xtype: 'radiogroup',
					width: 400,
					labelAlign: 'top',
					id: 'assets',
					name: 'assets',								
					style: 'margin-left:100px; margin-top: 10px;',
					fieldLabel: 'Do you have $200 000 or more in available liquid assets?',
					items: [
						{
							xtype: 'radiofield',
							boxLabel: 'YES'
						},
						{
							xtype: 'radiofield',
							boxLabel: 'NO'
						}
					]
				},
				{
					xtype: 'textfield',
					name: 'find_us',
					id: 'find_us',
					margin: '20px 60px 0px 60px;',
					fieldLabel: 'How did you hear about us?',
					allowBlank: false,
					anchor: '100%'
				},
				{
					xtype: 'textfield',
					name: 'comments',
					id: 'comments',
					margin: '20px 60px 0px 60px;',
					fieldLabel: 'Comments',
					allowBlank: false,
					anchor: '100%'
				},

				{
					xtype: 'button',
					margin: '20px 120px;',
					width: 100,
					text: 'Send...',
					handler: function() {
						var Firstname = Ext.getCmp('first_name').getRawValue();
						var Lastname = Ext.getCmp('last_name').getRawValue();
						var Email = Ext.getCmp('email').getRawValue();
						var Assets = Ext.getCmp('assets').getValue();
						var Phone = Ext.getCmp('phone').getRawValue();
						var Location = Ext.getCmp('location').getRawValue();
						var Findus = Ext.getCmp('find_us').getRawValue();
						var Comments = Ext.getCmp('comments').getRawValue();
						//alert(Firstname + ' ' + Lastname + ' ' + Email + ' ' + Phone + ' ' + Location + ' ' + Findus + ' ' + Comments);
						
						if ((Firstname.length == 0) || (Lastname.length == 0) || (Email.length == 0) || (Phone.length == 0) || (Location.length == 0) || (Findus.length == 0))
						{
							Ext.MessageBox.alert('Enquiry Not Sent', 'Please fill out all fields before submitting...'); 
						}else
						{					
							Ext.Ajax.request({
								url : 'services/services.php' , 
								params : { 
									service : 'SEND_FRANCHISE_FEEDBACK', 
									first_name: Firstname, 
									last_name: Lastname,
									assets: Assets,
									email: Email,
									phone: Phone,
									location: Location, 
									find_us: Findus,
									comments: Comments
								},
								method: 'POST',
								success: function ( result, request ) { 
									if (result.responseText == "SUCCESS")
									{										
										franchiseWindow.removeAll();
										franchiseWindow.add({
											html: '<br><h1><a align="center" target="_blank" href="franchise-pack.pdf" style="font-size:2em;">Download Franchise Pack Here</a></h1><br>'							
										});
										franchiseWindow.setHeight(10);
									}
									else
									{
										Ext.MessageBox.alert('Feedback Not Sent', 'Please use our email listed on the contact page to make your enquiry!');
									}
								},
								failure: function ( result, request) { 
									Ext.MessageBox.alert('Load Failed', 'You are leaving the page before it has finished loading... <br>Please wait...'); 
								} 
							});
						
						}		
						
						//franchiseWindow.close();
					},
					anchor: '100%'
				}]	
		}]
	});
	franchiseWindow.show();
	
}

function wrapper_play_testimonial(youTubeID)
{	
	var win = new Ext.Window(
	{
		title: 'Real Customers, Real Stories...',
		closable:true,
		width:662,
		height:463,
		resizable: false,
		//border:false,
		modal: true,
		html: '<object width="646" height="396"><param value="http://www.youtube.com/v/' + youTubeID + '?hl=en&amp;fs=1" name="movie"><param value="transparent" name="wmode"><param value="true" name="allowFullScreen"><param value="always" name="allowscriptaccess"><embed width="646" height="396" wmode="transparent" allowfullscreen="true" allowscriptaccess="always" type="application/x-shockwave-flash" src="http://www.youtube.com/v/' + youTubeID + '?hl=en&amp;fs=1"></object>',
		plain:true,
		buttons: [
		{
			text:'Close',
			handler:function()
					{
						//alert(win.getHeight());
						//alert(win.getWidth());
						win.close();
					}
		}]
	});

	win.show(this); 
}

function convert24Hto12(time)
{
	var timeArr = time.split(":");
	if (timeArr.length == 1)  //no colon in input format assume hhmm formatting
	{
		timeArr[0] = time[0] + time[1];
		timeArr.push(time[2] + time[3]);
	}
	var timeSuffix = '';
	
	if (parseInt(timeArr[0]) > 12)
	{
		timeArr[0] = parseInt(timeArr[0]) - 12;
		timeSuffix = ' PM';
	}else if (parseInt(timeArr[0]) < 12)
		timeSuffix = ' AM';
	else
		timeSuffix = ' PM';
	
	if ((parseInt(timeArr[0]) < 10) && (timeArr[0].length == 2)) //string leading 0
		timeArr[0] = timeArr[0][1];  //just grab the 2nd digit only
		
	return timeArr[0] + ':' + timeArr[1] + timeSuffix;
}

function wrapper_play_radio()
{
	var win = new Ext.Window(
	{
		title: 'Our Radio Advertisements!',
		closable:true,
		width: 516,
		height: 416,
		resizable: false,
		//border:false,
		modal: true,
		html: '<div style="width:500px; z-index:9999; height:400px; background-image:url(images/radio-ads-large.png); background-repeat:no-repeat"><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><p>&nbsp;&nbsp;&nbsp;&nbsp;Abel Truck Hire Ad<br />&nbsp;&nbsp;&nbsp;&nbsp;<embed type="application/x-shockwave-flash" flashvars="audioUrl=http://www.abel.com.au/audio/abel-truck.mp3" src="http://www.google.com/reader/ui/3523697345-audio-player.swf" width="300" height="27" quality="best"></embed><br /><br />&nbsp;&nbsp;&nbsp;&nbsp;Abel Car Hire Ad<br />&nbsp;&nbsp;&nbsp;&nbsp;<embed type="application/x-shockwave-flash" flashvars="audioUrl=http://www.abel.com.au/audio/abel-29.mp3" src="http://www.google.com/reader/ui/3523697345-audio-player.swf" width="300" height="27" quality="best"></embed></p></div>',
		plain:true,
		buttons: [
		{
			text:'Close',
			handler:function()
					{
						//alert(win.getHeight());
						//alert(win.getWidth());
						win.close();
					}
		}]
	});

	win.show(this); 	
}
