/*
* SOFTTEK VALORES CORPORATIVOS S.A. DE C.V. (SOFTTEK)
* COPYRIGHT 2008(C)
*
* 1. MENSAJE LEGAL
* EL USO Y DECOMPILACION DEL CODIGO Y LIBRERIAS CONTENIDO EN ESTA DISTRIBUCION
* ESTA LIMITADO EXCLUSIVAMENTE PARA SOFTTEK Y SUS CLIENTES POR LO QUE
* QUEDA LEGALMENTE PROHIBIDO HACER USO DE CUALQUIER ARTEFACTO POR CUALQUIER
* OTRA PERSONA FISICA O MORAL A MENOS QUE SOFTTEK LO ACREDITE POR ESCRITO PARA HACERLO.
*/
/**
* USER MANAGEMENT FEATURE COMMON JAVASCRIPT FUNCTIONS
* @author ricardo.barranco@softtek.com
*
*/
// Global variable to references Dialog Alert Popup
var alertDialog;
var confirmDialog;
var DIALOG_ERROR = 1;
var DIALOG_WARNING = 2;
var DIALOG_SUCCESS = 3;
var DIALOG_WAIT = 4
/**
* Shows the alert Dialog Popup Window
* @param txtTitle Dialog Title
* @param txtContent Dialog Content
*/
function dialogAlert(txtTitle, txtContent, flag, dialogType)
{
if (flag) {
document.getElementById("mascara").style.visibility="visible";
}
if(alertDialog == null)
{
pane = document.createElement('div');
// create the message place holder and add it to the dialog
promptMessage = document.createElement('div');
promptMessage.id = "promptMessage";
pane.appendChild(promptMessage);
alertDialog = new dijit.Dialog({ title: txtTitle},pane);
dojo.body().appendChild(alertDialog.domNode);
alertDialog.startup();
}
var contenido = "
";
alertDialog.attr("title", txtTitle);
dojo.byId('promptMessage').innerHTML = decodeHtml(contenido);
alertDialog.show();
if (flag) {
dojo.connect(alertDialog,"hide",function (e) {
document.getElementById("mascara").style.visibility="hidden";
});
}
return alertDialog;
}
/*Función para mostrar un diálogo de confirmación,
* en callbackFn pasar el nombre de una función JS que se va a ejecutar si la respuesta del
* usuario es SI. Usar e para hacer llegar un objeto a la función que se ejecuta dar click en SI
* */
function dialogConfirm(title, question, callbackFn, e) {
callback = function(mouseEvent) {
errorDialog.hide();
errorDialog.destroyRecursive();
if (window.event) e = window.event;
var srcEl = mouseEvent.srcElement? mouseEvent.srcElement : mouseEvent.target; //IE or Firefox
if (srcEl.id == 'yes') {
callbackFn(e);
}
errorDialog=null;
questionDiv=null;
yesButton=null;
noButton=null;
};
var errorDialog = new dijit.Dialog({ id: 'queryDialog', title: title });
var questionDiv = dojo.create('div', { innerHTML: question });
var yesButton = new dijit.form.Button(
{ label: 'Si', id: 'yes', onClick: callback });
var noButton = new dijit.form.Button(
{ label: 'No', id: 'no', onClick: callback });
errorDialog.containerNode.appendChild(questionDiv);
errorDialog.containerNode.appendChild(yesButton.domNode);
errorDialog.containerNode.appendChild(noButton.domNode);
errorDialog.show();
}
function getImage(dialogType){
var imagePath = contextPath+"/images/main/";
if(!dialogType)
dialogType = 0;
switch(dialogType){
case DIALOG_ERROR :
imagePath = imagePath + "tache.png";
break;
case DIALOG_WARNING:
imagePath = imagePath + "ico-alert-48x48.png";
break;
case DIALOG_SUCCESS:
imagePath = imagePath + "ok.png";
break;
case DIALOG_WAIT:
imagePath = imagePath + "reloj.png";
break;
default:
imagePath = imagePath + "ico-alert-48x48.png";
}
return imagePath;
}
/**
* Shows the alert Dialog Popup Window
* @param txtTitle Dialog Title
* @param txtContent Dialog Content
*/
/*function dialogAlert(txtTitle, txtContent)
{
if(alertDialog == null)
{
pane = document.createElement('div');
// create the message place holder and add it to the dialog
promptMessage = document.createElement('div');
promptMessage.id = "promptMessage";
pane.appendChild(promptMessage);
alertDialog = new dijit.Dialog({ title: txtTitle},pane);
dojo.body().appendChild(alertDialog.domNode);
alertDialog.startup();
}
alertDialog.attr("title", txtTitle);
//alertDialog.attr("content", txtContent);
dojo.byId('promptMessage').innerHTML = decodeHtml(txtContent);
alertDialog.domNode.style.zIndex = 2000;
alertDialog.show();
return alertDialog;
}
*/
/**
* Shows a "wait" Dialog
*/
function showWait()
{
return dialogAlert("Cargando", "Por favor, espere...",false, DIALOG_WAIT);
}
/**
* Hides the "wait" Dialog
*/
function hideWait()
{
alertDialog.hide();
}
/**
* A prototype function to extend the functionality of Array object.
* It verifies if an element is contained in the Array.
* @param element Element to find
* @return true if the element is contained in Array otherwise false.
*/
Array.prototype.contains = function (element)
{
for (var i = 0; i < this.length; i++)
{
if (this[i] == element)
{
return true;
}
}
return false;
}
/**
* Validates that the value doesn't contain any special character
* such as !°"#$%&/()=?'¿|¨´*][
* @param value String value to validate
* @return true if string doesn't contain special characters otherwise false
*/
function isValidInputString(value)
{
var pattern=/^([\s\w+@_.-])*$/;
if (pattern.test(value)) {
return true;
} else {
return false;
}
}
/**
* Convert encoded html into an html tags
* @param text String value to decode
* @return Html decoded text
*/
function decodeHtml(text) {
var newText = text.replace("&","&");
newText = newText.replace("<","<");
newText = newText.replace(">",">");
return(newText );
}
function replaceAll(source,toFind,toReplace){
var temp = source;
var index = temp.indexOf(toFind);
while(index!=-1){
temp = temp.replace(toFind,toReplace);
index = temp.indexOf(toFind);
}
return temp;
}
function procesarErrores(errors){
for(i=0;i