var barra=String.fromCharCode(47);
var cometes=String.fromCharCode(34);
function ver(capa){
	var num_capes=array_capes.length;
	with(document){
		for(i=0;i<num_capes;i++){
			getElementById(array_capes[i]).style.display='none';
		}
		getElementById(capa).style.display='inline';
	}
	doAjax(PAGINA_VERIFY_PROCES,"funcion=comprovacio","verify",'post','0');
}

function verify(resposta){
	if(resposta!='login'){
		document.location.href=PAGINA_ADMIN_INICI;
	}
}

function mostrar_form(id){
	ver(CAPA_CARREGANT);
	eval(FORMULARI_FIXE+".id.value=id");
	doAjax(PAGINA_PROCES,"funcion=mostrar_form&id="+id,"mostrar(item,'contingut_resu');//","post","0");
}

function mostrar_form_vincle(id){
	ver(CAPA_CARREGANT);
	eval(FORMULARI_FIXE+".id.value=id");
	doAjax(PAGINA_PROCES,"funcion=mostrar_form&id="+id+"&id_vincle="+eval(FORMULARI_FIXE+".id_vincle.value")+"&tipus_relacio="+eval(FORMULARI_FIXE+".tipus_relacio.value"),"mostrar(item,'contingut_resu');//","post","0");
}

function estat_form(flag){
	if(flag=='disabled')	tipus_estat='disabled';
	else			tipus_estat='';

	var num_camps_form=camps_form.length;

	with(eval(FORMULARI_INTERN)){
		for(i=0;i<num_camps_form;i++){
			eval(camps_form[i]+".disabled=tipus_estat;");
		}
		enviar.disabled=tipus_estat;
		cancelar.disabled=tipus_estat;
	}
}

function actualitzar(){
	estat_form('disabled');
	with(eval(FORMULARI_INTERN)){
		valorsURL='funcion=actualitzar&id='+eval(FORMULARI_FIXE).id.value;
		num_camps_form=camps_form.length;
		for(i=0;i<num_camps_form;i++){
			eval("valorsURL=valorsURL+\"&"+camps_form[i]+"=\"+encodeURIComponent("+camps_form[i]+".value);");
		}
	}
	doAjax(PAGINA_PROCES,valorsURL,FUNCIO_LLISTAT,'post','0');
}

function mostrar(resposta,capa){
	document.getElementById(capa).innerHTML=resposta;
	ver(capa);
}

function canvia_estat(id,estat){
	doAjax(PAGINA_PROCES,"funcion=canvia_estat&id="+id+"&estat="+estat,FUNCIO_LLISTAT,'post','0');
}

function ordena(ordenavalor){
	with(eval(FORMULARI_FIXE)){
		ordre.value=ordenavalor;
		pagina.value='1';
		eval(FUNCIO_LLISTAT);
	}
}
function eliminar(id){
	if(confirm(msg_eliminar)){
		num_enllas=eval("document.getElementById('enllas_eliminar_"+id+"')");
		num_enllas.innerHTML="<b>"+msg_processant+"<"+barra+"b>";
		eval(FORMULARI_FIXE+".id.value=id");
		doAjax(PAGINA_PROCES,'funcion=eliminar&id='+id,FUNCIO_LLISTAT,'post','0');
	}
}
function mostrar_instruccions_html(){
	ver('capa_instruccions_html');
}
function is_email(email){
	if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/.test(email)){
		return true;
	}else{
		return false;
	}

}
function guardar_ordre_ajax(){
	var valorsURL="";
	with(document.formulario){
		for(var i=0;i<length;i++){
			valorsURL=valorsURL + "&" + elements[i].name + "="+elements[i].value;
		}
	}
	doAjax(PAGINA_PROCES,"funcion=guardar_ordre"+valorsURL,FUNCIO_LLISTAT,'post','0');
}
function obrir_finestra(url,ample,alsada){
	vent=open(url,"","toolbar=0,location=0,status=0,menubar=0,scrollbars=no,resizable=no,width="+ample+",height="+alsada+",top=left,MinButton=False,MaxButton=False");
}
function verifica_pais(NOM_FORM){
	with(eval(NOM_FORM)){
		//Si el pais no es Espanya ocultem id_provincia, id_municipi
		if(id_pais.value!='180'){
			id_provincia.value="";
			id_provincia.disabled='disabled';
		}else{
			id_provincia.disabled='';
		}
	}
}
function verifica_provincia(NOM_FORM){
	with(eval(NOM_FORM)){
		//Si la provincia no es Barcelona, Girona, Lleida o Tarragona ocultem id_municipi
		if(id_provincia.value!='9' && id_provincia.value!='21' && id_provincia.value!='31' && id_provincia.value!='46'){
			try{
				id_municipi.value="";
				id_municipi.disabled='disabled';
			}catch(e){}
			try{
				localitat.value="";
				localitat.disabled='disabled';
			}catch(e){}

		}else{
			try{
				id_municipi.disabled='';
			}catch(e){}
			try{
				localitat.disabled='';
			}catch(e){}
		}
	}
}

function posa_textareas(){
	tinyMCE.init({
		// General options
		mode : "textareas",
		theme : "advanced",
		plugins : "safari,pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template",

		// Theme options
		theme_advanced_buttons1 : "bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,styleselect",
		theme_advanced_buttons2 : "cut,copy,paste,pastetext,pasteword,|,search,replace,|,bullist,numlist,|,undo,redo,|,link,unlink,anchor,image,code,|,preview",
		theme_advanced_buttons3 : "tablecontrols,|,removeformat,|,sub,sup,|,charmap,iespell,media,advhr,|,print,|,ltr,rtl",
		theme_advanced_buttons4 : "insertlayer,moveforward,movebackward,absolute,|,styleprops,|,cite,abbr,acronym,del,ins,attribs,|,visualchars,nonbreaking,template,pagebreak",
		theme_advanced_toolbar_location : "top",
		theme_advanced_toolbar_align : "left",
		theme_advanced_statusbar_location : "bottom",
		theme_advanced_resizing : true,

		// Example content CSS (should be your site CSS)
		content_css : "css/content.css",

		// Drop lists for link/image/media/template dialogs
		template_external_list_url : "lists/template_list.js",
		external_link_list_url : "lists/link_list.js",
		external_image_list_url : "lists/image_list.js",
		media_external_list_url : "lists/media_list.js",

		// Replace values for the template plugin
		template_replace_values : {
			username : "Some User",
			staffid : "991234"
		}
	});

}