﻿

function getcustomerinfo(objid) {
	var phone = $("#" + objid).val();
	if (phone != "") {
		$.ajax({
			url: "/install/getcustomer.ashx",
			dataType: "json",
			type: "GET",
			data: { pp: phone },
			success: function (JSON) {
				
				if (JSON[0] == true) {
					$("select[name$='ddlStep2CustomerType']").val(JSON[1].type);

					if (JSON[1].type == "1") {
						$("tr.customertype.typeid1").show();
						$("tr.customertype.typeid2").hide();
						$("tr.customertype.typeid3").hide();
						$("input[name$='txtStep2CustomerName']").val(JSON[1].name);
					}
					else if (JSON[1].type == "2") {
						$("tr.customertype.typeid1").hide();
						$("tr.customertype.typeid2").show();
						$("tr.customertype.typeid3").hide();
						$("input[name$='txtStep2CVRNumber']").val(JSON[1].cvr);
						$("input[name$='txtStep2CompanyName']").val(JSON[1].companyname);
					}
					else if (JSON[1].type == "3") {
						$("tr.customertype.typeid1").hide();
						$("tr.customertype.typeid2").hide();
						$("tr.customertype.typeid3").show();
						$("input[name$='txtStep2EANnumber']").val(JSON[1].EAN);
						$("input[name$='txtStep2PublicName']").val(JSON[1].companyname);
					}



					$("input[name$='txtStep2CustomerAtt']").val(JSON[1].att);
					$("input[name$='txtStep2CustomerAddress']").val(JSON[1].address);
					$("input[name$='txtStep2CustomerAddress2']").val(JSON[1].address2);
					$("input[name$='txtStep2CustomerZip']").val(JSON[1].zip);
					$("input[name$='txtStep2CustomerCity']").val(JSON[1].city);
					$("select[name$='ddlStep2CustomerCountry']").val(JSON[1].countryid);
					$("input[name$='txtStep2CustomerEmail']").val(JSON[1].email);
					$("input[name$='txtStep2CustomerPhone']").val(JSON[1].phone);

				}
				else {
					alert("Dit telefonnummer blev ikke fundet");
				}
			},
			error: function (s) { alert("error: " + s) }
		});
	}
	else{
		alert("Du skal indtaste et telefonnummer");
	}
}
