﻿//alert("MANAGER IS CALLED");
jQuery.noConflict();
var counter = 0;
var counter1 = 0;
var firstLoad = 1;
var passAuxid = 0;

jQuery(document).ready(function(){    
	Cardthartic.initialize();
});

Cardthartic = {
    state: {
        //searchText: 'Enter keyword or Item#',
        searchText : ' Enter Item # for Quick Find',
        passwordFogotMessage_EmailSent: 'Email successfully sent.',
        passwordFogotMessage_EmailDoesNotExists: 'Email you entered is not registered. Check spelling and try again.',
        sendCardMessage_EmailSent: 'Email successfully sent.',
        sendCardMessage_ErrorSendingMail: "Error sending email. Check spelling repipient's and yours email and try again."
    },

    initialize: function() {
        //categories
        jQuery("div#navMenu ul.collapseExpand a").click(function() {
            var sender = jQuery(this);

            var isLeaf = sender.attr("isLeaf");
            if (isLeaf == "False") {
                Cardthartic.categoryClicked(sender);
                return false;
            }

            //            var LeadId = AIKON.CommerceLive.WebService.Lead.GetSessionLead();
            //            if (LeadId.value != '' && LeadId.value != null) {
            //                //counter = 1;
            //                jQuery("a.registration").html('Logged IN');
            //            }
        });

        Cardthartic.bindProductButtons();

        //search
        jQuery("div#search input.searchText").focus(function(e) {
            var value = jQuery(this).val();
            if (value == Cardthartic.state.searchText)
                jQuery(this).val('');
        });
        jQuery("div#search input.searchText").blur(function(e) {
            var value = jQuery(this).val();
            if (value == '')
                jQuery(this).val(Cardthartic.state.searchText);
        });
        jQuery("div#search input.searchText").keypress(function(e) {
            if (e.which == 13) {
                var search = jQuery(this).val();
                if (search != '' && search != Cardthartic.state.searchText)
                    window.location = "default.aspx?nodeid=2&text=" + search;

                e.stopPropagation();
                return false;
            }
        });
        jQuery("div#search input.searchButton").click(function(e) {
            var search = jQuery("div#search input.searchText").val();

            if (search != '' && search != Cardthartic.state.searchText)
                window.location = "default.aspx?nodeid=2&text=" + search;

            e.stopPropagation();
            return false;
        });

        //addressBook radio
        jQuery("div.scrollBox input[@type=radio]").click(function(e) {
            jQuery("div.scrollBox input[@type=radio]").attr("checked", false);
            jQuery(this).attr("checked", true);

            return false;
        });

        //forgotPassword
        jQuery("div.signin a#forgotPassword").click(function(e) {
            //new addition Harpal Singh
            jQuery("div.signin").hide();
            jQuery("div#forgotPasswordPopup").show();
            return false;
        });


        jQuery("div#forgotPasswordPopup a#close").click(function(e) {
            jQuery("div#forgotPasswordPopup").hide();
            jQuery("div#forgotPasswordPopup div#message").hide();
            jQuery("div#forgotPasswordPopup div#message").html('');
            jQuery("div#forgotPasswordPopup input#email").val('');

            return false;
        });
        // newly Added Harpal Singh
        jQuery("div#forgotPasswordPopup a#send").click(function(e) {
            var email = jQuery("div#forgotPasswordPopup input#email").val();
            var leadType = 1;
            AIKON.CommerceLive.WebService.Lead.PasswordForget(email, leadType, Cardthartic.passwordForget_Succeeded);

            return false;
        });
        //commented by harpal singh
        //        jQuery("div#forgotPasswordPopup a[leadType]").click(function(e) {
        //            var email = jQuery("div#forgotPasswordPopup input#email").val();
        //            var leadType = jQuery(this).attr("leadType");
        //            AIKON.CommerceLive.WebService.Lead.PasswordForget(email, leadType, Cardthartic.passwordForget_Succeeded);

        //            return false;
        //        });


        /// For registration POP UP
        jQuery("div.signin2 a#forgotPassword").click(function(e) {
            //new addition Harpal Singh
            jQuery("div.signin2").hide();
            jQuery("div#forgotPasswordPopup").show();
            return false;
        });


        jQuery("div#forgotPasswordPopup2 a#close").click(function(e) {
            jQuery("div#forgotPasswordPopup2").hide();
            jQuery("div#forgotPasswordPopup2 div#message").hide();
            jQuery("div#forgotPasswordPopup2 div#message").html('');
            jQuery("div#forgotPasswordPopup2 input#email").val('');

            return false;
        });
        // newly Added Harpal Singh
        jQuery("div#forgotPasswordPopup2 a#send").click(function(e) {
            var email = jQuery("div#forgotPasswordPopup2 input#email").val();
            var leadType = 1;
            AIKON.CommerceLive.WebService.Lead.PasswordForget(email, leadType, Cardthartic.passwordForget_Succeeded);

            return false;
        });

        jQuery("div.forgotPasswordPopup3 a.close").click(function(e) {
            jQuery("div.forgotPasswordPopup3").hide();
            jQuery("div.forgotPasswordPopup3 div.message").hide();
            jQuery("div.forgotPasswordPopup3 div.message").html('');
            jQuery("div.forgotPasswordPopup3 input.email").val('');

            return false;
        });
        // newly Added Harpal Singh
        jQuery("div.forgotPasswordPopup3 a.send").click(function(e) {
            //Cardthartic.closePopups();
            var container = jQuery("div.forgotPasswordPopup3");
            var email2 = container.find("input.email").val();
            var email = jQuery("div.forgotPasswordPopup3 input.email").val();
            alert(email);
            //email = jQuery("div.forgotPasswordPopup3 input.email").val();
            //alert(email);
            var leadType = 1;
            AIKON.CommerceLive.WebService.Lead.PasswordForget(email, leadType, Cardthartic.passwordForget_Succeeded3);

            return false;
        });

        //        passwordForget_Succeeded3: function(result) {
        //            var message = '';
        //            if (result.value)
        //                message = Cardthartic.state.passwordFogotMessage_EmailSent;
        //            else
        //                message = Cardthartic.state.passwordFogotMessage_EmailDoesNotExists;

        //            jQuery("div.forgotPasswordPopup3 div.message").html(message);
        //            jQuery("div.forgotPasswordPopup3 div.message").show();
        //        };


        // show submissionGuidelinesPopup na strani default.aspx?nodeid=813
        jQuery("a#submissionGuidelines").click(function(e) {
            jQuery("div#submissionGuidelinesPopup").show();
            return false;
        });
        jQuery("div#submissionGuidelinesPopup a#close").click(function(e) {
            jQuery("div#submissionGuidelinesPopup").hide();
            return false;
        });
        Cardthartic.showBanners();

        // registration, learn how link
        jQuery("a.securityLearnHow").click(function(e) {
            jQuery("div#securityLearnHowPopup").show();
            return false;
        });
        jQuery("div#securityLearnHowPopup a#close").click(function(e) {
            jQuery("div#securityLearnHowPopup").hide();
            return false;
        });

        // show retailer coming soon
        //        jQuery("div#mainNav ul li a:last").click(function(e) {
        //            var popup = jQuery("div.retailerPopup");
        //            jQuery("div.retailerPopup").show();
        //            return false;
        //        });
        jQuery("a.registerRetailer").click(function(e) {
            Cardthartic.closePopups();
            jQuery("div.retailerPopup").show();
            return false;
        });
        jQuery("div.retailerPopup a#close").click(function(e) {
            jQuery("div.retailerPopup").hide();
            return false;
        });
        jQuery("div.comingSoonPopup a#comingSoonPopupClose").click(function(e) {
            jQuery("div.comingSoonPopup").hide();
            return false;
        });

        // creditCardEdit, show security code info
        jQuery("a#securityCode").click(function(e) {
            jQuery("div#securityCodePopup").show();
            return false;
        });
        jQuery("div#securityCodePopup a#close").click(function(e) {
            jQuery("div#securityCodePopup").hide();
            return false;
        });


        /*
        Ana je trazila da se za sada skine.
        jQuery("div#calloutLink").mouseover(function(){
        jQuery("div#shadebox").show();
        }).mouseout(function(){
        jQuery("div#shadebox").hide();
        });
        jQuery("div#footer").mouseover(function(){
        jQuery("div#shadebox").show();
        }).mouseout(function(){
        jQuery("div#shadebox").hide();
        });
        */
    },
    bindProductButtons: function() {
        //products //add to shopping cart
        jQuery("div.card a.cardButton[@name=addToCart]").click(function() {
            Cardthartic.closeAddToCardPopups();
            var productId = jQuery(this).attr("auxId");
            var container = jQuery("div.addToCardPopup[@auxId=" + productId + "]");
            container.show();
            return false;
        });
        jQuery("div.magnet a.cardButton[@name=addToCart]").click(function() {
            Cardthartic.closeAddToCardPopups();
            var productId = jQuery(this).attr("auxId");
            var container = jQuery("div.addToCardPopup[@auxId=" + productId + "]");
            container.show();
            return false;
        });

        jQuery("div.popup_content a.cardButton[@name=addToCart]").click(function() {
            // ovako je bilo pre, pa sad hoce da se vidi novi popup sa dropdownom Cardthartic.addToCart(jQuery(this));
            Cardthartic.closePopups();
            Cardthartic.closeAddToCardPopups();
            var productId = jQuery(this).attr("auxId");
            var container = jQuery("div.addToCardPopup[@auxId=" + productId + "]");
            container.show();
            return false;
        });

        jQuery("div.addToCardPopup a.formButton1[@name=addToCardButton]").click(function() {
            Cardthartic.addToCart(jQuery(this));
            return false;
        });
        jQuery("a.productInfo").click(function(event) {
            Cardthartic.closePopups();
            var productId = jQuery(this).attr("auxId");
            var container = jQuery("div.productInfo[@auxId=" + productId + "]");
            Cardthartic.setPopupPosition(container)
            container.show();
            return false;
        });
        jQuery("div.productInfo a.close").click(function() {
            Cardthartic.closePopups();
            return false;
        });
        jQuery("div.addToCardPopup a.close").click(function() {
            Cardthartic.closeAddToCardPopups();
            return false;
        });
        /// Added By Harpal Singh For Registartion Form
        jQuery("a.registration").click(function() {

            var LeadId = AIKON.CommerceLive.WebService.Lead.GetSessionLead();
            if (LeadId.value != '' && LeadId.value != null) {
                counter = 1;
            }
            else {
                counter = 0;
            }

            if (counter === 0) {
                //window.location = "default.aspx?nodeid=2&ctgid=5&PageNo=25";
                //            //window.location = "default.aspx?nodeid=2&text=" + search;
                Cardthartic.closePopups();
                jQuery("div.registration div.message").hide();
                jQuery("div.registration div.message").html('');
                //            jQuery("div.registration input#txtMemberName").val('zal400@aol.com');
                //            jQuery("div.registration input#txtPassword").val('mmb032148');
                jQuery("div.registration input#txtMemberName").val('');
                jQuery("div.registration input#txtPassword").val('');
                var productId = jQuery(this).attr("auxId");
                //var container = jQuery("div.registration");
                var container = jQuery("div.registration[@auxId=" + productId + "]");
                Cardthartic.setPopupPosition(container)
                container.show();
                return false;
            }
            else if (counter === 1) {
                alert("already registered no need to register again");
            }
        });

        //        jQuery("a.registration").mouseover(function() {
        //            //alert("mouse over");
        //            //jQuery("a.registration").disabled = true;
        ////            var LeadId = AIKON.CommerceLive.WebService.Lead.GetSessionLead();
        ////            if (LeadId.value != '' && LeadId.value != null) {
        ////                counter = 1;
        ////            }
        ////            return false;

        //        });

        jQuery("div.registration a.close").click(function() {
            Cardthartic.closePopups();
            return false;
        });

        jQuery("div.registration").keypress(function(e) {
            if (e.which == 13) {
                //alert("enter pressed");
                //jQuery("div.registration a.login").click();
                //Cardthartic.closePopups();
                Cardthartic.closePopups();
                var productId = jQuery(this).attr("auxId");
                var container;
                if (productId)
                    container = jQuery("div.registration[auxId=" + productId + "]");
                else
                    container = jQuery("div.registration");

                var email = container.find("input#txtMemberName").val();
                //           window.location = "default.aspx?nodeid=25";
                var pwd = container.find("input#txtPassword").val();
                var remember = container.find("input#ChkBoxRemember").val();
                if (email != '' && pwd != '') {
                    //alert("Login SuccessFul");
                    var lead = AIKON.CommerceLive.WebService.Lead.DoLogin(email, pwd, remember);
                    if (lead.value == false) {
                        lead.value = "User not Found Please Register";
                        alert(lead.value);
                    }
                    else {
                        window.location = location.href;
                    }
                }
            }
            return true;

        });



        jQuery("div.orderbar").click(function() {
            var LeadId = AIKON.CommerceLive.WebService.Lead.GetSessionLead();
            if (LeadId.value == '' || LeadId.value == null) {
                var container = jQuery("div.signin");
                Cardthartic.setPopupPosition(container)
                container.show();
            }
        });


        jQuery("div.registration a.login").click(function() {

            alert("login button clicked");
            //Cardthartic.closePopups();
            container = jQuery("div.registration");
            alert(container);
            var email = container.find("input#txtMemberName").val();
            alert(email);
            //           window.location = "default.aspx?nodeid=25";
            var pwd = container.find("input#txtPassword").val();
            alert(pwd);
            var remember = container.find("input#ChkBoxRemember").val();
            if (email != '' && pwd != '') {
                //alert("Login SuccessFul");
                var lead = AIKON.CommerceLive.WebService.Lead.DoLogin(email, pwd, remember);
                if (lead.value == false) {
                    lead.value = "User not Found Please Register";
                    alert(lead.value);
                }
                else {
                    window.location = location.href;
                }
            }
            return false;
        });

        jQuery("div.registration a.RegisterNow").click(function() {
            //alert("new register clicked");
            Cardthartic.closePopups();
            window.location = "default.aspx?nodeid=24";
        });

        // commented before there was no popup i added................
        //        jQuery("div.registration a.ForgotPassword").click(function(e) {
        //            var email = jQuery("div.registration input#txtMemberName").val();
        //            var leadType = 1; //jQuery(this).attr("leadType");
        //            alert(email);
        //            alert(leadType);
        //            if (email != '' && email != null) {
        //                AIKON.CommerceLive.WebService.Lead.PasswordForget(email, leadType, Cardthartic.passwordForget_Succeeded);
        //            }
        //            else {
        //                alert("atleast email is required");
        //            }
        //            return false;
        //        });

        jQuery("div.registration a.ForgotPassword").click(function() {
            jQuery("div.registration").hide();
            //jQuery("div.forgotPasswordPopup3").show();
            jQuery("div#forgotPasswordPopup").show();
        });


        jQuery("div.NewRegisterForm a.close").click(function() {
            Cardthartic.closePopups();
        });

        jQuery("div.AddToCartPopup a.close").click(function() {
            Cardthartic.closePopups();
        });




        jQuery("div.card a.cardButton[@name=addToCartButtonNew],div.magnet a.cardButton[@name=addToCartButtonNew]").click(function() {

            //event.stopImmediatePropagation();
            var LeadId = AIKON.CommerceLive.WebService.Lead.GetSessionLead();
            //alert(LeadId.value);
            //AIKON.CommerceLive.WebService.Lead.GetSessionLead(Cardthartic.GetSessionLead_Succeeded);
            if (LeadId.value == '' || LeadId.value == null) {
                //jQuery("div.addtocartpopup").show();
                var container = jQuery("div.signin");
                Cardthartic.setPopupPosition(container)
                container.show();
                //alert("register or login before adding to cart");
            }
            else {
                //var leadid = 1;
                var quantity = 1;
                var addressID = 0;
                var auxId = jQuery(this).attr("auxId");
                //var addressBox = jQuery("div.cardLeft select.addressSelect[@auxId =" + auxId + "]");
                //var quantityBox = jQuery("div.cardLeft input.quantity[@auxId=" + auxId + "]");


                var quantityBox = jQuery("input.quantity[@auxId=" + auxId + "]");
                var addressBox = jQuery("select.addressSelect[@auxId=" + auxId + "]");
                if (quantityBox != null)
                    quantity = quantityBox.val();
                if (addressBox != null)
                    addressID = addressBox.val();

                // commented for testing     
                //                var addressBox = jQuery("div.cardLeft select.addressSelect").attr("value");
                //                var Box = jQuery("div.cardLeft select.addressSelect");
                //                
                //                var quantityBox = jQuery("div.cardLeft input.quantity").attr("value");

                //                if (quantityBox != null)
                //                    quantity = quantityBox;
                //                if (addressBox != null)
                //                    addressID = addressBox;
                //var auxId = sender.attr("auxId");
                //                var auxId = jQuery("div.card a.cardButton[@name=addToCartButtonNew]").attr("auxId");
                //var auxId =  jQuery("div.cardLeft a.cardButton[@name=addToCartButtonNew]").attr("auxId");

                //var auxId = jQuery("div.cardLeft").attr("auxId");
                //var auxId = jQuery("div.card span.cardTitle").val();
                
                passAuxid = auxId;
                var productId = auxId;
                var isVariant = jQuery("div.card a.cardButton[@name=addToCartButtonNew],div.magnet a.cardButton[@name=addToCartButtonNew]").attr("isVariant");
                if (isVariant == 'True')
                    window.location = "default.aspx?nodeid=601&p=" + auxId;
                else {
                    //if (objPO)
                    //if (counter1 % 2 == 0) {
                    //                    setTimeout(Cardthartic.TestTimeout, 20000);
                    //setTimeout (test(function (){}),20000);

                    AIKON.CommerceLive.WebService.ShoppingCart.AddWithAddress(LeadId.value, productId, addressID, quantity, Cardthartic.updateOrderItemCount);
                    //  AIKON.CommerceLive.WebService.ShoppingCart.AddWithAddress(objPO.LeadID, productId, addressID, quantity, Cardthartic.addToShoppingCart_Succeeded);
                    //  counter1 = counter1 + 1;
                    //}
                    return false;
                }

            }
            return false;

        });




        //                GetSessionLead_Succeeded: function(LeadId) {
        //                if (LeadId.value == '' || LeadId.value == null) {
        //                    var container = jQuery("div.addtocartpopup");
        //                    Cardthartic.setPopupPosition(container)
        //                    container.show();
        //                    //alert("register or login before adding to cart");
        //                }
        //                else {
        //                    //var leadid = 1;
        //                    var quantity = 1;
        //                    var addressID = 0;
        //                    var auxId = jQuery(this).attr("auxId");
        //        //            //var addressBox = jQuery("div.cardLeft select.addressSelect[@auxId =" + auxId + "]");
        //        //            //var quantityBox = jQuery("div.cardLeft input.quantity[@auxId=" + auxId + "]");


        //                    var quantityBox = jQuery("input.quantity[@auxId=" + auxId + "]");
        //                    var addressBox = jQuery("select.addressSelect[@auxId=" + auxId + "]");
        //                    if (quantityBox != null)
        //                        quantity = quantityBox.val();
        //                    if (addressBox != null)
        //                        addressID = addressBox.val();

        //                    // commented for testing     
        //        //            //                var addressBox = jQuery("div.cardLeft select.addressSelect").attr("value");
        //        //            //                var Box = jQuery("div.cardLeft select.addressSelect");
        //        //            //                
        //        //            //                var quantityBox = jQuery("div.cardLeft input.quantity").attr("value");

        //        //            //                if (quantityBox != null)
        //        //            //                    quantity = quantityBox;
        //        //            //                if (addressBox != null)
        //        //            //                    addressID = addressBox;
        //        //            //var auxId = sender.attr("auxId");
        //        //            //                var auxId = jQuery("div.card a.cardButton[@name=addToCartButtonNew]").attr("auxId");
        //        //            //var auxId =  jQuery("div.cardLeft a.cardButton[@name=addToCartButtonNew]").attr("auxId");

        //        //            //var auxId = jQuery("div.cardLeft").attr("auxId");
        //        //            //var auxId = jQuery("div.card span.cardTitle").val();
        //                    var productId = auxId;
        //                    var isVariant = jQuery("div.card a.cardButton[@name=addToCartButtonNew]").attr("isVariant");
        //                    if (isVariant == 'True')
        //                        window.location = "default.aspx?nodeid=601&p=" + auxId;
        //                    else {
        //        //                //if (objPO)
        //        //                //if (counter1 % 2 == 0) {
        //                        AIKON.CommerceLive.WebService.ShoppingCart.AddWithAddress(LeadId.value, productId, addressID, quantity, Cardthartic.addToShoppingCart_Succeeded);
        //        //                //  AIKON.CommerceLive.WebService.ShoppingCart.AddWithAddress(objPO.LeadID, productId, addressID, quantity, Cardthartic.addToShoppingCart_Succeeded);
        //        //                //  counter1 = counter1 + 1;
        //        //                //}
        //                    }
        //                }
        //                
        //                }


        jQuery("a[@name=sendecard]").click(function(event) {
            //            Cardthartic.closePopups();
            //            if (jQuery.browser.safari)
            //                top = document.body.scrollTop;
            //            else
            //                top = document.documentElement.scrollTop;
            //            jQuery("div.comingSoonPopup").css("top", top);
            //            jQuery("div.comingSoonPopup").css("position", "absolute");
            //            jQuery("div.comingSoonPopup").show();
            //            return false;

            Cardthartic.closePopups();
            jQuery("div.sendecard div.message").hide();
            jQuery("div.sendecard div.message").html('');
            jQuery("div.sendecard input#txtRecipientsFirstName").val('');
            jQuery("div.sendecard input#txtRecipientsEmail").val('');
            jQuery("div.sendecard input#txtYourFirstName").val('');
            jQuery("div.sendecard input#txtYourEmail").val('');
            jQuery("div.sendecard textarea#txtPersonalizedMessage").val('');
            jQuery("div.sendecard input#txtSignedBy").val('');
            var productId = jQuery(this).attr("auxId");
            var container = jQuery("div.sendecard[@auxId=" + productId + "]");
            Cardthartic.setPopupPosition(container)
            container.show();
            return false;

        });
        jQuery("a[@name=sendExperienceECard]").click(function(event) {
            Cardthartic.closePopups();
            jQuery("div.sendecard div.message").hide();
            jQuery("div.sendecard div.message").html('');
            jQuery("div.sendecard input#txtRecipientsFirstName").val('');
            jQuery("div.sendecard input#txtRecipientsEmail").val('');
            jQuery("div.sendecard input#txtYourFirstName").val('');
            jQuery("div.sendecard input#txtYourEmail").val('');
            jQuery("div.sendecard textarea#txtPersonalizedMessage").val('');
            jQuery("div.sendecard input#txtSignedBy").val('');
            var container = jQuery("div.sendecard");
            Cardthartic.setPopupPosition(container)
            container.show();
            return false;
        });
        jQuery("div.sendecard a.send").click(function() {
            var productId = jQuery(this).attr("auxId");

            var container;
            if (productId)
                container = jQuery("div.sendecard[auxId=" + productId + "]");
            else
                container = jQuery("div.sendecard");

            var recipientsFirstName = container.find("input#txtRecipientsFirstName").val();
            var recipientsEmail = container.find("input#txtRecipientsEmail").val();
            var yourFirstName = container.find("input#txtYourFirstName").val();
            var yourEmail = container.find("input#txtYourEmail").val();
            var personalizedMessage = container.find("textarea#txtPersonalizedMessage").val();
            var signedBy = container.find("input#txtSignedBy").val();

            var message = '';
            if (recipientsFirstName == '')
                message = "Recipient's first name is required.";
            else if (recipientsEmail == '')
                message = "Recipient's email address is required.";
            else if (yourFirstName == '')
                message = "Your first name is required.";
            else if (yourEmail == '')
                message = "Your email address is required.";
            else if (personalizedMessage == '')
                message = "Personalized message is required.";
            else if (signedBy == '')
                message = "Signed by is required.";

            if (message != '')
                message = "Error: Please confirm that you have entered all your information correctly and try sending again.";

            if (message != '') {
                jQuery("div.sendecard div.message").html(message);
                jQuery("div.sendecard div.message").show();
            }
            else {
                jQuery("div.sendecard div.message").html('');
                jQuery("div.sendecard div.message").hide();

                AIKON.CommerceLive.WebService.Lead.SendECard(productId, recipientsFirstName, recipientsEmail, yourFirstName, yourEmail, personalizedMessage, signedBy, Cardthartic.sendECard_Succeeded);
            }
            return false;
        });
        jQuery("div.sendecard a.close").click(function() {
            Cardthartic.closePopups();
            return false;
        });
        jQuery("a.enlarge").click(function(event) {
            Cardthartic.closePopups();

            var productId = jQuery(this).attr("auxId");
            var container = jQuery("div.enlarge[@auxId=" + productId + "]");

            Cardthartic.setPopupPosition(container)
            container.show();

            return false;
        });
        jQuery("a.front").mouseover(function(event) {
            var productId = jQuery(this).attr("auxId");
            var front = jQuery("img.frontPicture[@auxId=" + productId + "]");
            var inside = jQuery("img.insidePicture[@auxId=" + productId + "]");
            front.show();
            inside.hide();
            return false;
        });
        jQuery("a.inside").mouseover(function(event) {
            var productId = jQuery(this).attr("auxId");
            var front = jQuery("img.frontPicture[@auxId=" + productId + "]");
            var inside = jQuery("img.insidePicture[@auxId=" + productId + "]");
            front.hide();
            inside.show();
            return false;
        });
        jQuery("div.enlarge a.close").click(function() {
            Cardthartic.closePopups();
            return false;
        });
         jQuery("a.testfront").mouseover(function(event){
            //alert("mouseover");
            var productId = jQuery(this).attr("href");
            //alert(productId);            
            jQuery("img#largeBannerImg").attr('src',productId);            
            return false;
        }); 
        jQuery("a.testfront").mouseout(function(event){
            //alert("mouseout");
            var productId = jQuery("a.testfrontInside").attr("href");
            jQuery("img#largeBannerImg").attr('src',productId); 
            
            
            
            return false;
        }); 
                          
        
    },
    showBanners: function() {
        var rand = 0;
        var imgsPassages = new Array(
                            "images/cardthartic/banner_small_1.png",
                            "images/cardthartic/banner_small_1a.png",
                            "images/cardthartic/banner_small_1b.png"
                            );
        var imgsMeaningsOfLife = new Array(
                            "images/cardthartic/banner_small_2.png",
                            "images/cardthartic/banner_small_2a.png",
                            "images/cardthartic/banner_small_2b.png",
                            "images/cardthartic/banner_small_2c.png"
                            );
        var imgsLittleReminders = new Array(
                            "images/cardthartic/banner_small_3.png",
                            "images/cardthartic/banner_small_3a.png"
                            );
        var imgsFairyCardmother = new Array(
                            "images/cardthartic/banner_small_4.png",
                            "images/cardthartic/banner_small_4a.png",
                            "images/cardthartic/banner_small_4b.png"
                            );

        var linksPassages = new Array(
                             "default.aspx?nodeid=2&ctgid=47",
                             "default.aspx?nodeid=2&ctgid=47",
                             "default.aspx?nodeid=2&ctgid=47"
                             );
        var linksMeaningsOfLife = new Array(
                             "default.aspx?nodeid=2&ctgid=42",
                             "default.aspx?nodeid=2&ctgid=42",
                             "default.aspx?nodeid=2&ctgid=42",
                             "default.aspx?nodeid=2&ctgid=42"
                             );
        var linksLittleReminders = new Array(
                             "default.aspx?nodeid=2&ctgid=34",
                             "default.aspx?nodeid=2&ctgid=34"
                             );
        var linksFairyCardmother = new Array(
                             "default.aspx?nodeid=2&ctgid=29",
                             "default.aspx?nodeid=2&ctgid=29",
                             "default.aspx?nodeid=2&ctgid=29"
                             );

        var imgsLarge = new Array(
                            "images/cardthartic/banner_large_1.jpg",                             
                            "images/cardthartic/banner_large_2.jpg",                             
                            "images/cardthartic/banner_large_3.jpg", 
                            "images/cardthartic/banner_large_4.jpg", 
                            "images/cardthartic/banner_large_5.jpg", 
                            "images/cardthartic/banner_large_6.jpg", 
                            "images/cardthartic/banner_large_7.jpg", 
                            "images/cardthartic/banner_large_9.jpg", 
                            "images/cardthartic/banner_large_10.jpg", 
                            "images/cardthartic/banner_large_11.jpg"
                            );
                            
         var imgsLargeTurn = new Array(
                            "images/cardthartic/banner_large_1i.jpg",                           
			    "images/cardthartic/banner_large_2i.jpg",                           
                            "images/cardthartic/banner_large_3i.jpg", 
                            "images/cardthartic/banner_large_4i.jpg", 
                            "images/cardthartic/banner_large_5i.jpg", 
                            "images/cardthartic/banner_large_6i.jpg", 
                            "images/cardthartic/banner_large_7i.jpg", 
                            "images/cardthartic/banner_large_9i.jpg", 
                            "images/cardthartic/banner_large_10i.jpg", 
                            "images/cardthartic/banner_large_11i.jpg"
                            );

        var linksLarge = new Array(
                            "default.aspx?nodeid=2&ctgid=17&pageno=4",
                            "default.aspx?nodeid=2&ctgid=10&pageno=22",
                            "default.aspx?nodeid=2&ctgid=24&pageno=1",
                            "default.aspx?nodeid=2&ctgid=5&pageno=1",
                            "default.aspx?nodeid=2&ctgid=10&pageno=18",
                            "default.aspx?nodeid=2&ctgid=10&pageno=22",
                            "default.aspx?nodeid=2&ctgid=10&pageno=25",
                            "default.aspx?nodeid=2&ctgid=10&pageno=25",
                            "default.aspx?nodeid=2&ctgid=17&pageno=5",
                            "default.aspx?nodeid=2&ctgid=10&pageno=23",
                            "default.aspx?nodeid=2&ctgid=10&pageno=20",
                            "default.aspx?nodeid=2&ctgid=17&pageno=4",
                            "default.aspx?nodeid=2&ctgid=14&pageno=1",
                            "default.aspx?nodeid=2&ctgid=10&pageno=9",
                            "default.aspx?nodeid=2&ctgid=13&pageno=2",
                            "default.aspx?nodeid=2&ctgid=5&pageno=2",
                            "default.aspx?nodeid=2&ctgid=17&pageno=1"
                            );
        rand = Math.floor(imgsLarge.length * Math.random());
       //jQuery("img#largeBannerImg").attr('src',imgsLarge[rand]);    
        //jQuery("a#largeBannerLink").attr('href',imgsLarge[rand]);    
        //jQuery("a#largeBannerLink").attr('href',linksLarge[rand]);    
        jQuery("img#largeBannerImg").attr('src',imgsLarge[rand]);            
        jQuery("a#largeBannerLink").attr('href',imgsLargeTurn[rand]); 
        jQuery("a#largeBannerLinkInside").attr('href',imgsLarge[rand]); 
        
        //rand = Math.floor(imgsPassages.length * Math.random());
        //jQuery("a#smallBannerLink1").attr('href',linksPassages[rand]);    
        //jQuery("img#smallBannerImg1").attr('src',imgsPassages[rand]);    

        //rand = Math.floor(imgsMeaningsOfLife.length * Math.random());
        //jQuery("a#smallBannerLink2").attr('href',linksMeaningsOfLife[rand]);    
        //jQuery("img#smallBannerImg2").attr('src',imgsMeaningsOfLife[rand]);    

        //rand = Math.floor(imgsLittleReminders.length * Math.random());
        //jQuery("a#smallBannerLink3").attr('href',linksLittleReminders[rand]);    
        //jQuery("img#smallBannerImg3").attr('src',imgsLittleReminders[rand]);    

        //rand = Math.floor(imgsFairyCardmother.length * Math.random());
        //jQuery("a#smallBannerLink4").attr('href',linksFairyCardmother[rand]);    
        //jQuery("img#smallBannerImg4").attr('src',imgsFairyCardmother[rand]);    



    },

    // addToCart
    addToCart: function(sender) {
        var quantity = 1;
        var addressID = 0;
        var auxId = sender.attr("auxId");
        var isVariant = sender.attr("isVariant");
        var LeadID = sender.attr("LeadId");
        var quantityBox = jQuery("input.quantity[@auxId=" + auxId + "]");
        var addressBox = jQuery("select.addressSelect[@value=" + AddressID + "]");
        if (quantityBox != null)
            quantity = quantityBox.val();
        if (addressBox != null)
            addressID = addressBox.val();
        // if product is variant then redirect user to detail page to select one of child products    	        
        if (isVariant == 'True')
            window.location = "default.aspx?nodeid=601&p=" + auxId;
        else
            Cardthartic.addToShoppingCart(auxId, quantity, addressID);
        // Cardthartic.closeAddToCardPopups();            
    },
    addToShoppingCart: function(productId, quantity, addressID) {
        //Commented By HArpal Singh For his own Use
        if (objPO)
        //var LeadId = AIKON.CommerceLive.WebService.Lead.GetSessionLead();
            AIKON.CommerceLive.WebService.ShoppingCart.AddWithAddress(objPO.leadID, productId, addressID, quantity, Cardthartic.addToShoppingCart_Succeeded);
        //if (LeadId.value != '' && LeadId.value != null) {
        //  AIKON.CommerceLive.WebService.ShoppingCart.AddWithAddress(LeadId, productId, addressID, quantity, Cardthartic.addToShoppingCart_Succeeded);
        //}
    },
    addToShoppingCart_Succeeded: function(result) {
        // CardtharticShoppingPreview module is emitting this function;
        //Commented By Harpal Singh Because  the definatin is not there ..........
        //Cardthartic.updateOrderItemCount(result);
        //setTimeout(testtimeout, 200000);
        updateOrderItemCount(result);

        var itemsCount = Cardthartic.getOrderAttribute(result.value, 'order_total_items_count');
        //commented by Harpal Singh
        jQuery("label.itemCount").html(itemsCount);
        //jquery("label.OrderItemCount").html(itemsCount);
        /// added to rrefresh the page ...... Harpal Singh
        //window.location = location.href;
    },
    getOrderAttribute: function(order, attribute) {
        var orders = order.getElementsByTagName('Order');
        for (var i = 0; i < orders.length; i++) {
            orderAttibutes = orders[i].getElementsByTagName('OrderAtributes');
            attributes = orderAttibutes[0].getElementsByTagName('Attribute');
            for (var j = 0; j < attributes.length; j++) {
                if (attributes[j].getAttribute('name') == attribute)
                    return attributes[j].childNodes[0].data;
            }
        }
        // added to refresh the page becoz the particular update function was not firing....Harpal Singh
        //window.location = location.href;
        return null;
    },
    passwordForget_Succeeded: function(result) {
        var message = '';
        if (result.value)
            message = Cardthartic.state.passwordFogotMessage_EmailSent;
        else
            message = Cardthartic.state.passwordFogotMessage_EmailDoesNotExists;

        jQuery("div#forgotPasswordPopup div#message").html(message);
        jQuery("div#forgotPasswordPopup div#message").show();
    },
    // newly added
    passwordForget_Succeeded3: function(result) {
        var message = '';
        if (result.value)
            message = Cardthartic.state.passwordFogotMessage_EmailSent;
        else
            message = Cardthartic.state.passwordFogotMessage_EmailDoesNotExists;

        jQuery("div.forgotPasswordPopup3 div.message").html(message);
        jQuery("div.forgotPasswordPopup3 div.message").show();
    },


    sendECard_Succeeded: function(result) {
        var message = '';
        if (result.value)
            message = Cardthartic.state.sendCardMessage_EmailSent;
        else
            message = Cardthartic.state.sendCardMessage_ErrorSendingMail;

        jQuery("div.sendecard div.message").html(message);
        jQuery("div.sendecard div.message").show();
    },

    closePopups: function() {
        jQuery("div.productInfo").hide();
        jQuery("div.sendecard").hide();
        jQuery("div.enlarge").hide();
        jQuery("div.registration").hide();
        jQuery("div.NewRegisterForm").hide();
        jQuery("div.AddToCartPopup").hide();
    },

    //expandCollapse categories
    categoryClicked: function(control) {
        var image = control.attr("image");
        var url = control.attr("url");
        var parentCategoryId = control.attr("parentCategoryId");
        var opened = control.attr("opened");
        var catalogId = control.attr("catalogId");
        var categoryId = control.attr("categoryId");

        //show spash if exist
        if (image) {
            var img = jQuery("div.splash img");
            var anchor = jQuery("div.splash a");

            img.show();
            img.attr("src", "images/cardthartic/" + image);
            if (url != "") {
                anchor.attr("disabled", "");
                anchor.attr("href", url);
            }
            else
                anchor.attr("disabled", "");

            jQuery("div.breadcrumbs").hide();
            jQuery("div#search_result_container").hide();
        }

        //close all other categories in same level and below
        var categories = Cardthartic.findCategories(parentCategoryId, true);
        for (var i = 0; i < categories.length; i++) Cardthartic.closeCategory(categories[i]);

        if (opened == "true")
            Cardthartic.closeCategory(control);
        else
            Cardthartic.openCategory(control);

        //select current anchor and all its parents
        //disselect all anchors
        jQuery("a[categoryid]").removeClass("active");
        //select current
        control.addClass("active");
        //select current's parents
        var parents = Cardthartic.findParents(categoryId);
        for (var i = 0; i < parents.length; i++) parents[i].addClass("active");
        //select catalog and deselect all other catalogs
        jQuery("a[auxId]").removeClass("active");
        jQuery("a[auxId=" + catalogId + "]").addClass("active");
    },
    closeCategory: function(control) {
        var categoryId = control.attr("categoryId");
        control.attr("opened", "false");

        //close all elements (not just first level)
        var categories = Cardthartic.findCategories(categoryId, false);
        for (var i = 0; i < categories.length; i++) {
            var category = categories[i];
            category.hide();
            //IE7 fix hide also li element (if not hidden li has height)
            category.parent().hide();
            category.attr("opened", "false");
        }
    },
    openCategory: function(control) {
        var categoryId = control.attr("categoryId");
        control.attr("opened", "true");
        control.next("ul").show();

        //only open first level
        var categories = Cardthartic.findCategories(categoryId, true);
        for (var i = 0; i < categories.length; i++) {
            var category = categories[i];
            category.show();
            //IE7 fix show also li element
            category.parent().show();
        }
    },
    findCategories: function(parentId, directChildren) {
        var categories = new Array();

        var parent = jQuery("a[categoryId=" + parentId + "]")
        if (parent.length == 1) {
            var parent_lo = parseInt(parent.attr("lo"));
            var parent_hi = parseInt(parent.attr("hi"));
            var parent_indent = parseInt(parent.attr("indent"));

            jQuery("a[categoryid]").each(function() {
                var lo = parseInt(jQuery(this).attr("lo"));
                var hi = parseInt(jQuery(this).attr("hi"));
                var indent = parseInt(jQuery(this).attr("indent"));

                if ((lo > parent_lo) && (hi < parent_hi) && (!directChildren || (directChildren && indent == parent_indent + 1)))
                    categories.push(jQuery(this));
            });
        } else {
            //if parent = null => first level => indent = 2
            jQuery("a[categoryid][indent=2]").each(function() {
                categories.push(jQuery(this));
            });
        }

        return categories;
    },
    findParents: function(categoryId) {
        var categories = new Array();

        var current = jQuery("a[categoryId=" + categoryId + "]")
        var control_lo = parseInt(current.attr("lo"));
        var control_hi = parseInt(current.attr("hi"));

        jQuery("a[categoryid]").each(function() {
            var lo = parseInt(jQuery(this).attr("lo"));
            var hi = parseInt(jQuery(this).attr("hi"));
            if ((lo < control_lo) && (hi > control_hi))
                categories.push(jQuery(this))
        });

        return categories;
    },

    closeAddToCardPopups: function() {
        jQuery("div.addToCardPopup").hide();
    },
    showStores: function(storeName) {
        jQuery("div.storeLocations").hide();
        jQuery("div." + storeName).show();
        /*
        jQuery("div.productInfo").hide();
        jQuery("div.sendecard").hide();
        jQuery("div.enlarge").hide();    
        */
    },
    setPopupPosition: function(container) {
        var popup = container.find("div.popup");
        var popup_wraper = container.find("div.popup_wraper");
        var top;

        if (jQuery.browser.safari)
            top = document.body.scrollTop + 80;
        else
            top = document.documentElement.scrollTop + 80;

        popup.css("top", top);
        popup_wraper.css("top", top + 50);
    },
    addressValidatorEvaluateIsValid: function(source, agruments) {
        var listHTML = '';
        var country = document.getElementById(source.countryControlToValidate);
        var state = document.getElementById(source.stateControlToValidate);
        var city = document.getElementById(source.cityControlToValidate);
        var zip = document.getElementById(source.zipControlToValidate);

        var addreses = AIKON.CommerceLive.WebService.Shipping.ValidateAddress(country.value, state.value, city.value, zip.value).value;
        if (addreses.length > 1) {
            for (var i = 0; i < addreses.length; i++) {
                var address = addreses[i];
                listHTML += '<li><a class="addressValidation" href="#" onclick="Cardthartic.populateAddress(\'' +
	            source.countryControlToValidate + '\',\'' +
	            source.stateControlToValidate + '\',\'' +
	            source.cityControlToValidate + '\',\'' +
	            source.zipControlToValidate + '\',\'' +
	            address.CountryRegionID + '\',\'' +
	            address.StateProvinceID + '\',\'' +
	            address.City + '\',\'' +
	            address.ZIP + '\');return false;">' + address.State + ' ' + address.City + ' ' + address.ZIP + '</a></li>'
            }
            source.errormessage = 'Address was not recognized. Click to select?<ul>' + listHTML + '</ul>';
            arguments[1].IsValid = false;
        }
        else
            arguments[1].IsValid = true;
    },
    populateAddress: function(countryControlToValidate, stateControlToValidate, cityControlToValidate, zipControlToValidate,
                              countryValue, stateValue, cityValue, zipValue) {
        var country = document.getElementById(countryControlToValidate);
        var state = document.getElementById(stateControlToValidate);
        var city = document.getElementById(cityControlToValidate);
        var zip = document.getElementById(zipControlToValidate);

        selectOptionByValue(country, countryValue);
        selectOptionByValue(state, stateValue);
        city.value = cityValue;
        var ziparr = zipValue.split('-');
        zip.value = ziparr[1];
        //zip.value = zipValue;

    },
    // added by harpal singh 
    updateOrderItemCount: function(order) {
        if (order) {
            var orderTotal = Cardthartic.getOrderAttribute(order.value, 'order_total');
            var itemsCount = Cardthartic.getOrderAttribute(order.value, 'order_total_items_count');
            if (itemsCount > 1) {
                jQuery("#ctl07_ctl03_lblOrderItemCount").html(itemsCount + ' Item');
                //jQuery("<%=#lblOrderItemCount.ClientID%>").html(itemsCount + ' Item');
                //document.getElementById("<%=OrderItemCount.ClientID%>").value == itemsCount + "Item";
            }
            //jQuery("label.itemCount").html(itemsCount);
            else if (itemsCount == 1)
                jQuery("#ctl07_ctl03_lblOrderItemCount").html(itemsCount + ' Item');
            else if (itemsCount == 0)
                jQuery("#ctl07_ctl03_lblOrderItemCount").html(itemsCount + ' Item');
            //        else
            //            ctl07_ctl03_lblOrderItemCount.html('0 Items');
            jQuery("div.ordercomplete[@auxId=" + passAuxid + "]").show();
            setTimeout('jQuery("div.ordercomplete[@auxId=' + passAuxid + ']").hide()', 2000);
            passAuxid = 0;
            //setTimeout('jQuery("div.ordercomplete").hide()', 2000);
        }
    }

};
 
 function selectOptionByValue(oSelect, value){
    if (oSelect.options.length > 0)
    {
        oSelect.selectedIndex = 0;
        for (i = 0; i < oSelect.options.length; i++){
            if (oSelect.options[i].value == value){
                oSelect.selectedIndex = i;
                break;
            }
        }
    }
}

//function updateOrderItemCount(order) {
//    if (order) {
//        var orderTotal = Cardthartic.getOrderAttribute(order.value, 'order_total');
//        var itemsCount = Cardthartic.getOrderAttribute(order.value, 'order_total_items_count');
//        if (itemsCount > 1) {
//            jQuery("#ctl07_ctl03_lblOrderItemCount").html(itemsCount + ' Item');
//            //jQuery("<%=#lblOrderItemCount.ClientID%>").html(itemsCount + ' Item');
//            //document.getElementById("<%=OrderItemCount.ClientID%>").value == itemsCount + "Item";
//        }
//        //jQuery("label.itemCount").html(itemsCount);
//        else if (itemsCount == 1)
//            jQuery("#ctl07_ctl03_lblOrderItemCount").html(itemsCount + ' Item');
//        else if (itemsCount == 0)
//            jQuery("#ctl07_ctl03_lblOrderItemCount").html(itemsCount + ' Item');
////        else
////            ctl07_ctl03_lblOrderItemCount.html('0 Items');
//    }
//}
function addToShoppingCartNew_Succeeded(result) {
    updateOrderItemCount(result);
    var itemsCount = Cardthartic.getOrderAttribute(result.value, 'order_total_items_count');
    //commented by Harpal Singh
    jQuery("label.itemCount").html(itemsCount);
}




