var request = false;

function createRequest() {
	try {
	  request = new XMLHttpRequest();
	} catch (trymicrosoft) {
	  try {
	    request = new ActiveXObject("Msxml2.XMLHTTP");
	  } catch (othermicrosoft) {
	    try {
	      request = new ActiveXObject("Microsoft.XMLHTTP");
	    } catch (failed) {
	      request = false;
	    }
	  }
	}
	
	if (!request)
	  alert("Error initializing XMLHttpRequest!");
}




function toggle_ojo(ojo,que) {
	if (ojo.src.indexOf('img/ojo_cerrado.gif') > -1) {
		ojo.src='img/ojo_abierto.gif';
		ojo.title = que + " VISIBLE";
        ojo.alt = que + "VISIBLE";
	} else {
		ojo.src='img/ojo_cerrado.gif';
		ojo.title = que + " INVISIBLE";
        ojo.alt = que + " INVISIBLE";
	};

}


function removeChildrenFromNode(node)
{
   if(node !== undefined && node !== null)
   {
      return;
   }
   
   var len = node.childNodes.length;
   
	while (node.hasChildNodes())
	{
	  node.removeChild(node.firstChild);
	}
}

function comprobar_formato_codigo(codigo) {

	 
	// our Regular Expression
	var regex=/^[A-Z]{3}[0-9]{3,4}$/;
	 
	// do the comparison, if we have a match
	if (regex.test(codigo))
	{
	      return true;
	}
	else
	{
	      return false;
	}

}

function flecha_dcha (imgFlecha) {
   imgFlecha.src = 'img/flecha_dcha.gif';
   imgFlecha.title = "PULSE PARA DESPLEGAR TABLA";
   imgFlecha.alt = "PULSE PARA DESPLEGAR TABLA";
}

function flecha_abajo(imgFlecha) {
   imgFlecha.src = 'img/flecha_abajo.gif';
   imgFlecha.title = "PULSE PARA PLEGAR TABLA";
   imgFlecha.alt = "PULSE PARA PLEGAR TABLA";
}


function desplegar_cat(cat) {
	createRequest();
     var url = "/admin/desplegar_cat.php?cat=" +  cat;
     // alert(url);
     request.open("GET", url, true);
     //request.onreadystatechange = updatePage;
     request.send(null);
}

function desplegar_anyo(anyo) {
	createRequest();
     var url = "/admin/desplegar_anyo.php?anyo=" +  anyo;
     // alert(url);
     request.open("GET", url, true);
     //request.onreadystatechange = updatePage;
     request.send(null);
}

// www.sean.co.uk

function pausecomp(millis)
{
date = new Date();
var curDate = null;

do { var curDate = new Date(); }
while(curDate-date < millis);
}

function mostrar_thumbnail (capa) {
document.getElementById(capa).style.visibility 	= 'visible';
document.getElementById(capa).style.display 	= 'inline';
}

function ocultar_thumbnail (capa) {
document.getElementById(capa).style.visibility 	= 'hidden';
document.getElementById(capa).style.display 	= 'none';
}

function ocultar_thumbnail_retardada (capa) {
	setTimeout('ocultar_thumbnail(\''+capa+'\')',1250);
}

 function IsValidDate(Day,Mn,Yr){
    var DateVal = Mn + "/" + Day + "/" + Yr;
    var dt = new Date(DateVal);
	//alert('checking Date');
    if(dt.getDate()!=Day){
        //alert('Invalid Date');
        return(false);
        }
    else if(dt.getMonth()!=Mn-1){
    //this is for the purpose JavaScript starts the month from 0
        //alert('Invalid Date');
        return(false);
        }
    else if(dt.getFullYear()!=Yr){
        //alert('Invalid Date');
        return(false);
        }
        
    return(true);
 }
 
function framePrint(whichFrame,id){
	//Detect IE5.5+
/*version=0
if (navigator.appVersion.indexOf("MSIE")!=-1){
temp=navigator.appVersion.split("MSIE")
version=parseFloat(temp[1])
}*/

	
if ( !whichFrame ) whichFrame = window;	
/*
if ((version>=5.5) && (version < 7)){  //NON IE browser will return 0
//alert("You're using IE "+version) 
//alert(id)

abrirVentana(''+id , 'Ficha imprimible' , '620','450');
} else {*/
	whichFrame.focus();
	whichFrame.print();
//}
}