﻿function redirectToPagePage(ddlName) {
    box = document.getElementById(ddlName);
    destination = box.options[box.selectedIndex].value;
    if (destination) location.href = destination;
}

//This code is used to provide a reference to the RadWindow "wrapper"
function GetRadWindow() {
    var oWindow = null;
    if (window.radWindow) oWindow = window.radWindow;
    else if (window.frameElement.radWindow) oWindow = window.frameElement.radWindow;
    return oWindow;
}
//SizeToFit RadWindow Pop-up
function SizeToFitRadWindow() {
    window.setTimeout(
        function() {
            var oWnd = GetRadWindow();
            oWnd.SetWidth(document.body.scrollWidth + 30);
            oWnd.SetHeight(document.body.scrollHeight + 70);

        }, 10
    );
}


//Note: Not using JQuery
function expandCollapse() {
    for (var i = 0; i < expandCollapse.arguments.length; i++) {
        var element = document.getElementById(expandCollapse.arguments[i]);
        element.style.display = (element.style.display == "none") ? "block" : "none";
    }
}

function textboxMultilineMaxlength(objTextbox, intMaxLength, strStatusDivId) {
    if (strStatusDivId != null && document.getElementById(strStatusDivId) != null) {
        if (intMaxLength - objTextbox.value.length >= 30) {
            document.getElementById(strStatusDivId).innerHTML = (intMaxLength - objTextbox.value.length);
        }
        else if (intMaxLength - objTextbox.value.length >= 20 && intMaxLength - objTextbox.value.length < 30) {
            document.getElementById(strStatusDivId).innerHTML = "<span style='color:#FFCC66; font-weight:bold;'>" + (intMaxLength - objTextbox.value.length) + "</span>";
        }
        else if (intMaxLength - objTextbox.value.length >= 10 && intMaxLength - objTextbox.value.length < 20) {
            document.getElementById(strStatusDivId).innerHTML = "<span style='color:#FF9900; font-weight:bold;'>" + (intMaxLength - objTextbox.value.length) + "</span>";
        }
        else if (intMaxLength - objTextbox.value.length < 10) {
            document.getElementById(strStatusDivId).innerHTML = "<span style='color:#F00; font-weight:bold;'>" + (intMaxLength - objTextbox.value.length) + "</span>"
        }

        //        if (objTextbox.value.length >= intMaxLength)
        //            return false;
        //        else 
        return true;
    }
}


//String Replacement
String.prototype.trim = function() {
    return this.replace(/^\s+|\s+$/g, "");
}
// Replaces all instances of the given substring.
String.prototype.replaceAll = function(strTarget, /* The substring you want to replace */strSubString /* The string you want to replace in. */) {
    var strText = this;
    var intIndexOfMatch = strText.indexOf(strTarget);

    // Keep looping while an instance of the target string
    // still exists in the string.
    while (intIndexOfMatch != -1) {
        // Relace out the current instance.
        strText = strText.replace(strTarget, strSubString)

        // Get the index of any next matching substring.
        intIndexOfMatch = strText.indexOf(strTarget);
    }

    // Return the updated string with ALL the target strings
    // replaced out with the new substring.
    return (strText);
}

function insertBBcode(fieldId, tag) {
    field = document.getElementById(fieldId);
    //	if(tag=='b' || tag=='i' || tag=='u' || tag == 'php' || tag == 'code')
    //	{

    if (document.selection) {
        field.focus();
        var selected = document.selection.createRange().text;
        sel = document.selection.createRange();
        sel.text = '[' + tag + ']' + selected + '[/' + tag + ']';
    }
    //MOZILLA/NETSCAPE/SAFARI support
    else if (field.selectionStart || field.selectionStart == 0) {
        var startPos = field.selectionStart;
        var endPos = field.selectionEnd;
        var selected = field.value.substring(startPos, endPos);
        field.focus();
        //field.value = field.value.substring(0, startPos) + '[' + tag + '][/' + tag +']' + field.value.substring(endPos, field.value.length);
        field.value = field.value.substring(0, startPos) + '[' + tag + ']' + selected + '[/' + tag + ']' + field.value.substring(endPos, field.value.length);
    }

    return false;
}

//Allow the defined "Default Button" to submit the form for a particular region AND prevent the Enter button from triggering a post back if it's in a TextArea
function FireDefaultButton(event, target) {
    // srcElement is for IE
    var element = event.target || event.srcElement;

    if (13 == event.keyCode && !(element && "textarea" == element.tagName.toLowerCase())) {
        var defaultButton;
        defaultButton = document.getElementById(target);

        if (defaultButton && "undefined" != typeof defaultButton.click) {
            defaultButton.click();
            event.cancelBubble = true;
            if (event.stopPropagation)
                event.stopPropagation();
            return false;
        }
    }
    return true;
}

//Search Box
function searchFocus(q) {
    q.style.background = '#ffffff';
}
function searchBlur(q) {
    if (q.value == '') {
        q.style.background = '#FFFFFF url(http:\x2F\x2Fwww.google.com\x2Fcoop\x2Fintl\x2Fen\x2Fimages\x2Fgoogle_custom_search_watermark.gif) left no-repeat';
    }
}