/*!
 * @author Gproxy Design Inc.
 * @copyright (c) 2010, Gproxy Design Inc. All rights reserved.
 * @version 1.0
 *
 * Gproxy doesn't allow to copy or change this code without Gproxy authorization.
 * See http://www.gproxy.com/licenses/license01.pdf for the full license governing this code.
 */
var GPR_PUP = function($){
    var objOptions = {
        fade: 500,
        winTimeOut: 7000
    };
    return {
        /**
         * POP UP MESSAGGES
         * Init
         * @param {Object} objOptions
         */
        init: function(obj){
            if (obj !== null && obj !== undefined) {
                $.extend(objOptions, obj);
            }
        },
        /**
         * POP UP MESSAGGES
         * Show
         * @param {String} strMsg
         */
        show: function(strMsg){
            $('.pup-win').remove();
            $('body').append('<div class="pup-win">' + strMsg + '</div>');
            $('.pup-win').fadeTo(0, 0);
            $('.pup-win').append('<div class="pup-close">X Close</div>');
            $('.pup-close');
            $('.pup-win').fadeTo(objOptions.fade, 1);
            $('.pup-close').click(function(){
                $('.pup-win').fadeTo(objOptions.fade, 0, function(){
                    $('.pup-win').remove();
                });
            });
            setTimeout(function(){
                $('.pup-win').fadeTo(objOptions.fade, 0, function(){
                    $('.pup-win').remove();
                });
            }, objOptions.winTimeOut);
        }
    }
}(jQuery);

var GPR_COOKIES = function($){
    return {
        /**
         * COOKIES
         * Create a cookie
         * @param {String} strName
         * @param {String} strValue
         * @param {Integer} intDays
         */
        create: function(strName, strValue, intDays){
            var strExpires = "";
            if (intDays) {
                var dteDate = new Date();
                dteDate.setTime(dteDate.getTime() + (intDays * 24 * 60 * 60 * 1000));
                strExpires = "; expires=" + dteDate.toGMTString();
            }
            document.cookie = strName + "=" + escape(strValue) + strExpires + "; path=/";
        },
        /**
         * COOKIES
         * Read a cookie
         * @param {String} strName
         */
        read: function(strName){
            var strStart = "", strEnd = "";
            if (document.cookie.length > 0) {
                strStart = document.cookie.indexOf(strName + "=");
                if (strStart != -1) {
                    strStart = strStart + strName.length + 1;
                    strEnd = document.cookie.indexOf(";", strStart);
                    if (strEnd == -1) {
                        strEnd = document.cookie.length;
                    }
                    return unescape(document.cookie.substring(strStart, strEnd));
                }
            }
            return null;
        },
        /**
         * COOKIES
         * Erase a cookie
         * @param {String} strName
         */
        erase: function(strName){
            this.create(strName, "", -1);
        }
    }
}(jQuery);

var GPR_OPTIONS = function($){
    var objOptions = {
        loginURL: document.location,
        cartURL: document.location,
        checkoutURL: document.location,
        siteNumber: 1,
        customerId: "",
        companyId: ""
    };
    
    return {
        /**
         * POP UP MESSAGGES
         * Init
         * @param {Object} objOptions
         */
        init: function(obj){
            if (obj !== null && obj !== undefined) {
                $.extend(objOptions, obj);
            }
        },
        
        options: function(){
            return objOptions;
        },
		
        getUrlVar: function(name){
            var regexS = "[\\?&]"+name+"=([^&#]*)";
			var regex = new RegExp ( regexS );
			var tmpURL = window.location.href;
			var results = regex.exec( tmpURL );
			if( results == null )
				return"";
			else
				return results[1]; 
        }
    }
    
}(jQuery);

var GPR_AJAX_TOOLS = function($){
    var objOptions = {
        loadingImgURL: ""
    };
    return {
        /**
         * AJAX TOOLS
         * Init
         * @param {Object} objOptions
         */
        init: function(obj){
            if (obj !== null && obj !== undefined) {
                $.extend(objOptions, obj);
            }
        },
        /**
         * AJAX TOOLS
         * Starts Loading ajax request
         * @param {String} strCntId
         * @param {String} strMsg
         */
        startLoading: function(strCntId, strMsg){
            $("#" + strCntId + " .gpr-loading").remove();
            $("#" + strCntId + " .gpr-errors").remove();
            $("#" + strCntId).append('<div class="gpr-loading"><span>' + strMsg + '</span><img src="' + objOptions.loadingImgURL + '"/></div>');
        },
        
        /**
         * AJAX TOOLS
         * Show ajax request errors
         * @param {String} strCntId
         */
        stopLoading: function(strCntId){
            $("#" + strCntId + " .gpr-loading").remove();
            $("#" + strCntId + " .gpr-errors").remove();
        },
        
        /**
         * AJAX TOOLS
         * Show ajax request errors
         * @param {String} strCntId
         * @param {String} strSource
         * @param {String} strCode
         * @param {String} strDetails
         */
        showError: function(strCntId, strSource, strCode, strDetails){
            $("#" + strCntId + " .gpr-loading").remove();
            $("#" + strCntId + " .gpr-errors").remove();
            $("#" + strCntId).append('<div class="gpr-errors">' + strSource + ", code: " + unescape(strCode) + ", details: " + unescape(strDetails) + '</div>');
        }
    }
}(jQuery);

