// Show Advertise
function show_content(id)
{
	if(document.domain=="192.168.10.2") {
		var url = "http://"+document.domain+"/Exponient/block_info.php?id=" + id;
	} else {
		var url = "http://"+document.domain+"/block_info.php?id=" + id;
	}
	loadXMLBlockContent(url,id);
}

function loadXMLBlockContent(url,id)
{
	//alert(id);
	// branch for native XMLHttpRequest object
	if (window.XMLHttpRequest)
	{
		req = new XMLHttpRequest();
		req.onreadystatechange = processloadXMLBlockContent;
		
		req.open("GET", url, true);
		req.send(null);
		// branch for IE/Windows ActiveX version
	}
	else if (window.ActiveXObject)
	{
		req = new ActiveXObject("Microsoft.XMLHTTP");
		if (req)
		{
			req.onreadystatechange = processloadXMLBlockContent;
			req.open("GET", url, true);
			req.send();
		}
	}
}

function processloadXMLBlockContent()
{
	// only if req shows "complete"
	if (req.readyState == 4) {
		// only if "OK"
		if (req.status == 200) {
			// ...processing statements go here...
			var urlpath1='';
			var block='';
			var block_left;
			var block_top;
			response  = req.responseXML.documentElement;
    			for(var x = 0; response.getElementsByTagName('urlpath')[0].childNodes[x]; x++ )
				 urlpath1 = urlpath1.concat(response.getElementsByTagName('urlpath')[0].childNodes[x].data);			
			block_position = response.getElementsByTagName('block_position')[0].firstChild.data;					 
			block_name = response.getElementsByTagName('block_name')[0].firstChild.data;
			
			/* 
				This code is added by sushant
				To get left position.
			*/
			var elem = document.getElementById("mainDiv");
			var leftOffset = elem.offsetLeft;
			var topOffset = elem.offsetTop;
			var parent = elem.offsetParent;

			while(parent != document.body)
			{
				leftOffset += parent.offsetLeft;
				topOffset += parent.offsetTop;
				parent = parent.offsetParent;
			}

			var Offsets = new Object();
			Offsets.top = topOffset;
			Offsets.left = leftOffset;
			L = Offsets.left;
			T = Offsets.top;
			if(navigator.appName=="Netscape")
			{
				W = document.getElementById('mainDiv').clientWidth-4;
			}
			else
			{
				W = document.getElementById('mainDiv').clientWidth+2;
			}
			/* End Here */

			if(block_position=="left") {
				//document.getElementById('block_id').style.marginLeft = document.getElementById(block_name).offsetLeft + 200;
				document.getElementById('block_id').style.left = L;
				document.getElementById('block_id').style.top = T;
				document.getElementById('block_id').style.width = W;
				//document.getElementById('block_id').style.marginLeft = getRealLeft(block_name) + 220;
			} else {
				//document.getElementById('block_id').style.marginLeft = document.getElementById(block_name).offsetLeft - 500;
				document.getElementById('block_id').style.left = L;
				document.getElementById('block_id').style.top = T;
				document.getElementById('block_id').style.width = W;
				//document.getElementById('block_id').style.marginLeft = getRealLeft(block_name) - 585;
			}
			//alert(document.getElementById(block_name).offsetTop);
			//document.getElementById('block_id').style.marginTop = document.getElementById(block_name).offsetTop;
			//document.getElementById('block_id').style.marginTop = getRealTop(block_name);
			document.getElementById('block_id').innerHTML = urlpath1;
			document.getElementById('block_id').style.display = "block";

			if (document.getElementById('mainDiv').clientHeight > document.getElementById('block_id').clientHeight)
			{
				var tmpHeight = (parseInt(document.getElementById('mainDiv').clientHeight) - parseInt(document.getElementById('block_id').clientHeight)) + 2;
				var tmpcontaint = '<div style="clear:both;height:'+tmpHeight+'">&nbsp;</div>';
				document.getElementById('block_id').innerHTML += tmpcontaint;
			}
			return false;
		} else {
			alert("There was a problem retrieving the XML data:\n" + req.statusText);
		}
	}
}
/*function processloadXMLBlockContent()
{
	// only if req shows "complete"
	if (req.readyState == 4)
	{
		// only if "OK"
		if (req.status == 200)
		{
			response = req.responseXML.documentElement;
			block_id = response.getElementsByTagName('block')[0].firstChild.data;
			website_response = response.getElementsByTagName('urlpath')[0].firstChild.data;
			//alert(website_response);  //see here
			document.getElementById('block_id').style.display = "block";
			document.getElementById('block_id').innerHTML = website_response;		
		}
		else
		{
			alert("There was a problem retrieving the XML data:\n" + req.statusText);
		}
	}
}*/

function hideBlock()
{
	document.getElementById('block_id').style.display = "none";
}

function show_courses(id)
{
	if(document.domain=="192.168.10.2") {
		var url = "http://"+document.domain+"/Exponient/course_info.php?id=" + id;
	} else {
		var url = "http://"+document.domain+"/course_info.php?id=" + id;
	}
        loadXMLCourseContent(url,id);	

}
function loadXMLCourseContent(url,id)
{
	// branch for native XMLHttpRequest object
	if (window.XMLHttpRequest)
	{
		req = new XMLHttpRequest();
		req.onreadystatechange = processloadXMLCourseContent;
		req.open("GET", url, true);
		req.send(null);
		// branch for IE/Windows ActiveX version
	}
	else if (window.ActiveXObject)
	{
		req = new ActiveXObject("Microsoft.XMLHTTP");
		if (req)
		{
			req.onreadystatechange = processloadXMLCourseContent;
			req.open("GET", url, true);
			req.send();
		}
	}
}
function processloadXMLCourseContent()
{
	/* 
		This code is added by sushant
		To get left and top position.
	*/
	var elem = document.getElementById("mainDiv");
	var leftOffset = elem.offsetLeft;
	var topOffset = elem.offsetTop;
	var parent = elem.offsetParent;

	while(parent != document.body)
	{
		leftOffset += parent.offsetLeft;
		topOffset += parent.offsetTop;
		parent = parent.offsetParent;
	}

	var Offsets = new Object();
	Offsets.top = topOffset;
	Offsets.left = leftOffset;
	L = Offsets.left;
	T = Offsets.top;
	if(navigator.appName=="Netscape")
	{
		W = document.getElementById('mainDiv').clientWidth-3;
	}
	else
	{
		W = document.getElementById('mainDiv').clientWidth+2;
	}
	/* End Here */


	// only if req shows "complete"
	if (req.readyState == 4) {
		// only if "OK"
		if (req.status == 200) {
			// ...processing statements go here...
			var urlpath='';
			response  = req.responseXML.documentElement;
    		for(var x = 0; response.getElementsByTagName('urlpathNew')[0].childNodes[x]; x++ )
				 urlpath = urlpath.concat(response.getElementsByTagName('urlpathNew')[0].childNodes[x].data);			
			document.getElementById('block_id').innerHTML = urlpath;
			document.getElementById('block_id').style.left = L;
			document.getElementById('block_id').style.top = T;
			document.getElementById('block_id').style.width = W;
			document.getElementById('block_id').style.display = "block";
//alert(document.getElementById('mainDiv').clientHeight+">>>>>>"+document.getElementById('course_id').clientHeight);
			
			if (document.getElementById('mainDiv').clientHeight > document.getElementById('block_id').clientHeight)
			{
				var tmpHeight = (parseInt(document.getElementById('mainDiv').clientHeight) - parseInt(document.getElementById('block_id').clientHeight)) + 2;
				var tmpcontaint = '<div style="clear:both;height:'+tmpHeight+'">&nbsp;</div>';
				document.getElementById('block_id').innerHTML += tmpcontaint;
			}
			else
			{
				var tmpcontaint = '<div style="clear:both;height:30px">&nbsp;</div>';
				document.getElementById('block_id').innerHTML += tmpcontaint;
			}
			return false;
		} else {
				alert("There was a problem retrieving the XML data:\n" + req.statusText);
				}
	}
}

/*function processloadXMLCourseContent()
{
	// only if req shows "complete"
	if (req.readyState == 4)
	{
		// only if "OK"
		if (req.status == 200)
		{
			response = req.responseXML.documentElement;
			//course_id = response.getElementsByTagName('course')[0].firstChild.data;
			website_response = response.getElementsByTagName('urlpathNew')[0].firstChild.data;
			document.getElementById('course_id').style.display = "block";
			document.getElementById('course_id').innerHTML = website_response;		
		}
		else
		{
			alert("There was a problem retrieving the XML data:\n" + req.statusText);
		}
	}
}*/
function hideCourse()
{
	document.getElementById('block_id').style.display = "none";
}

function getRealLeft(el){
	var xPos = document.getElementById(el).offsetLeft;
	var tempEl = document.getElementById(el).offsetParent;
	while (tempEl != null) {
	xPos += tempEl.offsetLeft;
	tempEl = tempEl.offsetParent;
	}
	return xPos;
}

function getRealTop(el){
	var yPos = document.getElementById(el).offsetTop;
	var tempEl = document.getElementById(el).offsetParent;
	while (tempEl != null) {
	yPos += tempEl.offsetTop;
	tempEl = tempEl.offsetParent;
	}
	return yPos;
}