var xmlHttp;
var destination;

// ----- BEGIN HANDLING PHP DOCUMENTS ------
// Called by getMainContent() in script.js
function getContent(content,dest){ 
	xmlHttp=GetXmlHttpObject();
	destination = dest;
	if(xmlHttp==null){
		alert ("Browser does not support HTTP Request");
		return;
	}
	if(content=="services_emailArchive") {
		document.getElementById(destination).innerHTML="Loading e-mail archive...";
		var url="includes/services_emailArchive.php";
	}
	/*
	else if(content=="classifieds") {
		var url="http://www.newyorkcroats.com/classifieds/index.php";
	}
	else if(content=="services_news") {
		document.getElementById(destination).innerHTML="Loading news...";
		var url="includes/services_news.php";
	}*/
	else if(content=="main_home") {
		document.getElementById(destination).innerHTML="Loading home page content...";
		var url="includes/main_home.php?lang=" + locale;
	}
/*	else if(content=="main_contactUs") {
		var url="/tinc?key=5tfxcmXN&formname=ContactUs_1";
	} */
	else{
//		var url="responsexml.php";
		var url="includes/" + content + ".php";
		url=url+"?lang=" + locale;
		url=url+"&sme=" + isServicesMenuExpanded;
		url=url+"&ime=" + isInfoMenuExpanded;
		url=url+"&cme=" + isCroatiaMenuExpanded;
		url=url+"&mmme=" + isMultimediaMenuExpanded;
		url=url+"&mime=" + isMiscMenuExpanded;
		url=url+"&lme=" + isLinksMenuExpanded;
//		url=url+"?content="+content;
//		url=url+"&type="+type;
		url=url+"&sid="+Math.random();
	}
	xmlHttp.onreadystatechange=stateChanged;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

// Initiates when PHP sends back XML-formatted response
function stateChanged(){ 
	if(xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){
		 document.getElementById(destination).innerHTML=xmlHttp.responseText;
	}
}

// Calls XML HTTP Request
function GetXmlHttpObject(){ 
 var objXMLHttp=null;
 if(window.XMLHttpRequest)
  {
  objXMLHttp=new XMLHttpRequest();
  }
 else if(window.ActiveXObject)
  {
  objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
 return objXMLHttp;
}
// ----- END HANDLING PHP DOCUMENTS ------

// ----- BEGIN HANDLING XML DOCUMENTS ------
// Loads an XML document
function loadXMLDoc(fname) {
	var xmlDoc;
	// code for IE
	if (window.ActiveXObject)
	  {
	  xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
	  }
	// code for Mozilla, Firefox, Opera, etc.
	else if (document.implementation && document.implementation.createDocument)
	{
	  xmlDoc=document.implementation.createDocument("","",null);
	}
	else
	{
	  alert('Your browser cannot handle this script');
	}
	xmlDoc.async=false;
	xmlDoc.load(fname);
	return(xmlDoc);
}

// Script for formatting an XML document with it's respective XSL. Called by buttons in "expand____.php"
function getMainContent_XML(content,nav) {
	xmlName = "http://www.newyorkcroats.com/includes/" + content + ".xml";
	xslName = "http://www.newyorkcroats.com/xsl/" + content + ".xsl";
	xml=loadXMLDoc(xmlName);
	xsl=loadXMLDoc(xslName);
	// code for IE
	if (window.ActiveXObject) {
		ex=xml.transformNode(xsl);
		document.getElementById("dynamicContent_td").innerHTML=ex;
	}
	// code for Mozilla, Firefox, Opera, etc.
	else if (document.implementation && document.implementation.createDocument) {
		xsltProcessor=new XSLTProcessor();
		xsltProcessor.importStylesheet(xsl);
		resultDocument = xsltProcessor.transformToFragment(xml,document);
		document.getElementById("dynamicContent_td").innerHTML = "";
		document.getElementById("dynamicContent_td").appendChild(resultDocument);
	}
	document.title = "new york croats dot com [version 4]: " + nav;
	document.getElementById('thirdLevelLine_hx_id').innerHTML=nav;
}
// ----- END HANDLING XML DOCUMENTS ------