﻿$(function() {
// Major version of Flash required

    $('<a href="#top" class="backtotop">[back to top]</a>')
                .insertBefore('a.questionlink:gt(1)');
    $('<a id="top" name="top"></a>')
                .prependTo('body');



    if (window.location.href.toLowerCase().indexOf('aboutus') > 0) {
        $("#pressreleases *[id^=press]").hide().eq(0).show();
        $('#year').change(function() {
            year = $(this).val();
            $("#pressreleases *[id^=press]").hide();
            $("#pressreleases #press" + year).show();

        });
        $('#ancShowMore').click(function(e) {
            e.preventDefault();
            if ($(this).html() == "Show Archive") {
                $(this).html('Hide Archive');
            }
            else {
                $(this).html('Show Archive');
            }
            $('#divShowMore').slideToggle('slow');
        });

        $('#lnkteam').click(function(event) {
            event.preventDefault();
            new Boxy("<div style='padding-right:10px;'><iframe frameborder='0' src ='/StaticPages/Team' width='100%' height='100%'><p>Your browser does not support iframes.</p></iframe></div>", {
                height: '500px',
                width: '775px',
                title: this.title,
                modal: true
            });
        });
    }
    if (window.location.href.toLowerCase().indexOf('prices') > 0) {
        var countryDropDown = $('.select-shiptocountry select');
        if (countryDropDown.length) {
            if (countryDropDown.val() == "India") {
                showIndia('photoprints');
            }
            else {
                showGlobal('photoprints');
            }
            $('.select-shiptocountry select').select({ width: 90 });
            $('.select-shiptocountry select').change(function() {
                if ($(this).val() == "India") {
                    showIndia('photoprints');
                } else {
                    showGlobal('photoprints');
                }
            });
        }
        $("#loadingajax").ajaxStart(function() {
            $(this).css({
                opacity: 0.7,
                width: $("#main-content").width(),
                height: $("#pricing").height()
            });
            $(this).show();

        });
        $("#loadingajax").ajaxStop(function() {
            $(this).hide();
        });
    }
    screenshotPreview();
    $(".recommended tr").children().addClass("center");
    $(".recommended tr").each(function() {
        $(this).children("th").eq(0).removeClass("center");
        $(this).children("td").eq(0).removeClass("center");
    });
    $(".help table tr").each(function() {
        $(this).children("td").eq(0).addClass("strong");
    });

    if (window.location.href.toLowerCase().indexOf('career') > 0) {
        $(".jobdescription:gt(0)").hide();
        $firstLink = $(".joblisting li a")[0];
        $("#mailtolink").attr("href", "mailto:jobs@zoomin.com?subject=" + $firstLink.innerHTML);
        $("#mailsubject").html($firstLink.innerHTML);
        $("#paraemail").show();
        $(".joblisting li a").click(function(event) {
            event.preventDefault();
            var urlParam = this.href.split('#');
            $("#mailtolink").attr("href", "mailto:jobs@zoomin.com?subject=" + this.innerHTML);
            $("#mailsubject").html(this.innerHTML);
            $(".jobdescription").hide();
            $('#' + urlParam[1]).show();
        });
    }
    if (window.location.href.toLowerCase().indexOf('offer') > 0) {
        $("#offersfeed").feed({
            url: "/Proxy/?Key=URL_OffersRss&contentType=application/octet-stream",
            count: 3,
            template: "<div class='promo'><h3>@title</h3><p>@content:encoded</p></div>",
            errortext: "<br/>There are no specials currently running.  Please check back here often to find the latest offers on ZoomIn products.",
            vars: ["title", "content:encoded"],
            loading: function() {
            },
            complete: function(html) {
                $(this).html(html);
                //Seach and replace all the zoomin.com links to open in the same window
                $(this).find("a").each(function() {
                    if ($(this).attr("href").indexOf("zoomin.com") > 0) {
                        $(this).attr("target", "_self");
                    }
                });
            }
        });
    }
    
});

var isIE = (navigator.appVersion.indexOf("MSIE") != -1) ? true : false;
var isWin = (navigator.appVersion.toLowerCase().indexOf("win") != -1) ? true : false;
var isOpera = (navigator.userAgent.indexOf("Opera") != -1) ? true : false;

function DetectFlashVer(reqMajorVer, reqMinorVer, reqRevision) {
    versionStr = GetSwfVer();
    if (versionStr == -1) {
        return false;
    } else if (versionStr != 0) {
        if (isIE && isWin && !isOpera) {
            // Given "WIN 2,0,0,11"
            tempArray = versionStr.split(" "); 	// ["WIN", "2,0,0,11"]
            tempString = tempArray[1]; 		// "2,0,0,11"
            versionArray = tempString.split(","); // ['2', '0', '0', '11']
        } else {
            versionArray = versionStr.split(".");
        }
        var versionMajor = versionArray[0];
        var versionMinor = versionArray[1];
        var versionRevision = versionArray[2];

        // is the major.revision >= requested major.revision AND the minor version >= requested minor
        if (versionMajor > parseFloat(reqMajorVer)) {
            return true;
        } else if (versionMajor == parseFloat(reqMajorVer)) {
            if (versionMinor > parseFloat(reqMinorVer))
                return true;
            else if (versionMinor == parseFloat(reqMinorVer)) {
                if (versionRevision >= parseFloat(reqRevision))
                    return true;
            }
        }
        return false;
    }
}

function GetSwfVer() {
    // NS/Opera version >= 3 check for Flash plugin in plugin array
    var flashVer = -1;
    if (navigator.plugins != null && navigator.plugins.length > 0) {
        if (navigator.plugins["Shockwave Flash 2.0"] || navigator.plugins["Shockwave Flash"]) {
            var swVer2 = navigator.plugins["Shockwave Flash 2.0"] ? " 2.0" : "";
            var flashDescription = navigator.plugins["Shockwave Flash" + swVer2].description;
            var descArray = flashDescription.split(" ");
            var tempArrayMajor = descArray[2].split(".");
            var versionMajor = tempArrayMajor[0];
            var versionMinor = tempArrayMajor[1];
            if (descArray[3] != "") {
                tempArrayMinor = descArray[3].split("r");
            } else {
                tempArrayMinor = descArray[4].split("r");
            }
            var versionRevision = tempArrayMinor[1] > 0 ? tempArrayMinor[1] : 0;
            var flashVer = versionMajor + "." + versionMinor + "." + versionRevision;
        }
    }
    // MSN/WebTV 2.6 supports Flash 4
    else if (navigator.userAgent.toLowerCase().indexOf("webtv/2.6") != -1) flashVer = 4;
    // WebTV 2.5 supports Flash 3
    else if (navigator.userAgent.toLowerCase().indexOf("webtv/2.5") != -1) flashVer = 3;
    // older WebTV supports Flash 2
    else if (navigator.userAgent.toLowerCase().indexOf("webtv") != -1) flashVer = 2;
    else if (isIE && isWin && !isOpera) {
        flashVer = ControlVersion();
    }
    return flashVer;
}

function showMap(country) {
    var divMapUS = document.getElementById("divMapUS");
    var divMapIndia = document.getElementById("divMapIndia");
    var pnlGoogleMap = document.getElementById("ctl00_ContentPlaceHolder1_pnlGoogleMap");
    hideMap();
    if (pnlGoogleMap) {
        pnlGoogleMap.style.display = "inline";
    }
    if (country.toLowerCase() == "usa") {
        divMapUS.style.display = "block"
        divMapUS.innerHTML = "<iframe width='365' height='300' frameborder='0' scrolling='no' marginheight='0' marginwidth='0' src='http://maps.google.com/maps/ms?ie=UTF8&amp;hl=en&amp;msa=0&amp;msid=112328907291113156975.00044d3facaed32e13222&amp;s=AARTsJpKd695VtfgjwyBlBXctKT2V1nAvQ&amp;ll=40.064147,-75.308533&amp;spn=0.078826,0.125313&amp;z=12&amp;output=embed'></iframe><br /><small><a href='http://maps.google.com/maps/ms?ie=UTF8&amp;hl=en&amp;msa=0&amp;msid=112328907291113156975.00044d3facaed32e13222&amp;ll=40.064147,-75.308533&amp;spn=0.078826,0.125313&amp;z=12&amp;source=embed' style='color:#0000FF;text-align:left'>View Larger Map</a></small>"
    }
    else {
        divMapIndia.style.display = "block"
        divMapIndia.innerHTML = "<iframe width='365' height='300' frameborder='0' scrolling='no' marginheight='0' marginwidth='0' src='http://maps.google.com/maps/ms?ie=UTF8&amp;hl=en&amp;msa=0&amp;msid=112328907291113156975.00044d3facaed32e13222&amp;s=AARTsJpKd695VtfgjwyBlBXctKT2V1nAvQ&amp;ll=18.983302,72.836512&amp;spn=0.006089,0.007832&amp;z=16&amp;output=embed'></iframe><br /><small><a href='http://maps.google.com/maps/ms?ie=UTF8&amp;hl=en&amp;msa=0&amp;msid=112328907291113156975.00044d3facaed32e13222&amp;ll=18.983302,72.836512&amp;spn=0.006089,0.007832&amp;z=16&amp;source=embed' style='color:#0000FF;text-align:left'>View Larger Map</a></small>"

    }
}

function hideMap() {
    var divMapUS = document.getElementById("divMapUS");
    var divMapIndia = document.getElementById("divMapIndia");
    divMapUS.style.display = "none"
    divMapIndia.style.display = "none"
}

function emailCheck(str) {

    var at = "@"
    var dot = "."
    var lat = str.indexOf(at)
    var lstr = str.length
    var ldot = str.indexOf(dot)
    if (str.indexOf(at) == -1) {
        return false
    }

    if (str.indexOf(at) == -1 || str.indexOf(at) == 0 || str.indexOf(at) == lstr) {
        return false
    }

    if (str.indexOf(dot) == -1 || str.indexOf(dot) == 0 || str.indexOf(dot) == lstr) {
        return false
    }

    if (str.indexOf(at, (lat + 1)) != -1) {
        return false
    }

    if (str.substring(lat - 1, lat) == dot || str.substring(lat + 1, lat + 2) == dot) {
        return false
    }

    if (str.indexOf(dot, (lat + 2)) == -1) {
        return false
    }

    if (str.indexOf(" ") != -1) {
        return false
    }

    return true
}

function submitMail() {

    /* Email Validation */
    var err = 0;
    $("#summary-error-1").hide();
    $("#summary-error-2").hide();
    $("#summary-error-3").hide();
    if ($("#emailaddress").val() == "") {
        $("#summary-error-1").show();
        err++;
    } else if (!emailCheck($("#emailaddress").val())) {
        $("#summary-error-2").show();
        err++;
    }
    if ($("#message").val() == "") {
        $("#summary-error-3").show();
        err++;
    }

    if (err == 0) {
        //        /* Send Mail */
        //        var formData = "emailaddress=" + $("#emailaddress").val() + "&subject=" + $("#subject").val() + "&message=" + $("#message").val();
        //        $.post('/AboutUs/?sendmail=1', formData, function(data) {
        //            $("#ContactForm").hide();
        //            $("#ThankYou").show();
        //        });
       
        
        $.ajax({
            url: "/AboutUs",
            type: "POST",
            cache: false,
            data: {
                sendmail: "1",
                emailaddress: $("#emailaddress").val(),
                subject: $("#subject").val(),
                message: $("#message").val(),
                flashversion: GetUserFlashVersion()
            },
            success: function(result) {
                if (result.message != "success")
                { $("#ContactForm").hide(); $("#ThankYou").show(); }
            }
        });
    }
    return false;
};

function GetUserFlashVersion() {
    var requiredMajorVersion = 8;
    // Minor version of Flash required
    var requiredMinorVersion = 0;
    // Minor version of Flash required
    var requiredRevision = 0;
    var FlashVersion;
    var hasReqestedVersion = DetectFlashVer(requiredMajorVersion, requiredMinorVersion, requiredRevision);
    if (hasReqestedVersion) {
        FlashVersion = GetSwfVer()
    }
    else {
        FlashVersion = "Required version not found"
    }
    return FlashVersion;
}

function ControlVersion() {
    var version;
    var axo;
    var e;

    // NOTE : new ActiveXObject(strFoo) throws an exception if strFoo isn't in the registry

    try {
        // version will be set for 7.X or greater players
        axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.7");
        version = axo.GetVariable("$version");
    } catch (e) {
    }

    if (!version) {
        try {
            // version will be set for 6.X players only
            axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.6");

            // installed player is some revision of 6.0
            // GetVariable("$version") crashes for versions 6.0.22 through 6.0.29,
            // so we have to be careful.

            // default to the first public version
            version = "WIN 6,0,21,0";

            // throws if AllowScripAccess does not exist (introduced in 6.0r47)
            axo.AllowScriptAccess = "always";

            // safe to call for 6.0r47 or greater
            version = axo.GetVariable("$version");

        } catch (e) {
        }
    }

    if (!version) {
        try {
            // version will be set for 4.X or 5.X player
            axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.3");
            version = axo.GetVariable("$version");
        } catch (e) {
        }
    }

    if (!version) {
        try {
            // version will be set for 3.X player
            axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.3");
            version = "WIN 3,0,18,0";
        } catch (e) {
        }
    }

    if (!version) {
        try {
            // version will be set for 2.X player
            axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash");
            version = "WIN 2,0,0,11";
        } catch (e) {
            version = -1;
        }
    }
    return version;
}

function showIndia(parentID) {
    $("#" + parentID).find(".global").hide();
    $("#" + parentID).find(".india").fadeIn('slow');

}
function showGlobal(parentID) {
    $("#" + parentID).find(".india").hide();
    $("#" + parentID).find(".global").fadeIn('slow');
}
function showPrices() {
    if ($('.select-currency select').val() == "INR") {
        showRupee();
    }
    else {
        showDollar();
    }
}
function canvasprints() {
    showPrices();
    bindCountrySelector("canvasprints");
}
function books() {
    bindCountrySelector("books");
    showPrices();  
    $(".btnPremium").click(function(e) {
        var $divParent = $(this).parents("div:first");
        $divParent.find(".premium").show();
        $divParent.find(".classic").hide();
    });
    $(".btnClassic").click(function(e) {
        var $divParent = $(this).parents("div:first");
        $divParent.find(".classic").show();
        $divParent.find(".premium").hide();
    });
}
function mugs() {
    showPrices();
    bindCountrySelector("mugs");
}
function calendars() {
    showPrices();
    bindCountrySelector("calendars");
}
function gifts() {
    showPrices();
}
function tshirts() {
    showPrices();
    bindCountrySelector("tshirts");
}
function posters() {
    showPrices();
    bindCountrySelector("posters");
}
function cards() {
    showPrices();
    bindCountrySelector("cards");
}
function gifts() {
    showPrices();
    bindCountrySelector("gifts");
}
function frames() {
    showPrices();
    bindCountrySelector("frames");
}
function bindCountrySelector(divID) {
    if ($("#" + divID + ' .select-shiptocountry select').val() == "India") {
        showIndia(divID);
    }
    else {
        showGlobal(divID);
    }
    $("#" + divID + ' .select-shiptocountry select').select({ width: 90 });
    $("#" + divID + ' .select-shiptocountry select').change(function() {
        if ($(this).val() == "India") {
            showIndia(divID);
        } else {
            showGlobal(divID);
        }
    });
}