﻿function changeMessage(myId, myClass, myString) {
    $("#" + myId).slideUp("normal", function () {
        document.getElementById(myId).className = myClass;
        document.getElementById(myId).innerHTML = myString;
    });
    $("#" + myId).slideDown();
}

function getRadioValue(radioObject) {
    for (i = 0; i < radioObject.length; i++) {
        if (radioObject[i].checked) {
            return radioObject[i].value;
        }
    }

    return "";
}

function getQueryString(name)
{
    name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
    var regexS = "[\\?&]" + name + "=([^&#]*)";
    var regex = new RegExp(regexS);
    var results = regex.exec(window.location.href);
    if(results == null){
        return "";
    }else{
        return decodeURIComponent(results[1].replace(/\+/g, " "));
    }
}

function fixQuotes(string){
    string = string.replace(new RegExp('"', 'g'), '&#92;&#34;');
    string = string.replace(new RegExp("'", "g"), "&#92;&#39;");
    return string;
}

function parseBool(string){
    return /true/i.test(string);
}

function setupWatermarks() {
    //Get empty textboxes
    var emptyTextBoxes = $("input:text").filter(function () {
        return $(this).attr("watermark") != undefined;
    });

    //Loop them
    emptyTextBoxes.each(function () {
        //Set focus
        $(this).focus(function () {
            if ($(this).val() == $(this).attr("watermark")) {
                $(this).val("");
                $(this).removeClass("watermark");
            }
        });

        //Set blur
        $(this).blur(function () {
            if ($(this).val() == "") {
                $(this).val($(this).attr("watermark"));
                $(this).addClass("watermark");
            }
        });

        //Initialize
        if ($(this).val() == "" || $(this).val() == $(this).attr("watermark")) {
            $(this).val($(this).attr("watermark"));
            $(this).addClass("watermark");
        }
    });
}
