﻿//LIVEPERSON INVITATION POSITIONING BEGIN
var lpPosY = 100;
//LIVEPERSON INVITATION POSITIONING END

//PAGE ONLOAD FUNCTON
$(document).ready(function() 
{
    $("div.divUnmountedRingsSearch input").addClass("globalSearchCheckBox");
    IE6CorrectPNG();
});

String.prototype.trim = function()
{
	return this.replace(/^\s+|\s+$/g,"");
}

String.prototype.ltrim = function()
{
	return this.replace(/^\s+/,"");
}

String.prototype.rtrim = function()
{
	return this.replace(/\s+$/,"");
}

function ClearAllFields(formName)
{
    if (formName = "")
        formName = "aspnetForm";
        
    $(formName).find(":input").each(function() 
    {
        switch(this.type) 
        {
            case "password":
            case "select-multiple":
            case "select-one":
            case "text":
            case "textarea":
                $(this).val("");
                break;
            case "checkbox":
            case "radio":
                this.checked = false;
        }
    });
}

function FormattedCurrency(Amount)
{
    if (Amount != null && Amount != "")
    {
        var dollars, cents, minus = "", delimiter = ",";
        var amountArray = Amount.toString().split('.')

        if (amountArray != null && amountArray.length > 1)
            cents = amountArray[1];

        dollars = parseInt(amountArray[0]);

        if (isNaN(dollars))
            return "";

        if (dollars < 0)
            minus = "-";

        dollars = Math.abs(dollars).toString();
        	            
        amountArray = [];
        
        while (dollars.length > 3)
        {
            var nn = dollars.substr(dollars.length - 3);
            
            amountArray.unshift(nn);
            dollars = dollars.substr(0, dollars.length - 3);
        }

        if (dollars.length > 0)
            amountArray.unshift(dollars);

        dollars = amountArray.join(delimiter);

        Amount = dollars + ((cents != null && cents.length > 1) ? "." + cents : "");

        return minus + Amount;
    }
    else
        return 0;
}

function StripCurrencyCharacters(Amount)
{
    if (Amount != null)
        return Amount.replace("$", "").replace(/,/gi, "");
}

function ValidatePassword(password)
{
    var disallowedCharacters = new Array(" ", "<", ">", "'", "\"", "`", "~", "?", "/");
    
    if (password.trim() == "")
        return false;
    else if (password.trim().length < 6 || password.trim().length > 12)
        return false;
    else
    {
        for (var character in disallowedCharacters)
            if (password.indexOf(disallowedCharacters[character]) != -1)
                return false;
    }
    
    return true;
}

function SuppressAllEvents()
{
    window.history.forward(1);
    document.onkeydown = new Function("return false");
    document.onkeypress = new Function("return false");
    document.onkeyup = new Function("return false");
    
    if (document.all)
    {
        document.onmousedown = SuppressAllMouseEvents;
        document.onmouseup = SuppressAllMouseEvents;
    }
    else if (document.layers)
    {
        window.captureEvents(Event.MOUSEDOWN);
    }
    else
    {
        document.onclick = SuppressAllMouseEvents;
        document.ondblclick = SuppressAllMouseEvents;
    }
    
    document.oncontextmenu = new Function("return false");
}

function SuppressAllMouseEvents(e)
{
    if (document.all && event.button > 0)
        return false;
    else
    {
        if (e.button > 0)
        {
            e.preventDefault();
            return false;
        }
        else if (e.which > 0)
            return false;
    }
}

function AllowNumbersOnly(e)
{
    var keyID = (window.event) ? event.keyCode : e.keyCode;

    if ((window.event && event.shiftKey) || e.shiftKey)//Prevent use of the Shift key
        return false;
        
    if (keyID > 31 && (keyID < 48 || keyID > 57) && (keyID < 96 || keyID > 105) && keyID != 46)
        return false;

    return true;
}

function SuppressEnterKey(e)
{
    var keyID = (window.event) ? event.keyCode : e.keyCode;
    
    if (keyID == 13)
        return false;
}

function UnsuppressEnterKey(e)
{
    var keyID = (window.event) ? event.keyCode : e.keyCode;
    
    if (keyID == 13)
        return true;
}

function BrowserIsIE6()
{
    if (navigator.appVersion.indexOf("MSIE") != -1)
    {
        var arVersion = navigator.appVersion.split("MSIE");
        var version = parseFloat(arVersion[1]);

        if (version == 5.5 || version == 6) 
            return true;
        else
            return false;
    }
    else
        return false;
}

function IE6CorrectPNG()//Correctly handle PNG transparency in Win IE 5.5 & 6.
{
    if (BrowserIsIE6() && (document.body.filters)) 
    {
        for(var i = 0; i < document.images.length; i++)
        {
            var img = document.images[i];
            var imgName = img.src.toUpperCase();
         
            if (imgName.substring(imgName.length-3, imgName.length) == "PNG")
            {
                var imgID = (img.id) ? "id='" + img.id + "' " : "";
                var imgClass = (img.className) ? "class='" + img.className + "' " : "";
                var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' ";
                var imgStyle = "display:inline-block;" + img.style.cssText;
            
                if (img.align == "left")
                    imgStyle = "float:left;" + imgStyle;
                
                if (img.align == "right")
                    imgStyle = "float:right;" + imgStyle;
                
                if (img.parentElement.href)
                    imgStyle = "cursor:hand;" + imgStyle;
            
                var strNewHTML = "<span " + imgID + imgClass + imgTitle + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";" + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader" + "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>";
            
                img.outerHTML = strNewHTML;
                i--;
            }
        }
    }
}