var arrHost = location.href.split("/");
var protocol = arrHost[0];
var host = arrHost[2];

var devAppHost = "devtp.trainingpeaks.com";
var devSupportHost = "devsupport.trainingpeaks.com";

if (location.href.indexOf("localhost") > -1) {
    devAppHost = "localhost";
    devSupportHost = "localhost";
}

if (location.href.indexOf("deployumbraco") > -1) {
    devAppHost = "deploytp.trainingpeaks.com";
    devSupportHost = "deploysupport.trainingpeaks.com";
}

if (location.href.indexOf("devsupport") > -1)
    host = "devumbraco.trainingpeaks.com";


$(document).ready(function () {
    if (location.href.indexOf("devumbraco") > -1 || location.href.indexOf("devsupport") > -1 || location.href.indexOf("deployumbraco") > -1) {

        if (location.href.indexOf("deployumbraco") > -1)
            $("#wrapper").append("<div style=\"position:fixed;width:100%;z-index:3000;bottom:0;left:0;padding:3px;background:purple;font-weight:bold;border:2px solid purple;color:#fff;opacity:0.4;filter:alpha(opacity=40)\">DEPLOY ENVIRONMENT</div>");
        else
            $("#wrapper").append("<div style=\"position:fixed;width:100%;z-index:3000;bottom:0;left:0;padding:3px;background:#b20101;font-weight:bold;border:2px solid #cc0000;color:#fff;opacity:0.4;filter:alpha(opacity=40)\">DEVELOPMENT ENVIRONMENT</div>");

        $("a[href^='http://home.trainingpeaks.com']")
       .each(function () {
           this.href = this.href.replace(/^http:\/\/home\.trainingpeaks\.com/, protocol + "//" + host);
       });
        $("a[href^='https://home.trainingpeaks.com']")
       .each(function () {
           this.href = this.href.replace(/^https:\/\/home\.trainingpeaks\.com/, protocol + "//" + host);
       });
        $("a[href^='http://www.trainingpeaks.com']")
       .each(function () {
           this.href = this.href.replace(/^http:\/\/www\.trainingpeaks\.com/, "http://" + devAppHost);
       });
        $("a[href^='https://www.trainingpeaks.com']")
       .each(function () {
           this.href = this.href.replace(/^https:\/\/www\.trainingpeaks\.com/, "https://" + devAppHost);
       });
        $("form[action^='http://home.trainingpeaks.com']")
       .each(function () {
           this.action = this.action.replace(/^http:\/\/home\.trainingpeaks\.com/, "http://" + host);
       });
        $("form[action^='https://home.trainingpeaks.com']")
       .each(function () {
           this.action = this.action.replace(/^https:\/\/home\.trainingpeaks\.com/, "https://" + host);
       });
        $("form[action^='http://www.trainingpeaks.com']")
       .each(function () {
           this.action = this.action.replace(/^http:\/\/www\.trainingpeaks\.com/, "http://" + devAppHost);
       });
        $("form[action^='https://www.trainingpeaks.com']")
       .each(function () {
           this.action = this.action.replace(/^https:\/\/www\.trainingpeaks\.com/, "https://" + devAppHost);
       });
        $("a[href^='http://support.trainingpeaks.com']")
       .each(function () {
           this.href = this.href.replace(/^http:\/\/support\.trainingpeaks\.com/, "http://" + devSupportHost);
       });
    }
});

