// JavaScript Document

function getCalendarForMonth(month, year){
  	var dayOfWeekArray = new Array("D", "S", "T", "Q","Q", "S", "S")
  	var monthArray = new Array("Janeiro", "Fevereiro", 
                   "Março", "Abril", "Maio", "Junho", 
                   "Julho", "Agosto", "Setembro", 
                   "Outubro", "Novembro", "Dezembro")
  	var noDaysArray = new Array(31, 28, 31, 30, 31, 30, 
                    31, 31, 30, 31, 30, 31)
  	var firstOfMonth = new Date(month + "/1/" + year )
  	var day = - firstOfMonth.getDay()

	var currentTime = new Date()
	var today = currentTime.getDate()

	// determine number of days in month
	var noDays = noDaysArray[month-1]
	if (month == 2){
		if((year % 4 == 0 && year % 100 != 0) || year % 400 == 0){
	  		noDays = 29
	  	}
	}

	//fabricate string for tables
	var strMonth = "<TABLE border='0' align='center' cellpadding='0' cellspacing='1' >"
	strMonth += "<TR><TD>"
	strMonth += "<TABLE border=0 cellpadding=3 cellspacing=0 align='center'>"
	strMonth += "</TR><TR bgcolor='#4CA0BA' align='center'>"
  	
	for(var i = 0; i<=6; i++){
		strMonth += "<TD width=10><FONT face='arial' color='white' size=1>"
    	strMonth += dayOfWeekArray[i] + "</FONT></TD>"
	}
  
  	strMonth += "</TR><TR align='right'>"

  	//fabricate first week of month
  	for (i = 0; i <= 6; i++){
    	strMonth += "<TD width=10><FONT face='arial' size=1 color='white'>"
    	day++
    	if(day > 0){
      		if (day == today)
				strMonth += "<span style='color:orange;'>"+day+"</span>"
			else
				strMonth += day
      	}else{
      		strMonth += " "
      	}
    	strMonth += "</FONT></TD>"
    }

  	//fabricate remaining weeks
  	for(var j=1; j < 6; j++){
    	strMonth += "</TR><TR align='right'>"
    	for (i = 0; i <= 6; i++){
      		strMonth += "<TD><FONT face='arial' size=1 color='white'>"
      		day++
      		if(day <= noDays){
				if (day == today)
        			strMonth += "<span style='color:#D3E213;'>"+day+"</span>"
				else
					strMonth += day
        	}else{
        		strMonth += " "
        	}
      		strMonth += "</FONT></TD>"
      	}
    	if (day >= noDays){
      		break;
      	}
    }
  	strMonth += "</TR></TABLE>"
  	strMonth += "</TD></TR></TABLE>"

  	return strMonth
}

function list_date(){
	var aux;
	
	<!-- Begin
	Stamp = new Date();
	year = Stamp.getYear();
	if (year < 2000) year = 1900 + year;
	aux = '' + Stamp.getDate() +"/"+(Stamp.getMonth() + 1)+ "/"+ year + '';
	var Hours;
	var Mins;
	var Time;
	Hours = Stamp.getHours();

	if (Hours == 0)
		Hours = 24;

	Mins = Stamp.getMinutes();
	if (Mins < 10)
		Mins = "0" + Mins;

	aux += '&nbsp;&nbsp;&nbsp;' + Hours + ":" + Mins + '';
	// End -->
	return aux;
}

function aceitaNums_telf()
{
	//alert(event.keyCode)// pra saber kal a tecla ke se carrega
	if (event.keyCode != 43){ // tecla +
		if ((event.keyCode < 48) || (event.keyCode > 57)  )
			event.returnValue = false
	}
}

function validaNumber(obj, valor_min, valor_max){
	//check if an value is number and if is on the interval
   if (isNaN(obj.value)){
      alert ("Valores Não Numéricos!");
      return false;
   }

	if (valor_min != 0 && valor_max != 0)
	   // check age range
	   if (parseInt(obj.value) < valor_min || parseInt(obj.value) > valor_max)
	   {
		  alert ("Valores fora do limite estabelecido! min:"+valor_min+" max:"+valor_max);
		  return false;
	   }
	
	return true;
}

// JavaScript Document
function toggleVisibility(me){
	if (me.style.visibility=="hidden"){
		me.style.visibility="visible";
	}else{
		me.style.visibility="hidden";
	}
}

function toggleLayer(whichLayer){

	if (document.getElementById){
		// this is the way the standards work
		var style2 = document.getElementById(whichLayer).style;
		style2.display = style2.display? "":"none";
	}else if (document.all){
		// this is the way old msie versions work
		var style2 = document.all[whichLayer].style;
		style2.display = style2.display? "":"none";
	}else if (document.layers){
		// this is the way nn4 works
		var style2 = document.layers[whichLayer].style;
		style2.display = style2.display? "":"none";
	}
}

//Create a center popup
function createwindow(url, largura, altura,Scroll,nome){
	esq = (screen.availWidth - largura ) / 2 -30;
	cim  = (screen.availHeight - altura) / 2 - 10 ;	
	janela = window.open(url,nome,"toolbar=no,width="+ largura + ",height=" + altura + ",left=" + esq + ",top=" + cim + ",scrollbars="+ Scroll +",directories=no,status=no,resize=no,menubar=no")
} 

function valid(){					

	if (document.forms.Contacto.nome.value.length < 3){
		alert('Por favor introduza o seu  nome!');
		return false;
	}

	if (!valid_Email(document.forms.Contacto.email.value,'O Email que indicou não é válido.') || document.forms.Contacto.email.value.length < 7) {
		alert('Por favor introduza um e-mail válido!');
		return false;					
	}

	if (document.forms.Contacto.assunto.value.length < 5) {
		alert('Por favor introduza sua mensagem!');
		return false;
	}
}

function submit_newsletter(){

	aux=0;
	if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(f_subscrever.email_newsletter.value)){
		return true;            
	}

	if (aux==0){
		alert("Endereço de E-mail inválido!")
		f_subscrever.email_newsletter.focus();
    	return false;
	}

	return true;
}

function aceitaNums_telf(){
	//alert(event.keyCode)// pra saber kal a tecla ke se carrega
	if (event.keyCode != 43){ // tecla +
		if ((event.keyCode < 48) || (event.keyCode > 57))
			event.returnValue = false
	}
}

function validaNumber(obj, valor_min, valor_max){
	//check if an value is number and if is on the interval
   if (isNaN(obj.value)){
      alert ("Valores Não Numéricos!");
      return false;
   }

	if (valor_min != 0 && valor_max != 0)
		if (parseInt(obj.value) < valor_min || parseInt(obj.value) > valor_max){// check age range
			alert ("Valores fora do limite estabelecido! min:"+valor_min+" max:"+valor_max);
		  	return false;
	   	}
	
	return true;
}

//______________________________________________________________
function valid_Email(email, msg){			

	email2='%'+email+'%';

	var re=/\%[a-z\-\_0-9]+(\.[a-z\-\_0-9]+)*@[a-z\-\_0-9]+(\.[a-z\-\_0-9]+)*\%/i;

	if (!email2.match(re))
		return false;

	var tam = email.length;
	var varA=0;
	var varB=0;

	for (i=0;i < tam;i++){
		caracter = email.substr(i,1);

		if(caracter == '@' && varA==0){
			varA = i;
		}

		if(caracter == '.' && varA>0 && varB==0){
			varB = i;				
		}		
	}

	var str1 = email.substr(0,varA);
	var str2 = email.substr(varA+1,varB-(varA+1));
	var str3 = email.substr(varB+1,tam);

	if(str1.length < 2 || str2.length < 2 || str3.length < 2){
		return false;
	}
	return true;
}

//___________________________________________________________________________
