var ns6=document.getElementById&&!document.all

function restrictinput(maxlength,e,placeholder){
if (window.event&&event.srcElement.value.length>=maxlength)
return false
else if (e.target&&e.target==eval(placeholder)&&e.target.value.length>=maxlength){
var pressedkey=/[a-zA-Z0-9\.\,\/]/ //detect alphanumeric keys
if (pressedkey.test(String.fromCharCode(e.which)))
e.stopPropagation()
}
}

function countlimit(maxlength,e,placeholder){
var theform=eval(placeholder)
var lengthleft=maxlength-theform.value.length
var placeholderobj=document.all? document.all[placeholder] : document.getElementById(placeholder)
if (window.event||e.target&&e.target==eval(placeholder)){
if (lengthleft<0)
theform.value=theform.value.substring(0,maxlength)
placeholderobj.innerHTML=lengthleft
}
}


function displaylimit(thename, theid, thelimit){
var theform=theid!=""? document.getElementById(theid) : thename
var limit_text='<b><span id="'+theform.toString()+'">'+thelimit+'</span></b> caracteres para o limite do campo.'
if (document.all||ns6)
document.write(limit_text)
if (document.all){
eval(theform).onkeypress=function(){ return restrictinput(thelimit,event,theform)}
eval(theform).onkeyup=function(){ countlimit(thelimit,event,theform)}
}
else if (ns6){
document.body.addEventListener('keypress', function(event) { restrictinput(thelimit,event,theform) }, true); 
document.body.addEventListener('keyup', function(event) { countlimit(thelimit,event,theform) }, true); 
}
}



function janela(pagina){
window.open(pagina,"Pagamento","height=500,width=820,left=100,top=80,scrollbars=yes");
}

function abreChat() {
var pop_window = window.open("about:blank","janela","width=350,height=350,resizable=0,toolbar=0,location=0,directories=0,status=1,menubar=0");
pop_window.focus();
document.getElementById('auto').submit();
}

function numbersOnly(myfield, e){
	if (myfield.length ==0) myfield.value=0;  
	var key;
	var keychar;
	if (window.event)
		key = window.event.keyCode;
	else if (e)
	    key = e.which;
	else
	    return true;

	keychar = String.fromCharCode(key);
	if ((key==null) || (key==0) || (key==8) ||  (key==9)|| (key==13)|| (key==27) )
		return true;
	else if ((("0123456789").indexOf(keychar) > -1))
		return true;
	else
		return false;
}

function mudaFoco(caracteres,focoAtual,novoFoco){
	if(focoAtual.value.length==caracteres){
		novoFoco.focus();		
	}
}

function ConsultaSEDEX(sObjeto) {
  var sURL;
  sURL='http://websro.correios.com.br/sro_bin/txect01$.QueryList?P_LINGUA=001&P_TIPO=001&P_COD_UNI='+sObjeto;
  popup=window.open(sURL,'_blank','top=20,left=20,height=400,width=540,resizable=yes,status=no,scrollbars=yes,toolbar=yes,menubar=no,location=no');
  popup.focus();
  }



function ValidaEmail(email) {
    var achou_ponto=false;
    var achou_arroba=false;
    var achou_caracter=false;

    for (var i=0; i<email.length; i++) {
            if (email.charAt(i)=="@")
            { 
                if (email.charAt(i+1)==".")
                achou_arroba=false;
                else
                achou_arroba=true;
            }
            else if (email.charAt(i)==".") achou_ponto=true;
            else if (email.charAt(i)!=" ") achou_caracter=true;
    }

    if((email.charAt(0)=="W" || email.charAt(0)=="w") &&
        (email.charAt(1)=="W" || email.charAt(1)=="w") &&
        (email.charAt(2)=="W" || email.charAt(2)=="w") &&
        (email.charAt(3)=="."))
    {
        achou_ponto=false;
        achou_caracter=false;
    }
    if(email.charAt(email.length-1)==".")
    {
        achou_ponto=false;
    } 
    return (achou_ponto && achou_arroba && achou_caracter);
}

function ChangeImage(numero) {
	thumbs = new Array(4);
	thumbs[1] = document.thumb_a;
	thumbs[2] = document.thumb_b;
	thumbs[3] = document.thumb_c;
	thumbs[4] = document.thumb_d;
	thumbs[5] = document.thumb_e;

	thumbs[6] = document.thumb_abe;
	thumbs[7] = document.thumb_box;
	thumbs[8] = document.thumb_gde;

	aux = document.foto_principal.src;
	document.foto_principal.src = thumbs[numero].src;
	thumbs[numero].src = aux;
}






//---------------------------- checar -------------------------- //
var checkobj

function agreesubmit(el){
checkobj=el
if (document.all||document.getElementById){
for (i=0;i<checkobj.form.length;i++){  //hunt down submit button
var tempobj=checkobj.form.elements[i]
if(tempobj.type.toLowerCase()=="submit")
tempobj.disabled=!checkobj.checked
}
}
}

function defaultagree(el){
if (!document.all&&!document.getElementById){
if (window.checkobj&&checkobj.checked)
return true
else{
alert("Please read/accept terms to submit form")
return false
}
}
}

