var exclude=1;
var agt=navigator.userAgent.toLowerCase();
var win=0;var mac=0;var lin=1;
if(agt.indexOf('win')!=-1){win=1;lin=0;}
if(agt.indexOf('mac')!=-1){mac=1;lin=0;}
var lnx=0;if(lin){lnx=1;}
var ice=0;
var ie=0;var ie4=0;var ie5=0;var ie6=0;var com=0;var dcm;
var op5=0;var op6=0;var op7=0;
var ns4=0;var ns6=0;var ns7=0;var mz7=0;var kde=0;var saf=0;
if(typeof navigator.vendor!="undefined" && navigator.vendor=="KDE"){
	var thisKDE=agt;
	var splitKDE=thisKDE.split("konqueror/");
	var aKDE=splitKDE[1].split("; ");
	var KDEn=parseFloat(aKDE[0]);
	if(KDEn>=2.2){
		kde=1;
		ns6=1;
		exclude=0;
		}
	}
else if(agt.indexOf('webtv')!=-1){exclude=1;}
else if(typeof window.opera!="undefined"){
	exclude=0;
	if(/opera[\/ ][5]/.test(agt)){op5=1;}
	if(/opera[\/ ][6]/.test(agt)){op6=1;}
	if(/opera[\/ ][7-9]/.test(agt)){op7=1;}
	}
else if(typeof document.all!="undefined"&&!kde){
	exclude=0;
	ie=1;
	if(typeof document.getElementById!="undefined"){
		ie5=1;
		if(agt.indexOf("msie 6")!=-1){
			ie6=1;
			dcm=document.compatMode;
			if(dcm!="BackCompat"){com=1;}
			}
		}
	else{ie4=1;}
	}
else if(typeof document.getElementById!="undefined"){
	exclude=0;
	if(agt.indexOf("netscape/6")!=-1||agt.indexOf("netscape6")!=-1){ns6=1;}
	else if(agt.indexOf("netscape/7")!=-1||agt.indexOf("netscape7")!=-1){ns6=1;ns7=1;}
	else if(agt.indexOf("gecko")!=-1){ns6=1;mz7=1;}
	if(agt.indexOf("safari")!=-1 || (typeof document.childNodes!="undefined" && typeof document.all=="undefined" && typeof navigator.taintEnabled=="undefined")){mz7=0;ns6=1;saf=1;}
	}
else if((agt.indexOf('mozilla')!=-1)&&(parseInt(navigator.appVersion)>=4)){
	exclude=0;
	ns4=1;
	if(typeof navigator.mimeTypes['*']=="undefined"){
		exclude=1;
		ns4=0;
		}
	}
if(agt.indexOf('escape')!=-1){exclude=1;ns4=0;}
if(typeof navigator.__ice_version!="undefined"){exclude=1;ie4=0;}

//********************************************************************************


var AjaxFrameObject;

// constructor
function AjaxFrame(objectName, container){

	//Properties
	this.ObjectName = objectName;
	this.Container = container;
	this.DefaultHeight = 400;
	this.Width = "100%";
	this.Height = "auto";
	
	this.CssClass = "";
	
	this.LoadingMessage = "Content loading";
	this.LoadingImage = "";
	this.LoadingCssClass = "";
	this.DisplayAsLoading = false;
	
	this.UseAjax = true;
	this.WebServiceName = null;
	this.WebServiceMethod = null;
	
	this.Init = afInit;
	this.Reset = afReset;
	
	//Methods
	this.GetContentHeight = afGetContentHeight;
	this.GetIframeDocument = afGetIframeDocument;
	this.AdjustIFrameHeight = afAdjustIFrameHeight;
	this.FixHeight = afFixHeight;

	this.SetClass = afSetClass;
	
	this.FrameLoadedHandler = afFrameLoadedHandler;
	
	this.LoadContent = afLoadContent;
	this.LoadUrl = afLoadUrl;
	
	// Internal variables
	this.IframeObject = "ifrContent";
	this.LoadHandlerAdded = false;
	this.ContentWritten = false;
	this.IframeHeight = 0;
	this.OnIframeAdjust = null;

	AjaxFrameObject = this;
}

function afGetContentHeight( doc ){
	
	var h = this.DefaultHeight; // default or "fallback" height, if content measure fails

	if(doc != null){
	    
	    if( op7 ){
	        //alert("opera");
	        h = doc.body.scrollHeight+20;
	    }else if ( mz7 ){
	        //alert("firefox");
	        h = doc.body.scrollHeight+22;
	    }else if ( ns6 ){
	        //alert("netscape");
	        h = doc.body.scrollHeight;
	    }else if ( ie5 ){
	        //alert("ie");
	        h = doc.body.scrollHeight;
		}else if (!window.opera && !document.mimeType && document.all && document.getElementById){
			h = doc.body.offsetHeight;
        }	    
	    
	    /*
		if (window.opera){
			h = doc.body.scrollHeight;
		}else if (!window.opera && !document.mimeType && document.all && document.getElementById){
			h = doc.body.offsetHeight;
		}else if ( document.getElementById ) { // IE
			h = doc.body.scrollHeight;
		}
		*/
	}	
	return h;
}
function afGetIframeDocument(obj){
	var ifrDoc = null;
	if (obj.contentDocument) { // For NS6
		ifrDoc = obj.contentDocument; 
	} else if (obj.contentWindow) {	// For IE5.5 and IE6
		ifrDoc = obj.contentWindow.document;
	} else if (obj.document) {	// For IE5
		ifrDoc = obj.document;
	} 
	return ifrDoc;
}
function afAdjustIFrameHeight(){
	var ifr = getObj(this.IframeObject);
	if ( ifr ) {
		ifr.style.height = "20px";
		var doc = this.GetIframeDocument(ifr);
		if ( doc ){
            // update current height
		    this.IframeHeight = this.GetContentHeight(doc);
			ifr.style.height = this.IframeHeight + "px";
		}
        // update is done. set class back to normal
		this.SetClass(this.CssClass);

	    // call custom event handler (if present)
	    if( typeof(this.OnIframeAdjust) == "function" ){
	        this.OnIframeAdjust();
	    }
	}
}
function afFixHeight(){
	var cmd = this.ObjectName + '.AdjustIFrameHeight();';
	window.setTimeout(cmd,100);
}
function afSetClass( cssName ){
	var div = getObj(this.Container);
	if( div ) {
		div.className = cssName;
	}		
}
function afLoadContent( html ) {

	this.SetClass(this.LoadingCssClass);
	
	if ( this.ContentWritten ){
		this.Reset();
		this.LoadContent(html);
		return;
	}
	
	var ifr = getObj(this.IframeObject);
	if ( ifr ) {
		var doc = this.GetIframeDocument(ifr);
		if ( doc ){

			// write content to iframe
			doc.write(html);
			
			this.ContentWritten = true;
			
			// add handler for future load events (fired by internal navigation/links in iframe)
			var ifr = getObj(this.IframeObject);
			if ( ifr ) {
				addIframeEvent(ifr, this.FrameLoadedHandler);
			}

			// fix height for current content
			this.FixHeight();
		}
		
	}
}
function afLoadUrl( url ) {

	this.SetClass(this.LoadingCssClass);

	var ifr = getObj(this.IframeObject);
	if ( ifr ) {
		if(	this.UseAjax && this.WebServiceName!=null && this.WebServiceMethod!=null ){
			//Load content via webservice
			
		}else{
			//Load url normally
			ifr.src = url;
		}
	}

	// add handler for future load events (fired by internal navigation/links in iframe)
	var ifr = getObj(this.IframeObject);
	if ( ifr && this.Height == "auto" ) {
		addIframeEvent(ifr, this.FrameLoadedHandler);
	}

}
function afFrameLoadedHandler(){
	//can't use "this" because it's fired via event handler
	AjaxFrameObject.FixHeight();
}
function afInit(){
	this.Reset();
	if ( this.DisplayAsLoading ) this.SetClass(this.LoadingCssClass);
	else this.SetClass(this.CssClass);
}
function afReset(){
	var div = getObj(this.Container);
    
    this.IframeObject = 'ifrContent_' + this.ObjectName
	
	if( div ) {

	    // create loading div and iframe
	    var html = "";
        if ( this.Height == "auto" ) {
		    html += '<div id="divLoadingMessage">' + this.LoadingMessage + '</div>';
		    html += '<iframe id="'+ this.IframeObject +'" src="about:blank" marginwidth="0" marginheight="0" scrolling="no" frameborder="0" width="' + this.Width + '" style="height:20px;"></iframe>';
        }else{
		    html += '<iframe id="'+ this.IframeObject +'" src="about:blank" marginwidth="0" marginheight="0" scrolling="auto" frameborder="0" style="width:' + this.Width + ';height:' + this.Height + ';"></iframe>';
        }
        
		div.innerHTML = html;
		this.ContentWritten = false;
	}	
}

//**********************************************************************************************
//	Support functions
//**********************************************************************************************

function addIframeEvent( obj, fn ){
	if(window.addEventListener){ // Mozilla, Netscape, Firefox
		obj.addEventListener('load',fn, false);
	} else { // IE
		//obj = document.getElementById("contentFRM");
		obj.attachEvent("onload",fn);
	}
}
function getObj( id ){
	var obj = null;
	if( document.getElementById ){
		obj = document.getElementById(id);
	}
	return obj;
}
function dump(obj){
	var str = "";
	for( prop in obj ){
		str += prop;
		str += ": ";
		str += obj[prop];
		str += "\n";
	}
	if (arguments[1]){
		document.getElementById(arguments[1]).innerHTML = "<xmp>" + str + "</xmp>";
	}else{
		alert(str)
	}
}

function buildPage(){
	var str = "";
	
	str += "<html>";
	str += "<head>";
	str += "";
	str += "</head>";
	str += "<body>";
	
	str += "<h1>Sample Content</h1>";
	str += "<p><a href='sample2.htm'>Sample 2</a></p>";
	str += "<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Cras lectus. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Praesent sit amet pede viverra sem egestas convallis. In id purus. Vestibulum lectus arcu, vulputate ac, porta sed, tristique quis, urna. Curabitur non risus. Etiam nec magna consequat massa facilisis rutrum. Donec quis mi ac justo blandit feugiat. In justo. Curabitur ante purus, molestie sit amet, volutpat at, pulvinar eget, diam. Nunc at nibh vel odio adipiscing consequat. Ut ac urna. Curabitur ac urna. Morbi luctus pede at ligula. Cras id urna in lorem molestie tincidunt. Cras ac lacus. Cras neque nunc, hendrerit non, aliquam non, molestie at, elit. Phasellus sit amet eros sit amet quam lobortis suscipit. Morbi nonummy volutpat libero. Phasellus vel risus. </p>";
	str += "<p>Maecenas nibh. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos hymenaeos. Suspendisse purus. In sit amet velit non erat consectetuer pulvinar. Mauris ipsum. Aenean sit amet magna non ante volutpat accumsan. Pellentesque dui lorem, adipiscing facilisis, convallis facilisis, scelerisque sed, augue. Vivamus eu nisl. In ut nisi. Curabitur ultricies felis eget mi. Praesent eleifend sapien. Morbi justo turpis, congue quis, auctor ac, imperdiet sit amet, eros. Mauris tempor imperdiet risus. Mauris quis dolor. Sed eget felis. Nulla eu augue ut odio adipiscing nonummy. Pellentesque tristique leo id odio. </p>";
	str += "<p>Duis tempus velit non odio pretium lobortis. Duis vitae pede. Nullam quis velit iaculis arcu ornare auctor. Ut venenatis. Vivamus laoreet, sapien ut iaculis lacinia, magna metus pellentesque sem, ac lobortis odio lectus sollicitudin diam. Aliquam ut ante. Donec in elit non quam consectetuer luctus. Donec feugiat varius sem. Nunc ut urna. Cras pharetra mattis sem. </p>";
	str += "";
	
	str += "</body>";
	str += "</html>";
	
	return str;
}