window.onload=function(){overSetup();}

// JavaScript Document

function nothing()
{
	return;
}

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

function openpopup(url)
{
        window.open(url,"nova","width=400,height=300, status=no")
}

function tableruler()
{
	if (document.getElementById && document.createTextNode)
	{
		var tables=document.getElementsByTagName('table');
		for (var i=0;i<tables.length;i++)
		{
			if(tables[i].className=='tb_results')
			{
				var trs=tables[i].getElementsByTagName('tr');
				for(var j=0;j<trs.length;j++)
				{
					if(trs[j].parentNode.nodeName=='TBODY')
					{
						trs[j].onmouseover=function(){this.className='ruled';return false;}
						trs[j].onmouseout=function(){this.className='';return false}
					}
				}
			}
		}
	}
}

/* Funções ... */

function overSetup() {
	var img, sh, sn, sd
	for (var i = 0; (img = document.images[i]); i++) {
		if (img.getAttribute) {

			sn = img.getAttribute("src");
			sh = img.getAttribute("hsrc");
			sd = img.getAttribute("dsrc");

			if (sn != "" && sn != null) {
				img.n = new Image();
				img.n.src = img.src;

				if (sh != "" && sh != null) {
					img.h = new Image();
					img.h.src = sh;
					img.onmouseover = SwapOn
					img.onmouseout  = SwapOff
				}

				if (sd != "" && sd != null) {
					img.d = new Image();
					img.d.src = sd;
					img.onmousedown = SwapDown
				}
			}
		}
	}
}

function SwapOn() {
	this.src = this.h.src;
}

function SwapOff() {
	this.src  = this.n.src;
}

function SwapDown() {
	this.src  = this.d.src;
	this.temp = typeof(document.onmouseup) != 'undefined' && typeof(document.onmouseup) != 'unknown' ? document.onmouseup : "";
	SwapUp.img = this;
	document.onmouseup = SwapUp;
}

function SwapUp() {
	var ths = SwapUp.img;
	ths.src = ths.n.src;
	if (ths.temp) document.onmouseup = ths.temp;
}

/*
 *	Converte os "NAMES" dos campos em nomes padrão em português
*/

function transStr(str) {
    var strings = [
	['titular_conta', 'Titular da conta'],
	['endereco_imovel', 'Endereço do imovel'],
	['nome_condominio', 'Nome do condomínio'],
	['nome_proprietario', 'Nome do proprietario'],
	['cpf_cnpj', 'CPF/CNPJ'],
	['rg', 'RG'],
	['fone_1', 'Fone 1'],
	['email', 'E-mail'],
	['name', 'Nome'],
	['phone', 'Telefone'],
	['message', 'Mensagem'],
	['bancos', 'Bancos'],
	['agencia', 'Agencia'],
	['cc', 'C/C'],
	['localizacao', 'Localização'],
	['tipo_imovel', 'Tipo de imóvel'],
	['investimento', 'Investimento'],
	['caracteristicas', 'Características'],
	['condominio', 'Nome do condomínio'],
	['endereco', 'Endereço'],
	['unidades', 'Nº de unidades'],
	['tipo', 'Tipo'],
	['funcionario', 'Funcionário contratado'],
	['seu_nome', 'Seu nome'],
	['sindico', 'Sindico'],
	['envio', 'Forma de envio da proposta'],
	['end_proposta', 'Endereço para proposta'],
	['phone1', 'Fone para contato 1'],
    ['phone_1', 'Telefone 1'],
    ['phone_2', 'Telefone 2'],
    ['bairro', 'Bairro'],
    ['area_total', 'Área total'],
    ['area_privada', 'Área provada'],
    ['valor_condominio', 'Valor do condomínio'],
    ['obs', 'Observações'],
    ['valor_esperado', 'Valor esperado'],
    ['imovel', 'Imóvel'],
	['data', 'Data']
	];
	var label = "";
	for (var i = 0; i < strings.length; i ++) {
		if (str.indexOf(strings[i][0]) >= 0) {
			label = strings[i][1];
		}
	}
	return (label != "") ? label : str;
}

Array.prototype.push = function(v) {
	this[this.length] = v
	return v
}

/*
 *	Validador de formulários
*/
function checkRequired(frm, fields) {

	var f = frm;
	var errors = [];
	var foco = [];
	var em = 0;

//	transStr("subject");
	for (i=0;i<f.length;i++){

		var fieldobj = f.elements[i];

		if(fields.indexOf(fieldobj.name)!=-1) {
			if(((fieldobj.type=="text"||fieldobj.type=="password"||fieldobj.type=="textarea"||fieldobj.type=="file")&&trim(fieldobj.value)=='')){
				errors.push(transStr(fieldobj.name));
				foco.push(fieldobj.name);
			}
			if(transStr(fieldobj.name) == transStr("email") && fieldobj.value != ""){
				var re = new RegExp;
				re = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
				var arr = re.exec(fieldobj.value);

				if (arr == null) {
					foco.push(fieldobj.name);
					errors.push("O e-mail digitado não é válido.");

					em = (transStr(foco[0]) == transStr("email")) ? 1 : 0;
				}
			}
			if(fieldobj.type=="select-one"){
				var txt_select = fieldobj.options[fieldobj.selectedIndex].text
				if(txt_select.indexOf("---")!="-1"){
                    errors.push(transStr(fieldobj.name));
                    foco.push(fieldobj.name);
				}
			}
		}
		if((fieldobj.type != "submit")&&(fieldobj.type != "radio"))
			eval("f."+fieldobj.name+".style.background = '#ffffff '");
	}
		
	var s = ((errors.length - em) > 1) ? "s" : "";
	
	if((errors.length - em) == 0){
		var STD_ERROR_PREFIX = "";
	} else {
		var STD_ERROR_PREFIX = "Você deixou "+(errors.length - em)+" campo"+s+" incompleto"+s+".\n";
			STD_ERROR_PREFIX += "Por favor verifique e tente novamente.\n";
	}
	if (errors.length > 0) {
        eval("f."+foco[0]+".focus();");
//        if(f.eval(foco[0]).type != "select-one")
//            eval("f."+foco[0]+".select();");

		// Marca os compos errados e incompletos
		for (i=0; i<errors.length; i++){
	    	eval("f."+foco[i]+".style.background = '#fffec3'");
	    }
		alert(STD_ERROR_PREFIX + errors.join("\n"));
		return false;
	}

 return true;
}
function trim(strn) {
	return strn.replace(/^\s*(.*\S|.*)\s*$/, '$1');
}



/* IE ActiveX FIX */


var bo_ns_id = 0;

function startIeFix(){
  if(isIE()){
    document.write('<div style="display: none;" id="bo_ns_id_' + bo_ns_id + '">');
  }
}

function endIeFix(){
  if(isIE()){
    document.write('</div>');
    var theObject = document.getElementById("bo_ns_id_" + bo_ns_id++);
    if(theObject.firstChild.data){
      theObject.firstChild.removeAttribute('data');
    }
    var theParams = theObject.getElementsByTagName("param");
    var theParamsLength = theParams.length;
    for (var j = 0; j < theParamsLength; j++) {
      if(theParams[j].name.toLowerCase() == 'flashvars'){
        var theFlashVars = theParams[j].value;
      }
    }
    var theInnnerHTML = theObject.innerHTML;
    var re = /<param name="FlashVars" value="">/ig;
    theInnnerHTML = theInnnerHTML.replace(re, "<param name='FlashVars' value='" + theFlashVars + "'>");
    theObject.outerHTML = theInnnerHTML;
  }
}

function isIE(){
  var strBrwsr = navigator.userAgent.toLowerCase();
  if(strBrwsr.indexOf("msie") > -1 && strBrwsr.indexOf("mac") < 0){
    return true;
  }else{
    return false;
  }
}
