﻿

function isSequential(Value, validChars, numChars) {
        if (Value.length < numChars) return false;

        var charSet = Value.substring(Value.length - numChars);
            if (validChars.indexOf(charSet) > -1) {
                return true;
            }       
        return false;
    }
    function contains(Value, validChars) {

        for (i = 0; i < value.length; i++) {

            if (validChars.indexOf(Value.charAt(i)) >-1) {
               return true
            }
        }
        return false;
    }

    function isRepetative(Value, numChars) {
        if (Value.length < numChars) return false;

        var charSet = Value.substring(Value.length - numChars);
        var count = 1;
        var curChar = charSet.charAt(0);
             
        for (i = 1; i < charSet.length; i++) {
         
            if (curChar == charSet.charAt(i)) {
                count += 1;
                curChar = charSet.charAt(i);
            }
        }
        
        if (count == numChars) {
            return true;
        } 
        else
        {
return false;
        }         
    } 


function passwordStrength(password, passwordStrength, passwordDescription, text) {
    var numbers = "0123456789";
    var lowercase = "abcdefghijklmnopqrstuvwxyz";
    var uppercase = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
    var punctuation = "!.@$£#*()%~<>{}[]/\|:;'";
 
    var desc = new Array();

    desc[0] = "Very Weak";

    desc[1] = "Weak";

    desc[2] = "Better";

    desc[3] = "Medium";

    desc[4] = "Strong";

    desc[5] = "Strongest";

    var score = 0;

    //if password bigger than 6 give 1 point

    if (password.length > 8) score++;

    //if password has both lower and uppercase characters give 1 point      

    if ((password.match(/[a-z]/)) && (password.match(/[A-Z]/))) score++;

    //if password has at least one number give 1 point

    if (password.match(/[0-9]/)) score++;

    //if password bigger than 12 give another 1 point

    if (password.length > 12) score++;

    //if password has at least one special character give 1 point

    //if (password.match(/[!.@$£#*()%~<>{}]/)) score++;
    if (password.match(/[^a-zA-Z0-9]/)) score++;
    
    
    //if password has at 2 or more of the same character take 1 point (i.e. abc1123)
    if (isRepetative(password, 2)) {
       score--;
    //  alert("Repeating characters reduces the effectivness of your password");
  }

  if (isSequential(password, lowercase, 3)) {
      score--;
    //  alert("using sequential characters reduces the effectivness of your password");
  }
  if (isSequential(password, uppercase, 3)) {
      score--;
   //   alert("using sequential characters reduces the effectivness of your password");
  }
  if (isSequential(password, numbers, 3)) {
      score--;
    //  alert("using sequential numbers reduces the effectivness of your password");
  }

// if score falls below 0, set to zero
if (score < 0) score = 0;


    if (text == 'Y') {    
  document.getElementById(passwordDescription).innerHTML = desc[score];
}

if (password.length== 0) {
    document.getElementById(passwordDescription).innerHTML = "No Password Entered";
}



document.getElementById(passwordStrength).className = "passwordStrength strength" + score;

}

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);
    }

    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));
    }

    // 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);

   }

   /*******************************************************************************/


