function validacao_form(obri,campo,formato){
	ok=validacao_obrigatorio(obri);
	if (ok==false) {
		return ok;
	}
	ok=validacao_formato(campo,formato);
	return ok;
}

function validacao_obrigatorio(campo){
	for (i=0 ;i<campo.length;i++) {
		if (typeof(document.getElementById(campo[i]))=="object") {
			if (document.getElementById(campo[i]).value=='') {
				document.getElementById(campo[i]).focus();
				alert("Tem que preencher os campos obrigatórios");
				return false;
			}
		}else{
			var campos=document.getElementById(campo[i]+"[]");
			var ok=false;
			if (campos.length>1){
				for (y=0;y<campos.length ;y++ ) {
					if (campos[y].checked==true) {
						ok=true;
					}
				}
			}else{
				if (campos.checked==true) {
					ok=true;
				}
			}
			if (ok==false){
				campos.focus();
				alert("Tem que preencher os campos obrigatórios");
				return false;
			}
		}
	}
	return true;
}

function validacao_formato(campo,formato){
	for (i=0;i<campo.length;i++) {
		valor=document.getElementById(campo[i]).value;
		if (valor!=''){
			switch (formato[i]) {
				case '2':
					var validformat=/^[0-9\.,]+$/;
					if (!validformat.test(valor)) {
						document.getElementById(campo[i]).focus();
						alert("O campo não esta correctamente preenchido.\nO campo tem que ser em formato numérico");
						return false;
					}
					break
				case '3':
					var validformat=/^[a-zA-Z0-9\-\._]+@[a-zA-Z0-9\-_]+(\.?[a-zA-Z0-9\-_]*)\.[a-zA-Z]{2,3}$/;
					if (!validformat.test(valor)) {
						document.getElementById(campo[i]).focus();
						alert("O campo não esta correctamente preenchido.\nO campo não tem um email válido");
						return false;
					}
					break
				case '4':
					var validformat=/^\d{2}-\d{2}-\d{4}$/;
					if (!validformat.test(valor)) {
						document.getElementById(campo[i]).focus();
						alert("O campo não esta correctamente preenchido.\nO campo não tem uma data válida (dd-mm-aaaa)");
						return false;
					}
					break
			}
		}
	}
	return true;
}



function form_venda_extra(value){
	display='none';
	visible='hidden';
	var div=document.getElementById("form_venda_exta");
	if (value=="mini") {
		display='block';
		visible='visible';
	}
	div.style.display=display;
	div.style.visibility=visible;
}

function open_upload(id_campo){
	var win=window.open("upload.php?campo="+id_campo, "upload"+id_campo,
			      "toolbar=no,menubar=no,personalbar=no,width=500,height=255," +
			      "scrollbars=no,resizable=no");
}

function nav_foto(open){
	var i=0;
	var style='';
	while(document.getElementById("foto_"+i)){
		if (i==open) {
			style='';
		}else{
			style='none';
		}
		document.getElementById("foto_"+i).style.display=style;
		i++;
	}
}

function menu(open){
	var i=1;
	var display='';
	while(document.getElementById("menu_"+i)){
		if (i==open) {
			display='';
		}else{
			display='none';
		}
		document.getElementById("menu_"+i).style.display=display;
		i++;
	}
}

function page_galeria_next(){
	var max=0;
	var i=1;
	var open=1;
	while(document.getElementById("pag_gal_"+i)){
		max=i;
		if (document.getElementById("pag_gal_"+i).style.display!='none') {
			open=i;
		}
		i++;
	}
	if (open<max){
		open++;
	}
	page_galeria(open);
	return false;
}

function page_galeria_back(){
	var max=0;
	var i=1;
	var open=1;
	while(document.getElementById("pag_gal_"+i)){
		max=i;
		if (document.getElementById("pag_gal_"+i).style.display!='none'){
			open=i;
		}
		i++;
	}
	if (open>1){
		open--;
	}
	page_galeria(open);
	return false;
}

function page_galeria(open){
	var i=1;
	var display='';
	while(document.getElementById("pag_gal_"+i)){
		if (i==open) {
			display='';
		}else{
			display='none';
		}
		document.getElementById("pag_gal_"+i).style.display=display;
		i++;
	}
	return false;
}

function open_recomenda(){
	window.open("recomenda.php", "JANELA", "height = 400, width = 500");
}