//objeto regexp para chequeo de correos
var cadenaMail=/^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?$/i;
var utf=/^[a-zA-Z\bÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÑÔÕÖØÙÚÛÜÝÞÑßàáâãäåæçèéêëìíîïðñòóôõöñøùúûüýþñ_]$/;

var cadenaTelefono=/[:0-9:]{3,10}[\. /\)\(-]*[:0-9:]{6,10}/;

//comprueba que la cadena no tenga palabras prohibidas
function contiene_tacos(string)
{
    tacos =  Array(
                    'meada',       'coño',          'tetas',
                    'enculad',     'urinario',      'vagina',
                    'coñazo',      'vibrador',      'jodem',
                    'jodet',        'joder',        'morir',
                    'muere',	'capullo',	'chupam',
                    'xxx',          'puta',		'puto',
                    'cabron',	'ramera',	'mamada',
                    'hdlgp',	'follar',	'maricon',
                    'mamon',	'gilipo',	'follen',
                    'follada',	'subnormal',	'sunormal',
                    'mierda',	'cagada',	'chumino',
                    'picha'
    );
    
    // Chequea palabrotas
    for(i=0; i<tacos.length; i++)
    {
        if(string.toUpperCase().match( tacos[i].toUpperCase()) )
        {
            return true;
        }
    }
    
    // Pasa el test
    return false;
}



//comprueba la longitud de una cadena
function chequeaLongitud(o,min,max) {
      return true;
			if ( o.length > max || o.length < min ) {
				return false;
			} else {
				return true;
			}

		}
	
		
//comprueba que la cadena cumpla el regexp pasado
function chequea(o,regexp) {
			if ( !( regexp.test( o ) ) ) {
				return false;
			} else {
				return true;
			}

		}
		
		
	
		
//es correo sin tacos?
function es_correo(o){
  if(!chequea(o,cadenaMail)){
	  return false;
		}else if(contiene_tacos(o)){
		 return false;
		}else return true;
}		

		
//comprueba la longitud y tacos
function longitud_sin_tacos(o,min,max) {
			if ( o.length > max || o.length < min ) {
				return false;
			} else 
			  if(contiene_tacos(o)){
		 		 		return false;
					}else return true;
		}

//comprueba cadena de numeros (ok)
function es_numero(o,min,max) {
	  var reg= new RegExp("^\\d{"+min+","+max+"}$"); 
				if(!(chequea(o,reg))){
		 		 		return false;
					}else return true;
		}		

//comprueba la longitud ,tacos, alfanumerica (ok)
function alfanumerica_sin_tacos(o,min,max) {
			var reg= new RegExp("^[a-z_A-Z\\d]{"+min+","+max+"}$");
		  if(contiene_tacos(o)){
		 		 		return 'Palabra malsonante';
					}else 
					if(!chequea(o,reg)){
		 		 		return ' Verifica los datos.';
					}else return true;
		}	

//comprueba la longitud ,tacos, texto con acentos y � espacios(\\s) y numeros (\\d) (ok)
function texto_sin_tacos(o,min,max) {
			var reg= new RegExp("^[a-zA-Z\\s\\dÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÑÔÕÖØÙÚÛÜÝÞÑßàáâãäåæçèéêëìíîïðñòóôõöñøùúûüýþñ_]{"+min+","+max+"}$");
				if(contiene_tacos(o)){
		 		 		return false;
					}else 
					if(!chequea(o,reg)){
		 		 		return false;
					}else return true;
		}	
		

/* empleadas en formularios */
/*-------------------------------------------------------*/		
function indicaError(campo,error){
var $elem=$("input[name='"+campo+"']");
var $info=$('#mensaje_form_info');
$elem.addClass('ui-state-error').effect("pulsate",{},100);
$info.text(error).effect("shake",{},500);
$elem.focus();
}	

/* pegote para sustituir a la vieja funcion */
function visor_cuadro1($link,$ancho,$alto) {
        var src = $link;
        var title = "Ver imagen: ";
        var $modal = $('img[src$="'+src+'"]');

	if ($modal.length) {
		$modal.dialog('open')
	} else {
        var img = $('<img alt="'+src+'" width="'+$ancho+'" height="'+$alto+'" style="display:none;padding: 0px;" />')
        .attr('src',src).appendTo('body');
        setTimeout(function() {
          img.dialog({
            title: title,
            width: $ancho+"px",
            modal: true
          });
        }, 1);
        }

      }

function visor_cuadro(cuadro,ancho,alto){
texto='<!DOCTYPE html>';
texto+='<html lang="es" ><head>';
texto+='<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />';
texto+='<meta name="copyright" content="&copy; 2010 cossio.net" />';
texto+='<title>Visor imagenes</title>';
texto+='<link rel="stylesheet" type="text/css" href="http://www.cossio.net/css/cossio.css" />';
texto+='</head><body"><script type="text/javascript">';
texto+='altoimagen='+alto+';';
texto+='anchoimagen='+ancho+';';
texto +="function zoomImagen(valorzoom){";
texto +="im=document.getElementById('idventana');";
texto +="(valorzoom==-2)? alto1='100%' : ((valorzoom !=-1 &&valorzoom!=100)?";
texto +="alto1=String(Math.round(Math.abs(valorzoom)*altoimagen/100))+'px': alto1='auto');";
texto +="(valorzoom==-1)? ancho1='100%' : ((valorzoom !=-2 &&valorzoom!=100)?";
texto +="ancho1=String(Math.round(Math.abs(valorzoom)*anchoimagen/100))+'px': ancho1='auto');";
texto +="im.style.width=ancho1;";
texto +="im.style.height=alto1;";
texto +="return true;}";
texto +="function ajustaDiv(menos){";
texto +="x=document.getElementById('div_central');";
texto +="var ah;";
texto +="if (self.innerHeight) ah = window.innerHeight - menos;";
texto +="else if (document.documentElement && document.documentElement.clientHeight)";
texto +="ah = document.documentElement.clientHeight -menos;";
texto +="else if (document.body)	ah = document.body.clientHeight - menos;";
texto +="x.style.height=ah+'px';";
texto +="}";

texto +="</script>";
texto+='<div class="noticia">';
texto+='<h1 style="text-align:center">';
texto+="<input type = 'button'  value='25%' onclick='zoomImagen(25)'/>";
texto+="<input type = 'button'  value='50%' onclick='zoomImagen(50)'/>";
texto+="<input type = 'button'  value='75%' onclick='zoomImagen(75)'/>";
texto+="<input type = 'button'  value='100%' onclick='zoomImagen(100)'/>";
texto+="<input type = 'button'  value='150%' onclick='zoomImagen(150)'/>";
texto+="<input type = 'button'  value='200%' onclick='zoomImagen(200)'/>";
texto+="<input type = 'button'  value='300%' onclick='zoomImagen(300)'/>";
texto+="<input type = 'button'  value='Ancho' onclick='zoomImagen(-1)'/>";
texto+="<input type = 'button'  value='Alto' onclick='zoomImagen(-2)'/>";
texto+="</h1>";
texto+='<div id="div_central" style="text-align:center;overflow:auto">';
texto+='<img src="'+cuadro+'" alt="" id="idventana" name="idventana"/>';
texto+='</div>';
texto+='</div></body></html>';

 v=window.open("","visor","screenY=0,screenX=0,top=0,left=0,width="+screen.width+",height="+screen.height+", scrollbars,resizable");
v.document.write(texto);
v.document.close();
 }


// empleada para lanzar tinyMCE
editar=function (archivo){
    /* Carga TinyMCE sino lo esta ya */
    if(typeof (tinymce) == "undefined"){
      $.getScript('/tinymce/jscripts/tiny_mce/jquery.tinymce.js',function(){

       //carga opciones de configuración (ahi  esta la variable "config_tinymce")
       if(typeof (config_tinymce) == "undefined"){
       // si no existe config_tinymce lo cargamos y creamos el dialogo
       $.getScript('/tinymce/config/config_tiny_completo.js', function(){
                  config_tinymce.archivo=archivo;
                  //esta linea no necesaria´si usamos setupcontent_callback en config_tiny_completo.js
                  //$('#editorHtml').load("/php/motores/carga_pagina_en_tinymce.php?pagina="+config_tinymce.archivo);
                  $('#editorHtml').tinymce(config_tinymce );
                  $('#dialogo_editor').dialog({
                                          title:'Editando el archivo: '+config_tinymce.archivo,
                                          modal: false,
                                          autoOpen:true,
                                          width:900,
                                          //buttons: { "Cerrar": function() { $(this).dialog("close"); }},
                                          close: function(event, ui) {
                                                       $('#editorHtml').tinymce().remove();
                                                       //$('#editorHtml').tinymce().destroy();
                                                     }
                                          });

     })
    }
      });
    }

    else{
      config_tinymce.archivo=archivo;
      //esta linea no necesaria´si usamos setupcontent_callback en config_tiny_completo.js
      //$('#editorHtml').load("/php/motores/carga_pagina_en_tinymce.php?pagina="+config_tinymce.archivo);
      $('#editorHtml').tinymce(config_tinymce );
      $('#dialogo_editor').dialog('option','title','Editando el archivo: '+config_tinymce.archivo);
      $('#dialogo_editor').dialog('open');
    }
}

function extension(archivo) {
      //recupero la extensión de este nombre de archivo
      file_ext = (archivo.substring(archivo.lastIndexOf(".")+1)).toLowerCase();
      //alert (file_ext);
   return file_ext;
}

/*la emplean los bloques div de clase noticia*/
function verOcultar(obj){
  if(parseInt(obj.parentNode.style.height)== 36)obj.parentNode.style.height="auto";
   else obj.parentNode.style.height="36px";
}

/* muestra - oculta un elemento de la pagina empleada en fisica y quimica antiguas*/
 function verOno(obj){
   if(!document.getElementById(obj))return alert("No existe el elemento: \n"+obj);
	 objeto=document.getElementById(obj);
	 if(objeto.style.display!="none")
	    objeto.style.display="none";
			else{
	        if(document.all) objeto.style.display="block";
			      else{
			           if(objeto.tagName=="TABLE")objeto.style.display="table";
			              else if(objeto.tagName=="TD")objeto.style.display="table-cell";
			                   else if(objeto.tagName=="TR")objeto.style.display="table-row";
			                        else objeto.style.display="block";
			          }
           }
 }
