﻿



function Tab(currentField, nextField) {
    // Determine if the current field's max length has been reached.

    if (currentField.value.length == currentField.maxLength) {
        // Retreive the next field in the tab sequence, and give it the focus.

        document.getElementById(nextField).focus();
    }
}

    function NewWindow(ref, h, w, s) {
        if (s == undefined) {
            s = "no";
        }
        if (h == "max") {
            h = screen.height / 1.2;
        }
        if (w == "max") {
            w = screen.width / 1.2;
        }
        var winW = (screen.width - w) / 2;
        var winH = (screen.height - h) / 2;
        var strFeatures = "toolbar=no,status=no,menubar=no,location=no"
        strFeatures = strFeatures + ",scrollbars=" + s + ",resizable=no,height=" + h + ",width=" + w + ",top=" + winH + ",left=" + winW + ""

        newWin = window.open(ref, "TellObj", strFeatures);
        newWin.opener = top;
    }



    function showhide(id) {
        var obj;
        if (document.getElementById) {
            obj = document.getElementById(id);
            if (obj.style.display == "none") {
                obj.style.display = "block";
            } else {
                obj.style.display = "none";
            }
        }
    }



    function roundToPrecision(inputNum, desiredPrecision) {
        var precisionGuide = Math.pow(10, desiredPrecision);
        return (Math.round(inputNum * precisionGuide) / precisionGuide);
    }

    //converts the input number into a string and adds zeroes
    //until the desired precision is reached and then
    //returns the new string



    function addZeroesToPrecision(inputNum, desiredPrecision) {
        var numString = inputNum + "";
        // var s = numString.substring(numString.search(/\./))
        // alert(s);
        //  if (s = 0) {
        //       numString = numString + ".";
        // }

        var afterDecimalString = numString.substring(numString.search(/\./) + 1);
        alert(afterDecimalString);
        while (afterDecimalString.length < desiredPrecision) {
            afterDecimalString += "0";
            numString += "0";
        }
        return (numString);
    }



    // Textbox on focus and onblur attributes
    function DoBlur(fld) {
        fld.className = 'textbox-blur';
    }


    function DoFocus(fld) {
        fld.className = 'textbox-focus';
    }


    function DisableCopyPaste() {

        // alert('This functionality has been disabled !');            

        window.clipboardData.clearData("Text"); //for cleaning up the clipboard

        // Cancel default behavior

        event.returnValue = false;

    }
    function showhide(id) {
        var obj;
        if (document.getElementById) {
            obj = document.getElementById(id);
            if (obj.style.display == "none") {
                obj.style.display = "block";
            } else {
                obj.style.display = "none";
            }
        }
    }


    function addLoadEvent(func) {
        var oldonload = window.onload;
        if (typeof window.onload != 'function') {
            window.onload = func;
        }
        else {
            window.onload = function() {
                oldonload();
                func();
            }
        }
    }

    function changeFontSize(inc) {
        var p = document.getElementsByTagName('p');
        for (n = 0; n < p.length; n++) {
            if (p[n].style.fontSize) {
                var size = parseInt(p[n].style.fontSize.replace("px", ""));
            } else {
                var size = 12;
            }
            p[n].style.fontSize = size + inc + 'px';

        }
    }

    function imgOn(imgName) {
        if (document.images) {
            document[imgName].src = eval(imgName + ".src");
        }
    } 			   //This function changes the image back when off.
    function imgOff(imgName) {
        if (document.images) {
            document[imgName].src = eval(imgName + ".src");
        }
    }


    function preloadimages() {
        var myimages = new Array()
        for (i = 0; i < preloadimages.arguments.length; i++) {
            myimages[i] = new Image()
            myimages[i].src = preloadimages.arguments[i]

        }
    }

    // Textbox on focus and onblur attributes
    function DoBlur(fld) {
        fld.className = 'textbox-blur';
    }


    function DoFocus(fld) {
        fld.className = 'textbox-focus';
    }

    function ConfirmLeaveWebsite(name) {
        var msg;
        msg = 'You are now leaving The Legend Group® Website. \n\n'
        msg += 'Neither The Legend Group® nor its affiliates endorse '+name+'\'s website, its sponsors, '
        msg += 'or any of the policies, activities, products or services offered on the site or by '
        msg += 'any company or advertiser on this site.\n\nThank you for visiting The Legend Group®.';

        return confirm(msg);
    }
    //usage: onclick="return ConfirmLeaveWebsite('name');"

    function theRotator() {
        //Set the opacity of all images to 0
        $('div#rotator ul li').css({ opacity: 0.0 });

        //Get the first image and display it (gets set to full opacity)
        $('div#rotator ul li:first').css({ opacity: 1.0 });

        //Call the rotator function to run the slideshow, 6000 = change to next image after 6 seconds
        setInterval('rotate()', 5000);

    }

    function rotate() {
        //Get the first image
        var current = ($('div#rotator ul li.show') ? $('div#rotator ul li.show') : $('div#rotator ul li:first'));

        //Get next image, when it reaches the end, rotate it back to the first image
        var next = ((current.next().length) ? ((current.next().hasClass('show')) ? $('div#rotator ul li:first') : current.next()) : $('div#rotator ul li:first'));

        //Set the fade in effect for the next image, the show class has higher z-index
        next.css({ opacity: 0.0 })
	.addClass('show')
	.animate({ opacity: 1.0 }, 1000);

        //Hide the current image
        current.animate({ opacity: 0.0 }, 1000)
	.removeClass('show');

    };

    function MaxLength(Object, MaxLen) {
      
        return (Object.value.length <= (MaxLen-1));
    }

    // EMAIL MASKING
    /*******************************************************************************/
    function mailLink(name, domain, extension, displayName) {

        if (displayName == undefined) {
            displayName = name + "@" + domain + "." + extension
        }

        linkOnHover = displayName;
        document.write('<a href="mail' + 'to:' + name + '@' + domain + '.' + extension + '" title="' + linkOnHover + '">' + displayName + '</a>')
    }
    
    /*******************************************************************************/
    
    
    
    // CONTACT FORM SECTIONS
    /*******************************************************************************/
    function moreinfo(obj) {
     //   alert(obj.location.href);

        var page = encodeURIComponent(obj.location.href);
        var title = encodeURIComponent(obj.document.title);
        NewWindow('/popups/contact/default.aspx?type=4&page=' + page + '&title=' + title + '',700,520,"yes");

    }
    function rfp(obj) {
        //   alert(obj.location.href);

        var page = encodeURIComponent(obj.location.href);
        var title = encodeURIComponent(obj.document.title);
        NewWindow('/popups/contact/rfp.aspx?&page=' + page + '&title=' + title + '', 750, 480);

    }
    function contactUs() {
       NewWindow('/popups/contact/default.aspx?type=1', 700, 490);

   }
   function ContactInvPro(id) {
       NewWindow('/popups/contact/default.aspx?type=2&id=' + id + '', 700, 490);

   }
   function ContactRep(id) {
       NewWindow('/popups/contact/default.aspx?type=3&enc=y&id=' + id + '', 700, 490);

   }
   function ContactRVP(id) {
       NewWindow('/popups/contact/default.aspx?type=3&enc=n&id=' + id + '', 700, 490);

   }

   /*******************************************************************************/



