// functions for swap images

function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}
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_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_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];}
}


//Função que faz o scroll no conteúdo da esquerda (Twitter e Agenda)
var incremento = 40;
var valor_margin_twitter = 0;
var valor_margin_agenda = 0;

function scroll_div(chamada,acao,nome_div)  {
	
	if (chamada =='twitter') {
		if (acao =='desce') {
			valor_margin_twitter = valor_margin_twitter + incremento;
		}  
		else if(acao =='sobe') {
			valor_margin_twitter = valor_margin_twitter - incremento;
		}
		if (valor_margin_twitter < 0) { valor_margin_twitter = 0;}
		document.getElementById(nome_div).style.marginTop = "-" + valor_margin_twitter + "px";

	} else if (chamada =='agenda') {
		if (acao =='desce') {
			valor_margin_agenda = valor_margin_agenda + incremento;
		}  
		else if(acao =='sobe') {
			valor_margin_agenda = valor_margin_agenda - incremento;
		}
		if (valor_margin_agenda < 0) { valor_margin_agenda = 0;}
		document.getElementById(nome_div).style.marginTop = "-" + valor_margin_agenda + "px";
	}

}

//Cadastra no informativo
function add_informe()  {
	if (!document.form1.nome.value)  {
   	     alert("Por favor, informe o nome!");
		 document.form1.nome.focus();
    }
	else if (!document.form1.email.value)  {
         alert("Por favor, informe o email!");
	     document.form1.email.focus();
   }
   else if ((document.form1.email.value.indexOf("@",0))== -1 || 
	  (document.form1.email.value.indexOf("@",0)) < 1 || 
	  (document.form1.email.value.indexOf(".",0))== -1 ||
	  (document.form1.email.value.indexOf("@",0))== document.form1.email.value.length - 1 ||
	  (document.form1.email.value.indexOf(".",0))== document.form1.email.value.length - 1) {
		alert("Formato de e-mail incorreto!");
		document.form1.email.focus();
		document.form1.email.select();
   }  
   else if (!document.form1.estado.value)  {
         alert("Por favor, informe o estado!");
	     document.form1.estado.focus();
   }
   else {
		//Envia o form
  		try{
				xmlhttp = new XMLHttpRequest();
			}catch(ee){
				try{
					xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
				}catch(e){
					try{
						xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
					}catch(E){
						xmlhttp = false;
					}
				}
		}
		url = "http://www.arteccom.com.br/system/usuarios.asp?banco=7&login="+ document.form1.email.value +"&nome="+ document.form1.nome.value +"&uf=" + document.form1.estado.value;
	//	xmlhttp.overrideMimeType('text/html; charset=iso-8859-1');
//		xmlhttp.setRequestHeader("Content-Type", "text/html;charset=iso-8859-1");
		xmlhttp.open("GET", url, true);
		xmlhttp.onreadystatechange=function() {
		    if (xmlhttp.readyState==4) {
				//alert('ok1');
				//document.getElementById("div_return_ajax").innerHTML = xmlhttp.responseText;
				document.getElementById("fundo_cinza").style.display = 'inline';
				document.getElementById("div_return_ajax").style.display = "inline";
					//			alert('ok2');
				//document.body.style.backgroundColor = "#FFFFF0";
			}
		}
	    xmlhttp.send(null);
   }   
   return false;
}

function tamanho_pagina ()  {
	     var xScroll, yScroll;
		
		if (window.innerHeight && window.scrollMaxY) {	
			xScroll = window.innerWidth + window.scrollMaxX;
			yScroll = window.innerHeight + window.scrollMaxY;
		} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
			xScroll = document.body.scrollWidth;
			yScroll = document.body.scrollHeight;
		} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
			xScroll = document.body.offsetWidth;
			yScroll = document.body.offsetHeight;
		}
		
		var windowWidth, windowHeight;
		
		if (self.innerHeight) {	// all except Explorer
			if(document.documentElement.clientWidth){
				windowWidth = document.documentElement.clientWidth; 
			} else {
				windowWidth = self.innerWidth;
			}
			windowHeight = self.innerHeight;
		} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
			windowWidth = document.documentElement.clientWidth;
			windowHeight = document.documentElement.clientHeight;
				
		} else if (document.body) { // other Explorers
			windowWidth = document.body.clientWidth;
			windowHeight = document.body.clientHeight;
		}	
		
		// for small pages with total height less then height of the viewport
		if(yScroll < windowHeight){
			pageHeight = windowHeight;
		} else { 
			pageHeight = yScroll;
		}
	
		// for small pages with total width less then width of the viewport
		if(xScroll < windowWidth){	
			pageWidth = xScroll;		
		} else {
			pageWidth = windowWidth;
		}
		
		return [pageWidth,pageHeight];	
}




//Submenu
var disappeardelay=0  //menu disappear speed onMouseout (in miliseconds)
var enableanchorlink=0 //Enable or disable the anchor link when clicked on? (1=e, 0=d)
var hidemenu_onclick=1 //hide menu when user clicks within menu? (1=yes, 0=no)

var ie5=document.all
var ns6=document.getElementById&&!document.all

function showhide(obj, e, visible, hidden){
if (ie5||ns6)
dropmenuobj.style.left=dropmenuobj.style.top=-500
if (e.type=="click" && obj.visibility==hidden || e.type=="mouseover")
obj.visibility=visible
else if (e.type=="click")
obj.visibility=hidden
}

function iecompattest(){
return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

function dropdownmenu(obj, e, dropmenuID, posX, posY){
if (window.event) event.cancelBubble=true
else if (e.stopPropagation) e.stopPropagation()
if (typeof dropmenuobj!="undefined") //hide previous menu
dropmenuobj.style.visibility="hidden"
clearhidemenu()
if (ie5||ns6){
obj.onmouseout=delayhidemenu
dropmenuobj=document.getElementById(dropmenuID)
if (hidemenu_onclick) dropmenuobj.onclick=function(){dropmenuobj.style.visibility='hidden'}
dropmenuobj.onmouseover=clearhidemenu
dropmenuobj.onmouseout=ie5? function(){ dynamichide(event)} : function(event){ dynamichide(event)}
showhide(dropmenuobj.style, e, "visible", "hidden")
dropmenuobj.style.left = posX + "px"
dropmenuobj.style.top  = posY + "px"
}
return clickreturnvalue()
}

function clickreturnvalue(){
if ((ie5||ns6) && !enableanchorlink) return false
else return true
}

function contains_ns6(a, b) {
while (b.parentNode)
if ((b = b.parentNode) == a)
return true;
return false;
}

function dynamichide(e){
if (ie5&&!dropmenuobj.contains(e.toElement))
delayhidemenu()
else if (ns6&&e.currentTarget!= e.relatedTarget&& !contains_ns6(e.currentTarget, e.relatedTarget))
delayhidemenu()
}

function delayhidemenu(){
delayhide=setTimeout("dropmenuobj.style.visibility='hidden'",disappeardelay)
}

function clearhidemenu(){
if (typeof delayhide!="undefined")
clearTimeout(delayhide)
}
