// ==============================================================
// telepark.cms

// This Software is copyright (c) 2007 by telepark, 
// Inh. Patrick Thomas, www.telepark.de. 
// All rights reserved. 

// You may not modify, extend, alter, reverse engineer or emulate
// the functionality, or create derivative works of the 
// Software in parts or it's entirety without the prior
// written consent of telepark.
// ==============================================================

// create HttpRequest
function createHttpRequest() {
	var xmlhttp;
 	try {
 		xmlhttp = new XMLHttpRequest();
 	} catch (e) {
  		var XmlHttpVersions = new Array('MSXML2.XMLHTTP.6.0',
  										'MSXML2.XMLHTTP.5.0',
  										'MSXML2.XMLHTTP.4.0',
  										'MSXML2.XMLHTTP.3.0',
  										'MSXML2.XMLHTTP',
  										'Microsoft.XMLHTP'
  										);
  		for (var i = 0; i<XmlHttpVersions.length && !xmlhttp; i++) {
  			try {
  				xmlhttp = new ActiveXObject(XmlHttpVersions[i]);
  			}
  			catch(e) {
  			}
  		}
 	}
 	if (!xmlhttp) {
 		alert('Error creating the XMLHttpRequest object.');
 	} else {
		return xmlhttp;
 	}
}


function toggleNewsItem(id) {
	if (document.getElementById('news_' + id)) {
		if (document.getElementById('news_' + id).style.display == 'none') {
			document.getElementById('news_' + id).style.display = 'block';
			if (document.getElementById('news_' + id).innerHTML=='') {
				loadContentBody(id);
			}
		}
		else if (document.getElementById('news_' + id).style.display == 'block') {
			document.getElementById('news_' + id).style.display = 'none';		
		}
	}
}

// load content body
function loadContentBody(articleid) {
	document.getElementById('news_' + articleid).innerHTML = '<img src=\"admin/imgs/anim-progress.gif\" style=\"margin-left:48%;\" />';
	var xmlhttp = createHttpRequest();
	xmlhttp.open("GET", "admin/modules/news/ajax/loadNewsContent.php?articleid=" + articleid, true);
	xmlhttp.onreadystatechange=function() {
	  // readyState==4 - meaning the load is complete
	  if (xmlhttp.readyState==4) {
		// only if "OK"
		var status = '';
		try {
			status = xmlhttp.status;
			if (status==200) {
			//alert(xmlhttp.responseText);
			eval(xmlhttp.responseText);
			}
		}
		catch(e) {
			status = '';
		}
	  }
	}
	xmlhttp.send(null);
}