/*
  Funciones en javascript para la página Web
*/


function DateDiff( start, end, interval, rounding ) {
	var iOut = 0;        // Create 2 error messages, 1 for each argument.     
	var startMsg = "Check the Start Date and End Date\n"
	startMsg += "must be a valid date format.\n\n"
	startMsg += "Please try again." ;
	var intervalMsg = "Sorry the dateAdd function only accepts\n"
	intervalMsg += "d, h, m OR s intervals.\n\n"
	intervalMsg += "Please try again." ;
	var bufferA = Date.parse( start ) ;
	var bufferB = Date.parse( end ) ;    	    // check that the start parameter is a valid Date.
	if ( isNaN (bufferA) || isNaN (bufferB) ) {
		//alert( startMsg );
		alert( startMsg + "start: " + start + " end: " + end) ;
		return null ;
	}	    
	// check that an interval parameter was not numeric.
	if ( interval.charAt == 'undefined' ) {
		// the user specified an incorrect interval, handle the error.
		alert( intervalMsg ) ;
		return null ;    
	}
	var number = bufferB-bufferA ;
	// what kind of add to do?
	switch (interval.charAt(0))    {
		case 'd': case 'D':
			iOut = parseInt(number / 86400000) ;
			if(rounding) iOut += parseInt((number % 86400000)/43200001) ;
			break ;
		case 'h': case 'H':
			iOut = parseInt(number / 3600000 ) ;
			if(rounding) iOut += parseInt((number % 3600000)/1800001) ;
			break ;
		case 'm': case 'M':
			iOut = parseInt(number / 60000 ) ;
			if(rounding) iOut += parseInt((number % 60000)/30001) ;
			break ;
		case 's': case 'S':
			iOut = parseInt(number / 1000 ) ;
			if(rounding) iOut += parseInt((number % 1000)/501) ;
			break ;
		default:
			// If we get to here then the interval parameter
			// didn't meet the d,h,m,s criteria.  Handle
			// the error.
			alert(intervalMsg) ;
			return null ;
		}
	return iOut ;
}


function isnumeric(sText)
{
   var ValidChars = "0123456789.";
   var IsNumber=true;
   var Char;

 
   for (i = 0; i < sText.length && IsNumber == true; i++) 
      { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
         IsNumber = false;
         }
      }
   return IsNumber;
   
   }

function escribir(str)
{
	window.aqui.innerHTML=str;
}

function borrar()
{
	window.aqui.innerHTML='';
}

function ident()	
	{
		a = abrir ("/ctav/archivos/identificacion.asp?datos=n");
		
		if (a!="no")
		
			{	window.location.href="/ctav/comun/no_identificado.asp";		}
		else
			{ return a;}
	}

function abrir(str)
{	
   var strFeatures,a;
   	
   strFeatures = "dialogWidth=230px;dialogHeight=120px;";
   strFeatures = strFeatures + "help:no;center:yes;border:thin;status:no;";
   strFeatures = strFeatures + "scrollbars=no;toolbar=no;menubar=yes;";   
   
   a = window.showModalDialog(str,null,strFeatures);     
   
   return a;
}

function formatea_fecha ( fecha )
{
	var f, d, m, y = "", pos1, pos2 = 0;
	if ( fecha != "" )
	{
		pos1 = fecha.indexOf("/",0);
		d = fecha.substring(0,(pos1));
		if ( d.length < 2 ) 
		{
			d = "0" + d;
		};
		pos2 = fecha.indexOf( "/", ( pos1 ) + 1 );
		m = fecha.substring( ( pos1 ) + 1, ( pos2 ) );
		if ( m.length < 2 ) 
		{
			m = "0" + m;
		};
		y = fecha.substring( ( pos2 ) + 1 );
		if ( y.length < 4 ) 
		{
			if ( y > 70 ) 
			{
				y = "19" + y;
			}
			else 
			{
				y = "20" + y;
			};
		};
		f = d + "/" + m + "/" + y;
		return ( f );
	}
	else 
	{
		return (" ");
	}
}
function imprimir(x)
{
	/*---------------------------------------------------------------------------------
		Código para imprimir una página web	    
	---------------------------------------------------------------------------------*/		
    if ( window.quitar_logo && (x!='logo') )
    {		window.quitar_logo.innerHTML=""; 	}
    /*---------------------------------------------------------------------------------
        Imprimir el escudo pequeño, para el detalle de los formularios
    ---------------------------------------------------------------------------------*/		
    if ( window.quitar_logo && (x=='logo') )
    {		window.quitar_logo.innerHTML="<img valign=bottom align=left src=/ctav/imagenes/loguito.jpg  width=328 height=36>"; 	}
	if ( window.quitar_menu )
	{		window.quitar_menu.innerHTML=""; 	}
	
	if ( window.quitar_enlace_superior ) 
	{ 		window.quitar_enlace_superior.innerHTML=""; 	}
	
	if ( window.quitar_enlace_inferior ) 
	{		window.quitar_enlace_inferior.innerHTML=""; 	}	

	if ( window.quitar_imp ) 
	{		window.quitar_imp.innerHTML=""; 	}

	if ( window.quitar_cont ) 
	{		window.quitar_cont.innerHTML=""; 	}

	if ( window.quitar_cont2 ) 
	{		window.quitar_cont2.innerHTML=""; 	}

	if ( window.quitar_cont3 ) 
	{		window.quitar_cont3.innerHTML=""; 	}

	if ( window.quitar_cont4 ) 
	{		window.quitar_cont4.innerHTML=""; 	}

	if ( window.quitar_cont_icaro ) 
	{		window.quitar_cont_icaro.innerHTML="<td width='9px' valign='top'>"; 	}

	
	setTimeout("window.print();window.location.reload();",5000,"Javascript"); 			
}

function nueva_ventana(str, x, y)
{
	var strFeatures;
   	   
   strFeatures = "Width=" + x + "px,Height=" + y + "px,";
   strFeatures = strFeatures + "center:yes,resizable=yes,status:no,";   
   strFeatures = strFeatures + "scrollbars=yes,toolbar=no,menubar=no";   
   
   /*Ventana no modal*/
   window.open(str,null,strFeatures);
}
function ventanita(wintype) { 
ventanita = window.open(wintype,"SmallWin","toolbar=no,directories=no,status=no, scrollbars=no,menubar=no,width=730,height=650"); SmallWin.window.focus() 
}



/*********************************************************************************************
					Funciones para VISADO ELECTRONICO
**********************************************************************************************/
function control_docs(fase)
{
		var a;
//		alert("control_docs.asp?id_fase=" + fase + "&datos=N");
		a = abrir_doc ("control_docs.asp?id_fase=" + fase );
		if (a == "S")		
		{
			window.location.href="consulta_documentos.asp?id_fase=" + fase;
			return true;
		}
		else
		{ 
			return false;
		}
}

function abrir_doc(str)
{	
   var strFeatures,a;
   	
   strFeatures = "dialogWidth:320px;dialogHeight:200px;";
   strFeatures = strFeatures + "help:no;center:yes;border:thin;status:no;";
   strFeatures = strFeatures + "scrollbars:no;toolbar:no;menubar:no;resizable:no";   
   
   a = window.showModalDialog(str,null,strFeatures);     
   
   return a;
}
