function mOs(a) {
    if (a == 'o') {
        document.getElementById('otherSitesMenu').style.display = 'block';
    } else {
        document.getElementById('otherSitesMenu').style.display = 'none';
    }
}
function pularPara(max, atual, id) {
    var campo = document.getElementById(id);
    if (campo) {
        if (atual.value.length == max) {
            campo.focus();
        }
    }
}

function alternar(div) {
    if (document.getElementById(div).style.display == "none") {
        $('#' + div).slideDown("slow");
    } else {
        $('#' + div).slideUp("slow");
    }
}
function over(src,cursor) {src.bgColor = "#AFB8CF"}
function out(src) {src.bgColor = ""}
function voltar() {window.history.back()}
function imprimir() {window.print()}
function fechar() {window.close()}
function abrir() {
	var windowFeatures = "", nomeArquivo = "", nomeJanela = "", erro = null
	Argumentos = abrir.arguments; noArgumentos = Argumentos.length; nomeArquivo = Argumentos[0]
	for (i = 1; i < noArgumentos; i++) {
		valor = Argumentos[i].substring(2,Argumentos[i].length)
		switch(Argumentos[i].substring(0,2)) {
			case "nj" : nomeJanela = valor; break
			case "to" : windowFeatures += "top=" + valor + ", "; break
			case "le" : windowFeatures += "left=" + valor + ", "; break
			case "he" : windowFeatures += "height=" + valor + ", "; break
			case "wi" : windowFeatures += "width=" + valor + ", "; break
			case "lb" : windowFeatures += "location=" + valor + ", "; break
			case "mb" : windowFeatures += "menubar=" + valor + ", "; break
			case "sc" : windowFeatures += "scrollbars=" + valor + ", "; break
			case "st" : windowFeatures += "status=" + valor + ", "; break
			case "tb" : windowFeatures += "toolbar=" + valor + ", "; break
			case "tt" : windowFeatures += "titlebar=" + valor + ", "; break
			case "re" : windowFeatures += "resizable=" + valor + ", "; break
			default : erro = '"Código de atributo não informado no '+(i+1)+' º argumento (' +Argumentos[i]+ ')"'
		}
	}
	windowFeatures = windowFeatures.substring(0,windowFeatures.lastIndexOf(","))
	if (erro) { alert(erro) } else { novaJanela = window.open(nomeArquivo, nomeJanela, windowFeatures) }
}

var aLabelList = new Array()
var aErrorList = new Array()
var regEx = /^.+@.+\..{2,3}$/
function fgFormValidate(oForm) {
    var iLabelCount = 0
    var sError = ""

    aLabelList.splice(0, aLabelList.length)
    aErrorList.splice(0, aErrorList.length)
        	
    feFormValidate(oForm)
        	
    if (aLabelList.length == 1)
        sError += "* O campo '" + aLabelList[0] + "' é obrigatório.\n"
    if (aLabelList.length > 1) {
        iLabelCount = 0
        sError += "* Os campos "
        for (i = 0; i < aLabelList.length; i++) {
            iLabelCount++
            sError += "'" + aLabelList[i] + "'"
            if (iLabelCount != aLabelList.length) 
                if (iLabelCount == (aLabelList.length - 1)) sError += " e "; else sError += ", " 
        }
        sError += " são obrigatórios.\n"
    }
    if (aErrorList.length > 0) {
        sError += "\n"
        for (i = 0; i < aErrorList.length; i++) sError += "* " + aErrorList[i] + "\n"
        sError = sError.substr(0, (sError.length - 1))
    }
    if (sError == "") { return true } else { alert(sError); return false }
}

function limpa(campo) {
   campo.value = '';
}
function validaUsuario(campo) {
   if(campo.value == ''){
   	campo.value = 'Usuário';
   }
}
function validaSenha(campo) {
   if(campo.value == ''){
   	campo.value = 'Senha';
   }
}
function Sel_pag(targ,selObj,restore){ 
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}
function abrir() {
	var windowFeatures = "", nomeArquivo = "", nomeJanela = "", erro = null
	Argumentos = abrir.arguments; noArgumentos = Argumentos.length; nomeArquivo = Argumentos[0]
	for (i = 1; i < noArgumentos; i++) {
		valor = Argumentos[i].substring(2,Argumentos[i].length)
		switch(Argumentos[i].substring(0,2)) {
			case "nj" : nomeJanela = valor; break
			case "to" : windowFeatures += "top=" + valor + ", "; break
			case "le" : windowFeatures += "left=" + valor + ", "; break
			case "he" : windowFeatures += "height=" + valor + ", "; break
			case "wi" : windowFeatures += "width=" + valor + ", "; break
			case "lb" : windowFeatures += "location=" + valor + ", "; break
			case "mb" : windowFeatures += "menubar=" + valor + ", "; break
			case "sc" : windowFeatures += "scrollbars=" + valor + ", "; break
			case "st" : windowFeatures += "status=" + valor + ", "; break
			case "tb" : windowFeatures += "toolbar=" + valor + ", "; break
			case "tt" : windowFeatures += "titlebar=" + valor + ", "; break
			case "re" : windowFeatures += "resizable=" + valor + ", "; break
			default : erro = '"Código de atributo não informado no '+(i+1)+' º argumento (' +Argumentos[i]+ ')"'
		}
	}
	windowFeatures = windowFeatures.substring(0,windowFeatures.lastIndexOf(","))
	if (erro) { alert(erro) } else { novaJanela = window.open(nomeArquivo, nomeJanela, windowFeatures) }
}
function formatar(src, mask) {
			var i = src.value.length;
			var saida = mask.substring(i,i+1);
			var ascii = event.keyCode;
			if (saida == "A") {
				if ((ascii >=97) && (ascii <= 122)) { 
					event.keyCode -= 32;
				} else {
					event.keyCode = 0;
				}
			} else if (saida == "0") {
				if ((ascii >= 48) && (ascii <= 57)) {
					return
				} else {
					event.keyCode = 0
				}
			} else if (saida == "#") {
				return;
			} else {
				src.value += saida;
				i += 1
				saida = mask.substring(i,i+1);
				if (saida == "A") {
					if ((ascii >=97) && (ascii <= 122)) {
						event.keyCode -= 32;
					} else {
						event.keyCode = 0; 
					}
				} else if (saida == "0") {
					if ((ascii >= 48) && (ascii <= 57)) {
						return
					} else {
						event.keyCode = 0 
					}
				} else {
					return;
				}
			}
		}	
		
		
		
function AtualizaUploads (sucesso, arquivo){
	if (Number(sucesso) == 1)
		alert('Arquivo ' + arquivo + ' enviado com sucesso!');
	else
		alert('Erro no envio do arquivo ' + arquivo + '.');
}

function fakeClick(id) { 
    var evt; 
    var elm = document.getElementById(id);

    if (document.createEvent){ 
        evt = document.createEvent("MouseEvents"); 
        evt.initMouseEvent("click", true, true, window, 
        0, 0, 0, 0, 0, false, false, false, false, 0, null); 
    } 
    (evt)? elm.dispatchEvent(evt):(elm.click && elm.click());
}

function postInterestedData(id) {
    var fname = document.getElementById('txtName').value;
    var femail = document.getElementById('txtEmail').value;
    var fphone = document.getElementById('txtPhone').value;
    var fcompany = document.getElementById('txtCompany').value;
    var fmessage = document.getElementById('txtMessage').value;

    if (fname.length == 0 || femail.length == 0 || fphone.length == 0 || fcompany.length == 0 || fmessage.length == 0) {
        alert("Preencha todos os campos para enviar a mensagem.");
        return false;
    }

    $.post("produtosDetInterested.aspx", { id: id, name: fname, email: femail, phone: fphone, company: fcompany, message: fmessage },
        function(data) {
            alert(data);
        });
}
