﻿function SearchBox_onFocus(searchBox, defaultSearchText) {
    if (defaultSearchText == searchBox.value) {
        searchBox.value = "";
        searchBox.style.fontStyle = 'normal';
        searchBox.style.color = 'black';
    }
}

function SearchBox_onBlur(searchBox, defaultSearchText) {
    if ("" == searchBox.value) {
        searchBox.value = HtmlDecode(defaultSearchText);
        searchBox.style.fontStyle = 'italic';
        searchBox.style.color = '#666666';      
    }
}

function SearchBox_Search(id, defaultSearchText) {
    searchBox = $get(id);
    searchText = escape(searchBox.value);
    if (defaultSearchText != searchText) {
        window.location = "http://social.msdn.microsoft.com/Search/?query=" + searchText;
        return false;
    }
}

//Code found on http://blogs.msdn.com/aoakley/archive/2003/11/12/49645.aspx
//   client side version of the useful Server.HtmlDecode method
//   takes one string (encoded) and returns another (decoded)
//
// Modification note: remove unused part of the function
function HtmlDecode(s) {
    var out = "";
    if (s == null) return;

    var l = s.length;

    //loop thru to find ASCII character value
    for (var i = 0; i < l; i++) {
        var ch = s.charAt(i);

        if (ch == '&') {
            var semicolonIndex = s.indexOf(';', i + 1);

            if (semicolonIndex > 0) {
                var entity = s.substring(i + 1, semicolonIndex);

                //decode
                if (entity.length > 1 && entity.charAt(0) == '#') {
                    if (entity.charAt(1) == 'x' || entity.charAt(1) == 'X')
                        ch = String.fromCharCode(eval('0' + entity.substring(1)));
                    else
                        ch = String.fromCharCode(eval(entity.substring(1)));
                }

                i = semicolonIndex;
            }
        }

        out += ch;
    }

    return out;
}

function OnTouCheckBoxClick(checkBoxId, nextBtnId, enableCSS, disableCSS) {
    var checkedBox = document.getElementById(checkBoxId);
    var nextBtn = document.getElementById(nextBtnId);

    if ((checkedBox == null) || (nextBtn == null))
        return;

    //Added enableCSS and disableCSS after the fact 
    //  to make it backward compatiable these 2 if statement is needed. 
    if (enableCSS == null)
        enableCSS = "OrangeButtonText";

    if (disableCSS == null)
        disableCSS = "OrangeButtonTextDisabled";

    if (checkedBox.checked) {
        nextBtn.disabled = false;
        Sys.UI.DomElement.removeCssClass(nextBtn, disableCSS);
        Sys.UI.DomElement.addCssClass(nextBtn, enableCSS + " CursorHand");
    }
    else {
        nextBtn.disabled = true;
        Sys.UI.DomElement.removeCssClass(nextBtn, enableCSS);
        Sys.UI.DomElement.removeCssClass(nextBtn, "CursorHand");
        Sys.UI.DomElement.addCssClass(nextBtn, disableCSS);
    }
}

/* Sign In Wizard */
function CheckUserForms() {
    if (typeof (Page_Validators) !== "undefined") {
        var failedControls = new Array();
        for (var i = 0; i < Page_Validators.length; i++) {
            var validator = Page_Validators[i];

            if (!((validator.controltovalidate == null)
                       || (validator.controltovalidate == undefined))) {

                var userInputControl = $get(validator.controltovalidate);

                if (userInputControl) {
                    /* Change the border color of the control depending on if it failed validation */
                    if (validator.isvalid && !IsInArray(failedControls, userInputControl)) {
                        userInputControl.style.border = "1px solid #CCCCCC";
                    } else {
                        failedControls.push(userInputControl);
                        userInputControl.style.border = "1px solid red";
                    }
                }

            }
        }
    }
}


/* Utilities */
function IsInArray(array, searchValue) {
    for (var i = 0; i < array.length; i++) {
        if (array[i] === searchValue)
            return true;
    }
    return false;
}

if(typeof(Sys)!=='undefined')Sys.Application.notifyScriptLoaded();