function basket_manipulate(record_id, media_id, id_anchor, price, title, thumbnail, type, date, object_number, record_type, duration, framerate, media_id, profiles, start_frame, end_frame, umids){
	$.ajax({
		type: "POST",
		url: "/xml/basket_status.php",
		dataType: "xml",
		data: "record_id="+record_id+"&media_id="+media_id+"&start_frame="+start_frame+"&end_frame="+end_frame+"",
		success: function(xml) {
			$(xml).find('basket').each(function(){
				var status = $(this).attr('record_status');
				if(status == "[+] Basket"){
					$.ajax({
						type: "POST",
						url: "/xml/basket_status.php",
						dataType: "xml",
						data: "add_to_basket=1&record_id="+record_id+"&media_id="+media_id+"&quantity=1&price="+price+"&title="+title+"&thumbnail="+thumbnail+"&date="+date+"&object_number="+object_number+"&record_type="+record_type+"&duration="+duration+"&framerate="+framerate+"&media_id="+media_id+"&profiles="+profiles+"&start_frame="+start_frame+"&end_frame="+end_frame+"&umids="+umids+"",
						success: function(xml) {
							$(xml).find('basket').each(function(){
								var status_update = $(this).attr('record_status');
								$('#basket_status_'+id_anchor+'_'+start_frame+'_'+end_frame+'').empty();
								if(type == "img"){
									$('#basket_status_'+id_anchor+'_'+start_frame+'_'+end_frame+'').html('<img src="images/basket_added.png" height="25" width="25" alt="Remove this record from your basket" />');
									$('#basket_status2_'+id_anchor+'_'+start_frame+'_'+end_frame+'').html('<p>Remove from Basket</p>');
								} else {
									$('#basket_status_'+id_anchor+'_'+start_frame+'_'+end_frame+'').html('<span>'+status_update+'</span>');	
								}
							});	
						}
					});
	
					
				} else if(status == "[-] Basket") {
					
					$.ajax({
						type: "POST",
						url: "/xml/basket_status.php",
						dataType: "xml",
						data: "remove_from_basket=1&record_id="+record_id+"&media_id="+media_id+"&start_frame="+start_frame+"&end_frame="+end_frame+"",
						success: function(xml) {
							$(xml).find('basket').each(function(){
								var status_update = $(this).attr('record_status');
								$('#basket_status_'+id_anchor+'').empty();
								if(type == "img"){
									$('#basket_status_'+id_anchor+'_'+start_frame+'_'+end_frame+'').html('<img src="images/basket_add.png" height="25" width="25" alt="Add this record to your basket" />');
									$('#basket_status2_'+id_anchor+'_'+start_frame+'_'+end_frame+'').html('<p>Add to Basket</p>');
								} else {
									$('#basket_status_'+id_anchor+'_'+start_frame+'_'+end_frame+'').html('<span>'+status_update+'</span>');	
								}
							});	
						}
					});
					
				} else {
					
					return false;
					
				}
			});
		}
	});	
}
function check_format_options(record_id, media_id){
	var wmv_id = document.getElementById("wmv_" + media_id);
	var mov_id = document.getElementById("mov_" + media_id);
	var screener_id = document.getElementById("screener_" + media_id);
	var private_id = document.getElementById("private_" + media_id);
	
	/*if (!$('#screener_'+media_id+'').attr('checked') && !$('#private_'+media_id+'').attr('checked')) {
		alert('Please select a video type.');
		return false;
	}
	*/
	if (!$('#wmv_'+media_id+'').attr('checked') && !$('#mov_'+media_id+'').attr('checked')) {
		alert('Please select a video format.');
		return false;
	}
	
}

function check_dvd_rom_format_options(record_id, media_id){
	var wmv_id = document.getElementById("dvd_rom_wmv_" + media_id);
	var mov_id = document.getElementById("dvd_rom_mov_" + media_id);
	var screener_id = document.getElementById("dvd_rom_screener_" + media_id);
	var private_id = document.getElementById("dvd_rom_private_" + media_id);
	
	/*if (!$('#dvd_rom_screener_'+media_id+'').attr('checked') && !$('#dvd_rom_private_use_'+media_id+'').attr('checked')) {
		alert('Please select a video type.');
		return false;
	}*/
	if (!$('#dvd_rom_wmv_'+media_id+'').attr('checked') && !$('#dvd_rom_mov_'+media_id+'').attr('checked')) {
		alert('Please select a video format.');
		return false;
	}
	
}

function check_dvd_video_format_options(record_id, media_id){
	/*if (!$('#dvd_video_screener_'+media_id+'').attr('checked') && !$('#dvd_video_private_use_'+media_id+'').attr('checked')) {
		alert('Please select a video type.');
		return false;
	}*/
	
}



function check_storage_options(){
	alert('Please select a storage medium for all records.');
		return false;
		
}

function check_totals(){ 

	if($('#terms').attr('checked') == true){
		return true;
	} else {
		alert("Please tick the box to indicate you have read our User Agreement.");
		return false;
	}
	
}

function check_format_availability(type, screener_id, private_id, wmv_id, mov_id, commercial_wmv_path, wmv_path, commercial_mov_path, mov_path) {
	
	var wmv_id = document.getElementById(wmv_id);
	var mov_id = document.getElementById(mov_id);
	var screener_id = document.getElementById(screener_id);
	var private_id = document.getElementById(private_id);
	
	if(type == "screener") {
		if(screener_id.checked == true) {
			if(commercial_wmv_path > 0){
				wmv_id.disabled = false;
			} else {
				wmv_id.disabled = true;
				wmv_id.checked = false;
				mov_id.checked = true;
				//alert('Sorry, a Windows Media format with a time-coded screener is not available for this record.');
			}
			
			if(commercial_mov_path > 0){
				wmv_id.disabled = false;
			} else {
				wmv_id.disabled = true;
				wmv_id.checked = false;
				mov_id.checked = true;
				//alert('Sorry, a Windows Media format with a time-coded screener is not available for this record.');
			}
		} else {
			
			if(private_id.checked == true) {
				if(wmv_path > 0){
					wmv_id.disabled = false;
				} else {
					wmv_id.disabled = true;
					wmv_id.checked = false;
					mov_id.checked = true;
					//alert('Sorry, a Windows Media format with a time-coded screener is not available for this record.');
				}
				
				if(mov_path > 0){
					mov_id.disabled = false;
				} else {
					mov_id.disabled = true;
					mov_id.checked = false;
					wmv_id.checked = true;
					//alert('Sorry, a Quicktime format with a time-coded screener is not available for this record.');
				}
				
			} else {
				wmv_id.disabled = false;
			}
		}
		
	} else if(type == "private") {
		
		if(private_id.checked == true) {
			if(wmv_path > 0){
				mov_id.disabled = false;
			} else {
				mov_id.disabled = true;
				mov_id.checked = false;
				wmv_id.checked = true;
				//alert('Sorry, a Quicktime format for private use is not available for this record.');
			}
			
			if(mov_path > 0){
				mov_id.disabled = false;
			} else {
				mov_id.disabled = true;
				mov_id.checked = false;
				wmv_id.checked = true;
				//alert('Sorry, a Quicktime format for private use is not available for this record.');
			}
			
		} else {
			
			if(screener_id.checked == true) {
				if(commercial_wmv_path > 0){
					wmv_id.disabled = false;
				} else {
					wmv_id.disabled = true;
					wmv_id.checked = false;
					mov_id.checked = true;
					//alert('Sorry, a Windows Media format for private use is not available for this record.');
				}
				
				if(commercial_mov_path > 0){
					mov_id.disabled = false;
				} else {
					mov_id.disabled = true;
					mov_id.checked = false;
					wmv_id.checked = true;
					//alert('Sorry, a Quicktime format for private use is not available for this record.');
				}
				
			} else {
				mov_id.disabled = false;
			}
		}
		
	} else if(type == "wmv") {
		
		if(screener_id.checked == true) {
			if(commercial_wmv_path <= 0 && wmv_id.checked == true) {
				wmv_id.disabled = true;
				wmv_id.checked = false;
				mov_id.checked = true;
				//alert('Sorry, a Windows Media format with a time-coded screener is not available for this record.');
			}
			if(commercial_mov_path <= 0 && mov_id.checked == true) {
				mov_id.disabled = true;
				mov_id.checked = false;
				wmv_id.checked = true;
				//alert('Sorry, a Quicktime format with a time-coded screener is not available for this record.');
			}
			
		} 
		if(private_id.checked == true) {
			if(wmv_path <= 0 && wmv_id.checked == true) {
				wmv_id.disabled = true;
				wmv_id.checked = false;
				mov_id.checked = true;
				//alert('Sorry, a Windows Media format for private use is not available for this record.');
			}
			if(mov_path <= 0 && mov_id.checked == true) {
				mov_id.disabled = true;
				mov_id.checked = false;
				wmv_id.checked = true;
				//alert('Sorry, a Quicktime format for private use is not available for this record.');
			}
		}
		
		
	} else if(type == "mov") {
		
		if(screener_id.checked == true) {
			if(commercial_wmv_path <= 0 && wmv_id.checked == true) {
				wmv_id.disabled = true;
				wmv_id.checked = false;
				mov_id.checked = true;
				//alert('Sorry, a Windows Media format with a time-coded screener is not available for this record.');
			}
			if(commercial_mov_path <= 0 && mov_id.checked == true) {
				mov_id.disabled = true;
				mov_id.checked = false;
				wmv_id.checked = true;
				//alert('Sorry, a Quicktime format with a time-coded screener is not available for this record.');
			}
			
		} 
		if(private_id.checked == true) {
			if(wmv_path <= 0 && wmv_id.checked == true) {
				wmv_id.disabled = true;
				wmv_id.checked = false;
				mov_id.checked = true;
				//alert('Sorry, a Windows Media format for private use is not available for this record.');
			}
			if(mov_path <= 0 && mov_id.checked == true) {
				mov_id.disabled = true;
				mov_id.checked = false;
				wmv_id.checked = true;
				//alert('Sorry, a Quicktime format for private use is not available for this record.');
			}
		}
	}
	
}
function check_options(count)
{
	var checked1 = false;
	var checked2 = false;
	var checked3 = false;
	
	for(i=0;i<count;i++)
	{
		if(document.options_form.option_usage[i].checked)
		{
			checked1 = true;
		}
		if(document.options_form.option_format[i].checked)
		{
			checked2 = true;
		}
		
	}
	
	if(checked1 != true || checked2 != true)
	{
		alert("Please check all of the available options.");
		
		return false;
	}
	else
	{
		return true;	
	}
}

function validate_email(field,alerttxt){
	with(field){
		apos=value.indexOf("@");
		dotpos=value.lastIndexOf(".");
		if(apos<1||dotpos-apos<2){
			alert(alerttxt);
			return false;
		} else {
			return true;
		}
	}
}	
function checkout_validate(thisform) {
	if($('#bill_name').val() == ''){	
		alert('You must provide us with your billing name.');
		document.getElementById('bill_name').focus();
		return false;
	}
	if(validate_email(thisform.bill_email,"You must provide us with a valid e-mail address.")==false){
		document.getElementById('bill_email').focus();
		return false;	
	}	
	if($('#bill_addr_1').val() == ''){
		alert('Please fill out the field labelled \'Address 1\'.');	
		document.getElementById('bill_addr_1').focus();
		return false;
	}
	/*
	if($('#bill_city').val() == ''){
		alert('Please fill out the field labelled \'Address 3 (city)\'.');
		document.getElementById('bill_city').focus();
		return false;
	}
	*/
	if($('#bill_post_code').val() == ''){
		alert('Please fill out the field labelled \'Postcode / ZIP\'.');
		document.getElementById('bill_post_code').focus();
		return false;
	}
	if($('#customer').val() == ''){
		alert('Please fill out the field labelled \'Name of Cardholder\'.');
		document.getElementById('customer').focus();
		return false;
	}
	if($('#card_no').val() == ''){
		alert('Please fill out the field labelled \'Card Number\'.');
		document.getElementById('card_no').focus();
		return false;
	}
	if($('#expiry').val() == ''){
		alert('Please fill out the field labelled \'Expiry Date (MM/YY)\'.');
		document.getElementById('expiry').focus();
		return false;
	}
	return true;
}
// Function used to request download
function request_download(order_item_id, umid, title, downloadExpiry) 
{
	
	var downloadError = 0;
	
	// Send request to download script, return with download url
	$.ajax({
		beforeSend: function() { // Hide download link and show loading link
			$('a#download_'+order_item_id+'').hide();
			$('span#download-loading-'+order_item_id+'').show();
		},
		type: "GET",
		timeout: "10000", // Milliseconds
		url: "/xml/record_download.php",
		dataType: "xml",
		data: "umid="+umid+"&title="+encodeURIComponent(title)+"&downloadExpiry="+downloadExpiry+"",
		success: function(xml) {
			$(xml).find('download').each(function(){ // Get download URL from XML
				var downloadReturn = $(this).text();
				downloadError = $(this).attr('error');
				if(downloadError == 0) // If no error has been found (an error code greater than 0 is returned if an error occurs) 
				{
					window.location = downloadReturn; // Forward window onto download URL
				}
				else
				{
					alert('There was an error. Please try again. '+downloadReturn); // Download URL failed, display error
				}
			});			
		},
		complete: function() { // Hide loading text and show download link
			$('span#download-loading-'+order_item_id+'').hide();
			$('a#download_'+order_item_id+'').show();
		},
		error: function(XMLHttpRequest) { // Alert with error if download request fails
			alert('There was an error. Please try again. '+XMLHttpRequest);
			$('span#download-loading-'+order_item_id+'').hide();
			$('a#download_'+order_item_id+'').show();
		}
	});	
}
//Function used to check if the given country is a part of the European Union
function checkCountryIsEU(country)
{
	
	// Variable for array search
	var euSearch = 0;
	
	// EU list from http://europa.eu/abc/european_countries/index_en.htm
	var euArr = [ "Austria", 
			      "Belgium", 
			      "Bulgaria", 
			      "Cyprus", 
			      "Czech Republic", 
				  "Denmark", 
				  "Estonia", 
				  "Finland", 
				  "France", 
				  "Germany", 
				  "Greece", 
				  "Hungary", 
				  "Ireland", 
				  "Italy", 
				  "Latvia", 
				  "Lithuania", 
				  "Luxembourg", 
				  "Malta", 
				  "Netherlands", 
				  "Poland", 
				  "Portugal", 
				  "Romania", 
				  "Slovakia", 
				  "Slovenia", 
				  "Spain", 
				  "Sweden", 
				  "United Kingdom" ];
	
	// Search EU array for provided country
	euSearch = jQuery.inArray(country, euArr);
	
	//If euSearch returns -1, then provided country is not in EU list
	if(euSearch < 0)
	{
		
		// VAT display
		$('span#vat-span').empty();
		$('span#vat-span').append('0.00');
		
		// Overall total display
		$('span#overall-total-span').empty();
		$('span#overall-total-span').append($('input#sub_total').val());
		
		// Set amount of order
		$('input#amount').val($('input#sub_total').val());
	}
	else // If country is valid EU, apply VAT rates
	{
		
		// VAT display
		$('span#vat-span').empty();
		$('span#vat-span').append($('input#vat_total').val());
		
		// Overall total display
		$('span#overall-total-span').empty();
		$('span#overall-total-span').append($('input#overall_total').val());
		
		// Set amount of order
		$('input#amount').val($('input#overall_total').val());
	}
}
