var BrowserDetect = { init: function() { this.browser = this.searchString(this.dataBrowser) || "An unknown browser"; this.version = this.searchVersion(navigator.userAgent) || this.searchVersion(navigator.appVersion) || "an unknown version"; this.OS = this.searchString(this.dataOS) || "an unknown OS" }, searchString: function(data) { for (var i = 0; i < data.length; i++) { var dataString = data[i].string; var dataProp = data[i].prop; this.versionSearchString = data[i].versionSearch || data[i].identity; if (dataString) { if (dataString.indexOf(data[i].subString) != -1) return data[i].identity } else if (dataProp) return data[i].identity } }, searchVersion: function(dataString) { var index = dataString.indexOf(this.versionSearchString); if (index == -1) return; return parseFloat(dataString.substring(index + this.versionSearchString.length + 1)) }, dataBrowser: [{ string: navigator.userAgent, subString: "Chrome", identity: "Chrome" }, { string: navigator.userAgent, subString: "OmniWeb", versionSearch: "OmniWeb/", identity: "OmniWeb" }, { string: navigator.vendor, subString: "Apple", identity: "Safari", versionSearch: "Version" }, { prop: window.opera, identity: "Opera" }, { string: navigator.vendor, subString: "iCab", identity: "iCab" }, { string: navigator.vendor, subString: "KDE", identity: "Konqueror" }, { string: navigator.userAgent, subString: "Firefox", identity: "Firefox" }, { string: navigator.vendor, subString: "Camino", identity: "Camino" }, { string: navigator.userAgent, subString: "Netscape", identity: "Netscape" }, { string: navigator.userAgent, subString: "MSIE", identity: "Explorer", versionSearch: "MSIE" }, { string: navigator.userAgent, subString: "Gecko", identity: "Mozilla", versionSearch: "rv" }, { string: navigator.userAgent, subString: "Mozilla", identity: "Netscape", versionSearch: "Mozilla"}], dataOS: [{ string: navigator.platform, subString: "Win", identity: "Windows" }, { string: navigator.platform, subString: "Mac", identity: "Mac" }, { string: navigator.userAgent, subString: "iPhone", identity: "iPhone/iPod" }, { string: navigator.platform, subString: "Linux", identity: "Linux"}] };
var screenshotPreview = function() { xOffset = 10; yOffset = 30; $("a.screenshot").hover(function(e) { this.t = this.title; this.title = ""; var c = (this.t != "") ? "<br/>" + this.t : ""; $("body").append("<p id='screenshot'><img src='" + this.rel + "' alt='loading...' />" + c + "</p>"); $("#screenshot").css("top", (e.pageY - xOffset) + "px").css("left", (e.pageX + yOffset) + "px").fadeIn("fast") }, function() { this.title = this.t; $("#screenshot").remove() }); $("a.screenshot").mousemove(function(e) { $("#screenshot").css("top", (e.pageY - xOffset) + "px").css("left", (e.pageX + yOffset) + "px") }) };
if (typeof ZOOMIN == "undefined") { var ZOOMIN = {} } ZOOMIN.namespace = function() { var obj = null, i, j, arr, res; res = true; try { for (i = 0; i < arguments.length; i++) { arr = arguments[i].split("."); obj = ZOOMIN; for (j = (arr[0] == "ZOOMIN") ? 1 : 0; j < arr.length; j++) { obj[arr[j]] = obj[arr[j]] || {}; obj = obj[arr[j]] } } } catch (e) { res = false } return res };

/**
* By Default add util namespace.
* The util namespace will have all the general utilities.
*/
ZOOMIN.namespace("ZOOMIN.util");
/**
* This class has all the generic utility functions.
* @requires ZOOMIN.util
* @class Util
* @constructor
* @namespace ZOOMIN.util
*/
ZOOMIN.util.Util = function() { };
(function() {
    var util = ZOOMIN.util.Util; //shorthand    
    /**
    * This checks whether all the images under a element are loaded
    * and makes a callback when all the images are loaded under the element
    * @static
    * @method checkAllImagesLoaded
    * 
    */
    util.checkAllImagesLoaded = function(parentElement) {
        var imgArray;
        var i = 0;
        var res = false;
        if (parentElement == window || !parentElement) {
            imgArray = document.getElementsByTagName('img');
        }
        else {
            imgArray = parentElement.getElementsByTagName('img');
        }

        for (i = 0; i < imgArray.length; i++) {
            res = util.isImageLoaded(imgArray[i]);
            if (!res) {
                break;
            }
        }
        return res;
    };
    /**
    * This checks whether the given image has completely loaded.
    * @method isImageLoaded
    * @static
    */
    util.isImageLoaded = function(img) {
        var res = false;
        if (img) {
            //check whether it is loaded yet.
            if (img.complete) {
                res = true;
            }
        }
        return res;
    };
    /**
    * This function checks and notifies when all the images are loaded
    * in a element.
    * @method notifyImageLoad
    * @static
    */
    util.notifyImageLoad = function(element, callback, scope) {
        var timerId; //timer id when setting the interval
        var fn;

        fn = function() {
            var res;

            res = util.checkAllImagesLoaded(element);
            if (res) {
                window.clearInterval(timerId);
                if (callback && callback.call) {
                    scope = scope || window; //default scope for callback
                    callback.call(scope, element);
                }
            }
        };
        timerId = window.setInterval(fn, 1000);
    };
    /**
    * This function adds a parameter to the url
    * @method addUrlParam
    * @static
    */
    util.addUrlParam = function(url, paramName, paramValue) {
        if (url) {
            url = url + ((url.indexOf("?") > -1) ? "&" : "?") + paramName + "=" + paramValue;
        }
        return url;
    };
    /**
    * initializes the properties with default values
    * @param {Object} options value to be copied from
    * @param {Object} def default values
    * @return {Object} object with default values
    */
    util.initializeOptions = function(options, def) {
        options = options || {};
        def = def || {};
        for (var i in def) {
            if (util.hasOwnProperty(def, i)) {
                options[i] = options[i] || def[i];
            }
        }
        return options;
    };
    /**
    * Determines whether or not the property was added
    * to the object instance.  Returns false if the property is not present
    * in the object, or was inherited from the prototype.
    * @param {Object} o
    * @param {Object} prop
    * @see YAHOO.lang.hasOwnProperty
    */
    util.hasOwnProperty = function(o, prop) {
        if (Object.prototype.hasOwnProperty) {
            return o.hasOwnProperty(prop);
        }
        return (
			(typeof o[prop] !== "undefined") &&
			(o.constructor.prototype[prop] !== o[prop])
		);
    };
    /**
    * This creates a function to be called with the given scope.
    * This uses Function.apply to call the given function
    * @param {Function} fn pointer to the callback function
    * @param {Object} scope scope of the function to be called
    * @return {Function} a new function which will make a call to given function based on scope
    */
    util.bind = function(fn, scope) {
        scope = scope || window;
        //check whether it is a function
        if (!jQuery.isFunction(fn)) {
            throw new Error("not a valid function pointer");
        }
        return function() {
            //pass all the arguments and return whatever the function returns
            return fn.apply(scope, arguments);
        };
    };


    /**
    * Functions to read a cookie, create and delte
    */
    util.readCookie = function(name) {
        var nameEQ = name + "=";
        var ca = document.cookie.split(';');
        for (var i = 0; i < ca.length; i++) {
            var c = ca[i];
            while (c.charAt(0) == ' ') c = c.substring(1, c.length);
            if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length);
        }
        return null;
    };
    util.createCookie = function(name, value, days) {
        if (days) {
            var date = new Date();
            date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
            var expires = "; expires=" + date.toGMTString();
        }
        else var expires = "";
        document.cookie = name + "=" + value + expires + "; path=/";
    }
    util.eraseCookie = function(name) {
        createCookie(name, "", -1);
    };
    util.gup = function(name) {
        name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
        var regexS = "[\\?&]" + name + "=([^&#]*)";
        var regex = new RegExp(regexS);
        var results = regex.exec(window.location.href);
        if (results == null)
            return "";
        else
            return results[1];
    };
    var arrImages = new Array();
    util.preloadImages = function(imgList, folder) {
        var currentIndex = arrImages.length;
        if (currentIndex > 0) currentIndex--;
        for (i = 0; i < imgList.length; i++) {
            arrImages[currentIndex] = new Image();
            arrImages[currentIndex].src = globalImageRoot + folder + imgList[i];
            currentIndex++;
        }
    };
    /**
    * to avoid console.log
    */
    if (typeof console === "undefined") {
        console = {};
    }
    if (typeof console.log === "undefined") {
        console.log = function() {
            //empty function when console.log does not exist
        };
    }

})();

/**
* Open popup window
*
* Opens a popup window using as little as a URL. An optional params object can
* be passed.
*
* @param {String} href
* @param {Object} params
* @return {WindowObjectReference}
*/
ZOOMIN.namespace("ZOOMIN.Popup");
(function() {
    var popup = ZOOMIN.Popup; //shorthand
    var windowObject = null;
    var objBoxy = null;
    /*
    jQuery.ajax({
        url: "/Error/PopupOpened", type: 'GET', dataType: 'html', cache: false, success: function(html) {
            objBoxy = new Boxy(html, { height: 'auto', width: '325px', title: 'Switch to your new window', modal: true, show: false, unloadOnHide: false }); ;
        }
    });
    */
    popup.open = function(href, params, width, height) {
        // Defaults (don't leave it to the browser)
        var defaultParams = {
            "width": width,   // Window width
            "height": height,   // Window height
            "top": "0",     // Y offset (in pixels) from top of screen
            "left": "0",     // X offset (in pixels) from left side of screen
            "directories": "no",    // Show directories/Links bar?
            "location": "no",    // Show location/address bar?
            "resizeable": "yes",   // Make the window resizable?
            "menubar": "no",    // Show the menu bar?
            "toolbar": "no",    // Show the tool (Back button etc.) bar?
            "scrollbars": "yes",   // Show scrollbars?
            "status": "no"     // Show the status bar?
        };

        var windowName = params["windowName"] || "new_window";

        var i, useParams = "";

        // Override defaults with custom values while we construct the params string
        for (i in defaultParams) {
            useParams += (useParams === "") ? "" : ",";
            useParams += i + "=";
            useParams += params[i] || defaultParams[i];
        }

        return window.open(href, windowName, useParams);
    };
    popup.getPopup = function(event, obj, width, height) {
        try {
            // Prevent the browser's default onClick handler
            if (event !== null)
                event.preventDefault();

            // Grab parameters using jQuery's data() method
            var params = $(obj).data("zpopup") || {};

            // Use the target attribute as the window name
            if ($(obj).attr("target")) {
                params.windowName = $(obj).attr("target");
            }

            // Pop up the window
            var windowObject = popup.open(obj.href, params, width, height);

            // Save the window object for other code to use
            $(obj).data("windowObject", windowObject);

            return windowObject;
        }
        catch (ex) {
            throw (ex);
        }
    };
    popup.gotoPopup = function() {
        windowObject.focus();
    };
    popup.checkForClosed = function() {
        if (!windowObject.closed) setTimeout(popup.checkForClosed, 500);
        else {
            if (objBoxy != null) objBoxy.hide();
        }
    };
    popup.openPopup = function(event, obj) {
        windowObject = this.getPopup(event, obj, screen.width, screen.height);
        if (windowObject == null) {
            new Boxy.load("/Error/PopupBlocked?Browser=" + BrowserDetect.browser, { height: '450px', width: '542px', titleClass: 'altHeader', title: 'Popup was blocked!!', modal: true });
        }
        else {
            //objBoxy.load("/Error/PopupOpened", {});
            objBoxy.show();
            popup.checkForClosed();
        }
    };

})();
ZOOMIN.namespace("ZOOMIN.Common");
(function() {
    var common = ZOOMIN.Common;
    var zoominImportUrl = '/MyAccount/ImportAddress';
    var abZoominWin;

    common.Url = {

        // public method for url encoding
        encode: function(string) {
            return escape(this._utf8_encode(string));
        },

        // public method for url decoding
        decode: function(string) {
            return this._utf8_decode(unescape(string));
        },

        // private method for UTF-8 encoding
        _utf8_encode: function(string) {
            string = string.replace(/\r\n/g, "\n");
            var utftext = "";

            for (var n = 0; n < string.length; n++) {

                var c = string.charCodeAt(n);

                if (c < 128) {
                    utftext += String.fromCharCode(c);
                }
                else if ((c > 127) && (c < 2048)) {
                    utftext += String.fromCharCode((c >> 6) | 192);
                    utftext += String.fromCharCode((c & 63) | 128);
                }
                else {
                    utftext += String.fromCharCode((c >> 12) | 224);
                    utftext += String.fromCharCode(((c >> 6) & 63) | 128);
                    utftext += String.fromCharCode((c & 63) | 128);
                }

            }

            /*Encoding '+'*/
            var encodedCharacters = new Array('+');
            var decodedCharacters = new Array('%2B');
            for (var i = 0; i < encodedCharacters.length; i++) {
                utftext =
        utftext.replace(encodedCharacters[i], decodedCharacters[i]);
            }
            return utftext;
        },

        // private method for UTF-8 decoding
        _utf8_decode: function(utftext) {
            var string = "";
            var i = 0;
            var c = c1 = c2 = 0;

            while (i < utftext.length) {

                c = utftext.charCodeAt(i);

                if (c < 128) {
                    string += String.fromCharCode(c);
                    i++;
                }
                else if ((c > 191) && (c < 224)) {
                    c2 = utftext.charCodeAt(i + 1);
                    string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
                    i += 2;
                }
                else {
                    c2 = utftext.charCodeAt(i + 1);
                    c3 = utftext.charCodeAt(i + 2);
                    string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
                    i += 3;
                }

            }
            /*decoding '+'*/
            var encodedCharacters = new Array('+');
            var decodedCharacters = new Array('%2B');
            for (var i = 0; i < decodedCharacters.length; i++) {
                string =
         string.replace(decodedCharacters[i], encodedCharacters[i]);
            }
            return string;
        }

    };

    common.alphnumber = function(evt) {
        //var charCode = (evt.which) ? evt.which : event.keyCode
        var charCode = (window.event) ? evt.keyCode : evt.which;
        if (charCode == 8 || charCode == 9 || charCode == 13 || charCode == 0)
            return true;
        if ((charCode < 48 || charCode > 57) && (charCode < 65 || charCode > 90) && (charCode < 97 || charCode > 122))
            return false;

        return true;
    };

    common.isSpecialKey = function(evt) {
        var charCode = (window.event) ? evt.keyCode : evt.which;
        if (charCode == 38 || charCode == 39 || charCode == 40 || charCode == 41)
            return true;
        if (charCode == 92 || charCode == 222)// || (charCode==34  charCode==39)
            return false;
        if ((charCode > 36 && charCode < 42) || (charCode > 57 && charCode < 64))
            return false;
        return true;
    };

    common.isNumeric = function() {
        var e = arguments[0] || event;
        var charCode = (window.event) ? e.keyCode : e.which;
        if (charCode > 31 && (charCode < 48 || charCode > 57))
            return false;
        return true;
    };

    common.trim = function(str) {
        return str.replace(/^\s+|\s+$/g, '');
    };

    common.ClearTextOnFocus = function(element) {
        ctrlDefaultText = $(element).val();
        $(element).val('');
    };

    common.LoadDefaultText = function(element) {
        if ($(element).val() == '') {
            $(element).val(ctrlDefaultText);
        }
    };

    common.CheckEnterKeyClicked = function(element) {
        var e = arguments[0] || event;
        if (e.which || e.keyCode) {
            if ((e.which == 13) || (e.keyCode == 13)) {
                element.click(); return false;
            }
        } else { return true };
    };

    common.ValidateEmailID = function(emailadd) {
        var reg = /^([A-Za-z0-9_+\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
        if (reg.test(emailadd) == false) {
            return false;
        }
        else { return true; }
    };

    common.getXmlString = function(objXML) {
        alert('inside string ');

        if (document.implementation.createDocument)
            objXML.responseText;
        else
            objXML.xml;
    };

    common.importaddress = function(type) {
        var params = 'width=470px,height=518px,status=no,toolbar=no,menubar=no,resizable=0,scrollbars=no,directories=no';

        var hostName = $('#hdnUrl').val();
        if (hostName == "") {
            urlToOpen = window.location.protocol + '//' + window.location.hostname + zoominImportUrl + "?controlid=" + type, 'ZoominImport';
        }
        else if (hostName.indexOf('http') == -1) {
            urlToOpen = window.location.protocol + '//' + hostName + zoominImportUrl + "?controlid=" + type, 'ZoominImport';
        }
        else {
            urlToOpen = hostName + zoominImportUrl + "?controlid=" + type, 'ZoominImport';
        }
        new Boxy.load(urlToOpen, {
            title: "Address Importer",
            width: "470px",
            height: "437px",
            modal: true,
            actuator: $('#hancImport')[0]
        });
        if ($('#btnNextStep').length)
            $('#btnNextStep')[0].focus();
    };

    common.GetUserCheckOutAddress = function() {
        $.ajax({
            type: "GET",
            url: "/Account/GetUserAddressForCheckOut",
            dataType: "json",
            success: function(json) {
                var data = json.address;
                for (var i = 0; i < data.length; i++) {


                }
            }
        });
    };
    common.GetCheckOutCountries = function() {
        $.ajax({
            type: "GET",
            url: "/Account/GetCheckOutCountries",
            dataType: "json",
            success: function(json) {
            }
        });
    };
    common.GetCheckOutStates = function(countryGuid) {
        $.ajax({
            type: "GET",
            url: "/Account/GetCheckOutStates?countryguid=" + countryGuid,
            dataType: "json",
            success: function(json) {
            }
        });
    };
    common.ShowPriceBoxy = function(pricesDiv) {
        var options = {
            title: "Print Prices",
            closeable: true,
            draggable: true,
            modal: true,
            unloadOnHide: false,
            height: "300px",
            width: "350px"
        };
        var objBoxy = new Boxy($(pricesDiv), options);
    };

    common.IsValidUserName = function(evt) {
        var charCode = (window.event) ? evt.keyCode : evt.which;
        if (charCode == 8 || charCode == 9 || charCode == 13 || charCode == 0 || charCode == 46 || charCode == 45 || charCode == 95 || charCode == 8)
            return true;
        if ((charCode < 48 || charCode > 57) && (charCode < 65 || charCode > 90) && (charCode < 97 || charCode > 122))
            return false;

        return true;
    };

    common.DropdownToUL = function(valueattr, onChangeFunction) {
        var ts_selectclass = 'turnintodropdown'; 	// class to identify selects    

        var ts_boxclass = 'dropcontainer'; 		// parent element
        var ts_triggeron = 'activetrigger'; 		// class for the active trigger link
        var ts_triggeroff = 'trigger'; 		// class for the inactive trigger link
        var ts_dropdownclosed = 'dropdownhidden'; // closed dropdown
        var ts_dropdownopen = 'dropdownvisible'; // open dropdown
        if (valueattr == undefined) valueattr = "value";
        var count = 0;
        var toreplace = new Array();
        $("select." + ts_selectclass).each(function() {
            var objSelect = this;
            var $select = $(this);
            var $parent = $select.parent();
            var $hiddenfield = $("<input type='hidden'/>").attr("name", $select.attr("id")).attr("id", $select.attr("id")).val($('option:selected', $select).attr(valueattr));
            $parent.prepend($hiddenfield);
            var $trigger = $("<a/>").addClass(ts_triggeroff).attr("href", "#").append($("<span/>").html($('option:selected', $select).text()));
            $parent.append($trigger);
            var $dropdowndiv = $("<div/>").addClass(ts_boxclass);
            $parent.append($dropdowndiv);
            var $ul = $("<ul/>").addClass(ts_dropdownclosed);
            $dropdowndiv.append($ul);
            $trigger.click(function(e) {
                e.preventDefault();
                common.swapclass(this, ts_triggeroff, ts_triggeron)
                common.swapclass($ul[0], ts_dropdownclosed, ts_dropdownopen);
            });

            $select.find("option").each(function() {
                var name = $(this).attr(valueattr);
                if (name == undefined) name = "";
                var $li = $("<li/>").append($("<a/>").attr("href", "#").attr("name", name).html($(this).html()));
                $ul.append($li);
                $li.find("a").click(function(e) {
                    e.preventDefault();
                    $hiddenfield.val($(this).attr("name"));
                    common.swapclass($trigger[0], ts_triggeron, ts_triggeroff);
                    common.swapclass($ul[0], ts_dropdownopen, ts_dropdownclosed);
                    $trigger.find("span").html($(this).html());
                    if (onChangeFunction) onChangeFunction(this);
                });
            });
            $select.remove();
        });
    };
    common.swapclass = function(o, c1, c2) {
        var cn = o.className
        o.className = !$(o).hasClass(c1) ? cn.replace(c2, c1) : cn.replace(c1, c2);
    }
})();

function tamingselect() {
    if (!document.getElementById && !document.createTextNode) { return; }

    // Classes for the link and the visible dropdown

    /*
    Turn all selects into DOM dropdowns
    */
    
    var sels = document.getElementsByTagName('select');
    for (var i = 0; i < sels.length; i++) {
        if ($(sels[i]).hasClass(ts_selectclass)) {
            
            for (var j = 0; j < sels[i].getElementsByTagName('option').length; j++) {
                var newli = document.createElement('li');
                var newa = document.createElement('a');
                newli.v = sels[i].getElementsByTagName('option')[j].value;
                newli.elm = hiddenfield;
                newli.istrigger = trigger;
                newa.href = '#';
                newa.appendChild(document.createTextNode(
				sels[i].getElementsByTagName('option')[j].text));
                
                newli.appendChild(newa);
                replaceUL.appendChild(newli);
            }
            $(replaceUL).addClass(ts_dropdownclosed);
            var div = document.createElement('div');
            div.appendChild(replaceUL);
            $(div).addClass(ts_boxclass);
            sels[i].parentNode.insertBefore(div, sels[i])
            toreplace[count] = sels[i];
            count++;
        }
    }
    for (i = 0; i < count; i++) {
        toreplace[i].parentNode.removeChild(toreplace[i]);
    }
    
}


