// JavaScript Document

// muda o filtro dos produtos
function loadURL (DivID,url) {
	var date = new Date();
	var d  = date.getDate();	
	var randomnumber=Math.floor(Math.random()*111010101)
	$(DivID).innerHTML='';
	var RegionAjax=new Ajax(url, {
		method: 'get',
		data: 'date='+randomnumber,
		evalScripts: true,
		update: $(DivID)
	}).request(); 
}


function loadURL2 (DivID,url) {
	var date = new Date();
	var d  = date.getDate();
	var randomnumber=Math.floor(Math.random()*111010101)
	var RegionAjax=new Ajax(url, {
		method: 'get',
		data: 'date='+randomnumber,
		evalScripts: true,
		update: $(DivID),
		onComplete: function Fecha(){setTimeout("DivOff('"+DivID+"')",4000);}
	}).request(); 
}

function sendForm(DivID,formulario,url) {
	$(formulario).action=url;
	$(formulario).send({
		method: 'post',
		evalScripts: true,
		update: DivID
		});
}

function DivOff(DivID) {
			$(DivID).style.display='none';
		}

function DivOn(DivID) {
			$(DivID).style.display='block';
		}

function sendForm2(DivID,formulario,url) {
	$(formulario).action=url;
	$(formulario).send({
		method: 'post',			
		update: DivID,
		evalScripts: true,
		onComplete: function Fecha(){setTimeout("DivOff('"+DivID+"')",2000);}
		});
}

// update 
		function upSupl(formulario,cod_supl,cod_hotel,DivID) {			
			$(formulario).action='supl_form.asp?tab=insSuplSQL&oper=3&cod_supl='+cod_supl+'&cod_hotel='+cod_hotel;			
			if($('tipo_'+cod_supl).checked)
				tipo_temp=0
			else
				tipo_temp=1;			
			$(formulario).send({										
					//data:'texto='+$('texto'+cod_supl).value+'&tipo='+tipo_temp+'&valor='+$('valor_'+cod_supl).value+'&obriga='+$('obriga_'+cod_supl).checked+'&room='+$('room_'+cod_supl).checked+'&person='+$('person_'+cod_supl).checked,
					//data:'tipo='+tipo_temp+'&valor='+$('valor_'+cod_supl).value+'&obriga='+$('obriga_'+cod_supl).checked+'&room='+$('room_'+cod_supl).checked+'&person='+$('person_'+cod_supl).checked,
					method: 'post',
					evalScripts: true,
					onComplete:function focusDiv(){$('Text'+cod_supl).focus();setTimeout("DivOff('"+DivID+"')",4000);},
					update: DivID
				});
			
		}

function openModal(url) {
			MOOdalBox.open(				
				url, // the link URL
				"", // the caption (link's title) - can be blank
				"560 330" // width and height of the box - can be left blank				
				);
		}

function openModalXY(url,width,height) {
			var randomnumber=Math.floor(Math.random()*111010101);
			MOOdalBox.open(				
				url+'&op='+randomnumber, // the link URL
				"", // the caption (link's title) - can be blank
				width+" "+height // width and height of the box - can be left blank				
				);
		}
		
		
function tdmouseover(el) {
	el.style.color = "yellow"
	el.style.backgroundColor = "#c0c0c0"
}

function tdmouseout(el) {
	el.style.color = "black"
	el.style.backgroundColor = "white"
}

function closeDestaques() {
		MOOdalBox.close();
		myTabs.activate('destaques');
}


function onSubmitForm() {	
		var formDOMObj = document.frmSend;
		if (formDOMObj.attach1.value == "" && formDOMObj.attach2.value == "" && formDOMObj.attach3.value == "" && formDOMObj.attach4.value == "" )
			alert("Escolha os ficheiros.")
		else
			sendForm('fotosDIV','frmSend','upload.asp?idcategorias=<%=idcategorias%>');
	}
	
function contadorTextArea(campo,compcampo,maximo) {
	if (campo.value.length > maximo)
		campo.value = campo.value.substring(0, maximo); // trim se demasiado longo
		// actualiza os caracteres livres
	else
		compcampo.value = maximo - campo.value.length;
}

function changeData(datai,dataf) {			
			var output = Date.parse($(datai).value);
			var mydate = new Date(output);
			var ano=mydate.getFullYear();
			var mes=mydate.getMonth()+1;
			var dia=mydate.getDate()+1;
			
			// verifica&ccedil;&atilde;o se a data esta no fim do mes e ai tem que passar para o mes seguint
			switch (mes)
			{
			case 1,3,5,7,8,10:
			if (dia>31)	{
					//alert("deveria mudar");
					dia=1;
					mes=mes+1;
				}
				else {
					//alert("num fez nada");
				}
				break;
			case 12:				
				if (dia>31)	{
					//alert("deveria mudar");
					dia=1;
					mes=1;
					ano++;
				}
				else {
					//alert("num fez nada");
				}
				break;
			case 2:				
				// verificar se &eacute; bisexto
				 if (!( ((ano%4)==0) && ( ((ano%100)!=0) || ((ano%400)==0) ) )) teste=1; 
				 if (teste)
				  	dias=29;
				else
					dias=28;
				if (dia == dias)
				{
					dia=1;
					mes=mes+1;
				}
				break;
			default:				
				if (dia>30)
				{
					dia=1;
					mes=mes+1;
				}
			}
			
			ano = ano.toString();
			
			dia = dia.toString();
			mes = mes.toString();			
			//alert (ano.substring(1));
			//var datas =((mydate.getMonth()+1)+'/'+(mydate.getDate()+1)+'/'+ano);
			var datas=mes+'/'+dia+'/'+ano;
			//var datas=ano+'-'+mes+'-'+dia;
			//alert(datas);
			$(dataf).value=datas;
		}