﻿/// <reference path="./jQuery/jquery.intellisense.js"/>

function browserName()
{
    browserAgent = navigator.userAgent;
    var patternFirefox = /firefox/i;
    var patternNetscape = /netscape/i;
    var patternOpera = /opera/i;
    var patternSafari = /safari/i;
    var patternIE = /msie/i;
    var patternMac = /mac/i;

    if (patternFirefox.test(browserAgent))
	    return "Firefox";
    else if (patternNetscape.test(browserAgent))
	    return "Netscape";
    else if (patternOpera.test(browserAgent))
	    return "Opera";
    else if (patternSafari.test(browserAgent))
	    return "Safari";
    else if (patternIE.test(browserAgent) && patternMac.test(browserAgent))
	    return "MacIE";
    else if (patternIE.test(browserAgent))
	    return "IE";
    else
	    return "Other";
}

function autoChange(FIsPopulated, FRadioCheckbox)
{
    if (!(FRadioCheckbox == null || isWhitespace(FIsPopulated.value)))
        FRadioCheckbox.checked = true;
}

function autoCheck(FCheckboxA, FCheckboxB, FCheckUncheck)
{
    if (FCheckboxB != null)
    {
        if (FCheckUncheck && FCheckboxA.checked)
            FCheckboxB.checked = true;
        else if (!FCheckUncheck && !FCheckboxA.checked)
            FCheckboxB.checked = false;
    }
}

function autoEnableDisable(FCheckbox, FField, FTrueFalse)
{
    if (FField != null)
    {
        if (FCheckbox.checked)
            FField.disabled = !FTrueFalse;
        else
            FField.disabled = FTrueFalse;
    }
}

function requireCompanyName(businessAddressFlag, requiredb)
{
    var businessRequiredLabel = GetElement(requiredb);
switch (businessAddressFlag)
{
  case "0":
    businessRequiredLabel.style.display = '';
   	break;
  case "1":
    businessRequiredLabel.style.display = 'none';	
	break;
}
}

function setElementVisibility(select,cnameString,companyField,requiredbString,baddress,ad1String)
{
   var str= select;
   var ar = str.split(";");
   var name=ar[0];
   
   var cname=document.getElementById(cnameString);
   var adl=document.getElementById(ad1String);
   var requiredb=document.getElementById(requiredbString);	

   if (name.length)
   {
     cname.style.display = '';
	 ad1.style.display='none';

	 if(name=="optional")
	 {
		requiredb.style.display = '';
	 }
	 else if(name=="requiredb")
	 {    
	     if(baddress.checked)
		 {
		   requiredb.style.display = 'none';			  	    	   			   
		 }
		 else
		 {
  		   requiredb.style.display = ''; 
		 }
	 }
     else
     {
        requiredb.style.display = 'none';
	 }
   }
   else
   {
     companyField.value='';
	 cname.style.display = 'none'; 
	 ad1.style.display='';	 
   }

}

function Left(str, n)
{
    if (n <= 0)     
        return "";
    else if (n > String(str).length)   
        return str;                
    else 
        return String(str).substring(0,n);
}


function GetElement(id)
{
    if(document.all)
    {
        return document.all[id];
    }
    else
    {
        return document.getElementById(id);        
    }
    
}

function setSelectValue(selectBox, val) 
{
    var selectValueFound = false;
    for (i = 0; i < selectBox.length; i++) 
    {
        if (selectBox.options[i].value.toString() == val.toString()) 
        {
            selectBox.selectedIndex = i;
            selectValueFound = true;
            break;
        }
    }
    return selectValueFound;
}

function resetSelectBox(FSelectBox)
{
    for (Fi = 0; Fi < FSelectBox.length; Fi++)
    {

        if (FSelectBox.options[Fi].defaultSelected)
        {
            FSelectBox.selectedIndex = Fi;
            break;
        }
    }
}

function selectText(FSelectBox)
{
    textValue = FSelectBox.options[FSelectBox.selectedIndex].text;
    return trim(textValue);
}

function selectValue(selectBox) 
{
    var valueValue = selectBox.options[selectBox.selectedIndex].value;
    return trim(valueValue);
}

function trim(FString)
{
    return FString.replace(/^\s*|\s*$/g, "");
}

function getElementWidth(element) 
{
    var overflow = element.style.overflow;
    element.style.overflow = "hidden";
    var returnVal = element.scrollWidth;
    if (overflow == "") {
        element.style.overflow = "visible";
    }
    else {
        element.style.overflow = overflow
    }
    return returnVal;
}

function getElementHeight(element) 
{
    var overflow = element.style.overflow;
    element.style.overflow = "hidden";
    var returnVal = element.scrollHeight;
    if (overflow == "") {
        element.style.overflow = "visible";
    }
    else {
        element.style.overflow = overflow
    }
    return returnVal;
}

function isInteger(input,allowZero,allowNegative)
{
var pattern;
if (allowNegative)
    pattern = /[^\d\-]|\-{2,}/;
else if (allowZero)
	pattern = /\D/;
else
	pattern = /\D|^0/;

if (pattern.test(input))
    return false;
else
    return true;
}

function ajaxSyncCallback(eventTarget,eventArgument)
{
    var postData = __theFormPostData + "__CALLBACKID=" + WebForm_EncodeCallback(eventTarget) + "&__CALLBACKPARAM=" + WebForm_EncodeCallback(eventArgument);
    if (theForm["__EVENTVALIDATION"])
        postData += "&__EVENTVALIDATION=" + WebForm_EncodeCallback(theForm["__EVENTVALIDATION"].value);
    var xmlRequest,e;
    try
    {
        xmlRequest = new XMLHttpRequest();
    }
    catch(e)
    {
        try
        {
            xmlRequest = new ActiveXObject("Microsoft.XMLHTTP");
        }
        catch(e)
        {
        }
    }
    var setRequestHeaderMethodExists = true;
    try
    {
        setRequestHeaderMethodExists = (xmlRequest && xmlRequest.setRequestHeader);
    }
    catch(e)
    {
    }
    if (setRequestHeaderMethodExists)
    {
        xmlRequest.open("POST",theForm.action,false);
        xmlRequest.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=utf-8");
        xmlRequest.send(postData);
        var response = xmlRequest.responseText;
        if (response.charAt(0) == "s")
            return response.substring(1);
        else
            return "Error"; 
    }
}

function isPOBox(addressLine1, addressLine2) {
    if (isElement(addressLine1))
        addressLine1 = addressLine1.value;
    else
        addressLine1 = addressLine1;
    if (isElement(addressLine2))
        addressLine2 = addressLine2.value;
    else
        addressLine2 = addressLine2;

    var address1Chars = addressLine1.replace(/\W/g, "");
    var poBoxTest = /^(pobox|pob|postofficebox)\d/i;
    if (poBoxTest.test(address1Chars)) {
        if (isWhitespace(addressLine2))
            return true;
        else {
            var address2Chars = addressLine2.replace(/\W/g, "");
            if (poBoxTest.test(address2Chars))
                return true;
            else
                return false;
        }
    }
    else
        return false;
}

function isElement(object) {
    return (
    typeof HTMLElement === "object" ? object instanceof HTMLElement : //DOM2
    typeof object === "object" && object.nodeType === 1 && typeof object.nodeName === "string"
);
}

function isWhitespace(FValue)
{
    var pattern = /^\s*$/;
    if (pattern.test(FValue))
        return true;
    else
        return false;
}

function recursiveFind(outerElement, innerElementID) 
{
    if (outerElement.id == innerElementID) 
        return outerElement;
    else 
    {
        var index;
        for (index = 0; index < outerElement.childNodes.length; index++) 
        {
            var elem = recursiveFind(outerElement.childNodes[index], innerElementID);
            if (elem)
                return elem;
        }
        return null;
    }
}

Date.prototype.getMessage = function(messageDates)
{
    for (index = 0; index < messageDates.length; index++)
    {
        if (messageDates[index].Date.getMonth() == this.getMonth() && messageDates[index].Date.getDate() == this.getDate() && messageDates[index].Date.getYear() == this.getYear())
            return messageDates[index].Message;
    }
    return null;
}

function setupCalendarTextBox(inputFieldID, disabledDates, messageDates, minDate, maxDate, buttonImagePath, timePeriod)
{
    var yearRangeStr = '';
    var now = new Date();
    switch (timePeriod)
    {
        case 'Future':
            yearRangeStr = now.getFullYear() + ':2030';
            break;
        case 'Past':
            yearRangeStr = '1900:' + now.getFullYear();
            break;
        case 'PastAndFuture':
            yearRangeStr = '1900:2030';
            break;
    }

    nextQuery(document).ready(function()
    {
        nextQuery("#" + inputFieldID).datepicker({
            dateFormat: 'mm/dd/yy',
            showOn: 'button',
            buttonImage: buttonImagePath,
            buttonText: 'Select Date',
            buttonImageOnly: true,
            prevText: '',
            nextText: '',
            minDate: minDate,
            maxDate: maxDate,
            yearRange: yearRangeStr,
            beforeShowDay: function(date)
            {
                if (disabledDates)
                {
                    for (index = 0; index < disabledDates.length; index++)
                    {
                        if (disabledDates[index].getMonth() == date.getMonth() && disabledDates[index].getDate() == date.getDate() && disabledDates[index].getYear() == date.getYear())
                            return [false, 'disabledDays'];
                    }
                }
                if ((minDate && minDate > date) || (maxDate && maxDate < date))
                    return [false, 'disabledDays'];
                else
                    return [true, 'enabledDays'];
            },
            onChangeMonthYear: function(date)
            {
                if (messageDates)
                    addDateMessages(inputFieldID, messageDates);
            },
            onSelect: function() { } //Believe it or not, this is needed. When onSelect is null it conflicts with ASP .NET validators. ummmmm
        });
        if (messageDates)
        {
            nextQuery("#" + inputFieldID).parent().children('img').click(function()
            {
                addDateMessages(inputFieldID, messageDates);
            });
        }
        if (!nextQuery.datepicker.oldAdjustDate)
            nextQuery.datepicker.oldAdjustDate = nextQuery.datepicker._adjustDate;
        nextQuery.datepicker._adjustDate = function(id, offset, period) //overriding a datepicker core function
        {
            this.oldAdjustDate(id, offset, period); //to ensure that the old code still runs
            this._notifyChange(nextQuery.datepicker._curInst); //this ensures that the onChangeMonthYear event is fired correctly
        }
    });
}

function setupCalendarDropDown(inputFieldID, dropdownID, availableDates, messageDates, buttonImagePath)
{
    nextQuery(document).ready(function()
    {
        var selectedDate = availableDates[0];
        if (nextQuery("#" + inputFieldID).val() && nextQuery("#" + inputFieldID).val() != '')
        {
            selectedDate = nextQuery("#" + inputFieldID).val();
        }
        nextQuery("#" + inputFieldID).datepicker({
            dateFormat: 'mm-dd-yy', //needs to be in this format in order to select the correct date from the dropdownlist
            onSelect: function(date)
            {
                nextQuery("#" + dropdownID).val(date);
                nextQuery("#" + dropdownID).change(); //fire any attached events
            },
            showOn: 'button',
            buttonImage: buttonImagePath,
            buttonText: 'Select Date',
            buttonImageOnly: true,
            prevText: '',
            nextText: '',
            minDate: availableDates[0],
            maxDate: availableDates[availableDates.length - 1],
            defaultDate: selectedDate,
            beforeShowDay: function(date)
            {
                for (index = 0; index < availableDates.length; index++)
                {
                    if (availableDates[index].getMonth() == date.getMonth() && availableDates[index].getDate() == date.getDate() && availableDates[index].getYear() == date.getYear())
                        return [true, 'enabledDays'];
                }
                return [false, 'disabledDays'];
            },
            onChangeMonthYear: function(date)
            {
                if (messageDates)
                    addDateMessages(inputFieldID, messageDates);
            }
        });
        if (messageDates)
        {
            nextQuery("#" + inputFieldID).parent("td").children('img').click(function()
            {
                addDateMessages(inputFieldID, messageDates);
            });
        }
        if (!nextQuery.datepicker.oldAdjustDate)
            nextQuery.datepicker.oldAdjustDate = nextQuery.datepicker._adjustDate;
        nextQuery.datepicker._adjustDate = function(id, offset, period) //overriding a datepicker core function
        {
            this.oldAdjustDate(id, offset, period); //to ensure that the old code still runs
            this._notifyChange(nextQuery.datepicker._curInst); //this ensures that the onChangeMonthYear event is fired correctly
        }
    });
}

function addDateMessages(inputFieldID, messageDates)
{
    var target = nextQuery("#" + inputFieldID);
    var inst = nextQuery.data(target[0], "datepicker");
    var month = parseInt(inst.dpDiv.find(".ui-datepicker-one-month .ui-datepicker-header .ui-datepicker-new-month").val());
    var year = parseInt(inst.dpDiv.find(".ui-datepicker-one-month .ui-datepicker-header .ui-datepicker-new-year").val());
    var $weeks = inst.dpDiv.find(".ui-datepicker-one-month .ui-datepicker tbody .ui-datepicker-days-row");
    nextQuery.each($weeks, function()
    {
        var $days = nextQuery(this).children(".ui-datepicker-days-cell");
        nextQuery.each($days, function()
        {
            var day = nextQuery('> a', this).html() || nextQuery(this).html();
            if (day && isInteger(day, false, false))
            {
                day = parseInt(day);
                var currentDate = new Date(year, month, day);
                var message = currentDate.getMessage(messageDates);
                if (message)
                    nextQuery(this).html(nextQuery(this).html() + "<span class=\"labelSubText\">" + message + "</span>");
            }
        });
    });
}

function showObjects(obj)
{
    var properties = "Properties<br>----------<br>";
    var functions = "Functions<br>----------<br>";
    for (var i in obj)
    {
        if (typeof obj[i] == "function")
        {
            var start = obj[i].toString().indexOf('function');
            var stop = obj[i].toString().indexOf(')') + 1;
            functions += i + ": " + obj[i].toString().substring(start, stop) + "<br>";
        }
        else
            properties += i + ": " + obj[i] + "<br>";
    }

    var msg = "<div style='position: absolute; z-index: 300;'>";
    msg += properties + "<br><br>";
    msg += functions + "<br><br>";
    msg += "</div>"
    document.write(msg);
}

function changeStateCountry(txtShipZip, ddlState, ddlCountry)
{
    Nexternal.WebApp.WebServicesCommon.GetStateCountry(txtShipZip.value,
    function(result, eventArgs)
    {
        onChangeStateCountry(result, ddlState, ddlCountry);
    });
}

function onChangeStateCountry(result, ddlState, ddlCountry)
{
    if (result)
    {
        var state = result.split(";")[0];
        var country = result.split(";")[1];
        for (var i = 0; i < ddlState.length; i++)
        {
            if (state == ddlState.options[i].value.split(";")[0])
            {
                ddlState.selectedIndex = i;
                break;
            }
        }
        for (var i = 0; i < ddlCountry.length; i++)
        {
            if (country == ddlCountry.options[i].value.split(";")[0])
            {
                ddlCountry.selectedIndex = i;
                break;
            }
        }
    }
}

function changeState(ddlState, ddlCountry)
{
    var stateValue = selectValue(ddlState);
    var firstSemicolonPos = stateValue.indexOf(";");
    var lastSemicolonPos = stateValue.lastIndexOf(";");
    if (firstSemicolonPos != -1)
    {
        if (firstSemicolonPos == lastSemicolonPos)
            setSelectBox(ddlCountry, stateValue.slice(firstSemicolonPos + 1));
        else
            setSelectBox(ddlCountry, stateValue.slice(firstSemicolonPos + 1, lastSemicolonPos));
    }
}

function changeCountry(ddlCountry, ddlState)
{
    var countryValue = selectValue(ddlCountry);
    var firstSemicolonPos = countryValue.indexOf(";");
    var lastSemicolonPos = countryValue.lastIndexOf(";");
    if (firstSemicolonPos != -1)
    {
        if (firstSemicolonPos == lastSemicolonPos)
            setSelectBox(ddlState, countryValue.slice(firstSemicolonPos + 1));
        else
            setSelectBox(ddlState, countryValue.slice(firstSemicolonPos + 1, lastSemicolonPos));
    }
}

function setSelectBox(ddlSelect, textValue)
{
    var selectTextFound = false;
    for (var i = 0; i < ddlSelect.length; i++)
    {
        if (trim(ddlSelect.options[i].text) == textValue)
        {
            ddlSelect.selectedIndex = i;
            selectTextFound = true;
            break;
        }
    }
    return selectTextFound;
}

function arrayAndList(stringArray)
{
    var returnValue = "";
    for (var index = 0; index < stringArray.length; index++)
    {
        if (index > 0)
        {
            if (index == stringArray.length - 1)
                returnValue += " and ";
            else
                returnValue += ", ";
        }
        returnValue += stringArray[index];
    }
    return returnValue;
}


function getScrollWidth(element)
{
    var oldDisplay = nextQuery(element).css("display");
    nextQuery(element).css("display", "block"); //must be visible in order for "element.scrollWidth" to work
    var scrollWidth = parseInt(element.scrollWidth, 10);
    //return it to the old display
    nextQuery(element).css("display", oldDisplay);
    return scrollWidth;
}

function getScrollHeight(element)
{
    var oldDisplay = nextQuery(element).css("display");
    nextQuery(element).css("display", "block"); //must be visible in order for "element.scrollHeight" to work
    var scrollHeight = parseInt(element.scrollHeight, 10);
    //return it to the old display
    nextQuery(element).css("display", oldDisplay);
    return scrollHeight;
}

function setGIFLocation(container, updateProgressBlock, isModalPopup)
{
    if (container && updateProgressBlock && nextQuery(container).css("display") != "none" && nextQuery(updateProgressBlock).css("display") != "none")
    {
        //if it's a modalpopup treat the coord calculations as if the modal popup was the viewport
        var height, width;
        var area = null;
        var div = updateProgressBlock.getElementsByTagName('div')[0];
        if (div)
        {
            if (isModalPopup)
            {
                var scrollWidth = getScrollWidth(container);
                var scrollHeight = getScrollHeight(container);
                if (scrollWidth > nextQuery(updateProgressBlock).width() || scrollHeight > nextQuery(updateProgressBlock).height())
                {
                    Sys.UI.DomElement.setLocation(updateProgressBlock, 0, 0);
                    nextQuery(updateProgressBlock).width(scrollWidth);
                    nextQuery(updateProgressBlock).height(scrollHeight);
                }
                var modalPopupViewport = new ViewPortVars(container);
                area = modalPopupViewport.elementAreaOutsideViewPort(updateProgressBlock);
                height = nextQuery(updateProgressBlock).height();
                width = nextQuery(updateProgressBlock).width();
            }
            else
            {
                area = viewport.elementAreaOutsideViewPort(container);
                height = nextQuery(container).height();
                width = nextQuery(container).width();
            }
            var visibleTop = 0;
            var visibleLeft = 0;
            var visibleHeight = height;
            var visibleWidth = width;
            var divOffsetX = Math.floor(nextQuery(div).width() / 2);
            var divOffsetY = Math.floor(nextQuery(div).height() / 2);
            if (area)
            {
                visibleTop += area.Top;
                visibleLeft += area.Left;
                visibleHeight -= (area.Top + area.Bottom);
                visibleWidth -= (area.Left + area.Right);
            }
            var x = visibleLeft + Math.floor(visibleWidth / 2) - divOffsetX;
            var y = visibleTop + Math.floor(visibleHeight / 2) - divOffsetY;

            //Now make sure the coords are within the bounds of the container
            x = Math.max(x, 0);
            y = Math.max(y, 0);
            x = Math.min(x, width);
            y = Math.min(y, height);

            //special case adjustments (when the GIF is right on the border of the container)
            if (x - divOffsetX <= 0)
                x = divOffsetX;
            if (y - divOffsetY <= 0)
                y = divOffsetY;
            if (x + divOffsetX >= width)
                x = width - divOffsetX;
            if (y + divOffsetY >= height)
                y = height - divOffsetY;

            Sys.UI.DomElement.setLocation(div, x, y);
        }
    }
}

function setupOverlayAnimatedGIFPosition(container, updateProgressBlock, isModalPopup)
{
    //Set initial location of animated GIF before the scrolling and resizing events occur
    Sys.WebForms.PageRequestManager.getInstance().add_beginRequest(function(sender, args)
    {
        if (container && recursiveFind(container, args.get_postBackElement().id))
        {
            var intID = setInterval(function()
            {
                if (nextQuery(container).css("display") != "none" && nextQuery(updateProgressBlock).css("display") != "none")
                {
                    clearInterval(intID);
                    setGIFLocation(container, updateProgressBlock, isModalPopup);
                }
            }, 250);
        }
    });
    if (isModalPopup)
    {
        nextQuery(document.forms).submit(function()
        {
            if (Sys.WebForms.PageRequestManager.getInstance().get_isInAsyncPostBack())
            {
                var intervalID = setInterval(function()
                {
                    var scrollWidth = getScrollWidth(container);
                    var scrollHeight = getScrollHeight(container);
                    if (scrollWidth > nextQuery(updateProgressBlock).width() || scrollHeight > nextQuery(updateProgressBlock).height())
                    {
                        clearInterval(intervalID);
                        Sys.UI.DomElement.setLocation(updateProgressBlock, 0, 0);
                        nextQuery(updateProgressBlock).width(scrollWidth);
                        nextQuery(updateProgressBlock).height(scrollHeight);
                        setGIFLocation(container, updateProgressBlock, isModalPopup);
                    }
                }, 250);
            }         
        });
        nextQuery(container).scroll(function() { setGIFLocation(container, updateProgressBlock, isModalPopup); });
    }
    else
    {
        nextQuery(window).resize(function() { setGIFLocation(container, updateProgressBlock, isModalPopup); });
        nextQuery(window).scroll(function() { setGIFLocation(container, updateProgressBlock, isModalPopup); });
    }

}

function setupModalPopupValidatorCallout(behaviorID, modalpopup)
{
    var intID = setInterval(function()
    {
        var callout = $find(behaviorID);
        if (callout)
        {
            clearInterval(intID);
            if (!callout._popupBehavior)
            {
                callout._ensureCallout();
            }
            callout._popupBehavior.add_shown(function()
            {
                var modalViewport = new ViewPortVars(modalpopup);
                //input's left position + width + small buffer = right side of the control
                var x = nextQuery(callout._elementToValidate).scrollLeft() + nextQuery(callout._elementToValidate).width() + 3;
                var y = nextQuery(callout._elementToValidate).scrollTop();
                callout._popupBehavior.set_x(x + modalViewport.x());
                callout._popupBehavior.set_y(y + modalViewport.y());
            });
        }
    }, 250);
}

//Only comes up on the product detail page in firefox when the main image is positioned left
//and the detail style is tabbed. When that happens we call this function to reposition the validator callout
//manually using the style shown below
function reformatFaultyCallout(behaviorID)
{
    var intID = setInterval(function()
    {
        var callout = $find(behaviorID);
        if (callout)
        {
            clearInterval(intID);
            if (!callout._popupBehavior)
            {
                callout._ensureCallout();
            }
            callout._popupBehavior.add_shown(function()
            {
                var leftPostition = (nextQuery(callout._elementToValidate).width() + 5) + "px";
                var top = callout._elementToValidate.offsetTop;
                var topMargin = "-" + (top + 17) + "px";
                nextQuery(callout._popupTable).css({
                    "position": "relative",
                    "left": leftPostition,
                    "top": "0px",
                    "margin-top": topMargin,
                    "margin-bottom": "-90px",
                    "margin-right": "-168px",
                    "margin-left": "0px"
                });
            });
        }
    }, 250);
}

function modalPopupDisplay() {
        if (AjaxControlToolkit.ModalPopupBehavior) {
            if (!AjaxControlToolkit.ModalPopupBehavior.prototype.oldHide) {
                AjaxControlToolkit.ModalPopupBehavior.prototype.oldHide = AjaxControlToolkit.ModalPopupBehavior.prototype.hide;
                AjaxControlToolkit.ModalPopupBehavior.prototype.hide = function() {
                    var name = "#" + this._PopupControlID
                    nextQuery(name).css({ "display": "none" });
                    this.oldHide();
                }
            }
        }
}

function setupDymanicPopup(behaviorID, panelID)
{
    var intID = setInterval(function()
    {
        var dynamicPopulate = $find(behaviorID);
        if (dynamicPopulate)
        {
            clearInterval(intID);
            dynamicPopulate.add_populated(function() { viewport.positionPopup($get(panelID)); });
        }
    }, 250);
}

function isDefined(variable) {
    return (typeof (window[variable]) == "undefined") ? false : true;
}

//Patch Code for AjaxControlToolkit bug - 11/09/2009
//There is a bug in AjaxControlToolkit with Safari 3 that this code below fixes. Certain Modal Popups (Product Review and Product 
//Questions) will not launch correctly. If AjaxControlToolkit and/or Safari 3 are upgraded after 11/09/2009 try commenting this 
//patch code out and testing the bug again:
// 1) Go to product detail
// 2) Click on "Submit a Review"
// If the bug persists then the modal popup won't launch.
Sys.Browser.WebKit = {}; //Safari 3 is considered WebKit
if (navigator.userAgent.indexOf('WebKit/') > -1)
{
    Sys.Browser.agent = Sys.Browser.WebKit;
    Sys.Browser.version = parseFloat(navigator.userAgent.match(/WebKit\/(\d+(\.\d+)?)/)[1]);
    Sys.Browser.name = 'WebKit';
}
//End patch code

function resetDisableButton(submitButton, disabledButton)
{
    nextQuery(submitButton).css('display', 'inline');
    nextQuery(disabledButton).css('display', 'none');
}