/*Manejo de Cookies*/
// les damos 30 d?as de vida a las cookies

function getCookie(nombre){
  var cname = nombre + "=";               
  var dc = document.cookie;             
  if (dc.length > 0) {              
    begin = dc.indexOf(cname);       
    if (begin != -1) {           
      begin += cname.length;       
      end = dc.indexOf(";", begin);
      if (end == -1) end = dc.length;
        return unescape(dc.substring(begin, end));
    } 
  }
  return null;
}

function setCookie(nombre, valor, dias, path, dominio, secure) {
	var caduca = new Date(); 
	caduca.setTime(caduca.getTime() + (dias*24*60*60*1000));	
	document.cookie = nombre + "=" + escape(valor) + 
	((dias == null) ? "" : "; expires=" + caduca.toGMTString()) +
	((path == null) ? "" : "; path=" + path) +
	((dominio == null) ? "" : "; domain=" + dominio) +
	((secure == null) ? "" : "; secure");
}

/*Funcion para actualizar el campo text area con el contenido del editor tyni_MCE
 By Santiago Pérez(rivenvirus@gmail.com) 19 Jul 2007 6:28 pm
*/
	function ActualizarCampo(inst) {
		eval("var Objeto = document.Formulario.elements['"+inst.formTargetElementId+"'];");
		var ContenidoEditor = inst.getBody().innerHTML;
		if(ContenidoEditor == "<br>"){
			ContenidoEditor = "";
		}
		Objeto.value = ContenidoEditor;
		//alert(Objeto.value);
	}
/*Funcion para JQuery By Santiago Pérez*/
	function CambiarNombre(){
		var Args = CambiarNombre.arguments;
		if(Args[1] == undefined){
			Args[1]=Args[0].attr("name")+"[]";
		}
//		alert(Args[0].attr("name"));
//		alert(Args[1]);
		Args[0].attr("name",Args[1]);
	}
	function EsURL(Id,Extra){
		Extra = (Extra==undefined)?"":Extra;
		$('#'+Id).focus(function(){
			if($('#'+Id).val()=="")
				$('#'+Id).val("http://"+Extra);						
		});
		$('#'+Id).blur(function(){
			if($('#'+Id).val()=="http://"+Extra)
				$('#'+Id).val("");						
		});		

	}
	function MostrarOcultarMenu(Id){
		//alert($('#'+Id+' > ul').css('display'));
		if($('#'+Id+' > ul').css('display')=="none"){
			$('#'+Id+' > ul').show('medium')
		}else{
			$('#'+Id+' > ul').hide('medium')
		}
	}
	function IluminarFila(Id){	
		if($("#checkbox_"+Id).attr("checked")!=true){
			$("#"+Id).addClass("highlight_2");
		}


		
	}
	function ClickFila(Id){
		if($("#checkbox_"+Id).attr("checked")==true){
			$("#checkbox_"+Id).attr({checked:false});
			$("#"+Id).removeClass("highlight_2");
		}else{
			$("#checkbox_"+Id).attr({checked:true});
			$("#"+Id).addClass("highlight_2");
		}		
	}
	function MouseOutFila(Id){
		if($("#checkbox_"+Id).attr("checked")!=true){
			$("#"+Id).removeClass("highlight_2");	     			
		}
	};	
///////////////
//Funcion que coloca los nombres de los checkbox marcados en el campo
         //dato.
         
         function MarcarCheckboxes(){
                  var Elemento;
                  for (var i =0; i < document.Formulario.length; i++){
                       Elemento = document.Formulario.elements[i];
                       if (Elemento.type == "checkbox")
                           Elemento.checked=document.Formulario.ChkTodos.checked;
                  }
         }

         function ElementosMarcados(CampoDestino, Tipo){
                  var Elemento;
                  for (var i =0; i < document.Formulario.length; i++){
                       Elemento = document.Formulario.elements[i];
                       if (Elemento.type == Tipo){
                           if (Elemento.checked==true && Elemento.name != 'VarSistemaConservar' && Elemento.name != 'ChkTodos')
                               if (Tipo == 'hidden') {
                                   //alert(Tipo);
                                   CampoDestino.value = CampoDestino.value + Elemento.value.slice(4) + ',';
                               }else{
                                   CampoDestino.value = CampoDestino.value + Elemento.value + ',';
                               }
                       }
                  }
                  if (CampoDestino.value != "")
                      CampoDestino.value = CampoDestino.value.slice(0,-1);
         }


         function PresionarEliminar(){
                  var Campo = document.Formulario.ElementosEliminar;		
				  //alert(Campo);
                  ElementosMarcados(Campo,'checkbox');
				  //alert(Campo.value);
				  $('#TituloMensaje').html('Eliminar Elementos');
                  if (Campo.value != ""){
					  $('#MensajeMensaje').html('Está seguro de querer eliminar los elementos seleccionados');
					  
					  $('#MensajeAreaBotones').html('<input type="button" id="BotonMensajeContinuar"  name="Continuar" value="Cancelar" class="jqmClose" onClick="$(\'#ElementosEliminar\').val(\'\')"><input type="button" id="BotonMensajeContinuar"  name="Continuar" value="Continuar" onClick="document.Formulario.submit();">');
                  }else{
					  $('#MensajeMensaje').html('No ha seleccionado elementos para eliminar');
					  $('#MensajeAreaBotones').html('<input type="button" id="BotonMensajeContinuar"  name="Continuar" value="Continuar para eliminar" class="jqmClose">');					  
                  }
				  $('#dialog').jqm().jqmShow();
         }


         function PresionarEnviarCorreo(){
                  var Campo = document.Formulario.Categorias;
                  ElementosMarcados(Campo,'checkbox');
                  if (Campo.value != ""){
                      if (confirm("Está seguro de querer enviar esta información a las categorías seleccionadas")){
                          document.forms.Formulario.submit();
                      }
                  }else{
                      alert("No ha sido seleccionado ninguna categoría.");
                  }
         }

         function ValidarDescripcion (){
                  var Campo = document.AgregarGrupo.Descripcion;
                  if (Campo.value != ""){
                      document.AgregarGrupo.submit();
                  }else{
                      alert("Ingrese una nombre de grupo para poder continuar.");
                  }
         }
		function OtraBeca(nombre){
			for (var i =0; i < document.Formulario.length; i++){
				Elemento = document.Formulario.elements[i];
				Label = document.Formulario.getElementsByTagName( "label" );
				if(Elemento.name == nombre){
					if(Elemento.value == 'Otros'){	
						Label[0].style.visibility = 'visible';
					}else{					
						Label[0].style.visibility = 'hidden';					
					}
				}
			}
		}
