/**
 * modul_ecom.tools.js - created on Aug 24, 2011 9:13:25 PM by thomi
 * @copyright		win-soft.ch 2011
 * @author			Thomas Winteler <http://www.win-soft.ch>
 */

/**
 * *************************************************
 * Modul eCom: Global Settings
 * *************************************************
 */


function showModulEcomSettingsDialog(mode)
{
	checkLoginData();
	
	$('#DIV_admin_panel_menu').toggle("fast");
	
	if(mode === undefined) { mode = "list_ecom_modul_settings";}
	
	$.get("admin/modul_ecom_management.php?mode="+mode, function(data) {
		$(function(){
			$("#DIV_SM_modul_settings_dialog").html(data);
			var system_management_modul_settings_dialog_buttons = {};
			system_management_modul_settings_dialog_buttons[adminLanguage["System_Management_Modul_Close"]] = function() {
				$(this).dialog("close");
			};
			system_management_modul_settings_dialog_buttons[adminLanguage["System_Management_Modul_Add_Setting"]] = function() {
				showModulEcomManageSettingDialog('edit_ecom_setting');
			};
			$("#DIV_SM_modul_settings_dialog").dialog({
				title: adminLanguage["System_Management_Modul_Scheme_Settings"],
				bgiframe: true,
				height: 600,
				width: 800,
				modal: true,
				resizable: false,
				draggable: false,
				closeOnEscape: false,
				buttons: system_management_modul_settings_dialog_buttons,
				open: function() {
	                $('.ui-dialog-buttonpane').find('button:contains("'+adminLanguage["System_Management_Modul_Close"]+'")').button({
	                    icons: {
	                        primary: 'ui-icon-circle-close'
	                    }
	                });
	                $('.ui-dialog-buttonpane').find('button:contains("'+adminLanguage["System_Management_Modul_Add_Setting"]+'")').button({
	                    icons: {
	                        primary: 'ui-icon-circle-plus'
	                    }
	                });
				}
			});
		});
	});	
	
}


function systemManagementSearchModulEcomSettings()
{
	checkLoginData();

	$.get("admin/modul_ecom_management.php?mode=search_ecom_modul_settings&keyword="+$("#TEXT_SM_modul_settings_search").val(), function(data) {
//		console.log(data);
		$("#DIV_modul_settings_list_search").html(data);
	});
}


function showModulEcomManageSettingDialog(mode, ID, settingID)
{
	checkLoginData();

//	console.log(mode+" | "+ID+" | "+settingID);
	
	if(mode === undefined) { mode = "edit_ecom_setting";}
	if(ID === undefined) { ID = "";}
	if(settingID === undefined) { settingID = "";}
	$.get("admin/modul_ecom_management.php?mode="+mode+"&ID="+ID+"&settingID="+settingID, function(data) {
		$(function(){
			$("#DIV_SM_add_modul_setting_dialog").html(data);
			var system_management_add_modul_setting_dialog_buttons = {};
			system_management_add_modul_setting_dialog_buttons[adminLanguage["System_Management_Modul_Close"]] = function() {
				$(this).dialog("close");
			};
			$("#DIV_SM_add_modul_setting_dialog").dialog({
				title: adminLanguage["System_Management_Modul_Edit"],
				height: 600,
				width: 800,
				modal: false,
				resizable: false,
				draggable: false,
				buttons: system_management_add_modul_setting_dialog_buttons,
				open: function() {
	                $('.ui-dialog-buttonpane').find('button:contains("'+adminLanguage["System_Management_Modul_Close"]+'")').button({
	                    icons: {
	                        primary: 'ui-icon-circle-close'
	                    }
	                });
	                if(mode == "edit_ecom_setting_payment_method")
	                {
	                	loadTinyMceEditor('TEXTAREA_SM_modul_ecom_setting_payment_method_data', 'content', 0, "100");
	                }
				}
			});
		});
	});
}


function modulManagementSaveModulEcomSettings(mode, settingID)
{
	checkLoginData();

	if(settingID === undefined) { settingID = ""; }
	
	$(document).ready(function() {
			setTimeout(function() {  
        		$("input[type='text']:enabled:first").focus();
        	}, 500);

			jQuery.validator.messages.required = "";
			jQuery.validator.messages.email = "";
			jQuery.validator.messages.select = "";
			var validator = $("#FORM_SM_modul_ecom_settings").validate({
        		invalidHandler: function() {
    			var errors = validator.numberOfInvalids();
	    			if (errors) {
	    				var message = errors == 1
	    					? adminLanguage["Admin_General_Required_Fields"]
	    					: adminLanguage["Admin_General_Required_Fields"];
	    				$("#DIV_SM_modul_save_message").html("<img src=\"http://"+window.location.hostname+"/admin/img/16_exclamation.png\" style=\"margin-right: 10px;\">"+message);
	    				$("#DIV_SM_modul_save_message").show();
	    			} else {
	    				$("#DIV_SM_modul_save_message").css("display", "none");
	    			}
    			}

        	});
        	
        	var options = {
        		success: function(data) {
        			systemManagementProcessModulEcomSettings(data, mode, settingID);
        		}
//        		success: systemManagementProcessModulEcomSettings
        	};

            $("#FORM_SM_modul_ecom_settings").ajaxForm(options);

	});
}


function systemManagementProcessModulEcomSettings(data, mode, settingID)
{
	checkLoginData();

//	console.log(data+" "+mode);
	if(mode == "edit_ecom_setting")
	{
		systemManagementSearchModulEcomSettings();
	}
	$("#DIV_SM_modul_save_message").css("display", "block");
	$("#DIV_SM_modul_save_message").html("<img src=\"http://"+window.location.hostname+"/admin/img/16_success.png\" style=\"margin-right: 10px;\">"+adminLanguage["System_Management_Modul_Save_Success"]);
	$("#DIV_SM_button_global_save").css("display", "none");
	$("#DIV_SM_modul_save_message").fadeOut(4000);
	setTimeout(function() {  
		if(data)
		{
			if(mode == "edit_ecom_setting_delivery_cost" || mode == "edit_ecom_setting_delivery_method" || mode == "edit_ecom_setting_currency" || mode == "edit_ecom_setting_payment_method")
			{
				$("#DIV_modul_settings_tab_"+settingID).tabs("load", $("#DIV_modul_settings_tab_"+settingID).tabs("option", "selected"));
//				$("#DIV_modul_settings_tab_"+settingID).tabs("option", "selected");
				$("#DIV_SM_add_modul_setting_dialog").dialog("close");
			}
			else
			{
				showModulEcomManageSettingDialog(mode, data);
			}
		}
		else
		{
			if(mode == "edit_ecom_setting_delivery_cost" || mode == "edit_ecom_setting_delivery_method" || mode == "edit_ecom_setting_currency" || mode == "edit_ecom_setting_payment_method")
			{
				$("#DIV_modul_settings_tab_"+settingID).tabs("load", $("#DIV_modul_settings_tab_"+settingID).tabs("option", "selected"));
			}

			$("#DIV_SM_button_global_save").css("display", "block");
		}
	}, 4000);
}



function removeModulEcomSetting(mode, ID, item, settingID)
{
	if(mode === undefined) { mode = "";}
	if(item === undefined) { item = "";}
	if(ID === undefined) { ID = "";}
	if(settingID === undefined) { settingID = "";}
	
	checkLoginData();
	
	if(mode && item && ID && settingID && confirm(adminLanguage["System_Management_Modul_Ecom_Setting_Remove"]+"\n"+item))
	{
		var dataEcomItemRemove = $.ajax({
			url: "admin/modul_ecom_management.php?mode="+mode+"&ID="+ID+"&settingID="+settingID+"&remove=1",
			async: false
		});
		
		
		if(dataEcomItemRemove.responseText.length > 1)
		{
			$("#DIV_SM_modul_status_message").html("<img src=\"http://"+window.location.hostname+"/admin/img/16_failed.png\" style=\"margin-right: 10px;\">"+adminLanguage["System_Management_Modul_Ecom_Setting_Remove_Error"]+" - "+dataEcomItemRemove.responseText);
		}
		else
		{
			$("#DIV_SM_modul_status_message").html("<img src=\"http://"+window.location.hostname+"/admin/img/16_success.png\" style=\"margin-right: 10px;\">"+adminLanguage["System_Management_Modul_Ecom_Setting_Remove_Success"]);
			$("#DIV_modul_settings_tab_"+settingID).tabs("load", $("#DIV_modul_settings_tab_"+settingID).tabs("option", "selected"));

			$("#DIV_SM_modul_status_message").fadeOut(4000, function() {
				$("#DIV_SM_modul_status_message").html("");
				$("#DIV_SM_modul_status_message").css("display", "block");
			});
			
		}
		
	}	
	
}

/**
 * 
 * eCom Delivery Cost Countries
 * 
 */

function showModulEcomManageSettingCountryDialog(mode, deliveryCostID, settingID)
{
	checkLoginData();
	
	if(mode === undefined) { mode = "edit_ecom_setting_delivery_cost_country";}

	if($("#DIV_SM_modul_setting_dialog_option").html())
	{
		$.get("admin/modul_ecom_management.php?mode="+mode+"&deliveryCostID="+deliveryCostID+"&settingID="+settingID, function(data) {
			$("#DIV_SM_modul_setting_dialog_option").html(data);
		});
	}
	else
	{
		$.get("admin/modul_ecom_management.php?mode="+mode+"&deliveryCostID="+deliveryCostID+"&settingID="+settingID, function(data) {
			$(function(){
				$("#DIV_SM_modul_setting_dialog_option").html(data);
				var system_management_modul_settings_dialog_countries_buttons = {};
				system_management_modul_settings_dialog_countries_buttons[adminLanguage["System_Management_Modul_Close"]] = function() {
					$(this).dialog("close");
				};
				$("#DIV_SM_modul_setting_dialog_option").dialog({
					title: adminLanguage["System_Management_Modul_Edit"],
					bgiframe: true,
					height: 400,
					width: 500,
					modal: true,
					resizable: false,
					draggable: false,
					closeOnEscape: true,
					buttons: system_management_modul_settings_dialog_countries_buttons,
					open: function() {
						$("#DIV_SM_add_modul_setting_dialog").dialog("option", "closeOnEscape", false);
		                $('.ui-dialog-buttonpane').find('button:contains("'+adminLanguage["System_Management_Modul_Close"]+'")').button({
		                    icons: {
		                        primary: 'ui-icon-circle-close'
		                    }
		                });
					},
					beforeClose: function() {
						$("#DIV_SM_add_modul_setting_dialog").dialog("option", "closeOnEscape", true);
						$("#DIV_SM_modul_setting_dialog_option").html("");
					}
				});
			});
		});
	}
	
	
}


function modulEcomSaveDeliveryCostCountries(deliveryCostID, settingID)
{
	checkLoginData();

	if(deliveryCostID === undefined) { deliveryCostID = ""; }
	
	$(document).ready(function() {
//			setTimeout(function() {  
//        		$("input[type='text']:enabled:first").focus();
//        	}, 500);

			jQuery.validator.messages.required = "";
			jQuery.validator.messages.email = "";
			jQuery.validator.messages.select = "";
			jQuery.validator.messages.number = "";
			var validator = $("#FORM_SM_ecom_delivery_cost_countries").validate({
        		invalidHandler: function() {
    			var errors = validator.numberOfInvalids();
	    			if (errors) {
	    				var message = errors == 1
	    					? adminLanguage["Admin_General_Required_Fields"]
	    					: adminLanguage["Admin_General_Required_Fields"];
	    				$("#DIV_SM_country_save_message").html("<img src=\"http://"+window.location.hostname+"/admin/img/16_exclamation.png\" style=\"margin-right: 10px;\">"+message);
	    				$("#DIV_SM_country_save_message").show();
	    			} else {
	    				$("#DIV_SM_country_save_message").css("display", "none");
	    			}
    			}

        	});
        	
        	var options = {
        		success: function(data) {
        			modulEcomProcessDeliveryCostCountries(data, deliveryCostID, settingID);
        		}
        	};

            $("#FORM_SM_ecom_delivery_cost_countries").ajaxForm(options);

	});
}


function modulEcomProcessDeliveryCostCountries(data, deliveryCostID, settingID)
{
	checkLoginData();

	$("#DIV_SM_country_save_message").css("display", "block");
	$("#DIV_SM_country_save_message").html("<img src=\"http://"+window.location.hostname+"/admin/img/16_success.png\" style=\"margin-right: 10px;\">"+adminLanguage["System_Management_Modul_Save_Success"]);
	$("#BUTTON_SM_country_global_save").css("display", "none");
	$("#DIV_SM_country_save_message").fadeOut(1000);
	setTimeout(function() {  
		showModulEcomManageSettingCountryDialog("edit_ecom_setting_delivery_cost_country", deliveryCostID, settingID);
	}, 1000);
	
}


function modulEcomRemoveDeliveryCostCountry(deliveryCostID, deliveryCostCountryIDXID, countryName, settingID)
{
	if(deliveryCostCountryIDXID && confirm(adminLanguage["System_Management_Modul_Ecom_Delivery_Cost_Country_Remove"]+"\n"+countryName))
	{
		var dataRemoveDeliveryCostCountry = $.ajax({
			url: "admin/modul_ecom_management.php?mode=remove_ecom_setting_delivery_cost_country&deliveryCostID="+deliveryCostID+"&deliveryCostCountryIDXID="+deliveryCostCountryIDXID,
			async: false
		});
		
		if(dataRemoveDeliveryCostCountry.responseText.search(/success/) != -1)
		{
			$("#DIV_SM_country_save_message").css("display", "block");
			$("#DIV_SM_country_save_message").html("<img src=\"http://"+window.location.hostname+"/admin/img/16_success.png\" style=\"margin-right: 10px;\">"+adminLanguage["System_Management_Modul_Ecom_Delivery_Cost_Country_Remove_Success"]);
			$("#DIV_SM_country_save_message").fadeOut(1000);
			setTimeout(function() {  
				showModulEcomManageSettingCountryDialog("edit_ecom_setting_delivery_cost_country", deliveryCostID, settingID);
			}, 1000);
		}
		
	}
	
	
}

/**
 * *************************************************
 * Modul eCom: Product Settings
 * *************************************************
 */

/**
 * Product Price
 */

function showModulEcomProductPriceDialog(mode, productID)
{
	checkLoginData();
	
	if(mode === undefined) { mode = "edit_modul_ecom_product_price";}

	if($("#DIV_SM_modul_settings_dialog").html())
	{
		$.get("admin/modul_ecom_management.php?mode="+mode+"&productID="+productID, function(data) {
			$("#DIV_SM_modul_settings_dialog").html(data);
		});
	}
	else
	{
		$.get("admin/modul_ecom_management.php?mode="+mode+"&productID="+productID, function(data) {
			$(function(){
				$("#DIV_SM_modul_settings_dialog").html(data);
				var modul_ecom_product_price_dialog_buttons = {};
				modul_ecom_product_price_dialog_buttons[adminLanguage["System_Management_Modul_Close"]] = function() {
					$(this).dialog("close");
				};
				$("#DIV_SM_modul_settings_dialog").dialog({
					title: adminLanguage["Modul_Ecom_Product_Price_Settings"],
					bgiframe: true,
					height: 400,
					width: 500,
					modal: true,
					resizable: false,
					draggable: false,
					closeOnEscape: false,
					buttons: modul_ecom_product_price_dialog_buttons,
					open: function() {
						$("#DIV_modul_management_modul_dialog").dialog("option", "closeOnEscape", false);
		                $('.ui-dialog-buttonpane').find('button:contains("'+adminLanguage["System_Management_Modul_Close"]+'")').button({
		                    icons: {
		                        primary: 'ui-icon-circle-close'
		                    }
		                });
					},
					beforeClose: function() {
						$("#DIV_modul_management_modul_dialog").dialog("option", "closeOnEscape", true);
						$("#DIV_content_tab").tabs("load", $("#DIV_content_tab").tabs("option", "selected"));
						$("#DIV_SM_modul_settings_dialog").html("");
					}
				});
			});
		});
	}
	
	
}


function modulEcomSaveProductPriceSettings(productID)
{
	checkLoginData();

	if(productID === undefined) { productID = ""; }
	
	$(document).ready(function() {
			setTimeout(function() {  
        		$("input[type='text']:enabled:first").focus();
        	}, 500);

			jQuery.validator.messages.required = "";
			jQuery.validator.messages.email = "";
			jQuery.validator.messages.select = "";
			jQuery.validator.messages.number = "";
			var validator = $("#FORM_MM_ecom_price_settings").validate({
        		invalidHandler: function() {
    			var errors = validator.numberOfInvalids();
	    			if (errors) {
	    				var message = errors == 1
	    					? adminLanguage["Admin_General_Required_Fields"]
	    					: adminLanguage["Admin_General_Required_Fields"];
	    				$("#DIV_MM_product_price_save_message").html("<img src=\"http://"+window.location.hostname+"/admin/img/16_exclamation.png\" style=\"margin-right: 10px;\">"+message);
	    				$("#DIV_MM_product_price_save_message").show();
	    			} else {
	    				$("#DIV_MM_product_price_save_message").css("display", "none");
	    			}
    			}

        	});
        	
        	var options = {
        		success: function(data) {
        			modulEcomProcessProductPriceSettings(data, productID);
        		}
        	};

            $("#FORM_MM_ecom_price_settings").ajaxForm(options);

	});
}


function modulEcomProcessProductPriceSettings(data, productID)
{
	checkLoginData();

	$("#DIV_MM_product_price_save_message").css("display", "block");
	$("#DIV_MM_product_price_save_message").html("<img src=\"http://"+window.location.hostname+"/admin/img/16_success.png\" style=\"margin-right: 10px;\">"+adminLanguage["System_Management_Modul_Save_Success"]);
	$("#BUTTON_MM_product_price_global_save").css("display", "none");
	$("#DIV_MM_product_price_save_message").fadeOut(4000);
	setTimeout(function() {  
		showModulEcomProductPriceDialog("edit_modul_ecom_product_price", productID);
	}, 4000);
	
}

function modulEcomEditProductPrices(productID, productCurrencyIDXID)
{
	$("#TEXT_MM_ecom_product_price_retail_"+productCurrencyIDXID).removeAttr("readonly");
	$("#TEXT_MM_ecom_product_price_cost_"+productCurrencyIDXID).removeAttr("readonly");
	$("#TEXT_MM_ecom_product_price_list_"+productCurrencyIDXID).removeAttr("readonly");
	$("#DIV_MM_ecom_edit_prices_"+productCurrencyIDXID).html("<a href='javascript:void(0)' onclick='modulEcomSaveProductPrices("+productID+", "+productCurrencyIDXID+");'><img type=\"submit\" src=\"http://"+window.location.hostname+"/admin/img/16_save.png\" style=\"margin-right: 0px;\" title=\""+adminLanguage["Modul_Ecom_Product_Price_Settings_Save"]+"\"></a>");
}

function modulEcomSaveProductPrices(productID, productCurrencyIDXID)
{
	
	var dataProductPrice = $.ajax({
		url: "admin/modul_ecom_management.php?mode=save_modul_ecom_product_price&productID="+productID+"&productCurrencyIDXID="+productCurrencyIDXID+"&productRetailPrice="+$("#TEXT_MM_ecom_product_price_retail_"+productCurrencyIDXID).val()+"&productCostPrice="+$("#TEXT_MM_ecom_product_price_cost_"+productCurrencyIDXID).val()+"&productListPrice="+$("#TEXT_MM_ecom_product_price_list_"+productCurrencyIDXID).val(),
		async: false
	});
	
	
	if(dataProductPrice.responseText.search(/success/) != -1)
	{
		$("#DIV_MM_product_price_save_message").css("display", "block");
		$("#DIV_MM_product_price_save_message").html("<img src=\"http://"+window.location.hostname+"/admin/img/16_success.png\" style=\"margin-right: 10px;\">"+adminLanguage["System_Management_Modul_Save_Success"]);
		$("#DIV_MM_product_price_save_message").fadeOut(4000);
		setTimeout(function() {  
			showModulEcomProductPriceDialog("edit_modul_ecom_product_price", productID);
		}, 4000);
		$("#DIV_MM_ecom_edit_prices_"+productCurrencyIDXID).html("<a href='javascript:void(0)' onclick='modulEcomEditProductPrices("+productID+", "+productCurrencyIDXID+");'><img src=\"http://"+window.location.hostname+"/admin/img/16_edit.png\" style=\"margin-right: 0px;\" title=\""+adminLanguage["Modul_Ecom_Product_Price_Settings_Edit"]+"\"></a>");
		$("#TEXT_MM_ecom_product_price_retail_"+productCurrencyIDXID).attr("readonly", "readonly");
		$("#TEXT_MM_ecom_product_price_cost_"+productCurrencyIDXID).attr("readonly", "readonly");
		$("#TEXT_MM_ecom_product_price_list_"+productCurrencyIDXID).attr("readonly", "readonly");
	}
	else
	{
		$("#DIV_MM_product_price_save_message").css("display", "block");
		$("#DIV_MM_product_price_save_message").html("<img src=\"http://"+window.location.hostname+"/admin/img/16_failed.png\" style=\"margin-right: 10px;\">"+adminLanguage["Admin_General_Control_Fields"]);
	}
	
	
}

function modulEcomRemoveProductPrices(productID, productCurrencyIDXID, currency)
{
	if(productCurrencyIDXID && confirm(adminLanguage["Modul_Ecom_Product_Price_Settings_Remove"]+"\n"+adminLanguage["Modul_Ecom_Product_Price_Settings_Currency"]+": "+currency))
	{
		var dataRemoveProductPrice = $.ajax({
			url: "admin/modul_ecom_management.php?mode=remove_modul_ecom_product_price&productID="+productID+"&productCurrencyIDXID="+productCurrencyIDXID,
			async: false
		});
		
		if(dataRemoveProductPrice.responseText.search(/success/) != -1)
		{
			$("#DIV_MM_product_price_save_message").css("display", "block");
			$("#DIV_MM_product_price_save_message").html("<img src=\"http://"+window.location.hostname+"/admin/img/16_success.png\" style=\"margin-right: 10px;\">"+adminLanguage["Modul_Ecom_Product_Price_Settings_Remove_Success"]);
			$("#DIV_MM_product_price_save_message").fadeOut(4000);
			setTimeout(function() {  
				showModulEcomProductPriceDialog("edit_modul_ecom_product_price", productID);
			}, 4000);
		}
		
	}
	
	
}

/**
 * Product Files
 */

function showModulEcomProductFilesDialog(mode, productID)
{
	checkLoginData();
	
	if(mode === undefined) { mode = "edit_modul_ecom_product_files";}

	if($("#DIV_SM_modul_settings_dialog").html())
	{
		$.get("admin/modul_ecom_management.php?mode="+mode+"&productID="+productID, function(data) {
			$("#DIV_SM_modul_settings_dialog").html(data);
		});
	}
	else
	{
		$.get("admin/modul_ecom_management.php?mode="+mode+"&productID="+productID, function(data) {
			$(function(){
				$("#DIV_SM_modul_settings_dialog").html(data);
				var modul_ecom_product_price_dialog_buttons = {};
				modul_ecom_product_price_dialog_buttons[adminLanguage["System_Management_Modul_Close"]] = function() {
					$(this).dialog("close");
				};
				$("#DIV_SM_modul_settings_dialog").dialog({
					title: adminLanguage["Modul_Ecom_Product_Files_Help"],
					bgiframe: true,
					height: 600,
					width: 750,
					modal: true,
					resizable: false,
					draggable: false,
					closeOnEscape: false,
					buttons: modul_ecom_product_price_dialog_buttons,
					open: function() {
						$("#DIV_modul_management_modul_dialog").dialog("option", "closeOnEscape", false);
		                $('.ui-dialog-buttonpane').find('button:contains("'+adminLanguage["System_Management_Modul_Close"]+'")').button({
		                    icons: {
		                        primary: 'ui-icon-circle-close'
		                    }
		                });
					},
					beforeClose: function() {
						$("#DIV_modul_management_modul_dialog").dialog("option", "closeOnEscape", true);
						$("#DIV_content_tab").tabs("load", $("#DIV_content_tab").tabs("option", "selected"));
						$("#DIV_SM_modul_settings_dialog").html("");
					}
				});
			});
		});
	}
}

function updateModulEcomProductFiles(mode, productID)
{
	checkLoginData();

	if(mode === undefined) { mode = "update_modul_ecom_product_files";}
	
	var dataUpdateProductFiles = $.ajax({
		url: "admin/modul_ecom_management.php?mode="+mode+"&productID="+productID,
		async: false
	});

//	$("#DIV_MM_save_message").html(dataUpdateProductFiles.responseText);
//	$("#DIV_MM_save_message").show();
	$("#DIV_MM_save_message").css("display", "block");
	
	if(dataUpdateProductFiles.responseText.search(/success/) != -1)
	{
		$("#DIV_MM_save_message").html("<img src=\"http://"+window.location.hostname+"/admin/img/16_success.png\" style=\"margin-right: 10px;\">"+adminLanguage["Modul_Ecom_Product_Files_Update_Success"]);
		$("#DIV_MM_save_message").fadeOut(4000);
		setTimeout(function() {  
			$("#DIV_content_tab").tabs("load", $("#DIV_content_tab").tabs("option", "selected"));
		}, 4000);
	}
	else
	{
		$("#DIV_MM_save_message").html("<img src=\"http://"+window.location.hostname+"/admin/img/16_exclamation.png\" style=\"margin-right: 10px;\"><b>"+adminLanguage["Modul_Ecom_Product_Files_Update_Warning"]+"</b>");
		setTimeout(function() {  
			$("#DIV_MM_save_message").css("display", "none");
		}, 4000);
		
	}

	

}

function removeModulEcomProductFiles(mode, productID, productNumber)
{
	checkLoginData();

	if(mode === undefined) { mode = "remove_modul_ecom_product_files";}
	
	if(confirm(adminLanguage["Modul_Ecom_Product_Files_Remove"]+"\n"+productNumber))
	{
		var dataRemoveProductFiles = $.ajax({
			url: "admin/modul_ecom_management.php?mode="+mode+"&productID="+productID,
			async: false
		});

		if(dataRemoveProductFiles.responseText.search(/success/) != -1)
		{
			$("#DIV_MM_save_message").css("display", "block");
			$("#DIV_MM_save_message").html("<img src=\"http://"+window.location.hostname+"/admin/img/16_success.png\" style=\"margin-right: 10px;\">"+adminLanguage["Modul_Ecom_Product_Files_Remove_Success"]);
			$("#DIV_MM_save_message").fadeOut(4000);
			setTimeout(function() {  
				$("#DIV_content_tab").tabs("load", $("#DIV_content_tab").tabs("option", "selected"));
			}, 4000);
		}	
		
		
		
	}
	
}


function showModulEcomProductDetails(contentID, languageID, productID)
{

	$.get("system/modules/ecom/modul_ecom.php?mode=show_product_details&contentID="+contentID+"&languageID="+languageID+"&productID="+productID, function(data) {
		$(function(){
			$("#DIV_ecom_product_details_"+productID).html(data);
			var modul_ecom_product_details_buttons = {};
			modul_ecom_product_details_buttons[webLanguage["General_Close"]] = function() {
				$(this).dialog("close");
			};
			$("#DIV_ecom_product_details_"+productID).dialog({
				title: webLanguage["Modul_Ecom_Product_Details"],
				dialogClass: 'custom',
				bgiframe: true,
				height: getHeight()-10,
				width: modul_ecom_product_details_table_width+50,
				modal: true,
				resizable: false,
				draggable: false,
				closeOnEscape: true,
				buttons: modul_ecom_product_details_buttons,
				open: function() {
	                $('.ui-dialog-buttonpane').find('button:contains("'+webLanguage["General_Close"]+'")').button({
	                    icons: {
	                        primary: 'ui-icon-circle-close'
	                    }
	                });
				},
				beforeClose: function() {
					$("#DIV_ecom_product_details_"+productID).html("");
				}
			});
		});
	});
	
	
}



/**
 * Product order
 */

var basketSliderOptions = {
		disabled: true,
		value: 1,
		min: 1,
		max: 4,
		step: 1
};

var formError = true;

$(document).ready(function() {
	POgetBasketContent();
});

function POgetBasketContent()
{
	var dataPOgetBasketContent = $.ajax({
		url: "system/modules/ecom/modul_ecom.php?mode=po_get_basket_content",
		async: false
	});

	$("#"+ecomBasketDIV).html(dataPOgetBasketContent.responseText);
	
}

function POaddToBasket(productID, productNumber)
{
	if(confirm(webLanguage["Modul_Ecom_Product_Order_Add_To_Basket"]+"\n"+productNumber))
	{
		var dataPOaddToBasket = $.ajax({
			url: "system/modules/ecom/modul_ecom.php?mode=po_add_to_basket&productID="+productID,
			async: false
		});
		
		if(dataPOaddToBasket.responseText)
		{
			alert(webLanguage["Modul_Ecom_Basket_Order_Step_1_Max_Product_Qty"]+" "+dataPOaddToBasket.responseText);
		}
		
		
		POgetBasketContent();
	}
}

function POshowBasket(orderID, orderNumber, orderStep)
{
//    console.log("orderStep: "+orderStep);

	var dataPObasketContent = $.ajax({
		url: "system/modules/ecom/modul_ecom_basket.php?orderStep="+orderStep+"&orderID="+orderID,
		async: false
	});
	
	$("#DIV_ecom_basket_details").html(dataPObasketContent.responseText);
	
	$("#DIV_ecom_basket_slider").css("width", modul_ecom_basket_product_table_width);
	$("#DIV_ecom_basket_slider").slider(basketSliderOptions);
	$("#DIV_ecom_basket_slider_pane").css("width", modul_ecom_basket_product_table_width);
	$("#DIV_ecom_basket_slider_label").html(webLanguage["Modul_Ecom_Basket_Order_Step_"+orderStep]);
	var modul_ecom_basket_details_buttons = {};
	modul_ecom_basket_details_buttons[webLanguage["Modul_Ecom_Basket_Back"]] = function() {

//        console.log("back start: "+orderStep);
		
		orderStep--;
		var dataPObasketContent = $.ajax({
			url: "system/modules/ecom/modul_ecom_basket.php?orderStep="+orderStep+"&orderID="+orderID,
			async: false
		});	
		$("#DIV_ecom_basket_details").html(dataPObasketContent.responseText);
		if(orderStep == 1)
		{
			$('.ui-dialog-buttonpane').find('button:contains("'+webLanguage["Modul_Ecom_Basket_Back"]+'")').hide();
			$('.ui-dialog-buttonpane').find('button:contains("'+webLanguage["Modul_Ecom_Basket_Next"]+'")').show();
		}
		
		if(orderStep < 4)
		{
			$('.ui-dialog-buttonpane').find('button:contains("'+webLanguage["Modul_Ecom_Basket_Next"]+'")').show();
		}

		$("#DIV_ecom_basket_slider").css("width", modul_ecom_basket_product_table_width);
		$("#DIV_ecom_basket_slider").slider(basketSliderOptions);
		$("#DIV_ecom_basket_slider_pane").css("width", modul_ecom_basket_product_table_width);
		$("#DIV_ecom_basket_slider_label").html(webLanguage["Modul_Ecom_Basket_Order_Step_"+orderStep]);
		$("#DIV_ecom_basket_slider").slider("option", "value", orderStep);

//        console.log("back end: "+orderStep);

	};
	modul_ecom_basket_details_buttons[webLanguage["Modul_Ecom_Basket_Next"]] = function() {
        $('.ui-dialog-buttonpane').find('button:contains("'+webLanguage["Modul_Ecom_Basket_Back"]+'")').show();
        
//        console.log("next: "+orderStep);
        
		if(orderStep == 2)
		{
//			console.log("here...");
			POsaveCustomerInformation(orderID, orderStep);
			$("#FORM_modul_ecom_basket_customer").submit();
//			console.log("formError: "+formError);
			if(formError == false)
			{
				orderStep++;
			}
		}
		else
		{
			if(orderStep == 4)
			{
				POsaveCustomerOrder(orderID, orderStep);
				$("#FORM_modul_ecom_basket_basket_accept").submit();
			}
			else
			{
				orderStep++;
				var dataPObasketContent = $.ajax({
					url: "system/modules/ecom/modul_ecom_basket.php?orderStep="+orderStep+"&orderID="+orderID,
					async: false
				});
				if(dataPObasketContent.responseText.search(/order_end/) != -1)
				{
					orderStep--;
					 $('.ui-dialog-buttonpane').find('button:contains("'+webLanguage["Modul_Ecom_Basket_Next"]+'")').hide();
				}
				else
				{
					$("#DIV_ecom_basket_details").html(dataPObasketContent.responseText);
				}

				$("#DIV_ecom_basket_slider").css("width", modul_ecom_basket_product_table_width);
				$("#DIV_ecom_basket_slider").slider(basketSliderOptions);
				$("#DIV_ecom_basket_slider_pane").css("width", modul_ecom_basket_product_table_width);
				$("#DIV_ecom_basket_slider_label").html(webLanguage["Modul_Ecom_Basket_Order_Step_"+orderStep]);
				$("#DIV_ecom_basket_slider").slider("option", "value", orderStep);
			}
		}

//        console.log("next end: "+orderStep);

	};
	modul_ecom_basket_details_buttons[webLanguage["General_Close"]] = function() {
		$(this).dialog("close");
	};
	$("#DIV_ecom_basket_details").dialog({
		title: webLanguage["Modul_Ecom_Basket_Details"]+" "+orderNumber,
		dialogClass: 'custom',
		bgiframe: true,
		height: getHeight()-10,
		width: modul_ecom_basket_product_table_width+65,
		modal: true,
		resizable: false,
		draggable: false,
		closeOnEscape: true,
		buttons: modul_ecom_basket_details_buttons,
		open: function() {
            $('.ui-dialog-buttonpane').find('button:contains("'+webLanguage["Modul_Ecom_Basket_Back"]+'")').button({
                icons: {
                    primary: 'ui-icon-circle-triangle-w'
                }
            });
            $('.ui-dialog-buttonpane').find('button:contains("'+webLanguage["Modul_Ecom_Basket_Next"]+'")').button({
                icons: {
                    primary: 'ui-icon-circle-triangle-e'
                }
            });
            $('.ui-dialog-buttonpane').find('button:contains("'+webLanguage["General_Close"]+'")').button({
                icons: {
                    primary: 'ui-icon-circle-close'
                }
            });
            $('.ui-dialog-buttonpane').find('button:contains("'+webLanguage["Modul_Ecom_Basket_Back"]+'")').hide();
		},
		beforeClose: function() {
			$("#DIV_ecom_basket_details").html("");
			
			$("#DIV_system_messages").html("");
			$("#DIV_system_messages").css("display", "none");
			
			POgetBasketContent();
		}
	});
	
}

function POchangeBasketProductQty(orderID, orderNumber, productID, productQuantity, maxProductQuantity)
{
	
//	console.log(maxProductQuantity);
	
	newProductQuantity = prompt(webLanguage["Modul_Ecom_Basket_Order_Step_1_Change_Product_Qty"], productQuantity);
	
	if(isFinite(newProductQuantity) && newProductQuantity > 0)
	{
		if(maxProductQuantity > 0 && newProductQuantity > maxProductQuantity)
		{
			alert(webLanguage["Modul_Ecom_Basket_Order_Step_1_Max_Product_Qty"]+" "+maxProductQuantity);
			var dataPOchangeBasketProductQty = $.ajax({
				url: "system/modules/ecom/modul_ecom.php?mode=po_change_basket_product_qty&orderID="+orderID+"&productID="+productID+"&productQuantity="+maxProductQuantity,
				async: false
			});
		}
		else
		{
			var dataPOchangeBasketProductQty = $.ajax({
				url: "system/modules/ecom/modul_ecom.php?mode=po_change_basket_product_qty&orderID="+orderID+"&productID="+productID+"&productQuantity="+newProductQuantity,
				async: false
			});
		}
	}
	
	
	var dataPObasketContent = $.ajax({
		url: "system/modules/ecom/modul_ecom_basket.php?orderStep=1&orderID="+orderID,
		async: false
	});
	
	$("#DIV_ecom_basket_details").html(dataPObasketContent.responseText);
	$("#DIV_ecom_basket_slider").css("width", modul_ecom_basket_product_table_width);
	$("#DIV_ecom_basket_slider").slider(basketSliderOptions);
	$("#DIV_ecom_basket_slider_pane").css("width", modul_ecom_basket_product_table_width);
	$("#DIV_ecom_basket_slider_label").html(webLanguage["Modul_Ecom_Basket_Order_Step_1"]);
	
}

function POremoveFromBasket(orderID, orderNumber, productID, productTitle)
{
	if(confirm(webLanguage["Modul_Ecom_Basket_Order_Step_1_Remove_Product"]+"\n"+productTitle))
	{
		var dataPOremoveFromBasket = $.ajax({
			url: "system/modules/ecom/modul_ecom.php?mode=po_remove_basket_product&orderID="+orderID+"&productID="+productID,
			async: false
		});

		if(dataPOremoveFromBasket.responseText == 1)
		{
//			console.log(dataPOremoveFromBasket.responseText);
			
			var dataPObasketContent = $.ajax({
				url: "system/modules/ecom/modul_ecom_basket.php?orderStep=1&orderID="+orderID,
				async: false
			});
			
			$("#DIV_ecom_basket_details").html(dataPObasketContent.responseText);
			$("#DIV_ecom_basket_slider").css("width", modul_ecom_basket_product_table_width);
			$("#DIV_ecom_basket_slider").slider(basketSliderOptions);
			$("#DIV_ecom_basket_slider_pane").css("width", modul_ecom_basket_product_table_width);
			$("#DIV_ecom_basket_slider_label").html(webLanguage["Modul_Ecom_Basket_Order_Step_1"]);
		}
		else
		{
			alert(webLanguage["Modul_Ecom_Basket_Order_Step_1_Remove_Basket"]+"\n"+orderNumber);
			
			var dataPOremoveBasket = $.ajax({
				url: "system/modules/ecom/modul_ecom.php?mode=po_remove_basket&orderID="+orderID,
				async: false
			});
			
			$("#DIV_ecom_basket_details").html("");
			$("#DIV_ecom_basket_details").dialog("close");
			$("#DIV_ecom_basket_details").dialog("destroy");
		}
		
	}
	
}

function POremoveBasket(orderID, orderNumber)
{
	if(confirm(webLanguage["Modul_Ecom_Basket_Order_Step_1_Remove_Basket"]+"\n"+orderNumber))
	{
		var dataPOremoveBasket = $.ajax({
			url: "system/modules/ecom/modul_ecom.php?mode=po_remove_basket&orderID="+orderID,
			async: false
		});
		
		$("#DIV_ecom_basket_details").html("");
		$("#DIV_ecom_basket_details").dialog("close");
		$("#DIV_ecom_basket_details").dialog("destroy");
	}
	
}

/**
 * Customer Login
 */

function POshowCustomerLoginDialog(mode)
{
	if(mode === undefined) { mode = "ecom_customer_login";}

	var customerManagementDialogTitle = webLanguage["Modul_Ecom_Basket_Order_Step_2_Customer_Login"];
	if(mode == "ecom_customer_login_reset")
	{
		customerManagementDialogTitle = webLanguage["Modul_Ecom_Basket_Order_Step_2_Customer_Login_Reset"];
	}

	var dataPOgetCustomerLogin = $.ajax({
		url: "system/modules/ecom/modul_ecom_customer.php?mode="+mode,
		async: false
	});

	if($("#DIV_ecom_customer_management").html())
	{
		$("#DIV_ecom_customer_management").html(dataPOgetCustomerLogin.responseText);
		$("#DIV_ecom_customer_management").dialog("option", "title", customerManagementDialogTitle);
//		console.log("html exists");
	}
	else
	{
		$("#DIV_ecom_customer_management").html(dataPOgetCustomerLogin.responseText);
		var modul_ecom_customer_buttons = {};
		modul_ecom_customer_buttons[webLanguage["General_Close"]] = function() {
			$(this).dialog("close");
		};
		$("#DIV_ecom_customer_management").dialog({
			dialogClass: 'custom',
			title: customerManagementDialogTitle,
			bgiframe: true,
			height: 350,
			width: 400,
			modal: true,
			resizable: false,
			draggable: false,
			closeOnEscape: false,
			buttons: modul_ecom_customer_buttons,
			open: function() {
	            $('.ui-dialog-buttonpane').find('button:contains("'+webLanguage["General_Close"]+'")').button({
	                icons: {
	                    primary: 'ui-icon-circle-close'
	                }
	            });
	            $("#DIV_ecom_basket_details").dialog("option", "closeOnEscape", false);
			},
			beforeClose: function() {
	            $("#DIV_ecom_basket_details").dialog("option", "closeOnEscape", true);
			},
			close: function() {
				$("#DIV_ecom_customer_management").html("");
				$("#DIV_ecom_customer_management").dialog("destroy");
//				console.log(window.location.search);
				querystring = window.location.search;
				if(querystring.search(/\?login/) != -1 || querystring.search(/\?register/) != -1)
				{
					window.location.href = "http://"+window.location.hostname;
				}
			}
		});
	}



	
}

function POcheckCustomerLogin()
{
//	console.log("save: "+orderStep);
	
	$(document).ready(function() {
			setTimeout(function() {  
        		$("input[type='text']:enabled:first").focus();
        	}, 500);

			jQuery.validator.messages.required = "";
			jQuery.validator.messages.email = "";
			jQuery.validator.messages.select = "";
			jQuery.validator.messages.number = "";
			jQuery.validator.messages.url = "";
			var validator = $("#FORM_modul_ecom_customer_login").validate({
				ignoreTitle: true,
        		invalidHandler: function() {
//        			console.log("errors: "+validator.numberOfInvalids());
        			var errors = validator.numberOfInvalids();
	    			if (errors)
	    			{
//	    				console.log("erorrrrsss: "+errors);
	    				var message = errors == 1
	    					? webLanguage["General_Required_Fields"]
	    					: webLanguage["General_Required_Fields"];
	    				$("#DIV_ecom_customer_login_message").html("<img src=\"http://"+window.location.hostname+"/admin/img/16_exclamation.png\" style=\"margin-right: 10px; vertical-align: bottom;\"><b>"+message+"</b>");
	    				$("#DIV_ecom_customer_login_message").show();
	    			}
	    			else
	    			{
	    				$("#DIV_ecom_customer_login_message").css("display", "none");
	    			}
    			}

        	});
        	
        	var options = {
            		success: function(data) {
            			POprocessCustomerLogin(data);
            		}
            	};

               $("#FORM_modul_ecom_customer_login").ajaxForm(options);
			

	});	
}

function POprocessCustomerLogin(data)
{
//	$("#DIV_ecom_customer_login_message").css("display", "block");
//	$("#DIV_ecom_customer_login_message").html("<img src=\"http://"+window.location.hostname+"/admin/img/16_success.png\" style=\"margin-right: 10px; vertical-align: bottom;\"><b>"+data+"</b>");
//	$("#BUTTON_ecom_customer_login").css("display", "none");
//	$("#DIV_ecom_customer_login_message").fadeOut(4000);
//	setTimeout(function() {
//		
//	}, 4000);

	if(data.search(/login_failure/) != -1)
	{
		setTimeout(function() {  
    		$("input[type='text']:enabled:first").focus();
    	}, 500);
		$("#TEXT_customer_user_name").val("");
		$("#TEXT_customer_user_password").val("");
		$("#DIV_ecom_customer_login_message").css("display", "block");
		$("#DIV_ecom_customer_login_message").html("<img src=\"http://"+window.location.hostname+"/admin/img/16_exclamation.png\" style=\"margin-right: 10px;\">"+webLanguage["Modul_Ecom_Customer_Login_Failure"]);
	}
	else if(data.search(/login_captcha_failure/) != -1)
	{
		setTimeout(function() {  
    		$("input[type='text']:enabled:first").focus();
    	}, 500);
		$("#TEXT_customer_user_name").val("");
		$("#TEXT_customer_user_password").val("");
		$("#TEXT_customer_captcha_code").val("");
		$("#DIV_ecom_customer_login_message").css("display", "block");
		$("#DIV_ecom_customer_login_message").html("<img src=\"http://"+window.location.hostname+"/admin/img/16_exclamation.png\" style=\"margin-right: 10px;\">"+webLanguage["Modul_Ecom_Customer_Login_Captcha_Failure"]);
	}
	else if(data.search(/login_disabled_failure/) != -1)
	{
		setTimeout(function() {  
    		$("input[type='text']:enabled:first").focus();
    	}, 500);
		$("#TEXT_customer_user_name").val("");
		$("#TEXT_customer_user_password").val("");
		$("#DIV_ecom_customer_login_message").css("display", "block");
		$("#DIV_ecom_customer_login_message").html("<img src=\"http://"+window.location.hostname+"/admin/img/16_exclamation.png\" style=\"margin-right: 10px;\">"+webLanguage["Modul_Ecom_Customer_Login_Disabled_Failure"]);
	}
	else if(data.search(/login_try_failure/) != -1)
	{
		setTimeout(function() {  
    		$("input[type='text']:enabled:first").focus();
    	}, 500);
		$("#TEXT_customer_user_name").val("");
		$("#TEXT_customer_user_password").val("");
		$("#DIV_ecom_customer_login_message").css("display", "block");
		$("#DIV_ecom_customer_login_message").html("<img src=\"http://"+window.location.hostname+"/admin/img/16_exclamation.png\" style=\"margin-right: 10px;\">"+webLanguage["Modul_Ecom_Customer_Login_Try_Failure"]);
	}
	else if(data.search(/login_not_exists/) != -1)
	{
		setTimeout(function() {  
    		$("input[type='text']:enabled:first").focus();
    	}, 500);
		$("#TEXT_customer_user_name").val("");
		$("#TEXT_customer_captcha_code").val("");
		$("#DIV_ecom_customer_login_message").css("display", "block");
		$("#DIV_ecom_customer_login_message").html("<img src=\"http://"+window.location.hostname+"/admin/img/16_exclamation.png\" style=\"margin-right: 10px;\">"+webLanguage["Modul_Ecom_Customer_Login_Not_Exists"]);
	}
	else if(data.search(/login_exists/) != -1)
	{
		$("#BUTTON_ecom_customer_login").css("display", "none");
		$("#DIV_ecom_customer_login_message").css("display", "block");
//		$("#DIV_ecom_customer_login_message").html(data);
		$("#DIV_ecom_customer_login_message").html("<img src=\"http://"+window.location.hostname+"/admin/img/16_success.png\" style=\"margin-right: 10px;\">"+webLanguage["Modul_Ecom_Customer_Login_Exists"]);
		$("#DIV_ecom_customer_login_message").fadeOut(4000, function(){
//			if(data) data  = "?"+data;
			window.location.href = "http://"+window.location.hostname;
		});
	}
	else
	{
		$("#BUTTON_ecom_customer_login").css("display", "none");
		$("#DIV_ecom_customer_login_message").css("display", "block");
//		$("#DIV_ecom_customer_login_message").html(data);
		$("#DIV_ecom_customer_login_message").html("<img src=\"http://"+window.location.hostname+"/admin/img/16_success.png\" style=\"margin-right: 10px;\">"+webLanguage["Modul_Ecom_Customer_Login_Success"]);
		$("#DIV_ecom_customer_login_message").fadeOut(4000, function(){
			if(data) data  = "?"+data;
			window.location.href = "http://"+window.location.hostname+"/"+data;
		});
	}

	
	
}

/**
 * Save Customer Information
 */

function POsaveCustomerInformation(orderID, orderStep)
{
//	console.log("save: "+orderStep);
	
	$(document).ready(function() {
			setTimeout(function() {  
        		$("input[type='text']:enabled:first").focus();
        	}, 500);

			jQuery.validator.messages.required = "";
			jQuery.validator.messages.email = "";
			jQuery.validator.messages.select = "";
			jQuery.validator.messages.number = "";
			jQuery.validator.messages.url = "";
			var validator = $("#FORM_modul_ecom_basket_customer").validate({
				ignoreTitle: true,
        		invalidHandler: function() {
//        			console.log("errors: "+validator.numberOfInvalids());
        			var errors = validator.numberOfInvalids();
	    			if (errors)
	    			{
//	    				console.log("erorrrrsss: "+errors);
	    				var message = errors == 1
	    					? webLanguage["General_Required_Fields"]
	    					: webLanguage["General_Required_Fields"];
	    				
	    				showSystemMessageBox(message, "alert", 1);
//	    				$("#DIV_system_messages").html("<img src=\"http://"+window.location.hostname+"/admin/img/16_exclamation.png\" style=\"margin-right: 10px; vertical-align: bottom;\"><b>"+message+"</b>");
//	    				$("#DIV_system_messages").show();
	    			}
	    			else
	    			{
	    				showSystemMessageBox("", "", 0);
	    			}
    			}

        	});
        	
			var formValid = $("#FORM_modul_ecom_basket_customer").valid();
			
			if(formValid)
			{
				formError = false;
			}
			else
			{
				formError = true;
			}
			
        	var options = {
            		success: function(data) {
            			POprocessCustomerInformation(data, orderID, orderStep);
            		}
            	};

               $("#FORM_modul_ecom_basket_customer").ajaxForm(options);
			

	});	
}

function POprocessCustomerInformation(data, orderID, orderStep)
{
//	console.log("process orderStep start: "+orderStep);
	
	$("#DIV_system_messages").css("display", "block");
	showSystemMessageBox(webLanguage["General_Save_Success"], "success", 1);
//	$("#DIV_system_messages").html("<img src=\"http://"+window.location.hostname+"/admin/img/16_success.png\" style=\"margin-right: 10px; vertical-align: bottom;\"><b>"+webLanguage["General_Save_Success"]+"</b>");
//	$("#BUTTON_MM_product_price_global_save").css("display", "none");
	setTimeout(function() {
		$("#DIV_system_messages").slideUp(2000, function() {
			orderStep++;
			var dataPObasketContent = $.ajax({
				url: "system/modules/ecom/modul_ecom_basket.php?orderStep="+orderStep+"&orderID="+orderID,
				async: false
			});
			if(dataPObasketContent.responseText.search(/order_end/) != -1)
			{
				orderStep--;
				 $('.ui-dialog-buttonpane').find('button:contains("'+webLanguage["Modul_Ecom_Basket_Next"]+'")').hide();
			}
			else
			{
				$("#DIV_ecom_basket_details").html(dataPObasketContent.responseText);
			}
			$("#DIV_ecom_basket_slider").css("width", modul_ecom_basket_product_table_width);
			$("#DIV_ecom_basket_slider").slider(basketSliderOptions);
			$("#DIV_ecom_basket_slider_label").html(webLanguage["Modul_Ecom_Basket_Order_Step_"+orderStep]);
			$("#DIV_ecom_basket_slider").slider("option", "value", orderStep);
	
	//		console.log("process orderStep end: "+orderStep);
		});
	}, 1000);

	
}

function POsaveDeliveryCost(orderID, deliveryCostID)
{
//	console.log(orderID+" "+deliveryCostID);
	var dataPOsaveDeliveryCost = $.ajax({
		url: "system/modules/ecom/modul_ecom.php?mode=po_save_delivery_cost&orderID="+orderID+"&deliveryCostID="+deliveryCostID,
		async: false
	});

	var dataPObasketContent = $.ajax({
		url: "system/modules/ecom/modul_ecom_basket.php?orderStep=1&orderID="+orderID,
		async: false
	});
	
	$("#DIV_ecom_basket_details").html(dataPObasketContent.responseText);
	$("#DIV_ecom_basket_slider").css("width", modul_ecom_basket_product_table_width);
	$("#DIV_ecom_basket_slider").slider(basketSliderOptions);
	$("#DIV_ecom_basket_slider_label").html(webLanguage["Modul_Ecom_Basket_Order_Step_1"]);
	
}

function POsaveDeliveryMethod(orderID, deliveryMethodID)
{
//	console.log(orderID+" "+deliveryMethodID);
	var dataPOsaveDeliveryCost = $.ajax({
		url: "system/modules/ecom/modul_ecom.php?mode=po_save_delivery_method&orderID="+orderID+"&deliveryMethodID="+deliveryMethodID,
		async: false
	});

	var dataPObasketContent = $.ajax({
		url: "system/modules/ecom/modul_ecom_basket.php?orderStep=3&orderID="+orderID,
		async: false
	});
	
	$("#DIV_ecom_basket_details").html(dataPObasketContent.responseText);
	$("#DIV_ecom_basket_slider").css("width", modul_ecom_basket_product_table_width);
	$("#DIV_ecom_basket_slider").slider(basketSliderOptions);
	$("#DIV_ecom_basket_slider_label").html(webLanguage["Modul_Ecom_Basket_Order_Step_3"]);
	$("#DIV_ecom_basket_slider").slider("option", "value", 3);
}

function POopenPaymentMethodInformationDialog(data, title)
{
//	$(function(){
	
	$("#DIV_ecom_payment_information").html(data);
		var modul_ecom_payment_information_buttons = {};
		modul_ecom_payment_information_buttons[webLanguage["General_Close"]] = function() {
			$(this).dialog("close");
		};
		$("#DIV_ecom_payment_information").dialog({
			dialogClass: 'custom',
			title: title,
			bgiframe: true,
			height: 250,
			width: 400,
			modal: true,
			resizable: false,
			draggable: false,
			closeOnEscape: false,
			buttons: modul_ecom_payment_information_buttons,
			open: function() {
                $('.ui-dialog-buttonpane').find('button:contains("'+webLanguage["General_Close"]+'")').button({
                    icons: {
                        primary: 'ui-icon-circle-close'
                    }
                });
                $("#DIV_ecom_basket_details").dialog("option", "closeOnEscape", false);
			},
			beforeClose: function() {
                $("#DIV_ecom_basket_details").dialog("option", "closeOnEscape", true);
			}
		});
//	});
}

function POdisableButtonNext()
{
	$('.ui-dialog-buttonpane').find('button:contains("'+webLanguage["Modul_Ecom_Basket_Next"]+'")').hide();
}

/**
 * Customer order
 */

function POsaveCustomerOrder(orderID, orderStep)
{
//	console.log("orderPaymentMethod: "+orderPaymentMethod);
	
	$(document).ready(function() {
			setTimeout(function() {  
        		$("input[type='text']:enabled:first").focus();
        	}, 500);

			jQuery.validator.messages.required = "";
			jQuery.validator.messages.email = "";
			jQuery.validator.messages.select = "";
			jQuery.validator.messages.number = "";
			jQuery.validator.messages.url = "";
			var validator = $("#FORM_modul_ecom_basket_basket_accept").validate({
				ignoreTitle: true,
        		invalidHandler: function() {
//        			console.log("errors: "+validator.numberOfInvalids());
        			var errors = validator.numberOfInvalids();
	    			if (errors)
	    			{
//	    				console.log("erorrrrsss: "+errors);
	    				var message = errors == 1
	    					? webLanguage["General_Required_Fields"]
	    					: webLanguage["General_Required_Fields"];
	    				
	    				showSystemMessageBox(message, "alert", 1);
//	    				$("#DIV_system_messages").html("<img src=\"http://"+window.location.hostname+"/admin/img/16_exclamation.png\" style=\"margin-right: 10px; vertical-align: bottom;\"><b>"+message+"</b>");
//	    				$("#DIV_system_messages").show();
	    			}
	    			else
	    			{
	    				showSystemMessageBox("", "", 0);
//	    				$("#DIV_system_messages").css("display", "none");
	    			}
    			}

        	});
        
			
			var formAcceptValid = $("#FORM_modul_ecom_basket_basket_accept").valid();
	
//			if(orderPaymentMethod == "Paypal" && formAcceptValid)
//			{
////				console.log("IF orderPaymentMethod: "+orderPaymentMethod);
////				var dataPOOrderProcess = $.ajax({
////					url: "system/modules/ecom/modul_ecom_order.php?mode=modul_ecom_basket_order&orderID="+orderID+"&orderStep="+orderStep+"&orderComplete=0&orderStatus=paypal_pre_save",
////					async: false
////				});
//				
//				$('#FORM_modul_ecom_basket_paypal').submit();
//				
//				POprocessCustomerOrder('', orderID, orderStep, orderPaymentMethod);
//			}
//			else if(orderPaymentMethod != "Paypal" && formAcceptValid)
//			{
//				console.log("ELSE orderPaymentMethod: "+orderPaymentMethod);
		    	var options = {
		        		success: function(data) {
		        			POprocessCustomerOrder(data, orderID, orderStep, orderPaymentMethod);
		        		}
		        	};
		
		    		$("#FORM_modul_ecom_basket_basket_accept").ajaxForm(options);
//			}
			

	});	
}

function POprocessCustomerOrder(data, orderID, orderStep, orderPaymentMethod)
{
	
//	$("#DIV_ecom_basket_info_messages").css("display", "block");
	messageText = webLanguage["Modul_Ecom_Basket_Processing"];
	messageIcon = "success";
	if(orderPaymentMethod == "Paypal")
	{
		messageText = webLanguage["Modul_Ecom_Basket_Paypal_Processing"];
		messageIcon = "progress";
//		$('.ui-dialog-buttonpane').find('button:contains("'+webLanguage["Modul_Ecom_Basket_Back"]+'")').hide();
	}
	showSystemMessageBox(messageText, messageIcon, 1);
//	$("#DIV_system_messages").html("<img src=\"http://"+window.location.hostname+"/admin/img/16_"+messageIcon+".png\" style=\"margin-right: 10px; vertical-align: bottom;\"><b>"+messageText+"</b>");
	$('.ui-dialog-buttonpane').find('button:contains("'+webLanguage["Modul_Ecom_Basket_Back"]+'")').hide();
	$('.ui-dialog-buttonpane').find('button:contains("'+webLanguage["Modul_Ecom_Basket_Next"]+'")').hide();

//	$("#DIV_ecom_basket_info_messages").css("float", "none");
//	$("#DIV_ecom_basket_info_messages").dialog({
//		dialogClass: 'custom',
//		title: webLanguage["Modul_Ecom_Basket_Order_Step_4"],
//		bgiframe: true,
//		height: 100,
//		width: 300,
//		modal: true,
//		resizable: false,
//		draggable: false,
//		closeOnEscape: false
////		open: function() { $(".ui-dialog-titlebar-close").hide(); }
//	});

	
	if(orderPaymentMethod == "Paypal")
	{
		setTimeout(function() {
			$('#FORM_modul_ecom_basket_paypal').submit();
		}, 2000);
	}
	else
	{
//		$("#DIV_ecom_basket_info_messages").fadeOut(4000);

		var dataPOOrderResponse = $.ajax({
			url: "system/modules/ecom/modul_ecom_order.php?mode=modul_ecom_basket_order_response",
			async: false
		});

		setTimeout(function() {
			
			
			showSystemMessageBox("", "", 0);
//			$("#DIV_system_messages").html("");
//			$("#DIV_system_messages").css("display", "none");
//			$("#DIV_ecom_basket_info_messages").dialog("close");
			
//			$("#DIV_ecom_basket_info_messages").dialog("close");

			
			$("#DIV_ecom_basket_details").html(dataPOOrderResponse.responseText);
			$("#DIV_ecom_basket_slider_label").html(webLanguage["Modul_Ecom_Basket_Order_Response"]);

		}, 4000);
	}
	
}

function POshowBasketResponse(orderID, orderNumber)
{
//    console.log("orderStep: "+orderStep);

	var dataPObasketContent = $.ajax({
		url: "system/modules/ecom/modul_ecom_order.php?mode=modul_ecom_basket_order_response",
		async: false
	});
	
	$("#DIV_ecom_basket_details").html(dataPObasketContent.responseText);
	
	$("#DIV_ecom_basket_slider").css("width", modul_ecom_basket_product_table_width);
	$("#DIV_ecom_basket_slider").slider(basketSliderOptions);
	$("#DIV_ecom_basket_slider_pane").css("width", modul_ecom_basket_product_table_width);
	$("#DIV_ecom_basket_slider_label").html(webLanguage["Modul_Ecom_Basket_Order_Response"]);
	$("#DIV_ecom_basket_slider").slider("option", "value", 4);
	var modul_ecom_basket_details_buttons = {};
	modul_ecom_basket_details_buttons[webLanguage["General_Close"]] = function() {
		$(this).dialog("close");
	};
	$("#DIV_ecom_basket_details").dialog({
		title: webLanguage["Modul_Ecom_Basket_Details"]+" "+orderNumber,
		dialogClass: 'custom',
		bgiframe: true,
		height: getHeight()-10,
		width: modul_ecom_basket_product_table_width+65,
		modal: true,
		resizable: false,
		draggable: false,
		closeOnEscape: true,
		buttons: modul_ecom_basket_details_buttons,
		open: function() {
            $('.ui-dialog-buttonpane').find('button:contains("'+webLanguage["General_Close"]+'")').button({
                icons: {
                    primary: 'ui-icon-circle-close'
                }
            });
		},
		beforeClose: function() {
			$("#DIV_ecom_basket_details").html("");
			POgetBasketContent();
		}
	});
	
}


/**
 * Cutomer Product Registration
 */

var registerSliderOptions = {
		disabled: true,
		value: 1,
		min: 1,
		max: 4,
		step: 1
};

function PRshowCustomerRegisterWizard(wizardStep, type)
{

//	console.log("wizardStep: "+wizardStep);

	switch (type)
	{
		case 'register' :
			
			dialogTitle = webLanguage["Modul_Ecom_Register_Wizard_Title"];
			buttonStep4Label = webLanguage["Modul_Ecom_Customer_Register_Finish"];
			
			break;

		case 'support' :
			
			dialogTitle = webLanguage["Modul_Ecom_Support_Wizard_Title"];
			buttonStep4Label = webLanguage["Modul_Ecom_Customer_Support_Finish"];
			
			break;

		default :
			break;
	}
	
	
//	console.log($("#DIV_ecom_register_slider").slider("option", "value"));

	registerDialogHeight = 650;
	
//	console.log(getHeight()-10+" "+registerDialogHeight);
	
	if(getHeight()-10 < registerDialogHeight)
	{
		registerDialogHeight = getHeight()-10;
	}
	
//	if(type == "register")
//	{
		var dataPRregisterContent = $.ajax({
			url: "system/modules/ecom/modul_ecom_registration.php?registrationStep="+wizardStep+"&type="+type,
			async: false
		});
//	}
//	else if(type == "support")
//	{
//		dataPRregisterContent = $.ajax({
//			url: "system/modules/ecom/modul_ecom_support.php?supportStep="+wizardStep,
//			async: false
//		});
//	}
	

	if($("#DIV_ecom_customer_wizard").html())
	{
		$("#DIV_ecom_customer_wizard").html(dataPRregisterContent.responseText);
		
		$("#DIV_ecom_register_slider").css("width", modul_ecom_register_product_table_width);
		$("#DIV_ecom_register_slider").slider(registerSliderOptions);
		$("#DIV_ecom_register_slider_pane").css("width", modul_ecom_register_product_table_width);
		$("#DIV_ecom_register_slider_label").html(webLanguage["Modul_Ecom_Customer_Register_Step_"+wizardStep]);
		$("#DIV_ecom_register_slider").slider("option", "value", wizardStep);


		switch (wizardStep)
		{
			case 3 :
				
				$('.ui-dialog-buttonpane').find('button:contains("'+webLanguage["Modul_Ecom_Basket_Next"]+'")').button({
	                label: buttonStep4Label,
	            	icons: {
	                    primary: 'ui-icon-circle-check'
	                }
	            });
				
				break;
			
			case 4:
				
				if(type == "support")
				{
					$("#DIV_ecom_register_slider_label").html(webLanguage["Modul_Ecom_Customer_Support_Step_"+wizardStep]);
				}
				
				$('.ui-dialog-buttonpane').find('button:contains("'+webLanguage["Modul_Ecom_Basket_Next"]+'")').hide();
				$('.ui-dialog-buttonpane').find('button:contains("'+buttonStep4Label+'")').hide();
//				$('.ui-dialog-buttonpane').find('button:contains("'+webLanguage["Modul_Ecom_Basket_Back"]+'")').hide();
				
				break;
			default :
				break;
		}
	
	
	}
	else
	{
		$("#DIV_ecom_customer_wizard").html(dataPRregisterContent.responseText);
		
		$("#DIV_ecom_register_slider").css("width", modul_ecom_register_product_table_width);
		$("#DIV_ecom_register_slider").slider(registerSliderOptions);
		$("#DIV_ecom_register_slider_pane").css("width", modul_ecom_register_product_table_width);
		$("#DIV_ecom_register_slider_label").html(webLanguage["Modul_Ecom_Customer_Register_Step_"+wizardStep]);
		
		var modul_ecom_register_details_buttons = {};
//		modul_ecom_register_details_buttons[webLanguage["Modul_Ecom_Basket_Back"]] = function() {
//			
//			
////			console.log("wizardStep: "+wizardStep);
//			if(wizardStep > 1)
//			{
//				wizardStep--;
////				console.log("back wizardStep: "+wizardStep);
//			}
//
//			PRshowCustomerRegisterWizard(wizardStep, type);
//			
//		};
		
		modul_ecom_register_details_buttons[webLanguage["Modul_Ecom_Basket_Next"]] = function() {

			if(wizardStep == 1)
		    {
				$("#FORM_modul_ecom_registration_customer_data").submit();
				
		    }

		};
		modul_ecom_register_details_buttons[webLanguage["General_Close"]] = function() {
			$(this).dialog("close");
		};
		
		$("#DIV_ecom_customer_wizard").dialog({
			title: dialogTitle,
			dialogClass: 'custom',
			bgiframe: true,
			height: registerDialogHeight,
			width: modul_ecom_register_product_table_width+65,
			modal: true,
			resizable: false,
			draggable: false,
			closeOnEscape: true,
			buttons: modul_ecom_register_details_buttons,
			open: function() {
//	            $('.ui-dialog-buttonpane').find('button:contains("'+webLanguage["Modul_Ecom_Basket_Back"]+'")').button({
//	                icons: {
//	                    primary: 'ui-icon-circle-triangle-w'
//	                }
//	            });
	            $('.ui-dialog-buttonpane').find('button:contains("'+webLanguage["Modul_Ecom_Basket_Next"]+'")').button({
	                icons: {
	                    primary: 'ui-icon-circle-triangle-e'
	                }
	            });
	            $('.ui-dialog-buttonpane').find('button:contains("'+webLanguage["General_Close"]+'")').button({
	                icons: {
	                    primary: 'ui-icon-circle-close'
	                }
	            });
//	            $('.ui-dialog-buttonpane').find('button:contains("'+webLanguage["Modul_Ecom_Basket_Back"]+'")').hide();
			},
			beforeClose: function() {
				$("#DIV_ecom_customer_wizard").html("");
				
				showSystemMessageBox("", "", 0);

				var dataPRregisterContent = $.ajax({
					url: "system/modules/ecom/modul_ecom_customer.php?mode=modul_ecom_destroy_customer_session",
					async: false
				});
//				POgetBasketContent();
			},
			close: function() {
				window.location.href = "http://"+window.location.hostname;
			}
		});
	}
	
	
}


function PRcheckCustomerInformation(wizardStep, type)
{
//	console.log("save: "+orderStep);
	
	$(document).ready(function() {
			setTimeout(function() {  
        		$("input[type='text']:enabled:first").focus();
        	}, 500);

			jQuery.validator.messages.required = "";
			jQuery.validator.messages.email = "";
			jQuery.validator.messages.select = "";
			jQuery.validator.messages.number = "";
			jQuery.validator.messages.url = "";
			var validator = $("#FORM_modul_ecom_registration_customer_data").validate({
				ignoreTitle: true,
        		invalidHandler: function() {
//        			console.log("errors: "+validator.numberOfInvalids());
        			var errors = validator.numberOfInvalids();
	    			if (errors)
	    			{
//	    				console.log("erorrrrsss: "+errors);
	    				var message = errors == 1
	    					? webLanguage["General_Required_Fields"]
	    					: webLanguage["General_Required_Fields"];
	    				
	    				showSystemMessageBox(message, "alert", 1);
//	    				$("#DIV_system_messages").html("<img src=\"http://"+window.location.hostname+"/admin/img/16_exclamation.png\" style=\"margin-right: 10px; vertical-align: bottom;\"><b>"+message+"</b>");
//	    				$("#DIV_system_messages").show();
	    			}
	    			else
	    			{
	    				showSystemMessageBox("", "", 0);
//	    				$("#DIV_system_messages").css("display", "none");
	    			}
    			}

        	});
        	
//			var formValid = $("#FORM_modul_ecom_registration_customer_data").valid();
//			
//			if(formValid)
//			{
//				formError = false;
//			}
//			else
//			{
//				formError = true;
//			}
			
        	var options = {
            		success: function(data) {
            			PRprocessCustomerInformation(data, wizardStep, type);
            		}
            	};

               $("#FORM_modul_ecom_registration_customer_data").ajaxForm(options);
			

	});	
}

function PRprocessCustomerInformation(data, wizardStep, type)
{
//	console.log("data: "+data);
	
	if(data.search(/login_captcha_failure/) != -1)
	{
		setTimeout(function() {  
    		$("input[type='text']:enabled:first").focus();
    	}, 500);
		$("#TEXT_customer_captcha_code").val("");
		showSystemMessageBox(webLanguage["Modul_Ecom_Customer_Login_Captcha_Failure"], "alert", 1);
//		$("#DIV_system_messages").css("display", "block");
//		$("#DIV_system_messages").html("<img src=\"http://"+window.location.hostname+"/admin/img/16_exclamation.png\" style=\"margin-right: 10px;\"><b>"+webLanguage["Modul_Ecom_Customer_Login_Captcha_Failure"]+"</b>");
	}
	else
	{
		if(data.search(/no_registered_products/) != -1)
		{
			consoleLog(wizardStep);
			wizardStep = 3;
		}
		showSystemMessageBox(webLanguage["General_Save_Success"], "success", 1);
//		$("#DIV_system_messages").css("display", "block");
//		$("#DIV_system_messages").html("<img src=\"http://"+window.location.hostname+"/admin/img/16_success.png\" style=\"margin-right: 10px; vertical-align: bottom;\"><b>"+webLanguage["General_Save_Success"]+"</b>");
//		$("#BUTTON_MM_product_price_global_save").css("display", "none");
		setTimeout(function() {
			$("#DIV_system_messages").slideUp(2000, function() {
				wizardStep++;
				PRshowCustomerRegisterWizard(wizardStep, type);
			});

		
		}, 1000);
	}
	
	
//	setTimeout(function() {
//		
////		wizardStep++;
////		PRshowCustomerRegisterWizard(wizardStep);
//
//	}, 1000);
	
}


function PSshowSupportRequestDialog(mode, status)
{
	checkLoginData();

	if(mode === undefined) { mode = "";}
	if(status === undefined) { status = 1; }
	
	var dataPSsupportContent = $.ajax({
		url: "system/modules/ecom/modul_ecom_support.php?mode="+mode+"&status="+status,
		async: false
	});

	
	
	if($("#DIV_ecom_customer_wizard").html())
	{
		$("#DIV_ecom_customer_wizard").html(dataPSsupportContent.responseText);
	}
	else
	{
		$('#DIV_admin_panel_menu').toggle("fast");

		$("#DIV_ecom_customer_wizard").html(dataPSsupportContent.responseText);
		var modul_ecom_support_dialog_buttons = {};
		modul_ecom_support_dialog_buttons[webLanguage["General_Reload"]] = function() {
			PSshowSupportRequestDialog(mode, status);
		};
		modul_ecom_support_dialog_buttons[webLanguage["General_Close"]] = function() {
			$(this).dialog("close");
		};
		$("#DIV_ecom_customer_wizard").dialog({
			title: webLanguage["Modul_Ecom_Support_Requests_Title"],
//			dialogClass: 'custom',
			bgiframe: true,
			height: 600,
			width: 800,
			modal: true,
			resizable: false,
			draggable: false,
			closeOnEscape: true,
			buttons: modul_ecom_support_dialog_buttons,
			open: function() {
                $('.ui-dialog-buttonpane').find('button:contains("'+webLanguage["General_Reload"]+'")').button({
                    icons: {
                        primary: 'ui-icon-circle-arrow-s'
                    }
                });
                $('.ui-dialog-buttonpane').find('button:contains("'+webLanguage["General_Close"]+'")').button({
                    icons: {
                        primary: 'ui-icon-circle-close'
                    }
                });
			},
			beforeClose: function() {
				$("#DIV_ecom_customer_wizard").html("");
				
				showSystemMessageBox("", "", 0);
//				$("#DIV_system_messages").html("");
//				$("#DIV_system_messages").css("display", "none");
			}
		});
	}
	
}


function PSshowSupportRequestDetailsDialog(supportRequestID, supportRequestNumber)
{
	checkLoginData();


	var dataPSsupportDetailsContent = $.ajax({
		url: "system/modules/ecom/modul_ecom_support.php?mode=support_request_details&id="+supportRequestID,
		async: false
	});

	
	
	if($("#DIV_ecom_customer_wizard_details").html())
	{
		$("#DIV_ecom_customer_wizard_details").html(dataPSsupportDetailsContent.responseText);
	}
	else
	{
		$("#DIV_ecom_customer_wizard_details").html(dataPSsupportDetailsContent.responseText);
		var modul_ecom_support_details_dialog_buttons = {};
//		modul_ecom_support_details_dialog_buttons[webLanguage["General_Reload"]] = function() {
//			PSshowSupportRequestDialog(mode, status);
//		};
		modul_ecom_support_details_dialog_buttons[webLanguage["General_Close"]] = function() {
			$(this).dialog("close");
		};

		$("#DIV_ecom_customer_wizard_details").dialog({
			title: webLanguage["Modul_Ecom_Support_Requests_Details_Title"]+" "+supportRequestNumber,
//			dialogClass: 'custom',
			bgiframe: true,
			height: 600,
			width: 700,
			modal: true,
			resizable: false,
			draggable: false,
			closeOnEscape: false,
			buttons: modul_ecom_support_details_dialog_buttons,
			open: function() {
//                $('.ui-dialog-buttonpane').find('button:contains("'+webLanguage["General_Reload"]+'")').button({
//                    icons: {
//                        primary: 'ui-icon-circle-arrow-s'
//                    }
//                });
                $('.ui-dialog-buttonpane').find('button:contains("'+webLanguage["General_Close"]+'")').button({
                    icons: {
                        primary: 'ui-icon-circle-close'
                    }
                });
                $("#DIV_ecom_customer_wizard").dialog("option", "closeOnEscape", false);
			},
			beforeClose: function() {
				$("#DIV_ecom_customer_wizard_details").html("");
				
				showSystemMessageBox("", "", 0);
//				$("#DIV_system_messages").html("");
//				$("#DIV_system_messages").css("display", "none");
			},
			close: function () {
                $("#DIV_ecom_customer_wizard").dialog("option", "closeOnEscape", true);
                $("#DIV_support_requests_tab").tabs("load", $("#DIV_support_requests_tab").tabs("option", "selected"));
			}
		});
	}
	
}


function PScheckSupportRequestDetails(supportRequestID)
{
//	console.log("save: "+orderStep);
	
	$(document).ready(function() {
			setTimeout(function() {  
        		$("input[type='text']:enabled:first").focus();
        	}, 500);

			jQuery.validator.messages.required = "";
			jQuery.validator.messages.email = "";
			jQuery.validator.messages.select = "";
			jQuery.validator.messages.number = "";
			jQuery.validator.messages.url = "";
			var validator = $("#FORM_modul_ecom_support_request_details_data").validate({
				ignoreTitle: true,
        		invalidHandler: function() {
//        			console.log("errors: "+validator.numberOfInvalids());
        			var errors = validator.numberOfInvalids();
	    			if (errors)
	    			{
//	    				console.log("erorrrrsss: "+errors);
	    				var message = errors == 1
	    					? webLanguage["General_Required_Fields"]
	    					: webLanguage["General_Required_Fields"];
	    					
	    				showSystemMessageBox(message, "alert", 1);
//	    				$("#DIV_system_messages").html("<img src=\"http://"+window.location.hostname+"/admin/img/16_exclamation.png\" style=\"margin-right: 10px; vertical-align: bottom;\"><b>"+message+"</b>");
//	    				$("#DIV_system_messages").show();
	    			}
	    			else
	    			{
	    				showSystemMessageBox("", "", 0);
//	    				$("#DIV_system_messages").css("display", "none");
	    			}
    			}

        	});
        	
//			var formValid = $("#FORM_modul_ecom_registration_customer_data").valid();
//			
//			if(formValid)
//			{
//				formError = false;
//			}
//			else
//			{
//				formError = true;
//			}
			
        	var options = {
            		success: function(data) {
            			PSprocessSupportRequestDetails(data, supportRequestID);
            		}
            	};

               $("#FORM_modul_ecom_support_request_details_data").ajaxForm(options);
			

	});	
}

function PSprocessSupportRequestDetails(data, supportRequestID)
{
//	console.log("data: "+data);
	
		showSystemMessageBox(webLanguage["General_Save_Success"], "success", 1);
//		$("#DIV_system_messages").css("display", "block");
//		$("#DIV_system_messages").html("<img src=\"http://"+window.location.hostname+"/admin/img/16_success.png\" style=\"margin-right: 10px; vertical-align: bottom;\"><b>"+webLanguage["General_Save_Success"]+"</b> "+data);
//		$("#BUTTON_MM_product_price_global_save").css("display", "none");
		PSshowSupportRequestDetailsDialog(supportRequestID);
		setTimeout(function() {
			$("#DIV_system_messages").slideUp(2000, function() {
				$("#DIV_support_requests_tab").tabs("load", $("#DIV_support_requests_tab").tabs("option", "selected"));
			});

		
		}, 1000);
	
	
//	setTimeout(function() {
//		
////		wizardStep++;
////		PRshowCustomerRegisterWizard(wizardStep);
//
//	}, 1000);
	
}














