
var IE=((navigator.appName == "Microsoft Internet Explorer") || ((navigator.appName == "Netscape") && (parseInt(navigator.appVersion)==5)));
var NN6=((navigator.appName == "Netscape") && (parseInt(navigator.appVersion)==5));
var NN=((navigator.appName == "Netscape")&&(document.layers));

function getObject(identificador)
{
var aux;
   if (document.layers) aux=document.layers[''+identificador+''];
     else if (document.all) aux=document.all[''+identificador+''];
        else if (document.getElementById) aux=document.getElementById(''+identificador+'');                
return aux;
}
function ventanaSize(w,h)
{
if (document.all) 
	{
		window.resizeTo(w,h);

	}
else if (document.layers||document.getElementById)
	{
	if ( window.outerHeight<screen.availHeight|| window.outerWidth<screen.availWidth)
		{
		 window.outerHeight=h;
		 window.outerWidth = w;
		}
	}

}

function solo_numerico(tecla)
{
if (tecla < 48 || tecla > 57)
{
	return false;
}
else return  true;
}
function añadirfavoritos(url,titulo)
{
if (IE || NN6)
	{
      
      window.external.AddFavorite(url,titulo);
	}	 
else 
	{ 
         alert("Presione Crtl+D para agregar este sitio a sus favoritos"); 
	}
}
function capaVisible(id)
	{
 if (document.layers) document.layers[''+id+''].visibility = "show"
        else if (document.all) document.all[''+id+''].style.visibility = "visible"
        else if (document.getElementById) document.getElementById(''+id+'').style.visibility = "visible"                
    }
function capaInvisible(id)
	{
        if (document.layers) document.layers[''+id+''].visibility = "hide"
        else if (document.all) document.all[''+id+''].style.visibility = "hidden"
        else if (document.getElementById) document.getElementById(''+id+'').style.visibility = "hidden"             

	}
function capaPos(id,x,y,v)
	{
	if(v==0)
		{	
        if (document.layers) document.layers[''+id+''].left = x;
        else if (document.all) document.all[''+id+''].style.left = x;
        else if (document.getElementById) document.getElementById(''+id+'').style.left = x;
    	}
	if(v==1)
		{	
        if (document.layers) document.layers[''+id+''].top=y;
        else if (document.all) document.all[''+id+''].style.top=y;
        else if (document.getElementById) document.getElementById(''+id+'').style.top=y;
		}
	if(v==2)
		{	
        if (document.layers) document.layers[''+id+''].left = x;
        else if (document.all) document.all[''+id+''].style.left = x;
        else if (document.getElementById) document.getElementById(''+id+'').style.left = x;
        if (document.layers) document.layers[''+id+''].top=y;
        else if (document.all) document.all[''+id+''].style.top=y;
        else if (document.getElementById) document.getElementById(''+id+'').style.top=y;
		}
	}
function centraCapa(id,idd,loQue)
	{
	var A,B,C,D;
	if(loQue==1)
		{	
       	if (document.layers){ A=document.layers[''+idd+''].top; C=document.layers[''+id+''].top;}
    	else if (document.all) {A=document.all[''+idd+''].style.top;C=document.all[''+id+''].style.top;}
    	else if (document.getElementById){ A=document.getElementById(''+idd+'').style.top; C=document.getElementById(''+id+'').style.top;}
		capaPos(id,((A-C)/2),0,0);
		}
	else if (loQue==2)
			{
	       	if (document.layers){ A=document.layers[''+idd+''].left; C=document.layers[''+id+''].left;}
    		else if (document.all) {A=document.all[''+idd+''].style.left;C=document.all[''+id+''].style.left;}
    		else if (document.getElementById){ A=document.getElementById(''+idd+'').style.left; C=document.getElementById(''+id+'').style.left;}
			capaPos(id,0,((A-C)/2),1);

			}
		else if (loQue==3)
				{
		       	if (document.layers){ A=document.layers[''+idd+''].left; C=document.layers[''+id+''].left;}
    			else if (document.all) {A=document.all[''+idd+''].style.left;C=document.all[''+id+''].style.left;}
    			else if (document.getElementById){ A=document.getElementById(''+idd+'').style.left; C=document.getElementById(''+id+'').style.left;}
			   	if (document.layers){ B=document.layers[''+idd+''].top; D=document.layers[''+id+''].top;}
    			else if (document.all) {B=document.all[''+idd+''].style.top;D=document.all[''+id+''].style.top;}
    			else if (document.getElementById){ B=document.getElementById(''+idd+'').style.top; D=document.getElementById(''+id+'').style.top;}
				capaPos(id,((A-C)/2),((B-D)/2),2);
				}
	
	}

function testFecha(fecha_aux) {
//var datePat = /^(\d{1,2})(\/|-)(\d{1,2})\2(\d{2}|\d{4})$/;

var datePat = /^(\d{1,2})(\/|-)(\d{1,2})\2(\d{2})$/;

var matchArray = fecha_aux.match(datePat); // is the format ok?
if (matchArray == null) {
//alert("Formato fecha incorrecto.")
return false;
}
month = matchArray[3]; 
day = matchArray[1];
year = matchArray[4];

if (month < 1 || month > 12) { 
//alert("El Valor del mes debe estar situado entre  1 y 12.");
return false;
}
if (day < 1 || day > 31) {
//alert("El Valor del dia debe estar situado entre  1 y 31.");
return false;
}
if ((month==4 || month==6 || month==9 || month==11) && day==31) {
//alert("El mes "+month+" no tiene 31 dias")
return false
}
if (month == 2) { 
var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
if (day>29 || (day==29 && !isleap)) {
alert("Febrero " + year + " no tiene " + day + " dias");
return false;
   }
}
return true;  
}


function solo_numerico(tecla)
{
if (tecla < 48 || tecla > 57)
{
	return false;
}
else return  true;
}

function teclas(tecla,cuadro,decimales,buscar)
{
if(!buscar)
	var buscar=46;//ascii del caracter admitido
if (tecla < 48 || tecla > 57)
	{
	if (tecla==buscar)
		{
		if (cuadro.value.indexOf(String.fromCharCode(buscar))==-1)
			{
			return true;
			}		
		else
			{
			return false;
			}
		}
	else{
		return false;
		}
	}
	else
	{//para solo admitir una vez el caracter 46 (.)
		var aux=cuadro.value.split(String.fromCharCode(buscar));
		var aux_str=aux[1];
		if (aux_str.length>=2)
			{
			 return  false;
			}
		else
			{
			 return  true;
			}
		
	}
}

function testCIF(cif) 
  {
    var aux = cif.toUpperCase(); 
    if (!/^[A-Za-z0-9]{9}$/.test(aux)) 
	return false;
    else if (!/^[ABCDEFGHKLMNPQS]/.test(aux))
	return false;	
    else 
      return true;
  }

  function calculoLetraNIF(DNI)
       {
	     var baremo;
     	     var letraNIF, letras = "TRWAGMYFPDXBNJZSQVHLCKET";
          	baremo = DNI % 23; // equivale a DNI-23*(DNI/23)
        	letraNIF = letras.charAt(baremo);
	     return letraNIF;
         }
 
function testHttpB(urln)
	{
		    h  = urln.charAt(0);
			ht = urln.charAt(1);
			htt = urln.charAt(2);
			http  = urln.charAt(3);
			http_ = urln.charAt(4);
			http__ = urln.charAt(5);
			http___ = urln.charAt(6);
			if ((h == 'h' && ht == 't' && htt== 't' && http == 'p' && http_== ':' && http__== '/' && http___== '/') || (h == 'f' && ht == 't' && htt== 'p' && http == ':')){
			} 
			else
			 { 
			 	return false;
			 }	
	}


function VerificarMail(strMail) 
      {
       // Define la expresion regular para verificar si el email tiene el formato usuario@dominio
        var patMail = /^(.+)@(.+)$/;

       // Define la expresion regular para nombres de usuario validos
        var patUser = /^[a-zA-Z\d_-]+(\.[a-zA-Z\d_-]+)*$/;

       // Define la expresion regular para direccciones IP
        var patDomainIP = /^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/;

       // Define la expresion regular para nombres de dominio validos
        var patDomain = /^[a-zA-Z\d_-]+(\.[a-zA-Z\d_-]+)+$/;

       // Verifica que el string que recibe la funcion sea del tipo string@string y separa los substring
       // correspondientes a usuario y dominio
        var matchArray = strMail.match(patMail);
        if(matchArray == null)
        {
         return false;
        }
        var user = new String(matchArray[1]);
        var domain = new String(matchArray[2]);
      
       // Si el nombre de usuario no es valido la funcion devuelve falso
        if(user.match(patUser) == null) 
        {
         return false;
        }

       // Verifica si el string de dominio corresponde a una direccion IP
       // De ser asi varifica que la ip sea valida.  La funcion devuelve verdadero si la ip es valida y falso si no lo es
        var IPArray = domain.match(patDomainIP);
        if(IPArray != null)
        {
         for (var i=1;i<=4;i++) 
         {
          if(IPArray[i]>255)
          {
           return false;
          }
         }
         return true;
        }

       // Verifica que el string de dominio sea valido.
       // Si es valido verifica que la ultima extension tenga 3 o 4 caracteres de longitud (2 o 3 caracteres mas el punto)
        var domainArray = domain.match(patDomain);
        if(domainArray == null) 
        {
         return false;
        }
        if(domainArray[domainArray.length - 1].length < 3 || domainArray[domainArray.length - 1].length > 4) 
        { 
         return false;
        }

       // Si la funcion no devolvio false entonces el parametro de entrada es una direccion de mail valida
       // Por lo tanto la funcion devuelve true      
        return true;
}
   
function esnumerico(strString)
      {
	 
      var strValidChars = "0123456789E.,-";
      var strChar;
      var blnResult = true;
	  if (strString == ""){
	  	blnResult = false;
	  }
      for (i = 0; i < strString.length && blnResult == true; i++)
        {
        strChar = strString.charAt(i);
        if (strValidChars.indexOf(strChar) == -1)
          {
          blnResult = false;
          }
        }
      return blnResult;
      }

       


// ABREVENTANA



function abreventana(url, name, w, h, perc,scroll) {
        var winX = (screen.availWidth - w)*perc*.01;
        var winY = (screen.availHeight - h)*perc*.01;
        popupWin = window.open(url, name,'toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars='+scroll+',resizable=0,width=' + w + ',height=' + h + ',left=' + winX + ',top=' + winY);
		if ((document.window != null) && (!popupWin.opener)) 
             popupWin.opener = document.window; 
             popupWin.focus(); 

}



// REDIRIGE A LA PÁGINA ANTERIOR CON UN DELAY DE SEGUNDOS
				function redirigeme(){
					var Tiempo = 2; // Número de segundos
					setTimeout("history.go(-1)",Tiempo * 1000);
				}

// RECARGA UNA VENTANA DESDE OTRA

function openURL(sURL) {
   		opener.document.location = sURL;
}

// SACA DE UN THUMBNAIL LA IMAGEN ORIGINAL EN GRANDE

//Thumbnail image viewer- 
//© Dynamic Drive (www.dynamicdrive.com)
//For full source code, usage terms, and 100's more DHTML scripts, visit http://www.dynamicdrive.com


function enlarge(which,e)
{
//Render image code for IE 4+ and NS6
if (ie||ns6)
	{
	crossobj=document.getElementById? document.getElementById("showimage") : document.all.showimage
	if (crossobj.style.visibility=="hidden")
		{
		crossobj.style.left=ns6? pageXOffset+e.clientX : document.body.scrollLeft+event.clientX
		crossobj.style.top=ns6? pageYOffset+e.clientY : document.body.scrollTop+event.clientY
		crossobj.innerHTML='<img src="'+which+'">'
		crossobj.style.visibility="visible"
		}
	else
		crossobj.style.visibility="hidden"
	return false
	}
	//Render image code for NS 4
	else if (document.layers)
	{
	if (document.showimage.visibility=="hide")
		{
		document.showimage.document.write('<a href="#" onMouseover="drag_dropns(showimage)"><img src="'+which+'" border=0></a>')
		document.showimage.document.close()
		document.showimage.left=e.x
		document.showimage.top=e.y
		document.showimage.visibility="show"
		}
		else
		document.showimage.visibility="hide"
	return false
	}
//if NOT IE 4+ or NS 4, simply display image in full browser window
	else
		return true
}


function closepreview()
{
crossobj.style.visibility="hidden"
}

//By Dynamicdrive.com

//drag drop function for NS 4////
/////////////////////////////////

var nsx,nsy,nstemp

function drag_dropns(name){
temp=eval(name)
temp.captureEvents(Event.MOUSEDOWN | Event.MOUSEUP)
temp.onmousedown=gons
temp.onmousemove=dragns
temp.onmouseup=stopns
}

function gons(e){
temp.captureEvents(Event.MOUSEMOVE)
nsx=e.x
nsy=e.y
}
function dragns(e){
temp.moveBy(e.x-nsx,e.y-nsy)
return false
}

function stopns(){
temp.releaseEvents(Event.MOUSEMOVE)
}

//drag drop function for IE 4+ and NS6////
/////////////////////////////////

function drag_drop(e){
if (ie&&dragapproved){
crossobj.style.left=tempx+event.clientX-offsetx
crossobj.style.top=tempy+event.clientY-offsety
}
else if (ns6&&dragapproved){
crossobj.style.left=tempx+e.clientX-offsetx
crossobj.style.top=tempy+e.clientY-offsety
}
return false
}

function initializedrag(e)
{
	if (ie&&event.srcElement.id=="drag"||ns6&&e.target.id=="drag"){
	offsetx=ie? event.clientX : e.clientX
	offsety=ie? event.clientY : e.clientY
	tempx=parseInt(crossobj.style.left)
	tempy=parseInt(crossobj.style.top)
	dragapproved=true
	document.onmousemove=drag_drop
	}
}

document.onmousedown=initializedrag
document.onmouseup=new Function("dragapproved=false")

//-->




