
// Options:
//   Num 1 -> Col·leccions
//   Num 2 -> Institucions participants
//   Num 3 -> Properes incorporacions
//   Num 4 -> Informació tècnica

function callOption(iNum) {
	var content = document.getElementById("contents");

	if(content != null) {
		var pare = content.parentNode;
		pare.removeChild(content);
	}

	var contentFrm = document.getElementById("contentFrame");
	var iF_pi = document.getElementById("idWiki_pi");
	var iF_it = document.getElementById("idWiki_it");
	var iF_qe = document.getElementById("idWiki_qe");

	if(iF_it != null) {contentFrm.removeChild(iF_it);}
	if(iF_pi != null) {contentFrm.removeChild(iF_pi);}
	if(iF_qe != null) {contentFrm.removeChild(iF_qe);}
	
	makeFrame(iNum, contentFrm);
}


function makeFrame(iNum, father) {
	if(iNum == 3) {
		var iFsrc = "http://" + location.hostname + "/wiki/dokuwiki/doku.php?id=properes_incorporacions";
		var identif = "idWiki_pi";
	}
	else if(iNum == 4) {  //iNum=4
        	var iFsrc = "http://" + location.hostname + "/wiki/dokuwiki/doku.php?id=informacio_tecnica&do=login";
		var identif = "idWiki_it";
	}
	else {  //iNum=5
        	var iFsrc = "http://" + location.hostname + "/wiki/dokuwiki/doku.php?id=que_es";
		var identif = "idWiki_qe";
	}

	var ifrm = document.createElement("IFRAME");
	ifrm.style.visibility = "hidden";
	ifrm.setAttribute("id", identif);
	ifrm.setAttribute("name", identif);
	ifrm.setAttribute("src", iFsrc);
	ifrm.setAttribute("frameborder", 0);
	
	if (navigator.userAgent.indexOf("MSIE") > -1 && !window.opera) {
		ifrm.onreadystatechange = function(){
        		if (ifrm.readyState == "complete"){
				setIframeProperties();
            			//alert("Local iframe is now loaded.");
				//alert ("The state of the document: " + ifrm.readyState);
        		}
    		};
	} 
	else {
		ifrm.onload = function(){
			setIframeProperties();
			//alert("Local iframe is now loaded.");
		};
	}

	father.appendChild(ifrm);
} 

function setIframeProperties() {
	var iframeID = document.getElementById("contentFrame").getElementsByTagName('iframe')[0].id;
	var newID = document.getElementById(iframeID);

	newID.style.position = "relative";
	newID.style.visibility = "visible";
	newID.style.width = "100%";
	newID.style.height = "" + getDocHeight(newID) + "px";

        //alert(getDocHeight(iNum));
}


function getDocHeight(newID) {
	//var D = document.getElementById(+newID+).contentWindow.document;
	var D = newID.contentWindow.document;

    return Math.max(
        Math.max(D.body.scrollHeight, D.documentElement.scrollHeight),
        Math.max(D.body.offsetHeight, D.documentElement.offsetHeight),
        Math.max(D.body.clientHeight, D.documentElement.clientHeight)
    );
}


