function selectAll(){
	var x = document.getElementsByTagName("input");
		
	for (var i=0;i<x.length;i++)
  	{ 
  		if(x[i].type=="checkbox"){
  			x[i].checked=true;
  		}
  	}
}

function MM_swapImgRestore() { //v3.0
	  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
	}

	function MM_preloadImages() { //v3.0
	  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
		var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
		if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
	}

	function MM_findObj(n, d) { //v4.01
	  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
		d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
	  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
	  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
	  if(!x && d.getElementById) x=d.getElementById(n); return x;
	}

	function MM_swapImage() { //v3.0
	  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
	   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
	}

	function abre_janela_abstract(link){

		var largura = 590;
		var altura = 334;
		var w = largura;
		var h = altura;
		var winl = (screen.width - w) / 2;
		var wint = (screen.height - h) / 2;
		winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',title=Secção Regional Norte da Ordem dos Médicos,status=no,toolbar=no,menubar=no,scrollbars=yes,resizable=no';
		win = window.open(link, 'SPR', winprops);
		if (parseInt(navigator.appVersion) >= 4) win.window.focus();

		//newwindow = window.open (link, "mywindow","location=0,status=0,scrollbars=0,width=512,height=380");
		//newwindow.moveTo(self.screen.width/4,self.screen.height/8);
	}

	function ver_imagem(path, titulo, w, h){

		//var w = document.getElementById('imgwidth').value;
		//var h = document.getElementById('imgheight').value;
		var largura = w;
		var altura = h;
		var screenX = screen.width;
		var screenY = screen.height;
		var winl;
		var wint;

		if (w > screenX){
			largura = screenX;
			if (h > screenY){
				altura = screenY;
				largura = (w * screenY) / (h);
			} else {
				altura = (h * screenX) / (w);
			}
		} else {
			largura = w;
			if (h > screenY){
				altura = screenY;
				largura = (w * screenY) / (h);
			} else {
				altura = h;
			}
		}

		winl = (screenX - largura) / 2;
		wint = (screenY - altura) / 2;

		winprops = 'height='+altura+',width='+largura+',top='+wint+',left='+winl+',status=no,toolbar=no,menubar=no,scrollbars=no,resizable=no,directories=no';
		win = window.open('imagem.php?titulo='+titulo+'&imagem='+path+'&width='+screenX+'&height='+screenY,'', winprops);
		if (parseInt(navigator.appVersion) >= 4) win.window.focus();
	}


	//esta funcao serve para alterar a cor do texto de press_realeases ao passar o rato
	function changeStyleById(id, color){
		if (document.getElementById){
			var nodeObj = document.getElementById(id);
			nodeObj.style.color = color;
		}
	}

	function MultiSelector( list_target){
		this.list_target = list_target;
		this.count = 0;
		this.id = 0;
		this.addElement = function( element ){
			if( element.tagName == 'INPUT' && element.type == 'file' ){
				element.name = 'file[]';
				element.className= 'adm_campo';
				element.multi_selector = this;element.onchange = function(){
					var new_element = document.createElement( 'input' );
					new_element.type = 'file';
					this.parentNode.insertBefore( new_element, this );
					this.multi_selector.addElement( new_element );
					this.multi_selector.addListRow( this );
					this.style.position = 'absolute';
					this.style.left = '-1000px';
				};
				this.count++;
				this.current_element = element;
			} else {
				alert( 'Error: not a file input element' );
			}
		}
		this.addListRow = function( element ){
			var new_row = document.createElement( 'div' );
			var new_row_button = document.createElement( 'input' );
			new_row_button.type = 'button';
			new_row_button.value = 'remover';
			new_row_button.className = 'adm_campo';
			new_row.element = element;
			new_row_button.onclick= function(){
				this.parentNode.element.parentNode.removeChild(
				this.parentNode.element );
				this.parentNode.parentNode.removeChild( this.parentNode );
				this.parentNode.element.multi_selector.count--;
				this.parentNode.element.multi_selector.current_element.disabled = false;
				return false;
			};
			new_row.innerHTML = '<b>' + element.value + '</b>  ';
			new_row.appendChild( new_row_button );
			this.list_target.appendChild( new_row );
		}
	}

	function vercartao(){
		with (document.form_cartao) {
				method = "POST";
				action="cartao.php";
				jan = displayWindow('','cartao','241', '165','');
				target='cartao';
				submit();
			}
	}

	function displayWindow(theURL,winName,width,height,features) {

		var window_width = width;
	    var window_height = height;
	    var newfeatures= features;
	    var window_top = (screen.height-window_height)/2;
	    var window_left = (screen.width-window_width)/2;
	    newWindow=window.open(''+ theURL + '',''+ winName + '','width=' + window_width + ',height=' + window_height + ',top=' + window_top + ',left=' + window_left + ',features=' + newfeatures + ',status=no,toolbar=no,menubar=no,scrollbars=no,resizable=no,directories=no');
	    newWindow.focus();
	}

	function cartao(login){
		var window_width = 241;
	    var window_height = 165;
	    var window_top = (screen.height-window_height)/2;
	    var window_left = (screen.width-window_width)/2;
		window.open('/membro/cartao/cartao.php?login='+login,'Cartao_'+login,'top=' + window_top + ',left=' + window_left + ',toolbar=no,width=241,height=165,directories=no,status=no,scrollbars=no,resize=no,menubar=no,location=no');
	}

	function showhide(){
		 var listObj=document.registo.especialidades;
		 var layer='';

		 for(i=0 ; i<listObj.options.length ; i++){
	     	layer='especial'+listObj.options[i].value;
	     	if (listObj.options[i].selected){
	      	   document.getElementById(layer).style.display='block';
	        	 document.registo.elements['cb_'+layer].checked=true;
	        	 eval('document.registo.'+layer+'.value ='+listObj.options[i].value+';');
	   	    } else{
	        	document.getElementById(layer).style.display='none';
	         	document.registo.elements['cb_'+layer].checked=false;
	         	eval('document.registo.'+layer+'.value=0;');
	     	}
	 	}
	}

	function changeColorOn(idten, n){
		for(i=1;i<=n;i++){
			document.getElementById(i+idten).style.color='rgb(118,168,159)';
		}
	}

	function changeColorOff(idten, n){
		for(i=1;i<=n;i++){
			document.getElementById(i+idten).style.color='rgb(95,92,92)';
		}
	}

	function changecolorlink_on(col){
		for(i=1;i<=3;i++){
			document.getElementById('row1col'+col).style.color='rgb(118,168,159)';
			document.getElementById('row2col'+col).style.color='rgb(118,168,159)';
		}
	}

	function changecolorlink_off(col){
		for(i=1;i<=3;i++){
			document.getElementById('row1col'+col).style.color='rgb(95,92,92)';
			document.getElementById('row2col'+col).style.color='rgb(95,92,92)';
		}
	}

	function muda_seta(){
		obj = document.getElementById('seta');
		div = document.getElementById('texto');
		if(obj.value==0){
			obj.value=1;
			obj.src='../../ficheiro/interface/seta_desc.GIF';
			div.style.display='block';
			window.resizeTo(250,435);
		}else{
			if(obj.value==1){
				obj.value=0;
				obj.src='../../ficheiro/interface/seta_asc.GIF';
				div.style.display='none';
				window.resizeTo(250,235);

			}
		}
	}

function fillSelectFromArray(selectCtrl, itemArray, defaultItem, goodPrompt, badPrompt) {
	var i, j;
	var prompt;

	// empty existing items
	for (i = selectCtrl.options.length; i >= 0; i--) {
		selectCtrl.options[i] = null;
	}

	prompt = (itemArray != null) ? goodPrompt : badPrompt;

	if (prompt == null) {
		j = 0;
	} else {
		selectCtrl.options[0] = new Option(prompt);
		j = 1;
	}

	if (itemArray != null) {

		// add new items
		for (i = 0; i < itemArray.length; i++) {
			selectCtrl.options[j] = new Option(itemArray[i][0]);
			if (itemArray[i][1] != null) {
				selectCtrl.options[j].value = itemArray[i][1];
			}
			j++;
		}

		// select first item (prompt) for sub list
		if (defaultItem == null) {
			defaultItem = 0;
		}
		selectCtrl.options[defaultItem].selected = true;
	}
}

	function addLoadEvent(func) {

		var oldonload = window.onload;

		if (typeof window.onload != 'function') {
			window.onload = func;
		} else {
			window.onload = function() {
				if (oldonload) {
					oldonload();
				}
				func();
			}
		}
	}

	// Funções para a Sondagem

	function MultiRespostas( list_target){
		this.list_target = list_target;
		this.count = 0;
		this.id = 0;
		this.addElement = function( element ){
			if( element.tagName == 'INPUT' && element.type == 'text' ){
				element.name = 'resposta[]';
				element.className= 'style_input_resposta';
				element.multi_selector = this;

				element.onchange = function(){
					var new_element = document.createElement( 'input' );
					new_element.type = 'text';
					this.parentNode.insertBefore( new_element, this );

					this.multi_selector.addElement( new_element );
					this.multi_selector.addListRow( this );
					this.style.position = 'absolute';
					this.style.left = '-1000px';
				};
				//if(this.current_element.value!=new_element.value){
					this.count++;
					this.current_element = element;


			} else {
				alert( 'Error: not a file input element' );
			}
		}
		this.addListRow = function( element ){
			var new_row = document.createElement( 'div' );
			var new_row_button = document.createElement( 'img' );
			new_row_button.id="menos";
			new_row_button.src = "../../ficheiro/interface/menos.jpg";
			//new_row_button.innerHTML = '<img src="../../ficheiro/interface/menos.jpg" border=0>';
			new_row.element = element;
			new_row_button.onclick= function(){
				this.parentNode.element.parentNode.removeChild(
				this.parentNode.element );
				this.parentNode.parentNode.removeChild( this.parentNode );
				this.parentNode.element.multi_selector.count--;
				this.parentNode.element.multi_selector.current_element.disabled = false;
				return false;
			};
			new_row.innerHTML = '<input type="text" name="'+element.name+'" value="'+element.value+'" class="style_input_resposta">&nbsp;&nbsp;';
			new_row.appendChild( new_row_button );
			this.list_target.appendChild( new_row );
		}
	}









	//fim das funções para a sondagem