

var numbr=1;
var tipo="Appear";
var randprodDest;
var prodDest=new Array();
function randomProd(){


randprodDest = self.setInterval(function (){

if(numbr!=prodDest.length-1){
  numbr++;
}else{
  numbr=1;
}






Effect.Appear("blcProdDest", { duration: 4.0,from:1,to:1,afterFinishInternal:function (){Effect.Fade("blcProdDest", { duration: 4.0,from:1,to:1});}});




muda_img(prodDest[numbr],numbr);
},"8000");
}

function muda_img(id,pos){


window.clearInterval(randprodDest);
numbr=pos;

var obj = document.getElementById("blcProdDest");

var serverPage ="prodDestaque2.php";
var params = "id="+id+"&pos="+pos;


xmlhttp.open("GET",serverPage+"?"+params);
xmlhttp.onreadystatechange = function() {
if(xmlhttp.readyState == 1) {
  obj.innerHTML="<div style='width:466px;height:234px;' align='center' valign='middle'><img src='./sysimages/ajax-loader.gif' border='0' style='margin-top:100px;'></div>";
}else if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
  obj.innerHTML = xmlhttp.responseText;
  randomProd();
}
}
xmlhttp.send(null);
}


function verifica_pesq(form) {

var form = document.getElementById(form);


var txt=form.valor_pesq;
var texto = txt.value;
var error;

  if((txt.value=="") || (txt.value==unescape(json[351]))){
      alert(unescape(json[352]));
      error=1;
  }else if(txt.value!="" &&  texto.length<3){
      alert(unescape(json[353]));
      error=2;
      //return false;
  }

  if((txt.value!=unescape(json[351])) && (texto.value!="") && (texto.length>=3)){
     error=0;
     //document.getElementById(form).submit();
      
  }
  
  if(error>0){
    return false;
  }else {
    return document.getElementById(form).submit();
  }
  
  
}

function mudaMetodoPagamento(id){


for(i=1;i<onmouseMP1.length;i++){
    var objMP = document.getElementById("tdMP" + i);
    var objDP = document.getElementById("detalhePagamento" + i);
    if(objMP!=null){
       document.getElementById('pagamento' + i ).src="sysimages/imgtransp.png";
       if(objDP!=null){
       document.getElementById('detalhePagamento' + i ).style.display='none';
       }
       objMP.onmouseout=onmouseMP2[i];
       objMP.onmouseover=onmouseMP1[i];
    }
}

if(document.getElementById('detalhePagamento' + id )!=null){
document.getElementById('detalhePagamento' + id ).style.display='';
}
document.getElementById("tdMP" + id).onmouseout=onmouseMP1[id];
document.getElementById('pagamento' + id ).src="sysimages/opselect.jpg";
document.getElementById('pagamentoCHK' + id ).checked=true;
//var obj = document.getElementById("actualiza_carrinho2");
var serverPage ="actualizaMP.php";
var params = "id="+id;


xmlhttp.open("GET",serverPage+"?"+params);
xmlhttp.onreadystatechange = function() {
if(xmlhttp.readyState == 1){
  //obj.innerHTML="<div style='width:647px;height:300px;border:0px solid red;padding-top:250px;' align='center'><img src='./sysimages/ajax-loader.gif' border='0' ></div>";
}else if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
  //obj.innerHTML = xmlhttp.responseText;
}
}
xmlhttp.send(null);
}
var crt=0;
function actualiza_carrinho(tipo){

if(tipo==0){
 var obj = document.getElementById("actualiza_carrinho1");
}else if(tipo==1){
 var obj = document.getElementById("actualiza_carrinho2");
}


var serverPage ="actualiza_carrinho.php";
var params = "tipo="+tipo;

if(crt==1){
  params = params+"&crt=1";
}

xmlhttp.open("GET",serverPage+"?"+params);
xmlhttp.onreadystatechange = function() {
if(xmlhttp.readyState == 1){
  //obj.innerHTML="<div style='width:647px;height:300px;border:0px solid red;padding-top:250px;' align='center'><img src='./sysimages/ajax-loader.gif' border='0' ></div>";
}else if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
  obj.innerHTML = xmlhttp.responseText;
}
}
xmlhttp.send(null);
}
function carrinho_multiple(prodID,Qt,action){
if (xmlhttp)
{
// tenta estabelecer ligação
try
{
///------------------inicio-----------------------


var serverPage="carrinho_actions.php";


var prod_id = prodID;
var params = "action="+action+"&prod_id="+prodID+"&qt="+Qt;

xmlhttp.open("POST", serverPage,true);

//Send the proper header information along with the request
xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xmlhttp.setRequestHeader("Content-length", params.length);
xmlhttp.setRequestHeader("Connection", "close");

xmlhttp.onreadystatechange = function() {//Chama a função quando o estado mudar
if(xmlhttp.readyState == 1 ) {
//showHideIndicator(true);
}else if(xmlhttp.readyState == 4 && xmlhttp.status == 200) {


  if(xmlhttp.responseText){
      var obj = document.getElementById("info_carrinho");
      obj.innerHTML = xmlhttp.responseText;
      if(document.getElementById("infoCart")!=null){
      document.getElementById("infoCart").style.display='';
      }
      new Effect.Pulsate(document.getElementById("info_carrinho"),{duration: 5.0,pulses:5});
      if(document.getElementById("info_carrinho2")!=null){
      new Effect.Pulsate(document.getElementById("info_carrinho2"),{duration: 5.0,pulses:5});
      }
      alert(unescape(json[298]));
  }
}
}
xmlhttp.send(params);
}
//--------------------fim do bloco try-----------------------
  

  // mostra mensagem em caso de erro
  catch (e)
    {
      alert("Não foi possivel adicionar ao carrinho:\n" + e.toString());
    }
  }
}
//Função de carrinho de compras
function carrinho(prodID,Qt,action){
if (xmlhttp)
{
// tenta estabelecer ligação
try
{
///------------------inicio-----------------------


var serverPage="carrinho_actions.php";
//var obj = document.getElementById(objID);

var prod_id = prodID;
if(Qt!="0" && action!='remove'){
  var qt = document.getElementById("qt_carrinho").value;
}else {
  var qt=0;
}

var params = "action="+action+"&prod_id="+prodID+"&qt="+qt;

xmlhttp.open("POST", serverPage,true);

//Send the proper header information along with the request
xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xmlhttp.setRequestHeader("Content-length", params.length);
xmlhttp.setRequestHeader("Connection", "close");

xmlhttp.onreadystatechange = function() {//Chama a função quando o estado mudar
if(xmlhttp.readyState == 1 ) {
//showHideIndicator(true);
}else if(xmlhttp.readyState == 4 && xmlhttp.status == 200) {


  if(xmlhttp.responseText){
      var obj = document.getElementById("info_carrinho");
      obj.innerHTML = xmlhttp.responseText;
      if(document.getElementById("infoCart")!=null){
      document.getElementById("infoCart").style.display='';
      }
      new Effect.Pulsate(document.getElementById("info_carrinho"),{duration: 5.0,pulses:5});
      if(document.getElementById("info_carrinho2")!=null){
      new Effect.Pulsate(document.getElementById("info_carrinho2"),{duration: 5.0,pulses:5});
      }
      
      if(action=="add" && qt!=0){
      alert(unescape(json[298]));
      }else if(action=="remove" || qt==0){
      alert(unescape(json[309]));
      window.location='index.php?id=104';
      }
      
  }
}
}
xmlhttp.send(params);
}
//--------------------fim do bloco try-----------------------
  

  // mostra mensagem em caso de erro
  catch (e)
    {
      alert("Não foi possivel adicionar ao carrinho:\n" + e.toString());
    }
  }
}

var OBJ;
var total;
var elem = new Array();
 function formErros(obj)
{
OBJ=obj;
total=obj.length;
 
var frmObj=OBJ.form;
objID=obj.id;
 
  
 elem = frmObj.elements;
 
  for(i = 0; i < elem.length; i++){
  
  if(elem[i].id==objID){
    //document.getElementById(objID).style.borderColor="#B40812";
    document.getElementById(objID).style.backgroundColor = "#F7F5EF";
		document.getElementById(objID).style.color  = '#F2A816';
		document.getElementById(objID).value = unescape(json[282]);
  }else {
    if(elem[i].type!="submit"){
    elem[i].style.color  = '#707052';
		elem[i].style.backgroundColor = "#FFFFFF";
		}
  }
  
  }
}

var elem = new Array();
 function formErros2(obj)
{
OBJ=obj;
total=obj.length;
 
var frmObj=OBJ.form;
objID=obj.id;
 
  
 elem = frmObj.elements;
 
  for(i = 0; i < elem.length; i++){
  
  if(elem[i].id==objID){
    //document.getElementById(objID).style.borderColor="#B40812";
    document.getElementById(objID).style.backgroundColor = "#F7F5EF";
		document.getElementById(objID).style.color  = '#F2A816';
		//alert(unescape(json[370]));
  }else {
    if(elem[i].type!="submit"){
    elem[i].style.color  = '#707052';
		elem[i].style.backgroundColor = "#FFFFFF";
		}
  }
  
  }
}
var DOM = YAHOO.util.Dom;
var EVT = YAHOO.util.Event;
function validate_form(_obj,lg){
		
		var errors = false;
		if (lg=='pt'){
      var txt_erro = unescape(json[282]);
      var txt_erro2 = 'E-mail incorrecto.';
    } else if (lg=='gb'){
      var txt_erro = 'Mandatory field.';
      var txt_erro2 = 'Invalid E-mail.';
    } else if (lg=='sp'){
      var txt_erro = 'Campo obligatorio.';
      var txt_erro2 = 'E-mail incorrecto.';
    }
    
    
		DOM.getElementsByClassName(
			'required',
			null,
			_obj,
			function(e){
				
				var _tag  = e.tagName;
				var _type = e.getAttribute('type');
				var _emai = e.getAttribute('email');
				var _passw = e.getAttribute('pass');
				var _cpassw = e.getAttribute('cpass');

				if(_tag == 'TEXTAREA' || _type == 'text' && _type !='password'){

					if(e.value == '' || e.value == unescape(json[282]) || e.value =="O seu nome" ){

						//e.style.border = '1px solid #B40812';
						e.style.backgroundColor = "#F7F5EF";
						e.style.color  = '#F2A816';
						e.value = unescape(json[282]);
						
						EVT.addListener(e, "focus", function(){ e.value = ''; });
						
						if(errors == false) errors = true;
						
					} else {
						//e.style.border = '1px solid #D3D3D3';
						e.style.color  = '#707052';
						e.style.backgroundColor = "#FFFFFF";
					}
					
					if(_emai == 1){
						if(verify_email(e.value) == false){
							
							e.style.backgroundColor = "#F7F5EF";
						  e.style.color  = '#F2A816';
							e.value = unescape(json[283]);
							
							EVT.addListener(e, "focus", function(){ e.value = ''; });
							
							if(errors == false) errors = true;
							
						} else {
							//e.style.border = '1px solid #D3D3D3';
						  e.style.color  = '#707052';
						  e.style.backgroundColor = "#FFFFFF";
						}
					}
				} else if(_type == 'password' ) {
					
					if(e.value == '' && _passw==1){
          	e.style.border = '1px solid #B40812';
						//e.style.color  = '#000000';
						//e.value = 'Campo de preenchimento obrigatório.';
						//alert("Preencha a palavra-chave");
						EVT.addListener(e, "focus", function(){ e.value = ''; });
						
						if(errors == false) errors = true;
          }else if(e.value == '' && _cpassw==1){
          	e.style.border = '1px solid #B40812';
						//e.style.color  = '#000000';
						//e.value = 'Campo de preenchimento obrigatório.';
						//alert("Repita a palavra-chave");
						EVT.addListener(e, "focus", function(){ e.value = ''; });
						
						if(errors == false) errors = true;
          }else if(e.value != '' && e.value !=document.getElementById("pass").value && _cpassw==1){
          	e.style.border = '1px solid #B40812';
						//e.style.color  = '#000000';
						//e.value = 'Campo de preenchimento obrigatório.';
						//alert("A repetição da palavra-chave não é igual");
						EVT.addListener(e, "focus", function(){ e.value = ''; });
						
						if(errors == false) errors = true;
          }else {
						e.style.border = '1px solid #B40812';
						//e.style.color  = '#000000';
					}

				} else if(_type == 'checkbox') {
					
					if(e.checked == false){
						e.checked = true;
						alert(unescape(json[284]));
						if(errors == false) errors = true;
					}

				}
				
			}
		);
		
		if(errors == true){
			return false;
		} else {
			return true;
		}
		
	}
	
	function verify_email(_mail){
		
		var status = false;     
		var emailRegEx = /^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i;
		
		if (_mail.search(emailRegEx) == -1) {
			status = false;
		} else {
			status = true;
		}
		     
		return status;

	}

function verifica_filtro(){

var formNav = document.getElementById("form_order"); 

var marca = formNav.m.value;
var pchave = formNav.kw.value;

if (marca==0  && pchave==unescape(json[266]) ){
alert(unescape(json[268]));
return false;
}else {
return true;
}

}

function mudaPaginaTemas(p){
if (xmlhttp)
{
// tenta estabelecer ligação
try
{
var obj = document.getElementById("lstTemas");
var formNav = document.getElementById("form_nav");
var pagina =  document.getElementById("pagina1").value;
var pagina2 =  document.getElementById("pagina2").value;

var pg1=document.getElementById("pagina1");
var pg2=document.getElementById("pagina2");
var pg1Index = pg1.selectedIndex;



var id = formNav.id;

var serverPage ="paginacaoTemas.php";
var params = "pagina="+p+"&id="+id;



xmlhttp.open("GET",serverPage+"?"+params);
xmlhttp.onreadystatechange = function() {
if(xmlhttp.readyState == 1 ) {
  obj.innerHTML="<div style='width:647px;height:300px;border:0px solid red;padding-top:250px;' align='center'><img src='./sysimages/ajax-loader.gif' border='0' ></div>";
}else if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
  if(xmlhttp.responseText){
    obj.innerHTML = xmlhttp.responseText;
    pg1.selectedIndex=(p-1);
  }
}
}
xmlhttp.send(null);
}catch (e)
{
alert("Ocorreu um erro por favor tente novamente."+ e.toString());
}

}else {
document.getElementById("form_nav").submit();
}
}
var teste=0;
function mudaPaginaProdutos(pg,idnav,idpg){
if (xmlhttp)
{
// tenta estabelecer ligação
try
{
var formNav = document.getElementById("form_nav");
var id = formNav.id;
document.getElementById(idnav).selectedIndex=(pg-1);
var obj = document.getElementById("lstProdutos");

var pagina =  document.getElementById(idnav).value;
var pagina2 =  document.getElementById("pagina2");





if(teste==1){alert(idnav);alert(document.getElementById(idnav).selectedIndex);}
var serverPage ="paginacaoProdutos.php";
var params = "pagina="+pagina+"&id="+idpg+"&pg="+idpg;


xmlhttp.open("GET",serverPage+"?"+params);
xmlhttp.onreadystatechange = function() {
if(xmlhttp.readyState == 1 ) {
  obj.innerHTML="<div style='width:647px;height:300px;border:0px solid red;padding-top:250px;' align='center'><img src='./sysimages/ajax-loader.gif' border='0' ></div>";
}else if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
  obj.innerHTML = xmlhttp.responseText;
  document.getElementById("pagina").selectedIndex=(pg-1);
  //alert(pg-1);
  if(pagina2!=null){
    pagina2.selectedIndex=(pg-1);
  }
  
}
}
xmlhttp.send(null);
}catch (e)
{
alert("Ocorreu um erro por favor tente novamente."+ e.toString());
}

}else {
  document.getElementById("form_nav").submit();
}
}

function mudaPagPesq(){
  document.getElementById("form_navp").submit();
}

function minusPlusCart(tipo,objID)
{

if(objID==null){
var obj = document.getElementById("qt_carrinho");
}else {
var obj = document.getElementById(objID);
}

var qt = parseInt(obj.value);
if(tipo==1){
obj.value = qt+1;
}else if(tipo==0 && qt>1){
obj.value = qt-1;
}

}
var numbr=1;
var tipo="Appear";
var randBlc;
function randomBloc(){


randBlc = self.setInterval(function (){

if(numbr!=imgBlc.length-1){
  numbr++;
}else{
  numbr=1;
}





//Effect.BlindDown("not_dest", { duration: 1.0,from:0,to:1,afterFinishInternal:function (){Effect.Appear("not_dest", { duration: 14.0,from:1,to:1});}});
Effect.Appear("blc_img", { duration: 5.0,from:1,to:1,afterFinishInternal:function (){Effect.Fade("blc_img", { duration: 5.0,from:1,to:1});}});




imgBloco(imgBlc[numbr],numbr);
},"10000");
}

function imgBloco(id,key){

numbr=key;
window.clearInterval(randBlc);


var obj = document.getElementById("blc_img");
var sq = document.getElementById("sq_" + id);

for(i=1;i<imgBlc.length;i++){
document.getElementById("sq_" + imgBlc[i]).src='sysimages/sq.jpg';
}

var serverPage ="imgBloco.php";
var params = "id="+id;


xmlhttp.open("GET",serverPage+"?"+params);
xmlhttp.onreadystatechange = function() {
if(xmlhttp.readyState == 1 ) {
  obj.innerHTML="<div style='width:320px;' align='center'><img src='./sysimages/ajax-loader.gif' border='0' ></div>";
}else if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
  obj.innerHTML = xmlhttp.responseText;
  sq.src = "sysimages/sq_sel.jpg";
  randomBloc();
}
}
xmlhttp.send(null);
}

// ABRE E FECHA TUDO

function showQ(id) {
  
  var el = document.getElementById(id);
  var el2 = document.getElementById("tit_" + id);
  
  var xclose = document.getElementsByTagName("tr");
  var xclose2 = document.getElementsByTagName("td");
  for (var i=0; i<xclose.length; i++) {
    if (xclose[i].className == "fechar"){
      xclose[i].style.display = "none";
     
    }
  }
  for (var i=0; i<xclose2.length; i++) {
    if (xclose2[i].className == "artigoEscondido"){
      //alert(xclose2[i].id);
      xclose2[i].className = "artigos";
      xclose2[i].onmouseover = qM[0];
      xclose2[i].onmouseout = qM[1];
    }
     
    
  }
  

  el.style.display = "block";
  el2.className = "artigoEscondido";
  el2.onmouseout= qM[2];
  
  
}

//SUBAREA

function showSub(id)
{
  document.getElementById(id).style.display = "block";
}

function hideSub(id){
  document.getElementById(id).style.display = "none";
}

//SUBMENU

function showSubMenu(id)
{ 
  
  for(i=1;i<submn[sel_submn].length;i++){
    
    var objSMN = document.getElementById("submenu" + submn[sel_submn][i]);
    if(objSMN!=null){
      objSMN.style.display = "none";
    }
    var objMNL = document.getElementById("td_submenu" + submn[sel_submn][i]);
    if(objMNL!=null){
       objMNL.className = "menulat";
       objMNL.onmouseout=submnMOU[sel_submn][i];
       objMNL.onmouseover=submnMOV[sel_submn][i];
    }
    
  }
  
  document.getElementById(id).style.display = "block";
  document.getElementById("td_" + id).className = "menulatsel";
  document.getElementById("td_" + id).onmouseout = submnMOV[sel_submn][i];
}

function hideSubMenu(id){
  document.getElementById(id).style.display = "none";
}
