//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" ).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_contact" )
			.click(function() {
				$( "#dialog-form" ).dialog( "open" );
			});

		$( "#dialog_login" )
			.click(function() {
				$( "#dialog-form2" ).dialog( "open" );
			});			
			
		$( "#dialog_registrar" )
			.click(function() {
				$( "#dialog-form3" ).dialog( "open" );
			});			
			
		var nom = $( "#nom" ),
			ins = $( "#ins" ),
			car = $( "#car" ),
			cel = $( "#cel" ),			
			tel = $( "#tel" ),
			ema = $( "#ema" ),
			log_ = $( "#log_" ),
			pas = $( "#pas" ),
			allFields3 = $( [] ).add( nom ).add( ins ).add( car ).add( cel ).add( tel ).add( ema ).add( log_ ).add( pas );
			
		$( "#dialog-form3" ).dialog({
			autoOpen: false,
			height: 500,
			width: 350,
			modal: true,
			buttons: {
				"Registrar": function() {
					sprylogin.reset()
					sprypassword.reset()
					var bValid = true;

					var resp=sprynom.validate();		
					if(!resp) return false;	
					var resp=spryema.validate();		
					if(!resp) return false;	
					var resp=sprylog.validate();		
					if(!resp) return false;	
					var resp=sprypas.validate();		
					if(!resp) return false;	

					if ( bValid ) {						
							$.ajax({url: 'js/ajax_reg_afiliado.php',type: 'POST',async: true,data: $("#frmregistro").serialize(),dataType:'html',success: procesaRespuesta3});		
						
						$( this ).dialog( "close" );
					}
					

				},
				Cancel: function() {
					$( this ).dialog( "close" );
				}
			},
			close: function() {
				allFields3.val( "" ).removeClass( "ui-state-error" );
			}
		});	
			
	<!-- -->
		var login = $( "#login" ),
			password = $( "#password" ),
			allFields2 = $( [] ).add( login ).add( password ),
			tips2 = $( ".validateTips" );


		$( "#dialog-message" ).dialog({
			autoOpen: false,
			modal: true,
			buttons: {
				Ok: function() {
					$( this ).dialog( "close" );
				}
			}
		});
	
		$( "#dialog-form2" ).dialog({
			autoOpen: false,
			height: 300,
			width: 350,
			modal: true,
			buttons: {
				"Entrar": function() {
					sprylogin.reset()
					sprypassword.reset()
					var bValid = true;

					var resp=sprylogin.validate();		
					if(!resp) return false;	
					var resp=sprypassword.validate();		
					if(!resp) return false;	

					if ( bValid ) {						
							$.ajax({url: 'js/ajax_login.php',type: 'POST',async: true,data: $("#frmlogin").serialize(),dataType:'html',success: procesaRespuesta});		
						
						$( this ).dialog( "close" );
					}
					

				},
				Cancel: function() {
					$( this ).dialog( "close" );
				}
			},
			close: function() {
				allFields2.val( "" ).removeClass( "ui-state-error" );
			}
		});	
	<!-- -->			
	});
	

	
	function procesaRespuesta(estado) {
		if(estado!='no') {
			$("#pDialog").html("Bienvenido al sistema: "+estado)
			$( "#dialog-message" ).dialog( "option", "buttons", { "Ok": function() { $(this).dialog("close"); } } );			
			$( "#dialog-message" ).dialog( "open" );	
			$( "#dialog_login" ).html(" <strong>Bienvenido, "+estado+"</strong> ");
			$( "#dialog_login" ).unbind('click');
			$( "#dialog_login" )
				.click(function() {
					window.location.href='cerrar_sesion.php';
				});			

		}else {
			$("#pDialog").html("El usuario no existe en el sistema. Intente nuevamente");
			sprylogin.reset();	sprypassword.reset();			
			$( "#dialog-message" ).dialog( "option", "buttons", { "Ok": function() { $( "#dialog-form2" ).dialog( "open" ); $(this).dialog("close"); } } );
			$( "#dialog-message" ).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 );	
		
	}

	function procesaRespuesta3(estado) {
		if(estado>0) {
			$("#pDialog").html("Los datos han sido enviados 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 );	
		
	}
		
	function verVideo(id) {
        var valores = 'id='+id;
		$.ajax({url: 'buscarVideo.php',type: 'POST',async: true,data: valores,dataType:'html',success: mostrar});		
	}
    function mostrar(html) {
		$("#multimedianota").html(html);
    }

