function validaUpdate(obj){
  var password = document.getElementById('password');
  
  if(password.value != ""){
    return verify_form_data(obj,'THISFORM2',formErros);
  }else {
    return verify_form_data(obj,'THISFORM',formErros);
  }
  return false;
}

function alteraArmazem(objID){
  document.getElementById(objID).disabled = false;
  
  document.getElementById(objID).onchange = function(){
      var confirmacao = window.confirm("Ao alterar o armazém onde pretende levantar os artigos escolhidos, perderá todos os artigos que possui no carrinho.Confirma que pretende proceder á alteração?", "");
      if(confirmacao){
        document.getElementById('frmarm2').submit();
        //window.location=window.location.href + '&arm=' + document.getElementById(objID).value;
      }
  }
}

function mudaArmazem(id){
  var confirmacao = window.confirm("Ao alterar o armazém onde pretende levantar os artigos escolhidos, todo o seu carrinho terá que ser recalculado.Tem a certeza que pretende proceder á alteração?", "");
  if(confirmacao){
    window.location='index.php?id=69&step=2&arm=' + id;
  }
}

var numbr=1;
var tpb = 0;
var randMarcas;
function random_dest(){


randMarcas = self.setInterval(function (){

if(numbr!=tpb){
  numbr++;
}else{
  numbr=1;
}  

var objName = "pag"+numbr;

    Effect.Appear("marcas", { duration: 10.0,from:1,to:0.5,afterFinishInternal:function (){
    var elems = document.getElementsByTagName('div');
    for(i=0;i<=elems.length-1;i++){
      if(elems[i].className=='pagBLC'){
        elems[i].style.display='none';
      }
    }
    document.getElementById(objName).style.display='block';
    Effect.Fade("marcas", { duration: 10.0,from:0.5,to:1,afterFinishInternal:function (){
      
    }
  });

}});


},"20000");
}
var num=1;
var tpc = 0;
var randCamp;
function random_campanhas(tipo){


randCamp = self.setInterval(function (){

if(num!=tpc){
  num++;
}else{
  num=1;
}  

//var objName = "pag"+num;

Effect.Appear("bannerH", { duration: 5.0,from:1,to:1,afterFinishInternal:function (){
	muda_campanha(num,camp[num],tipo);
}});
},"10000");
}

function muda_campanha(numb,id,tipo){
if (xmlhttp)
    {
      //tenta estabelecer ligação
      try{
          num = numb;
          
          var obj = document.getElementById("bannerH");
          var serverPage ="camp.php";
          var params = "ajx=1&id="+id+"&tipo="+tipo;
          
          xmlhttp.open("GET",serverPage+"?"+params,true);
          xmlhttp.onreadystatechange = function() {
          if(xmlhttp.readyState == 1 ) {
              window.clearInterval(randCamp);
          }else if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
            if(xmlhttp.responseText){
              
              var elems = document.getElementsByTagName('div');
              for(i=0;i<=elems.length-1;i++){
                if(elems[i].className=='square_sel'){
                  elems[i].className='square';
                }
              }
              
              var sq = document.getElementById('sq_' + num);
              if(sq!=null){
                //alert(num);
                sq.className='square_sel';
              }
              
              
              //obj.style.display = 'block';
              var resultado = xmlhttp.responseText;
              resultado=resultado.split("#");
              
              if(resultado[0]=='1'){
                obj.style.border="1px solid #D1D1D1";
              	obj.innerHTML = resultado[1];
              }else if(resultado[0]=='2'){
               obj.style.border="1px solid #D1D1D1";
               var soH = new SWFObject(resultado[1], 'flash', resultado[2],resultado[3], '9', '#000000');
          	   soH.addParam("wmode", "transparent");
          	   soH.addParam('scale', 'scale');
          	   //so2.addVariable('blc','<?=$var_bl?>')      
          	   soH.write('bannerH');
              	
              }
              random_campanhas(tipo);
           }
          }
          }
          xmlhttp.send(null);
          
          
      }catch (e){
        alert("Ocorreu um erro por favor tente novamente."+ e.toString());
        //return false;
      }
    
    }
}


function verificaTermos(){

  if(document.getElementById('condicoes').checked==true){ 
    return true;
  }else{ 
    alert('Por favor confirme que leu as Condições de Utilização antes de prosseguir.');
    return false;
  }
  
}

function validaPesqM(form,objID){
 
  
  
  var obj = document.getElementById(objID);
  var marca = form.m.value;
  var ref = form.ref.value;
  
  if(form.teste != null){
    var teste = form.teste.value;
  }  
    if(marca==""){
      alert(unescape(json[30]));
      return false;
    }
    if(ref=="" || ref==" "){
      alert(unescape(json[31]));
      return false;
    }
    
    if (xmlhttp)
    {
      //tenta estabelecer ligação
      try{
         //form.submit();
          
          
          
          var serverPage ="pesquisaMarcas.php";
          var params = "ajx=1&m=" + marca + "&ref=" + ref + "&teste=" + teste;
          
          xmlhttp.open("GET",serverPage+"?"+params,true);
          xmlhttp.onreadystatechange = function() {
          if(xmlhttp.readyState == 1 ) {
              //alert("OK");
              return false;
              obj.style.display = 'block';
              obj.innerHTML="<div style='width:733px;height:150px;border:0px solid red;padding-top:100px;' align='center'><img src='./sysimages/ajax-loader.gif' border='0' ></div>";
          }else if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
            if(xmlhttp.responseText){
              obj.style.display = 'block';
              obj.innerHTML = xmlhttp.responseText;
              
              var rf = document.getElementById('ref');
              if(rf!=null){ rf.onblur = function(){ if(this.value==''){ this.value=ref; } } }
              
               return false; 
            }
          }
          }
          xmlhttp.send(null);
          return false;
          
      }catch (e){
        alert("Ocorreu um erro por favor tente novamente."+ e.toString());
        //return false;
      }
    
    }else {
      //form.submit();
      return true;
    }
  
}

function openinf(mr1){
 
  var mr1 = document.getElementById(mr1);
  if(mr1!=null){
    mr1.style.display = 'block';
  }
  setOpacity(document.getElementById('marcas'),100);
  window.clearInterval(randMarcas);
  
}

function closeinf(mr1){
  var mr1 = document.getElementById(mr1);
  if(mr1!=null){
    mr1.style.display = 'none';
  }
  if(bg_format!=1){
    random_dest();
  }
  
  
}



function setOpacity(obj,value) {
	obj.style.opacity = value/10;
	obj.style.filter = 'alpha(opacity=' + value*10 + ')';
}


function openMenu(img, cnt, tit, div) {
  
  
  var img = document.getElementById(img);
  var cnt = document.getElementById(cnt);
  var tit = document.getElementById(tit);
  var div = document.getElementById(div);
  
  if(div.className == "bt aberto") {
  
    var divs2 = document.getElementsByTagName("div");
    var divs_len2 = divs2.length;
    
    for (var x=0; x < divs_len2; x++) {
      if (divs2[x].className == "cont_bt"){
          divs2[x].style.display = 'none';
      }
      if (divs2[x].className == "close"){
        divs2[x].className = "open";
      }
      if (divs2[x].className == "txt_bt"){
        divs2[x].style.cursor = 'pointer';
      }
      if (divs2[x].className == "bt aberto"){
        divs2[x].className = 'bt fechado';
      }
    } 

  } else {
    
    var divs2 = document.getElementsByTagName("div");
    var divs_len2 = divs2.length;
    
    for (var x=0; x < divs_len2; x++) {
      if (divs2[x].className == "cont_bt"){
          divs2[x].style.display = 'none';
      }
      if (divs2[x].className == "close"){
        divs2[x].className = "open";
      }
      if (divs2[x].className == "txt_bt"){
        divs2[x].style.cursor = 'pointer';
      }
      if (divs2[x].className == "bt aberto"){
        divs2[x].className = 'bt fechado';
      }
    } 
    
    
    img.className = 'close';
    cnt.style.display = 'block'; 
    div.className = 'bt aberto';
    //div.style.cursor = 'default';
    img.style.cursor = 'default';
    
  }    


}


function openPOP(pop) {
  var pop = document.getElementById(pop);
  pop.style.display = 'block';
}

function closePOP(pop) {
  var pop = document.getElementById(pop);
  pop.style.display = 'none';
}


function trocaRadios(selID,armazemID,tipo) {
  var sel = document.getElementById(selID);
  
  var divs2 = document.getElementsByTagName("select");
    var divs_len2 = divs2.length;
    
    for (var x=0; x < divs_len2; x++) {
          divs2[x].disabled = true;
      }
  if(sel!=null){
    sel.disabled = false;
  }    
  
  if(sel!=null )
    mudaRota(sel,armazemID,tipo);
  
}


function incrementar(tipo,id,max){
		var qt = document.getElementById('qt_dev' + id)
		qt.value = parseInt(qt.value);
		 
		if(tipo==1){//incrementa
      if(qt.value<max){//se não exceder o máximo (quantidade comprada)
        qt.value++;
      }
    }else if(tipo==0){//desincrementa
      if(qt.value>0){//se não for menor que 1
        qt.value--;
      }
    }
		
}


function incrementar2(val){
		var txt2 = document.getElementById('txt2')
		txt2.value = parseInt(txt2.value) + val
}

function incrementar4(val){
		var txt4 = document.getElementById('txt4')
		txt4.value = parseInt(txt4.value) + val
}

function incrementar3(val){
		var txt3 = document.getElementById('txt3')
		txt3.value = parseInt(txt3.value) + val
}

function trocaRadio(selp){
  
  var selp = document.getElementById(selp);
  selp.disabled = false;
}

function closeRadio(selp){
  var selp = document.getElementById(selp);
  selp.disabled = true;
}



function openGama(idgama, idbt){
	var gama = document.getElementById(idgama);
    var divs = document.getElementsByTagName("div");
	var bt = document.getElementById(idbt);
    
    for (var i=0; i < divs.length; i++) {
      if (divs[i].className == "containergama"){
          divs[i].style.display = 'none';
      }
	  
	  if (divs[i].className == "btfechagama"){
          divs[i].style.display = 'none';
      }
    }
	
	gama.style.display = 'block';
	bt.style.display = 'block';
}

function closeGama(idgama, idbt){
	var gama = document.getElementById(idgama);
	var bt = document.getElementById(idbt);
    
	gama.style.display = 'none';
	bt.style.display = 'none';
}


var myWidth;
var myHeight;

function getSize() {
  
  var obj = document.getElementById('fundo_opaco');
  
  if( typeof( window.innerWidth ) == 'number' ) { 
  
  //Non-IE 
  
  myWidth = window.document.body.scrollWidth;
  myHeight = window.document.body.scrollHeight; 
  
  } else if( document.documentElement && 
  
  ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) { 
  
  //IE 6+ in 'standards compliant mode' 
  
  myWidth = document.documentElement.scrollWidth; 
  myHeight = document.documentElement.scrollHeight 
  
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) { 
  
  //IE 4 compatible 
  
  myWidth = document.body.scrollWidth; 
  myHeight = document.body.scrollHeight; 
  
  }
  
  
  
  var tamanho = new Array();
  tamanho[0] = myWidth;
  tamanho[1] = myHeight; 
  
  if(obj!=null){    
    obj.style.width = tamanho[0] + 'px';
    obj.style.height = (tamanho[1] + 160) + 'px';
  }
  
  return  tamanho;
}
var teste = 0;
function mudaRota(obj,armazemID,tipo){
  
  
  if (xmlhttp)
  {
      //tenta estabelecer ligação
      try{
          
          
          var rota =  obj.value;
          
          var obj = document.getElementById("resume_values");
          var serverPage ="ajax_resume.php";
          var params = "rota="+ rota + "&armazemID=" + armazemID + "&tipo=" + tipo;
          
          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 ) {
                
          }else if(xmlhttp.readyState == 4 && xmlhttp.status == 200) {
              
              if(xmlhttp.responseText){
                  var resultado = xmlhttp.responseText;
                  
                  resultado = resultado.split("|**|");
                  
                  var total_pvp1 = document.getElementById('total_pvp1');
                  var total_descontos1 = document.getElementById('total_descontos1');
                  var subtotal1 = document.getElementById('subtotal1');
                  var total_portes1 = document.getElementById('total_portes1');
                  var total_taxas1 = document.getElementById('total_taxas1');
                  var total_iva1 = document.getElementById('total_iva1');
                  var total_carrinho1 = document.getElementById('total_carrinho1');
                  
                  
                 
                  
                  
                      
                      if(total_pvp1!=null)
                        total_pvp1.innerHTML = resultado[8];
                      
                      if(total_taxas1!=null)
                        total_taxas1.innerHTML = resultado[7];  
                        
                      if(total_descontos1!=null)
                        total_descontos1.innerHTML = resultado[6];
                      
                      if(total_portes1!=null)
                        total_portes1.innerHTML = resultado[5];
                      
                      if(subtotal1!=null)
                        subtotal1.innerHTML = resultado[3]; 
                        
                      if(total_iva1!=null)
                        total_iva1.innerHTML = resultado[2];   
                        
                      if(total_carrinho1!=null)
                        total_carrinho1.innerHTML = resultado[1];  
                          
                  
                  
              }
          }
        }
        xmlhttp.send(params);
        return false;
    
  }catch (e){
      alert("Não foi possivel modificar a rota:\n" + e.toString());
      return false;
  }
  
  }
}

















