
//retorna a tecla pressionada - Internet Explorer e Netscape
function getkey(e)
{
	if (window.event)
	   key = window.event.keyCode;
	else
	   key = e.which;

	return key;
}

function isNum(key)
{
	if ( key == 0 || key == 8 ) //tab, backspace
		return true;

	if ( key == 32 ) //space
		return false;

	if ( key<48  ||  key>57  )
		return false;
}

function blurCEP(CEP)
{
	//alert(CEP);
	if ( CEP.length == 8 )
		document.form_inscricao.editnrcep.blur();
	else
		return false;
}


function checkCEP (CEP) {
    if (CEP.length != 8 )
    	return false;
    return true;
}

function isValidEmail(str) {
   return (str.indexOf(".") > 0) && (str.indexOf("@") > 0);

}


/*Função loadIframe - efetua um reload no conteúdo do iframe para consultar o CEP*/
function loadIframe(iframeName, url) {
  if ( window.frames[iframeName] ) {
    window.frames[iframeName].location = url;
	//alert(url);
    return false;
  }
  else return true;
}




function valida_cpf(form) {

   with(form)
   {
    if (editnrcpf.value == '') {
            alert("Deve-se preencher o número do CPF com dígito verificador e sem traço separador.");
            editnrcpf.focus();
            return false;
       }

    if (!(validacpf(editnrcpf.value)))
       { alert("O CPF informado é inválido.");
         editnrcpf.focus();
         return false;
       }
       
    if (editemail.value == '') {
            alert("Deve-se preencher o e-mail para prosseguir.");
            editemail.focus();
            return false;
       }

   }
}



function valida_login(form) {
   with(form)
   {

    if (email.value == '') {
            alert("Deve-se preencher o e-mail para prosseguir.");
            email.focus();
            return false;
       }


    if (senha.value == '') {
            alert("Informe a SENHA para acesso.");
            senha.focus();
            return false;
       }
   }
}

function valida_contato(form) {
   with(form)
   {
    if (assunto.value == '0') {
            alert("Informe o assunto!");
            assunto.focus();
            return false;
       }
    if (nome.value == '') {
            alert("Informe o seu nome!");
            nome.focus();
            return false;
       }
    if (email.value == '') {
            alert("Informe o seu e-mail.");
            email.focus();
            return false;
       }

    if (cidade.value == '') {
            alert("Informe a cidade.");
            cidade.focus();
            return false;
       }
    if (estado.value == '') {
            alert("Informe o estado.");
            estado.focus();
            return false;
       }
    if (telefone.value == '') {
            alert("Informe o telefone.");
            telefone.focus();
            return false;
       }
    if (comentarios.value == '') {
            alert("Informe seu comentário.");
            comentarios.focus();
            return false;
       }

   }
}


function valida_promocao(form) {
   with(form)
   {
    if (nome.value == '') {
            alert("Informe o seu nome!");
            nome.focus();
            return false;
       }
    if (email.value == '') {
            alert("Informe o seu e-mail.");
            email.focus();
            return false;
       }

    if (cidade.value == '') {
            alert("Informe a cidade.");
            cidade.focus();
            return false;
       }
    if (telefone.value == '') {
            alert("Informe o telefone.");
            telefone.focus();
            return false;
       }

   }
}

function valida_indique(form) {
   with(form)
   {

    if (emailind1.value == '') {
            alert("Informe o seu nome!");
            emailind1.focus();
            return false;
       }


    if (nomeind2.value == '') {
            alert("Informe o nome de seu amigo.");
            nomeind2.focus();
            return false;
       }

    if (emailind2.value == '') {
            alert("Informe o e-mail de seu amigo.");
            emailind2.focus();
            return false;
       }

   }
}


function stripCharsInBag(s, bag){
	var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++){
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function daysInFebruary (year){
	// February has 29 days in any year evenly divisible by four,
    // EXCEPT for centurial years which are not also divisible by 400.
    return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}
function DaysArray(n) {
	for (var i = 1; i <= n; i++) {
		this[i] = 31
		if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
		if (i==2) {this[i] = 29}
   }
   return this;
}

function isDate(dtStr){
	var daysInMonth = DaysArray(12);
	var pos1=dtStr.indexOf(dtCh);
	var pos2=dtStr.indexOf(dtCh,pos1+1);
	var strDay=dtStr.substring(0,pos1);
	var strMonth=dtStr.substring(pos1+1,pos2);
	var strYear=dtStr.substring(pos2+1);
	strYr=strYear;
	if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1);
	if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1);
	for (var i = 1; i <= 3; i++) {
		if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1);
	}
	month=parseInt(strMonth);
	day=parseInt(strDay);
	year=parseInt(strYr);
	if (pos1==-1 || pos2==-1){
		alert("O formato correto para a data é: dd/mm/yyyy.");
		return false;
	}
	if (strMonth.length<1 || month<1 || month>12){
		alert("Por favor, entre com um mês válido.");
		return false;
	}
	if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
		alert("Por favor, entre com um dia válido.");
		return false;
	}
	if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
		alert("Por favor, entre com 4 dígitos para ano entre "+minYear+" e "+maxYear);
		return false;
	}
	if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
		alert("Por favor, entre com uma data válida.");
		return false;
	}
return true;
}


function trim(str)
{
   return str.replace(/^\s*|\s*$/g,"");
}

function validacpf(cpf_p){
	//alert(cpf_p);
	var i;
	s = cpf_p;
	var c = s.substr(0,9);
	var dv = s.substr(9,2);
	var d1 = 0;
   var arrayInvalidos;

   arrayInvalidos = ["11111111111","22222222222","33333333333",
                     "44444444444","55555555555","66666666666","77777777777",
                     "88888888888","99999999999","00000000000"];

   for (var i = 0; i < arrayInvalidos.length; i++){
     if (arrayInvalidos[i] == cpf_p){
		return false;
	   }
   }

	for (i = 0; i < 9; i++) {
		d1 += c.charAt(i)*(10-i);
	}


	if (d1 == 0){
		return false;
	}

	d1 = 11 - (d1 % 11);

	if (d1 > 9) d1 = 0;

	if (dv.charAt(0) != d1)
	{ return false; }

	d1 *= 2;

	for (i = 0; i < 9; i++) {
		d1 += c.charAt(i)*(11-i);
	}

	d1 = 11 - (d1 % 11);
	if (d1 > 9) d1 = 0;
	if (dv.charAt(1) != d1) {
		return false;
	}
   return true;
}



function IsNumeric(strString) {
   var strCaracteres = "0123456789.-";
   var Caracter;
   var isNumber = true;

   if (strString.length == 0) return false;

   for (i = 0; i < strString.length && isNumber == true; i++)
      {
      Caracter = strString.charAt(i);
      if (strCaracteres.indexOf(Caracter) == -1)
         {
         isNumber = false;
         }
      }
   return isNumber;
}

function inter(varLargura,varAltura,varTopo,urlArquivo,varId,varTagname) {

	function abre()
        {

          e = Math.round((document.body.clientWidth/2) - (varLargura/2));

          if(document.all)
          {

            if(urlArquivo.substr(urlArquivo.length-"/images/br/inter_novas_lojas_.swf".length,"/images/br/inter_novas_lojas_.swf".length)=="/images/br/inter_novas_lojas_.swf")
            {document.getElementById('intermission').style.left =0;}else{document.getElementById('intermission').style.left = 0;}

          }

          else
          {
            if(urlArquivo.substr(urlArquivo.length-"/images/br/inter_novas_lojas_.swf".length,"/images/br/inter_novas_lojas_.swf".length)=="/images/br/inter_novas_lojas_.swf")
            {
              document.getElementById('intermission').style.marginLeft = 0;
            }else{
              document.getElementById('intermission').style.marginLeft = 0;
            }
          }

        }


	onresize = function() {
		if (IsNumeric(varLargura))
			abre();
	}

	var xwidth="";

        if(!document.all){xwidth="left:0;";}else{
	xwidth="width:"+varLargura+";";
        }

	document.write("<div id='intermission' style='position:absolute;"+xwidth+"height:"+ varAltura +";z-index:1;top:"+ varTopo +"px;left:0;'><object classid=clsid:D27CDB6E-AE6D-11cf-96B8-444553540000 codebase=http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0 width="+ varLargura +" height="+ varAltura +"><param name=movie value="+ urlArquivo +"?id="+ varId +"&tagname="+ varTagname +"><param name=quality value=high><param name=wmode value=transparent><embed src="+ urlArquivo +"?id="+ varId +"&tagname="+ varTagname +" width="+ varLargura +" height="+ varAltura +" quality=high pluginspage=http://www.macromedia.com/go/getflashplayer type=application/x-shockwave-flash wmode=transparent></embed></object></div>");
	if (IsNumeric(varLargura))
		abre();
}
function fecha() {
	document.getElementById('intermission').style.display = 'none';
}


