// JavaScript Document
    $(document).ready(function() {

	$("#pac_cat").change(function(){
		var uid = $(this).val();
		$("#div_pac_cat").hide();
		$.ajax(
		{
			type: "POST",
			url: "http://www.gobolivia.com.bo/web/body/listSubCat.php",
			data: "uid="+uid,
			success: function(datos)
			{
				if(datos!='clear'){
					$('#subcat').html(datos);
					$('#subcat').show();
				}else{
					$('#subcat').html('');					
					$('#subcat').hide();
				}
			}
		});	
	});

		$("#reqInf").click(function(){
			if($("#formReqInf").attr('style')=='display: none;'){
				$("#formReqInf").show();
			}else{
				$("#formReqInf").hide();
			}
		});
		$("#swSend").click(function(){
				if(this.checked){
					$("#btnSub").attr('disabled','');
				}else{
					$("#btnSub").attr('disabled','disabled');
				}
		});
				
		$("#ct_pay0").change(function(){
			$("#ct_pay0_").text($("#ct_pay0").val());
		});
		$("#ct_country0").change(function(){
			$("#ct_country0_").text($("#ct_country0").val());
		});
		$("#ct_country").change(function(){
			$("#ct_country_").text($("#ct_country").val());
		});
		//on submit
			$("form.validable").bind("submit", function(e){
				var post = "";
				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");
									$("#div_"+idName).show();
								}else{
									var idName = $(el).attr("name");
									if(post==''){
										post = idName + "=" + $(el).val();
									}else{
										post = post + "&"+idName + "=" + $(el).val();
									}
									
								}
							}	
						});
					}
				});
				if ($(this).find(".req").size() > 0) {
					$.stop(e || window.event);
					return false;
				}
				//alert(post);
				//alert($(this).attr('id')+".php");
				if($("#ct_pay0").val()){
					post = post + "&"+$("#ct_pay0").attr("id") + "=" + $("#ct_pay0").val();
				}
				if($("#ct_country0").val()){
					post = post + "&"+$("#ct_country0").attr("id") + "=" + $("#ct_country0").val();
				}
				if($("#ct_country").val()){
					post = post + "&"+$("#ct_country").attr("id") + "=" + $("#ct_country").val();
				}
				if($("#ct_servi0").val()){
					post = post + "&"+$("#ct_servi0").attr("id") + "=" + $("#ct_servi0").val();
				}
				if($("#ct_pack0").val()){
					post = post + "&"+$("#ct_pack0").attr("id") + "=" + $("#ct_pack0").val();
				}	
				if($("#country").val()){
					post = post + "&"+$("#country").attr("id") + "=" + $("#country").val();
				}
				if($("#ct_city").val()){
					post = post + "&"+$("#ct_city").attr("id") + "=" + $("#ct_city").val();
				}				
				if($("#pac_cat").val()){
					post = post + "&"+$("#pac_cat").attr("id") + "=" + $("#pac_cat").find(':selected').text();
				}
				if($("#pac_subcat").val()){
					post = post + "&"+$("#pac_subcat").attr("id") + "=" + $("#pac_subcat").find(':selected').text();
				}
				var uid =$(this).attr('id');
				$.ajax(
				{
						//alert (this+'1');
						type: "POST",
						url: "http://www.gobolivia.com.bo/web/send/"+$(this).attr('id')+".php",
						data: post,
						success: function(datos)
						{
							$("#res_"+uid).html(datos).fadeIn();
							setTimeout("$('#res_"+uid+"').fadeOut(700);",3000);							
						}
				});			
				return false;
				//return true;
			});
		
		// on focus	remueve los tag de error
			$("form.validable").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).fadeOut(800);
						}
				});
			});
		// end	

    });
	
	
function validate2()
	{
	// Probando lo del captcha
	var captcha = document.getElementById('captcha').value;
	if (captcha=="")
		{
		//document.getElementById('divcaptcha').innerHTML ='código requerido';
		validate();
		}
	else
		{
		ajax=objectAjax();
		//uso del medotod POST
		ajax.open("POST", "captchaVerify.php",true);
		ajax.onreadystatechange=function() {
				if (ajax.readyState==4) 
					{
					//mostrar resultados en esta capa
					res = ajax.responseText;
					if (res==0) 
						{ 	
						document.getElementById('captcha').value='';
						validate();
						document.getElementById('divcaptcha').innerHTML ='Código incorrecto';						
						}
					else
						{
						validate();
						}
						
					}
				}  
		ajax.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
		//enviando los valores
		ajax.send("captcha=" + captcha);
		}

	}	
