﻿//Trim String
String.prototype.trim = function() {
    return this.replace(/^\s*/, "").replace(/\s*$/, "");
}

//Get radio buttion selected value
function GetRadioElementSelectedValue(radioElement) {

    if (radioElement.length != undefined) {
        for (var i = 0; i < radioElement.length; i++) {
            if (radioElement[i].checked) {
                var radVal = radioElement[i].value;
                return radVal;
            }
        }
    }
    else {
        if (radioElement.checked) {
            return radioElement.value;
        }
    }

}

//Get selected index based on value
function SetSelectedIndexBasedOnValue(dropDownElement, value) {

    for (var i = 0; i < dropDownElement.options.length; i++) {
        if (dropDownElement.options[i].value == value) {
            dropDownElement.options[i].selected = true;
        }
    }
}


//Function for image change on mouse down
function ButtonDown(buttonId, imageName) {
    if (document.images) {
        var element = document.getElementById(buttonId);
        element.src = "/Content/Images/" + imageName + "-click.png";
    }
}

//Function for image change on mouse up
function ButtonUp(buttonId, imageName) {
    if (document.images) {
        var element = document.getElementById(buttonId);
        element.src = "/Content/Images/" + imageName + ".png";
    }
}

//Function for image change on mouse over
function ButtonMouseOver(buttonId, imageName) {
    if (document.images) {
        var element = document.getElementById(buttonId);
        element.src = "/Content/Images/" + imageName + "-hover.png";
    }
}

//Function for image change on mouse out
function ButtonMouseOut(buttonId, imageName) {
    if (document.images) {
        var element = document.getElementById(buttonId);
        element.src = "/Content/Images/" + imageName + ".png";
    }
}

//Function for page navigation
function Navigate(href, newWindow) {
    if (newWindow) {
        window.open(href, "PopupWindow", "", "");
    }
    else {
        document.location.href = href;
    }
}

//Set cookie
function SetCookie(c_name, value, exdays) {
    var exdate = new Date();
    exdate.setDate(exdate.getDate() + exdays);
    var c_value = escape(value) + ((exdays == null) ? "" : "; expires=" + exdate.toUTCString());
    document.cookie = c_name + "=" + c_value;
}

//Read cookie
function GetCookie(c_name) {
    var i, x, y, ARRcookies = document.cookie.split(";");
    for (i = 0; i < ARRcookies.length; i++) {
        x = ARRcookies[i].substr(0, ARRcookies[i].indexOf("="));
        y = ARRcookies[i].substr(ARRcookies[i].indexOf("=") + 1);
        x = x.replace(/^\s+|\s+$/g, "");
        if (x == c_name) {
            return unescape(y);
        }
    }
}
