﻿function resizeaddtocart() {
    var pd = window.parent.document;
    var i = pd.getElementById('ifDisplay');
    var tcd = document.getElementById('tblCartDetails');
    var cw = pd.getElementById('cartwizardcontainer');

    cw.style.width = tcd.clientWidth + 30;
}

function popitup(url, name) 
{
    newwindow = window.open(url, name, 'height=450,width=802');
    if (window.focus) { newwindow.focus() }
    return false;
}

function changeElement(ElementName, ElementValue) 
{
    obj = document.getElementById(ElementName);
    obj.value = ElementValue;
}

function NumbersOnlyBoxStrip(obj) 
{
    obj.value = obj.value.replace(/[^0-9]/, "");
}

function NumbersOnlyBoxStripDenyDecimalAllowNegative(obj) 
{
    obj.value = obj.value.replace(/[^0-9-]/, "");
}

function NumbersOnlyBoxStripAllowDecimalDenyNegative(obj) 
{
    obj.value = obj.value.replace(/[^0-9.]/, "");
}

function NumbersOnlyBoxStripAllowDecimalAllowNegative(obj) 
{
    obj.value = obj.value.replace(/[^0-9-.]/, "");
}

function confirmDelete(pageId, panelId, contentId) 
{
    if (confirm("Are you sure you want to delete")) 
    {
        document.location = "default.aspx?id=" + pageId + "&mode=del&panelId=" + panelId + "&contentId=" + contentId;
    }
}

function loadeditPanel(pageId, panelId) 
{
    document.location = "default.aspx?id=" + pageId + "&mode=editPanel&panelId=" + panelId;
}

function BuildConfigureGadgetLink(realPageId, panelNumber, gadgetClassName, instanceId, useid) 
{
    var width = 0;
    var divs = document.getElementsByTagName('div');
    for (x = 0; x < divs.length; x++) 
    {
        var id = divs[x].id;
        var targetString = "_Panel" + panelNumber;
        var position = id.search(targetString)
        if (position != -1) 
        {
            width = document.getElementById(id).offsetWidth;
            width = width - 8;
        }
    }
    var LinkDestination = "ConfigureGadget.aspx?EnableEdit=True&PageId=" + realPageId + "&PanelId=" + panelNumber + "&gadgetType=" + gadgetClassName + "&InstanceId=" + instanceId + "&useid=" + useid + "&width=" + width;
    window.open(LinkDestination, 'ManageGadget', 'scrollbars=1,resizable=1,height=600,width=840');
    return false;
}

function BuildAddGadgetLink(realPageId, panelNumber) 
{
    var width = 0;
    var divs = document.getElementsByTagName('div');
    for (x = 0; x < divs.length; x++) 
    {
        var id = divs[x].id;
        var targetString = "_Panel" + panelNumber;
        var position = id.search(targetString)
        if (position != -1) 
        {
            width = document.getElementById(id).offsetWidth;
            width = width - 8;
        }
    }
    var LinkDestination = "AddGadget.aspx?EnableEdit=False&PageId=" + realPageId + "&PanelId=" + panelNumber + "&width=" + width;
    window.open(LinkDestination, 'ManageGadget', 'scrollbars=1,resizable=1,height=600,width=840');
    return false;
}

function ConfirmMassPriceUpdate() 
{
    if (confirm("This will update all items returned in your query.  These changes cannot be undone. Are you sure?")) 
    {
        document.getElementById("confirm").value = "yes";
    }

}
function AddImageInput(imageCounter) 
{
    var elem
    if (imageCounter < 1 || imageCounter > 12) 
    {
        imageCounter = 1;
    }
    if (imageCounter == 12) 
    {
        elem = document.getElementById('AddImage');
        elem.onclick = function() { return false };
        return;
    }
    var IncrementedImageCounter = imageCounter + 1;
    var elementId = "image" + IncrementedImageCounter + "_wrapper";
    document.getElementById(elementId).style.display = "block";
    elem = document.getElementById('AddImage');
    elem.onclick = function() { AddImageInput(IncrementedImageCounter); return false; };
}
function setMode(mode, id) 
{
    var elem = document.getElementById('ctl00_ContentPlaceHolder1_hidden_Mode');
    elem.value = mode;
    var elem2 = document.getElementById('ctl00_ContentPlaceHolder1_hidden_id');
    elem2.value = id;
}

function SetEventManagerField(fieldName, desiredValue) 
{
    //String that the .NET framework automatically precedes control ids with
    //in order to ensure uniqueness.
    var DotNet_IdPrefix = "ctl00_ContentPlaceHolder1_";
    document.getElementById(DotNet_IdPrefix + fieldName).value = desiredValue;
}

function RollAds(ids) 
{
    var nextIndex = 0
    for (i = 0; i < ids.length; i++) 
    {
        var ele = document.getElementById("ctl00_ContentPlaceHolder1_" + ids[i] + "_anchor");
        if ((ele) && (ele.className == "AdImage")) 
        {
            ele.className = "AdImage_Hidden";
            nextImageIndex = i + 1;
            if (nextImageIndex >= ids.length) 
            { nextImageIndex = 0; }
            ele = document.getElementById("ctl00_ContentPlaceHolder1_" + ids[nextImageIndex] + "_anchor");
            ele.className = "AdImage";
            return;
        }
    }
}

function RollAdsBack(ids) 
{
    var nextImageIndex = 0
    for (i = ids.length - 1; i >= 0; i--) 
    {
        var ele = document.getElementById("ctl00_ContentPlaceHolder1_" + ids[i] + "_anchor");
        if ((ele) && (ele.className == "AdImage")) 
        {
            ele.className = "AdImage_Hidden";
            nextImageIndex = i - 1;
            if (nextImageIndex < 0) 
            {
                nextImageIndex = ids.length-1;
            }
            ele = document.getElementById("ctl00_ContentPlaceHolder1_" + ids[nextImageIndex] + "_anchor");
            ele.className = "AdImage";
            return;
        }
    }
}

function ConfirmGadgetDelete() 
{
    if (confirm('Are you sure you want to delete this gadget?')) 
    { return true; }
    else 
    { return false; }

}
function ShowElement(id) 
{
    var element = document.getElementById(id);
    element.style.display = '';
}

function HideElement(id) 
{
    var element = document.getElementById(id);
    element.style.display = 'none';
}

function Clear(elem) 
{
    if (elem.value == "All Clubs" || elem.value == "All Societies" || elem.value == "All Judges" || elem.value == "All Dealers") 
    {
        elem.value = "";
    }
}


function toggleVisible(obj, div) 
{
    target = document.getElementById(div);
    if (obj.checked) 
    {
        target.style.display = 'block';
    }
    else 
    {
        target.style.display = 'none';
    }
}

function toggleVisible2(obj, div1, div2, div3) 
{
    ctrl = document.getElementById(obj);
    target1 = document.getElementById(div1);
    target2 = document.getElementById(div2);
    target3 = document.getElementById(div3);
    if (ctrl.value == "on") 
    {
        target1.style.display = 'none';
        target2.style.display = 'block';
        target3.style.display = 'block';
        ctrl.value = "off";
    }
    else 
    {
        target1.style.display = 'block';
        target2.style.display = 'none';
        target3.style.display = 'none';
        ctrl.value = "on";
    }
}

function ajaxRequest() 
{
    var activexmodes = ["Msxml2.XMLHTTP", "Microsoft.XMLHTTP"] //activeX versions to check for in IE
    if (window.ActiveXObject) //Test for support for ActiveXObject in IE first (as XMLHttpRequest in IE7 is broken)
    {
        for (var i = 0; i < activexmodes.length; i++) 
        {
            try 
            {
                return new ActiveXObject(activexmodes[i])
            }
            catch (e) 
            {
                //suppress error
            }
        }
    }
    else 
    {
        if (window.XMLHttpRequest) // if Mozilla, Safari etc
        {
            return new XMLHttpRequest()
        }
        else 
        {
            return false
        }
    }
}

function shoppingCartAdd(itemid, qval, msgdiv, control, target)
{
    var Stamp = new Date();
    var url = "ShoppingSelectionHandler.aspx?Id=" + itemid + "&Quantity=" + qval + "&Target=" + target + "&Time=" + Stamp.getTime();
    var h = $(window).height();
    var w = $(window).width();
    $('#cartcontents').load(url, '', function() { showcartwizard(); });
 /*   $(control).parents('tr').find('.infocell').html($(control).parents('tr').find('.infocell').html() + '<div class="addedtocart">(Added to Cart)</div>');
    $(control).parents('.itemwrapper').css('background-color', "#F8F7EF");  */
    return true;
}

function shoppingCartMany(itemid, quantityctrl, msgdiv, control, target) 
{
    var qtarget = document.getElementById(quantityctrl);
    return shoppingCartAdd(itemid, qtarget.value, msgdiv, control, target);
}

function shoppingCartOne(itemid, msgdiv, control, target)
{
    return shoppingCartAdd(itemid, 1, msgdiv, control, target);
}


function showcartwizard() 
{
    window.onscroll = function(e) { scrollupdatecartwizard(); }
    document.body.onscroll = function(e) { scrollupdatecartwizard(); }
    var h = $(window).height();
    var w = $(window).width();
    $('#cartwizardcontainer').show();
    scrOfY = 0;
    scrOfX = 0;
    if (typeof (window.pageYOffset) == 'number') 
    {
        //Netscape compliant
        scrOfY = window.pageYOffset;
        scrOfX = window.pageXOffset;
    }
    else if (document.body && (document.body.scrollLeft || document.body.scrollTop)) 
    {
        //DOM compliant
        scrOfY = document.body.scrollTop;
        scrOfX = document.body.scrollLeft;
    }
    else if (document.documentElement && (document.documentElement.scrollLeft || document.documentElement.scrollTop)) 
    {
        //IE6 standards compliant mode
        scrOfY = document.documentElement.scrollTop;
        scrOfX = document.documentElement.scrollLeft;
    }
    if (scrOfX == 'undefined') { scrOfX = 0; }
    if (scrOfY == 'undefined') { scrOfY = 0; }
    $('#cartwizardcontainer').css('top', h / 2 - $('#cartwizardcontainer').height() / 2 + scrOfY);
    $('#cartwizardcontainer').css('left', w / 2 - $('#cartwizardcontainer').width() / 2 + scrOfX);
    $('.ShoppingCartText').html('An item has been added to your cart');
}

function scrollupdatecartwizard() { closewizardwindow(); }

function closewizardwindow() { $('#cartwizardcontainer').hide(); }

function wishListAdd(itemid, msgdiv) 
{
    var Stamp = new Date();
    var url = "AddToWishList.aspx?Id=" + itemid + "&Time=" + Stamp.getTime();

    $('#' + msgdiv).load(url);
    return true;
}

var ads = new Array();
function startRotation(ad, max) 
{
    var x;
    ads[ad] = 1;
    for (x = 2; x <= max; x++) 
    {
        $('#ctl00_ContentPlaceHolder1_AdvertisingAd' + ad + 'Image' + x).hide();
    }
    setInterval('rotateAds(' + ad + ',' + max + ')', 4000);
}

function rotateAds(ad, max) 
{
    var current = 0;
    var x;
    if (ads[ad] != undefined) 
    {
        if (ads[ad] == max) 
        {
            current = max;
            ads[ad] = 1;
        }
        else 
        {
            current = ads[ad];
            ads[ad]++;
        }
    }
    else 
    {
        ads[ad] = 1;
        current = 0;
    }
    for (x = 1; x <= max; x++) 
    {
        if (x == current) 
        { $('#ctl00_ContentPlaceHolder1_AdvertisingAd' + ad + 'Image' + x).fadeOut(1500); }
        else if (x == ads[ad]) 
        { $('#ctl00_ContentPlaceHolder1_AdvertisingAd' + ad + 'Image' + x).fadeIn(1500);  }
    }
}

function setDuesPurchase() 
{
    var selected;
    /*
    $(".membershipindividualpanel").css('display', 'none');
    selected = "#ctl00_ContentPlaceHolder1_Panel" + document.getElementById('ctl00_ContentPlaceHolder1_MembershipSelector').value;
    $(selected).fadeIn();
    */
}
function movechecoutdata() 
{
    var checkbox;
    checkbox = document.getElementById('ctl00_ContentPlaceHolder1_MoveAddress');
    if (checkbox.checked == true) 
    {
        document.getElementById('ctl00_ContentPlaceHolder1_txtBFirstName').value = document.getElementById('ctl00_ContentPlaceHolder1_txtSFirstName').value;
        document.getElementById('ctl00_ContentPlaceHolder1_txtBLastName').value = document.getElementById('ctl00_ContentPlaceHolder1_txtSLastName').value;
        document.getElementById('ctl00_ContentPlaceHolder1_txtBAddress1').value = document.getElementById('ctl00_ContentPlaceHolder1_txtSAddress1').value;
        document.getElementById('ctl00_ContentPlaceHolder1_txtBAddress2').value = document.getElementById('ctl00_ContentPlaceHolder1_txtSAddress2').value;
        document.getElementById('ctl00_ContentPlaceHolder1_txtBCity').value = document.getElementById('ctl00_ContentPlaceHolder1_txtSCity').value;
        document.getElementById('ctl00_ContentPlaceHolder1_txtBState').value = document.getElementById('ctl00_ContentPlaceHolder1_txtSState').value;
        document.getElementById('ctl00_ContentPlaceHolder1_txtBZip').value = document.getElementById('ctl00_ContentPlaceHolder1_txtSZip').value;
        document.getElementById('ctl00_ContentPlaceHolder1_ddlBCountries').value = document.getElementById('ctl00_ContentPlaceHolder1_ddlSCountries').value;
        document.getElementById('ctl00_ContentPlaceHolder1_txtBPhone').value = document.getElementById('ctl00_ContentPlaceHolder1_txtSPhone').value;
    }
}
function showccv() 
{
    $("#ccvdiv").fadeIn();
}
function CheckBoxChecked(obj, args) 
{
    alert(args);
    args.IsValid = false;
}
function startCheckingTerms() 
{
    setInterval("checkterms()", 250);
}
function checkterms() 
{
    if ($("#ctl00_ContentPlaceHolder1_chkAgreeToTerms:checked").val()) {
        $("#ctl00_ContentPlaceHolder1_btnProcessOrder").css('display', 'inline');
    } else {
        $("#ctl00_ContentPlaceHolder1_btnProcessOrder").css('display', 'inline');
    }
}
function openAlertDetail(ID) 
{
    if ($("#ctl00_ContentPlaceHolder1_alert" + ID).css('display') == 'none') 
    {
        $(".alertbody").css('display', 'none');
        $("#ctl00_ContentPlaceHolder1_alert" + ID).css('display', '');
    }
    else 
    {
    $("#ctl00_ContentPlaceHolder1_alert" + ID).css('display', 'none');
    }
}
function SelectSearch(pane, control) 
{
    closePaneRadios(pane);
    openCorrectPane(control);
}
function closePaneRadios(pane) 
{

    $("." + pane + " .Prompt").css('display', 'none');
    $("." + pane + " .Data").css('display', 'none');
}
function openCorrectPane(control) 
{
    if (control != null) 
    {
        $("#" + control.id + " ~ .Prompt:first").css('display', 'block')
        $("#" + control.id + " ~ .Data:first").css('display', 'block')
    }
}
function setDealerSearch() 
{
    /*
    var name;
    var specialty;
    name = document.getElementById('ctl00_ContentPlaceHolder1_name');
    specialty = document.getElementById('ctl00_ContentPlaceHolder1_specialty');
    SelectSearch("Left", name);
    SelectSearch("Middle", specialty);*/
}

function toggleDisplay(cssclass) 
{
    if ($("." + cssclass).css('display') == 'none') 
    {
       // $("." + cssclass).css('display', '');
        $("." + cssclass).fadeIn(1000);
    }
    else 
    {
        $("." + cssclass).fadeOut(1000);
        // $("." + cssclass).css('display', 'none');
    }
}

function searchRedirect(query)
{
    window.location = '/SearchResults.aspx?cx=014831022120749635589%3Abm_rfnfc7vg&cof=FORID%3A9&ie=UTF-8&sa=Search&q=' + query;
}

