//autovaciar campos de formulario
function input_focus(campo,texto){
	if(campo.value==texto){campo.value='';}
}
function input_blur(campo,texto){
	if(campo.value==''){campo.value=texto;}
}
function buscarPlan(){
	if(document.searchForm.searchQuestion.value=='') {
		alert('Ingrese la opción de busqueda');
		return false;
	}
	document.searchForm.submit();
}

	$(document).ready(function() {
	  //<img src="img/ajax-loader.gif" border=0>		
	  $('<div id="procesando"><span></span> Cargando...</div>')
		.insertAfter('#msgAjax')
		.ajaxStart(function() {
		  $(this).show();
		}).ajaxStop(function() {
		  $(this).hide();
		});
		
	});


	$(function() {
		
		var mailto=null;
		var divmailto=document.getElementById("divmailto");
		if(divmailto) {
			$("#divmailto").click(function() {
				mailto=document.getElementById(this.id).getAttribute("correo");
				$("#contantar_a").val(mailto);
				$( "#dialog-form" ).dialog( "open" );
			});
		}
		
		// a workaround for a flaw in the demo system (http://dev.jqueryui.com/ticket/4375), ignore!
		$( "#dialog:ui-dialog" ).dialog( "destroy" );
		
		$("#divRespAjax").hide();
		
		var name = $( "#name" ),
			email = $( "#email" ),
			comentarios = $( "#comentarios" ),
			telefono = $( "#telefono" ),
			allFields = $( [] ).add( name ).add( email ).add( comentarios ).add( telefono ),
			tips = $( ".validateTips" );

		$( "#dialog-form" ).hide();
		
		$( "#dialog-form" ).dialog({
			autoOpen: false,
			height: 450,
			width: 480,
			modal: true,
			buttons: {
				"Enviar": function() {
					var bValid = true;

					var resp=spryname.validate();		
					if(!resp) return false;	
					var resp=spryemail.validate();		
					if(!resp) return false;	
					var resp=sprycomentarios.validate()
					if(!resp) return false;	

					if ( bValid ) {						
							$.ajax({url: 'js/ajax_contacto.php',type: 'POST',async: true,data: $("#frmcontacto").serialize(),dataType:'html',success: procesaRespuesta2});		
						
						$( this ).dialog( "close" );
					}
				},
				"Cancelar": function() {
					$( this ).dialog( "close" );
				}
			},
			close: function() {
				allFields.val( "" ).removeClass( "ui-state-error" );
			}
		});


		$( "#dialog-message" ).dialog({
			autoOpen: false,
			modal: true,
			buttons: {
				Ok: function() {
					$( this ).dialog( "close" );
				}
			}
		});

		$( "#dialog_contact" )
			.click(function() {
				$( "#dialog-form" ).dialog( "open" );
			});
			
	<!-- -->			
	});
	
	
	function procesaRespuesta2(estado) {
		if(estado>0) {
			$("#pDialog").html("El mensaje ha sido enviado correctamente. Muy pronto nos contactaremos con usted.");
			$( "#dialog-message" ).dialog( "option", "buttons", { "Ok": function() {  $(this).dialog("close"); } } );
			$( "#dialog-message" ).dialog( "open" );
		}else {		
			$("#pDialog").html(" Hubo problemas el enviar el mensaje. Intente nuevamente!.");
			$( "#dialog-message" ).dialog( "option", "buttons", { "Ok": function() {  $(this).dialog("close"); } } );
			$( "#dialog-message" ).dialog( "open" );
		}
	
		$("#divRespAjax").show();
		setTimeout(function() {
			$("#divRespAjax").hide();
		}, 5000 );	
		
	}
		

