// JavaScript Document 
// Validate with jquery version 1.3
// more validations added and uses name instead if div

	var filters = {
			required: function(el) {return ($(el).val() != '' && $(el).val() != -1);},
			email: function(el) {return /^[A-Za-z][A-Za-z0-9_\.\-]*@[A-Za-z0-9_\-]+\.[A-Za-z0-9_.\-]+[A-za-z]$/.test($(el).val());},
			password: function(el){return /^[a-zA-Z0-9áéíóúAÉÍÓÚÑñ\.,;:\|)"(º_@><#&'\?¿¡!/\\%\$=]*$/.test($(el).val());},			
			alphanum: function(el){return /^[a-zA-Z0-9 áéíóúAÉÍÓÚÑñ\.,;:\|)"(º_@><#&'\?¿¡!/\\%\$=]*$/.test($(el).val());}
		};	


$.extend({
		/* PARAMOS LA EJECUCIÓN*/
		stop: function(e){
        if (e.preventDefault) e.preventDefault();
        if (e.stopPropagation) e.stopPropagation();
    }, 
    /* PERSONALIZAMOS LA SALIDA POR PANTALLA */
    alert: function(str) {
    	alert(str);	
    }
});

function openwindow(tipoConsulta)
{
		mywindow = window.open("http://www.fundempresa.org.bo/portal/sitio/consultasWeb.jsp?tipoConsulta="+tipoConsulta+"&random=" + Math.random(),"mywindow","toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=750,height=550");
        mywindow.moveTo(200, 100);        
}

function openpopup(tipoConsulta)
{
		mywindow = window.open(tipoConsulta,"mywindow","toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=yes,width=900,height=560");
        mywindow.moveTo(200, 100);        
}

var ok=false;

$(document).ready(function(){

	$("#formLog input").keypress(function(){
            ok=true;
	});

// hide message 
  if($('#messageBox').html()!='' )
	  $('#messageBox').fadeIn(800, function() {
	          setTimeout(function(){ $('#messageBox').fadeOut(800) },4000);
	      });


//on submit
	$("form.validable2").bind("submit", function(e){
		if (typeof filters == 'undefined') return;
	    $(this).find("input, textarea, select").each(function(x,el){ 
	        if ($(el).attr("className") != 'undefined') { 
				$(el).removeClass("req");
	        	$.each(new String($(el).attr("className")).split(" "), function(x, klass){
	            if ($.isFunction(filters[klass]))
	                if (!filters[klass](el)){
						$(el).addClass("req");
						var idName = $(el).attr("name");
                        if($(el).val()==''){
                            $("#div_"+idName).show();
						}
                        else{
                            $("#div_"+idName+"_2").show();
						}
						}
	        });
	        }
	    });
		if ($(this).find(".req").size() > 0) {
			$.stop(e || window.event);
			return false;
		}
		else{
                           usuario = $("#ct_mail_log").val();
                           password = $("#ct_name_log").val();
                           if(ok){
                               // $(this).hide();
                                $('#loading2').show();
                                   mywindow = window.open("http://www.fundempresa.org.bo/portal/sitio/ingresoWeb.jsp?cdUsuario="+usuario+"&cdClave="+password+"&random=" + Math.random(),"mywindow","toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=750,height=550");
                                    mywindow.moveTo(200, 100);  
                                $('#loading2').hide(); 
                                $("#ct_mail_log").val('');
                                $("#ct_name_log").val('');
                            }
                            else{
                             $('#messageBox').html('Forbidden');  
                             $('#messageBox').fadeIn(800, function() {
                                          setTimeout(function(){ $('#messageBox').fadeOut(800) },4000);
                                      });
                            }
			   return false;
                           
		}
	});

// on focus	remueve los tag de error
	$("form.validable2").find("input, textarea, select").each(function(x,el){ 
		$(el).bind("focus",function(e){
				if ($(el).attr("className") != 'undefined') { 
								$(el).removeClass("req");
						var idName = $(el).attr("name");
						$("#div_"+idName).hide();
						$("#div_"+idName+"_2").hide();
				}
		});
	});
// end

});

