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

	function findObj(theObj, theDoc)
	{
	  var p, i, foundObj;
	  
	  if(!theDoc) theDoc = document;
	  if( (p = theObj.indexOf("?")) > 0 && parent.frames.length)
	  {
		theDoc = parent.frames[theObj.substring(p+1)].document;
		theObj = theObj.substring(0,p);
	  }
	  if(!(foundObj = theDoc[theObj]) && theDoc.all) foundObj = theDoc.all[theObj];
	  for (i=0; !foundObj && i < theDoc.forms.length; i++) 
		foundObj = theDoc.forms[i][theObj];
	  for(i=0; !foundObj && theDoc.layers && i < theDoc.layers.length; i++) 
		foundObj = findObj(theObj,theDoc.layers[i].document);
	  if(!foundObj && document.getElementById) foundObj = document.getElementById(theObj);
	  
	  return foundObj;
	}

	function showHideLayers()
	{ 
	  var i, visStr, obj, args = showHideLayers.arguments;
	  for (i=0; i<(args.length-2); i+=3)
	  {
		if ((obj = findObj(args[i])) != null)
		{
		  visStr = args[i+2];
		  if (obj.style)
		  {
			obj = obj.style;
			if(visStr == 'show') visStr = 'visible';
			else if(visStr == 'hide') visStr = 'hidden';
		  }
		  obj.visibility = visStr;
		}
	  }
	}

	var msgWait = 'Aguarde por favor...';
	var days_text = new Array();
	var days_value = new Array();
	
	var hours_text = new Array();
	var hours_value = new Array();

	var empty_text = new Array();
	var empty_value = new Array();
	
	empty_text[0] = '&nbsp;';
	empty_value[0] = null;

	function f_updateBox (el,val,enable)
	{
		value = eval(val + '_value');
		text = eval(val + '_text');

		el.options.length = 0;
		el.options.length = value.length;
		
		j=0;
		for (i in value)
		{
			el.options[j].text = text[i];
			el.options[j].value = value[i];
			if (value[i]==0) el.options[j].disabled = "disabled";
			j++;
		}
		
		if (enable) el.disabled = false;
		else el.disabled = true;
	}
	
	function f_getDays (id)
	{
		if (id!=null && id!='' && id!='0')
		{
			findObj('divData').style.display = 'none';
			findObj('divHora').style.display = 'none';
	
			findObj('divMsg').style.display = 'block';
		
			findObj('msgTxtTit').innerHTML = 'Data';
			findObj('msgTxt').innerHTML = msgWait;
			
			parent['fProcess'].location.href = "/servicos/consultas_process?c=Days&d=" + id;
		}
		else
		{
			findObj('divData').style.display = 'none';
			findObj('divHora').style.display = 'none';
	
			findObj('divMsg').style.display = 'block';
		
			findObj('msgTxtTit').innerHTML = 'Data';
			findObj('msgTxt').innerHTML = 'Escolha o medico p.f.';
		}
	}
	
	function f_setDays (enable)
	{
		f = document.forms['form_consultas'];
		
		f_updateBox(f['dia'],'days',enable);

		findObj('divData').style.display = 'block';

		findObj('divMsg').style.display = 'block';

		findObj('msgTxtTit').innerHTML = 'Hora';
		findObj('msgTxt').innerHTML = 'Escolha o dia p.f.';
	}

	function f_getHours (medico,data)
	{
		if (data!=null && data!='' && data!='0')
		{
			findObj('divHora').style.display = 'none';
			findObj('divMsg').style.display = 'block';
		
			findObj('msgTxtTit').innerHTML = 'Hora';
			findObj('msgTxt').innerHTML = msgWait;
			
			parent['fProcess'].location.href = "/servicos/consultas_process/?c=Hours&d=" + medico + "&e=" + data;
			//location.href = document.location + "&b=process&c=Hours&d=" + medico + "&e=" + data;
		}
		else
		{
			findObj('divHora').style.display = 'none';
	
			findObj('divMsg').style.display = 'block';
		
			findObj('msgTxtTit').innerHTML = 'Hora';
			findObj('msgTxt').innerHTML = 'Escolha o dia p.f.';
		}
	}
	
	function f_setHours (enable)
	{
		f = document.forms['form_consultas'];
		
		f_updateBox(f['hora'],'hours',enable);

		findObj('divHora').style.display = 'block';

		findObj('divMsg').style.display = 'none';
	}
	
	var fields = new Array ('cliente','telefone');
	function f_check(el)
	{
		var i = 0; var ret = true;
		
		for (i=0;i<fields.length;i++)
		{
			if (el[fields[i]].value == "") ret = false;
		}
		
		if (!ret) alert ("Por favor preencha os seguintes campos:\n\n- Nome do dono\n- Telefone/telemóvel.");
		return ret;
	}
