
function reload_code(){
	elem = document.getElementById("code_image");
	
	var xpto = new Image();
	xpto.src='captcha.php?'+Math.random();
	
	elem.src = xpto.src;
}


function update_select(file, source, selObj, extra_1){
	
	$("#"+selObj).removeOption(/./);
	$("#"+selObj).ajaxAddOption('services/'+file, { p: source.value, extra_1:extra_1  }, false);
	
}


// 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("Accepter venligst vore handelsbetingelser");
			return(false);
		}
		return true;
	}
	return(true);
}

function vazio(campo, nome) {
	if (campo && campo.value == "") {
		open_required(rec_fld1 + nome + "!");
		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.name=='password'){
		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);		
		}
	}
	else if(campo && campo.password != ""){
		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 numeric(campo, nome) {

	if (campo && !IsNumeric(campo.value)) {
		open_required(fill_4 + " " + nome + "!");
		return(false);
	}
	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_cart(msg){
	$.fn.colorbox({html:'<p class="alert_box" id="info">'+msg+'</p><p class="alert_options cartpop"> '+ stayButton()+goButton()+'</p>', open:true, close:''});


}

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 excluirCom(id, pagina, query) {
	createAlert(id, pagina, query, comentarioPrompt(id, pagina, query));
}
function excluirUser(id, pagina, query) {
	$.fn.colorbox({html:'<p class="alert_box" id="excluir">'+conf_acc+'</p><p class="alert_options cartpop"> '+ yesButtonUsr(id, pagina, query)+noButton()+'</p>', open:true});
}

function yesButton(removeID, pagina, query){
	return '<input type="button" onclick="location.href=\'' + pagina + '?removeID=' + removeID +'&' + query + '\';" 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 yesButtonUsr(removeID, pagina, query){
	return '<input type="button" onclick="location.href=\'' + pagina + '?removeUserID=' + 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 stayButton(){
	return '<input type="button" onclick="$.fn.colorbox.close();" class="act_button" id="cancel" value="« '+cart_stay+'" />';
}
function goButton(){
	return '<input type="button" onclick="location.href=\'cart.php\'" class="act_button" id="go" value="'+cart_go+' »" />';
}	

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;
}

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 submit_form(form){
	if(typeof form.onsubmit == "function") {
		if(!form.onsubmit()) {
			return false;
		}
	}
	return form.submit();
}
function IsNumeric(input){
   return (input - 0) == input && input.length > 0;
}
