// PopUp
function OpenWindow(theURL,winName,features) {
  window.open(theURL,winName,features);
}


function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
/* Animação thumbs produtos */
var xm = 0;
var ym = 0;
document.onmousemove = function(e){
	if (window.event) e=window.event;
	xm = e.clientX;
	ym = e.clientY;
}
var panel = {
	speed : .015,
	t : 0,
	O : [],
	over : false,
	run : function() {
		panel.t += panel.speed;
		for (var i = 0, o; o = panel.O[i]; i++)
			o.anim(i + panel.t);
	},
	init : function(){
		for (var i = 0, o; o = document.images[i]; i++){
			if (o.className.indexOf('panel') >= 0) {
				if(o.parentNode.href != undefined) {
					var div = document.createElement("a");
					div.href = o.parentNode.href;
				} else {
					var div = document.createElement("div");
				}
				div.className = 'panel';
				var img = document.createElement("img");
				img.src = o.src;
				img.className = 'imgPanel';
				o.parentNode.replaceChild(div,o);
				div.appendChild(img);
				div.ims = img.style;
				div.iw = img.width;
				div.ih = img.height;
				div.cx = -div.iw / 2;
				div.cy = -div.ih / 2;
				div.anim = function(t) {
					nw = this.offsetWidth;
					nh = this.offsetHeight;
					if (panel.over == this){
						for (var nx = 0, ny = 0, o = this; o != null; o = o.offsetParent) nx += o.offsetLeft, ny += o.offsetTop;
						var x = Math.max(-this.iw + nw, Math.min(0, (-(xm - nx) * (this.iw - nw)) / nw));
						var y = Math.max(-this.ih + nh, Math.min(0, (-(ym - ny) * (this.ih - nh)) / nh));
						if (Math.abs(xm-nx-nw * .5) > nw || Math.abs(ym-ny-nh * .5) > nw ) panel.over = false;
					} else {
						var mx = (this.iw - nw) * .5;
						var my = (this.ih - nh) * .5;
						var x = -mx * (1 + Math.cos(t * 1.2));
						var y = -my * (1 + Math.sin(t));
					}
					this.cx += (x - this.cx) * .1;
					this.cy += (y - this.cy) * .1;
					this.ims.left = Math.round(this.cx) + 'px';
					this.ims.top  = Math.round(this.cy) + 'px';
				}
				div.onmouseover = function(){
					//panel.over = this;
				}
				this.O.push(div);
			}
		}
		setInterval(panel.run, 32);
	}
}
onload = function ()
{
	panel.init();
}
// Função para a formatação dos campos
function Mascara(tipo, campo, teclaPress) {
    if (window.event)
    {
        var tecla = teclaPress.keyCode;
    } else {
        tecla = teclaPress.which;
    }
    var s = new String(campo.value);
    s = s.replace(/(\.|\(|\)|\/|\-| )+/g,'');
    tam = s.length + 1;
    if ( tecla != 9 && tecla != 8 ) {
        switch (tipo){
        case 'CPF' :
            if (tam > 3 && tam < 7)
                campo.value = s.substr(0,3) + '.' + s.substr(3, tam);
            if (tam >= 7 && tam < 10)
                campo.value = s.substr(0,3) + '.' + s.substr(3,3) + '.' + s.substr(6,tam-6);
            if (tam >= 10 && tam < 12)
                campo.value = s.substr(0,3) + '.' + s.substr(3,3) + '.' + s.substr(6,3) + '-' + s.substr(9,tam-9);
        break;
		case 'CNPJ' :
            if (tam > 2 && tam < 6)
                campo.value = s.substr(0,2) + '.' + s.substr(2, tam);
            if (tam >= 6 && tam < 9)
                campo.value = s.substr(0,2) + '.' + s.substr(2,3) + '.' + s.substr(5,tam-5);
            if (tam >= 9 && tam < 13)
                campo.value = s.substr(0,2) + '.' + s.substr(2,3) + '.' + s.substr(5,3) + '/' + s.substr(8,tam-8);
            if (tam >= 13 && tam < 15)
                campo.value = s.substr(0,2) + '.' + s.substr(2,3) + '.' + s.substr(5,3) + '/' + s.substr(8,4)+ '-' + s.substr(12,tam-12);
        break;
		case 'IE' :
            if (tam > 3 && tam < 7)
                campo.value = s.substr(0,3) + '.' + s.substr(3, tam);
            if (tam >= 7 && tam < 10)
                campo.value = s.substr(0,3) + '.' + s.substr(3,3) + '.' + s.substr(6,tam-6);
            if (tam >= 10 && tam < 12)
                campo.value = s.substr(0,3) + '.' + s.substr(3,3) + '.' + s.substr(6,3) + '.' + s.substr(9,tam-9);
        break;
        case 'TEL' :
            if (tam > 2 && tam < 4)
                campo.value = '(' + s.substr(0,2) + ') ' + s.substr(2,tam);
            if (tam >= 7 && tam < 11)
                campo.value = '(' + s.substr(0,2) + ') ' + s.substr(2,4) + '-' + s.substr(6,tam-6);
        break;
        case 'CEP' :
            if (tam > 5 && tam < 7)
                campo.value = s.substr(0,5) + '-' + s.substr(5, tam);
        break;
		case 'DATA' :
            if (tam > 2 && tam < 4)
                campo.value = s.substr(0,2) + '/' + s.substr(2, tam);
            if (tam > 4 && tam < 11)
                campo.value = s.substr(0,2) + '/' + s.substr(2,2) + '/' + s.substr(4,tam-4);
        break;
        }
    }
}
// função para verificar se o valor digitado é número
function digitos(event){
    if (window.event){// IE
        key = event.keyCode;
    } else if ( event.which ) {// netscape
        key = event.which;
    }
    if ( key != 8 || key != 13 || key < 48 || key > 57 )
        return ( ( ( key > 47 ) && ( key < 58 ) ) || ( key == 8 ) || ( key == 13 ) );
    return true;
}
