
var xmlhttp;

function ajax(){
	xmlhttp = false;
	try {
		xmlhttp = new XMLHttpRequest();
		//alert("defined");
	} catch (e) {
		try {
			xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		} catch (e) {
			xmlhttp = false;
			alert("Error: Unable to initialize AJAX object.");
		}
	}
}

function parseXML(oxml){
	
	//alert("response");
	
}

/**
*	obj = is the object that holds Features OR World OR Web  OR Events.
*	catobj = Optional, is the object of the category if the category was clicked.
*	tmenu = The selected top menu.. if it was features, world, web or events.
*	category = Optional, the category ID to view the contents of it.
*/
function getData(obj,catobj,tmenu,category){
	ajax();
	var url = 'glance.php?article='+tmenu+'&catid='+category;
	//alert(url);
	if(!xmlhttp){
		alert("Error");
	}
	xmlhttp.onreadystatechange = function (){
	if(xmlhttp.readyState == 4){
		//alert("Value: "+xmlhttp.responseText);
		//parseXML(xmlhttp.responseXML);
		//alert("Text: "+xmlhttp.responseXML);
		var xmlDoc=xmlhttp.responseXML.documentElement;
		//alert("Text: "+xmlDoc.getElementsByTagName("category")[0].firstChild.nodeValue);
		var articles = '';
		if(tmenu=="features"){
			articles = '<table cellpadding="0" cellspacing="0" border="0"><tr><td><div class="lmenu" style="float:left;border-left-width:0px;" onclick="getData(\'\',\'\',\'features\',\'\');">'+xmlDoc.getElementsByTagName("article")[0].firstChild.nodeValue+'</div></td>';
		} else {
			articles = '<table cellpadding="0" cellspacing="0" border="0"><tr><td><div class="mmenu" style="float:left;border-left-width:0px;" onclick="getData(\'\',\'\',\'features\',\'\');">'+xmlDoc.getElementsByTagName("article")[0].firstChild.nodeValue+'</div></td>';
		}
		if(tmenu == "world"){
			articles += '<td><div class="mmenu" style="float:left;border-bottom-color:#fff;color:#000;" onclick="getData(\'\',\'\',\'world\',\'\');">'+xmlDoc.getElementsByTagName("article")[1].firstChild.nodeValue+'</div></td>';
		} else {
			articles += '<td><div class="mmenu" style="float:left;" onclick="getData(\'\',\'\',\'world\',\'\');">'+xmlDoc.getElementsByTagName("article")[1].firstChild.nodeValue+'</div></td>';
		}
		if(tmenu=="web"){
			articles += '<td><div class="mmenu" style="float:left;border-bottom-color:#fff;color:#000;" onclick="getData(\'\',\'\',\'web\',\'\');">'+xmlDoc.getElementsByTagName("article")[2].firstChild.nodeValue+'</div></td>';
		} else {
			articles += '<td><div class="mmenu" style="float:left;" onclick="getData(\'\',\'\',\'web\',\'\');">'+xmlDoc.getElementsByTagName("article")[2].firstChild.nodeValue+'</div></td>';
		}
		//;
		try {
			if(tmenu=="event"){
				articles += '<td><div class="mmenu" style="float:left;border-bottom-color:#fff;color:#000;" onclick="getData(\'\',\'\',\'event\',\'\');">'+xmlDoc.getElementsByTagName("article")[3].firstChild.nodeValue+'</div></td>';
			} else {
				articles += '<td><div class="mmenu" style="float:left;" onclick="getData(\'\',\'\',\'event\',\'\');">'+xmlDoc.getElementsByTagName("article")[3].firstChild.nodeValue+'</div></td>';
			}
		} catch (e) {
			
		}
		articles += '</tr></table>';
		document.getElementById("glances").innerHTML= articles;
		
		
		// Now prepairing Categories.
		var categs = '';
		var alaa = '';
		document.getElementById("categories").innerHTML = '';
		document.getElementById("glance_image").innerHTML = '';
		document.getElementById("glance_title").innerHTML = '';
		document.getElementById("glance_head").innerHTML = '';
		document.getElementById("glance_f").innerHTML = '';
		document.getElementById("glance_details").innerHTML= '';
		try{
			document.getElementById("glance_authors").innerHTML = '';
		} catch(e) { }
		try{
		for (i=0;i<xmlDoc.getElementsByTagName("count")[0].firstChild.nodeValue;i++){
			//alert("Count: "+xmlDoc.getElementsByTagName("categories")[0].childNodes.length); return false;
			try{
				alaa= xmlDoc.getElementsByTagName("title")[0].firstChild.getAttribute("select");
			} catch (e){
				alaa = xmlDoc.getElementsByTagName("category")[0].firstChild.nodeValue;
			}
			try{
				if(category == xmlDoc.getElementsByTagName("category")[i].firstChild.nodeValue){
					categs += '<div class="category" style="color:#000;" onclick="getData(\'glances\',\'categories\',\''+tmenu+'\',\''+xmlDoc.getElementsByTagName("category")[i].firstChild.nodeValue+'\');">'+xmlDoc.getElementsByTagName("category")[i].firstChild.nodeValue+'</div>';
				} else {
					if(category=="" && i==0){ iss = 'style="color:#000;"';} else { iss = '';}
					categs += '<div class="category" '+iss+' onclick="getData(\'glances\',\'categories\',\''+tmenu+'\',\''+xmlDoc.getElementsByTagName("category")[i].firstChild.nodeValue+'\');">'+xmlDoc.getElementsByTagName("category")[i].firstChild.nodeValue+'</div>';
				}
			}catch(e){}
		} //alert("I = "+i);
		} catch (e) {}
		document.getElementById("categories").innerHTML= categs+'<br class="clear" />';
		categs = '';
		//alert("Title: "+xmlDoc.getElementsByTagName("title")[0].firstChild.nodeValue);
		try{//alert(xmlDoc.getElementsByTagName("img")[0].firstChild.nodeValue);
		document.getElementById("glance_image").innerHTML= '<img src="'+xmlDoc.getElementsByTagName("img")[0].firstChild.nodeValue+'" width="300" border="0" alt="At A Glance" />';
		document.getElementById("glance_image").style.height = 'auto';
		document.getElementById("glance_image").style.marginTop = '15px';
		document.getElementById("glance_image").style.marginBottom = '15px';
		} catch (e) {document.getElementById("glance_image").innerHTML= '';
		document.getElementById("glance_image").style.margin = '0';
		document.getElementById("glance_image").style.height = '0';
		}
		try{
		document.getElementById("glance_title").innerHTML= xmlDoc.getElementsByTagName("title")[0].firstChild.nodeValue;
		document.getElementById("glance_title").style.height = 'auto';
		} catch (e) {document.getElementById("glance_title").innerHTML= '';
		document.getElementById("glance_title").style.height = '0';
		document.getElementById("glance_title").style.margin = '0';
		}
		try {
		document.getElementById("glance_head").innerHTML= xmlDoc.getElementsByTagName("head")[0].firstChild.nodeValue;
		document.getElementById("glance_head").style.height = 'auto';
		}catch (e){document.getElementById("glance_head").innerHTML= '';
		document.getElementById("glance_head").style.height = '0';
		document.getElementById("glance_head").style.margin = '0';
		}
		try {
			document.getElementById("glance_authors").innerHTML = 'words: ' + xmlDoc.getElementsByTagName("words")[0].firstChild.nodeValue;
		} catch (e){document.getElementById("glance_authors").innerHTML= '';}
		try {
			document.getElementById("glance_authors").innerHTML += '&nbsp;&nbsp;&nbsp;images: ' + xmlDoc.getElementsByTagName("images")[0].firstChild.nodeValue + '</span>';
		} catch (e){ }
		try {
		document.getElementById("glance_f").innerHTML= xmlDoc.getElementsByTagName("title")[0].firstChild.getAttribute("type");
		} catch (e){document.getElementById("glance_f").innerHTML= '';}
		try {
		document.getElementById("glance_details").innerHTML= xmlDoc.getElementsByTagName("details")[0].firstChild.nodeValue;
		} catch (e) {document.getElementById("glance_details").innerHTML= '';}
		
		try{
			xmlDoc.getElementsByTagName("web")[0].firstChild.nodeValue;
			document.getElementById("glance_image").innerHTML= '';
			document.getElementById("glance_head").innerHTML= '';
			document.getElementById("glance_title").innerHTML= '';
			document.getElementById("glance_authors").innerHTML= '';
			document.getElementById("glance_f").innerHTML= '';
			document.getElementById("glance_details").innerHTML = '';
			xmlDoc.getElementsByTagName("title")[0].firstChild.nodeValue;
			for(i=0;i<xmlDoc.getElementsByTagName("added").length;i++){
			try{
				document.getElementById("glance_image").innerHTML += '<div><a style="font-size:11px;" href="web/'+xmlDoc.getElementsByTagName("title")[i].firstChild.nodeValue+'/"><img src="'+xmlDoc.getElementsByTagName("url")[i].firstChild.nodeValue.replace('web/','downloads/')+'" align="left" style="margin-right:5px;" width="45" alt="thumb" border="0" />' + xmlDoc.getElementsByTagName("title")[i].firstChild.nodeValue + '<br class="clear" />' + '</a></div><br class="clear" />';
				}catch(e){
					document.getElementById("glance_image").innerHTML = '<div><h3>'+xmlDoc.getElementsByTagName("data")[0].firstChild.nodeValue+'</h3></div>';
				}
			}
			
		} catch (e) { }
		
	}//alert('Cat: '+category);
	/*if(tmenu=="web" && category==""){
		
	}*/
	if(category=="Media" || category =="media"){
		var ic = '';
		var bc = '';
		for(i=0;i<xmlDoc.getElementsByTagName("icount")[0].firstChild.nodeValue;i++){
			if(i%2==0){
				bc = '#fff;';
			} else {
				bc = '#eee;';
			}
			ic+= '<div style="padding:5px;width:385px;margin-bottom:7px;cursor:pointer;background:'+bc+'" onclick="window.location=\'http://www.nox-mag.com/web/media/\'"><h3 style="color:#000;font-weight:bold;">'+xmlDoc.getElementsByTagName("title")[i].firstChild.nodeValue+'</h3><div>'+xmlDoc.getElementsByTagName("details")[i].firstChild.nodeValue+'</div></div>';
		}//alert(ic);
		document.getElementById("glance_image").innerHTML = ic;
	}
	if((category =="STORE") && tmenu=="web"){
				document.getElementById("glance_image").innerHTML = '<div><h3>Coming Soon...</h3></div>';
			}
	};//alert(url);
	xmlhttp.open("GET",url,true);
	xmlhttp.setRequestHeader('content-type', "text/xml");
	xmlhttp.send(null);
}