//##############Document Info##############
/*
Created On: 	2009-01-01
Creator:			Juan Enrique Garcia Rivera
Software:		Casinfo Website
Version:			2.0
Description:		This file contains functions and processes for the cashless system
*/
//############Document Info End #############

//Modification List
/*---------------------------------------------
-->20090715A | JG | Modifying the infoMsg Object to allow multi messages in one table. Adding the Sorting order for the infoMsg
=============================================================================================================
-->20090216B | JG | Added the Menu Manager Function
-->20090216A | JG | Modifying the login, creating a new logStat variable
=============================================================================================================
-->20090214B | JG | Modified th cjAjax Object, to create the xmlHttp Object once it is created
-->20090214A | JG | Modifying the login, removing some unecessary variables
=============================================================================================================
-->20090213B | JG | Creating the infoMsg Object to present messages to the customers
-->20090213A	| JG | Changed the popWindow From Fx to Object
=============================================================================================================
-->20090212A	| JG | Modifying the logVal Function and LogProc to do the new login way
=============================================================================================================
-->20081212A	| JG | Modifying the getMyVal function to get the correct key value
=============================================================================================================
-->20081204A	| JG | Fixing Hour in  todaySet(dtVal, tFormat)
---------------------------------------------*/
//Variables Globales
var pageType = "";  //Tipo de pagina
var usrApps = "";
//var logStat = ""; //Estado del login		-->20090214A 		-->20090216A
var logStat = new Array("0", "", "scripts/cwv2_umloginprocess.php", "");		//-->20090216A	Array(loginStatus: [ 0:Not Processed | 1:not allowed | 2:allowed ], formID, loginScriptRelPath, receivedPath );
var loginTimer = 3000;  //Timer para realizar nuevamente la solicitud si esa se demora;
var tempStatus = ""; // Usada para cambiar un valor cualquiera.
var rootAddress = "https://216.86.201.18/cwv2/"; //Variable para establecer la ubicacion de las imagenes en el sitio
var imgDir = "imgs/";
var cancelBtn = '<input type="button" name="close" id="close" class="btnTypeB" value="Close" onClick="javascript: pObj.closeMe();">';
var rtrMsg = '<img src=\"imgs/icons/loader03.gif\"><br><br><span class="text">Data is being retrieved...</span>';

var curBrowser = getBrowser();

//General Object Creations
var gralReq = new cjAjax("", "", "", "", "POST");
var iObj = new infoMsg();
var pObj = new popupWindow("cover", "authPlace", "", 0, 0, "" ,'');

//Variables para el manejo de errores
errCount = 1;

function t()
{
        alert("Test Msg");
}

//Function for browser detection, Added By JG 20080911, Made By JD 20080911
function getBrowser()
{
	var ua = navigator.userAgent.toLowerCase(); 
	var bsr = "none";
	
	if(ua.indexOf("opera") != -1)
	{
		bsr = "Opera";
	}
	
	if(ua.indexOf("msie") != -1)
	{
		bsr = "Internet Explorer";
	}
	
	if(ua.indexOf("firefox") != -1)
	{
		bsr = "Firefox";
	}
	
	if(ua.indexOf("chrome") != -1)
	{
		bsr = "Google Chrome";
	}
	
	if(ua.indexOf("chrome") == -1 && ua.indexOf("safari") != -1)
	{
		bsr = "@Safari";
	}
	
	return bsr;
}

//Funcion para errores
function getMyErr(eNumber)
{
	var errArr = new Array(10000);
	
	//Initialize the Array in blank values, done to solve any initialization problems since not all array values are defined.
	for(i=0;i<errArr.length;i++)
	{
		errArr[i] = "";
	}
	
	errArr[0] = "An error has ocurred, and cannot be determined.";
	errArr[1] = "The following field is empty and requires a value:";
	errArr[2] = "The following field only accept numeric values:"
	errArr[3] = "Loginname cannot be empty.";
	errArr[4] = "Password cannot be empty.";
	errArr[5] = "Invalid login request!. Select a section or application.";
	errArr[6] = "User not valid!";
	errArr[7] = "User not allowed to view this page!";
		
	//General error Listing
	errArr[1001] = "If the problem persists, call your System Administrator for help.";
	errArr[1002] = "Please try again later.";
	errArr[1003] = "E-mail must be in the following format: accountname@domainname.com";
	errArr[1004] = "First Name field cannot be empty."
	errArr[1005] = "Last Name field cannot be empty.";
	errArr[1006] = "The E-Mail field cannot be empty.";
	errArr[1007] = "Birth Date must be as follow 2009-06-20 00:00:00.";
	errArr[1008] = "Please input the old password.";
	errArr[1009] = "Please type the new password.";
	errArr[1010] = "Confirm the new password.";
	errArr[1011] = "The confirmation password field do not match the new password field.";
	errArr[1012] = "Start date cannot be empty.";
	errArr[1013] = "End data cannot be empty.";
	errArr[1014] = "Please input a title for the news.";
	errArr[1015] = "Please input a short title for the news.";
	errArr[1016] = "News content cannot be emtpy. Please input some data for the news.";
	
	//Contact Section Errors
	errArr[6001] = "First Name field is empty.";
	errArr[6002] = "Last Name field is empty.";	
	errArr[6003] = "Please select a country.";	
	errArr[6004] = "E-mail field is empty.";	
	errArr[6005] = "Incorrect E-mail format.";		
	errArr[6006] = "Commentary field is empty.";
	
	//User Management Errors
	errArr[8001] = "Enter your login, i.e.(yourname@company.com)";
	errArr[8002] = "Enter your password";
	errArr[8003] = "Login invalid please type you email address as login, i.e.(yourname@company.com)";
	errArr[8004] = "Enter your first name";
	errArr[8005] = "Name invalid";
	errArr[8006] = "Enter your last name";
	errArr[8007] = "Last name invalid";
	errArr[8008] = "Enter your login, i.e.(yourname@company.com)";
	errArr[8009] = "Login invalid please type you email address as login, i.e.(yourname@company.com)";
	errArr[8010] = "Enter your birth date";
	errArr[8011] = "Birth date invalid, only number(4 digits)";
	errArr[8012] = "Empty month";
	errArr[8013] = "Empty date";	
			
	return errArr[eNumber];
}

/*===================Menu Manager Functions===================*/
//Example of menu new Array("MenuLabel", "MenuLink", Status);  Status: [ 1:On | 0:Off ]				-->20090216B
var curMenuObj = new Array(
new Array("")
)
var timer;
var secs = 1000;

function menuCreator(position, type, itms)
{
	clearTimeout(timer);
	
	/*Clearing previos menu*/
	menuCreatorClose();
	
	var pos = document.getElementById(position);

	curMenuObj[0][0] = pos.id;	
	
	pos.className = "menuClassContainer";
	
	/*pos.onMouseOver = function()
	{
		clearTimeout(timer);
	}
	
	pos.onMouseOut = function ()
	{
		timer = setTimeout("menuCreatorClose()", secs);
	}*/
	
	htmlCode = "";
	
	htmlCode = htmlCode + '<table width="100%" border="0" align="center" cellpadding="0" cellspacing="0" onMouseOver="javascript:clearTimeout(timer);" onMouseOut="javascript: timer = setTimeout(\'menuCreatorClose()\', secs);">\n';
	
	switch(type.toUpperCase())
	{
		case "V":
			for(i=0; i<itms.length; i++)
			{
				htmlCode = htmlCode + '<tr>\n';
				if(itms[i][2]==1)
				{
					htmlCode = htmlCode + '<td align="center" class="menuItem"  nowrap="nowrap"><a href="' + itms[i][1] + '" class="mainSubMenu">' + itms[i][0] + '</a></td>\n';
				}
				htmlCode = htmlCode + '</tr>\n';
			}
		break;
		
		case "H":
			for(i=0; itms.length; i++)
			{
				htmlCode = htmlCode + '<tr>\n';
				htmlCode = htmlCode + '<td align="center"></td>\n';
				htmlCode = htmlCode + '</tr>\n';
			}
		break;
		
		default:	
	}
	
	htmlCode = htmlCode + '</table>\n';

	pos.innerHTML = htmlCode;
	
	//clipboardData.setData("Text", htmlCode);
	
	//timer = setTimeout("alert('Cerrar')", secs);
}

//Function to close the already created menu
function menuCreatorClose()
{
	if(curMenuObj[0][0]!="")
	{
		var selObj = document.getElementById(curMenuObj[0][0]);
		
		selObj.className = "menuClassContainerOff";
		selObj.innerHTML = "";
		curMenuObj[0][0] = "";
	}
}
/*================Menu Manager Functions Ends ================*/


//Funcion para esconder y mostrar
function simpleShowHide(id, action)
{
        //alert("1");
        document.getElementById(id).style.display = action;
        //alert("2");
}

//Function to hide a set of options, tabs or spans, and show one. The first parameter will be the one that beshowed, all remaining params will be hidden
function smartShowHide()
{
        //if(arguments[1])
        //{
                for(inc=1;inc<arguments.length;inc++)
                {
                        //alert(arguments[inc]);
                        document.getElementById(arguments[inc]).style.display = 'none';
                }
        //}

        document.getElementById(arguments[0]).style.display = 'block';
}

function displayMore(imgId, spanId)
{
        if(imgId!="")
        {
                var imgChg, disp;

                if(document.getElementById(spanId).style.display=="none")
                {
                        imgChg = "minus_small";
                        disp = "block";
                }
                else
                {
                        imgChg = "add_small";
                        disp = "none";
                }

                document.getElementById(spanId).style.display = disp;
                document.getElementById(imgId).src = imgDir + "icons/" + imgChg + ".gif";
        }

}

//Funcion para mostrar y esconder los parametros del reporte para ver mas espacio en el reporte
function repView(reptParamId, reptResId, resize)
{
	var imgId = "sHReptImg";
	var btnId = "sHReptBtn";
	var txtId = "sHReptTxt";
	
	//alert(screen.height);
	
	//Cambia el script de accion
	if(document.getElementById(reptParamId).style.display=="none")
	{
		//alert("mostrar");
		document.getElementById(btnId).onClick = "javascript:repView('" + reptParamId + "', '" + reptResId + "', " + resize + ");";
		document.getElementById(txtId).innerHTML = "Hide Params";
		//alert(document.getElementById(btnId).onClick);
	}
	else
	{
		//alert("Esconder");
		document.getElementById(btnId).onClick = "javascript:repView('" + reptParamId + "', '" + reptResId + "', " + resize + ");";
		document.getElementById(txtId).innerHTML = "Show Params";
		//alert(document.getElementById(btnId).onClick);		
	}	
	
	//Muestra o esconde el menu y hace el cambio de las imagenes
	displayMore(imgId, reptParamId);
	
	//Si el espacio de resultados requiere resize, se hace el mismo
	if(resize)
	{
		document.getElementById(reptResId).style.width = (mySize("w", 0)) - (300);
		document.getElementById(reptResId).style.height = (mySize("h", 0)) - (screen.height/1.9);
	}	
}

//Funcion para hacer el set de variables
function setMyVar(where, what)
{
        for(i=0;i<where.length;i++)
        {
                document.getElementById(where[i]).value = what[i];
        }
}

//Function to set variables of forms, specifiying the type, Array or String by now, Added By JG 20080901
function setVars(where, what, type)
{
	switch(type.toLowerCase())
	{
		case "array":
			for(i=0;i<where.length;i++)
			{
					document.getElementById(where[i]).value = what[i];
			}
		break;
		
		case "string":
			where = where.split(",");
			what = what.split(",");
			
			for(i=0;i<where.length;i++)
			{
					document.getElementById(where[i]).value = what[i];
			}
		break;
	}
}

//Function to retrieve the value of a key=value String, added By JG 20080918
function getMyVal(strVal, key)
{
	var temp = new Array(10);
	var cont = true;
	var origStr = "";
	
	//-->20081212A Starts
	while(cont==true)
	{
		if(strVal.indexOf(key)>=0)
		{
			
			temp[0] = strVal.substr(strVal.indexOf(key));
			
			if(strVal.indexOf(key)>0)
			{
				temp[1] = strVal.substr((strVal.indexOf(key) - 1), 1);							//checking the character before
			}
			else
			{
				temp[1] = "<NODATA>";
			}
			
			temp[2] = strVal.substr((strVal.indexOf(key) + key.length), 1);				//checking the character after the word
									
			if((temp[1]=="&" || temp[1]=="<NODATA>") && temp[2]=="=")
			{
				cont = false;
				
				if(temp[0].indexOf("&")>=0)
				{
					temp[4] = temp[0].substring(0, temp[0].indexOf("&"));
				}
				else
				{
					temp[4] = temp[0];
				}
								
				temp[5] = temp[4].substring((temp[4].indexOf("=") + 1));
				
				temp[9] = temp[5];
			}
			else
			{
				if(origStr=="")
				{
					origStr = strVal;
				}
				
				if(temp[0].indexOf("&")>=0)
				{
					cont = true;
					
					temp[0] = temp[0].substr(temp[0].indexOf("&"));
					
					strVal = temp[0];
				}
				else
				{
					cont = false;
					temp[9] = "";
				}
			}
		}
		else
		{
			temp[9] = "";
			cont = false;
		}
	}
	
	return temp[9];
	
	//-->20081212A Ends
}

//Function that returns an array containing the values for each column in a table row, Added By JG, 20081031
function getColData(htmlCode)
{
	var d1 = /<+[a-zA-Z1-9\s=]+>/;
	var d2 = /<+\/+[a-zA-Z1-9\s]+>/;	
	
	//alert(htmlCode);
	
	//str = regReplace(htmlCode, d1, '<DIVER>', 0);
	str = replaceMe(htmlCode, "</TD>", "<DIVER>");
	str = replaceMe(str, "</td>", "<DIVER>");
	
	//alert(str);
	
	str = str.split('<DIVER>');
	
	//alert(str);
	
	for(i=0;i<str.length;i++)
	{
		str[i] = regReplace(str[i], d1, '', 0);
		str[i] = regReplace(str[i], d2, '', 0);
		str[i] = trim(str[i]);
	}
	
	if(str[str.length-1]=="" && str.length>0)
	{
		str.splice(str.length-1, 1);
	}
		
	return str;
}
//Funciones para determinar el tamano de la pagina, y posicion central
function mySize(param, size)
{
        var screenW;
        var screenH;
        var bodyW;
        var bodyH;
        var fullHeight;
        var totalW;
        var totalH;

        var xPos;
        var yPos;

        param = param.toLowerCase();

        screenW = screen.width;
        screenH = screen.height;

        bodyW = document.body.clientWidth;
        bodyH = document.body.clientHeight;

        fullHeight = document.body.scrollHeight;

        totalH = document.body + document.body.scrollTop;

        if(totalH<screenH)
        {
                totalH = screenH;
        }

        totalW = bodyW;

        if(param == "x")
        {
                xPos = (totalW/2) - (size/2);
        }
        else if(param == "y")
        {
                if(size>bodyH)
                {
                        yPos = (document.body.scrollTop + ((totalH-200)/2)) - +(size/2);
                }
                else
                {
                        yPos = (document.body.scrollTop + (bodyH/2)) -  +(size/2);
                }
        }


        switch (param)
        {
                case "w":
                        return totalW;
                break;

                case "h":
                        if(fullHeight<screenH)
                        {
                                fullHeight = screenH;
                        }
                        return fullHeight;
                break;

                case "x":
                        return xPos;
                break;

                case "y":
                        return yPos;
                break;
        }
}

//Funciones para el manejo de fechas
//funcion para escribir valores de la fecha en listbox
function wDate(type)
{
        type = type.toLowerCase();
        var x = new Date();

        switch (type)
        {
                case "m":
                        for(i=1;i<=12;i++)
                        {
                                if(i<=9)
                                {
                                        document.write('<option value="0' + i + '">0' + i + '</option>');
                                }
                                else
                                {
                                        document.write('<option value="' + i + '">' + i + '</option>');
                                }
                        }
                break;

                case "d":
                        for(i=1;i<=31;i++)
                        {
                                if(i<=9)
                                {
                                        document.write('<option value="0' + i + '">0' + i + '</option>');
                                }
                                else
                                {
                                        document.write('<option value="' + i + '">' + i + '</option>');
                                }
                        }
                break;

                case "y":
                        for(i=1930;i<=x.getFullYear();i++)	//Changed from getYear, because getYear(), is unsupported in some browsers and present a failure, By JG 20080911
                        {
                                document.write('<option value="' + i + '">' + i + '</option>');
                        }
                break;

                case "hh":
                        for(i=1;i<=12;i++)
                        {
                                if(i<=9)
                                {
                                        document.write('<option value="0' + i + '">0' + i + '</option>');
                                }
                                else
                                {
                                        document.write('<option value="' + i + '">' + i + '</option>');
                                }
                        }
                break;

                case "mm":
                        for(i=0;i<=59;i++)
                        {
                                if(i<=9)
                                {
                                        document.write('<option value="0' + i + '">0' + i + '</option>');
                                }
                                else
                                {
                                        document.write('<option value="' + i + '">' + i + '</option>');
                                }
                        }
                break;

                case "ss":
                        for(i=0;i<=59;i++)
                        {
                                if(i<=9)
                                {
                                        document.write('<option value="0' + i + '">0' + i + '</option>');
                                }
                                else
                                {
                                        document.write('<option value="' + i + '">' + i + '</option>');
                                }
                        }
                break;
        }

}

//funcion para escribir valores de la fecha en listbox
function wDate2(type)
{
        type = type.toLowerCase();
        var x = new Date();

        switch (type)
        {
                case "m":
                        for(i=1;i<=12;i++)
                        {
                                if(i<=9)
                                {
                                        document.write('<option value="0' + i + '">0' + i + '</option>');
                                }
                                else
                                {
                                        document.write('<option value="' + i + '">' + i + '</option>');
                                }
                        }
                break;

                case "d":
                        for(i=1;i<=31;i++)
                        {
                                if(i<=9)
                                {
                                        document.write('<option value="0' + i + '">0' + i + '</option>');
                                }
                                else
                                {
                                        document.write('<option value="' + i + '">' + i + '</option>');
                                }
                        }
                break;

                case "y":
                        for(i=x.getFullYear()-100;i<=x.getFullYear()-21;i++)	//Changed from getYear, because getYear(), is unsupported in some browsers and present a failure, By JG 20080911
                        {
                                document.write('<option value="' + i + '">' + i + '</option>');
                        }
                break;

                case "hh":
                        for(i=1;i<=12;i++)
                        {
                                if(i<=9)
                                {
                                        document.write('<option value="0' + i + '">0' + i + '</option>');
                                }
                                else
                                {
                                        document.write('<option value="' + i + '">' + i + '</option>');
                                }
                        }
                break;

                case "mm":
                        for(i=0;i<=59;i++)
                        {
                                if(i<=9)
                                {
                                        document.write('<option value="0' + i + '">0' + i + '</option>');
                                }
                                else
                                {
                                        document.write('<option value="' + i + '">' + i + '</option>');
                                }
                        }
                break;

                case "ss":
                        for(i=0;i<=59;i++)
                        {
                                if(i<=9)
                                {
                                        document.write('<option value="0' + i + '">0' + i + '</option>');
                                }
                                else
                                {
                                        document.write('<option value="' + i + '">' + i + '</option>');
                                }
                        }
                break;
        }

}

//Function to set variables of forms using a comma separated string
function strSetMyVar(where, what)
{
        where = where.split(",");
		what = what.split(",");
		
		for(i=0;i<where.length;i++)
        {
				document.getElementById(where[i]).value = what[i];
        }
}


//Funcion para ver la fecha actual
function todaySet(dtVal, tFormat)
{
	var m, d, y, hh, mm, ss
	var dt = new Date();
	m = dt.getMonth() + 1;
	d = dt.getDate();
	y = dt.getFullYear();	//Changed from getYear, because getYear(), is unsupported in some browsers and present a failure, By JG 20080911
	hh = dt.getHours();
	mm =  dt.getMinutes();
	ss = dt.getSeconds();
		
	switch(dtVal)
	{	
		case "day":
			if(d<=9)
			{
				d = "0" + d;
			}
			else
			{
				d = d.toString();
			}
		
			return d;
		break;
		
		case "month":
			if(m<=9)
			{
				m = "0" + m;
			}
			else
			{
				m = m.toString();
			}
		
			return m;
		break;
		
		case "year":
			return y;
		break;
		
		case "hour":
			//-->20081204A	
			if(hh>=12)
			{				
				if(hh==12)
				{
					document.getElementById(tFormat).value = "PM";
				}
				else if(hh>12)
				{
					hh = hh -12;
					
					document.getElementById(tFormat).value = "PM";
				}
			}
			else
			{
				if(hh==0)
				{
					hh = 12;
				}
				
				document.getElementById(tFormat).value = "AM";
			}
			
			if(hh<=9)
			{
				hh = "0" + hh;
			}
			else
			{
				hh = hh.toString();
			}			
			//-->20081204A	
				
			return hh;
		break;
		
		case "minute":
			if(mm<=9)
			{
				mm = "0" + mm;
			}
			else
			{
				mm = mm.toString();
			}
		
			return mm;
		break;
		
		case "second":
			if(ss<=9)
			{
				ss = "0" + ss;
			}
			else
			{
				ss = ss.toString();
			}
			
			return ss;
		break;
	}
}

//Funcion para obtener la fecha en formato sql version de javascript
function sqlDateFormatJs()
{
        var Y, M, D, hh, mm, ss;
        var ya = new Date();
        //ya = now

        Y = ya.getFullYear();	//Changed from getYear, because getYear(), is unsupported in some browsers and present a failure, By JG 20080911
        M = ya.getMonth();
        D = ya.getDate();
        hh = ya.getHours();
        mm = ya.getMinutes();
        ss = ya.getSeconds();

        M = M + 1;

        if(M <= 9)
        {
                M = "0" + M;
        }

        if(D <= 9)
        {
                D = "0" + D
        }

        if(hh <= 9)
        {
                hh = "0" + hh
        }

        if(mm <= 9)
        {
                mm = "0" + mm
        }

        if(ss <= 9)
        {
                ss = "0" + ss
        }

        sDFJ = Y + "-" + M + "-" + D + " " + hh + ":" + mm + ":" + ss;

        //return sDFJ;
        return sDFJ;
}

//Funcion que valida el rango de fechas a ver si son validos
function valDates(startDate, endDate)
{
	if(startDate>endDate)
		{
			alert("The date range introduced is invalid, please set a different date range.");
			return false;
		}
		else
		{
		return true;
		}
}

//Function to manage numbers	- Section added By JG, 20080927
//Function to format in decimal format or any number format - added By JG, 20080927
function formatNumber(type, decimal, amt)
{
	var amtTemp = new Number(amt);
	
	switch(type.toLowerCase())
	{
		case "money":
			amtTemp = "$" + amtTemp.toFixed(2);
		break;
	}
	
	return amtTemp;
}

//Function to manage strings
//Function to make a trim removing whitespaces from the beginning and the end of the string - added By JG, 20081031
function trim(stringToTrim) {
	return stringToTrim.replace(/^\s+|\s+$/g,"");
}

//Function to make a trim removing whitespaces from the left side of the string - added By JG, 20081031
function ltrim(stringToTrim) {
	return stringToTrim.replace(/^\s+/,"");
}

//Function to make a trim removing whitespaces from the right side of the string - added By JG, 20081031
function rtrim(stringToTrim) {
	return stringToTrim.replace(/\s+$/,"");
}

//Function to replace a string with another string
function replaceMe(str, replaceStr, replacementStr)
{
        var strTemp = str;
		var intStr, wellStr, curPos, charLen;
		
		wellStr = "";
		cusPos = -1;
		charLen = replaceStr.length;
		
        var x;
        while(strTemp.indexOf(replaceStr)>=0)
        {
                //Debug
				/*
				x = confirm("Desea continuar");
                if(!x)
                {
                        break;
                }
				*/
				                
				curPos = strTemp.indexOf(replaceStr);

				intStr = strTemp.substring(0, (curPos + charLen));
								
				strTemp = strTemp.substring((curPos + charLen));
				//intStr = intStr.substring(0, (curPos + 1));
				wellStr = wellStr + intStr.replace(replaceStr, replacementStr);
				
				/*				
				alert("intStr: " + intStr);
				alert("strTemp: " + strTemp);
				alert("wellStr: " + wellStr);	
				*/        
		}
		
		wellStr = wellStr + strTemp;
				
        return wellStr;
}

//Function to replace values in a string with Regular Expressions, Modified By JG 20081029
function regReplace(strr, regexp, replacer, tms)
{
	//Use 0 if you want to replace all	
	if(tms==0)
	{
		var n = 1
		while(n==1)
		{
			if(regexp.test(strr))
			{
				strr = strr.replace(regexp, replacer);
			}
			else
			{
				n = 0;
			}
		}
	}
	else if(tms>0)
	{
		for(i=0;i<tms;i++)
		{
			strr = strr.replace(regexp, replacer);
		}
	}
	else
	{
		strr = strr.replace(regexp, replacer);
	}

	return strr;
}

function sendTo(url, btnVal, id, btnId)
{
        //alert("iniciando");
        document.getElementById(id).action = url;
        //alert(document.getElementById(id).action);
        document.getElementById(btnId).value = btnVal;
        //alert(document.getElementById(btnId).value);
        document.getElementById(btnId).click();
        setTimeout("document.getElementById('" + btnId + "').click()", 1000);
}
//Funciones para el proceso dentro del website, login, link validation

/*-->20090214A  Starts
function processLink(type, action, appName)
{

}
-->20090214A Ends */


//User Messages Sections -->20090213B
function infoMsg()
{
	//Private variables
	this.id = "";
	
	this.stat ="off";
	
	this.title = "";
	this.data = "";
	this.type = "normal";
	this.style = "simpleText";
	
	this.mainCont = "";
	this.cont = "";	
	
	//-->20090715A Starts
	this.errorMsgArr = new Array("none");
	this.allowMsgArr = new Array("none");
	this.warnMsgArr = new Array("none");
	this.normalMsgArr = new Array("none");	
	//-->20090715A Ends
	
	//Method that set initial Parameters for the infoMsg
	this.setParams = function(infoData, infoType, infoPosition)
	{
		if(infoType=="")
		{
			this.type = "normal";
		}
		else
		{
			this.type = infoType.toLowerCase();
		}
		
		//-->20090715A Starts
		var daLen;
		//Selecting the corresponding Class for this issue
		switch(this.type)
		{
			case "error":
				this.style = "errorText";
				this.title = "Attention!!!";
				
				daLen = parseInt(this.errorMsgArr.length, 10);
				
				this.errorMsgArr[daLen] = infoData;
			break;
			
			case "warn":
				this.style = "warnText";
				this.title = "Warning!!";
				
				daLen = parseInt(this.warnMsgArr.length, 10);
				
				this.warnMsgArr[daLen] = infoData;
			break;
			
			case "allow":
				this.style = "allowText";
				this.title = "Allowed!";
				
				daLen = parseInt(this.allowMsgArr.length, 10);
				
				this.allowMsgArr[daLen] = infoData;
			break;
			
			default:
				this.style = "simpleText";
				this.title ="Message";
				
				daLen = parseInt(this.normalMsgArr.length, 10);
				
				this.normalMsgArr[daLen] = infoData;
		}
		//-->20090715A Ends		
		
		//this.data = infoData;												//-->20090715A | Erased as is not used
		this.cont = document.getElementById(infoPosition);
		this.cont.style.display = 'block';
		this.cont.style.padding = '5px';
	}
	
	//Method that creates the message
	this.createMe = function()
	{
		var htmlCode = "";
		var style = this.style;
		var title = this.title;
		//var rcvData = this.data;
		
		//Setting the ID for this box
		/*if(this.id[0]=="<EMPTY>")
		{
			this.id[0] = "infoMsg" + this.id.length;
			this.
		}
		else
		{
			var temp = this.id.length + 1;
			this.id[temp] = "infoMsg" + temp;
		}*/
				
		//Creating the main container if is necessary
		if(this.stat=="off")
		{
			this.createContainer();
		}
		
		//htmlCode = htmlCode + '';
		//htmlCode = htmlCode + '<table width="100%" border="0" align="center" cellpadding="0" cellspacing="0" id="infoMsgMain" class="infoMsg01">';
		//htmlCode = htmlCode + '<tr>';
		//htmlCode = htmlCode + '<td><table width="100%" border="0" cellspacing="0" cellpadding="0">';
		//htmlCode = htmlCode + '<table border="0" cellspacing="0" cellpadding="0" class="infoMsg01">';		
		//htmlCode = htmlCode + '<tr>';
		//htmlCode = htmlCode + '<td class="' + style + '" width="50" valign="center">' + title + ' &gt;</td>';
		//htmlCode = htmlCode + '<td class="simpleText" valign="center">' + "" + '</td>';
		//htmlCode = htmlCode + '<td width="30" align="center" valign="middle"><a href="javascript:;" class="xBtn" onClick="javascript:iObj.closeMe();">X</a></td>';
		//htmlCode = htmlCode + '</tr>';
		//htmlCode = htmlCode + '</table></td>';
		//htmlCode = htmlCode + '</table>';
		//htmlCode = htmlCode + '</tr>';
		//htmlCode = htmlCode + '<tr>';
		//htmlCode = htmlCode + '<td class="' + style + '">' + rcvData + '</td>';
		//htmlCode = htmlCode + '</tr>';
		///htmlCode = htmlCode + '</table>';	
		
		//-->20090715A Starts
		//Creating the structure for each message type, will close in one X
		htmlCode = htmlCode + '<table border="0" cellspacing="0" cellpadding="0" class="infoMsg01">';		
		htmlCode = htmlCode + '<tr>';
		htmlCode = htmlCode + '<td valign="center" align="center">';
		htmlCode = htmlCode + '<table cellpadding="5" cellspacing="0" align="center" width="100%">';
		htmlCode = htmlCode + '<tr>';
		htmlCode = htmlCode + '<td class="infoMsg03" align="center" width="100%"><b>MESSAGES</b></td>';
		htmlCode = htmlCode + '<td class="infoMsg03" width="30" align="center" valign="middle"><a href="javascript:;" class="xBtn" onClick="javascript:iObj.closeMe();">X</a></td>';
		htmlCode = htmlCode + '</tr>';
		htmlCode = htmlCode + '</table>';
		htmlCode = htmlCode + '</td>';
		htmlCode = htmlCode + '</tr>';
		
		if(this.allowMsgArr.length>1 || this.warnMsgArr.length>1 || this.errorMsgArr.length>1 || this.normalMsgArr.length>1)
		{		
			if(this.allowMsgArr.length>1)
			{
				//Creating the Allowed Values
				htmlCode = htmlCode + '<tr><td>';
				htmlCode = htmlCode + '<table align="center" cellpadding="3" cellspacing="0" border="0">'
	
				for(imc=1;imc<this.allowMsgArr.length;imc++)
				{
					htmlCode = htmlCode + '<tr>';
					
					if(imc==1)
					{
						htmlCode = htmlCode + '<td class="allowText" valign="top" width="50">&gt;Allowed</td>';
						htmlCode = htmlCode + '<td align="left" valign="middle" class="infoMsg02" nowrap>' + this.allowMsgArr[imc] + '</td>';
					}
					else
					{
						htmlCode = htmlCode + '<td class="allowText" valign="top" width="50">&nbsp;</td>';
						htmlCode = htmlCode + '<td align="left" valign="middle" class="infoMsg02" nowrap>' + this.allowMsgArr[imc] + '</td>';
					}
					
					htmlCode = htmlCode + '</tr>';
				}
			
				htmlCode = htmlCode + '</table>';
				htmlCode = htmlCode + '</td></tr>';	
			}
				
			if(this.errorMsgArr.length>1)
			{			
				//Creating the Error Values
				htmlCode = htmlCode + '<tr><td>';
				htmlCode = htmlCode + '<table align="center" cellpadding="3" cellspacing="0" border="0">'
				
				for(imc=1;imc<this.errorMsgArr.length;imc++)
				{
					htmlCode = htmlCode + '<tr>';
					
					if(imc==1)
					{
						htmlCode = htmlCode + '<td class="errorText" valign="top" width="50">&gt;Error!!</td>';
						htmlCode = htmlCode + '<td align="left" valign="middle" class="infoMsg02" nowrap>' + this.errorMsgArr[imc] + '</td>';
					}
					else
					{
						htmlCode = htmlCode + '<tr>';
						htmlCode = htmlCode + '<td class="errorText" valign="top" width="50">&nbsp;</td>';
						htmlCode = htmlCode + '<td align="left" valign="middle" class="infoMsg02" nowrap>' + this.errorMsgArr[imc] + '</td>';
					}
					
					htmlCode = htmlCode + '</tr>';
				}
				
				htmlCode = htmlCode + '</table>';
				htmlCode = htmlCode + '</td></tr>';
			}
				
			if(this.warnMsgArr.length>1)
			{			
				//Creating the Warn Values
				htmlCode = htmlCode + '<tr><td>';
				htmlCode = htmlCode + '<table align="center" cellpadding="3" cellspacing="0" border="0">'			
				
				for(imc=1;imc<this.warnMsgArr.length;imc++)
				{
					htmlCode = htmlCode + '<tr>';
									
					if(imc==1)
					{
						htmlCode = htmlCode + '<td class="warnText" valign="top" width="50">&gt;Warning!!</td>';
						htmlCode = htmlCode + '<td align="left" valign="middle" class="infoMsg02" nowrap>' + this.warnMsgArr[imc] + '</td>';
					}
					else
					{
						htmlCode = htmlCode + '<td class="warnText" valign="top" width="50">&nbsp;</td>';
						htmlCode = htmlCode + '<td align="left" valign="middle" class="infoMsg02" nowrap>' + this.warnMsgArr[imc] + '</td>';
					}
					
					htmlCode = htmlCode + '</tr>';				
				}
				
				htmlCode = htmlCode + '</table>';
				htmlCode = htmlCode + '</td></tr>';		
			}
			
			if(this.normalMsgArr.length>1)
			{			
				//Creating the Normal Values
				htmlCode = htmlCode + '<tr><td>';
				htmlCode = htmlCode + '<table align="center" cellpadding="3" cellspacing="0" border="0">'			
				
				for(imc=1;imc<this.normalMsgArr.length;imc++)
				{
					htmlCode = htmlCode + '<tr>';
									
					if(imc==1)
					{
						htmlCode = htmlCode + '<td class="simpleText" valign="top" width="50">&gt;Message</td>';
						htmlCode = htmlCode + '<td align="left" valign="middle" class="infoMsg02" nowrap>' + this.normalMsgArr[imc] + '</td>';
					}
					else
					{
						htmlCode = htmlCode + '<td class="simpleText" valign="top" width="50">&nbsp;</td>';
						htmlCode = htmlCode + '<td align="left" valign="middle" class="infoMsg02" nowrap>' + this.normalMsgArr[imc] + '</td>';
					}
					
					htmlCode = htmlCode + '</tr>';				
				}			
				
				htmlCode = htmlCode + '</table>';
				htmlCode = htmlCode + '</td></tr>';										
			}
		}
		else
		{
			htmlCode = "";
		}
		
		htmlCode = htmlCode + '</table>';				
		//-->20090715A Ends
		
		this.mainCont.innerHTML = htmlCode;
		//clipboardData.setData("Text", htmlCode);
	}
	
	//Method that creates the main container
	this.createContainer = function()
	{
		var htmlCode = "";
		
		this.stat = "on";
		
		htmlCode = htmlCode + '<span id="infoMsgMainContainer"></span>';
		this.cont.innerHTML = htmlCode;
		
		this.mainCont = document.getElementById("infoMsgMainContainer");
	}
	
	//Method that should close only the selected container
	this.closeMe = function()
	{
		//This should look for available infoMsgs, but is not doing it now
		if(this.stat=="on")
		{
			this.mainCont.innerHTML = "";
			this.cont.innerHTML = "";
			//this.cont.style.display = "none";
			this.stat = "off";
			this.errorMsgArr = new Array("none");
			this.allowMsgArr = new Array("none");
			this.warnMsgArr = new Array("none");
			this.normalMsgArr = new Array("none");				
		}
	}
	
	//Method that should close all container cleaning everything
	this.closeAll = function()
	{
		
	}
	
}

//Popup Windows Object Definition					-->20090213A
function popupWindow(cover, container, handle, containerH, containerW, title, data)
{	
	//Private variables
	var style = ""; 
	
	this.cover = "";
	this.container = "";
	this.handle = "";
	this.title = "Untitled";
	this.data = "";
	this.height = 500;
	this.width = 500;
	this.status = "off";		//Status can be [off: Popup is closed | on:popup is open]
	this.refreshStatus = "none";
	
	this.setParams =  function(rCover, rContainer, rHandle, rContainerH, rContainerW, rTitle, rData)
	{
		cover = rCover;
		container = rContainer;
		title = rTitle;
		data = rData;
		containerH = rContainerH;
		containerW = rContainerW;
	}
		
	this.create = function() 
	{	
		//if(this.status!="on" && this.refreshStatus!="none")
		//{
			//Creating the cover
			this.cover = document.getElementById(cover);
			this.cover.className = "coverOn";
			this.cover.style.height = mySize('h', 0) + "px";
			this.cover.style.width = mySize('w', 0) + "px";
			this.status = "on";
			
			//Creating the container
			if(this.refreshStatus=="none")
			{
				this.title = title;
				this.data = data;
			}
			else
			{
				this.refreshStatus = "none";
			}
	
			var dataHTML = "";
			
/*			dataHTML = '<div id="myHandler" class="handlerOn">' + this.title + '</div>';
			dataHTML = dataHTML + '<table width="100%" height="100%" border="0" align="center" cellpadding="0" cellspacing="0">\n';
			dataHTML = dataHTML + '<tr>\n';
			dataHTML = dataHTML + '<td valign="top" class="popupWindowText">' + this.data + '</td>\n';
			dataHTML = dataHTML + '</tr>\n';
			dataHTML = dataHTML + '<tr>\n';
			dataHTML = dataHTML + '<td height="24" align="right"><img src="../imgs/layout/popupBase_07.jpg" width="27" height="24"></td>\n';
			dataHTML = dataHTML + '</tr>\n';
			dataHTML = dataHTML + '</table>\n';
*/			
			dataHTML = dataHTML + '<table width="100%" height="100%" border="0" cellspacing="0" cellpadding="0" id="apop" class="' + style + '">\n';
			dataHTML = dataHTML + '<tr>\n';
			dataHTML = dataHTML + '<td id="topl"></td>\n';
			dataHTML = dataHTML + '<td id="topm"><div id="myHandler">' + this.title + '</div></td>\n';
			dataHTML = dataHTML + '<td id="topr"></td>\n';
			dataHTML = dataHTML + '</tr>\n';
			dataHTML = dataHTML + '<tr>\n';
			dataHTML = dataHTML + '<td valign="bottom" id="midl"><table width="100%" cellpadding="0" cellspacing="0"><tr><td id="popSideL"></td></tr></table></td>\n';
			dataHTML = dataHTML + '<td rowspan="2" valign="top" id="midm">\n';
			dataHTML = dataHTML + this.data + '\n';
			dataHTML = dataHTML + '</td>\n';
			dataHTML = dataHTML + '<td valign="bottom" id="midr"><table width="100%" cellpadding="0" cellspacing="0"><tr><td id="popSideR"></td></tr></table></td>\n';
			dataHTML = dataHTML + '</tr>\n';
			dataHTML = dataHTML + '<tr>\n';
			dataHTML = dataHTML + '<td valign="top" id="midl2"><table width="100%" cellpadding="0" cellspacing="0"><tr><td id="popSideL2"></td></tr></table></td>\n';
			dataHTML = dataHTML + '<td valign="top" id="midr2"><table width="100%" cellpadding="0" cellspacing="0"><tr><td id="popSideR2"></td></tr></table></td>\n';
			dataHTML = dataHTML + '</tr>\n';
			dataHTML = dataHTML + '<tr>\n';
			dataHTML = dataHTML + '<td id="botl">&nbsp;</td>\n';
			dataHTML = dataHTML + '<td id="botm"></td>\n';
			dataHTML = dataHTML + '<td id="botr">&nbsp;</td>\n';
			dataHTML = dataHTML + '</tr>\n';
			dataHTML = dataHTML + '</table>\n';
			
			this.container = document.getElementById(container);
			
			if(containerH>0 || containerH.length>0 || isNaN(containerH)==false)
			{
				this.height = parseInt(containerH, 10);
			}
			
			if(containerW>0 || containerW.length>0 || isNaN(containerW)==false)
			{
				this.width = parseInt(containerW, 10);
			}
			
			this.container.className = 'authOn';
			this.container.style.height = this.height + "px";
			this.container.style.width = this.width + "px";
			this.container.style.top = mySize('y', this.height) + "px";
			this.container.style.left = mySize('x', this.width) + "px";
			this.container.innerHTML = dataHTML;
			
			//clipboardData.setData("Text", dataHTML);
	
			Drag.init(document.getElementById("myHandler"), this.container);
		//}
		//else
		//{
		//	alert("Popup Window Cannot be created again");
		//}
	}
	
	this.refreshMe = function ()
	{
		//Recreating the window
		this.closeMe();
		this.refreshStatus = "refreshing";		
		this.create();
	}
	
	this.closeMe = function()
	{
		if(this.status=="on")
		{
			//turnning off the popup
			this.cover.className = "coverOff";
						
			this.container.className = "authOff";
			this.container.innerHTML = 'Code';

			this.status = "off";
		}
		else
		{
			alert("No popup windows is open");
		}
	}
	
	this.setStyle = function(clsName, type)
	{
		style = clsName;
		this.refreshMe();
	}
}


//Formulario de Login
function logVal(fname)
{
	var f = document.forms[fname];
	var url = "";
	var msg;
	var cBack = "loginProc";
	var cont = document.getElementById("resultMsg");		//-->20090212A
	
	//-->20090216A	Array(loginStatus: [ 0:Not Processed | 1:not allowed | 2:allowed ], formID, loginScriptRelPath, receivedPath );
	//Processing the logStatus Variable
	if(logStat[0]==0)
	{
		logStat[1] = f.id;
		logStat[3] = f.action;
		url = logStat[2]; 
	}
	else if(logStat[0]=="1")
	{
		url = logStat[2];
		logStat[0] = "0";
	}
	else if(logStat[0]=="2")		//This checks if the user is allowed and then return a positive answer for it to log in
	{
		f.action = logStat[3];
		f.submit();
		return true;
	}	
		
	/*-->20090214A  Starts
	if(logStat == true)
	{
		document.forms[fname].submit();
		return true;
	}
   // else if(logStat == false)
	//{
	//	return false;
	//}
	-->20090214A  Ends */

	if(f.login.value == "")
	{
		iObj.setParams(getMyErr(3), "error", "resultMsg");
		iObj.createMe();
		f.login.focus();
		return false;
	}

	if(f.password.value == "")
	{
		iObj.setParams(getMyErr(4), "error", "resultMsg");
		iObj.createMe();
		f.password.focus();
		return false;
	}

	if(f.appname.value == "")
	{
		iObj.setParams(getMyErr(5), "error", "resultMsg");
		iObj.createMe();
		return false;
	}

	iObj.closeMe();

	pageType = f.appname.value;
	msg = "login=" + f.login.value + "&password=" + f.password.value + "&appname=" + f.appname.value;

	var wtMsg = "";

	wtMsg = wtMsg + '<p align="center" class="text" style="color:#FFFFFF;"><img src="imgs/icons/loader04.gif"><br><br>Checking your credentials...</p>';

	gralReq.sendParams("login", url, msg, cBack, "POST");
	gralReq.waitMsg = wtMsg;
	gralReq.waitMsgPos = cont.id;
	gralReq.resPos = cont.id;
	gralReq.errMgr = "Off";
	gralReq.sendRequest();

	//setTimeout('logVal("' + fname + '")', loginTimer);		-->20090214A 

	return false;
}

//Funciones para el manejo de usuarios

//Funcion para procesar la solicitud de login
function loginProc(strResult)
{
	strResult = unescape(strResult);
	var isAllowed = false;
	var cont = document.getElementById("resultMsg");												//-->20090212A
	//Default value for the logStat[0]																				//-->20090216A
	logStat[0] = "1";
	
	//clipboardData.setData("Text", strResult);
	//alert(strResult);
	
	if(strResult=="" || strResult=="0")
	{
		iObj.setParams(getMyErr(6), "error", "resultMsg");											//-->20090214A
		iObj.createMe();																									//-->20090214A

		//cont.innerHTML = '<span class="errorText">' + getMyErr(6) + '</span>';		//-->20090214A
		//document.getElementById("res").innerHTML = strResult;
		//logStat = false;	-->20090214A 
		//return false;		-->20090214A 
	}
	else if(strResult=="1")
	{
		iObj.setParams(getMyErr(7), "error", "resultMsg");											//-->20090214A
		iObj.createMe();																									//-->20090214A

		//cont.innerHTML = '<span class="errorText">' + getMyErr(7) + '</span>';		//-->20090214A
		//document.getElementById("res").innerHTML = strResult;
		//logStat = false;		-->20090214A 
		//return false;			-->20090214A 
	}
	else
	{
		var res1 = accessPage(strResult, pageType);
		
		if(res1 != "User approved!")
		{
			iObj.setParams(res1, "error", "resultMsg");													//-->20090214A
			iObj.createMe();																								//-->20090214A
		
			//cont.innerHTML = "<span class=\"errorText\">" + res1 + "</span>";			//-->20090214A
			//logStat = false;		-->20090214A 
		}
		else
		{
			iObj.setParams(res1, "allow", "resultMsg");													//-->20090214A
			iObj.createMe();																								//-->20090214A
			
			//cont.innerHTML = "<span class=\"allowText\">" + res1 + "</span>";			//-->20090214A
			//logStat = true;		-->20090214A 
			logStat[0] = "2";																								//-->20090216A
			setTimeout("logVal('" + logStat[1] + "')", loginTimer);									//-->20090216A
		}
		//document.getElementById("res").innerHTML = strResult;
		//logStat = true;
	}
}

//Function to determine user access to the page
function accessPage(str, page)
{
	var temp = str;
	var group = new Array();
	
	//Add contition when an error comes out
	temp = temp.indexOf(page);
	
	if(temp>0)
	{
		temp = "User approved!";
		return temp;
	}
	else
	{
		return getMyErr(7);
	}
}

//Funcion para crear las tablas
function createPosition(target, numPos)
{
	var htmlData;
	
	htmlData = '<table width="100%" border="0" cellspacing="0" cellpadding="0">\n';
	
	for(i=numPos;i>=1;i--)
	{
		htmlData = htmlData + '</tr>\n';
		htmlData = htmlData + '<tr>\n';
		htmlData = htmlData + '<td heigth="4">\n';
		htmlData = htmlData + '</td>\n';
		htmlData = htmlData + '</tr>\n';	
		htmlData = htmlData + '<tr>\n';
		htmlData = htmlData + '<td>\n';
		htmlData = htmlData + '<span id="pos' + i + '"></span>\n';
		htmlData = htmlData + '</td>\n';
	}
	
	htmlData = htmlData + '</table>\n';
	
	document.getElementById(target).innerHTML = htmlData;
	//document.getElementById("pos" + numPos).className = "reportHeader";
}

//Ajax Library																			//-->20090214B
//Ajax Object Class, Added on 20080801
function cjAjax(reqName, sendUrl, sendMsg, cbackFx, sendMethod)
{
	var infoMsg;
	var xmlHttp;
	var ajaxResult = "none";	
	var isAborted = false;
	
	xmlHttp=getAjax(xmlHttp);														//-->20090214B

	//Configuration Parameters
	//Add the ResponseId, WaitingMessage, ProcessingType (wait, cancel, warn)
	//wait = put new requests in a queue
	//cancel = cancel actual request and put the new request
	//warn = pops a message to the user to select if the actual request maybe cancelled and process the new request, queue the new request or not cancel actual request.
	this.name = reqName;
	this.id = reqName;	//For Now it generates the same value as the name
	this.url = sendUrl;
	this.msg = sendMsg;
	this.cback = cbackFx;
	this.astatus = "idle";
	this.method = sendMethod.toUpperCase();
		
	//Properties for automated answers on the page.
	//If a callback is defined, this option will be ignored
	//If this variables are defined the answer in getResult will also be palced but the status will change from processing to idle before this method is called
	//Defines the position in which the answer should be place in the report
	this.resPos = "none";
	//Define a custom message while the request is being retrieved. If waitMSgPos is not defined, this wont be used
	this.waitMsg = '<p align="center" style="color:#FFFFFF; font-family:verdana; font-size:10 px;">Data is being retrieved...</p>';		
	//Defines the place in which the default or custome message should appear.
	this.waitMsgPos = "none";	
	
	//Handling error properties
	//Using the error manager is disabled by default, write on to make it work
	this.errMgr = "Off";
	
	//Set a new request parameters, overriding existing
	this.sendParams = function(nReqName, nSendUrl, nSendMsg, nCbackFx, nSendMethod)
					  {
						this.name = nReqName;
						this.id = nReqName;	//For Now it generates the same value as the name
						this.url = nSendUrl;
						this.msg = nSendMsg;
						this.cback = nCbackFx;
						this.astatus = "idle";
						this.method = nSendMethod.toUpperCase();
					  }
					  		
	this.info = function()
				{
					infoMsg = "Process Name: " + this.name + "\n";
					infoMsg = infoMsg + "Process ID: " + this.id + "\n";
					infoMsg = infoMsg + "Send URL: " + this.url + "\n";
					infoMsg = infoMsg + "Send Msg: " + this.msg + "\n";
					infoMsg = infoMsg + "Call Back Defined: " + this.cback + "\n";
					infoMsg = infoMsg + "Send Method: " + this.method + "\n";
					infoMsg = infoMsg + "Object Status: " + this.astatus + "\n";
					infoMsg = infoMsg + "Response position: " + this.resPos + "\n";
					infoMsg = infoMsg + "Waiting Request Message: " + this.waitMsg + "\n";
					infoMsg = infoMsg + "Waiting Request Message Position: " + this.waitMsgPos + "\n";
					
					alert(infoMsg);
				}
				
	//Function to send Data
	this.sendRequest = function ()
						{
								if(this.astatus=="idle")
								{
									var type = "default";
									var me = this;
									
									//check if cBack is defined, if not set answer to the result variable
									if(this.cback!="")
									{
										type = this.cback;
									}
							
									//alert(this.msg);
														
									if (xmlHttp==null)
									{
											alert("Your Browser don't support AJAX!");
											return;
									}
												
									//Check and send Ajax request
									try
									{
											xmlHttp.onreadystatechange = function () {stateChanged(type, me);};
											xmlHttp.open(this.method,this.url,true);
											xmlHttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
											xmlHttp.send(this.msg);
											this.astatus = "processing";
											
											if(this.waitMsgPos!="none" && this.waitMsgPos!="")
											{
												document.getElementById(this.waitMsgPos).innerHTML = this.waitMsg;
											}
									}
									catch(e)
									{
											alert("Process can't be completed due to: " + e.description);
											return;
									}
								}
						}
	
	//Function to cancel the ajax request
	this.cancel = function()
					{
						this.astatus = "idle";
						ajaxResult = "Cancelled!"
						isAborted = true;
						xmlHttp.abort();
						//alert("Request Cancelled");
					}

	//Function to get Ajax result
	this.getResult = function()
					{		
						//alert(this.astatus);
						this.astatus = "idle";
						return ajaxResult;
					}
	
	//Function to verify if Ajax is available
	function getAjax(rcvObj)
	{
	  try
		{
			// Firefox, Opera 8.0+, Safari
			rcvObj=new XMLHttpRequest();
		}
	  catch (e)
		{    // Internet Explorer
			try
		  		{      rcvObj=new ActiveXObject("Msxml2.XMLHTTP");      }
			catch (e)
		  		{      rcvObj=new ActiveXObject("Microsoft.XMLHTTP");   }
		}
		
		return rcvObj;
	}
			
	//Funcion that process Ajax Result
	function stateChanged(cback, props)
	{
			var strRes;
						
			if(props.waitMsgPos=="none" && props.waitMsgPos=="")
			{
				document.getElementById(props.waitMsgPos).inerHTML = "";
			}
			
			//clipboardData.setData("Text", xmlHttp.responseText);
			
			if(xmlHttp.readyState==4 && xmlHttp.status==200)
			{
				strRes = xmlHttp.responseText;
				props.cancel();											//-->20090214B
												
				props.astatus = "ok";
				
				if(cback=="default")
				{
					ajaxResult = strRes;
					
					if(props.resPos!="none" && props.resPos!="")
					{
						document.getElementById(props.resPos).innerHTML = props.getResult();
					}
				}
				else
				{
					setTimeout(cback + "('"+ escape(strRes) +"')", 1);
				}
				
			}
			else if(xmlHttp.readyState==4 && xmlHttp.status!=200)
			{
				strRes = xmlHttp.responseText;
				
				//Check if the request was aborted
				if(isAborted==false)
				{
					props.cancel();										//-->20090214B
					
					ajaxResult = "There was an error with the server, Please try again. If the problem persist contact your System Administrator";
				
					props.astatus = "errors";
					
					//Checks if the error manager is used or activated			
					if(props.errMgr.toLowerCase()=="on")
					{
						errHandle("Page cannot be found!", strRes);
					}
					else
					{
						//If resPos variable is set, then shows the answer
						if(props.resPos!="none" && props.resPos!="")
						{
							document.getElementById(props.resPos).innerHTML = props.getResult();
						}
					}
				}
				else
				{
					//If resPos variable is set, then shows the answer
					if(props.resPos!="none" && props.resPos!="")
					{
						document.getElementById(props.resPos).innerHTML = props.getResult();
					}
				
					isAborted = false;
				}	
			}
	}		
}

//Funciones para el manejo de errores
function errHandle(errText, errData)
{
	//intSurvRrefresh = setInterval("getSurveillanceData()", survRefreshRate);
	
	 //style="height:60px; overflow:auto;
	
	errData = escape(errData);
	
	document.getElementById("errManager").style.display = "block";
	
	document.getElementById("errorReport").style.height = "60px";
	document.getElementById("errorReport").style.overflow = "auto";
	document.getElementById("errorReport").innerHTML = '<br>' + errCount + '. ' + errText + '<a href="javascript:;" onclick="javascript:clipboardData.setData(\'Text\', unescape(\'' + errData + '\'));" class="topMnu">(copy to clipboard)</a></li>' + document.getElementById("errorReport").innerHTML;
	
	errCount = errCount + 1;
}

//Funcion para limpiar el panel de errores
function errClear()
{
	document.getElementById("errManager").style.display = "none";
	
	errCount = 1;
	
	document.getElementById("errorReport").style.height = "0px";
	document.getElementById("errorReport").style.overflow = "auto";
	document.getElementById("errorReport").innerHTML = "";	
}

//Exporting Functions

//Function to Export to Word, Excel
function sendToExcel2(target, fileNameStr, fileType)
{
        var queryMsg = document.getElementById(target).innerText;

        if(queryMsg=="")
        {
                alert("No Data to be exported!");
        }
        else
        {
                var fields, data;

                fields = queryMsg.split("&");

                data = "";

                data = data + '<p align="center" class="simpleText">Table is Being Exported to <span style="text-transform:">' + fileType + '! <br><br>Please Wait until the Save Dialog Box Appears.<br>Once the file has been save you can close this window.<br>\n';
                data = data + '<form id="exporting" name="exporting" method="post" action="scripts/export.php">\n';
                data = data + '<input name="' + fields[0].substr(0, fields[0].indexOf("=")) + '" id="' + fields[0].substr(0, fields[0].indexOf("=")) + '" type="hidden" value="' + fields[0].substr(fields[0].indexOf("=") + 1).replace("scripts/", "") + '" >\n';

                for(i=1;i<fields.length;i++)
                {
                        data = data + '<input name="' + fields[i].substr(0, fields[i].indexOf("=")) + '" id="' + fields[i].substr(0, fields[i].indexOf("=")) + '" type="hidden" value="' + fields[i].substr(fields[i].indexOf("=") + 1) + '" >\n';
                }
                data = data + '<input name="filename" id="filename" type="hidden" value="' + fileNameStr + '" >\n';
                data = data + '<input name="filetype" id="filetype" type="hidden" value="' + fileType + '" >\n';
				data = data + '</form>\n';
                data = data + '&nbsp;&nbsp;\n';
                data = data + '<input type="button" name="noBtn" id="noBtn" class="btnInside" style="width:80px;" value=" Close " onClick="javascript: closePopWindow(\'cover\', \'authPlace\', \'handler\'); "></p>\n';

                //alert(dataArr);

                //clipboardData.setData("Text", data);

                popWindow('cover', 'authPlace', 'handler', 150, 300, 'Exporting Data To ' + fileType, data);

				document.getElementById("noBtn").focus();
                document.getElementById("exporting").submit();
        }
}

//Function to send to Printing Report
function sendToPrint(target, fileNameStr, fileType)
{
        var queryMsg = document.getElementById(target).innerText;

        if(queryMsg=="")
        {
                alert("No Data to be printed!");
        }
        else
        {
                var fields, data;
				
				queryMsg = queryMsg + "&printable=true";

                fields = queryMsg.split("&");

                data = "";

                data = data + '<p align="center" class="simpleText">Data is being printed!<br><br>Please Wait until the print window appear.<br><br>Once the window load the report, click <b>Preview</b> to see how the report will be printed, and click <b>Print</b> to print the report. <br><br>Select Landscape or Portrait for printing orientation.<br>\n';
                data = data + '<form id="printing" name="printing" method="post" action="scripts/print.php" target="_blank">\n';
                data = data + '<input name="' + fields[0].substr(0, fields[0].indexOf("=")) + '" id="' + fields[0].substr(0, fields[0].indexOf("=")) + '" type="hidden" value="' + fields[0].substr(fields[0].indexOf("=") + 1).replace("scripts/", "") + '" >\n';

                for(i=1;i<fields.length;i++)
                {
                        data = data + '<input name="' + fields[i].substr(0, fields[i].indexOf("=")) + '" id="' + fields[i].substr(0, fields[i].indexOf("=")) + '" type="hidden" value="' + fields[i].substr(fields[i].indexOf("=") + 1) + '" >\n';
                }
                data = data + '<input name="filename" id="filename" type="hidden" value="' + fileNameStr + '" >\n';
                data = data + '<input name="filetype" id="filetype" type="hidden" value="' + fileType + '" >\n';
				data = data + '</form>\n';
                data = data + '&nbsp;&nbsp;\n';
                data = data + '<input type="button" name="noBtn" id="noBtn" class="btnInside" style="width:80px;" value=" Close " onClick="javascript: closePopWindow(\'cover\', \'authPlace\', \'handler\'); "></p>\n';

                //alert(dataArr);

                //clipboardData.setData("Text", data);

                popWindow('cover', 'authPlace', 'handler', 150, 300, 'Printing Data' + fileType, data);

				document.getElementById("noBtn").focus();
				document.getElementById("printing").submit();
        }
}

//Funcionalidad Drag And Drop
var Drag = {

        obj : null,

        init : function(o, oRoot, minX, maxX, minY, maxY, bSwapHorzRef, bSwapVertRef, fXMapper, fYMapper)
        {
                o.onmousedown   = Drag.start;

                o.hmode                 = bSwapHorzRef ? false : true ;
                o.vmode                 = bSwapVertRef ? false : true ;

                o.root = oRoot && oRoot != null ? oRoot : o ;

                if (o.hmode  && isNaN(parseInt(o.root.style.left  ))) o.root.style.left   = "0px";
                if (o.vmode  && isNaN(parseInt(o.root.style.top   ))) o.root.style.top    = "0px";
                if (!o.hmode && isNaN(parseInt(o.root.style.right ))) o.root.style.right  = "0px";
                if (!o.vmode && isNaN(parseInt(o.root.style.bottom))) o.root.style.bottom = "0px";

                o.minX  = typeof minX != 'undefined' ? minX : null;
                o.minY  = typeof minY != 'undefined' ? minY : null;
                o.maxX  = typeof maxX != 'undefined' ? maxX : null;
                o.maxY  = typeof maxY != 'undefined' ? maxY : null;

                o.xMapper = fXMapper ? fXMapper : null;
                o.yMapper = fYMapper ? fYMapper : null;

                o.root.onDragStart      = new Function();
                o.root.onDragEnd        = new Function();
                o.root.onDrag           = new Function();
        },

        start : function(e)
        {
                var o = Drag.obj = this;
                e = Drag.fixE(e);
                var y = parseInt(o.vmode ? o.root.style.top  : o.root.style.bottom);
                var x = parseInt(o.hmode ? o.root.style.left : o.root.style.right );
                o.root.onDragStart(x, y);

                o.lastMouseX    = e.clientX;
                o.lastMouseY    = e.clientY;

                if (o.hmode) {
                        if (o.minX != null)     o.minMouseX     = e.clientX - x + o.minX;
                        if (o.maxX != null)     o.maxMouseX     = o.minMouseX + o.maxX - o.minX;
                } else {
                        if (o.minX != null) o.maxMouseX = -o.minX + e.clientX + x;
                        if (o.maxX != null) o.minMouseX = -o.maxX + e.clientX + x;
                }

                if (o.vmode) {
                        if (o.minY != null)     o.minMouseY     = e.clientY - y + o.minY;
                        if (o.maxY != null)     o.maxMouseY     = o.minMouseY + o.maxY - o.minY;
                } else {
                        if (o.minY != null) o.maxMouseY = -o.minY + e.clientY + y;
                        if (o.maxY != null) o.minMouseY = -o.maxY + e.clientY + y;
                }

                document.onmousemove    = Drag.drag;
                document.onmouseup              = Drag.end;

                return false;
        },

        drag : function(e)
        {
                e = Drag.fixE(e);
                var o = Drag.obj;

                var ey  = e.clientY;
                var ex  = e.clientX;
                var y = parseInt(o.vmode ? o.root.style.top  : o.root.style.bottom);
                var x = parseInt(o.hmode ? o.root.style.left : o.root.style.right );
                var nx, ny;

                if (o.minX != null) ex = o.hmode ? Math.max(ex, o.minMouseX) : Math.min(ex, o.maxMouseX);
                if (o.maxX != null) ex = o.hmode ? Math.min(ex, o.maxMouseX) : Math.max(ex, o.minMouseX);
                if (o.minY != null) ey = o.vmode ? Math.max(ey, o.minMouseY) : Math.min(ey, o.maxMouseY);
                if (o.maxY != null) ey = o.vmode ? Math.min(ey, o.maxMouseY) : Math.max(ey, o.minMouseY);

                nx = x + ((ex - o.lastMouseX) * (o.hmode ? 1 : -1));
                ny = y + ((ey - o.lastMouseY) * (o.vmode ? 1 : -1));

                if (o.xMapper)          nx = o.xMapper(y)
                else if (o.yMapper)     ny = o.yMapper(x)

                Drag.obj.root.style[o.hmode ? "left" : "right"] = nx + "px";
                Drag.obj.root.style[o.vmode ? "top" : "bottom"] = ny + "px";
                Drag.obj.lastMouseX     = ex;
                Drag.obj.lastMouseY     = ey;

                Drag.obj.root.onDrag(nx, ny);
                return false;
        },

        end : function()
        {
                document.onmousemove = null;
                document.onmouseup   = null;
                Drag.obj.root.onDragEnd(        parseInt(Drag.obj.root.style[Drag.obj.hmode ? "left" : "right"]),
                                                                        parseInt(Drag.obj.root.style[Drag.obj.vmode ? "top" : "bottom"]));
                Drag.obj = null;
        },

        fixE : function(e)
        {
                if (typeof e == 'undefined') e = window.event;
                if (typeof e.layerX == 'undefined') e.layerX = e.offsetX;
                if (typeof e.layerY == 'undefined') e.layerY = e.offsetY;
                return e;
        }
}
