/*  
Padawan's JavaScript-Mega-Validator 3000+  
Todos os direitos reservados para Diego Pires Plentz  
Você pode usar esse código nas suas páginas desde que mantenha os créditos ;-)  
*/   
  
function Verifica_Email(email, obrigatorio){   
//Se o parâmetro obrigatório for igual à zero, significa que elepode estar vazio, caso contrário, não   
    var email = document.getElementById(email);   
    if((obrigatorio == 1) || (obrigatorio == 0 && email.value != "")){   
        if(!email.value.match(/([a-zA-Z0-9._-]+@[a-zA-Z0-9._-]+.[a-zA-Z0-9._-]+)/gi)){   
            alert("Informe um e-mail válido");   
            email.focus();   
            return false   
        }   
    }   
}   
  
function Verifica_Cep(cep, obrigatorio){   
//Se o parâmetro obrigatório for igual à zero, significa que elepode estar vazio, caso contrário, não   
    var cep    = document.getElementById(cep);   
    var strcep = cep.value;   
    if((obrigatorio == 1) || (obrigatorio == 0 && strcep != "")){   
        if (strcep.length != 9){   
            alert("CEP informado inválido.");   
            cep.focus();   
            return false   
        }else{   
            if (strcep.indexOf("-") != 5){   
                alert("Formato de CEP informado inválido.");   
                cep.focus();   
                return false   
            }else{   
                if (isNaN(strcep.replace("-","0"))){   
                    alert("CEP informado inválido.");   
                    cep.focus();   
                    return false   
                }   
            }   
        }   
    }       
}   
  
function formatar(src, mask){ 
//Formata para os diversos tipos
/*
CNPJ - OnKeyPress="formatar(this, '##.###.###/####-##')"
CPF - OnKeyPress="formatar(this, '###.###.###-##')"
DATA - OnKeyPress="formatar(this, '##/##/####')"
*/
    if (SoNumeros(src) == true) { 
       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);
       }
    }
}

function currencyFormat(fld, milSep, decSep, e){
//Formata o campo numerico
//onKeyPress="return(currencyFormat(this,'.',',',event));" 
//onKeyPress="return(currencyFormat(this,',','.',event));"
  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;  // Enter
  if (whichCode == 8) return true;  // Delete
  key = String.fromCharCode(whichCode);  // Get key value from key code
  if (strCheck.indexOf(key) == -1) return false;  // Not a valid key
  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;
}

function SoNumeros(e){
//Permite somente numeros
/*
onKeyPress="return Tecla(event);"
*/
 if (document.all) // Internet Explorer
  var tecla = event.keyCode;
 else if(document.layers) // Nestcape
  var tecla = e.which;
  if (tecla > 47 && tecla < 58 ) // numeros de 0 a 9
   return true;
  else
   {
    if (tecla != 8) // backspace
     event.keyCode = 0;
     //return false;
    else
     return true;
   }
}	

function AbrirFotoMembros(foto,quantidade)
{
    parent.AbrirPopupFotos(foto,quantidade,"Membros","OpalaClubeRJ.Com.Br",550,550);
}

function AbrirFotoEventos(foto,quantidade)
{
    parent.AbrirPopupFotos(foto,quantidade,"Eventos","OpalaClubeRJ.Com.Br",550,550);
}


//Centraliza a popup de fotos na página
function AbrirPopupFotos(foto,quantidade,tipo,titulo,largura,altura) {

var w = 800, h = 600;

if (document.all || document.layers) {
   w = screen.availWidth;
   h = screen.availHeight;
}

var popW = largura, popH = altura;
var leftPos = (w-popW)/2, topPos = (h-popH)/2;
	
window.open('../ver_foto.asp?foto=' + foto + '&quantidade=' + quantidade + '&tipo=' + tipo,'Opala','width=' + popW + ',height=' + popH + ',top=' + topPos + ',left=' + leftPos + ',toolbar=0,status=0,menubar=0,scrollbars=0,directories=0');
}


//Centraliza o popup na página
function AbrirPopUp(url,ww,hh,nome) {

var w = 800, h = 600;

if (document.all || document.layers) {
   w = screen.availWidth;
   h = screen.availHeight;
}

var popW = ww, popH = hh;
var leftPos = (w-popW)/2, topPos = (h-popH)/2;
	
window.open(''+url+'',''+nome+'','width=' + popW + ',height=' + popH + ',top=' + topPos + ',left=' + leftPos + ',toolbar=0,status=0,menubar=0,scrollbars=0,directories=0');

}
          
     
    var fadeimages=new Array()
    //SET IMAGE PATHS. Extend or contract array as needed
    fadeimages[0]=["imagens/boutique/1.jpg", "boutique/produtos.asp", ""]
    fadeimages[1]=["imagens/boutique/2.jpg", "boutique/produtos.asp", ""]
    fadeimages[2]=["imagens/boutique/3.jpg", "boutique/produtos.asp", ""]
    fadeimages[3]=["imagens/boutique/4.jpg", "boutique/produtos.asp", ""]
    fadeimages[4]=["imagens/boutique/5.jpg", "boutique/produtos.asp", ""]
    fadeimages[5]=["imagens/boutique/6.jpg", "boutique/produtos.asp", ""]
    fadeimages[6]=["imagens/boutique/7.jpg", "boutique/produtos.asp", ""]
    fadeimages[7]=["imagens/boutique/8.jpg", "boutique/produtos.asp", ""]

    var fadebgcolor="#COCOCO"

    ////NO need to edit beyond here/////////////
     
    var fadearray=new Array() //array to cache fadeshow instances
    var fadeclear=new Array() //array to cache corresponding clearinterval pointers
     
    var dom=(document.getElementById) //modern dom browsers
    var iebrowser=document.all
     
    function fadeshow(theimages, fadewidth, fadeheight, borderwidth, delay, pause, displayorder){
    this.pausecheck=pause
    this.mouseovercheck=0
    this.delay=delay
    this.degree=10 //initial opacity degree (10%)
    this.curimageindex=0
    this.nextimageindex=1
    fadearray[fadearray.length]=this
    this.slideshowid=fadearray.length-1
    this.canvasbase="canvas"+this.slideshowid
    this.curcanvas=this.canvasbase+"_0"
    if (typeof displayorder!="undefined")
    theimages.sort(function() {return 0.5 - Math.random();}) //thanks to Mike (aka Mwinter) :)
    this.theimages=theimages
    this.imageborder=parseInt(borderwidth)
    this.postimages=new Array() //preload images
    for (p=0;p<theimages.length;p++){
    this.postimages[p]=new Image()
    this.postimages[p].src=theimages[p][0]
    }
     
    var fadewidth=fadewidth+this.imageborder*2
    var fadeheight=fadeheight+this.imageborder*2
     
    if (iebrowser&&dom||dom) //if IE5+ or modern browsers (ie: Firefox)
    document.write('<div id="master'+this.slideshowid+'" style="position:relative;width:'+fadewidth+'px;height:'+fadeheight+'px;overflow:hidden;"><div id="'+this.canvasbase+'_0" style="position:absolute;width:'+fadewidth+'px;height:'+fadeheight+'px;top:0;left:0;filter:progid:DXImageTransform.Microsoft.alpha(opacity=10);opacity:0.1;-moz-opacity:0.1;-khtml-opacity:0.1;background-color:'+fadebgcolor+'"></div><div id="'+this.canvasbase+'_1" style="position:absolute;width:'+fadewidth+'px;height:'+fadeheight+'px;top:0;left:0;filter:progid:DXImageTransform.Microsoft.alpha(opacity=10);opacity:0.1;-moz-opacity:0.1;-khtml-opacity:0.1;background-color:'+fadebgcolor+'"></div></div>')
    else
    document.write('<div><img name="defaultslide'+this.slideshowid+'" src="'+this.postimages[0].src+'"></div>')
     
    if (iebrowser&&dom||dom) //if IE5+ or modern browsers such as Firefox
    this.startit()
    else{
    this.curimageindex++
    setInterval("fadearray["+this.slideshowid+"].rotateimage()", this.delay)
    }
    }

    function fadepic(obj){
    if (obj.degree<100){
    obj.degree+=10
    if (obj.tempobj.filters&&obj.tempobj.filters[0]){
    if (typeof obj.tempobj.filters[0].opacity=="number") //if IE6+
    obj.tempobj.filters[0].opacity=obj.degree
    else //else if IE5.5-
    obj.tempobj.style.filter="alpha(opacity="+obj.degree+")"
    }
    else if (obj.tempobj.style.MozOpacity)
    obj.tempobj.style.MozOpacity=obj.degree/101
    else if (obj.tempobj.style.KhtmlOpacity)
    obj.tempobj.style.KhtmlOpacity=obj.degree/100
    else if (obj.tempobj.style.opacity&&!obj.tempobj.filters)
    obj.tempobj.style.opacity=obj.degree/101
    }
    else{
    clearInterval(fadeclear[obj.slideshowid])
    obj.nextcanvas=(obj.curcanvas==obj.canvasbase+"_0")? obj.canvasbase+"_0" : obj.canvasbase+"_1"
    obj.tempobj=iebrowser? iebrowser[obj.nextcanvas] : document.getElementById(obj.nextcanvas)
    obj.populateslide(obj.tempobj, obj.nextimageindex)
    obj.nextimageindex=(obj.nextimageindex<obj.postimages.length-1)? obj.nextimageindex+1 : 0
    setTimeout("fadearray["+obj.slideshowid+"].rotateimage()", obj.delay)
    }
    }
     
    fadeshow.prototype.populateslide=function(picobj, picindex){
    var slideHTML=""
    if (this.theimages[picindex][1]!="") //if associated link exists for image
    slideHTML='<a href="'+this.theimages[picindex][1]+'" target="'+this.theimages[picindex][2]+'">'
    slideHTML+='<img src="'+this.postimages[picindex].src+'" border="'+this.imageborder+'px">'
    if (this.theimages[picindex][1]!="") //if associated link exists for image
    slideHTML+='</a>'
    picobj.innerHTML=slideHTML
    }
     
     
    fadeshow.prototype.rotateimage=function(){
    if (this.pausecheck==1) //if pause onMouseover enabled, cache object
    var cacheobj=this
    if (this.mouseovercheck==1)
    setTimeout(function(){cacheobj.rotateimage()}, 100)
    else if (iebrowser&&dom||dom){
    this.resetit()
    var crossobj=this.tempobj=iebrowser? iebrowser[this.curcanvas] : document.getElementById(this.curcanvas)
    crossobj.style.zIndex++
    fadeclear[this.slideshowid]=setInterval("fadepic(fadearray["+this.slideshowid+"])",50)
    this.curcanvas=(this.curcanvas==this.canvasbase+"_0")? this.canvasbase+"_1" : this.canvasbase+"_0"
    }
    else{
    var ns4imgobj=document.images['defaultslide'+this.slideshowid]
    ns4imgobj.src=this.postimages[this.curimageindex].src
    }
    this.curimageindex=(this.curimageindex<this.postimages.length-1)? this.curimageindex+1 : 0
    }
     
    fadeshow.prototype.resetit=function(){
    this.degree=10
    var crossobj=iebrowser? iebrowser[this.curcanvas] : document.getElementById(this.curcanvas)
    if (crossobj.filters&&crossobj.filters[0]){
    if (typeof crossobj.filters[0].opacity=="number") //if IE6+
    crossobj.filters(0).opacity=this.degree
    else //else if IE5.5-
    crossobj.style.filter="alpha(opacity="+this.degree+")"
    }
    else if (crossobj.style.MozOpacity)
    crossobj.style.MozOpacity=this.degree/101
    else if (crossobj.style.KhtmlOpacity)
    crossobj.style.KhtmlOpacity=this.degree/100
    else if (crossobj.style.opacity&&!crossobj.filters)
    crossobj.style.opacity=this.degree/101
    }
     
     
    fadeshow.prototype.startit=function(){
    var crossobj=iebrowser? iebrowser[this.curcanvas] : document.getElementById(this.curcanvas)
    this.populateslide(crossobj, this.curimageindex)
    if (this.pausecheck==1){ //IF SLIDESHOW SHOULD PAUSE ONMOUSEOVER
    var cacheobj=this
    var crossobjcontainer=iebrowser? iebrowser["master"+this.slideshowid] : document.getElementById("master"+this.slideshowid)
    crossobjcontainer.onmouseover=function(){cacheobj.mouseovercheck=1}
    crossobjcontainer.onmouseout=function(){cacheobj.mouseovercheck=0}
    }
    this.rotateimage()
    }

