// JavaScript Document
function mostraFlash(src, larg, alt, vars){
	var flash = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0" width="'+ larg +'" height="'+ alt +'">';
	flash += '<param name="movie" value="'+ src +'" />';	
	flash += '<param name="menu" value="false" />';	
	flash += '<param name="wmode" value="transparent" />';	
	flash += '<embed src="'+ src +'" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="'+ larg +'" height="'+ alt +'" menu = "false" wmode="transparent"></embed>';
	flash += '</object>';	
	document.write(flash);
}

var popUpWin=0;

function popUp(URLStr, width, height) {
	var left = (screen.width) ? (screen.width-width)/2 : 0;
	var top = (screen.height) ? (screen.height-height)/2 : 0;
  	if(popUpWin) {
		if(!popUpWin.closed) popUpWin.close();
	}
	popUpWin = open(URLStr, 'popUpWin', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,copyhistory=yes,width='+width+',height='+height+',left='+left+', top='+top+',screenX='+left+',screenY='+top+'');
}


function isVisible(obj){  //verifica se o elemento está visivel
	if(!obj.parentNode){return false;}
	while(obj.parentNode!=null){
		if(obj.style.display.toLowerCase()=='none' || obj.style.visibility.toLowerCase()=='hidden'){return false;}
		obj=obj.parentNode;
	}
	return true;
}

String.prototype.trim=function(){  //trim leading or trailing whitespace and extra spaces
	return this.replace(/^\s*/, "").replace(/\s*$/, "").replace(/\s{2,}/, " ");
}

function showImg(src, title)
{
  //criando um link falso, para o LightBox captar as informações
  var a_false = document.createElement("A");
  a_false.rel = "lightbox";
  a_false.href = src;
  a_false.title = title;
  //chamando a função do lightbox responsável pelo início das ações
  myLightbox.start(a_false);
  //anulando o link
  a_false = null;
}

function mudaSrc (id, src) {
	document.getElementById(id).src = src;
	return;
}


function showHide(id) {
	style = document.getElementById(id).style;
	if (style.display=='none') {
		style.display='';
		mostrandoMenu = true;
	} else {
		style.display='none';
		mostrandoMenu = false;
	}
	return;
}


function show(id) {
	style = document.getElementById(id).style;
	style.display='';
	mostrandoMenu = true;
	return;
}
function hide(id) {
	style = document.getElementById(id).style;
	style.display='none';
	mostrandoMenu = false;
	return;
}


function checkEmail(valor){
	if(valor==''){return true;}
	if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(valor)){return (true);}
	return (false);
}

function checkdate(d,m,y)
{
	if(!IsNumeric(d) || !IsNumeric(m) || !IsNumeric(y) || d.length<2 || m.length<2 || y.length<4){return false;}
	var yl=1900; // least year to consider
	var ym=2500; // most year to consider
	if (m<1 || m>12) return(false);
	if (d<1 || d>31) return(false);
	if (y<yl || y>ym) return(false);
	if (m==4 || m==6 || m==9 || m==11)
	if (d==31) return(false);
	if (m==2)
	{
		var b=parseInt(y/4);
		if (isNaN(b)) return(false);
		if (d>29) return(false);
		if (d==29 && ((y/4)!=parseInt(y/4))) return(false);
	}
	return(true);
}

function IsNumeric(sText)
{
	var ValidChars = "0123456789";
	var IsNumber=true;
	var Char;
	for (i = 0; i < sText.length && IsNumber == true; i++) 
	{ 
		Char = sText.charAt(i); 
		if (ValidChars.indexOf(Char) == -1) 
		{
			IsNumber = false;
		}
	}
	return IsNumber;
}

function isHour(value){
	if(value==''){alert('Favor digite uma hora.');return false;}
	var splitted=value.split(':');
	var hora=splitted[0];
	var minuto=splitted[1];
	var segundo=splitted[2];
	if(!IsNumber(hora) || !IsNumber(minuto) || !IsNumber(segundo) || hora>24 || minuto>59 || segundo>59){return false;}
	return true;
}


function checaCampos(form){  //verifica o preenchimento obrigatorios dos campos antes de enviá-los
	if(!form){return false;}
	var element,enviar=true;
	for(var i=0;i<form.elements.length;i++){
		element=form.elements[i];
		if(element.className.indexOf('required')>=0){  //campo requerido
			if(!isVisible(element)){continue;}
			if(element.type.toUpperCase()=='CHECKBOX'){  //se for um checkbox
				checkboxes=document.getElementsByName(element.name);
				for(var c=0;c<checkboxes.length;c++){
					if(checkboxes[c].checked){break;}
				}
				if(c<checkboxes.length){continue;}
				alert(element.title);
				element.focus();
				return false;
			}
			if(element.value.length<=0){  //nao preenchido
				if(element.type.toUpperCase().indexOf('SELECT')>=0){
					alert(element.title);
				}else{
					if(!isVisible(element)){continue;}
					alert(element.title);
				}
				element.focus();
				enviar=false;
				break;
			}
		}
		if(element.className.indexOf('email')>=0){  //campo tipo email
			if(!checkEmail(element.value.trim())){
				alert(element.title);
				element.focus();
				enviar=false;
				break;
			}
		}
		if(element.className.indexOf('hour')>=0){  //campo tipo hora HH:mm:ss
			if(!isHour(element.value.trim())){
				alert(element.title);
				element.focus();
				enviar=false;
				break;
			}
		}
		if(element.className.indexOf('number')>=0){  //campo tipo numero
			if(!IsNumeric(element.value.trim())){
				alert(element.title);
				element.focus();
				enviar=false;
				break;
			}
		}
		if(element.className.indexOf('day')>=0){  //campo tipo numero
			if(!IsNumeric(element.value.trim())&&!isDay(element.value.trim())){
				alert(element.title);
				element.focus();
				enviar=false;
				break;
			}
		}
	}
	return enviar;
}

function abreFoto(src){
	window.open("foto.php?src="+src, "Foto", "width=40,height=40,top=90,left=90,menubar=no,location=no,resizable=no,scrollbars=0,status=no");
}

function toggle(idName,visible){
	var obj;
	if(typeof(idName)=='object'){obj=idName;}else{obj=document.getElementById(idName);}
	if(!obj){return;}
	if(visible>0){  //force display
		obj.style.display="";
		return 1;
	}
	else if(visible<0){  //force hide
		obj.style.display="none";
		return -1;
	}
	else{  //toggle display on/off
		if(obj.style.display=='none'){
			obj.style.display="";
			return 1;
		}
		else{
			obj.style.display="none";
			return -1;
		}
	}
}