function checkEnterKey(event){
	if (event != null) {
		code = event.keyCode
		if (code == 13) frm_secure_outpostAdminLogin();
	}
}


function listChanged() {
    var form = window.document.ksShop;
	if (form) {
//		form.action.value= 'changed';
//		form.submit();

		var sub_category = form.frm_sub_category.options[form.frm_sub_category.selectedIndex].value;
		new Ajax.Updater("shop", sys_site +"secure/getWeddimngDepartments.php", {
			method: 'post',
			asynchronous: true,
			parameters : { sys_category: "Registries", sys_sub_category: sub_category,sys_order_id: sys_order_id, sys_login_id: sys_login_id },
			onSuccess: function(transport) { },
			onFailure: function(transport, e) { alert(e); },
			onException: function(transport, e) { alert(e); }
		});

	}
}
 
 function windowOpen(page, title, attributes) {
	window.open(page, title, attributes);
 }
 
 function windowClose() {
	window.close();
 }
 
 function Search(_form) {
	var form = window.document[_form]; 
	if (form.frm_search.value != "" || form.frm_date_search.value != "") {
		form.sys_action.value = "search"; 
		form.submit(); } 
	else 
		alert("Please enter a seach term.");
}

 
 function ajaxArchiveWedding(item_id) {
	if (confirm("Are you sure you want to archive this Wedding, it will still exist but just will not show in this list?")) {
		new Ajax.Request(sys_site +"secure/archiveWedding.php", {
			method: 'post',
			asynchronous: true,
			parameters : { sys_item_id: item_id },
			onSuccess: function(transport) { 
				document.location = sys_site + "secure/index/Weddings/Management/Page";
			},
			onFailure: function(transport, e) { alert(e); },
			onException: function(transport, e) { alert(e); }
		});
	}
 }
 
 function ajaxRestoreWedding() {
	var form = window.document.frm_restore_wedding;
	var item_id = form.frm_list_account.options[form.frm_list_account.selectedIndex].value;
 	if (confirm("Are you sure you want to restore this Wedding?")) {
		new Ajax.Request(sys_site +"secure/restoreWedding.php", {
			method: 'post',
			asynchronous: true,
			parameters : { sys_item_id: item_id },
			onSuccess: function(transport) { 
				document.location = sys_site + "secure/index/Weddings/Management/Page";
			},
			onFailure: function(transport, e) { alert(e); },
			onException: function(transport, e) { alert(e); }
		});
	}
}
 
 function ajaxDeleteGroup(sub_category) {
 
	if (confirm("Are you sure you want to delete this Department, as it will delete all products in it as well?")) {
		new Ajax.Request(sys_site +"secure/deleteGroup.php", {
			method: 'post',
			asynchronous: true,
			parameters : { sub_category: sub_category },
			onSuccess: function(transport) { 
				document.location = sys_site + "secure/index/Weddings/Management/Page";
			},
			onFailure: function(transport, e) { alert(e); },
			onException: function(transport, e) { alert(e); }
		});
	}
 }
  
 function ajaxDeleteRegistry(account_id) {
 
	if (confirm("Are you sure you want to delete this Registry?")) {
		new Ajax.Request(sys_site +"secure/deleteRegistry.php", {
			method: 'post',
			asynchronous: true,
			parameters : { item_id: account_id },
			onSuccess: function(transport) { 
				document.location = sys_site + "secure/index/Weddings/Management/Page";
			},
			onFailure: function(transport, e) { alert(e); },
			onException: function(transport, e) { alert(e); }
		});
	}
 }
 
   
 function ajaxDeleteProduct(account_email, category, sub_category, item_id) {
 
	if (confirm("Are you sure you want to delete this Product?")) {
		new Ajax.Request(sys_site +"secure/deleteProduct.php", {
			method: 'post',
			asynchronous: true,
			parameters : { account_email: account_email, item_id: item_id, sys_category: category, sys_sub_category: sub_category },
			onSuccess: function(transport) { 
				xml = transport.responseXML;
				var account_id = xml.getElementsByTagName("id")[0].childNodes[0].nodeValue;
				document.location = sys_site + "secure/index/Weddings/Registries/" + account_id + "/";
			},
			onFailure: function(transport, e) { alert(e); },
			onException: function(transport, e) { alert(e); }
		});
	}
 }
 
 function clearForm() {
	var form = window.document.frm_registry_products;
	form.sys_item_id.value = -1;

	form.frm_brand.value = "";
	form.frm_description.value = "";
	form.frm_price.value = "";
	form.frm_unit.value = "";
	form.frm_quantity.value = "";
	form.frm_sold.value = "";
	form.frm_manual_sold.value = "";
	form.frm_actual_sold.value = "";
	form.frm_styles.value = "";
	form.frm_department_code.value = "";
	form.frm_product_code.value = "";

	for (i=0; i < form.frm_department_group.options.length; i++) form.frm_department_group.selectedIndex = 0;
	for (i=0; i < form.frm_status.length; i++) form.frm_status[i].checked = false;
	for (i=0; i < form.frm_held.length; i++) form.frm_held[i].checked = false;
 }
 
 function calcQty() {
	var form = window.document.frm_registry_products;
	 if (parseInt(form.frm_manual_sold.value) + parseInt(form.frm_actual_sold.value) > parseInt(form.frm_quantity.value)) {
		alert("In-store sales and On-line sales are greater than the limit set by the customer.");
	 }
}
 
 
 function ajaxEditProduct(account_email, category, sub_category, item_id) {
		new Ajax.Request(sys_site +"secure/editProduct.php", {
			method: 'post',
			asynchronous: true,
			parameters : { account_email: account_email, item_id: item_id, sys_category: category, sys_sub_category: sub_category },
			onSuccess: function(transport) { 
				xml = transport.responseXML;
				var form = window.document.frm_registry_products;

				form.sys_item_id.value = xml.getElementsByTagName("id")[0].childNodes[0].nodeValue;
				form.sys_category.value = xml.getElementsByTagName("category")[0].childNodes[0].nodeValue;
				form.sys_sub_category.value = xml.getElementsByTagName("sub_category")[0].childNodes[0].nodeValue;

				form.frm_description.value = unescape(xml.getElementsByTagName("title")[0].childNodes[0].nodeValue);
				form.frm_price.value = xml.getElementsByTagName("price")[0].childNodes[0].nodeValue;
				form.frm_quantity.value = xml.getElementsByTagName("limit")[0].childNodes[0].nodeValue;
				form.frm_sold.value = xml.getElementsByTagName("sold_quantity")[0].childNodes[0].nodeValue;
				form.frm_manual_sold.value = xml.getElementsByTagName("manual_sold_quantity")[0].childNodes[0].nodeValue;
				form.frm_actual_sold.value = xml.getElementsByTagName("actual_sold_quantity")[0].childNodes[0].nodeValue;
				
//				form.frm_sold.value = parseInt(form.frm_manual_sold.value) + parseInt(form.frm_actual_sold.value);
				
				var style = unescape(xml.getElementsByTagName("style")[0].childNodes[0].nodeValue);
				form.frm_styles.value = (style == "&nbsp;" ? "" : style);
				
				var unit = unescape(xml.getElementsByTagName("unit")[0].childNodes[0].nodeValue);
				form.frm_unit.value = (unit == "&nbsp;" ? "" : unit);

				var brand = unescape(xml.getElementsByTagName("frm_brand")[0].childNodes[0].nodeValue);
				form.frm_brand.value = brand;

				var department_code = unescape(xml.getElementsByTagName("frm_department_code")[0].childNodes[0].nodeValue);
				form.frm_department_code.value = (department_code == "&nbsp;" ? "" : department_code);
				
				var product_code = unescape(xml.getElementsByTagName("frm_product_code")[0].childNodes[0].nodeValue);
				form.frm_product_code.value = (product_code == "&nbsp;" ? "" : product_code);

				var soldout = unescape(xml.getElementsByTagName("soldout")[0].childNodes[0].nodeValue);
				var department_group = xml.getElementsByTagName("sub_category")[0].childNodes[0].nodeValue;
				var special = unescape(xml.getElementsByTagName("special")[0].childNodes[0].nodeValue);

				for (i=0; i < form.frm_department_group.options.length; i++) form.frm_department_group.selectedIndex = 0;
				for (i=0; i < form.frm_status.length; i++) form.frm_status[i].checked = false;
				for (i=0; i < form.frm_held.length; i++) form.frm_held[i].checked = false;
				for (i=0; i < form.frm_department_group.options.length; i++) if(form.frm_department_group[i].value == department_group) form.frm_department_group.options[i].selected = true;
				for (i=0; i < form.frm_status.length; i++) if(form.frm_status[i].value == soldout) form.frm_status[i].checked = true;
				for (i=0; i < form.frm_held.length; i++) if(form.frm_held[i].value == special) form.frm_held[i].checked = true;

				self.scrollTo(0,250);

			},
			onFailure: function(transport, e) { alert(e); },
			onException: function(transport, e) { alert(e); }
		});
 }

