function canviarIdioma(id, nom){
	document.forms[0].idCurs.value = '';
	document.forms[0].idioma.value = id;
	document.forms[0].submit();
}

function veureCurs(idCurs){
	document.forms[0].idCurs.value = idCurs;
	document.forms[0].submit();
}

function veureHtml(nomHtml){
	document.forms[0].nomHtml.value = nomHtml;
	document.forms[0].submit();
}

function veureFormulari(idFormulari){
	document.forms[0].idFormulari.value = idFormulari;
	document.forms[0].submit();
}

function veureFormulariContacte(idFormulari, opcio1){
window.location.href = '';
	document.forms[0].opcio1.value = opcio1;
	document.forms[0].opcio2.value = '';
	document.forms[0].opcio3.value = '';
	document.forms[0].idFormulari.value = idFormulari;
	document.action = "index.aspx"
	document.forms[0].submit();
}

function establirVideo(idVideo){
	document.forms[0].idVideo.value = idVideo;
}

function enviarFormulari(idFormulari){
	if (validarFormulari()==true){
		inicialitzarHiddens();
		extractInputs();
		extractTextArea();
		extractSelects();
		document.forms[0].enviarFormulari.value = 'S';
		document.forms[0].submit();
	}else{
	alert('Cal informar el destinatari del missatge');}
}

function validarFormulari(){
	var objDest = document.getElementById("_ctl0_cmb_destinatari")
	if (objDest.value == '') {
		return false;}
	else
		{return true;}

}

function CanviaOpcio(obj, img, imgSrc, nomclass){
var objImg, objHref
objHref = window.document.getElementById(obj);
objHref.className = nomclass;

objImg = window.document.getElementById(img);
objImg.src = imgSrc;
}

function Go(){
	document.forms[0].idCurs.value = '';
    if (window.document.forms[0].action.indexOf("index.aspx")>-1) {
		window.document.forms[0].action = "index.aspx";
	}
    var argv = Go.arguments, argc = argv.length, opcio;
    document.forms[0].opcio1.value = "";
	document.forms[0].opcio2.value = "";
	document.forms[0].opcio3.value = "";
	for (var i=0; i<argc; i++) {
	  opcio = window.document.getElementById("opcio" + String(i+1));
	  opcio.value = argv[i];
	}
	document.forms[0].idFormulari.value = '';
	if (document.forms[0].idDetall){
		document.forms[0].idDetall.value = '';
	}
	document.forms[0].submit();
}

function GoWindowOpen(){
	var urlString;
	document.forms[0].idCurs.value = '';
    if (window.document.forms[0].action.indexOf("index.aspx")>-1) {
		urlString = "index.aspx?";
	}
    var argv = Go.arguments, argc = argv.length, opcio;
    document.forms[0].opcio1.value = "";
	document.forms[0].opcio2.value = "";
	document.forms[0].opcio3.value = "";
	for (var i=0; i<argc; i++) {
	  opcio = window.document.getElementById("opcio" + String(i+1));
	  urlString = urlString + "opcio" + String(i+1) + "=" + String(argv[i]) + "&";
	}
	document.forms[0].idFormulari.value = '';
	if (document.forms[0].idDetall){
		urlString = urlString + "idDetall=";
	}
	window.open(urlString,'_self');
}

//funcio a executar per mostrar alguna opcio de primer nivell
function show(id,norfont,norback,selfont,selback){
	//deseleccionar nivell pral
	//changeToUnselected(1,document.frmDatos.selectedPral.value,null,norback);
	///deseleccionar nivell sec
	//changeToUnselected(2,document.frmDatos.selectedSec.value,norfont,null);
	//document.frmDatos.selectedSec.value = '';
	//seleccionar nivell 1
	//changeToSelected(id,document.frmDatos.selectedPral.value,null,selback);
	//document.frmDatos.selectedPral.value = id;
	//carregar contingut
	loadDynamicContent(id);	
}

function changeToUnselected(lvl,field,norfont,norback){
	if (field !== ''){
		if (norfont != ''){
			document.getElementById('lvl'+lvl+'_'+field).style.color = norfont;
		}
		if (norback != ''){
			document.getElementById('lvl'+lvl+'_'+field).style.backgroundColor = norback;
		}
	}
}

function changeToSelected(id,lvl,field,selfont,selback){
	if (selfont != ''){
		document.getElementById('lvl'+lvl+'_'+id).style.color = selfont;
	}
	if (selback != ''){
		document.getElementById('lvl'+lvl+'_'+id).style.backgroundColor = selback;
	}
}

function loadDynamicContent(id){
	document.getElementById("Panel2").innerHTML = document.getElementById('t_lvl1_'+id).innerHTML;
	//load content
	//image	
	/*document.getElementById("temp_img").innerHTML = document.getElementById('lvl1_img_'+id).innerHTML;
	//flash
	document.getElementById("temp_flash").innerHTML = document.getElementById('lvl1_fla_'+id).innerHTML;
	//title
	document.getElementById("temp_title").innerHTML = document.getElementById('lvl1_tit_'+id).innerHTML;
	//text
	document.getElementById("temp_text").innerHTML = document.getElementById('lvl1_text_'+id).innerHTML;*/

}

function handleResizeContents(){	
	if ((document.getElementById("_ctl0_layout_tbl").scrollHeight > getDocumentHeight()) || (document.getElementById("_ctl0_layout_tbl").scrollWidth > getDocumentWidth())){
		document.body.style.overflow = 'scroll';
	}else{
		document.body.style.overflow = 'hidden';
		window.scrollTo(0,0);	
	}
}

function obrirFinestraCentrada(sarxiu,snom,stoolbar,sstatus,swidth,sheight,sresizable,sscrollbars){
var stop,sleft,parametres;
	sleft = (((screen.width - parseInt(swidth))/2)/10)*10;
	stop = (((screen.height - parseInt(sheight))/2)/10)*10;
	parametres = "toolbar=" + String(stoolbar) + ",status=" + String(sstatus) + ",width=" + String(swidth) + ",height=" + String(sheight) + ",resizable=" + String(sresizable) + ",top=" + String(stop) + ",left=" + String(sleft)+ ",scrollbars=" + String(sscrollbars);
	window.open(String(sarxiu),String(snom),String(parametres));
}

function privacitat(fitxer,nom){
	obrirFinestraCentrada(fitxer,nom,'no','no','350','400','no','no')
}

function avislegal(fitxer,nom){
	obrirFinestraCentrada(fitxer,nom,'no','no','350','400','no','no')
}

function credits(fitxer,nom){
	obrirFinestraCentrada(fitxer,nom,'no','no','410','190','no','yes')
}

//aquesta funció es recorre els inputs d'un´formla i informa dos input hiddens amb els noms del inputs i els seus valors
function inicialitzarHiddens(){
	document.forms[0].idInputs.value = '';
	document.forms[0].valorInputs.value = '';
	document.forms[0].titleInputs.value = '';
}

function extractInputs(){
	var elem;
	var aInputs = window.document.getElementsByTagName("input");
	for (i=0;i<aInputs.length;i++){
		if (aInputs[i].type=='text')  
		{
			document.forms[0].idInputs.value = document.forms[0].idInputs.value + '||' + aInputs[i].id;
			document.forms[0].valorInputs.value = document.forms[0].valorInputs.value + '||' + encodeURI(aInputs[i].value);
			document.forms[0].titleInputs.value = document.forms[0].titleInputs.value + '||' + aInputs[i].title;
		}
	}
}

function extractTextArea(){
	var elem;
	var aInputs = window.document.getElementsByTagName("textArea");
	for (i=0;i<aInputs.length;i++){
		document.forms[0].idInputs.value = document.forms[0].idInputs.value + '||' + aInputs[i].id;
		document.forms[0].valorInputs.value = document.forms[0].valorInputs.value + '||' + encodeURI(aInputs[i].value);
		document.forms[0].titleInputs.value = document.forms[0].titleInputs.value + '||' + aInputs[i].title;
	}
}

function extractSelects(){
	var elem;
	var aInputs = window.document.getElementsByTagName("select");
	for (i=0;i<aInputs.length;i++){
		document.forms[0].idInputs.value = document.forms[0].idInputs.value + '||' + aInputs[i].id;
		document.forms[0].valorInputs.value = document.forms[0].valorInputs.value + '||' + encodeURI(aInputs[i].value);
		document.forms[0].titleInputs.value = document.forms[0].titleInputs.value + '||' + aInputs[i].title;
	}
}
