var Win=new Array();
var numWin=0;
var IndexLayer=0;

function LoadFormFly(HDoc,Id,Str,Mode)
{
  win=numWin++;
	if ((!Win[win]) || (Win.closed)) 
	if(Mode == "Full") 
	{

		ScrWidth = screen.availWidth - 10;
		ScrHeight = screen.availHeight - 48;
		Str = Str + ',width=' + ScrWidth + ',height=' + ScrHeight + ',status=yes';
		Win[win] = window.open(HDoc,Id,Str);
	}
	else 
		Win[win] = window.open(HDoc,Id,Str);
	Win[win].focus();
  //return Win[win];
}


function LoadFormCenter(HDoc,Id,Str,Width,Height)
{ 
  win=numWin++;
	var Wcenter;
	var Hcenter;

	Wcenter = (screen.availWidth/2)-(Width/2);
	Hcenter = (screen.availHeight/2)-(Height/2);
	if ((!Win[win]) || (Win.closed)) 
	{
		ScrWidth = Width;
		ScrHeight = Height;
		Str = Str + ',top= '+ Hcenter +', left= '+ Wcenter +',width=' + ScrWidth + ',height=' + ScrHeight;
		Win[win] = window.open(HDoc,Id,Str);
	}
	Win[win].focus();
  //return Win[win];
}


function LoadFunction(Function)
{
	parent.AdminUsr.document.FrmListUsr.submit();
}


function LoadForm(Frm,StrParam,type)
{
	switch(Frm)
	{
		case 'AddUser':
			parent.MainFrame.document.location="insertar.php";
			break;
		case 'QueryUsr':
			parent.MainFrame.document.location="ViewDataUser.php?IdUser="+StrParam+"&Update=0";
			break;
		case 'UpdateUsr':
			parent.MainFrame.document.location="ViewDataUser.php?IdUser="+StrParam+"&Update=1";
			break;
		case 'AddProfile':
			parent.MainFrame.document.location="insertar.php";
			break;
		case 'QueryProfile':
			parent.MainFrame.document.location="ViewDataProfile.php?IdProfile="+StrParam+"&Update=0";
			break;
		case 'UpdateProfile':
			parent.MainFrame.document.location="ViewDataProfile.php?IdProfile="+StrParam+"&Update=1";
			break;
		case 'AddEvent':
			parent.MainFrame.document.location="insertar.php?type_form="+type;
			break;
		case 'QueryEvent':
			parent.MainFrame.document.location="ViewDatacontrol.php?gid_event="+StrParam+"&Update=0&type_form="+type;
			break;
		case 'UpdateEvent':
			parent.MainFrame.document.location="ViewDatacontrol.php?gid_event="+StrParam+"&Update=1&type_form="+type;
			break;
	}
}

function StartApp()
{
	parent.document.FrmLogin.submit();

}

function createLayer(id, left, top, width, height, content, visible, sendZindex) {

	if(width === false)
		add_WH = '';
	else
		add_WH = 'width: ' + width + '; height: ' + height + '; ';

	IndexLayer = IndexLayer + 1;
	
	valIndexLayer = IndexLayer;
	
	if (sendZindex)
	{
		valIndexLayer = sendZindex;
	}

	document.write('<div id="' + id + '"  style="overflow: hidden; position: absolute;  z-index:' + valIndexLayer + ';left: ' + left + '; top: ' + top + '; '+add_WH+' visibility: ' + visible + '; "  >' + content + '</div>');
}

/*Propiedad Intelectual <<Reynel Marroquin.>>
Función				:	PAJs()
Descripción			:	Función Encargada de traer todos los elementos de un objeto JavaScript
Parametros			:   
	ObjForArr			:	Objeto directo a obtener valores
	ObjInPrint			:	Objeto docmento donde se desea imprimir el resultado parametro opcional
Retorno				:	Escribe un listado en el documento donde se llame
Autor				:   Reynel Marroquin.
Fecha Creacion		:   22-Octubre-2007
Modificacion		:   22-Octubre-2007
Autor Modif.		:	Reynel Marroquin. */
function PAJs(ObjForArr, ObjInPrint )
{ 
	//Autor 		:	Reynel Marroquin. josegeoweb@hotmail.com 
	// ID #143
	// ej01: PrintArrayJs(document.styleSheets[0] [, parent.downFrame.document] );
	// esto pintaria el objeto style del documento actual en el frame marcado
	
	// Cuando escriben WindowOpen se abre en ventana nueva(se cambio)
	// si no esta definida se le aplica al documento
	
	if (ObjInPrint)
		ObjInPrint = document;
	else
	{
		var WinOpp = window.open("", "WinPrintArray", "top=50,left=50,height=570,width=770,status=yes,toolbar=no,menubar=yes,location=no, resizable=yes, scrollbars=yes" );
		ObjInPrint = WinOpp.document; 
	}
	
	// Buscamos en el documento algo escrito y lo limpiamos
	if (ObjInPrint)
	{
		if (ObjInPrint.body)
			ObjInPrint.body.innerHTML = "";
	}

	// Se escribe en el documento
	ObjInPrint.write("<TABLE border=1 STYLE=\"font-size: 11px; background-color: #EFEFEF; padding: 2px; border-top: 1px solid #3E3E3E; border-right: 1px solid #3E3E3E; border-bottom: 1px solid #3E3E3E; border-left: 1px solid #3E3E3E; BORDER-COLLAPSE: collapse;\">");
	//ObjInPrint.write("<TR><TD COLSPAN='2'>"+ObjForArr.type+"</TD></TR>");
	for (propriete in ObjForArr)
	{
		ObjInPrint.write("<TR><TD VALIGN=\"top\"><B>" + propriete + "</B> </TD><TD>");
		ObjInPrint.write("<PRE STYLE=\"display:inline;\">"+ ObjForArr[propriete] +"</PRE>");
		ObjInPrint.write("&nbsp;</TD></TR>");
	}
	ObjInPrint.write("</TABLE>");
}

// Escribe un valor de tipo label en una lista desplegable de formulario y lo escribe en un div
function ViewDescSelect(IdObjForm, IdDiv)
{
	Obj = document.getElementById( IdObjForm );
	document.getElementById( IdDiv ).innerHTML = (Obj.options[Obj.selectedIndex].label);
	//alert(Obj.option.selected);
	
}


//////////// Valida formularios (requiere Prototype) //////////
// Valida que los campos no son vacios
// retorna verdadero o falso.
function isValNull(ObjArr)
{
	var retur = true;
	ObjArr.each( function(obj)
				{ 
					if ( ( obj.value.empty() || obj.value.blank() ) && retur == 1 )
					{
						if ( !obj.value.empty())
							alert("El campo no puede contener solo espacios");
						else
							alert("El campo es requerido");

						obj.select();
						retur = false;
					}});
	return retur;
}


// Valida Que:
// 1) solo se escriban numeros 
// 2) no escriban caracteres no permitidos (se pueden agregar caracteres permitidos)
// 3) caracteres requeridos.
function isValNumStr(StrCad, TypeCad, AddStr)
{
	StrCad = new String (StrCad);
	if (TypeCad == 1)		// Solo numeros (1)
	{
		var StrVal = new String ("1234567890");

		/// Se debe agregar el caracter
		if (AddStr)
			StrVal += AddStr;
	}
	else if (TypeCad == 2)	// caracteres no permitidos (2)
	{
		var StrVal = new String ("ÁÉÍÓÚáéíóú$\"@#%^&*()[]+-{}`´~=|/\\?¿!¡ºª·¬¨Ç,;.:äëïöüÄËÏÖÜâêîôûÂÊÎÔÛÑñ<>");
		
		/// Se debe eliminar el caracter repetido
		if (AddStr)
			for (n=0; n<AddStr.length; n++)
				StrVal = StrVal.replace( AddStr.charAt(n), "" );		
	}
	else if (TypeCad == 3)	// caracteres requeridos (3)
	{
		var StrVal = new String (AddStr);		
	}
	else
		return true;
	
	if (TypeCad == 3)
	{
		for (i = 0; i < StrVal.length; i++)
		{
			var numI = new String (StrVal.charAt(i));
			if( StrCad.search(numI) == -1)
				return false;
		}
		return true;
	}

	for (i = 0; i < StrCad.length; i++)
	{
		var numI = new String (StrCad.charAt(i));
		
		if (TypeCad == 1)
			if( StrVal.search(numI) == -1 )
				return false;

		if (TypeCad == 2)
			if( StrVal.search(numI) != -1)
				return false;
	}

	return true;
}

// Se encarga de validar una direccion de correo
function isEmail(StrCad)
{
	var StrValue = StrCad;
    var exp_reg = /^[^@\s]+@[^@\.\s]+(\.[^@\.\s]+)+$/
    
    if (!(exp_reg.test(StrValue)))
    	return false;    
    
	return true;

	// Eje:
	// Valida que este escrito bien el mail
	/*if ( !isEmail( $('Obj_mail').value ) )
	{
		alert("Mal escrito el mail");
		$('Obj_mail').select();
		return false;
	}*/
}

// verifica que solo escriban numeros
function manejadorEntero()
{
  var evento = window.event || arguments[0];
  var codigo = evento.keyCode || evento.charCode;

  if(codigo == 8 || codigo ==9 || codigo == 35 || codigo ==36 || codigo == 37 || codigo ==39 || (codigo >= 48 && codigo <= 57))
	  return true;
  else
	{
  	if(!window.event)
			evento.preventDefault();
	  return false;
  }
}
