// JavaScript Document
function formsContact() { $("#formReqCon").toggle(); }

$(document).ready(function() {
		$("#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");
			//form 1
				if($("#ct_name0").val()){
					post = post + "&"+$("#ct_name0").attr("id") + "=" + $("#ct_name0").val();
				}
				if($("#ct_email0").val()){
					post = post + "&"+$("#ct_email0").attr("id") + "=" + $("#ct_email0").val();
				}
				if($("#ct_phone0").val()){
					post = post + "&"+$("#ct_phone0").attr("id") + "=" + $("#ct_phone0").val();
				}
				if($("#ct_country0").val()){
					post = post + "&"+$("#ct_country0").attr("id") + "=" + $("#ct_country0").val();
				}
				if($("#ct_city").val()){
					post = post + "&"+$("#ct_city").attr("id") + "=" + $("#ct_city").val();
				}
				
				
				//form 2
				if($("#ct_name1").val()){
					post = post + "&"+$("#ct_name1").attr("id") + "=" + $("#ct_name1").val();
				}
				if($("#ct_second1").val()){
					post = post + "&"+$("#ct_name1").attr("id") + "=" + $("#ct_name1").val();
				}
				if($("#ct_email1").val()){
					post = post + "&"+$("#ct_email1").attr("id") + "=" + $("#ct_email1").val();
				}
				if($("#ct_phone1").val()){
					post = post + "&"+$("#ct_phone1").attr("id") + "=" + $("#ct_phone1").val();
				}
				if($("#ct_country1").val()){
					post = post + "&"+$("#ct_country1").attr("id") + "=" + $("#ct_country1").val();
				}
				if($("#ct_servi1").val()){
					post = post + "&"+$("#ct_servi1").attr("id") + "=" + $("#ct_servi1").val();
				}
				if($("#ct_pack1").val()){
					post = post + "&"+$("#ct_pack1").attr("id") + "=" + $("#ct_pack1").val();
				}
				if($("#ct_num_po1").val()){
					post = post + "&"+$("#ct_num_po1").attr("id") + "=" + $("#ct_num_po1").val();
				}
				if($("#ct_city1").val()){
					post = post + "&"+$("#ct_city1").attr("id") + "=" + $("#ct_city1").val();
				}			
				if($("#ct_date1").val()){
					post = post + "&"+$("#ct_date1").attr("id") + "=" + $("#ct_date1").val();
				}
	 			var uid =$(this).attr('id');
				$.ajax(
				{
						//alert (this+'1');
						type: "POST",
						url: "http://www.gobolivia.com.bo/web/send/"+$(this).attr('id')+".php", //http://localhost/gobolivia/
						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		
    });
