/* Dynamic Content HACK
 * 2003 Stefan Born
 *
 * Loads content in an existing page.
 *
 * call with: onClick="content.call('destination','url');" in input buttons
 * or <a href="javascript:content.call('destination','url');">click</a>
 *
 * where destination is the id of an existing DIV
 * and url a relative path with content.
 *
 * The URL should deliver a valid HTML-page with content in body.
 *
 * No further HTML Markup needed.
 *
 * FORM and A with target "_self" will be changed.
 *
 * Use it like You want. No warranty given.
 * Keeping this information intact would be very nice.
 * 
*/

var content = new Content();

function Content(){
  this.jump2target = true;
  this.call = function(destination,source){	
  	//open connection
  	this.open(destination);
  	//call source
  	eval("c" + destination + ".location.href = source;");
  	this.clear(destination);
  	//show loading...
  	loading = document.createTextNode("loading...");
  	document.getElementById(destination).appendChild(loading);
  	if (this.jump2target) location.href="#" + destination;
  }
  this.clone = function(destination){		
  		//change link target
  		cadgerLinks = eval('c' + destination + '.document.getElementsByTagName("a");');
  		for(i=0;i<cadgerLinks.length;i++){
  			if(cadgerLinks[i].target == "_self"){
  				cadgerLinks[i].href = "javascript:content.call('" + destination + "','" + cadgerLinks[i].href + "');";
  				//cadgerLinks[i].target = "c" + destination;
  			}
  		}
  		//change form target
		cadgerForms = eval('c' + destination + '.document.getElementsByTagName("form");');
  		for(i=0;i<cadgerForms.length;i++){
  			if(cadgerForms[i].target == "_self"){
  				cadgerForms[i].target = "c" + destination;
  			}
  		}
  		this.clear(destination);
  		//clone nodes
  		document.getElementById(destination).innerHTML = eval('c' + destination + '.document.getElementsByTagName("body")[0].innerHTML;');
  }
  this.clear = function(destination){ //clear destination
  	document.getElementById(destination).innerHTML = "";
  }
  this.open = function(destination){ //open connection
  	if(!document.getElementById("connection"+destination)){
  		var connection = document.createElement("div");
  			connection.id = "connection"+destination;
  			connection.innerHTML = '<iframe name="c' + destination + '" onLoad="content.clone(\'' + destination + '\')" src="" style="display:none;"></iframe>';
  		document.getElementsByTagName("body")[0].appendChild(connection);


  	}
  }
window.status="finished"; 
}



