// switch form input
function switch_frm_ipt(getObj) {
switch (getObj.value) {
	case 'email':
		getObj.value = '';
		break;
	case 'senha':
		getObj.value = '';
		break;
	case 'pesquisar...':
		getObj.value = '';
		break;
	case 'informe seu email':
		getObj.value = '';
		break;
	case '':
		if (getObj.name == 'emailLogin') {
			getObj.value = 'email';
		} else if (getObj.name == 'senhaLogin') {
			getObj.value = 'senha';
		} else if (getObj.name == 'q') {
			getObj.value = 'pesquisar...';
		} else if (getObj.name == 'nlmail') {
			getObj.value = 'informe seu email';
		}
		break;
	}
}

// valida login
function validaLogin() {
var emailFilter=/^.+@.+\..{2,3}$/;
var illegalChars= /[\(\)\<\>\,\;\:\!\ \\\/\'\"\[\]]/;
var uE = document.header_l_frm.emailLogin;
var uP = document.header_l_frm.senhaLogin;

if (!(emailFilter.test(uE.value)) || uE.value.match(illegalChars)) {
	alert('Por favor, informe corretamente seu endereço de e-mail.');
	uE.focus();
	return false;
	}
if (uP.value==='' || uP.value==='senha') {
	alert('Por favor, informe sua senha de acesso.');
	uP.focus();
	return false;
	}
	document.header_l_frm.submit();
}

// valida newsletter
function validaNewsletter() {
var emailFilter=/^.+@.+\..{2,3}$/;
var illegalChars= /[\(\)\<\>\,\;\:\!\ \\\/\'\"\[\]]/;
var nlE = document.right_nl_frm.nlmail;
if (!(emailFilter.test(nlE.value)) || nlE.value.match(illegalChars)) {
	alert('Por favor, informe corretamente seu endereço de e-mail.');
	nlE.focus();
	return false;
	}
	document.right_nl_frm.submit();
}

// ads functions
function adLoad(xID,adF,adSize) {
adArray = adSize.split('|');

document.write('<iframe frameborder="no" scrolling="no" src="http://www.musitec.com.br/ads/load/?xid='+xID+'&adF='+adF+'&adW='+adArray[0]+'&adH='+adArray[1]+'" width="'+adArray[0]+'" height="'+adArray[1]+'" allowtransparency="true"></iframe>');
}

function adOfertas(xID,adF) {
document.write('<iframe frameborder="no" scrolling="no" src="http://www.musitec.com.br/ads/ofertas/?xid='+xID+'&adF='+adF+'" width="740" height="90" allowtransparency="true"></iframe>');
}

// Show Hide
function showHide(getObj,getVisibility) {
if (document.getElementById) {
	var targetElement = document.getElementById(getObj);
	targetElement.style.visibility = getVisibility;
	}
}

function displaySwitch(getObj,getDisplay) {
if (document.getElementById) {
	var targetElement = document.getElementById(getObj);
	targetElement.style.display = getDisplay;
	}
}

function displayToggle(getObj) {
if (document.getElementById) {
	var targetElement = document.getElementById(getObj);
	switch (targetElement.style.display) {
		case '':
			targetElement.style.display = "block";
			break;
		case 'none':
			targetElement.style.display = "block";
			break;
		case 'block':
			targetElement.style.display = "none";
			break;
		}
	}
}

// Http Request
function openRequest() {
	var getRequest;
	try {getRequest = new XMLHttpRequest();}
	catch(ee) {
		try {getRequest = new ActiveXObject("Msxml2.XMLHTTP");}
		catch(e) {try {getRequest = new ActiveXObject("Microsoft.XMLHTTP");}
		catch(e) {getRequest = false;}
		}
	}
return getRequest;
}

function loadEmbed(getArea,getApp) {
if (document.getElementById) {
	var exibeResultado = document.getElementById(getArea);
	var getRequest = openRequest();
	getRequest.open("GET", getApp, true);
	getRequest.onreadystatechange = function() {
		if (getRequest.readyState == 1) {
			if (getArea == 'loadThumbs') {
				exibeResultado.innerHTML = '<div id="loaderBox_thumbs"></div>';
			} else {
				exibeResultado.innerHTML = '<div id="loaderBox">Carregando...</div>';
			}
		}
	if (getRequest.readyState == 4) {
		if (getRequest.status == 200) {
			var resultado = getRequest.responseText;
			resultado = resultado.replace(/\+/g," ");
			resultado = unescape(resultado);
			exibeResultado.innerHTML = resultado;
			} else {
				exibeResultado.innerHTML = '<div id="loaderBoxError">Falha ao carregar!</div>';
			}
		}
	};
	getRequest.send(null);
	}
}

// forms count
function charCount(counterID, counterValue) {
if (document.getElementById) {
	var exibeResultado = document.getElementById(counterID);
		exibeResultado.innerHTML = "<b>" +counterValue+"</b> caracteres disponíveis";
	}
}

// comments save
function commentSave(cArea,cID) {
var commNome = document.commentForm.comm_nome;
var commTexto = document.commentForm.comm_texto;

if (commTexto.value==='') {
	document.getElementById("content_comment_eb").style.display = 'block';
	document.getElementById("content_comment_eb").innerHTML = 'Por favor, digite o texto de seu comentário.';
	window.self.location = '#content_comment_eb';
	commTexto.focus();
	return false;
	} else {
		document.getElementById("content_comment_eb").style.display = 'none';
		document.getElementById("content_comment_eb").innerHTML = '';
	}
if (commNome.value==='') {commNome.value='Anônimo';}
loadEmbed('content_comment_form','/_includes_new/comments/save/?ca='+cArea+'&c='+cID+'&commNome='+commNome.value+'&commTexto='+escape(commTexto.value));
}

// classificados save
function classificadosSave() {
var classificadosTitulo = document.classificadosForm.classificados_titulo;
var classificadosArea = document.classificadosForm.classificados_area;
var classificadosDesc = document.classificadosForm.classificados_desc;
var classificadosNome = document.classificadosForm.classificados_nome;
var classificadosTelefone = document.classificadosForm.classificados_telefone;
var classificadosEmail = document.classificadosForm.classificados_email;
var classificadosSite = document.classificadosForm.classificados_site;

if (classificadosTitulo.value==='') {
	document.getElementById("filterBox_form_eb").style.display = 'block';
	document.getElementById("filterBox_form_eb").innerHTML = 'Por favor, informe o título do anúncio.';
	window.self.location = '#filterBox_form_eb';
	classificadosTitulo.focus();
	return false;
	} else {
		document.getElementById("filterBox_form_eb").style.display = 'none';
		document.getElementById("filterBox_form_eb").innerHTML = '';
	}
if (classificadosArea.value==='') {
	document.getElementById("filterBox_form_eb").style.display = 'block';
	document.getElementById("filterBox_form_eb").innerHTML = 'Por favor, selecione a área do anúncio.';
	window.self.location = '#filterBox_form_eb';
	classificadosArea.focus();
	return false;
	} else {
		document.getElementById("filterBox_form_eb").style.display = 'none';
		document.getElementById("filterBox_form_eb").innerHTML = '';
	}
if (classificadosDesc.value==='') {
	document.getElementById("filterBox_form_eb").style.display = 'block';
	document.getElementById("filterBox_form_eb").innerHTML = 'Por favor, digite a descrição do anúncio.';
	window.self.location = '#filterBox_form_eb';
	classificadosDesc.focus();
	return false;
	} else {
		document.getElementById("filterBox_form_eb").style.display = 'none';
		document.getElementById("filterBox_form_eb").innerHTML = '';
	}
if (classificadosNome.value==='') {
	document.getElementById("filterBox_form_eb").style.display = 'block';
	document.getElementById("filterBox_form_eb").innerHTML = 'Por favor, informe o seu nome.';
	window.self.location = '#filterBox_form_eb';
	classificadosNome.focus();
	return false;
	} else {
		document.getElementById("filterBox_form_eb").style.display = 'none';
		document.getElementById("filterBox_form_eb").innerHTML = '';
	}
if (classificadosTelefone.value=='' && classificadosEmail.value=='' && classificadosSite.value=='') {
	document.getElementById("filterBox_form_eb").style.display = 'block';
	document.getElementById("filterBox_form_eb").innerHTML = 'Telefone, email ou site: ao um menos um dos 3 campos deve ser preenchido.';
	window.self.location = '#filterBox_form_eb';
	classificadosTelefone.focus();
	return false;
	} else {
		document.getElementById("filterBox_form_eb").style.display = 'none';
		document.getElementById("filterBox_form_eb").innerHTML = '';
	}
loadEmbed('newClassificadosBox','/_includes_new/classificados/save/?classificadosTitulo='+classificadosTitulo.value+'&classificadosArea='+classificadosArea.value+'&classificadosNome='+classificadosNome.value+'&classificadosTelefone='+classificadosTelefone.value+'&classificadosEmail='+classificadosEmail.value+'&classificadosSite='+classificadosSite.value+'&classificadosDesc='+escape(classificadosDesc.value));
}

// links save
function linksSave() {
var linksNome = document.linksForm.links_nome;
var linksArea = document.linksForm.links_area;
var linksUrl = document.linksForm.links_url;
var linksDesc = document.linksForm.links_desc;

if (linksNome.value==='') {
	document.getElementById("filterBox_form_eb").style.display = 'block';
	document.getElementById("filterBox_form_eb").innerHTML = 'Por favor, informe o nome do site.';
	window.self.location = '#filterBox_form_eb';
	linksNome.focus();
	return false;
	} else {
		document.getElementById("filterBox_form_eb").style.display = 'none';
		document.getElementById("filterBox_form_eb").innerHTML = '';
	}
if (linksArea.value==='') {
	document.getElementById("filterBox_form_eb").style.display = 'block';
	document.getElementById("filterBox_form_eb").innerHTML = 'Por favor, selecione a área de atuação.';
	window.self.location = '#filterBox_form_eb';
	linksArea.focus();
	return false;
	} else {
		document.getElementById("filterBox_form_eb").style.display = 'none';
		document.getElementById("filterBox_form_eb").innerHTML = '';
	}
if (linksUrl.value==='') {
	document.getElementById("filterBox_form_eb").style.display = 'block';
	document.getElementById("filterBox_form_eb").innerHTML = 'Por favor, informe o endereço do site.';
	window.self.location = '#filterBox_form_eb';
	linksUrl.focus();
	return false;
	} else {
		document.getElementById("filterBox_form_eb").style.display = 'none';
		document.getElementById("filterBox_form_eb").innerHTML = '';
	}
if (linksDesc.value==='') {
	document.getElementById("filterBox_form_eb").style.display = 'block';
	document.getElementById("filterBox_form_eb").innerHTML = 'Por favor, digite a descrição do site.';
	window.self.location = '#filterBox_form_eb';
	linksDesc.focus();
	return false;
	} else {
		document.getElementById("filterBox_form_eb").style.display = 'none';
		document.getElementById("filterBox_form_eb").innerHTML = '';
	}

loadEmbed('newLinkBox','/_includes_new/links/save/?linksNome='+linksNome.value+'&linksArea='+linksArea.value+'&linksUrl='+linksUrl.value+'&linksDesc='+escape(linksDesc.value));
}


// Send message
function sendMessage() {
var emailFilter=/^.+@.+\..{2,3}$/;
var illegalChars= /[\(\)\<\>\,\;\:\!\ \\\/\'\"\[\]]/;
var contatoPara = document.contatoForm.contato_para;
var contatoNome = document.contatoForm.contato_nome;
var contatoEmail = document.contatoForm.contato_email;
var contatoTexto = document.contatoForm.contato_texto;

if (contatoPara.value==='') {
	document.getElementById("contato_form_eb").style.display = 'block';
	document.getElementById("contato_form_eb").innerHTML = 'Por favor, selecione um destinatário.';
	window.self.location = '#contato_form_eb';
	contatoPara.style.backgroundColor='#ffffd9';
	contatoPara.focus();
	return false;
	} else {
		document.getElementById("contato_form_eb").style.display = 'none';
		document.getElementById("contato_form_eb").innerHTML = '';
		contatoPara.style.backgroundColor='';
	}
if (contatoNome.value==='') {
	document.getElementById("contato_form_eb").style.display = 'block';
	document.getElementById("contato_form_eb").innerHTML = 'Por favor, informe o seu nome.';
	window.self.location = '#contato_form_eb';
	contatoNome.style.backgroundColor='#ffffd9';
	contatoNome.focus();
	return false;
	} else {
		document.getElementById("contato_form_eb").style.display = 'none';
		document.getElementById("contato_form_eb").innerHTML = '';
		contatoNome.style.backgroundColor='';
	}
if (!(emailFilter.test(contatoEmail.value)) || contatoEmail.value.match(illegalChars)) {
	document.getElementById("contato_form_eb").style.display = 'block';
	document.getElementById("contato_form_eb").innerHTML = 'Por favor, informe corretamente seu endereço de e-mail.';
	window.self.location = '#contato_form_eb';
	contatoEmail.style.backgroundColor='#ffffd9';
	contatoEmail.focus();
	return false;
	} else {
		document.getElementById("contato_form_eb").style.display = 'none';
		document.getElementById("contato_form_eb").innerHTML = '';
		contatoEmail.style.backgroundColor='';
	}
if (contatoTexto.value==='') {
	document.getElementById("contato_form_eb").style.display = 'block';
	document.getElementById("contato_form_eb").innerHTML = 'Por favor, digite o texto de sua mensagem.';
	window.self.location = '#contato_form_eb';
	contatoTexto.style.backgroundColor='#ffffd9';
	contatoTexto.focus();
	return false;
	} else {
		document.getElementById("contato_form_eb").style.display = 'none';
		document.getElementById("contato_form_eb").innerHTML = '';
		contatoTexto.style.backgroundColor='';
	}
loadEmbed('contato_form_box','/_includes_new/contato_post/?contatoPara='+contatoPara.value+'&contatoNome='+contatoNome.value+'&contatoEmail='+contatoEmail.value+'&contatoTexto='+escape(contatoTexto.value));
}

// Download file
function downloadFile(filePath,fileName) {
	var downloadIFrame = document.createElement("iframe");
	downloadIFrame.src = "/_includes_new/downloads/?fp=" + filePath + "&fn=" + fileName;
	downloadIFrame.style.display = "none";
	document.body.appendChild(downloadIFrame);
}

// Select code
function selectCode(divID) { 
var textC=document.getElementById(divID);
if (document.selection) {
	var div = document.body.createTextRange();
	div.moveToElementText(textC);
	div.select();
} else {
	var div = document.createRange();
	div.setStartBefore(textC);
	div.setEndAfter(textC);
	window.getSelection().addRange(div);
	} 
}
