var com = com || {};
com.as = com.as || {};

/**
 * @author David Quispert Lazarte.
 * @link david.quispert@altrasoluciones.com
 */
com.as.Formulario = function() {
	this.idDialogForm = "";
	this.textSearchDefault = "";
};

com.as.Formulario.prototype = {
	/**
	 * @param String idButton format #id jquery
	 */
	eventClickForm:function(idButton) {with (this){
		$(idButton).bind('click',function(event) {
			event.preventDefault();
				if (idDialogForm != "") {
					if (!$(idDialogForm).dialog( "isOpen" )) {
						//var width = $(idDialogForm).dialog("option","width");
						var x = $(this).position().left;
					    var y = $(this).position().top - $(document).scrollTop();
					    $(idDialogForm).dialog({ position:[x,y + 84] });
						$(idDialogForm).dialog("open");
						/*$.ajax({
								type:"GET",
								dataType:"html",
								url:"./formularioRegistro.php",
								beforeSend:function(XMLHttpRequest){
									//$("").css("visibility","visible");
									$(idDialogForm).html('<img src="../home/images/blue-loading.gif"  id="loading-1" style="position: absolute;bottom: 50%;left: 40%;" />');	
										
								},
								success: function (data,textStatus,XMLHttpRequest){
									$(idDialogForm).html(data);	
								},
								complete: function (XMLHttpRequest,textStatus){
									//$("").css("visibility","hidden");
								}
						});*/
					} else {
						$(idDialogForm).dialog("close");
					}
				}
			});
	}},
	eventClickSend:function(idButton) {with (this){
		$(idButton).bind('click',function(event) {
			event.preventDefault();
				$.ajax({
								dataType:"json",
								type:"GET",
								url:"./registroDatos.php",
								data:$("#formRegistro").serialize(),
								beforeSend: function(XMLHttpRequest){
									$("#loading").css("display","block");
								},
								success: function(data,textStatus,XMLHttpRequest){
								
									if (textStatus == "success") {
			        						if (data.success === true) {
			        						  $("#dialog-mesage").html('<b style="color: green">'+data.message+'</b>');											
			        						} else{
												$("#dialog-mesage").html('<b style="color: red">'+data.message+'</b>');											
											}
			        					}
								
									//$("#dialog-mesage").html(data.message);	
								},
								complete: function(XMLHttpRequest){
								$("#loading").css("display","none");
								}								
						});
			
			});
	}},
	/**
	 * @param String idDialogForm format #id jquery
	 */
	configureDialogForm:function(idDialogFormSearch){ with(this){
		idDialogForm = idDialogFormSearch;
		$.fx.speeds._default = 500;
		$(idDialogForm).dialog({
			autoOpen: false,
			height: 270,
			width: 335,
			draggable:false,
			resizable:false,
			modal: false,
			show: 'blind',
			hide:'blind',
			buttons: {
				/*"Send": function() {
					
						
						$.ajax({
								dataType:"json",
								type:"GET",
								url:"./registroDatos.php",
								data:$("#formRegistro").serialize(),
								beforeSend: function(XMLHttpRequest){
									$("#loading").css("display","block");
								},
								success: function(data,textStatus,XMLHttpRequest){
								
									if (textStatus == "success") {
			        						if (data.success === true) {
			        						  $("#dialog-mesage").html('<b style="color: green">'+data.message+'</b>');											
			        						} else{
												$("#dialog-mesage").html('<b style="color: red">'+data.message+'</b>');											
											}
			        					}
								
									//$("#dialog-mesage").html(data.message);	
								},
								complete: function(XMLHttpRequest){
								$("#loading").css("display","none");
								}								
						});
						
						
				},*/	
				Close: function() {
					$( this ).dialog( "close" );
				}
			}
		});
		//for hide header
		$(".ui-widget-header").css('display','none');
	}},
	/**
	 * 
	 * @param String idInput format #id jquery
	 * @param String textDefault insertado como texto si el campo esta vacio.
	 * @returns
	 */
	addEventInputFocusInOut:function(idInput,textDefault) {
		this.textSearchDefault = textDefault;
		$(idInput).bind('focusin', function(event) {
				if ($(this).val() == textDefault) {
					$(this).val("");
				}
			});
		$(idInput).bind('focusout', function(event) {
			if ($(this).val() == "") {
				$(this).val(textDefault);
			}
		});
	}
};


