var content = "";

function doGetQuote(path, code) {
	
	content = document.getElementById("dialog").innerHTML;
	
	var name = "name="+escape(document.getElementById("name").value);
	var email = "&email="+escape(document.getElementById("email").value);
	var quantity = "&quantity="+escape(document.getElementById("quantity").value);
	var city_country = "&city_country="+escape(document.getElementById("city_country").value);
	var additional = "&additional="+escape(document.getElementById("additional").value);
	
	var index = document.getElementById("shipping_method").selectedIndex;
	
	if(index < 1) {
		$('#dialog').dialog('close');	
		return;
	}
	
	var shipping_method = "&shipping_method="+escape(document.getElementById("shipping_method").options[index].text);
	var path = "&path="+escape(path);
	var product_code = "&product_code="+escape(code);
	
	var params = "?"+name+email+quantity+city_country+shipping_method+additional+product_code+path;
	document.getElementById("dialog").innerHTML = "<img src='gfx/loading.gif'/><br/>Loading...";
	
	$("#dialog").dialog("option", "buttons", {"Close": function() { $("#dialog").dialog("close"); }});
	$("#dialog").load("send_quote_request.php"+params, function(response, status, xhr) {
		
		document.getElementById("dialog").innerHTML = "Thanks for your request. You shall receive a reply within 48 hours.";	
		setTimeout("$('#dialog').dialog('close')", 4000);
		
	});
}

function getQuote(path, code) {
	
	var title = "Get Quote";
		
	if(content != "") {
		document.getElementById("dialog").innerHTML = content;			
	}
	
	document.getElementById("quote_image").innerHTML = "<br/><img src='"+path+"' width='120' height='120' /><br/>Code: "+code+"<br/>";
	
	$("#dialog").dialog("destroy");
	$("#dialog").dialog({
		title: title,
		modal: true,
		draggable: false,
		resizable: false,
		width: 500,
		height: 500,
		buttons: {
			Send: function() {
				doGetQuote(path, code);
			},
			Cancel: function() {
				$(this).dialog("close");
			}			
		}
	});
	
	//document.getElementById("dialog").innerHTML = "Please fill in the following form to receive a quote";
}
