﻿jQuery.fx.off = true;

function PleaseWaitPopUp(bacgroundcolor) {
    $.nyroModalManual({
    	bgColor: bacgroundcolor,
        content: "<div id='AjaxLoading'>" + Translate('Common..Ajax.PleaseWait') + "</div>",
        modal: true,
        resizeable: false,
        autoSizable: false,
        closeButton: null,
        minWidth: 130,
        minHeight: 25,
        width: 130,
        height: 25
    });
}

function WebRequestManagerCompletedRequest(sender, eventArgs) {   
$.nyroModalRemove();
}

function WebRequestManagerInvokingRequest(sender, eventArgs) {

    PleaseWaitPopUp('transparent');
}



function PopUpDescription(ID, Type) {
    $.nyroModalManual({
        url: '/IDescription/?ID=' + ID + '&Type=' + Type,
        minWidth: 500,
        minHeight: 250,
        autoSizable: true,
        ltr: !RTL
    });
}


function PopUpLoadingMessage() {
    $.nyroModalManual({
        bgColor: '#ffffff',
        content: "<div id='AjaxLoadingImage' style='overlow:visible;white-space:nowrap;'>" + Translate('Common..Ajax.PleaseWaitLoadingImage') + "</div>",
        modal: true,
        resizeable: false,
        autoSizable: true,
        closeButton: null,
        minWidth: 10,
        minHeight: 25,
        //width: 300,
        height: 25
    });
}


// -------------------------------------------- DisplayMessage --------------------------------------------
function DisplayMessage(MessageObject) {
    var MessageBox = $("<p></p>");
    MessageBox.setTemplateElement("MessageBoxTemplate", null, { filter_data: (MessageObject.DisplayHtmlMessage != undefined) ? (!MessageObject.DisplayHtmlMessage) : false });
    MessageBox.processTemplate(MessageObject);
     $.nyroModalManual({
        bgColor: '#bbbbbb',
        content: unescape(MessageBox.html()),
        modal: false,
        resizeable: false,
        closeButton: null,
        minWidth: 0,
        minHeight: 0,
		css: { // Default CSS option for the nyroModal Div. Some will be overwritten or updated when using IE6
			bg: {
				position: 'absolute',
				overflow: 'hidden',
				top: 0,
				left: 0,
				height: '100%',
				width: '100%'
			},
			wrapper: {
				position: 'absolute',
				top: '50%',
				left: '50%',
				border: 'none',
				'background-color': 'transparent'
			},
			wrapper2: {
			},
			content: {
				overflow: 'auto'
			},
			loading: {
				position: 'absolute',
				top: '50%',
				left: '50%',
				marginTop: '-50px',
				marginLeft: '-50px'

			}
		}        
    });
}


var User = {
    Login: function() {
    if (!$(".LoginPanelContainer").jForm().validate()) return;    
        var Email = $("#fldLoginEmail").val();
        var Password = $("#fldLoginPassword").val();
        B2CPrint.G1.WebSite.WS.User.Login(Email, Password, this.LoginOnSucceeded, this.LoginOnFailed);
    },

    LoginOnSucceeded: function(data, args, methodName) {
        if (data.ActionSucceeded != undefined && !data.ActionSucceeded) {
            var MessageObject = {
                ErrorMessage: data.ErrorMessage,
                ErrorDescription: data.ErrorDescription,
                ErrorNumber: data.ErrorNumber,
                ErrorState: data.ErrorState,
                ErrorType: data.ErrorType,
                ErrorSource: data.ErrorSource
            };
            DisplayMessage(MessageObject);
        }
        else {
            window.location.reload();
        }
    },

    LoginOnFailed: function(error, userContext, methodName) {
        var MessageObject = {
            ErrorMessage: error._message,
            ErrorDescription: error.timedOut ? Translate('"Common..Error.Timeout"') : error._message,
            ErrorID: error._statusCode,
            ErrorState: 1
        };
        DisplayMessage(MessageObject);
    },

    Logout: function() {
        B2CPrint.G1.WebSite.WS.User.Logout(this.LogoutOnSucceeded, this.LogoutOnFailed);
    },

    LogoutOnSucceeded: function(data, args, methodName) {
        if (data.ActionSucceeded != undefined && !data.ActionSucceeded) {
            var MessageObject = {
                ErrorMessage: data.ErrorMessage,
                ErrorDescription: data.ErrorDescription,
                ErrorNumber: data.ErrorNumber,
                ErrorState: data.ErrorState,
                ErrorType: data.ErrorType,
                ErrorSource: data.ErrorSource
            };
            DisplayMessage(MessageObject);
        }
        else {
            window.location.reload();
        }
    },

    LogoutOnFailed: function(error, userContext, methodName) {
        var MessageObject = {
            ErrorMessage: error._message,
            ErrorDescription: error.timedOut ? Translate('"Common..Error.Timeout"') : error._message,
            ErrorID: error._statusCode,
            ErrorState: 1
        };
        DisplayMessage(MessageObject);
    }
};