/*********************************************************************************************************
				Funcions Generals en JavaScript
						(c)Copy-Raissss!
**********************************************************************************************************/

// Centra la pantalla q s'obre amb un window.open
// Retorna la part dels atributs de posicionament i dimensió de la nova pantalla
function fCentPant(nWidth,nHeight)
{
	var cToolbar = "";
	var nTop = 0, nLeft = 0;

	if (isNaN(nWidth) || isNaN(nHeight))
		return false;

	nTop 	= (screen.height/2) - (nHeight/2);
	nLeft 	= (screen.width/2) - (nWidth/2);

	cToolbar = "left=" + nLeft + "px,top=" + nTop + "px,width=" + nWidth + "px,height=" + nHeight + "px";

	return cToolbar;
}


// Maximitza Pantalla (es carrega al body onload)
function fMaximiza()
{
	window.moveTo(0,0);
	if (document.all)
	{
		top.window.resizeTo(screen.availWidth,screen.availHeight);
	}
	else if (document.layers||document.getElementById)
	{
		if (top.window.outerHeight<screen.availHeight||top.window.outerWidth<screen.availWidth)
		{
			top.window.outerHeight = screen.availHeight;
			top.window.outerWidth = screen.availWidth;
		}
	}
}

function isdate(fecha)
//Determina si un determinado elemento es una fecha, si es así retorna el parametro fecha por
{
 var validchar='1234567890';
 var aux='';
 var dia='';
 var mes='';
 var any='';
 if(fecha.length==0)
  return false;
  if(fecha.length<5)
   {return false;}
   for(nHowMany=0,i=0; i < fecha.length;i++) {
    for(found=0,j=0;j < validchar.length;j++)
     if(fecha.charAt(i)==validchar.charAt(j))
      {found=1; break;}
      if(found==0)
       nHowMany=nHowMany+1;}
   if(nHowMany==2)
    for(i=0,camp=0;i < fecha.length;i++) {
     for(found=0,j=0;j< validchar.length;j++)
      if(fecha.charAt(i)==validchar.charAt(j))
       {found=1; break;}
      if(found==0) {
       aux=aux+'-';
       camp=camp+1;}
      else {
       aux=aux+fecha.charAt(i);
       if(camp==0) dia=dia+fecha.charAt(i);
       if(camp==1) mes=mes+fecha.charAt(i);
       if(camp==2) any=any+fecha.charAt(i);}}
   if((nHowMany==1)&&(fecha.length<7))
    {return false;}
    if((nHowMany==1)&&(fecha.length>=7)&&(fecha.length<=9)){
     for(i=0;i < fecha.length;i++) {
      for(found=0,j=0;j< validchar.length;j++)
       if(fecha.charAt(i)==validchar.charAt(j))
        {found=1; break;}
       if(found==0)
        ara=i;}
      if(ara!=4) return false;
      dia=fecha.charAt(0)+fecha.charAt(1);
      mes=fecha.charAt(2)+fecha.charAt(3);
      for(any='',i=5;i< fecha.length;i++)
       any=any+fecha.charAt(i);}
    if((nHowMany==0)&&((fecha.length==6)||(fecha.length==8))) {
     if(fecha.length==6) {
      dia=fecha.charAt(0)+fecha.charAt(1);
      mes=fecha.charAt(2)+fecha.charAt(3);
      any=fecha.charAt(4)+fecha.charAt(5);}
     if(fecha.length==8) {
      dia=fecha.charAt(0)+fecha.charAt(1);
      mes=fecha.charAt(2)+fecha.charAt(3);
      any=fecha.charAt(4)+fecha.charAt(5)+fecha.charAt(6)+fecha.charAt(7);}}
      if((dia=='')||(mes=='')||(any=='')) {return false;}
      if(dia.length==1) dia='0'+dia;
      if(mes.length==1) mes='0'+mes;
      if(any.length==1) any='199'+any;
      if((any.length==2)&&(any>'70')) any='19'+any;
      if((any.length==2)&&(any<='70')) any='20'+any;
      if((any.length==3)&&(any<'970')) any='2'+any;
      if((any.length==3)&&(any>='970')) any='1'+any;
      if((dia=='00')||(mes=='00')) {return false;}
      if(mes>'12') {return false;}
      if((mes=='01')&&(dia>'31')) return false;
      if((mes=='02')&&(dia>'29')) return false;
      if((mes=='03')&&(dia>'31')) return false;
      if((mes=='04')&&(dia>'30')) return false;
      if((mes=='05')&&(dia>'31')) return false;
      if((mes=='06')&&(dia>'30')) return false;
      if((mes=='07')&&(dia>'31')) return false;
      if((mes=='08')&&(dia>'31')) return false;
      if((mes=='09')&&(dia>'30')) return false;
      if((mes=='10')&&(dia>'31')) return false;
      if((mes=='11')&&(dia>'30')) return false;
      if((mes=='12')&&(dia>'31')) return false;

      return(true);
}


function fFechaBarra(origen,destino)
{
	if (isdate(origen.value))
	{
		// Mirem si la data te 6 digits
		if (origen.value.length == 6)
		{	origen.value = origen.value.substr(0,2) + "/" + origen.value.substr(2,2) + "/" + "20" + origen.value.substr(4,2)
		}
		destino.value=origen.value
		if (origen.name!=destino.name)
		{	destino.focus();
			destino.select();
		}
	}
	else if (origen.value != "")
	{	origen.focus();
		origen.select();
	}
}
