// JavaScript Document var data = 1; var styleDefault = "url(../html/Business%20Center/img/formulario_b.gif) #FFF"; var styleValid = "url(../html/Business%20Center/img/input_verr.gif) #FFF"; var styleError = "url(../html/Business%20Center/img/input_verm.gif) #FFF"; var styleWarn = "url(../html/Business%20Center/img/input_amar.gif) #FFF"; function criarData() { _criarData(0, 0); } function criarData2() { _criarData(1, 0); } function criarData3() { _criarData(1, 1) } function _criarData(equips, horaAberta){ data = document.getElementsByName('date[]').length; data += 1; var data_ul = document.createElement('ul'); // cria um novo UL data_ul.id = "data"+data; // coloca um ID no UL horas = ""; for (i = 8; i < 23; i++) { var k = ""; if (i < 10) k += "0"; k += i + ":00"; horas += ""; } data_ul.innerHTML = "Dia "+data+"" + "" + "
  • " + "Data" + "" + "
  • " + "
  • " + "Horário" + ((horaAberta == 1) ? (" às " + "") : (" às " + "")) + "
  • " + "
  • " + "Nº de participantes" + "" + "   pessoas" + "
  • " + "
  • " + "Espaço" + "" + "
  • " + "
  • " + "Organização
    (mesas e cadeiras)
    " + "" + "
    " + "
  • " + "
  • " + "Equipamentos" + ((equips == 0) ? ( "
    Notebook
    Flip Chart
    Notebook Teachers
    " +"
    Projetor
    TV
    Projetor Teachers
    " ) : ( "" + "
    " + "" + "" + "" + "
    " + "
    " + "" + "" + "" + "" + "
    " + "
    " + "" + "" + "
    ")) + "
  • " + "
  • " + "Coffee Break" + "" + "" + "
  • ";// Conteudo da UL document.getElementById('data_hora_eventos').appendChild(data_ul);// insere UL como último nó do ID especificado //document.getElementById('data_hora_eventos').getElementsByTagName('a').item(0).style.display = 'block'; var buttons = document.getElementsByName("deleteButton"); for (i = 0; i < buttons.length; i++) { button = buttons[i]; button.style.display = 'none'; } buttons[buttons.length - 1].style.display = ''; /*if (data>1) alert(data) document.getElementById("deleteButton").style.display = "";*/ } function deletarDia(id){ var n = 0; var m = 1; var noData = document.getElementById('data_hora_eventos').getElementsByTagName('strong'); data = document.getElementsByName('date[]').length; data -=1; document.getElementById('data_hora_eventos').removeChild(document.getElementById(id)); if (noData.length==1){ document.getElementById('data_hora_eventos').getElementsByTagName('a').item(0).style.display = 'none'; } for (n=0 ; n < noData.length ; n++){ if (noData.item(n).id!="mostraLayout") noData.item(n).innerHTML = "Dia " + (m++); } var buttons = document.getElementsByName("deleteButton"); for (i = 0; i < buttons.length; i++) { button = buttons[i]; button.style.display = 'none'; } if (data > 1) buttons[buttons.length - 1].style.display = ''; /*if (data<2) { document.getElementById("deleteButton").style.display = "none"; }*/ } function showExtras(obj, idNumber){ var idExtras = 'servicos_extras' + idNumber; if (obj.checked == true){ document.getElementById(idExtras).style.display = 'inline' ; } if (obj.checked == false){ document.getElementById(idExtras).style.display = 'none' ; } } var valid = false; function checkName() { if ($("log").value!="") { $("log").style.background = styleWarn; new Ajax(url + "../../AjaxRequests/Orcamento.php", { postBody: "username=" + $("log").value, onComplete: function(data) { if (data=="valid") { $("log").style.background = styleValid; $("log_result").innerHTML = "Login válido"; return valid=true; } else if (data=="taken") { $("log").style.background = styleError; $("log_result").innerHTML = "Este login já está sendo usado"; return valid=false; } else if (data=="malformed") { $("log").style.background = styleError; $("log_result").innerHTML = "Login com caracteres inválidos"; return valid=false; } else if (data=="short") { $("log").style.background = styleError; $("log_result").innerHTML = "O login deve conter no mínimo 04 caracteres"; return valid=false; } else { $("log").style.background = styleError; $("log_result").innerHTML = "Login inválido"; return valid=false; } } }).request(); } else { $("log").style.background = styleDefault; $("log_result").innerHTML = ""; return valid=false; } } var validDates = new Array(); function checkDates(object) { object.style.background = styleWarn; //var dates = document.getElementsByName('date[]'); //for (i = 0; i < dates.length; i++) { //if (dates[i].value != '') if (object.value != '') { //var obj = dates[i]; var obj = object; new Ajax(url + "../../AjaxRequests/Orcamento.php", { //postBody: "date=" + dates[i].value, postBody: "date=" + object.value, onComplete: function(request) { if (request != '') { obj.style.background = styleError; validDates[object.value] = false; } else { obj.style.background = styleDefault; validDates[object.value] = true; } } }).request(); } } } function checkTime(id,event) { var val = $(id).value.replace(":",""); var key; if(!event) event=window.event; key = event.keyCode ? event.keyCode : event.which; //// Catch input //// // allow tab if (key == 9) return true; // does not work on IE // allow backspace and delete if (key == 8 || key == 46) { // delete the ':' as well if (val.length==2) $(id).value = val.replace(":",""); if (val.length==4) { val = val.replace(":",""); $(id).value = val.substr(0,1) + ":" + val.substr(1,3); } return true; } // field max length is 5 if (val.length > 3) return false; if ((key < 48 || key > 57)) return false; // max hour at a day is 24 if (val.length == 3 && parseInt(val.substr(0,2)) > 24) return false; //// Handle input // set the time format if (val.length==1) { $(id).value = val + ":"; } else if (val.length==3) { $(id).value = val.substr(0,2) + ":" + val.substr(2,1); } return true; } function checkPassword(warn) { with ($("solic_orcamento")) { if (senha.value!="" || senha_check.value!="") { if (senha.value.length<4) { senha.style.background = styleError; $("pass_result").innerHTML = "A senha deve ter no mínimo 04 caracteres"; return false } else if (senha.value!=senha_check.value) { if (warn) senha_check.style.background = styleWarn; else { senha.style.background = styleError; senha_check.style.background = styleError; $("pass_result").innerHTML = "As senhas digitadas não são iguais"; } return false; } else { senha.style.background = styleValid; senha_check.style.background = styleValid; $("pass_result").innerHTML = "Senha válida"; return true; } } else { senha.style.background = styleDefault; senha_check.style.background = styleDefault; $("pass_result").innerHTML = "Senha inválida"; return false; } } } function checkEmail(warn) { with ($("solic_orcamento")) { if (email.value!="" || email_check.value!="") { if (email.value!=email_check.value) { if (warn) email_check.style.background = styleWarn; else { email.style.background = styleError; email_check.style.background = styleError; $("email_result").innerHTML = "Os e-mails digitados não são iguais"; } return false; } else { email.style.background = styleValid; email_check.style.background = styleValid; $("email_result").innerHTML = "E-mail válido"; return true; } } else { email.style.background = styleDefault; email_check.style.background = styleDefault; $("email_result").innerHTML = "E-mail inválido"; return false; } } } function getLayouts(sendid, updateid) { $(updateid).setHTML('carregando'); new Ajax(url + "../../AjaxRequests/Orcamento.php", { postBody: "space=" + $(sendid).value, update: $(updateid) }).request(); } //// Form Validation //// function isInt(x) { var y=parseInt(x); if (isNaN(y)) return false; return x==y && x.toString()==y.toString(); } var reEmail = /^.+\@.+\..+$/ function isMail (s) { if (s=="") return false; else return reEmail.test(s) } function submit() { var obj = arguments[0]; var message = ""; var errors = new Array(); var warnings = new Array(); var elements = document.solic_orcamento.elements; // clear status for(elem in elements) if (elements[elem] && elements[elem].type=="text") elements[elem].style.background = styleDefault; // Clean up messy JavaScript array handling var days = new Array(); var dates = new Array(); var startTimes = new Array(); var endTimes = new Array(); var parts = new Array(); for (var i = 0;i < elements['inc[]'].length;i++) { days.push(elements['inc[]'][i]); dates.push(elements['date[]'][i]); startTimes.push(elements['startTime[]'][i]); endTimes.push(elements['endTime[]'][i]); parts.push(elements['participantes[]'][i]); } if (days.length==0) { days.push(elements['inc[]']); dates.push(elements['date[]']); startTimes.push(elements['startTime[]']); endTimes.push(elements['endTime[]']); parts.push(elements['participantes[]']); } // Check each dat that might have been added for (var i = 0; i < days.length; i++) { if (dates[i].value=="") { message += "- Data (campo não preenchido)\n"; errors.push(dates[i]); } else if (!validDates[dates[i].value]) { message += "- Data (data inválida)\n"; errors.push(dates[i]); } if (startTimes[i].value=="") { message += "- Hora inicial (campo não preenchido)\n"; errors.push(startTimes[i]); } if (endTimes[i].value=="") { message += "- Hora final (campo não preenchido)\n"; errors.push(endTimes[i]); } // Check if start time is smaller then end time if (startTimes[i].value!="" && endTimes[i].value!="") { var sh = parseInt(parseFloat(startTimes[i].value.split(":").shift())); var sm = parseInt(parseFloat(startTimes[i].value.split(":").pop())); var eh = parseInt(parseFloat(endTimes[i].value.split(":").shift())); var em = parseInt(parseFloat(endTimes[i].value.split(":").pop())); if (sh > 23 || sm > 59) { message += "- Hora inicial (a hora é inválida)\n"; errors.push(startTimes[i]); } if (eh > 23 || em > 59) { message += "- Hora final (a hora é inválida)\n"; errors.push(endTimes[i]); } if (!(sh < eh || (sh == eh && sm < em))) { message += "- Hora inicial / final (a hora inicial é maior que a hora final)\n"; errors.push(startTimes[i]); errors.push(endTimes[i]); } } if (!isInt(parts[i].value)) { message += "- Participantes (número de participantes não especificado)\n"; errors.push(parts[i]); } } // Check other (non repeatable) data of the form with ($("solic_orcamento")) { if (elements['empresa']) { if (cnpj.value=="" && tipocampo[0].checked) { message += "- CNPJ (campo não informado)\n" errors.push(cnpj); } if (empresa.value=="" && tipocampo[0].checked) { message += "- Empresa (nome de empresa não informado)\n"; errors.push(empresa); } if (cpf.value=="" && tipocampo[1].checked) { message += "- CPF (campo não informado)"; errors.push(cpf); } if (ddd.value!="" && !isInt(ddd.value)) { message += "- DDD (valor não numérico)\n"; errors.push(ddd); } else if (telefone.value=="") { errors.push(ddd); message += "- DDD (campo não preenchido)\n"; } if (telefone.value!="" && !isInt(telefone.value)) { message += "- Telefone (valor não numérico)\n"; errors.push(telefone); } else if (telefone.value=="") { errors.push(telefone); message += "- Telefone (campo não preenchido)\n"; } if (!isMail(email.value) || !checkEmail(true)) { message += "- E-mail (e-mail inválido)\n"; errors.push(email); } if (website=="") warnings.push(website); if (nome_solicitante.value=="") { message += "- Solicitante (campo não preenchido)\n"; errors.push(nome_solicitante); } if (!valid) { message += "- Login (o login não pode ser usado)\n"; errors.push(login); } if (!checkPassword(true)) { message += "- Senha (valor inválido)\n"; errors.push(senha); } } if (title.value=="") { message += "- Nome do evento (campo não preenchido)\n"; errors.push(title); } // Set warning color for(elem in warnings) if (warnings[elem].type=="text") warnings[elem].style.background = styleWarn; // Set error color for(elem in errors) if (errors[elem].type=="text" || errors[elem].type=="password") errors[elem].style.background = styleError; // Output error or submit if everything is okay if (message!="") { message = "Os dados informados no(s) campo(s) abaixo não são válidos:\n" + message alert(message); } else { if ($('sendButton')) { //$('sendButton').style.display = 'none'; //var _loading = document.createElement('a'); //_loading.innerText = 'Enviando'; //$('sendButton').getParent().appendChild(_loading); } $('botoes').style.display = 'none'; $('div_loading').style.display = 'block'; submit(); } } } /** * * * Funções para o select multiple * * */ //function add(from, to, save) function add(index) { from = $('equipamentos_available_' + index); to = $('equipamentos_selected_' + index); save = $('eq_' + index); eqType = $('equipamento_' + index); for (i = 0; i < from.options.length; i++) { var opt = from.options[i]; if (opt != null) { if (opt.selected) { var added = false; var value = eqType.value + ':' + opt.value; for (j = 0; j < to.options.length; j++) added = added || (to.options[j].value == value); if (!added) { to.options[to.length] = new Option(opt.text, value); save.value = save.value + value + ','; } } } } } //function remove(from) function remove(index) { from = $('equipamentos_selected_' + index); save = $('eq_' + index); for (i = 0; i < from.options.length; i++) { opt = from.options[i]; if (opt.selected) { var saved = save.value.split(','); save.value = ''; for (j = 0; j < saved.length - 1; j++) { if (saved[j] != opt.value) save.value = save.value + saved[j] + ','; } from.options[i] = null; i = 0; } } } //function addAll(from, to) function addAll(index) { from = $('equipamentos_available_' + index); to = $('equipamentos_selected_' + index); save = $('eq_' + index); eqType = $('equipamento_' + index); for (i = 0; i < from.options.length; i++) { var opt = from.options[i]; if (opt != null) { var added = false; var value = eqType.value + ':' + opt.value; for (j = 0; j < to.length; j++) added = added || (to.options[j].value == value); if (!added) { to.options[to.length] = new Option(opt.text, value); save.value = save.value + value + ','; } } } } //function removeAll(from) function removeAll(index) { from = $('equipamentos_selected_' + index); save = $('eq_' + index); while (from.options.length > 0) from.options[0] = null; save.value = ''; } /* * * * Funções para trocas dinâmicas * * */ function getEquipments(select, index) { new Ajax('ajaxRequests/Orcamento.php', { postBody: 'equipType=' + select.value + '&index=' + index, onComplete: function(request) { $('equipamentos_available_span_' + index).setHTML(request); } }).request(); } /* * * * Função para enviar um orçamento * * */ function sendToClient(eventId) { new Ajax("ajaxRequests/sendBudget.php", { postBody: 'eventId=' + eventId, onComplete: function(request) { //alert(request); $('conteudo').setHTML(request); } }).request(); } function orcamentoGetCompanyData() { with($('solic_orcamento')) { cnpj.style.background = styleWarn; empresa.style.background = styleWarn; ddd_tel.style.background = styleWarn; telefone.style.background = styleWarn; website.style.background = styleWarn; if (cnpj.value == '') { empresa.value = ''; empresa.disabled = ''; ddd_tel.value = ''; ddd_tel.disabled = ''; telefone.value = ''; telefone.disabled = ''; website.value = ''; website.disabled = ''; cnpj.style.background = styleDefault; empresa.style.background = styleDefault; ddd_tel.style.background = styleDefault; telefone.style.background = styleDefault; website.style.background = styleDefault; } else { new Ajax(url + '../../AjaxRequests/getCompanyData.php', { postBody: "cnpj=" + cnpj.value, onComplete: function(request) { if (request != '') { try { eval(request); //var _id = ... //var _address = ... //var _bairro = ... //var _cellular = ... //var _cep = ... //var _city = ... //var _cnpj = ... //var _complemento = ... //var _fax = ... //var _inscricaoEstadual = ... //var _name = ... //var _number = ... //var _phone = ... //var _solicitante = ... //var _state = ... //var _website = ... empresa.value = _name; empresa.disabled = 'disabled'; ddd_tel.value = _phone.split(' ')[0]; ddd_tel.disabled = 'disabled'; if (_phone.split(' ')[1]) telefone.value = _phone.split(' ')[1]; telefone.disabled = 'disabled'; website.value = _website; website.disabled = 'disabled'; } catch (e) { } } else { empresa.value = ''; empresa.disabled = ''; ddd_tel.value = ''; ddd_tel.disabled = ''; telefone.value = ''; telefone.disabled = ''; website.value = ''; website.disabled = ''; } cnpj.style.background = styleDefault; empresa.style.background = styleDefault; ddd_tel.style.background = styleDefault; telefone.style.background = styleDefault; website.style.background = styleDefault; } }).request(); } } } function passRetrieve() { with(document.getElementById('solic_orcamento')) { new Ajax(url + '../../esqueci.php', { postBody: 'login=' + login.value, onComplete: function(request) { alert(request); } }).request(); } }