function includeJs(jsFile) {
    return '<scr' + 'ipt type="text/javascript" language="javascript" src="' + jsFile + '"></sc' + 'ript>\r\n';
}

function load(setOfScripts) {
    var scriptHtml = "";
    for (var i in setOfScripts) {
        scriptHtml += includeJs(setOfScripts[i]);
    }
    document.write(scriptHtml);
}

function loadTheRest() {
    //Identifying Page specific files
    var lastIndexOfSlash = document.location.pathname.lastIndexOf('/');
    var file = document.location.pathname.substring(lastIndexOfSlash + 1);

    var lastIndexOfDot = file.lastIndexOf('.');
    document.parsedPageName = file.substring(0, lastIndexOfDot);

    var lastIndexOfComma = document.parsedPageName.lastIndexOf(',');
    if (lastIndexOfComma != -1) {
        document.parsedPageName = document.parsedPageName.substring(0, lastIndexOfComma);
    }

    load([
        "/Scripts/jquery-ui-1.8.16.custom.min.js",
    //"/Scripts/jquery.template.js",
        "/Scripts/jquery.query-2.0.1.js",
    // Knockout
        "/Scripts/knockout-1.2.1.js",
    // Common A3Z files
        "/Scripts/a3z_baseScript.js",
        "/Scripts/a3z_validation.js",
        "/Scripts/Common.js",
        "/Scripts/a3z_autofill.js",
    // Page specific script
        "/Scripts/Pages/" + document.parsedPageName + ".js",
    // Google Analytics
        "/Scripts/google-analytics.js"
    ]);
}


//load([
//    //JQuery files
//    "http://ajax.microsoft.com/ajax/jquery/jquery-1.6.1.min.js",
//    "http://ajax.aspnetcdn.com/ajax/jquery.validate/1.8.1/jquery.validate.min.js",
//    "http://ajax.aspnetcdn.com/ajax/jquery.templates/beta1/jquery.tmpl.min.js"
//]);
//// fallback if CDN is not up
if (typeof window.jQuery === "undefined") {
    load([
        "/Scripts/jquery-1.6.1.min.js",
        "/Scripts/jquery.validate.js",
        "/Scripts/jquery.tmpl.min.js"
    ]);
}

loadTheRest();
