// JavaScript Document

//função para fazer a alteração da imagem em "exposições"
function updateImg(pag,nro,wid) {
	if (pag == "exp") {
		document.images["view"].src = "../img/exp/exposicao_"+nro+".jpg";
		document.images["view"].width = wid;
		document.images["view"].height = 260;
	}
	if (pag == "obj") {
		document.images["view"].src = "../img/obj/objeto_"+nro+".jpg";
		//document.images["view"].width = wid;
		document.images["view"].height = 240;
	}
	if (pag == "ate") {
		document.images["view"].src = "../img/ate/atelie_"+nro+".jpg";
		document.images["view"].width = wid;
		document.images["view"].height = 260;
	}
}

//função para alterar o nome e legenda do produto
function updateTxt(nom, leg) {
	document.getElementById("pronom").innerHTML = nom;
	document.getElementById("proleg").innerHTML = leg;
}


//função para fazer o rollover do menu
function alterImg(img, destino) {
	img.src = "../img/"+destino;
}


//função que abre uma janela pop up
function abrirJanela(jan) {
	window.open(jan, "ref", "width=700, height=450, scrollbars=yes");
}

//funçaõ que faz uma validação em um e-mail enviado para a função
function validarEmail(email){
	//expressão regular...
	ex = /^[\w-]+(\.[\w-]+)*@(([A-Za-z\d][A-Za-z\d-]{0,61}[A-Za-z\d]\.)+[A-Za-z]{2,6}|\[\d{1,3}(\.\d{1,3}){3}\])$/;
	if ( ex.test(email) ) {
		return true;
	} else {
		return false;
	}
}
///-----------------------------------------


//função que verifica se todos os campos estão preenchidos...
//se for campo de e-mail, testa se é válido...
function isBlank(form){
	//passa como parâmetro o form
	//form = document.forms[nro];
	num_elem = form.elements.length;
	
	for (i=0; i<num_elem; i++){
		elem = form.elements[i];
		bugs = false;
		if ( (elem.type=="text" || elem.type=="password") && elem.id == "obriga" ){
			if (elem.value == ""){
				alert("Preenhca todos os campos obrigatórios!");
				elem.focus();
				bugs = true;
				break;
			}
		}
		
		if (elem.name == "email"){
			if (!validarEmail(elem.value)){
				alert("E-mail com formato inválido!");
				elem.focus();
				elem.select();
				bugs = true;
				break;
			} 
		}
	}//fim do for
	
		
	//para enviar o formulário... ou não...
	if (bugs){
		return false;
	} else {
		return true;
	}
}
//-----------------------------------------------------


// função para verificação dos dados... para a pagina de contato
function verificaDados(){
	email = document.f1.ema;
	assun = document.f1.ass;
	if (email.value == "") {
		alert("Campo E-MAIL é de preenchimento obrigatório!");
		email.focus();
		return false;
	}
	if (assun.value == "") {
		alert("Campo ASSUNTO é de preenchimento obrigatório!");
		assun.focus();
		return false;
	}
	
	if ( validarEmail(email.value) ) {
		return true;
	} else {
		alert("Campo E-MAIL com preenchimento errado!");
		email.focus();
		email.select();
		return false;
	}
}
//-----------------------------------------


//ABRIR E FECHAR PROPAGANDAS...
function abrirProp(){
	document.getElementById("prop").style.display = "block";
	document.getElementById("prop").style.position = "relative";
	document.getElementById("prop").style.top = "10px";
	document.getElementById("prop").style.left = "250px";
}
function fecharProp(){
	document.getElementById("prop").style.display = "none";
}
//---------------------------


//funçoes para o relógio "andando"
var timerID = null;
var timerRunning = false;
function stopClock (){
	if(timerRunning){
		clearTimeout(timerID);
	}
	timerRunning = false;
} 
function showTime() {
	now = new Date();
	day = now.getDate();
	mon = now.getMonth() + 1;
	yea = now.getFullYear();
	hours = now.getHours();
	minutes = now.getMinutes();
	seconds = now.getSeconds();
	
	//monta uma string com hora:minu:segu AM ou PM
	timeValue = "" + hours;
	timeValue += ((minutes < 10) ? ":0" : ":") + minutes;
	timeValue += ((seconds < 10) ? ":0" : ":") + seconds;
	document.getElementById("clock").innerHTML = day+"/"+mon+"/"+yea+" - "+timeValue;
	
	//chama a mesma função (recursivamente) de 1 em 1 segundo
	timerID = setTimeout("showTime()",1000);
	timerRunning = true;
}
function startClock () {
	stopClock();
	showTime();
}
//-------------------------------------


//função para limpar um formluário sendo enviado o objeto form
function limparForm(form) {
	nroe = form.elements.length;
	for(i=0; i<nroe; i++) {
		elem = form.elements[i];
		if (elem.type == "text") {
			elem.value = "";
		}
	}
}
//----------------------------------------------------



function mostrarImg(img) {
	document.imgbig.src = img.src;
}
//----------------------------------------------------