var generating_quote = '<table border=\"0\" width=\"300\" cellpadding=\"0\" style=\"border: 1px solid #CC3300\" cellspacing=\"0\"><tr><td width=\"49\" bgcolor=\"#F5F5F5\" height=\"40\"><p align=\"center\"><img border=\"0\" src=\"images/spinner.gif\" width=\"32\" height=\"32\"></td><td bgcolor=\"#F5F5F5\" height=\"40\"><font face=\"Arial\" style=\"font-size: 9pt\">Generating Quote. Please Wait ...</font></td></tr></table>'
var deleting_item = '<table border=\"0\" width=\"300\" cellpadding=\"0\" style=\"border: 1px solid #CC3300\" cellspacing=\"0\"><tr><td width=\"49\" bgcolor=\"#F5F5F5\" height=\"40\"><p align=\"center\"><img border=\"0\" src=\"images/spinner.gif\" width=\"32\" height=\"32\"></td><td bgcolor=\"#F5F5F5\" height=\"40\"><font face=\"Arial\" style=\"font-size: 9pt\">Deleting Order. Please Wait ...</font></td></tr></table>'
var searching_now = '<table border=\"0\" width=\"300\" cellpadding=\"0\" style=\"border: 1px solid #CC3300\" cellspacing=\"0\"><tr><td width=\"49\" bgcolor=\"#F5F5F5\" height=\"40\"><p align=\"center\"><img border=\"0\" src=\"images/spinner.gif\" width=\"32\" height=\"32\"></td><td bgcolor=\"#F5F5F5\" height=\"40\"><font face=\"Arial\" style=\"font-size: 9pt\">Searching Database. Please Wait ...</font></td></tr></table>'
var order_details_now = '<table border=\"0\" width=\"300\" cellpadding=\"0\" style=\"border: 1px solid #CC3300\" cellspacing=\"0\"><tr><td width=\"49\" bgcolor=\"#F5F5F5\" height=\"40\"><p align=\"center\"><img border=\"0\" src=\"images/spinner.gif\" width=\"32\" height=\"32\"></td><td bgcolor=\"#F5F5F5\" height=\"40\"><font face=\"Arial\" style=\"font-size: 9pt\">Find Order Details. Please Wait ...</font></td></tr></table>'
var edit_order = '<table border=\"0\" width=\"300\" cellpadding=\"0\" style=\"border: 1px solid #CC3300\" cellspacing=\"0\"><tr><td width=\"49\" bgcolor=\"#F5F5F5\" height=\"40\"><p align=\"center\"><img border=\"0\" src=\"images/spinner.gif\" width=\"32\" height=\"32\"></td><td bgcolor=\"#F5F5F5\" height=\"40\"><font face=\"Arial\" style=\"font-size: 9pt\">Retrieving Order Details ...</font></td></tr></table>'
var tracking = '<table border=\"0\" width=\"300\" cellpadding=\"0\" style=\"border: 1px solid #CC3300\" cellspacing=\"0\"><tr><td width=\"49\" bgcolor=\"#F5F5F5\" height=\"40\"><p align=\"center\"><img border=\"0\" src=\"images/spinner.gif\" width=\"32\" height=\"32\"></td><td bgcolor=\"#F5F5F5\" height=\"40\"><font face=\"Arial\" style=\"font-size: 9pt\">Tracking Order Now ...</font></td></tr></table>'
var fetching = '<table border=\"0\" width=\"300\" cellpadding=\"0\" style=\"border: 1px solid #CC3300\" cellspacing=\"0\"><tr><td width=\"49\" bgcolor=\"#F5F5F5\" height=\"40\"><p align=\"center\"><img border=\"0\" src=\"images/spinner.gif\" width=\"32\" height=\"32\"></td><td bgcolor=\"#F5F5F5\" height=\"40\"><font face=\"Arial\" style=\"font-size: 9pt\">Downloading Orders Now ...</font></td></tr></table>'
var validating = '<table border=\"0\" width=\"100%\" cellspacing=\"4\" cellpadding=\"4\"><tr><td bgcolor=\"#f5f5f5\"><font face=\"Trebuchet MS\" size=\"2\" color=\"#000000\">Verifying addresses - please wait a moment</font></td></tr><tr><td><font face=\"Trebuchet MS\" size=\"2\"><img border=\"0\" src=\"images/fetching.gif\" width=\"220\" height=\"19\"></font></td></tr></table>';
var confirming = '<table border=\"0\" width=\"100%\" cellspacing=\"4\" cellpadding=\"4\"><tr><td bgcolor=\"#f5f5f5\"><font face=\"Trebuchet MS\" size=\"2\" color=\"#000000\">Verifying information - please wait a moment</font></td></tr><tr><td><font face=\"Trebuchet MS\" size=\"2\"><img border=\"0\" src=\"images/fetching.gif\" width=\"220\" height=\"19\"></font></td></tr></table>';

function createRequestObject() {
    var ro;
    var browser = navigator.appName;
    if(browser == "Microsoft Internet Explorer"){
        ro = new ActiveXObject("Microsoft.XMLHTTP");
    }else{
        ro = new XMLHttpRequest();
    }
    return ro;
}

var http = createRequestObject();

var flag = false;

function smartMark() {
  if(flag == false) {
    markAll();
  }
  else {
    unmarkAll();
  }
  flag = !flag;
}

function markAll()
{f=document.forms.auctions;
 for(i=0;i<f.elements.length;i++)
  {if(f.elements[i].name=="selectOrder[]") 
       if(!f.elements[i].checked) f.elements[i].click();
  }
}

function unmarkAll()
{f=document.forms.auctions;
 for(i=0;i<f.elements.length;i++)
  {if(f.elements[i].name=="selectOrder[]") 
       if(f.elements[i].checked) f.elements[i].click();
  }
}

function submitenter(myfield,e)
{
var keycode;
if (window.event) keycode = window.event.keyCode;
else if (e) keycode = e.which;
else return true;

if (keycode == 13)
   {
   myfield.form.submit();
   return false;
   }
else
   return true;
}

function popUp(URL) {
day = new Date();
id = day.getTime();
eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=450,height=300');");
}


function showhideCollection(collection)
{

	if(collection.value.indexOf("UK -") != '-1')
	{
		document.forms.getquote.collection_postcode.style.display='inline';
	} else {
		document.forms.getquote.collection_postcode.style.display='none';
		document.forms.getquote.collection_postcode.value='';		
	}

}

function showhideDelivery(delivery)
{

	if(delivery.value.indexOf("UK -") != '-1' || delivery.value.indexOf("Isle Of Wight") != '-1' || delivery.value.indexOf("Scottish Highlands") != '-1' || delivery.value.indexOf("Northern Ireland") != '-1' || delivery.value.indexOf("Isle of Scilly") != '-1' || delivery.value.indexOf("Isle of Man") != '-1' || delivery.value.indexOf("Channel Islands") != '-1')
	{
		document.forms.getquote.delivery_postcode.style.display='inline';
	} else {
		document.forms.getquote.delivery_postcode.style.display='none';
		document.forms.getquote.delivery_postcode.value='';		
	}

}

// EBAY DOWNLOAD CODE

function fetchitems(id,username)
{

var button_layer = 'button_' + id;

	// document.getElementById('innerdiv').innerHTML = fetching;
	document.getElementById(button_layer).innerHTML = '<img src="images/fetching.gif">';
	var url = "p4d/system.php";
	var data = "action=fetch&fetchid=" + id + "&username=" + username;
	http.open("POST", url, true);
	http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    http.send(data);
	http.onreadystatechange = handleResponseFetching;

}

function handleResponseFetching() {
	
    if(http.readyState == 4){
	
        var response = http.responseText;
		var layers_replace = new Array();
				
		    layers_replace = response.split('*');	
							
			for(i=0;i<layers_replace.length;i++) {
					var update = new Array();
					update = layers_replace[i].split('|');
					// alert(update[0]);
					// alert(update[1]);
					document.getElementById(update[0]).innerHTML = update[1];
			}
			
    }
	
	// document.getElementById('innerdiv').innerHTML = '';
}

function handleResponse() {
	
    if(http.readyState == 4){
	
        var response = http.responseText;
			
		var layers_replace = new Array();
						
		    layers_replace = response.split('*');	
					
			for(i=0;i<layers_replace.length;i++) {
					var update = new Array();
					
					update = layers_replace[i].split('|');				
					
					if(update[0] == 'redirect')
					{
					window.location=update[1];
					} else {
					
					// alert(update[0]);
					// alert(update[1]);

					document.getElementById(update[0]).innerHTML = update[1];
					
						var error_fields = new Array();
						if(update[2]) {
							error_fields = update[2].split(',');	
								for(j=0;j<error_fields.length;j++) {
									document.forms.fix_errors[error_fields[j]].style.background = '#FFE8DF';
								}
						}
					}
			}
			
    }
	
	// document.getElementById('innerdiv').innerHTML = '';

}

function handleSearchResponse() {
	
    if(http.readyState == 4){
	
        var response = http.responseText;
			
		var layers_replace = new Array();
						
		    layers_replace = response.split('---*---');	
					
			for(i=0;i<layers_replace.length;i++) {
					var update = new Array();
					
					update = layers_replace[i].split('---|---');
					
					if(update[0] == 'redirect')
					{
					window.location=update[1];
					} else {
					
					document.getElementById(update[0]).innerHTML = update[1];
					
						var error_fields = new Array();
						if(update[2]) {
							error_fields = update[2].split(',');	
								for(j=0;j<error_fields.length;j++) {
									document.forms.fix_errors[error_fields[j]].style.background = '#FFE8DF';
								}
						}
					}
			}
			
    }
	
	// document.getElementById('innerdiv').innerHTML = '';

}

// END EBAY

// SYSTEM DOWNLOAD ITEMS

function fn(obj,rID,colID)
{

	var colA = rID + '-A';
	var colB = rID + '-B';
	var colC = rID + '-C';
	var colD = rID + '-D';			
           
   document.getElementById(colA).className  = colID
   document.getElementById(colB).className  = colID
   document.getElementById(colC).className  = colID
   // document.getElementById(colD).className  = colID
            
}

function fn_out(obj,rID,colID)
{

	var colA = rID + '-A';
	var colB = rID + '-B';
	var colC = rID + '-C';
	var colD = rID + '-D';	
            
   document.getElementById(colA).className  = colID
   document.getElementById(colB).className  = colID
   document.getElementById(colC).className  = colID
   // document.getElementById(colD).className  = colID
}

function book(id, itemid, bypass)
{

	// scrollTo(0,0);
	
	var weight_value = document.auctions['weight_'+id].value;
	var height_value = document.auctions['height_'+id].value;
	var length_value = document.auctions['length_'+id].value;
	var width_value = document.auctions['width_'+id].value;
	
	var errors = "";
	if(weight_value == 0) { errors = errors + "You must enter the weight of the parcel\n"; }
	if(height_value == 0 || length_value == 0 || width_value == 0) { errors = errors + "You must enter all of the dimensions of the parcel\n"; }
	
	if(errors && bypass != 'y') { 
	alert(errors);
	
	} else {
	
	// document.getElementById('innerdiv').innerHTML = generating_quote;
	document.getElementById('right').innerHTML = '<div align="center"><p>&nbsp;</p><img src="/images/gettingquote.gif"><P>Your quote is being generated.</div>';	
	
	var url = "p4d/system.php";
	var data = "action=quote&format=simple&weight=" + weight_value + "&height=" + height_value + "&length=" + length_value + "&width=" + width_value + "&itemid=" + itemid + "&id=" + id;

	http.open("POST", url, true);
	http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    http.send(data);
	http.onreadystatechange = handleResponse;
	}
}

function edit(id, itemid)
{

	scrollTo(0,0);
	// document.getElementById('innerdiv').innerHTML = edit_order;

	var url = "/p4d/system.php";
	var data = "action=quote&format=edit" + "&itemid=" + itemid + "&id=" + id;

	http.open("POST", url, true);
	http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    http.send(data);
	http.onreadystatechange = handleResponse;

}

function fix(id, itemid)
{

	var errors = "";
	if(!document.fix_errors.collection_name.value) { errors = errors + "You must enter the collection name\n"; 			document.fix_errors.collection_name.style.background = '#FFE8DF'; } else { document.fix_errors.collection_name.style.background = '#FFFFFF'; }
	if(!document.fix_errors.collection_address1.value) { errors = errors + "You must enter the collection address\n"; 	document.fix_errors.collection_address1.style.background = '#FFE8DF'; } else { document.fix_errors.collection_address1.style.background = '#FFFFFF'; }
	if(!document.fix_errors.collection_town.value) { errors = errors + "You must enter the collection town\n"; 			document.fix_errors.collection_town.style.background = '#FFE8DF'; } else { document.fix_errors.collection_town.style.background = '#FFFFFF'; }
	if(!document.fix_errors.collection_county.value) { errors = errors + "You must enter the collection county\n"; 		document.fix_errors.collection_county.style.background = '#FFE8DF'; } else { document.fix_errors.collection_county.style.background = '#FFFFFF'; }
	if(!document.fix_errors.collection_postcode.value) { errors = errors + "You must enter the collection postcode\n"; 	document.fix_errors.collection_postcode.style.background = '#FFE8DF'; } else { document.fix_errors.collection_postcode.style.background = '#FFFFFF'; }
	if(!document.fix_errors.collection_telephone.value) { errors = errors + "You must enter the collection telephone\n"; document.fix_errors.collection_telephone.style.background = '#FFE8DF'; } else { document.fix_errors.collection_telephone.style.background = '#FFFFFF'; }
	
	if(!document.fix_errors.delivery_name.value) { errors = errors + "You must enter the delivery name\n"; 			document.fix_errors.delivery_name.style.background = '#FFE8DF'; } else { document.fix_errors.delivery_name.style.background = '#FFFFFF'; }
	if(!document.fix_errors.delivery_address1.value) { errors = errors + "You must enter the delivery address\n"; 	document.fix_errors.delivery_address1.style.background = '#FFE8DF'; } else { document.fix_errors.delivery_address1.style.background = '#FFFFFF'; }
	if(!document.fix_errors.delivery_town.value) { errors = errors + "You must enter the delivery town\n"; 			document.fix_errors.delivery_town.style.background = '#FFE8DF'; } else { document.fix_errors.delivery_town.style.background = '#FFFFFF'; }
	if(!document.fix_errors.delivery_county.value) { errors = errors + "You must enter the delivery county\n"; 		document.fix_errors.delivery_county.style.background = '#FFE8DF'; } else { document.fix_errors.delivery_county.style.background = '#FFFFFF'; }
	if(!document.fix_errors.delivery_postcode.value) { errors = errors + "You must enter the delivery postcode\n"; 	document.fix_errors.delivery_postcode.style.background = '#FFE8DF'; } else { document.fix_errors.delivery_postcode.style.background = '#FFFFFF'; }
	if(!document.fix_errors.delivery_country.value) { errors = errors + "You must enter the delivery country\n"; 	document.fix_errors.delivery_country.style.background = '#FFE8DF'; } else { document.fix_errors.delivery_country.style.background = '#FFFFFF'; }
	if(!document.fix_errors.delivery_telephone.value) { errors = errors + "You must enter the delivery telephone\n"; document.fix_errors.delivery_telephone.style.background = '#FFE8DF'; } else { document.fix_errors.delivery_telephone.style.background = '#FFFFFF'; }
	
	if(document.fix_errors.weight.value == 0) { errors = errors + "You must enter the weight of the parcel\n"; document.fix_errors.weight.style.background = '#FFE8DF'; } else { document.fix_errors.weight.style.background = '#FFFFFF'; }
	if(document.fix_errors.height.value == 0) { errors = errors + "You must enter the height of the parcel\n"; document.fix_errors.height.style.background = '#FFE8DF'; } else { document.fix_errors.height.style.background = '#FFFFFF'; }
	if(document.fix_errors.width.value == 0) { errors = errors + "You must enter the width of the parcel\n"; document.fix_errors.width.style.background = '#FFE8DF'; } else { document.fix_errors.width.style.background = '#FFFFFF'; }
	if(document.fix_errors.length.value == 0) { errors = errors + "You must enter the length of the parcel\n"; document.fix_errors.length.style.background = '#FFE8DF'; } else { document.fix_errors.length.style.background = '#FFFFFF'; }
	
	if(errors) { 
	alert(errors);
	scrollTo(0,0);
	} else {
	
	// document.getElementById('innerdiv').innerHTML = generating_quote;
	
	var weight = document.fix_errors.weight.value;
	var height = document.fix_errors.height.value;
	var width = document.fix_errors.width.value;
	var length = document.fix_errors.length.value;
	
	var collection_name = document.fix_errors.collection_name.value;
	var collection_company = document.fix_errors.collection_company.value;
	var collection_address1 = document.fix_errors.collection_address1.value;
	var collection_address2 = document.fix_errors.collection_address2.value;
	var collection_address3 = document.fix_errors.collection_address3.value;
	var collection_town = document.fix_errors.collection_town.value;
	var collection_county = document.fix_errors.collection_county.value;
	var collection_postcode = document.fix_errors.collection_postcode.value;
	var collection_telephone = document.fix_errors.collection_telephone.value;
	var delivery_name = document.fix_errors.delivery_name.value;
	var delivery_company = document.fix_errors.delivery_company.value;
	var delivery_address1 = document.fix_errors.delivery_address1.value;
	var delivery_address2 = document.fix_errors.delivery_address2.value;
	var delivery_address3 = document.fix_errors.delivery_address3.value;
	var delivery_town = document.fix_errors.delivery_town.value;
	var delivery_county = document.fix_errors.delivery_county.value;
	var delivery_postcode = document.fix_errors.delivery_postcode.value;
	var delivery_country = document.fix_errors.delivery_country.value;
	var delivery_telephone = document.fix_errors.delivery_telephone.value;	
	
	var url = "/p4d/system.php";
	var data = "action=quote&format=full" + "&weight=" + weight + "&height=" + height + "&width=" + width + "&length=" + length + "&collection_name=" + collection_name + "&collection_company=" + collection_company + "&collection_address1=" + collection_address1 + "&collection_address2=" + collection_address2 + "&collection_address3=" + collection_address3 + "&collection_town=" + collection_town + "&collection_county=" + collection_county + "&collection_postcode=" + collection_postcode + "&collection_telephone=" + collection_telephone + "&delivery_name=" + delivery_name + "&delivery_company=" + delivery_company + "&delivery_address1=" + delivery_address1 + "&delivery_address2=" + delivery_address2 + "&delivery_address3=" + delivery_address3 + "&delivery_town=" + delivery_town + "&delivery_county=" + delivery_county + "&delivery_postcode=" + delivery_postcode + "&delivery_country=" + delivery_country + "&delivery_telephone=" + delivery_telephone + "&itemid=" + itemid + "&id=" + id;
	
	http.open("POST", url, true);
	http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    http.send(data);
	http.onreadystatechange = handleResponse;
	scrollTo(0,0);
	
	}
	
}

function combine(ids)
{

	scrollTo(0,0);
	var show_loader = true;
	
	// document.getElementById('innerdiv').innerHTML = generating_quote;
	
	var url = "/p4d/system.php";
	var data = "action=quote&format=combine&step=1&ids=" + ids;
		
	http.open("POST", url, true);
	http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    http.send(data);
	http.onreadystatechange = handleResponse;
	
}

function combineconfirm(ids)
{

	scrollTo(0,0);
	var show_loader = true;
	
	var weight_value = document.multi.weight.value;
	var height_value = document.multi.height.value;
	var length_value = document.multi.length.value;
	var width_value = document.multi.width.value;
	var combined_name_value = document.multi.combined_name.value;
	
	var errors = "";
	if(weight_value == 0) { errors = errors + "You must enter the weight of the parcel\n"; }
	if(height_value == 0 || length_value == 0 || width_value == 0) { errors = errors + "You must enter all of the dimensions of the parcel\n"; }
	if(!combined_name_value) { errors = errors + "You must enter a name for this combined package\n"; }
	
	if(errors) { 
	alert(errors);	
	} else {
	
	// document.getElementById('innerdiv').innerHTML = generating_quote;
	
	var url = "/p4d/system.php";
	var data = "action=quote&format=combineconfirm&step=2&" + "weight=" + weight_value + "&height=" + height_value + "&length=" + length_value + "&width=" + width_value + "&ids=" + ids + "&combined_name_value=" + combined_name_value;
		
	http.open("POST", url, true);
	http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    http.send(data);
	http.onreadystatechange = handleResponse;
	
	}
	
}

function multiconfirm(id, itemid, multiok)
{

	// document.getElementById('innerdiv').innerHTML = generating_quote;

	var weight_value = document.multi.weight.value;
	var height_value = document.multi.height.value;
	var length_value = document.multi.length.value;
	var width_value = document.multi.width.value;
	
	var errors = "";
	if(weight_value == 0) { errors = errors + "You must enter the weight of the parcel\n"; }
	if(height_value == 0 || length_value == 0 || width_value == 0) { errors = errors + "You must enter all of the dimensions of the parcel\n"; }
	
	if(errors) { 
	alert(errors);
	
	} else {	
	
	// document.getElementById('innerdiv').innerHTML = generating_quote;
	
	var url = "/p4d/system.php";
	var data = "action=quote&format=multi&multiok=" + multiok + "&itemid=" + itemid + "&weight=" + weight_value + "&height=" + height_value + "&length=" + length_value + "&width=" + width_value + "&id=" + id;
	
	http.open("POST", url, true);
	http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    http.send(data);
	http.onreadystatechange = handleResponse;
	
	}
	
}

function change(obj)
{
		var chosen = obj.value;

		var details = new Array();
	    details = chosen.split('---');	
		
		document.forms.book.hidden_service.value = details[1];
		document.forms.book.hidden_price.value = details[2];
		document.forms.book.hidden_carrier.value = details[3];
		document.forms.book.hidden_smdservice.value = details[4];
			
		var vat = ((parseFloat(details[2]) + parseFloat(document.forms.book.hidden_insurance_price.value)) * parseFloat(document.forms.book.hidden_vat.value)/100);
		document.forms.book.hidden_vat_total.value=RoundMe(vat,2);
		
		var total = parseFloat(document.forms.book.hidden_price.value) + parseFloat(document.forms.book.hidden_insurance_price.value) + parseFloat(document.forms.book.hidden_vat_total.value);
		document.forms.book.hidden_total.value=RoundMe(total,2);
		
		document.getElementById("display_service").innerHTML = details[1];
		document.getElementById("display_price").innerHTML = details[2];
		document.getElementById("display_vat").innerHTML = RoundMe(vat,2);
		document.getElementById("display_total").innerHTML = RoundMe(total,2);
		
		var url = "/p4d/system.php";
		var data = "action=collection_times&hidden_carrier=" + document.forms.book.hidden_carrier.value + "&hidden_service=" + document.forms.book.hidden_service.value + "&hidden_smdservice=" + document.forms.book.hidden_smdservice.value;
		http.open("POST", url, true);
		http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	    http.send(data);
		http.onreadystatechange = handleCollectionDropResponse;
		
		
}

function terms_ok()
{


if(document.forms.pay.terms.checked)
{
document.forms.paypal.paypal.disabled = false;
document.forms.payaccount.account.disabled = false;
document.forms.paycredit.credit.disabled = false;
document.forms.paypaypal.paypal.style.color= '#000000';
document.forms.payaccount.account.style.color= '#000000';
document.forms.paycredit.credit.style.color= '#000000';
} else {
document.forms.paypaypal.paypal.disabled = true;
document.forms.payaccount.account.disabled = true;
document.forms.paycredit.credit.disabled = true;
document.forms.paypaypal.paypal.style.color= '#808080';
document.forms.payaccount.account.style.color= '#808080';
document.forms.paycredit.credit.style.color= '#808080';
}

}

function cheap(id, itemid, bypass)
{

	scrollTo(0,0);
	// document.getElementById('innerdiv').innerHTML = generating_quote;
	
	var weight_value = document.auctions['weight_'+id].value;
	var height_value = document.auctions['height_'+id].value;
	var length_value = document.auctions['length_'+id].value;
	var width_value = document.auctions['width_'+id].value;
	
	var errors = "";
	if(weight_value == 0) { errors = errors + "You must enter the weight of the parcel\n"; }
	if(height_value == 0 || length_value == 0 || width_value == 0) { errors = errors + "You must enter all of the dimensions of the parcel\n"; }
	
	if(errors && bypass != 'y') { 
	alert(errors);
	
	} else {
	
	// document.getElementById('innerdiv').innerHTML = generating_quote;
	document.getElementById('right').innerHTML = '<div align="center"><p>&nbsp;</p><img src="/images/gettingquote.gif"><P>Your quote is being generated.</div>';		
	
	var url = "/p4d/cheap.php";
	var data = "weight=" + weight_value + "&height=" + height_value + "&length=" + length_value + "&width=" + width_value + "&itemid=" + itemid + "&id=" + id;

	http.open("POST", url, true);
	http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    http.send(data);
	http.onreadystatechange = handleResponse;
	}
}

function overseas_delivery(obj)
{

var delivery_country = obj.value;

if(delivery_country != 'uk')
{
document.forms.fix_errors.delivery_town.style.background = '#FFFFFF';
document.forms.fix_errors.delivery_county.style.background = '#FFFFFF';
document.forms.fix_errors.delivery_postcode.style.background = '#FFFFFF';
document.forms.fix_errors.delivery_town.disabled = false;
document.forms.fix_errors.delivery_county.disabled = false;
document.forms.fix_errors.delivery_postcode.disabled = false;
} else {
document.forms.fix_errors.delivery_town.style.background = '#f5f5f5';
document.forms.fix_errors.delivery_county.style.background = '#f5f5f5';
document.forms.fix_errors.delivery_postcode.style.background = '#f5f5f5';
document.forms.fix_errors.delivery_town.disabled = true;
document.forms.fix_errors.delivery_county.disabled = true;
document.forms.fix_errors.delivery_postcode.disabled = true;
}

}	
	
function ins(obj)
{

var insurance = obj.value;

		var details = new Array();
	    details = insurance.split('---');	
		
		document.forms.book.hidden_insurance_price.value = details[0];
		document.forms.book.hidden_insurance_name.value = details[1];
		
		var vat = ((parseFloat(details[0]) + parseFloat(document.forms.book.hidden_price.value)) * parseFloat(document.forms.book.hidden_vat.value)/100);
		document.forms.book.hidden_vat_total.value=RoundMe(vat,2);		
		
		var total = parseFloat(document.forms.book.hidden_price.value) + parseFloat(document.forms.book.hidden_insurance_price.value) + parseFloat(document.forms.book.hidden_vat_total.value);
		document.forms.book.hidden_total.value=RoundMe(total,2);		
		
		document.getElementById("display_insurance_price").innerHTML = details[0];
		document.getElementById("display_insurance_name").innerHTML = details[1];
		document.getElementById("display_vat").innerHTML = RoundMe(vat,2);		
		document.getElementById("display_total").innerHTML = RoundMe(total,2);
}


	function RoundMe(x,places) {

		return x.toFixed(2);
		
	}

// END SYSTEM

function copyCollection(obj)
{
	
	details = obj.value.split("---");
	
	var company = details[0];
	var address1 = details[1];
	var address2 = details[2];
	var address3 = details[3];
	var town = details[4];
	var county = details[5];
	var postcode = details[6];
	var business = details[7];	
	
	
	if(!company) { company = ''; }
	if(!address1) { address1 = ''; }
	if(!address2) { address2 = ''; }
	if(!address3) { address3 = ''; }
	if(!town) { town = ''; }
	if(!county) { county = ''; }
	if(!postcode) { postcode = ''; }	
	if(!business) { business = ''; }		

	document.getquote.collection_company.value = company;
	document.getquote.collection_address1.value = address1;
	document.getquote.collection_address2.value = address2;
	document.getquote.collection_address3.value = address3;
	document.getquote.collection_town.value = town;
	document.getquote.collection_county.value = county;
	document.getquote.collection_postcode.value = postcode;
	document.getquote.collection_business.value = business;	

}

function copyAccountCollection(obj)
{
	
	details = obj.value.split("---");
	
	var company = details[0];
	var address1 = details[1];
	var address2 = details[2];
	var address3 = details[3];
	var town = details[4];
	var county = details[5];
	var postcode = details[6];
	var business = details[7];	
	
	
	if(!company) { company = ''; }
	if(!address1) { address1 = ''; }
	if(!address2) { address2 = ''; }
	if(!address3) { address3 = ''; }
	if(!town) { town = ''; }
	if(!county) { county = ''; }
	if(!postcode) { postcode = ''; }	
	if(!business) { business = ''; }	

	document.fix_errors.collection_company.value = company;
	document.fix_errors.collection_address1.value = address1;
	document.fix_errors.collection_address2.value = address2;
	document.fix_errors.collection_address3.value = address3;
	document.fix_errors.collection_town.value = town;
	document.fix_errors.collection_county.value = county;
	document.fix_errors.collection_postcode.value = postcode;

}

function copyDelivery(obj)
{
	
	details = obj.value.split("---");
	
	var company = details[0];
	var address1 = details[1];
	var address2 = details[2];
	var address3 = details[3];
	var town = details[4];
	var county = details[5];
	var postcode = details[6];
	var business = details[7];	
	
	
	if(!company) { company = ''; }
	if(!address1) { address1 = ''; }
	if(!address2) { address2 = ''; }
	if(!address3) { address3 = ''; }
	if(!town) { town = ''; }
	if(!county) { county = ''; }
	if(!postcode) { postcode = ''; }	
	if(!business) { business = ''; }	

	document.getquote.delivery_company.value = company;
	document.getquote.delivery_address1.value = address1;
	document.getquote.delivery_address2.value = address2;
	document.getquote.delivery_address3.value = address3;
	document.getquote.delivery_town.value = town;
	document.getquote.delivery_county.value = county;
	document.getquote.delivery_postcode.value = postcode;
	document.getquote.delivery_business.value = business;	

}

function fixAccountDelivery(obj)
{
	
	details = obj.value.split("---");
	
	var company = details[0];
	var address1 = details[1];
	var address2 = details[2];
	var address3 = details[3];
	var town = details[4];
	var county = details[5];
	var postcode = details[6];
	
	
	if(!company) { company = ''; }
	if(!address1) { address1 = ''; }
	if(!address2) { address2 = ''; }
	if(!address3) { address3 = ''; }
	if(!town) { town = ''; }
	if(!county) { county = ''; }
	if(!postcode) { postcode = ''; }	

	document.fix_errors.delivery_company.value = company;
	document.fix_errors.delivery_address1.value = address1;
	document.fix_errors.delivery_address2.value = address2;
	document.fix_errors.delivery_address3.value = address3;
	document.fix_errors.delivery_town.value = town;
	document.fix_errors.delivery_county.value = county;
	document.fix_errors.delivery_postcode.value = postcode;

}


function copyAccount(obj)
{
	
	details = obj.value.split("---");
	
	var company = details[0];
	var address1 = details[1];
	var address2 = details[2];
	var address3 = details[3];
	var town = details[4];
	var county = details[5];
	var postcode = details[6];
	var business = details[7];	
	
	
	if(!company) { company = ''; }
	if(!address1) { address1 = ''; }
	if(!address2) { address2 = ''; }
	if(!address3) { address3 = ''; }
	if(!town) { town = ''; }
	if(!county) { county = ''; }
	if(!postcode) { postcode = ''; }	
	if(!business) { business = ''; }		

	document.fix_errors.company.value = company;
	document.fix_errors.address1.value = address1;
	document.fix_errors.address2.value = address2;
	document.fix_errors.address3.value = address3;
	document.fix_errors.town.value = town;
	document.fix_errors.county.value = county;
	document.fix_errors.postcode.value = postcode;
	document.fix_errors.is_business.value = business;	

}

function quote()
{


for(i=0; i<document.getquote.elements.length; i++)
{
	if(document.getquote.elements[i].name == 'weight[]' && document.getquote.elements[i].value == '')
	{
		DisplayAlert('AlertBox',200,250);
		return false;
	}
	else if((document.getquote.elements[i].name == 'dim1[]' && document.getquote.elements[i].value == '') || (document.getquote.elements[i].name == 'dim2[]' && document.getquote.elements[i].value == '') || (document.getquote.elements[i].name == 'dim3[]' && document.getquote.elements[i].value == ''))
	{
		DisplayAlert('AlertBox',200,250);
		return false;
	}	
}

return true;

}

function DisplayAlert(id,left,top) {
document.getElementById(id).style.left=left+'px';
document.getElementById(id).style.top=top+'px';
document.getElementById(id).style.display='block';
}


function noPackages(obj)
{

	var url = "/p4d/ajax.php";
	var data = "call=noPackages&qty=" + obj.value;

	http.open("POST", url, true);
	http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    http.send(data);
	http.onreadystatechange = showOutput;

}

function sameday(random)
{

	var url = "/p4d/ajax.php";
	var data = "call=sameday&random=" + random;

	http.open("POST", url, true);
	http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    http.send(data);
	http.onreadystatechange = showOutput;

}

function getCollection()
{

	var postcode = document.forms.getquote.collection_postcode_input.value;

	var url = "/p4d/ajax.php";
	var data = "call=getAddress&postcode=" + postcode;

	http.open("POST", url, true);
	http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    http.send(data);
	http.onreadystatechange = showCollection;

}

function getAccountCollection()
{

	var postcode = document.forms.fix_errors.collection_pcode.value;

	var url = "/p4d/ajax.php";
	var data = "call=getAddress&postcode=" + postcode;

	http.open("POST", url, true);
	http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    http.send(data);
	http.onreadystatechange = showAccountCollection;

}

function getDelivery()
{

	var postcode = document.forms.getquote.delivery_postcode_input.value;

	var url = "/p4d/ajax.php";
	var data = "call=getAddress&postcode=" + postcode;

	http.open("POST", url, true);
	http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    http.send(data);
	http.onreadystatechange = showDelivery;

}

function getAccountDelivery()
{

	var postcode = document.forms.fix_errors.delivery_pcode.value;

	var url = "/p4d/ajax.php";
	var data = "call=getAddress&postcode=" + postcode;

	http.open("POST", url, true);
	http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    http.send(data);
	http.onreadystatechange = showAccountDelivery;

}

function getAccount()
{

	var postcode = document.forms.fix_errors.input.value;

	var url = "/p4d/ajax.php";
	var data = "call=getAddress&postcode=" + postcode;

	http.open("POST", url, true);
	http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    http.send(data);
	http.onreadystatechange = showAccount;

}

function search()
{

var ordernumber = document.search.ordernumber.value;
var itemid = ordernumber;
var carrier = '';
var collect_from = document.search.collect_from.value;
var collect_to = document.search.collect_to.value;
var delivery_name = document.search.delivery_name.value;
var delivery_address = document.search.delivery_address.value;
var delivery_postcode = delivery_address;

	var url = "/p4d/orders.php";
	var data = "search=1&ordernumber=" + ordernumber + "&itemid=" + itemid + "&carrier=" + carrier + "&collect_from=" + collect_from + "&collect_to=" + collect_to + "&delivery_name=" + delivery_name + "&delivery_address=" + delivery_address + "&delivery_postcode=" + delivery_postcode;

	http.open("POST", url, true);
	http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    http.send(data);
	http.onreadystatechange = handleSearchResponse;
	scrollTo(0,0);

}

function show(ordernumber)
{

	var url = "/p4d/show_order.php";
	var data = "ordernumber=" + ordernumber;

	http.open("POST", url, true);
	http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    http.send(data);
	http.onreadystatechange = handleSearchResponse;
	scrollTo(0,0);

}

function reset_search()
{

	var url = "/p4d/orders.php";
	var data = "reset=true";

	http.open("POST", url, true);
	http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    http.send(data);
	http.onreadystatechange = handleSearchResponse;

}

function newAccount(accounttype)
{

	var accounttype = accounttype.value;
	
	var url = "/p4d/my_account.php";
	var data = "action=add&accounttype=" + accounttype;

	http.open("POST", url, true);
	http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    http.send(data);
	http.onreadystatechange = handleResponse;

}

function showOutput() {

  if (http.readyState == 4) {
 
	      results = http.responseText.split("---!---");
		  	  
			document.getElementById(results[0]).innerHTML = results[1];

	}
}

function showCollection() {

  if (http.readyState == 4) {
 
    if (http.responseText.indexOf('invalid') == -1) {
      qresults = http.responseText.split("___");
	  var count = qresults.length;
	  	  
		  var selbox = document.forms.getquote.collection;
     	  selbox.options.length = 0;	   
		  selbox.options[selbox.options.length] = new Option(count + ' Addresses Found - Please Choose','');	
			for (var i=0;i<qresults.length;i++)
			{
		      details = qresults[i].split("+++");
			  selbox.options[selbox.options.length] = new Option(details[0],details[1]);		      
			}

    }

	}
}

function showAccountCollection() {

  if (http.readyState == 4) {
 
    if (http.responseText.indexOf('invalid') == -1) {
      qresults = http.responseText.split("___");
	  var count = qresults.length;
	  	  
		  var selbox = document.forms.fix_errors.collection_postcode_dropdown;
     	  selbox.options.length = 0;	   
		  selbox.options[selbox.options.length] = new Option(count + ' Addresses Found - Please Choose','');	
			for (var i=0;i<qresults.length;i++)
			{
		      details = qresults[i].split("+++");
			  selbox.options[selbox.options.length] = new Option(details[0],details[1]);		      
			}

    }

	}
}


function showDelivery() {

  if (http.readyState == 4) {
 
    if (http.responseText.indexOf('invalid') == -1) {
      qresults = http.responseText.split("___");
	  var count = qresults.length;
	  	  
		  var selbox = document.forms.getquote.delivery;
     	  selbox.options.length = 0;	   
		  selbox.options[selbox.options.length] = new Option(count + ' Addresses Found - Please Choose','');	
			for (var i=0;i<qresults.length;i++)
			{
		      details = qresults[i].split("+++");
			  selbox.options[selbox.options.length] = new Option(details[0],details[1]);		      
			}

    }

	}
}

function showAccountDelivery() {

  if (http.readyState == 4) {
 
    if (http.responseText.indexOf('invalid') == -1) {
      qresults = http.responseText.split("___");
	  var count = qresults.length;
	  	  
		  var selbox = document.forms.fix_errors.delivery_postcode_dropdown;
     	  selbox.options.length = 0;	   
		  selbox.options[selbox.options.length] = new Option(count + ' Addresses Found - Please Choose','');	
			for (var i=0;i<qresults.length;i++)
			{
		      details = qresults[i].split("+++");
			  selbox.options[selbox.options.length] = new Option(details[0],details[1]);		      
			}

    }

	}
}

function showAccount() {

  if (http.readyState == 4) {
 
    if (http.responseText.indexOf('invalid') == -1) {
      qresults = http.responseText.split("___");
	  var count = qresults.length;
	  	  
		  var selbox = document.forms.fix_errors.account;
     	  selbox.options.length = 0;	   
		  selbox.options[selbox.options.length] = new Option(count + ' Addresses Found - Please Choose','');	
			for (var i=0;i<qresults.length;i++)
			{
		      details = qresults[i].split("+++");
			  selbox.options[selbox.options.length] = new Option(details[0],details[1]);		      
			}

    }

	}
}

function copyDown() {

var first_weight = '';
var first_dim1 = '';
var first_dim2 = '';
var first_dim3 = '';

var form = document.forms.getquote;
    for (i = 0; i < form.elements.length; i++) {
    	
    	if(form.elements[i].name == 'weight[]' && !first_weight) {
		var first_weight = form.elements[i].value;
    	}
    	else if(form.elements[i].name == 'dim1[]' && !first_dim1) {
		var first_dim1 = form.elements[i].value;
    	}    	
    	else if(form.elements[i].name == 'dim2[]' && !first_dim2) {
		var first_dim2 = form.elements[i].value;
    	}    	
    	else if(form.elements[i].name == 'dim3[]' && !first_dim3) {
		var first_dim3 = form.elements[i].value;
    	}    	    	    	
		
    }
    
f=document.forms.getquote;
 for(i=0;i<f.elements.length;i++)
  {
  	
  	if(f.elements[i].name=="weight[]") {
       f.elements[i].value = first_weight;
  	}
  	else if(f.elements[i].name=="dim1[]") {
       f.elements[i].value = first_dim1;
  	}
  	else if(f.elements[i].name=="dim2[]") {
       f.elements[i].value = first_dim2;
  	}
  	else if(f.elements[i].name=="dim3[]") {
       f.elements[i].value = first_dim3;
  	}  	  	
  	  	
    }

}