

function dump(obj ,returnOnly){
	var str = typeof obj + obj + '<br/>';
	if (returnOnly == undefined){ returnOnly = ''}
	for (elm in obj){
		if (returnOnly == typeof obj[elm] || '' == returnOnly){
			valor = '';
			if (typeof obj[elm] == 'number' || typeof obj[elm] == 'string'){valor = obj[elm]}
			str += '<strong>' +(typeof obj[elm]) +'</strong> ' +elm +' <i>' +valor +'</i><br/>';
		}
	}
	return str;
}

//===========================================================================
//
function printDump(obj ,returnOnly){
	document.body.innerHTML += dump(obj ,returnOnly);
}

//===========================================================================
//
function isAlpha(strChar) {
  var i, blnValid;

  blnValid = false;
  for (i = 0; i < strChar.length; i++) {
    if ((strChar.charAt(i) >= "a" && strChar.charAt(i) <= "z")
    || (strChar.charAt(i) >= "A" && strChar.charAt(i) <= "Z") )
    blnValid = true;
  }
  return blnValid;
}

//===========================================================================
//
function aSplit(strString, charSep) {
  var arrAux = new Array(), i, j;


 if (charSep.length == 1) {
   j = 0;
   arrAux[j] = "";
   for (i = 0; i < strString.length; i++) {
     if (strString.charAt(i) != charSep) {
       arrAux[j] = arrAux[j] + strString.charAt(i);
     }
     else {
       j++;
       arrAux[j] = "";
     }
   }

   return arrAux;
  }
  else return NaN;
}

//===========================================================================
//
function isEMail(email) {
   var Valid, strDomain, strUser, i, intCount;
   var arrAux;

   if (email == "") {
       return false;
   }
   else {
       Valid = false;

       if (email.charAt(email.length - 1) == ".") {
         email = email.substr(0, email.length - 1);
       }

       if (email.indexOf("@") > 0) {
           strDomain = email.substr(email.indexOf("@") + 1, email.length - (email.indexOf("@") + 1));
           strUser = email.substr(0, email.indexOf("@"));

           arrAux = aSplit(strUser, ".");

       intCount = -1;
       for (i = 0; i <= arrAux.length - 1; i++) {
         if (arrAux[i] > "" && arrAux[i].indexOf("@") == -1) {
             intCount++;
         }
       }

       if (intCount == arrAux.length - 1) Valid = true;

       if (Valid) {

         Valid = false;
         arrAux = aSplit(strDomain, ".");

           intCount = -1;
           for (i = 0; i <= arrAux.length - 1; i++) {

             if (arrAux[i] > "" && isAlpha(arrAux[i].charAt(0)) && arrAux[i].indexOf("@") == -1) {
             intCount++;
             }
           }

         if (intCount == arrAux.length - 1) Valid = true;

         }

       }
       if (!Valid) {
           return false;
       }
       else {
           return true;
       }

   }
}

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

//===========================================================================
//
function trim(string){
	return string.replace(/(^\s*)|(\s*$)/g,'');
}

//===========================================================================
//
var myWindow;
function popupWindow(url, w, h) {
    var width  = w;
    var height = h;
    
	var left = parseInt((screen.availWidth/2) - (width/2));
    var top  = parseInt((screen.availHeight/2) - (height/2));
	
    var windowFeatures = "width=" + width + ",height=" + height + 
        ",status=0,resizable=0,left=" + left + ",top=" + top + 
        ",screenX=" + left + ",screenY=" + top;
    
	myWindow = window.open(url, "subWind", windowFeatures);
	myWindow.focus();
}

//===========================================================================
//
function closeWindow() {
	window.close();		
}

//===========================================================================
//
function campoObrigatorio(string) {
	return 'O campo " '+string+' " é obrigatório!';
}

//===========================================================================
//
function envia() {
	var form = document.forms.contato;
	var nome = 	form.nome;
	var fone = 	form.telefone;	
	var email =	form.email;	
	var assunto = form.assunto;		
	var mensagem  = form.mensagem;

	if(trim(nome.value) == '') {
		alert(campoObrigatorio('Nome'));
		nome.focus();
		return false;
	
	} else if( (trim(email.value) == '') || !(isEMail(email.value)) ) {
		alert(campoObrigatorio('Email'));
		email.focus();
		return false;

	} else if(trim(assunto.value) == '') {
		alert(campoObrigatorio('Assunto'));
		assunto.focus();
		return false;

	} else if( trim(mensagem.value) == '') {
		alert(campoObrigatorio('Mensagem'));
		mensagem.focus();
		return false;
	
	} else {
		form.submit.disabled = true;
		return true;
		
	}
	return false;
}



function enviaPromo() {
	var form = document.forms.contato;
	var nome = 	form.nome;
	var fone = 	form.telefone;	
	var email =	form.email;	
	var cpf = form.cpf;		
	var sexo = form.sexo;		
	var endereco = form.endereco;
	var cidade = form.cidade;
	var uf = form.uf;		
	var cep = form.cep;
	var ddd = form.ddd;	
	var fone = form.fone;		

	if(trim(nome.value) == '') {
		alert(campoObrigatorio('Nome'));
		nome.focus();
		return false;
	
	} else if( (trim(email.value) == '') || !(isEMail(email.value)) ) {
		alert(campoObrigatorio('Email'));
		email.focus();
		return false;

	} else if(trim(cpf.value) == '') {
		alert(campoObrigatorio('CPF'));
		cpf.focus();
		return false;
		
	} else if(!isCpf(unformatNumber(cpf.value))) {
		alert('CPF inválido');
		cpf.focus();
		return false;
		
	} else if(trim(endereco.value) == '') {
		alert(campoObrigatorio('Endereço'));
		endereco.focus();
		return false;

	} else if(trim(cidade.value) == '') {
		alert(campoObrigatorio('Cidade'));
		cidade.focus();
		return false;

	} else if(trim(cep.value) == '') {
		alert(campoObrigatorio('CEP'));
		cep.focus();
		return false;

	} else if( trim(ddd.value) == '') {
		alert(campoObrigatorio('DDD'));
		ddd.focus();
		return false;

	} else if( trim(fone.value) == '') {
		alert(campoObrigatorio('Telefone'));
		fone.focus();
		return false;
	
	} else {
		form.submit();
		form.button.disabled = true;
		return true;		
	}
	return false;

}
function formataCep(cep){
	return cep.replace(/\D/g, "").replace(/(\d{5})(\d{3})(?:.*)/, "$1-$2");
}

function isCep(cep){
	return cep.match(/\d{5}-\d{3}/) != null;
}
