// Controle dos menus

function getParent(src) {
	while(src.tagName!="DIV") {
		src = src.parentNode;
	}
	return src;
}

Menu = function (src){
	
	var oThis = src;
	var timer;
	
	oThis.onmouseover = function(oEvent){
		clearInterval( timer );
		
		var oEvent = oEvent || window.event;
        var oTarget = oEvent.target || oEvent.srcElement;
		oTarget = getParent(oTarget);
		var obj = oTarget.style;
		//alert(oTarget.tagName + ' '  + oTarget.childNodes.length);

		var y = (oTarget.childNodes.length/2+2)*11;
		
		timer = setInterval( function(){
			var vely = ( y - parseFloat(obj.height) ) / 5;

			obj.height = parseFloat(obj.height) + vely + 'pt';
		
			if ( ( vely <= 0.8 ) ){
				obj.height = y + 'pt';
				clearInterval( timer );
			}
	 	} , 33 , this );
	}
	/*
	oThis.onmouseout = function(oEvent){
		clearInterval( timer );

		var oEvent = oEvent || window.event;
        var oTarget = oEvent.target || oEvent.srcElement;
		oTarget = getParent(oTarget);
		var obj = oTarget.style;
		var y = 25;

		timer = setInterval( function(){
			var vely = ( parseFloat(obj.height) - y ) / 5;

			obj.height = parseFloat(obj.height) - vely + 'pt';
		
			if ( ( vely <= 0.8 ) ){
				obj.height = y + 'pt';
				clearInterval( timer );
			}
	 	} , 33 , this );
	}
	*/
	oThis.onmouseout = function(oEvent){
		clearInterval( timer );

		var oEvent = oEvent || window.event;
        var oTarget = oEvent.target || oEvent.srcElement;
		oTarget = getParent(oTarget);
		var obj = oTarget.style;
		var y = 25;

		timer = setInterval( function(){
			var vely = 0.7;

			obj.height = parseFloat(obj.height) - vely + 'pt';
		
			if ( ( parseInt(obj.height) <= 26) ){
				obj.height = y + 'pt';
				clearInterval( timer );
			}
	 	} , 30 , this );
	}
}


// Controle HotCall cabeçalhos

Scroller = function(src,tempo){

	var browserName=navigator.appName; 
	var start = browserName=="Microsoft Internet Explorer" ? 0 : 1;
	var links = Array();
	
	var max_x = parseInt(src.style.width);
	
	for(i=start; i<src.childNodes.length; i=i+2){
		var label = src.childNodes[i].firstChild.data;
		//document.write('<a href="' + src.childNodes[i].href + '">' + label + '</a>');
		links[(i-start)/2] = '<a href="' + src.childNodes[i].href + '">' + label + '</a>';
	}
	src.innerHTML = '';
	
	// cria o scroller
	var scroller = document.createElement("div");
	scroller.style.width = src.style.width;
	scroller.style.position = 'relative';
	scroller.style.left = '20';
	scroller = src.appendChild(scroller);
	
	var i = 0;
	loop = function(){
		scroller.innerHTML = links[i];
		scrollin(scroller,max_x);
		i = i >= links.length - 1 ? i=0 : i+1;
		setTimeout("loop()",tempo);
	 }
	 loop();

}
function scrollin(src,x){
		
		var obj = src.style;
		obj.left = x;
		
		timer = setInterval( function(){
			var vel = ( parseFloat(obj.left) ) / 10;
			obj.left = parseFloat(obj.left) - vel + 'px';
		
			if ( ( vel <= 0.3 ) ){
				obj.left = 0 + 'px';
				clearInterval( timer );
			}
	 	} , 20 , this );
}


function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);

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_showHideLayers() { //v6.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
    obj.visibility=v; }
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function ContagemPalavras(sentence,idioma,tamanho) {
linguagem = idioma;
totalcaracteres = sentence.length;
	if (linguagem != 'en') {
		if (totalcaracteres > tamanho) {
		alert("Limite seu texto à " + tamanho + " caracteres. Atualmente ele está com " + totalcaracteres + " caracteres.");}
	}
	else if (linguagem == 'en') {
		if (totalcaracteres > tamanho) {
		alert("Limit your text in " + tamanho + " characters. It's already with " + totalcaracteres + " characters.");}
	}
}


function JustSoPicWindow(imageName,imageWidth,imageHeight,alt,bgcolor,hugger,hugMargin) {
// by E Michael Brandt of ValleyWebDesigns.com - Please leave these comments intact.
// version 3.0.4  

	if (bgcolor=="") {
		bgcolor="#FFFFFF";
	}
	var adj=10
	var w = screen.width;
	var h = screen.height;
	var byFactor=1;

	if(w<740){
	  var lift=0.90;
	}
	if(w>=740 & w<835){
	  var lift=0.91;
	}
	if(w>=835){
	  var lift=0.93;
	}
	if (imageWidth>w){	
	  byFactor = w / imageWidth;			
	  imageWidth = w;
	  imageHeight = imageHeight * byFactor;
	}
	if (imageHeight>h-adj){
	  byFactor = h / imageHeight;
	  imageWidth = (imageWidth * byFactor);
	  imageHeight = h; 
	}
	   
	var scrWidth = w-adj;
	var scrHeight = (h*lift)-adj;

	if (imageHeight>scrHeight){
  	  imageHeight=imageHeight*lift;
	  imageWidth=imageWidth*lift;
	}

	var posLeft=0;
	var posTop=0;

	if (hugger == "hug image"){
	  if (hugMargin == ""){
	    hugMargin = 0;
	  }
	  var scrHeightTemp = imageHeight - 0 + 2*hugMargin;
	  if (scrHeightTemp < scrHeight) {
		scrHeight = scrHeightTemp;
	  } 
	  var scrWidthTemp = imageWidth - 0 + 2*hugMargin;
	  if (scrWidthTemp < scrWidth) {
		scrWidth = scrWidthTemp;
	  }
	  
	  if (scrHeight<100){scrHeight=100;}
	  if (scrWidth<100){scrWidth=100;}

	  posTop =  ((h-(scrHeight/lift)-adj)/2);
	  posLeft = ((w-(scrWidth)-adj)/2);
 	}

	if (imageHeight > (h*lift)-adj || imageWidth > w-adj){
		imageHeight=imageHeight-adj;
		imageWidth=imageWidth-adj;
	}
	posTop = parseInt(posTop);
	posLeft = parseInt(posLeft);		
	scrWidth = parseInt(scrWidth); 
	scrHeight = parseInt(scrHeight);
	
	var agt=navigator.userAgent.toLowerCase();
	if (agt.indexOf("opera") != -1){
	  var args= new Array();
	  args[0]='parent';
	  args[1]=imageName;
	  var i ; document.MM_returnValue = false;
	  for (i=0; i<(args.length-1); i+=2) eval(args[i]+".location='"+args[i+1]+"'");
	} else {
	newWindow = window.open("vwd_justso.htm","newWindow","width="+scrWidth+",height="+scrHeight+",left="+posLeft+",top="+posTop);
	newWindow.document.open();
	newWindow.document.write('<html><title>'+alt+'</title><body leftmargin="0" topmargin="0" marginheight="0" marginwidth="0" bgcolor='+bgcolor+' onBlur="self.close()" onClick="self.close()">');  
	newWindow.document.write('<table width='+imageWidth+' border="0" cellspacing="0" cellpadding="0" align="center" height='+scrHeight+' ><tr><td>');
	newWindow.document.write('<img src="'+imageName+'" width='+imageWidth+' height='+imageHeight+' alt="Clique na imagem para fechá-la" >'); 
	newWindow.document.write('</td></tr></table></body></html>');
	newWindow.document.close();
	newWindow.focus();
	}
}

function contador_caracteres(opt_texto_conteudo, opt_contador, opt_maxSize) {
  var texto_conteudo = opt_texto_conteudo ?
    opt_texto_conteudo : "texto_conteudo";
  var contador = opt_contador ? opt_contador : "contador";
  var maxSize = opt_maxSize ? opt_maxSize : 255;
    
  var field = document.getElementById(texto_conteudo);
  if (field && field.value.length >= maxSize) {
    field.value = field.value.substring(0, maxSize);
  }
  var txtField = document.getElementById(contador);
  if (txtField) {  
    txtField.innerHTML = field.value.length;
  }
}

function trocaClass(c1, c2, id) {
    
	var ob = document.getElementById(id);
	
    if(ob.className == c1) {
        ob.className = c2;
    } else {
        ob.className = c1;
    }
    
}

function verificarCPF(c){
	var i; 
	s = c;
	var c = s.substr(0,9); 
	var dv = s.substr(9,2); 
	var d1 = 0; 
	var v = false;
	for (i = 0; i < 9; i++) 
	{ 
	d1 += c.charAt(i)*(10-i); 
	} 
	
	/*if (d1 == 0){ 
		alert("CPF Inválido, digite novamente!")
		v = true; 
		return false; 
	}*/ 
	
	d1 = 11 - (d1 % 11); 
	if (d1 > 9) d1 = 0; 
	if (dv.charAt(0) != d1) 
	{ 
	//alert("CPF Inválido, digite novamente!");
	v = true;
	return false; 
	} 
	
	d1 *= 2; 
	for (i = 0; i < 9; i++) 
	{ 
	d1 += c.charAt(i)*(11-i); 
	} 
	d1 = 11 - (d1 % 11); 
	if (d1 > 9) d1 = 0; 
	if (dv.charAt(1) != d1) 
	{ 
	//alert("CPF Inválido, digite novamente!");
	v = true;
	return false; 
	} 
	if (!v) {
	//alert(c + "\né um CPF Válido!") 
	}
}


function ValidaCNPJ(cnpj) {

	var i = 0;
	var l = 0;
	var strNum = "";
	var strMul = "6543298765432";
	var character = "";
	var iValido = 1;
	var iSoma = 0;
	var strNum_base = "";
	var iLenNum_base = 0;
	var iLenMul = 0;
	var iSoma = 0;
	var strNum_base = 0;
	var iLenNum_base = 0;

	if (cnpj == "") {
		//alert ("Preencha o campo CNPJ.");
  	}
  	else {
		
  		l = cnpj.length;
		for (i = 0; i < l; i++) {
			caracter = cnpj.substring(i,i+1)
		
			if ((caracter >= '0') && (caracter <= '9')) {
		   		strNum = strNum + caracter;
			}
			
		}
		
		if(strNum.length != 14) {
		alert ("CNPJ Inválido, digite novamente!");
		return false; 		
	  	}
		else {
		
			strNum_base = strNum.substring(0,12);
			iLenNum_base = strNum_base.length - 1;
			iLenMul = strMul.length - 1;
			for(i = 0;i < 12; i++)
			iSoma = iSoma +
			        parseInt(strNum_base.substring((iLenNum_base-i),(iLenNum_base-i)+1),10) *
			        parseInt(strMul.substring((iLenMul-i),(iLenMul-i)+1),10);
			
			iSoma = 11 - (iSoma - Math.floor(iSoma/11) * 11);
			if(iSoma == 11 || iSoma == 10)
			iSoma = 0;
			
			strNum_base = strNum_base + iSoma;
			iSoma = 0;
			iLenNum_base = strNum_base.length - 1
			for(i = 0; i < 13; i++)
			iSoma = iSoma +
			        parseInt(strNum_base.substring((iLenNum_base-i),(iLenNum_base-i)+1),10) *
			        parseInt(strMul.substring((iLenMul-i),(iLenMul-i)+1),10)
			
			iSoma = 11 - (iSoma - Math.floor(iSoma/11) * 11);
			if(iSoma == 11 || iSoma == 10)
			iSoma = 0;
			strNum_base = strNum_base + iSoma;
			if(strNum != strNum_base) {
				alert ("CNPJ Inválido, digite novamente!");
				return false; 			
			}
			else {
				//return(cnpj + "\né um CNPJ Válido!");
			}
		}
	}
}



// função que valida CPF
// O algorítimo de validação de CPF é baseado em cálculos
// para o dígito verificador (os dois últimos)
// Não entrarei em detalhes de como funciona
function validaCPF(s) {
	var c = s.substr(0,9);
	var dv = s.substr(9,2);
	var d1 = 0;
	for (var i=0; i<9; i++) {
		d1 += c.charAt(i)*(10-i);
 	}
	if (d1 == 0) return false;
	d1 = 11 - (d1 % 11);
	if (d1 > 9) d1 = 0;
	if (dv.charAt(0) != d1){
		return false;
	}
	d1 *= 2;
	for (var i = 0; i < 9; i++)	{
 		d1 += c.charAt(i)*(11-i);
	}
	d1 = 11 - (d1 % 11);
	if (d1 > 9) d1 = 0;
	if (dv.charAt(1) != d1){
		return false;
	}
    return true;
}


function ValidaCNPJ2(cnpj) {

	var i = 0;
	var l = 0;
	var strNum = "";
	var strMul = "6543298765432";
	var character = "";
	var iValido = 1;
	var iSoma = 0;
	var strNum_base = "";
	var iLenNum_base = 0;
	var iLenMul = 0;
	var iSoma = 0;
	var strNum_base = 0;
	var iLenNum_base = 0;

	if (cnpj == "") {
		//alert ("Preencha o campo CNPJ.");
  	}
  	else {
		
  		l = cnpj.length;
		for (i = 0; i < l; i++) {
			caracter = cnpj.substring(i,i+1)
		
			if ((caracter >= '0') && (caracter <= '9')) {
		   		strNum = strNum + caracter;
			}
			
		}
		
		if(strNum.length != 14) {
		return false; 		
	  	}
		else {
		
			strNum_base = strNum.substring(0,12);
			iLenNum_base = strNum_base.length - 1;
			iLenMul = strMul.length - 1;
			for(i = 0;i < 12; i++)
			iSoma = iSoma +
			        parseInt(strNum_base.substring((iLenNum_base-i),(iLenNum_base-i)+1),10) *
			        parseInt(strMul.substring((iLenMul-i),(iLenMul-i)+1),10);
			
			iSoma = 11 - (iSoma - Math.floor(iSoma/11) * 11);
			if(iSoma == 11 || iSoma == 10)
			iSoma = 0;
			
			strNum_base = strNum_base + iSoma;
			iSoma = 0;
			iLenNum_base = strNum_base.length - 1
			for(i = 0; i < 13; i++)
			iSoma = iSoma +
			        parseInt(strNum_base.substring((iLenNum_base-i),(iLenNum_base-i)+1),10) *
			        parseInt(strMul.substring((iLenMul-i),(iLenMul-i)+1),10)
			
			iSoma = 11 - (iSoma - Math.floor(iSoma/11) * 11);
			if(iSoma == 11 || iSoma == 10)
			iSoma = 0;
			strNum_base = strNum_base + iSoma;
			if(strNum != strNum_base) {
				return false; 			
			}
			else {
				//return(cnpj + "\né um CNPJ Válido!");
			}
		}
	}
}
