


function Validate_String(string, return_invalid_chars)
			 {
			 valid_chars = '1234567890-_.^~abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
			 invalid_chars = '';
			 
			 if(string == null || string == '')
				return(true);
			 
			 //For every character on the string.   
			 for(index = 0; index < string.length; index++)
				{
				char = string.substr(index, 1);                        
				
				//Is it a valid character?
				if(valid_chars.indexOf(char) == -1)
				  {
				  //If not, is it already on the list of invalid characters?
				  if(invalid_chars.indexOf(char) == -1)
					{
					//If it's not, add it.
					if(invalid_chars == '')
					   invalid_chars += char;
					else
					   invalid_chars += ', ' + char;
					}
				  }
				}                     
				
			 //If the string does not contain invalid characters, the function will return true.
			 //If it does, it will either return false or a list of the invalid characters used
			 //in the string, depending on the value of the second parameter.
			 if(return_invalid_chars == true && invalid_chars != '')
			   {
			   last_comma = invalid_chars.lastIndexOf(',');
			   
			   if(last_comma != -1)
				  invalid_chars = invalid_chars.substr(0, $last_comma) + 
				  ' and ' + invalid_chars.substr(last_comma + 1, invalid_chars.length);
						  
			   return(invalid_chars);
			   }
			 else
			   return(invalid_chars == ''); 
			 }
	
	
	
	function Validate_Email_Address(email_address)
			 {
			 //Assumes that valid email addresses consist of user_name@domain.tld
			 at = email_address.indexOf('@');
			 var dominio_temp=email_address.substr(at + 1, email_address.length);                  
			 dot = dominio_temp.indexOf('.');
	
			 
			 if(at == -1 || 
				dot == -1 ||
				dot == 0 ||
				dot == email_address.length - 1)
				return(false);
				
			 user_name = email_address.substr(0, at);
			 domain_name = email_address.substr(at + 1, email_address.length);                  
			 
			 if( Validate_String(domain_name) === false)         return(false);                     

			 return(true);
			 }
	
	

function contenido_cargar(url){

	$('#contenido_izquierdo').html("<p align='center'><img src='images/loading.gif' border='0'>Loading.....</p>");
	$('#contenido_izquierdo').load(url);
}

function buscador_avanzado_cargar(){

	$('#buscador_avanzado').html("<p align='center'><img src='images/loading.gif' border='0'>Loading.....</p>");
	$('#buscador_avanzado').load("buscador-avanzado.html");
}

function buscador_avanzado_buscar(){
	$("#header_cargando").show();


    $.get('buscador-avanzado-buscar.html', {cliente: document.getElementById("cmb_buscador_av_tarea_cliente").value,proyecto: document.getElementById("cmb_buscador_av_tarea_proyectos").value,opcion:3,desde:document.getElementById("txt_buscador_av_fecha_desde").value,hasta: document.getElementById("txt_buscador_av_fecha_hasta").value},
    	function(data_1) {
			$("#header_cargando").hide();
			$('#contenido_izquierdo').html(data_1);
    	}
    );

}

function init(){

	// Muestra el form inicial


		//Traigo el pizarron de la oficina
		$('#contenido_izquierdo').html("");
		$('#contenido_izquierdo').html("<p align='center'><img src='images/loading.gif' border='0'>Loading.....</p>");


	    $.get('/oficina-pizarron/', {opcion: 1 },
	    	function(data_1) {
				$('#contenido_izquierdo').html(data_1);
	    	}
	    );


		// Traigo la opcion para crear tareas
	    $.get('/tarea-crear/', {opcion: 1 },
	    	function(data_1) {
				$('#contenido_derecho').html(data_1);
	    	}
	    );

		// Cargo el buscador avanzado
		buscador_avanzado_cargar();

}




function menu_tareas_finalizadas(){

		$('#contenido_izquierdo').html("");
		$('#contenido_izquierdo').html("<p align='center'><img src='images/loading.gif' border='0'>Loading.....</p>");

		$.get('/tareas-finalizadas/', {opcion: 2 },
	    	function(data_1) {
				$('#contenido_izquierdo').html(data_1);
	    	}
	    );

}

function menu_oficinas_cambiar(){
	window.location.href="oficina-cambiar-"+document.getElementById("cmb_menu_oficinas").value+".html";

}

function fila_eliminar(div_id){
//  	$("#"+div_id).slideUp("slow");
  	$("#"+div_id).hide();

}

function reload_page(){
  //Refresca cada "xx" min mediante un scipt para no perder la coneccion con el server
	$('#reload').html("<p align='center'><img src='images/loading.gif' border='0'>Refreshing....</p>");
	$.get('/refresh.html', {opcion: 2 },
    	function(data_1) {
	        //setTimeout("reload_page()", 200000);
	        setTimeout("reload_page()", 150000);

			$('#notificaciones').empty();
			if (data_1 != "") $('#notificaciones').html(data_1);
			$('#reload').empty("");

		}
    );

}

var  upload_div_upload_loading;
var  upload_div_upload;
var  upload_txt_name_origen;
var  upload_txt_name_salida;
var  upload_tipo;

function upload (tipo,div_upload_loading,div_upload,txt_name_origen,txt_name_salida){
	/*
      	div_upload_loading	=> El div q muestra "subiendo archivo..."
		div_upload			=> El div de esa fila en particular
        txt_name			=> <El nombre del txt que hizo el upload
		tipo				=> El tipo de upload

	*/

	//Asigno a las variables glogales
	upload_div_upload_loading = div_upload_loading;
	upload_div_upload		  = div_upload;
	upload_txt_name_origen	  = txt_name_origen;
	upload_txt_name_salida	  = txt_name_salida;
	upload_tipo				  = tipo;


	ajaxFileUpload();

}


function ajaxFileUpload() {

	$("#"+upload_txt_name_origen).hide();
	$("#"+upload_div_upload_loading).show();

	$("#"+upload_div_upload_loading).ajaxStart(function(){
		$(this).show();
		$("#"+upload_txt_name_origen).hide();
		$('#'+upload_div_upload).show();
		$('#'+upload_div_upload).html('<img src="../images/icons/loading_redondo.gif" />');

	})
	.ajaxComplete(function(){
		$(this).hide();
	});

	$.ajaxFileUpload
	(
		{
			url:'ajax/upload.php?tipo=' + upload_tipo + '&txt_name=' +upload_txt_name_origen,
			secureuri:false,
			fileElementId: upload_txt_name_origen,
			dataType: 'html',

			success: function (data, status)
			{

				if (data != undefined) {
						var archivo_vec = data.split("#");
						$('#'+upload_div_upload).show();
						$('#'+upload_div_upload).empty();
						if (archivo_vec[1] != undefined ){
							$('#'+upload_div_upload).html('<img src="../images/icons/clip.gif" /> <strong>' + archivo_vec[1] + '</strong>');
							if (upload_txt_name_salida.lenght>0 )$('#'+upload_txt_name_salida).attr("value", archivo_vec[0]);
						}else{
							$('#'+upload_div_upload).html('<strong>ERROR</strong>'+data);
						}
				}
			},
			error: function (data, status, e)
			{
				alert(e);
			}
		}
	)

	return false;

}


