/******** Panels **********/

function panelButtonClick(context) {
	if ($("#" + context.attr("id") + "_panel").css("display") == "block") {
		panelHide(context);
	} else {
		panelShow(context);
	}
}

function panelShow(context) {
	$(".panel").hide();
	$(".panel_button").removeClass("panel_button_active");
	context.addClass("panel_button_active");
	$("#" + context.attr("id") + "_panel").show();
}

function panelHide(context) {
	$(".panel").hide();
	$(".panel_button").removeClass("panel_button_active");
}

function activatePanels(defaultButton) {
	$(".panel_button").click(function(){
		panelButtonClick($(this));
	});
	panelShow($("#" + defaultButton));
}

/************ Adjust iframe code *************/
function adjust(f,p) {
    var h = "auto";
    //var w = "auto";
    if (f.contentDocument) {
        h = f.contentDocument.documentElement.offsetHeight + 20 + "px";
        // the following line doesn't work as desired
       // w = f.style.width = f.contentDocument.documentElement.offsetWidth + 20 + "px";
    } else if (f.contentWindow) {
        h = f.contentWindow.document.body.scrollHeight + 5 + "px";
    //    w = f.contentWindow.document.body.scrollWidth + 5 + "px";
    }
  //  f.setAttribute("width",w);
    f.setAttribute("height",h);
    //p.setAttribute("width",w); // may or may not be needed in your situation
    //p.setAttribute("height",h); // may or may not bee need in your situation
}

// FRAME RESIZE
function resizeIframe(iframe,nextIframeId){
	if(typeof iframe == 'undefined'){
		iframe = $("iframe").get(0);
		if (iframe.contentDocument && iframe.contentDocument.body.offsetHeight) {
			// Mozilla specific 
			iframe.style.height = iframe.contentDocument.body.offsetHeight + 'px';
		} else {
			if (iframe.Document && iframe.Document.body.scrollHeight) {
				// IE specific
				iframe.style.height = iframe.Document.body.scrollHeight + 'px';
			}
		}
	}
	if (typeof iframe != 'undefined') {
		if (typeof iframe == 'string') {
			iframe = document.getElementById(iframe);
			
		}
	
		//iframe.style.display = "block";
		
		if (iframe.contentDocument && iframe.contentDocument.body.offsetHeight) {
			// Mozilla specific 
			iframe.style.height = iframe.contentDocument.body.offsetHeight + 'px';
		} else {
			if (iframe.Document && iframe.Document.body.scrollHeight) {
				// IE specific
				iframe.style.height = iframe.Document.body.scrollHeight + 'px';
			}
		}
		if (iframe.addEventListener) {
			iframe.addEventListener("load", readIframe, false);
		} else {
			if (iframe.attachEvent) {
				iframe.detachEvent("onload", readIframe);
				iframe.attachEvent("onload", readIframe);
			}
		}
		if (typeof nextIframeId != 'undefined' && nextIframeId != '') {
			resizeIframe(window.parent.document.getElementById(nextIframeId), '');
		}
	}
	
}

function readIframe(loadevt) {
	var crossevt	= (window.event) ? event : loadevt;
	var iframeRoot	= (crossevt.currentTarget) ? crossevt.currentTarget : crossevt.srcElement;
	if (iframeRoot) {
		resizeIframe(iframeRoot);
	}
}
function popitup(url) {
	newwindow=window.open(url,'name','height=675,width=590');
	if (window.focus) {newwindow.focus()}
	return false;
}

