﻿function hidediv(id) {
	//safe function to hide an element with a specified id
	try
{
	if (document.getElementById) { // DOM3 = IE5, NS6
		document.getElementById(id).style.display = 'none';
	}
	else {
		if (document.layers) { // Netscape 4
			document.id.display = 'none';
		}
		else { // IE 4
			document.all.id.style.display = 'none';
		}
	}
}
catch(err)
{
//Handle errors here
}
}
function showdiv(id) {
	//safe function to show an element with a specified id
		  
	if (document.getElementById) { // DOM3 = IE5, NS6
		document.getElementById(id).style.display = 'block';
	}
	else {
		if (document.layers) { // Netscape 4
			document.id.display = 'block';
		}
		else { // IE 4
			document.all.id.style.display = 'block';
		}
	}
}

function gById(id) {
	if (document.getElementById) { // DOM3 = IE5, NS6
		return document.getElementById(id);
	}else {if (document.layers) { // Netscape 4
	    return document.id;
	}else { // IE 4
		return document.all.id;
}}}


// uid is the unique ID 
//
// REMARK  :always name the loading content "loadImg_" + Uid
// and the iframe id : uid
//
// for height and width:
// choose : pixels, percentage
// example : 100px ,  100%     
//
// =>> for height u can use 'full' wich will try to resize the iframe to the content height
//
// example HTML: 
//<div id="loadImg_ifr3">
//<img src="img/ajax_load_HUGE.gif"/> Some extra text to show while loading
//</div>
//<iframe id="ifr3" src="http://www.google.be" onload="iframeLoaded('_3','full','100%');" height="1px" width="1px" ></iframe>
// >>> here UID must be '_3'
function iframeLoaded(uid, height, width){
	hidediv("loadImg_" + uid);
	var frm = gById(uid);
	//alert(height);
	if (height == "full"){
	    try{
	    var hgt = frm.contentWindow.document.body.scrollHeight + 35;
	    frm.height = hgt + "px";
	    }catch(err){
	        try{
	            var hgt = frm.document.body.offsetHeight;
	        }catch(err){
	            setIframeHeight( uid);  //"iframe" +
	            frm.height = hgt + "px";
	        }
	    }
	}else{
	    frm.height = height;
	}
    //if (width == 'fullSize'){
	//    frm.width = '' + (frm.contentWindow.document.body.scrollWidth + 10) + "px";
	//}else{
	    frm.width = width;
	//}
}
		function setIframeHeight(iframeID) {
		  var iframeEl = document.getElementById? document.getElementById(iframeID): document.all? document.all[iframeID]: null;
		  if (iframeEl) {
		  iframeEl.style.height = "auto"; // helps resize (for some) if new doc shorter than previous
		  var h = alertSize(iframeEl);
		  var new_h = h; //(h-148);
		  iframeEl.style.height = new_h + "px";
		  }
		}

		function alertSize(iframeEl) {
		  var myHeight = 0;
		  if( typeof( window.innerWidth ) == 'number' ) {
		    //Non-IE
		    myHeight = window.innerHeight;
		  } else if( iframeEl.document.documentElement && ( iframeEl.document.documentElement.clientWidth || iframeEl.document.documentElement.clientHeight ) ) {
		    //IE 6+ in 'standards compliant mode'
		    myHeight = iframeEl.document.documentElement.clientHeight;
		  } else if( iframeEl.document.body && ( iframeEl.document.body.clientWidth || iframeEl.document.body.clientHeight ) ) {
		    //IE 4 compatible
		    myHeight = iframeEl.document.body.clientHeight;
		  }
		  //window.alert( 'Height = ' + myHeight );
		  return myHeight;
		}
function getIframeHeight(frameid){
    try{
    var FFextraHeight = 10;
    var currentfr=document.getElementById(frameid);
    //works in ie
    //if (currentfr.document.body.offsetHeight) {//ns6 syntax    currentfr.contentDocument && 
    //    return currentfr.document.body.offsetHeight; 
    //}else 
    return currentfr.contentWindow.document.body.scrollHeight;
    if (currentfr.Document.body.scrollHeight) {//ie5+ syntax      currentfr.Document && 
        return currentfr.Document.body.scrollHeight;
    }
    }catch(err){
        //return err.description;
    }
}

function updateIframeSize(){
    iframeLoaded('ifr', 'full', '100%');
    //onmousemove="resizeContainer();" ondatabinding="resizeContainer();" onclick="resizeContainer();"
}
function getSelectValue(ID){
	try{
	   var obj = gById(ID);
	   return obj.options[obj.selectedIndex].value
	}catch(err){
		return '';
        //return err.description;
    }
}
function isVisible(obj)
{
    if (obj == document) return true
    
    if (!obj) return false
    if (!obj.parentNode) return false
    if (obj.style) {
        if (obj.style.display == 'none') return false
        if (obj.style.visibility == 'hidden') return false
    }
    
    //Try the computed style in a standard way
    if (window.getComputedStyle) {
        var style = window.getComputedStyle(obj, "")
        if (style.display == 'none') return false
        if (style.visibility == 'hidden') return false
    }
    
    //Or get the computed style using IE's silly proprietary way
    var style = obj.currentStyle
    if (style) {
        if (style['display'] == 'none') return false
        if (style['visibility'] == 'hidden') return false
    }
    
    return isVisible(obj.parentNode)
}
	function ToggleDiv(objID){
		if (isVisible(gById(objID))){
			hidediv(objID);
		}else{
			showdiv(objID);
		}
	}
