  // Clear prompt from username field, if required.
  function clearUsernamePrompt() {
    var username = document.getElementById("username");
    if (username.value == "Username") {
      username.value = "";
    }
  }
 
  // Set the prompt for the username field, if required.
  function setUsernamePrompt() {
    var username = document.getElementById("username");
    if (username.value == "") {
      username.value = "Username";
    }
  }
  // Clear prompt from password field, if required.
  function clearPasswordPrompt() {
    var password = document.getElementById("password");
    password.style.display = "inline";
    password.focus();
    var passwordPrompt = document.getElementById("passwordPrompt");
    passwordPrompt.style.display = "none";
  }
 
  // Set the prompt for the password field, if required.
  function setPasswordPrompt() {
    var password = document.getElementById("password");
   if (password.value == "") {
      password.style.display = "none";
      var passwordPrompt = document.getElementById("passwordPrompt");
     passwordPrompt.style.display = "inline";
    }
  }

// Verifica campo vazio

var zindex = 1000;

function checkRadio(campo, nome) {
	if (campo) {
		var checked = false;
		for(idx = 0; idx < campo.length; idx++){
			if(campo[idx].checked == true)
				checked = true;	
		}
		if(!checked){
			open_required("Please select something on " + nome + "!");
			return(false);
		}
		return true;
	}
	return(true);
}

function checkTermos(campo, nome) {
	if (campo) {
		if(!campo.checked){
			open_required("De forma a continuar tem de concordar com as condições de utilização");
			return(false);
		}
		return true;
	}
	return(true);
}

function vazio(campo, nome) {
	if (campo && campo.value == "") {
		open_required(rec_fld1 + nome + "!");
		return(false);
	}
	return(true);
}

function hascontent(campo, nome) {
	if (campo && campo.value.length < 30) {
		open_required('Please fill the field research focus (minimum 30 characters)');
		return(false);
	}
	return(true);
}

function imagens(campo, nome){
	if(document.formulario.tem_img.value == "0"){
		if(vazio(campo,nome))
			return true;
		return false;
	}
	else
		return true;
}

// Verifica select parado
function parado(campo, nome) {
	if (campo && campo.selectedIndex == 0) {
		open_required(rec_fld2 + nome + "!");
		return(false);
	}
	return(true);
}
function validaPassword(campo, nome) {
	if(campo && campo.value != ""){
		if (campo.value.length < 5) {
			open_required(acc_shr_pass);
			return(false);
		}
		else if(campo.value != document.formulario.password2.value){
			open_required(acc_wrg_pass2);
			return(false);		
		}
	}
	return(true);
}


// valida campo de email
function validaEmail(email, nome) {
	valido = /^.*\@.*\..*$/i;
	if (email && email.value.search(valido) == -1) {
		open_required(rec_fld1 + nome + "!");
		return(false);
	}
	return(true);
}


function checkDates(campo, nome) {
	if (campo) {
		var dataInicio = new Date(campo.value.replace(/-+/g,'/'));
		var dataFim = new Date(document.formulario.dataFim.value.replace(/-+/g,'/'));
		
		var milisegundos = dataFim.valueOf()-dataInicio.valueOf();
		var dias = milisegundos/86400000;
		if(dias<0){
			open_required("Invalid dates on " + nome + "!");
			return false;
		}
		return true;
	}
	return(true);
}


function setin(field){
	field.value ='';		
}
function setout(field, value){
	if(field.value=='')
		field.value=value;
}

function close_required(){
	
	var required = document.getElementById('required');
	var req_if	 = document.getElementById('req_if');
	required.style.display = 'none';
	
	req_if.style.display = 'none';
	
	//destroy_layer();

}

function open_required(msg){
	$.fn.colorbox({html:'<p class="alert_box" id="info">'+msg+'</p>', open:true});
	
	$().bind('cbox_complete', function(){
		setTimeout($.fn.colorbox.close, 2000);
		$().unbind('cbox_complete');
	});
}
/*
function open_required(mensagem) {
	createAlert(0, "", "", contentAlert(mensagem));
}
*/


function deleteMsg(removeID, pagina, query){
	$.fn.colorbox({html:'<p class="alert_box" id="excluir">'+conf_itm+'</p><p class="alert_options"> '+ yesButtonMsg(removeID, pagina, query)+noButton()+'</p>', open:true});
}

	
function open_update(mensagem) {
	createAlert(0, "", "", contentUpdate(mensagem));
}
function excluir(removeID, pagina, query){
	$.fn.colorbox({html:'<p class="alert_box" id="excluir">'+conf_itm+'</p><p class="alert_options"> '+ yesButton(removeID, pagina, query)+noButton()+'</p>', open:true});
}
function excluirWiki(removeID, pagina, query){
	$.fn.colorbox({html:'<p class="alert_box" id="excluir">STOP! Are you sure you want to remove the article? Once deleted, the article can NOT be restored!</p><p class="alert_options"> '+ yesButton(removeID, pagina, query)+noButton()+'</p>', open:true});
}
function excluirImg(removeID, pagina, query){
	$.fn.colorbox({html:'<p class="alert_box" id="excluir">'+conf_itm+'</p><p class="alert_options"> '+ yesButtonImg(removeID, pagina, query)+noButton()+'</p>', open:true});
}

function excluirLink(id, pagina, query) {
	createAlert(id, pagina, query, linkPrompt(id, pagina, query));
}

function excluirDoc(removeID, pagina, query){
	$.fn.colorbox({html:'<p class="alert_box" id="excluir">'+conf_itm+'</p><p class="alert_options"> '+ yesButtonDoc(removeID, pagina, query)+noButton()+'</p>', open:true});
}
function removeConnection(removeID, pagina, query){
	$.fn.colorbox({html:'<p class="alert_box" id="excluir">Are you sure you want to remove that connection?</p><p class="alert_options"> '+ yesButtonNet(removeID, pagina, query)+noButton()+'</p>', open:true});
}
function excluirCom(id, pagina, query) {
	createAlert(id, pagina, query, comentarioPrompt(id, pagina, query));
}
function excluirUser(id, pagina, query) {
	createAlert(id, pagina, query, deletePrompt(id, pagina, query));
}

function yesButton(removeID, pagina, query){
	return '<input type="button" onclick="location.href=\'' + pagina + '?removeID=' + removeID +'&' + query + '\';" class="act_button" id="confirmar" value="'+conf+'" />';
}
function yesButtonNet(removeID, pagina, query){
	return '<input type="button" onclick="document.remove'+removeID+'.submit();" class="act_button" id="confirmar" value="'+conf+'" />';
}
		
function yesButtonMsg(removeID, pagina, query){
	return '<input type="button" onclick="location.href=\'' + pagina + '?removeMsgID=' + removeID +'&' + query + '\';" class="act_button" id="confirmar" value="'+conf+'" />';
}
function yesButtonDoc(removeID, pagina, query){
	return '<input type="button" onclick="location.href=\'' + pagina + '?removeDocumentoID=' + removeID +'&' + query + '\';" class="act_button" id="confirmar" value="'+conf+'" />';
}
function yesButtonImg(removeID, pagina, query){
	return '<input type="button" onclick="location.href=\'' + pagina + '?removeImagemID=' + removeID +'&' + query + '\';" class="act_button" id="confirmar" value="'+conf+'" />';
}
function noButton(){
	return '<input type="button" onclick="$.fn.colorbox.close();" class="act_button" id="cancel" value="'+cancel+'" />';
}
	
function createAlert(id, pagina, query, html){
	
	var h = 150;
	var w = 300;
	
	findOffset(w,h);
	
	var required = document.getElementById('required');
	var req_if	 = document.getElementById('req_if');
	
	required.innerHTML = html
	
	required.style.display = 'block';
	required.style.visibility = 'visible';
	required.style.top = Yoffset+'px';
	required.style.left = Xoffset+'px';

	req_if.style.display = 'block';

	req_if.style.visibility = 'visible';
	req_if.style.top = Yoffset+'px';
	req_if.style.left = Xoffset+'px';

}
	
	
function toggleVis(id, bulet){
	
	var row = document.getElementById('tr_'+id)
	var i = document.getElementById('img_'+id)
	
	if(row.className == 'invisible'){
		row.className = 'visible';
		i.src=ons[bulet].src;
	}
	else{
		row.className = 'invisible';
		i.src=ofs[bulet].src;
	}
	
}


function showData(){
	var objecto = document.getElementById('periodo');
	objecto.style.visibility = 'visible';
	objecto.style.display = 'inline';

}

function hideData(){
	var objecto = document.getElementById('periodo');
	objecto.style.visibility = 'hidden';
	objecto.style.display = 'none'
	
}

function contentAlert(mensagem){
	//createLayer();
	var html;
	html = '<table class="alert_table"><tr><td align="center" class="erro"><img src="images/icons/pack/info.gif" alt="'+ok+'" title="'+ok+'" /><br /><br />' + mensagem + '</td></tr><tr><td align="center"><input type="button" onclick="close_required();" class="act_button" id="ok" value="'+ok+'" /></td></tr></table>';
	return html;
}

function contentPrompt(id, pagina, query){
	//createLayer();
	var html;
	html='<table class="alert_table"><tr><td colspan="2" align="center" class="erro"><img src="images/icons/pack/alert.gif" alt="'+ok+'" title="'+ok+'" /><br /><br />'+conf_itm+'</td></tr><tr><td align="center"><input type="button" onclick="location.href=\'' + pagina + '?' + query + '&removeID=' + id +'\';" class="act_button" id="confirmar" value="'+conf+'" /></td><td align="center"><input type="button" onclick="close_required();" class="act_button" id="cancel" value="'+cancel+'" /></td></tr></table>';
	return html;
}
function deletePrompt(id, pagina, query){
	//createLayer();
	var html;
	html='<table class="alert_table"><tr><td colspan="2" align="center" class="erro"><img src="images/icons/pack/alert.gif" alt="'+ok+'" title="'+ok+'" /><br /><br />'+conf_acc+'</td></tr><tr><td align="center"><input type="button" onclick="location.href=\'' + pagina + '?' + query + '&removeUserID=' + id +'\';" class="act_button" id="confirmar" value="'+conf+'" /></td><td align="center"><input type="button" onclick="close_required();" class="act_button" id="cancel" value="'+cancel+'" /></td></tr></table>';
	return html;
}
function contentUpdate(mensagem){
	//createLayer();
	var html;
	html = '<table class="alert_table"><tr><td align="center" class="erro"><img src="images/icons/pack/info.gif" alt="'+ok+'" title="'+ok+'" /><br /><br />' + mensagem + '</td></tr></table>';
	return html;
}
function linkPrompt(id, pagina, query){
	//createLayer();
	var html;
	html='<TABLE class="alert_table"><TR><TD colspan="2" align="center" class="erro"><img src="images/icons/pack/alert.gif" alt="'+ok+'" title="'+ok+'" /><br /><br />'+conf_lnk+'</TD></TR><TR><TD align="center"><input type="button" onclick="location.href=\'' + pagina + '?' + query + '&removeLinkID=' + id +'\';" class="act_button" id="confirmar" value="'+conf+'" /></TD><TD align="center"><input type="button" onclick="close_required();" class="act_button" id="cancel" value="'+cancel+'" /></TD></TR></TABLE>';
	return html;
}
function comentarioPrompt(id, pagina, query){
	//createLayer();
	var html;
	html='<table class="alert_table"><tr><td colspan="2" align="center" class="erro"><img src="images/icons/pack/alert.gif" alt="'+ok+'" title="'+ok+'" /><br /><br />'+conf_itm+'</td></tr><tr><td align="center"><input type="button"  onclick="location.href=\'' + pagina + '?' + query + '&removeComentarioID=' + id +'\';" class="act_button" id="confirmar" value="'+conf+'" /></td><td align="center"><input type="button" onclick="close_required();" class="act_button" id="cancel" value="'+cancel+'" /></td></tr></table>';
	return html;
}
document.write('<div id="required" class="required"></div>');
document.write('<iframe id="req_if" class="required_if" scrolling="no" frameborder="0"></iframe>');

function createLayer(){
	zindex					+= 2;

	var div 			= document.createElement("div");
	div.className 		= "disable_layer";
	div.style.zIndex	= zindex;
	div.id 				= "disable_layer_div";
	div.style.height	= mainbody.scrollHeight+"px";
	div.style.width		= mainbody.scrollWidth+"px";
	
	var frame 			= document.createElement("iframe");
	frame.className 	= "disable_layer_if";
	frame.scrolling 	= "no";
	frame.frameBorder 	= "0";
	frame.style.zIndex	= div.style.zIndex-1;
	frame.id 			= "disable_layer_if";
	frame.style.height	= mainbody.scrollHeight+"px";
	frame.style.width	= mainbody.scrollWidth+"px";

	mainbody.appendChild(div);	
	mainbody.appendChild(frame);	
}
function destroy_layer(){
	
	iframe = document.getElementById("disable_layer_if");
	div = document.getElementById("disable_layer_div");
	
	mainbody.removeChild(iframe);
	mainbody.removeChild(div);
	
	
}


function pop_print(form){
	var h = 520;
	var w = 800;
	var target = form
	findOffset(w,h);
	
	window.open(target, '', 'width='+w+', height='+h+', screenX=' + Xoffset+', scrollbars=1, screenY='+Yoffset);
}



function pop_form(form){
	var h = 400;
	var w = 500;
	
	findOffset(w,h);
	
	window.open(form, '', 'width='+w+', height='+h+', screenX=' + Xoffset+', scrollbars=0, screenY='+Yoffset);
}
function pop_up(imagem){
	var h = imagem.height;
	var w = imagem.width;
	var features='';
	findOffset(w,h);
	
	window.open('/galeria.php?i='+imagem.src, '', 'width='+w+', height='+h+', screenX=' + Xoffset+', screenY='+Yoffset+','+features);
}


function findOffset(w, h){
	
	w = parseInt(w);
	h = parseInt(h);
	
	if (parseInt(navigator.appVersion)>3) {
	 if (navigator.appName=="Netscape") {
	  winW = window.innerWidth;
	  winH = window.innerHeight;
	  
	  offX = window.pageXOffset
	  offY = window.pageYOffset
	 }
	 if (navigator.appName.indexOf("Microsoft")!=-1) {
	  var iebody=(document.compatMode && document.compatMode != "BackCompat")? document.documentElement : document.body
	  
	  if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ){
	  winW = document.documentElement.clientWidth;
	  winH = document.documentElement.clientHeight;
  
	  }
	  else {
		  winW = document.clientWidth;
		  winH = document.clientHeight;
	  }	  
	  offY = document.all? iebody.scrollTop : pageYOffset
	  offX = document.all ? iebody.scrollLeft : pageXOffset
	 }
	}
	Yoffset =  offY + (winH/2)-h/2;
	Xoffset = offX + (winW/2)-w/2;
}
function postGetContent2(source, vars, target, rand){


	if (window.XMLHttpRequest) {
		window['reqObj'+rand] = new XMLHttpRequest();
	} 
	else if (window.ActiveXObject) {
		window['reqObj'+rand] = new ActiveXObject("Microsoft.XMLHTTP");
	}

	if(window['reqObj'+rand]) {
		window['reqObj'+rand].open("POST", source, true);
		window['reqObj'+rand].setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=iso-8859-15;");
		window['reqObj'+rand].onreadystatechange = target;
		window['reqObj'+rand].send(vars);
	}
}


function update_sponsors(){

	var rand = Math.ceil(Math.random()*100);

	option = function(){
		//var selObj = document.getElementById(sel);
		document.getElementById('sponsorarea').innerHTML = window['reqObj'+rand].responseText;
	}
	//alert("p="+source.value+'&extra_1='+extra_1);
	postGetContent2('quadro_sponsors.php', "", option, rand);
}
