var nav4 = navigator.appName != 'Microsoft Internet Explorer'  ? true : false;
var msg = '';
var identsformupdate=Array();
var fecha2 = 0;
var IE = document.all?true:false;
//var msghelp = new appTT.toolTip();

if (!IE) document.captureEvents(Event.MOUSEDOWN)
if (!IE) document.captureEvents(Event.MOUSEOVER)
document.onmouseover = posicRatonXY;
var posicX = 0
var posicY = 0
var msg = '';
//var msghelp = new appTT.toolTip();
//funciones de la ayuda
	function showToolTip(mensajeoculto){
		//alert("perro");
		msghelp.message = mensajeoculto;
		msghelp.show();
	}
	function hideToolTip() {
		msghelp.hide();
	}
	

	


   function posicRatonXY(e)
    {
        if (IE)
        {

            if( document.documentElement &&  ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
            //IE6 standards compliant mode

            posicX = event.clientX + document.documentElement.scrollLeft;
            posicY = event.clientY + document.documentElement.scrollTop;
            }
            else
            {
                posicX = event.clientX + document.body.scrollLeft;
                posicY = event.clientY + document.body.scrollTop;
            }
        }

        else
        {
             posicX = e.pageX;
             posicY = e.pageY
        }

        if (posicX < 0) posicX = 0;
        if (posicY < 0) posicY = 0;

return true

    }


function heightframe()
 {
	if (window.scrollHeight)
	{
		return window.scrollHeight + document.documentElement.scrollTop;
	}
	else if (document.documentElement && document.documentElement.scrollHeight != 0)
	{
		return document.documentElement.scrollHeight + document.documentElement.scrollTop;
	}
	else if (document.body)
	{
		return document.body.scrollHeight + document.body.scrollTop	;
	}
	return false;
}

	function loadingLayer(funcion)
	{

		var loadingLayer = document.getElementById('loading_layer');
	    document.getElementById('bloqueaC').style.height = heightframe() + 'px';
		document.getElementById('bloqueaC').style.display = 'block';
		loadingLayer.style.display = 'block';
		setTimeout(funcion,50);
	}

	function unloadLayer()
	{
		var loadingLayer = document.getElementById('loading_layer');
		loadingLayer.style.display = 'none';
		var bloqueaC = document.getElementById('bloqueaC').style.display = 'none';
		document.getElementById('formUnload').style.display = 'none';
		document.getElementById('textoInformativo').innerHTML = 'Procesando la solicitud';
	    document.getElementById('imagenCargando').src = '../img/ajax-loader.gif';
	    document.getElementById('accionEspera').style.display = 'block';
	}

	function procesaInfo(msg)
	{
	  document.getElementById('accionEspera').style.display = 'none';
	  document.getElementById('textoInformativo').innerHTML = msg;

	  document.getElementById('formUnload').style.display = 'block';
	  document.getElementById('imagenCargando').src = '../img/ajax-loader.gif';
	}

	function urldecode(cadena)
	{
	   cadena = cadena.replace(/[+]/g," ");
	   return unescape(cadena);
	}

	function Borra(teclaP,valor)
	{
	    if(nav4)
	    {
	    	document.captureEvents(Event.KEYDOWN);
	    	var teclaCodigo = teclaP.which;
	    }
	    else
	    {
			var teclaCodigo = event.keyCode;

	    }
	    if (teclaCodigo == 46)
	    {
			if(confirm("�Seguro que deseas borrar este elemento del c�talogo?"))
			{
				loadingLayer('borraValor('+valor+')');
			}
	    }
	}

function seguro()
{
   if (confirm('Seguro deseas eliminar este alumno?'))
   {
	return true;
	}
	else
return false;
}

function trimCadena( str )
{
  //Pa' quitar los espacios en blanco al final y al principio de una cadena
  str = str.replace(/^\s*|\s*$/g,"");
  return str;
}


// Funci�n para deshabilitar las teclas que no sean n�meros, enter, y una que no me acuerdo


function acceptNumInt(evt){

	var key = nav4 ? evt.which : evt.keyCode;
	return (key <= 13 || (key >= 48 && key <= 57));
}

function recargos(valor,id){
  var porcentaje = 1 + (valor / 100);
  resta = document.getElementById('resta'+id).value;
  total = resta * porcentaje;

    document.getElementById('total'+id).value = total;

    var numberTest = new NumberFormat(total);

    numberTest.setCurrency(true);
    numberTest.setCommas(3);
    numberTest.setPlaces(2);
    numberTest.setCurrencyPrefix('$');

    document.getElementById('text'+id).innerHTML = numberTest.toFormatted();
    pushPay();
}

function acceptNumDec(evt){

var key = nav4 ? evt.which : evt.keyCode;
return (key <= 13 || key == 46 || (key >= 48 && key <= 57));
}

function onlyNumber(cadena)
{
	cadena = cadena.replace(/[A-Z]+/gi,"");
	return cadena;
}

function verifica(elmFORM)
{
	//alert(elmFORM.elements);
 var cnjFORM = elmFORM.elements;
 
 var Chequeo = 1;
 var Chequeo_text=1;
 var requeridos_valida_check=0;
 var requeridos_checkbox=0;
 var requeridos_radio =0;
 var requeridos_valida_radio=0;
 var campos="";
//alert (cnjFORM.length);
for (var i=0; i<cnjFORM.length; i++) {

if (cnjFORM[i].className=='requerido')
      {
      	
        var tipo_forma = cnjFORM[i].type;
        var nombre_campo=cnjFORM[i].title;
	var nombre2 = tipo=cnjFORM[i].name;
	//var nombre3 = cnjFORM[i-1].name;
//	if(nombre3.substring(0,5) == 'secc_')
//	{
//	  seccion = cnjFORM[i-1].value;
//	  seccion = seccion + ' -> ';
//	}
//	else
//	{
//	  seccion = '';
//	}
	switch(tipo_forma)
      	{
      	  case 'select-one':

	     if (cnjFORM[i].value == '0' || cnjFORM[i].value == '')
      	       {

      	       	  //cnjFORM[i].focus();
      	       	  alert ('Ingrese el siguiente campo del formulario: '+ nombre_campo);
		  return false;

      	       }
      	  break;

      	  case 'checkbox':
			var requeridos_valida_check=0;
			var cuantos=cnjFORM[i].id;
			requeridos_checkbox++;
			for (var j=0; j<cuantos ; j++){
			   if (cnjFORM[i+j].checked){
				requeridos_valida_check++;
				break;
			   }
			}
      	  	if (requeridos_valida_check == 0){
      	  	   	//cnjFORM[i].focus();
      	  	   	alert ('Ingrese el siguiente campo del formulario: '+ nombre_campo);
      	  	   		  return false;
      	  	}
      	  break;

      	  case 'radio':
      	  	var cuantos=cnjFORM[i].id;
			var requeridos_valida_radio=0;
      	  	requeridos_radio++;
      	  	for (var j=0; j<cuantos ; j++)
      	  	{
      	   	   if (cnjFORM[i+j].checked)
      	  	   {
      	  	   	requeridos_valida_radio++;
      	  	   	break;
      	  	   }
      	  	}
      	  	if (requeridos_valida_radio == 0)
      	  	   {

      	  	   	//cnjFORM[i].focus();
      	  	   	alert ('Ingrese el siguiente campo del formulario: '+ nombre_campo);
      	  	   	return false;
      	  	   }
    	  break;

      	  default:
      	  	if (cnjFORM[i].value.length == '')
      	  	{

		     //cnjFORM[i].focus();
		     alert ('Ingrese el siguiente campo del formulario: '+ nombre_campo);
		     	  return false;
      	  	}
       	  }
       }

     }
     return true;
}
function validarNumero(numero,nameField,idField){
	if(trimCadena != ''){
		if( !validaRS.isnumber(numero) ){
			alert("El campo "+nameField+" debe contener s�lo numeros");
			document.getElementById(idField).value = '';
		return false
	}
	return true;
	}
	return false;
}

function validarMail(mail,nameField,idField){
	mail = document.getElementById(idField).value;
	if(trimCadena(mail) != ''){
		if( !validaRS.isemail(mail) ){
			alert("El campo "+nameField+" debe contener una direcci�n de correo v�lida");
			document.getElementById(idField).value = '';
		return false
		}
		return true;
	}
	return false;
}

function validarFecha(fecha,idField){
	if(trimCadena(fecha) != ''){
		if( !validaRS.isdate(fecha) ){
			alert("La fecha que ingresaste no es v�lida el formato correcto es AAAA-MM-DD");
			document.getElementById(idField).value = '';
			document.getElementById(idField).focus();
		return false
	}
	return true;
	}
	return false;

}

function PY(){
		if (window.scrollHeight) {
			return document.documentElement.scrollTop;
		} else if (document.documentElement && document.documentElement.scrollHeight != 0) {
			return document.documentElement.scrollTop;
		} else if (document.body) {
			return document.body.scrollTop;
		}
		return false;
}
 function eventosAlta(){
 
 var 	org=document.getElementById("organization").value;
 var	name=document.getElementById("name").value;
 var	last=document.getElementById("last").value;
 var	email=document.getElementById("email").value;
 var	city=document.getElementById("city").value;
 var	country=document.getElementById("country").value;
 var	estado=document.getElementById("state").value;
 var	tel=document.getElementById("tel").value;
 var	cat=document.getElementById("category").value;
 var	title=document.getElementById("title").value;
 var	keyword=document.getElementById("keyword").value;
 var	url=document.getElementById("url").value;
 var	txt=document.getElementById("text").value;
 	if(org==""){
 	alert("check the organization");	
 	return;
 	}
 	if(name==""){
 	alert("check the name");
 	return;	
 	}
 	if(last==""){
 	alert("check the last name");	
 	return;
 	}
 	if(email==""){
 	alert("check the email");	
 	return;
 	}
 	if(city==""){
 	alert("check the city");	
 	return;
 	}
 	if(estado==""){
 	alert("check the state");	
 	return;
 	
 	}if(country==""){
 	alert("check the country");	
 	return;
 	
 	}if(cat==""){
 	alert("check category");	
 	return;
 	}
 	if(title==""){
 	alert("check the title");	
 	return;
 	}
 	if(keyword==""){
 	alert("check the keywords");	
 	return;
 	}
 	if(url==""){
 	alert("check URL");	
 	return;
 	}
 	if(txt==""){
 	alert("check text");	
 	return;
 	} 	else{
 	document.getElementById("forma").submit();
 	}
 	
 }
 function comprasPaypalIN(){
	var name=document.getElementById("nombre").value;
	var apellido=document.getElementById("apellido").value;
	var s=document.getElementById("correo").value;
	var ciudad=document.getElementById("ciudad").value;
	var direccion=document.getElementById('direccion').value;
	var codigo=document.getElementById('codigo').value;
	var state=document.getElementById('estado').value;
	var pais=document.getElementById("country").selectedIndex;
	var texto=document.getElementById("testimonio").value;
	var cantidad=document.getElementById("cantidad").value;
	var forma =document.getElementById("forma");
	  
	
		
	if (name==""){
		alert("Please Insert your First name");
		document.getElementById("nombre").focus();
		return;
	}
	if (apellido==""){
		alert("Please Insert your Last name ");
		document.getElementById("apellido").focus();
		return;
	}

		if (s==""){
		alert("Please Insert your email");
		document.getElementById("correo").focus();
		return;
	}

var filter=/^[A-Za-z][A-Za-z0-9_]*@[A-Za-z0-9_]+.[A-Za-z0-9_.]+[A-za-z]$/;
if (s.length == 0 ){
}
if (filter.test(s)){

}else{
alert("Please enter a valid e-mail account");
document.getElementById("correo").focus();
return;
}

  	if (direccion==""){
		alert("Please insert your  address");
		document.getElementById("direccion").focus();
		return;
	}
	
	if (ciudad==""){
		alert("Please insert your  city");
		document.getElementById("ciudad").focus();
		return;
	}

	
	if (codigo==""){ 
       alert("Please insert your  zip code ") 
       document.getElementById('codigo').focus() 
       return; 
    }
     var enteroCP= validarEntero(codigo);
     
     	if(enteroCP==""){
  			  alert("This is not valid postcode");	
  	  return;			
  	  }
  	  if(codigo.length <=4){
  		alert("This is not a valid code");
  		return;
  	}	
  	if (pais==0){
		alert("Please insert your country");
		document.getElementById("country").focus();
		return;
	}


	if (cantidad==""){
		alert("Please enter the amount");
		document.getElementById("cantidad").focus();
		return;
	}
	  var enteroCantidad= validarEntero(cantidad);
     	if(enteroCantidad==""){
      	alert("this is not a quantity");	
  	  return;			
  	  }
  	 forma.submit();
}