﻿
function ddtabcontent(tabinterfaceid) {
    this.tabinterfaceid = tabinterfaceid
    this.tabs = document.getElementById(tabinterfaceid).getElementsByTagName("a")
    this.enabletabpersistence = true
    this.hottabspositions = []
    this.currentTabIndex = 0
    this.subcontentids = []
    this.revcontentids = []
    this.selectedClassTarget = "link"
}
ddtabcontent.getCookie = function(Name) {
    var re = new RegExp(Name + "=[^;]+", "i");
    if (document.cookie.match(re))
        return document.cookie.match(re)[0].split("=")[1]
    return ""
}
ddtabcontent.setCookie = function(name, value) {
    document.cookie = name + "=" + value + ";path=/"
}
ddtabcontent.prototype = {
    expandit: function(tabid_or_position) {
        this.cancelautorun()
        var tabref = ""
        try {
            if (typeof tabid_or_position == "string" && document.getElementById(tabid_or_position).getAttribute("rel"))
                tabref = document.getElementById(tabid_or_position)
            else if (parseInt(tabid_or_position) != NaN && this.tabs[tabid_or_position].getAttribute("rel"))
                tabref = this.tabs[tabid_or_position]
        }
        catch (err) { alert("Invalid Tab ID or position entered!") }
        if (tabref != "")
            this.expandtab(tabref)
    },
    cycleit: function(dir, autorun) {
        if (dir == "next") {
            var currentTabIndex = (this.currentTabIndex < this.hottabspositions.length - 1) ? this.currentTabIndex + 1 : 0
        }
        else if (dir == "prev") {
            var currentTabIndex = (this.currentTabIndex > 0) ? this.currentTabIndex - 1 : this.hottabspositions.length - 1
        }
        if (typeof autorun == "undefined")
            this.cancelautorun()
        this.expandtab(this.tabs[this.hottabspositions[currentTabIndex]])
    },
    setpersist: function(bool) {
        this.enabletabpersistence = bool
    },
    setselectedClassTarget: function(objstr) {
        this.selectedClassTarget = objstr || "link"
    },
    getselectedClassTarget: function(tabref) {
        return (this.selectedClassTarget == ("linkparent".toLowerCase())) ? tabref.parentNode : tabref
    },
    urlparamselect: function(tabinterfaceid) {
        var result = window.location.search.match(new RegExp(tabinterfaceid + "=(\\d+)", "i"))
        return (result == null) ? null : parseInt(RegExp.$1)
    },
    expandtab: function(tabref) {
        var subcontentid = tabref.getAttribute("rel")
        var associatedrevids = (tabref.getAttribute("rev")) ? "," + tabref.getAttribute("rev").replace(/\s+/, "") + "," : ""
        this.expandsubcontent(subcontentid)
        this.expandrevcontent(associatedrevids)
        for (var i = 0; i < this.tabs.length; i++) {
            this.getselectedClassTarget(this.tabs[i]).className = (this.tabs[i].getAttribute("rel") == subcontentid) ? "selected" : ""
        }
        if (this.enabletabpersistence)
            ddtabcontent.setCookie(this.tabinterfaceid, tabref.tabposition)
        this.setcurrenttabindex(tabref.tabposition)
    },
    expandsubcontent: function(subcontentid) {
        for (var i = 0; i < this.subcontentids.length; i++) {
            var subcontent = document.getElementById(this.subcontentids[i])
            subcontent.style.display = (subcontent.id == subcontentid) ? "block" : "none"
        }
    },
    expandrevcontent: function(associatedrevids) {
        var allrevids = this.revcontentids
        for (var i = 0; i < allrevids.length; i++) {
            document.getElementById(allrevids[i]).style.display = (associatedrevids.indexOf("," + allrevids[i] + ",") != -1) ? "block" : "none"
        }
    },
    setcurrenttabindex: function(tabposition) {
        for (var i = 0; i < this.hottabspositions.length; i++) {
            if (tabposition == this.hottabspositions[i]) {
                this.currentTabIndex = i
                break
            }
        }
    },
    autorun: function() {
        this.cycleit('next', true)
    },
    cancelautorun: function() {
        if (typeof this.autoruntimer != "undefined")
            clearInterval(this.autoruntimer)
    },
    init: function(automodeperiod) {
        var persistedtab = ddtabcontent.getCookie(this.tabinterfaceid)
        var selectedtab = -1
        var selectedtabfromurl = this.urlparamselect(this.tabinterfaceid)
        this.automodeperiod = automodeperiod || 0
        for (var i = 0; i < this.tabs.length; i++) {
            this.tabs[i].tabposition = i
            if (this.tabs[i].getAttribute("rel")) {
                var tabinstance = this
                this.hottabspositions[this.hottabspositions.length] = i
                this.subcontentids[this.subcontentids.length] = this.tabs[i].getAttribute("rel")
                this.tabs[i].onclick = function() {
                    tabinstance.expandtab(this)
                    tabinstance.cancelautorun()
                    return false
                }
                if (this.tabs[i].getAttribute("rev")) {
                    this.revcontentids = this.revcontentids.concat(this.tabs[i].getAttribute("rev").split(/\s*,\s*/))
                }
                if (selectedtabfromurl == i || this.enabletabpersistence && selectedtab == -1 && parseInt(persistedtab) == i || !this.enabletabpersistence && selectedtab == -1 && this.getselectedClassTarget(this.tabs[i]).className == "selected") {
                    selectedtab = i
                }
            }
        }
        if (selectedtab != -1)
            this.expandtab(this.tabs[selectedtab])
        else
            this.expandtab(this.tabs[this.hottabspositions[0]])
        if (parseInt(this.automodeperiod) > 500 && this.hottabspositions.length > 1) {
            this.autoruntimer = setInterval(function() { tabinstance.autorun() }, this.automodeperiod)
        }
    }
}


var QScroller = new Class({ options: { slides: 'qslide', direction: 'h', duration: 3000, auto: false, delay: 1000, transition: Fx.Transitions.linear }, initialize: function(wrapper, options) {
    this.setOptions(options); this.wrapper = $(wrapper); this.wrapper.setStyles({ position: 'absolute', overflow: 'hidden' }); this.wrapper.addEvent('mouseenter', this.fireEvent.pass('onMouseEnter', this)); this.wrapper.addEvent('mouseleave', this.fireEvent.pass('onMouseLeave', this)); this.slideOut = new Element('ul').setStyles({ position: 'absolute', overflow: 'hidden', top: 0, left: 0, width: this.wrapper.getStyle('width'), height: this.wrapper.getStyle('height') }).injectInside(this.wrapper); this.slideIn = this.slideOut.clone(); this.slideIn.injectInside(this.wrapper); this.slides = $$('.' + this.options.slides); if ($defined(this.options.buttons)) {
        if ($defined(this.options.buttons.next)) { $(this.options.buttons.next).addEvent('click', this.next.bind(this)); }
        if ($defined(this.options.buttons.prev)) { $(this.options.buttons.prev).addEvent('click', this.prev.bind(this)); }
        if ($defined(this.options.buttons.play)) { $(this.options.buttons.play).addEvent('click', this.play.bind(this)); }
        if ($defined(this.options.buttons.stop)) { $(this.options.buttons.stop).addEvent('click', this.stop.bind(this)); } 
    }
    this.auto = this.options.auto; this.idxSlide = 0; this.step = 0; this.isFirst = true;
}, load: function() {
    if (!this.isFirst) { this.idxSlide += this.step; if (this.idxSlide > this.slides.length - 1) { this.idxSlide = 0; } else if (this.idxSlide < 0) { this.idxSlide = this.slides.length - 1; } }
    this.curSlide = this.slides[this.idxSlide].clone(); this.show();
}, show: function() {
    var slide = this.slideIn.getElement('ul'); if (slide) { slide.replaceWith(this.curSlide); } else { this.curSlide.injectInside(this.slideIn); }
    this.doEffect();
}, doEffect: function() {
    this.fxOn = true; var d = this.isFirst ? 0 : this.options.duration; var t = this.options.transition; var fxObj = this.slideIn.effects({ duration: d, transition: t }); var inX = 0; var inY = 0; var outX = 0; var outY = 0; var ww = this.wrapper.getStyle('width').toInt(); var wh = this.wrapper.getStyle('height').toInt(); if (this.step > 0) { if (this.options.direction == 'h') { inX = -ww; outX = ww; } else { inY = -wh; outY = wh; } } else { if (this.options.direction == 'h') { inX = ww; outX = -ww; } else { inY = wh; outY = -wh; } }
    if (this.isFirst) {
        if (this.auto) { this.step = 1; }
        this.isFirst = false;
    }
    fxObj.start({ top: [inY, 0], left: [inX, 0], opacity: [1, 1] }); this.slideOut.effects({ duration: d, transition: t }).start({ top: [0, outY], left: [0, outX] }); this.fxEnd.delay(d + 75, this);
}, fxEnd: function() { this.fxOn = false; this.swapSlides(); if (this.auto) { $clear(this.timer); this.timer = this.load.delay(this.options.delay, this); } }, stop: function() { $clear(this.timer); this.auto = false; }, play: function() { if (!this.auto) { $clear(this.timer); this.auto = true; this.step = 1; if (!this.fxOn) { this.load(); } } }, next: function() {
    this.stop(); if (this.fxOn) { return; }
    this.step = 1; this.load();
}, prev: function() {
    this.stop(); if (this.fxOn) { return; }
    this.step = -1; this.load()
}, swapSlides: function() { this.slideOut.setStyles({ zIndex: 0, opacity: 0 }); var t = this.slideOut; this.slideOut = this.slideIn; this.slideIn = t; }
}); QScroller.implement(new Options, new Events);


function autoFocus(e) { if (e.keyCode == 13) { document.getElementById('btnGo').focus(); } }
function sndUserCheckforcolor(theOpt) { http.open("get", "Ajax.aspx?proid=" + theOpt.value + "&ajmode=color"); http.onreadystatechange = handleResponse; http.send(null); }
function sndUserCheckforsize(theOpt) { http.open("get", "Ajax.aspx?proid=" + theOpt.value + "&ajmode=size"); http.onreadystatechange = handleResponse; http.send(null); }
function SelectedItem(theOpt, theTxt) { window.location.href = "category.aspx?cat=" + theOpt.value + "&searchterm=" + theTxt.value; }
function setDivPrice(theDiv, theOpt, theFlag) {
    if (theDiv != null && theOpt != null) {
        var xmlHttpReq = false; var self = this; if (window.XMLHttpRequest) { self.xmlHttpReq = new XMLHttpRequest(); }
        else if (window.ActiveXObject) { self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP"); }
        self.xmlHttpReq.open('POST', "ajaxCommonFunction.aspx", true); self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); self.xmlHttpReq.onreadystatechange = function() {
            if (self.xmlHttpReq.readyState == 4) {
                var GetValue = new Array(); theOpt.disabled = false; if (self.xmlHttpReq.responseText.indexOf('~' != -1)) { GetValue = self.xmlHttpReq.responseText.split("~"); }
                if (GetValue[0].toString() != "") {
                    if (GetValue[0].toString() == "0") { alert("Error : " + GetValue[1].toString()); }
                    else { var collDivs = document.getElementsByTagName('DIV'); if (collDivs != null) { theFlag.innerHTML = "<img src=\"http://www.giftstoindia24x7.com/Pictures/" + theOpt.options[theOpt.selectedIndex].text + ".jpg\" width=\"29\" height=\"15\">"; for (i = 0; i < collDivs.length; i++) { if (theDiv.id == collDivs[i].id) { collDivs[i].innerHTML = "Rs. " + collDivs[i].title + " / " + GetValue[1].toString() + " " + (collDivs[i].title / GetValue[2]).toFixed(2); } } } } 
                }
                else { alert("Sorry! Due to some error currency cannot be changed. Please try later"); } 
            }
            else { theOpt.disabled = true; theFlag.innerHTML = "<img src=\"http://goldengroceries.giftstoindia24x7.com/images/loading.gif\" width=\"20\" height=\"20\">"; } 
        }
        self.xmlHttpReq.send("mode=1&currId=" + theOpt.value);
    }
    else { alert("Sorry! No price found to change. Cannot Change currency."); } 
}
function autoFocus(e) { if (e.keyCode == 13) { document.getElementById('btnGo').focus(); } }
function AjaxObject() {
    var httpObject; try { httpObject = new XMLHttpRequest(); }
    catch (e) {
        try { httpObject = new ActiveXObject("Msxml2.XMLHTTP"); }
        catch (e) {
            try { httpObject = new ActiveXObject("Microsoft.XMLHTTP"); }
            catch (e) { alert("Your browser does not support AJAX!"); return false; } 
        } 
    }
    return httpObject;
}
function valid1() {
    var newObject = AjaxObject(); var search = document.getElementById("UcLeftPanel1_Uc_Search1_txtSearch").value; var srchCat = document.getElementById("UcLeftPanel1_Uc_Search1_cmbCategory").value; newObject.open("GET", "ajaxforStatictPage.aspx?srchProd=" + search + "&srchCat=All" + "&randN=" + Math.random()); newObject.onreadystatechange = function() {
        if (newObject.readyState == 4) {
            var ret = newObject.responseText; if (ret == "1") {
                if (search == "") { alert('Please enter your text to search'); document.getElementById("UcLeftPanel1_Uc_Search1_txtSearch").focus(); return false; }
                else if (srchCat == "0") { window.location = "http://canada.reliablegifts.com/SearchFound.htm?srchProd=" + search + "&srchCat=All"; }
                else { window.location = "http://canada.reliablegifts.com/SearchFound.htm?srchProd=" + search + "&srchCat=" + srchCat; } 
            }
            else { alert("Some problem "); } 
        }
        if (newObject.readyState < 4) { } 
    }
    newObject.send(null); flag = true;
}


function addToCart(mode, ProdId, CatId, qnty) {
    if (mode != "") {
        var xmlHttpReq = false; var self = this; if (window.XMLHttpRequest) { self.xmlHttpReq = new XMLHttpRequest(); }
        else if (window.ActiveXObject) { self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP"); }
        alert(self.xmlHttpReq); self.xmlHttpReq.open('POST', "ajaxAddToCart.aspx?rand=" + Math.random(), true); self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); self.xmlHttpReq.onreadystatechange = function() {
            if (self.xmlHttpReq.readyState == 4) {
                var GetValue = new Array(); if (self.xmlHttpReq.responseText.indexOf('~' != -1)) {
                    GetValue = self.xmlHttpReq.responseText.split("~"); if (GetValue[0].toString() == "0") { alert('There is some error. Please try again.'); }
                    else if (GetValue[0].toString() == "1") { var varUrl = GetValue[1].toString(); window.location = 'Cart.html'; } 
                }
                else { alert("There is some error on adding to cart. Please click browser refresh button."); } 
            }
            else { } 
        }
        self.xmlHttpReq.send("Mode=" + mode + "&ProdId=" + ProdId + "&CatId=" + CatId + "&qnty=" + qnty);
    } 
}
function addToCartNR(obj, mode, ProdId, CatId, qnty) {
    var ajaxDiv = document.getElementById("dropin"); var objMainDiv = document.getElementById("dvCartMain"); if (objMainDiv != null && ajaxDiv != null) {
        obj.disabled = true; var xmlHttpReq = false; var self = this; if (window.XMLHttpRequest) { self.xmlHttpReq = new XMLHttpRequest(); }
        else if (window.ActiveXObject) { self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP"); }
        self.xmlHttpReq.open('POST', "ajaxAddToCart.aspx", true); self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); self.xmlHttpReq.onreadystatechange = function() {
            if (self.xmlHttpReq.readyState == 4) {
                var GetValue = new Array(); if (self.xmlHttpReq.responseText.indexOf('~' != -1)) {
                    GetValue = self.xmlHttpReq.responseText.split("~"); if (GetValue[0].toString() == "0") { alert("There is some error. Please try again."); }
                    else if (GetValue[0].toString() == "1") { objMainDiv.innerHTML = GetValue[1].toString(); }
                    updateAlsoBought();
                }
                else { alert("There is some error on adding to cart. Please click browser refresh button."); }
                ajaxDiv.style.display = "none"; obj.disabled = false;
            }
            else { ajaxDiv.style.display = "block"; positionDivOnClick(ajaxDiv); obj.disabled = false; } 
        }
        self.xmlHttpReq.send("Mode=" + mode + "&ProdId=" + ProdId + "&CatId=" + CatId + "&qnty=" + qnty);
    } 
}
function fnCartAdd(Mode, intcounter, proID, catId) {
    var spnAddtocart = document.getElementById("spnBuyBtn_" + intcounter); var spnload = document.getElementById("spnload_" + intcounter); if (spnAddtocart != null && spnload != null) {
        var xmlHttpReq = false; var self = this; if (window.XMLHttpRequest) { self.xmlHttpReq = new XMLHttpRequest(); }
        else if (window.ActiveXObject) { self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP"); }
        spnAddtocart.style.display = "none"; spnload.style.display = "block"; self.xmlHttpReq.open('POST', "ajaxAddToCart.aspx", true); self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); self.xmlHttpReq.onreadystatechange = function() {
            if (self.xmlHttpReq.readyState == 4) {
                var GetValue = new Array(); if (self.xmlHttpReq.responseText.indexOf('~' != -1)) {
                    GetValue = self.xmlHttpReq.responseText.split("~"); if (GetValue[0].toString() == "0") { alert("There is some error. Please try again."); }
                    else if (GetValue[0].toString() == "1") { window.location = "http://canada.reliablegifts.com/Cart.htm"; } 
                }
                else { alert("There is some error on adding to cart. Please click browser refresh button."); }
                spnAddtocart.style.display = "block"; spnload.style.display = "none";
            }
            else { spnAddtocart.style.display = "none"; spnload.style.display = "block"; } 
        }
        self.xmlHttpReq.send("ProdId=" + proID + "&CatId=" + catId + "&mode=" + Mode + "&qnty=1");
    }
    else { alert("Objects not found. Try again."); } 
}
function addToCartNew(objImgName, objAjaxName, ProdId, CatId, qnty) {
    var oi = document.getElementById(objImgName); var od = document.getElementById(objAjaxName); if (oi != null && od != null) {
        oi.disabled = true; oi.style.display = "none"; od.style.display = "block"; var xmlHttpReq = false; var self = this; if (window.XMLHttpRequest) { self.xmlHttpReq = new XMLHttpRequest(); }
        else if (window.ActiveXObject) { self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP"); }
        self.xmlHttpReq.open('POST', "ajaxAddToCart.aspx", true); self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); self.xmlHttpReq.onreadystatechange = function() {
            if (self.xmlHttpReq.readyState == 4) {
                od.style.display = "none"; var GetValue = new Array(); if (self.xmlHttpReq.responseText.indexOf('~' != -1)) {
                    GetValue = self.xmlHttpReq.responseText.split("~"); if (GetValue[0].toString() == "0") { alert(GetValue[1].toString()); }
                    else if (GetValue[0].toString() == "1") { var varUrl = GetValue[1].toString(); window.location.href = 'Cart.htm'; }
                    else { oi.disabled = false; oi.style.display = "block"; } 
                }
                else { alert("There is some error on adding to cart. Please click browser refresh button."); } 
            }
            else { oi.disabled = true; oi.style.display = "none"; od.style.display = "block"; } 
        }
        self.xmlHttpReq.send("Mode=1&ProdId=" + ProdId + "&CatId=" + CatId + "&qnty=" + qnty);
    } 
}
