/************************************************
   Funções JavaScript FoliaCariocaViagens
   By Leozão
   
************************************************/

    function Formatar(src, mask){
      
	  var i     = src.value.length;
      var saida = mask.substring(0,1);
      var texto = mask.substring(i)
      if (texto.substring(0,1) != saida){
	      src.value += texto.substring(0,1);
      }
    }

/*****************************************************************
      Funcao Verificar
 *****************************************************************/

 function Verificar( obj ){

    var tecla = event.keyCode;

	if ((tecla == 9) || (tecla == 13)){
			 
        if (obj.value == ""){

		     obj.focus();
		     obj.select();
             Erro(obj);
		     event.returnValue = false;
			 return false;
        }
    
	}
 }

/*****************************************************************
      Retorna MSG de erro para determinado campo
 *****************************************************************/

 function Erro(obj){
 
     obj = eval( obj )
     window.alert("Digite ou escolha um valor para o campo " + obj.name);
     obj.setfocus; 
   	 obj.select();
 
 }


/*****************************************************************
      Funcao saida
 *****************************************************************/


function Go(valor){
    window.janela_principal.location.replace(valor);
}

/************************************************
     Função abrir Links
************************************************/	 

function Abre(url, width, height)
{
    window.open(url,"_blank","resizable=yes,toolbar=no,status=no,menubar=no,scrollbars=yes,width=" + width + ",height=" + height)
}

 
 /*****************************************************************
      Roda Imagem
 *****************************************************************/
 
  function roda_imagem2(){
     
     var minutos = new Date('mm')
     var img
	 var x
     
	 img = "";
     img     = "<img src=";
     img     += "fotos/reveillon_2007/fotos/";
	 
     x = minutos % 2

     if (x == 0){
         img    +=  "foto_01.jpg";
     }
     else{
         img    +=  "foto_02.jpg";
     }
		 
		 img    +=  " width=200 height=85>";
		 document.write (img);
	     img    = "";
   		 setTimeout(roda_imagem2(),99999);
	
   }

 /*****************************************************************
      Alterna Imagem
 *****************************************************************/

   function alterna_imagens(){
   
       var xtemp  = 3000
       var Imagem = new Array() 
       Imagem[0]  = 'fotos/reveillon_2007/fotos/foto_01.jpg'
       Imagem[1]  = 'fotos/reveillon_2007/fotos/foto_02.jpg'
       Imagem[2]  = 'fotos/reveillon_2007/fotos/foto_03.jpg'

       var p           = Imagem.length
       var carrega_img = new Array()

       for (i = 0; i < p; i++){
           carrega_img[i] = new Image()
           carrega_img[i].src = Imagem[i]
       }

       var x
       var j = 0
       roda_imagens();
   
   }
 
 /*****************************************************************
      Roda Imagem
 *****************************************************************/

   function roda_imagens(){

       if (document.body){
           document.body.background = Imagem[j];
           j = j + 1

       if (j > (p-1)) j=0
           x = setTimeout('roda_imagens()', xtemp)
       }
   }

 /*****************************************************************
      Verifica o Campo está vazio
 *****************************************************************/

 function Verificar( obj ){

    var tecla = event.keyCode;

	if ((tecla == 9) || (tecla == 13)){
			 
        if (obj.value == ""){

		     obj.focus();
		     obj.select();
             Erro(obj);
		     event.returnValue = false;
			 return false;
        }
    
	}
 }

 /*****************************************************************
      Validacao Email
 *****************************************************************/

 function Verificar_Email( obj ) {

    var tecla = event.keyCode;

	if ((tecla == 9) || (tecla == 13)){

         var email = obj.value;
         if ((email.indexOf("@",0) < 1) || (email.indexOf("@",0) == email.length - 1)) {
             window.alert("O seu e-mail está incorreto!");
	         obj.focus();
	         obj.select();
             return(false);

         }

	 }
 }
 

 /*****************************************************************
      Se estiver tudo Ok, envia o Form
 *****************************************************************/
 
 function Enviar(obj){
  
	    document.obj.submit(); 

 }
 
 /*****************************************************************
      Formata reais
 *****************************************************************/

    function FormataReais(fld, milSep, decSep, e) {

        var sep = 0;
        var key = '';
        var i = j = 0;
        var len = len2 = 0;
        var strCheck = '0123456789';
        var aux = aux2 = '';
        var whichCode = (window.Event) ? e.which : e.keyCode;
        if (whichCode == 13) return true;
        key = String.fromCharCode(whichCode);// Valor para o código da Chave
        if (strCheck.indexOf(key) == -1) return false; // Chave inválida
        len = fld.value.length;
        for(i = 0; i < len; i++)
        if ((fld.value.charAt(i) != '0') && (fld.value.charAt(i) != decSep)) break;
        aux = '';
        for(; i < len; i++)
        if (strCheck.indexOf(fld.value.charAt(i))!=-1) aux += fld.value.charAt(i);
        aux += key;
        len = aux.length;
        if (len == 0) fld.value = '';
        if (len == 1) fld.value = '0'+ decSep + '0' + aux;
        if (len == 2) fld.value = '0'+ decSep + aux;

        if (len > 2) {
           aux2 = '';

        for (j = 0, i = len - 3; i >= 0; i--) {
            if (j == 3) {
               aux2 += milSep;
               j = 0;

            }

            aux2 += aux.charAt(i);
            j++;
        }
        fld.value = '';
        len2 = aux2.length;
        for (i = len2 - 1; i >= 0; i--)
            fld.value += aux2.charAt(i);
            fld.value += decSep + aux.substr(len - 2, len);
        }
        return false;

    }

 /*****************************************************************
      Formata telefone
 *****************************************************************/

function formata_telefone( campo )
{   
    Verificar(campo);
	
	if( !campo ) return true; // caso o campo não exista desconsidera a validação
    var tecla = event.keyCode;
    var p = campo.value;
    var p1 = campo;

    if( ( tecla >= 48 && tecla <= 57  && !event.shiftKey ) || 
        ( tecla >= 96 && tecla <= 105 && !event.shiftKey ) ) {

        if( tecla > 57 )
            event.keyCode = event.keyCode - 48;

    if( p.length == 2 ) {
            pp = p;
            d4 = p.indexOf( '(' );
            d5 = p.indexOf( ')' );
            if( d4 == -1 ) {
                pp = "(" + pp;
            }
            if( d5 == -1 ) {
                pp = pp + ")";
            }
            p1.value = "";
            p1.value = pp;
        }

        if( p.length > 2 ) {
            d1 = p.indexOf( '(' )
            d2 = p.indexOf( ')' )
            if ( d2 == -1 ) {
                p30 = p.length;
                p30 = p.substring( 0, 4 );
                //alert(p30);
                p30 = p30 + ")"
                p31 = p.substring( 4, l30 );
                pp = p30 + p31;
                //alert(p31);
                p1.value = "";
                p1.value = pp;
            }
        }

        if( p.length > 5 ) {
            p11 = p.substring( d1 + 1, d2 );
            if( p11.length > 3 ) {
                p12 = p11;
                l12 = p12.length;
                l15 = p.length;
                //l12=l12-3
                p13 = p11.substring( 0, 3   );
                p14 = p11.substring( 3, l12 );
                p15 =   p.substring( d2 + 1, l15 );
                p1.value = "";
                pp = "(" + p13 + ")" + p14 + p15;
                p1.value = pp;
                //obj1.value="";
                //obj1.value=pp;
            }

            l16 = p.length;
            p16 = p.substring( d2 + 1, l16 );
            l17 = p16.length;
            if( l17 > 3 && p16.indexOf( '-' ) == -1 ) {
                p17 = p.substring( d2 + 1, d2 + 5 );
                p18 = p.substring( d2 + 5, l16 );
                p19 = p.substring( 0, d2 + 1 );
                //alert(p19);
                pp = p19 + p17 + "-" + p18;
                p1.value = "";
                p1.value = pp;
                //obj1.value="";
                //obj1.value=pp;
            }
        }

    }
    else {
        var teclaVolta   = 8;
        var teclaDelete  = 46;
        var teclaTab     = 9;
        var teclaSetaEsq = 37;
        var teclaSetaDir = 39;

        if( tecla != teclaVolta && 
            tecla != teclaDelete && 
            tecla != teclaTab &&
            tecla != teclaSetaDir &&
            tecla != teclaSetaEsq ) 
            event.keyCode = 39;
    }
}




// Formata a hora HH:MM:SS
// onKeyDown="formata_hora( this, event )"
function formata_hora( campo )
{
    if( !campo ) return true; // caso o campo não exista desconsidera a validação
    var tecla = event.keyCode;

    if( ( tecla >= 48 && tecla <= 57  && !event.shiftKey ) || 
        ( tecla >= 96 && tecla <= 105 && !event.shiftKey ) ) {

        if( tecla > 57 )
            event.keyCode = event.keyCode - 48;

        if( campo.value.length == 1 ) {
            campo.value += String.fromCharCode( event.keyCode ) + ':';
            event.keyCode = 39;
        }
    }
    else {
        var teclaVolta   = 8;
        var teclaDelete  = 46;
        var teclaTab     = 9;
        var teclaSetaEsq = 37;
        var teclaSetaDir = 39;

        if( tecla != teclaVolta && 
            tecla != teclaDelete && 
            tecla != teclaTab &&
            tecla != teclaSetaDir &&
            tecla != teclaSetaEsq ) 
            event.keyCode = 39;
    }
}

// Fomatação de números 9999.9999 para visualização - 9.999,9999
	function formata_monetario( valor ) {
				
		var	vr = valor; // campo.value;
		var i = vr.indexOf( "." )
		var	tam = vr.length;
	
		if ( i == -1 ) {
			vr = vr + "00";
			tam = tam + 2;
		}
		
		if ( i == tam - 2 ) {
			vr = vr.replace( ".", "" );
			vr = vr + "0";
		}
		if ( i != -1 ) {
			vr = vr.replace( ".", "" );
			tam = i + 2;
		}
	
		if ( tam <= 2 ) {
			return vr ; 
		}
		if ( (tam > 2) && (tam <= 5) ) {
			return vr.substr( 0, tam - 2 ) + ',' + vr.substr( tam - 2, tam ) ; 
		}
		if ( (tam >= 6) && (tam <= 8) ) {
			return vr.substr( 0, tam - 5 ) + '.' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam ) ; 
		}
		if ( (tam >= 9) && (tam <= 11) ) {
			return vr.substr( 0, tam - 8 ) + '.' + vr.substr( tam - 8, 3 ) + '.' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam ) ; 
		}
		if ( (tam >= 12) && (tam <= 14) ) {
			return vr.substr( 0, tam - 11 ) + '.' + vr.substr( tam - 11, 3 ) + '.' + vr.substr( tam - 8, 3 ) + '.' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam ) ; 
		}
		if ( (tam >= 15) && (tam <= 17) ) {
			return vr.substr( 0, tam - 14 ) + '.' + vr.substr( tam - 14, 3 ) + '.' + vr.substr( tam - 11, 3 ) + '.' + vr.substr( tam - 8, 3 ) + '.' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam ) ;
		}
		return vr;
	}
    

/*****************************************************************
      Altera Opacidade da Imagem
 *****************************************************************/

 function Clarear_Imagem( obj, num ){
     
     obj.style.filter = 'progid:DXImageTransform.Microsoft.Alpha(opacity=' + num + ')';

 }

/*****************************************************************
      Exibir Videos
 *****************************************************************/

 function ExibirVideo(video){
        html = '<object width=370 height=200>';
        html += '<a href=#><param name=movie value=http://www.youtube.com/v/' + video + '/>';
        html += '</param><param name=wmode value=transparent /></param>';
        html += '<embed src=http://www.youtube.com/v/' + video + ' type=application/x-shockwave-flash wmode=transparent width=370 height=200></embed></a>';
        html += '</object>';
        //document.write (html);
        document.divVideo.write(html);
 }

/*****************************************************************
      Exibir Fotos
 *****************************************************************/

	b=0
	function SlideShow(){
	
	pasta = "../../fotos/"
	switch (b){
	case 0:foto.src= pasta + "carnaval2009/foto_23.jpg";
		break;
	case 1:foto.src= pasta + "reveillon2008/foto_93.jpg";
		break;
	case 2:foto.src= pasta + "carnaval2009/foto_05.jpg";
		break;
	case 3:foto.src= pasta + "reveillon2008/foto_34.jpg";
		break;
	case 4:foto.src= pasta + "carnaval2009/foto_02.jpg";
		break;
	case 5:foto.src= pasta + "reveillon2008/foto_116.jpg";
		break;
	case 6:foto.src= pasta + "reveillon2008/foto_56.jpg";
		break;
	case 7:foto.src= pasta + "carnaval2009/foto_01.jpg";
		break;
	case 8:foto.src= pasta + "reveillon2008/foto_10.jpg";
		break;
	case 9:foto.src= pasta + "reveillon2008/foto_98.jpg";
	b=-1;
	}
	b++;
	}
