﻿/* Ajax methods */
function ajaxReplace(href, containerId, isAjaxParamName, onsuccess) {
    isAjaxParamName = isAjaxParamName ? isAjaxParamName : "isajaxrequest";

    /* Add parameter to href */
    var indexOf = href.indexOf("?");
    if (indexOf > -1) {
        href = href + "&";
    }
    else {
        href = href + "?";
    }
    href = href + isAjaxParamName + "=true",

	$j.ajax({
	    url: href,
	    dataType: "html",
	    success: function(response) {
	        $j(containerId).html(response);
	        if (typeof onsuccess == "function") {
	            onsuccess();
	        }
	    }
	});
}

function addQueryStringParameter(href, parameterName, parameterValue) {
    var indexOf = href.indexOf("?");
    if (indexOf > -1) {
        href = href + "&";
    }
    else {
        href = href + "?";
    }
    href = href + parameterName + "=" + parameterValue;
    return href;
}


function initEventsAndPage() {
    initEvents(true);
}

function initEvents(fireInitPage) {

//    setVAlign();

    if (fireInitPage) {
        /* moved in here so we can bind local events */
        if (typeof initPage == "function") {
            initPage();
        }
    }
}

// Fire off page specific init method
$j(document).ready(function() {

    initEvents();

    if (typeof initPage == "function") {
        initPage();
    }
});


/* String method to strip out a value */
function stripValue(search, prefix, terminator) {

    var result = search;

    if (search.indexOf(prefix) != -1) {
        var temp = search.indexOf(prefix) + prefix.length;
        if (search.indexOf(terminator, temp) != -1) {
            result = search.substring(temp, search.indexOf(terminator, temp))
        } else {
            result = search.substring(temp);
        }
    }

    return result;
}
