﻿var _baseUrl;

function SetFocusDelay(controlId)
{
	setTimeout("document.getElementById('" + controlId + "').focus()", 500);
}

function SimpleSwap(el,which){
  el.src=el.getAttribute(which || "origsrc");
}

function SimpleSwapSetup(){
  var x = document.getElementsByTagName("img");
  for (var i=0;i<x.length;i++){
    var oversrc = x[i].getAttribute("oversrc");
    if (!oversrc) continue;
      
    // preload image
    // comment the next two lines to disable image pre-loading
    x[i].oversrc_img = new Image();
    x[i].oversrc_img.src=oversrc;
    // set event handlers
    x[i].onmouseover = new Function("SimpleSwap(this,'oversrc');");
    x[i].onmouseout = new Function("SimpleSwap(this);");
    // save original src
    x[i].setAttribute("origsrc",x[i].src);
  }
}

function SetBaseUrl(url) {
    _baseUrl = url;
}

var PreSimpleSwapOnload =(window.onload)? window.onload : function(){};
window.onload = function() { PreSimpleSwapOnload(); SimpleSwapSetup(); }

function RemoveCareer(id) {
    $.ajax({
        type: "POST",
        cache: false,
        url: _baseUrl + "/quicklinks/removecareer",
        data: {
            id: id
        },
        dataType: "html",
        error: function(XMLHttpRequest, textStatus, errorThrown) {
            var message = XMLHttpRequest.responseText;
            var exp = new RegExp('<title>(.*)<\/title>', 'i');
            if (exp.exec(XMLHttpRequest.responseText)) {
                message = RegExp.lastParen;
            }
            var html = "<div style='min-height: 300px;'>";
            html += "<div style='margin: 0 auto; text-align: center; width: 100%; padding-top: 100px;'>";
            html += "<div>There was an error trying to remove a career.</div>";
            html += "<div>" + message + "</div>";
            html += "</div>";
            html += "</div>";
            $('#quicklinks-message').empty();
            $('#quicklinks-message').append(html);
        },
        success: function(data) {
            $('#quicklinks-careers').empty();
            $('#quicklinks-careers').append(data);

            var html = "<div class='status-panel' style='width: 225px;'>";
            html += "You have successfully removed a career from your Quicklinks.";
            html += "</div>";

            $('#quicklinks-message').empty();
            $('#quicklinks-message').append(html);
        }
    });
    return false;
}

function RemoveSchool(id) {
    $.ajax({
        type: "POST",
        cache: false,
        url: _baseUrl + "/quicklinks/removeschool",
        data: {
            id: id
        },
        dataType: "html",
        error: function(XMLHttpRequest, textStatus, errorThrown) {
            var message = XMLHttpRequest.responseText;
            var exp = new RegExp('<title>(.*)<\/title>', 'i');
            if (exp.exec(XMLHttpRequest.responseText)) {
                message = RegExp.lastParen;
            }
            var html = "<div style='min-height: 300px;'>";
            html += "<div style='margin: 0 auto; text-align: center; width: 100%; padding-top: 100px;'>";
            html += "<div>There was an error trying to remove a career.</div>";
            html += "<div>" + message + "</div>";
            html += "</div>";
            html += "</div>";
            $('#quicklinks-message').empty();
            $('#quicklinks-message').append(html);
        },
        success: function(data) {
            $('#quicklinks-schools').empty();
            $('#quicklinks-schools').append(data);

            var html = "<div class='status-panel' style='width: 225px;'>";
            html += "You have successfully removed a school from your Quicklinks.";
            html += "</div>";

            $('#quicklinks-message').empty();
            $('#quicklinks-message').append(html);
        }
    });
    return false;
}

function RemoveProgram(id) {
    $.ajax({
        type: "POST",
        cache: false,
        url: _baseUrl + "/quicklinks/removeprogram",
        data: {
            id: id
        },
        dataType: "html",
        error: function(XMLHttpRequest, textStatus, errorThrown) {
            var message = XMLHttpRequest.responseText;
            var exp = new RegExp('<title>(.*)<\/title>', 'i');
            if (exp.exec(XMLHttpRequest.responseText)) {
                message = RegExp.lastParen;
            }
            var html = "<div style='min-height: 300px;'>";
            html += "<div style='margin: 0 auto; text-align: center; width: 100%; padding-top: 100px;'>";
            html += "<div>There was an error trying to remove a program.</div>";
            html += "<div>" + message + "</div>";
            html += "</div>";
            html += "</div>";
            $('#quicklinks-message').empty();
            $('#quicklinks-message').append(html);
        },
        success: function(data) {
            $('#quicklinks-programs').empty();
            $('#quicklinks-programs').append(data);

            var html = "<div class='status-panel' style='width: 225px;'>";
            html += "You have successfully removed a program from your Quicklinks.";
            html += "</div>";

            $('#quicklinks-message').empty();
            $('#quicklinks-message').append(html);
        }
    });
    return false;
}
