//<!--

 /*
  * This function copies nodes from one tree to be imported
  * into another. Only css values will not be kept. That 
  * should not restrict the useability of this function
  */

 function importNode(oNode,bImportChildren){
  //  if(!document.importNode){
     var oNew;

     if(oNode.nodeType == 1){
       oNew = document.createElement(oNode.nodeName);
       for(var i = 0; i < oNode.attributes.length; i++){
	 oNew.setAttribute(oNode.attributes[i].name, oNode.attributes[i].value);
       }
       // oNew.style.cssText = oNode.style.cssText;
     } 
		
     if(bImportChildren && oNode.hasChildNodes()){
       for(var oChild = oNode.firstChild; oChild; oChild = oChild.nextSibling){
	 oNew.appendChild(importNode(oChild, true));
       }
     }else if(oNode.nodeType == 3){
       oNew = document.createTextNode(oNode.nodeValue);
     }
		
     return oNew; 
}

 //holds the xmlhttp object
 var xml;

/*
 * returns a httpRequest object. This
 * object can get and parse info from
 * a remote server, which can be imported
 * into the document tree
 */

function getHttpRequestObject(){
  if (typeof XMLHttpRequest == 'undefined'){
    var req=null;
    try {
      req = new ActiveXObject("Msxml2.XMLHTTP");
    }
    catch(e){
      try{
	req=new ActiveXObject("Microsoft.XMLHTTP");
      }
      catch(e2){
	req=null;
      }
    }
    return req;
  }
  else {
    return new XMLHttpRequest();
  }
}

/*
 * This function parses an xml file which
 * holds nodes that specify replacement of
 * nodes in the document tree. So depending
 * on what you say in the file, content in 
 * the document tree will be replaced
 */

function loadedData() 
{
  // only if req shows "complete"
  if (xml.readyState == 4) {
    // only if "OK"
    if (xml.status == 200) {
      //now get all the tag id's and their new values
      var response = xml.responseXML.documentElement.childNodes;

      for (f=0;f<response.length;f++){

	var replace = response[f].getAttribute('change');
	var newstyle = response[f].getAttribute('newstyle');
	var newContent="";
	if(response[f].firstChild){
	  newContent = response[f].firstChild.nodeValue
	};

	
	if(replace == 'content'){   //replace what's in between the tags

	  current = document.getElementById(response[f].tagName);
	  while(current.childNodes.length>0){	 	  
	    current.removeChild(current.childNodes[0]);
	  }
	  for(var a=0;a<response[f].childNodes.length;a++){
	    current.appendChild(importNode(response[f].childNodes[a],true));
	  }

	}else{                      //replace the value of an attribute
	  if(newstyle){
	     document.getElementById(response[f].tagName).style[newstyle] = newContent;
	  }
	  document.getElementById(response[f].tagName)[replace] = newContent;

	}
      }
    } else {
      alert("There was a problem retrieving the XML data:\n" + xml.statusText);
    }
  }
}

/*
 * this function loads data from the server and uses
 * this data to update the document tree, as soon
 * as it is loaded. Disable anti cache parameter
 * to make queries to server scripts work.
 */

function getData(url,bCache){
  xml = getHttpRequestObject()
  var d=new Date();
  if(!bCache){
    url += "?noCache=" + d.getMilliseconds();
  }
  if(xml){
    xml.onreadystatechange = loadedData;
    xml.open("GET", url, true);
    xml.send(null);
  }else{
    alert("shit no xmlHTTP object");
  }
}

/*
 * This function I stole from dreamweaver
 * however I removed the MM to make it cooler
 */

function jumpMenu(targ,selObj,restore){ 
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}

/*
 * wpop
 * pops up
 */

function wpop(url){
  var foo = window.open(url,'bar','width=760,height=500,scrollbars=1,resizable=1');
  foo.focus();
  void(0);  
};

/*
 * swich image
 */

var regex = /(http:\/\/[\w.]+)\/(.*)/;

function switchimage(idofimage){
  var obj = document.getElementById(idofimage);
  var name = obj.src;
  if(regex.test(name)){
    name=name.replace(regex,'$1/msover$2');
  }else{
    alert("Wrong domain");
  }
  obj.src = name;
}

function switchbackimage(idofimage){
  var obj = document.getElementById(idofimage);
  var name = obj.src;
  obj.src = name.replace('msover','');
}
//-->
