function frame(pagina){
 var width=817;
 var height=647;
 x = window.screen.width;
 y = window.screen.height;  
 var left = (x/2)-(width/2);
 var top = (y/2)-(height/2);
 janela=window.open(pagina,'Pagina', 'width='+width+', height='+height+', top='+top+', left='+left+', scrollbars=yes, status=no, toolbar=no, location=no, directories=no, menubar=no, resizable=no, fullscreen=no');
 janela.focus();
}

function foco(){ 
 if(document.form){
  document.form.elements[0].focus();
 }
}

function post_produtos(){
 var categoria=document.getElementById('categoria');
 goPage('?page=produtos&categoria='+categoria.value);
}

var bg="#FFFFFF";
var border="#999999";
var bg_erro="#FFFFFF";
var border_erro="#FF1717";

function checa_formulario(){
 var frm=document.form;

 for (var i = 0; i < frm.elements.length; i++){
  if ( (frm.elements[i].title.substr(0,1))=="*"){
	if (TrimString(frm.elements[i].value)==""){
	 alert("O campo é de preenchimento obrigatório!");
	 frm.elements[i].style.backgroundColor=bg_erro;
	 frm.elements[i].style.borderColor=border_erro;
	 frm.elements[i].focus();
	 return false;
	 break;
	}else{
	 frm.elements[i].style.backgroundColor=bg;
	 frm.elements[i].style.borderColor=border;
	}
 }else if ( (frm.elements[i].title.substr(0,1))=="#"){
	if (frm.elements[i].value<=0){
	 alert("O campo é de preenchimento obrigatório!");
	 frm.elements[i].style.backgroundColor=bg_erro;
	 frm.elements[i].style.borderColor=border_erro;
	 frm.elements[i].focus();
	 return false;
	 break;
	}else{
	 frm.elements[i].style.backgroundColor=bg;
	 frm.elements[i].style.borderColor=border;
	}
   }
 }

 var botao=document.getElementById("botao");
 botao.value="AGUARDE...";
 botao.disabled=1;
 setTimeout("document.form.submit()", 100);
  
}//fim checa_formulario

function desmarca(campo){
  if ( campo.title.substr(0,1)=="*"){
	if (TrimString(campo.value)!=""){
	 campo.style.backgroundColor=bg;
	 campo.style.borderColor=border;
	}
 }else if ( (campo.title.substr(0,1))=="#"){
	if (campo.value>0){
	 campo.style.backgroundColor=bg;
	 campo.style.borderColor=border;
	}
 }
}//fim desmarca


function TrimString(sInString) {
  sInString = sInString.replace( /^\s+/g, "" );// strip leading
  return sInString.replace( /\s+$/g, "" );// strip trailing
}

function mudaDiv(id,texto){
  html_div = document.getElementById(id);
  html_div.innerHTML = texto;
}
function removeDiv(id){
 var html_div = document.getElementById(id) || false;
 if(html_div!=false) {
  html_div.style.display='none';
 }
}

function goPage(url){
	window.location.href=url;
}
