
/**
 * Caso de algum erro de javascript,
 * abre-se um alert com os detalhes do erro.
 *
 */

window.onerror = function(msg, url, line) {
    var error = "";
    error += "Ocorreu um erro no sistema: \n\n";
    error += "Erro  : " + msg + "\n";
    error += "URL   : " + url + "\n";
    error += "Linha : " + line + "\n\n";
    error += "Por favor contacte o seu administrador.";
    window.alert(error);
}

window.removeBodyChild = function(child) {
    document.getElementsByTagName("body")[0].removeChild(child);
}

/**
 * Defaults methods
 *
 */
window.closeError = function() {
    window.removeBlackout();
	document.getElementById("window_error").style.display = "none";
}
window.closeConfirmDialog = function() {
	window.removeBlackout();
	document.getElementById("window_confirm_dialog").style.display = "none";
}
window.closeInputDialog = function(callback) {    
	var value = document.getElementById("txt_input_dialog").value;
	if (value == "")
	    return
	window.removeBlackout();	
	document.getElementById("window_input_dialog").style.display = "none";
	callback(value);
}

/**
 * Cria uma camada ofuscando o conteudo
 *
 */
window.blackout = function() {
    var div = document.createElement("div");
    div.setAttribute("id", "window_blackout");
    document.getElementsByTagName("body")[0].appendChild(div);
    return div;
}

window.removeBlackout = function() {
    var div = document.getElementById("window_blackout");
    if (div != null)
        window.removeBodyChild(div);
    return true;
}

/**
 * Cria uma janela popup ao centro da tela
 *
 */
window.popup = function(w, h) {
    var popup = document.createElement("div");
    popup.setAttribute("id", "popup_transfere");
    with (popup.style) {
        top = "50%";
        left = "50%";
        width = w + "px";
        height = h + "px";
        position = "absolute";
        margin = "-"+(h/2)+"px 0px 0px -"+(w/2)+"px";
    }
    return popup;
}

window.removePopup = function() {
    var div = document.getElementById("popup_transfere");
    if (div != null) 
        window.removeBodyChild(div);
    return true;
}


window.createLoading = function() {
    if (document.getElementById("window_loading") == null) {
        var body = document.getElementsByTagName("body")[0];
        var loading = document.createElement("div");
        loading.setAttribute("id", "window_loading");
        loading.innerHTML = "Carregando...";
        body.appendChild(loading);
    }
}
    
window.removeLoading = function() {
    var div = document.getElementById("window_loading");
    if (div != null)
        window.removeBodyChild(div);
}

/**
 * SGA Object
 *
 */
var SGA = function() {}



