/*	
	*******************************************************************************
	@Powered by WBC
	@Copyright(c) 2007	
	@Todos los Derechos Reservados	
	@Author Jhon Rhoos <j_hinojosa43@yahoo.es>
	@JavaScript - JSP
	*******************************************************************************	
*/

	function reverse(str)
	{
		var reversedstr = "";
		var strArray;
		strArray = str.split("");
		for(var i = str.length -1 ; i >= 0 ; i--)
		{
			reversedstr += strArray[i];
		}
		return reversedstr;
	}

	function ltrim(str)
	{
		while(""+str.charAt(0)==" ")
		{
			str=str.substring(1,str.length);
		}
		return str;
	}
	
	function trim(str)
	{
		str = ltrim(str);
		str = reverse(str);
		str = ltrim(str);
		str = reverse(str);
		return str;
	}
	
	function checkemail(str)
	{
		var filter=/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/
		return (filter.test(str))
	}
	
	function msg_box(msg)
	{
		alert(msg);
	}

/****************************************************************/

	function OpenBrWindow(theURL,winName,features, myWidth, myHeight, isCenter) 
	{ 
		if(window.screen)if(isCenter)if(isCenter=="true")
		{
			var myLeft = (screen.width-myWidth)/2;
			var myTop = (screen.height-myHeight)/2;
			features+=(features!='')?',':'';
			features+=',left='+myLeft+',top='+myTop;
		}
		window.open(theURL,winName,features+((features!='')?',':'')+'width='+myWidth+',height='+myHeight);
	}
	
	
	function Alert_Delete(IdPach, theURL, cadena){
		if(confirm(' ¿ Esta Seguro de Eliminar este Registro ?')){
			window.location= theURL+"?Action=delete"+ cadena +"&IdPach="+IdPach;
		} 
	}
	
	function Alert_Delete_St(Msgbox, IdPach, theURL, cadena){
		if(confirm(Msgbox)){
			window.location= theURL+"?Action=delete"+ cadena +"&IdPach="+IdPach;
		} 
	}
	
	function LocationEnter(evt,value,Href){				
		evt = (evt) ? evt : event
		var charCode = (evt.which) ? evt.which : evt.keyCode
		if(charCode==13)
		{
			window.location= Href.value;
		}
	}
	
	function return_prefijo(id, pref)
	{		
		opener.document.forms[0].IdN.value=id;
		opener.document.forms[0].txt_title_.value=pref;			
		window.close()		
	}	
	
	function WindowLocation(theURL,cadena)
	{	
		if(trim(cadena)=="")
			window.location= theURL;
		else
			window.location= theURL+"?"+cadena;	
	}
	
	function submitenter(myfield,e)
	{
		var keycode;
		if (window.event)
			 keycode = window.event.keyCode;
		else if (e) keycode = e.which;
		else return true;		
		if (keycode == 13)
		{
			myfield.form.submit();
			return false;
		}
		else
			return true;
	}
	
/****************************************************************/

	function CloseWindow()
	{
		window.opener.location.reload();
		window.close();
	}

/****************************************************************/

	function seleccionar_todo(){ 
		for (i=0;i<document.forms[0].elements.length;i++) 
		  if(document.forms[0].elements[i].type == "checkbox") 
			 document.forms[0].elements[i].checked=1 
	}
	
	function invertir() 
	{
		for (i = 0; i < form1.elements.length; i++)
		form1.elements[i].checked = !form1.elements[i].checked;		
	}
	
	
/*****************************************************************/
	
	function load_imajes(img, ancho, alto)
	{
		var ventana;		
		derecha=(screen.width-ancho)/2;
		arriba=(screen.height-alto)/2;	
		string="toolbar=0,scrollbars=1,location=0,scroll=true,statusbar=1,menubar=0,resizable=0,width="+ancho+",height="+alto+",left="+derecha+",top="+arriba+"";		
		ventana=window.open(img,"",string);		
		ventana.document.write('<html><head><title>Grupo ADE :: Imagen</title></head><body style="overflow:hidden" marginwidth="0" marginheight="0" topmargin="0" bottommargin="0" leftmargin="0" rightmargin="0" toolbar=1 scroll=true onUnload="opener.cont=0"><img src="' + img + '" onLoad="opener.redimensionar(this.width, this.height)">'); 
		ventana.document.close() ;		

		function redimensionar(ancho,alto) 
		{ 
			ventana.resizeTo(ancho,alto) 
			ventana.moveTo((screen.width-ancho)/2,(screen.height-alto)/2)
		} 	
	}


	function validar()
	{
		if (trim(document.form1.txt_nombre.value) == "")
		{
			alert("Ingrese Nombre");
			document.form1.txt_nombre.focus();
			return false;
		}
		if (trim(document.form1.txt_apell.value) == "")
		{
			alert("Ingrese apellido");
			document.form1.txt_apell.focus();
			return false;
		}
		
		if (trim(document.form1.txt_direc.value) == "")
		{
			alert("Ingrese Direccion");
			document.form1.txt_direc.focus();
			return false;
		}
		if (trim(document.form1.txt_city.value) == "")
		{
			alert("Ingrese Ciudad");
			document.form1.txt_city.focus();
			return false;
		}	
	
		if (trim(document.form1.txt_postal.value) == "")
		{
			alert("Ingrese Codigo Postal");
			document.form1.txt_postal.focus();
			return false;
		}
		if (trim(document.form1.txt_prov.value) == "")
		{
			alert("Ingrese provincia");
			document.form1.txt_prov.focus();
			return false;
		}	


		if (trim(document.form1.txt_country.value) == "")
		{
			alert("Ingrese Pais");
			document.form1.txt_country.focus();
			return false;
		}
		if (trim(document.form1.txt_phone.value) == "")
		{
			alert("Ingrese Telefono");
			document.form1.txt_phone.focus();
			return false;
		}	
		
		if (trim(document.form1.txt_mail.value) == "")
		{
			alert("Ingresar E-Mail");
			document.form1.txt_mail.focus();
			return false;
		}
		if (checkemail(trim(document.form1.txt_mail.value)) == false)
		{
			alert("Formato de E-Mail no valido");
			document.form1.txt_mail.focus();
			return false;
		}
		
		if (trim(document.form1.txt_confir.value) == "")
		{
			alert("Ingresar E-Mail");
			document.form1.txt_confir.focus();
			return false;
		}
		if (checkemail(trim(document.form1.txt_confir.value)) == false)
		{
			alert("Formato de E-Mail no valido");
			document.form1.txt_confir.focus();
			return false;
		}
		
		if (trim(document.form1.txt_mail.value) !=  trim(document.form1.txt_confir.value) )
		{
			alert("E-Mail no coincide");
			document.form1.txt_confir.focus();
			return false;
		}
		
		if (trim(document.form1.txt_consulta.value) == "")
		{
			alert("Ingrese Consulta");
			document.form1.txt_consulta.focus();
			return false;
		}	
		return true;
	}
	
	function validar4()
	{		
		if (trim(document.form1.txt_nombre.value) == "")
		{
			alert("Ingrese Nombre");
			document.form1.txt_nombre.focus();
			return false;
		}
		
		if (trim(document.form1.txt_email.value) == "")
		{
			alert("Ingresar E-Mail");
			document.form1.txt_email.focus();
			return false;
		}
		
		if (checkemail(trim(document.form1.txt_email.value)) == false)
		{
			alert("Formato de E-Mail no valido");
			document.form1.txt_email.focus();
			return false;
		}
		
		if (trim(document.form1.txt_empresa.value) == "")
		{
			alert("Ingrese Empresa");
			document.form1.txt_empresa.focus();
			return false;
		}	
						
		if (trim(document.form1.txt_cargo.value) == "")
		{
			alert("Ingrese Profesión / Cargo");
			document.form1.txt_cargo.focus();
			return false;
		}	
		
		
		if (trim(document.form1.txt_phone.value) == "")
		{
			alert("Ingrese Telefono");
			document.form1.txt_phone.focus();
			return false;
		}	
		
		if (trim(document.form1.txt_direc.value) == "")
		{
			alert("Ingrese Direccion");
			document.form1.txt_direc.focus();
			return false;
		}		
		
		if (trim(document.form1.txt_consulta.value) == "")
		{
			alert("Ingrese Consulta");
			document.form1.txt_consulta.focus();
			return false;
		}	
		return true;
	}
	
	function validar3()
	{		
		if (trim(document.form1.txt_nombre.value) == "")
		{
			alert("Ingrese Nombre");
			document.form1.txt_nombre.focus();
			return false;
		}
				
		if (trim(document.form1.txt_phone.value) == "")
		{
			alert("Ingrese Telefono");
			document.form1.txt_phone.focus();
			return false;
		}	
		
		if (trim(document.form1.txt_direc.value) == "")
		{
			alert("Ingrese Direccion");
			document.form1.txt_direc.focus();
			return false;
		}		
		
			if (trim(document.form1.txt_email.value) == "")
		{
			alert("Ingresar E-Mail");
			document.form1.txt_email.focus();
			return false;
		}
		
		if (checkemail(trim(document.form1.txt_email.value)) == false)
		{
			alert("Formato de E-Mail no valido");
			document.form1.txt_email.focus();
			return false;
		}
		return true;
	}
	
	function validar_curso()
	{
		if (trim(document.forms[0].cbo_curso.value) == "")
		{
			alert("Seleccione Curso");
			document.forms[0].cbo_curso.focus();
			return false;
		}
				
		if (trim(document.forms[0].txt_razon.value) == "")
		{
			alert("Ingresar Razon");
			document.forms[0].txt_razon.focus();
			return false;
		}
		
		if (trim(document.forms[0].txt_ruc.value) == "")
		{
			alert("Ingresar RUC");
			document.forms[0].txt_ruc.focus();
			return false;
		}	
		
		if (trim(document.forms[0].txt_direc.value) == "")
		{
			alert("Ingresar Direccion");
			document.forms[0].txt_direc.focus();
			return false;
		}	
				
		if (trim(document.forms[0].txt_telef.value) == "")
		{
			alert("Ingresar Telefono");
			document.forms[0].txt_telef.focus();
			return false;
		}	
		
		if (trim(document.forms[0].txt_mail.value) == "")
		{
			alert("Ingresar E-Mail");
			document.forms[0].txt_mail.focus();
			return false;
		}
		
		if (checkemail(trim(document.forms[0].txt_mail.value)) == false)
		{
			alert("Formato de E-Mail no valido");
			document.forms[0].txt_mail.focus();
			return false;
		}		

		if (trim(document.forms[0].txt_giro.value) == "")
		{
			alert("Indicar Giro de la Empresa");
			document.forms[0].txt_giro.focus();
			return false;
		}
			
		if (trim(document.forms[0].txt_func1.value) == "")
		{
			alert("Indicar nombre del funcionario \nSe requiere como minimo un Funcionario registrado");
			document.forms[0].txt_func1.focus();
			return false;
		}
		
		if (trim(document.forms[0].txt_carg1.value) == "")
		{
			alert("Debe indiciar el Cargo del Funcionario");
			document.forms[0].txt_carg1.focus();
			return false;
		}
		return true; 		
	}