var max_width = 400;
var np_name = '';
var np_id = '';
var reviews = new Array();

function getScrollXY() 
{
	var scrOfX = 0, scrOfY = 0;
	if( typeof( window.pageYOffset ) == 'number' ) 
	{
		//Netscape compliant
		scrOfY = window.pageYOffset;
		scrOfX = window.pageXOffset;
	} 
	else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) 
	{
		//DOM compliant
		scrOfY = document.body.scrollTop;
		scrOfX = document.body.scrollLeft;
	} 
	else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) 
	{
		//IE6 standards compliant mode
		scrOfY = document.documentElement.scrollTop;
		scrOfX = document.documentElement.scrollLeft;
	}
	return [ scrOfX, scrOfY ];
}
	
function expandDiv(evt)
{
	var coors = getScrollXY();
	var nifty = document.getElementById('table_div');
	var inner = document.getElementById('content_div');
	var close = document.getElementById('close_div');
	var flash_div = document.getElementById('flash_div');
	inner.innerHTML = '';
	close.innerHTML = '';
	close.style.margin = '';
	nifty.style.top = coors[1]+evt.clientY+'px';
	nifty.style.left = (coors[0]+evt.clientX-max_width)+'px';
	
	//alert(nifty.style.top + ":" + nifty.style.left);
	nifty.style.visibility = "visible";
	inner.style.width="0px"; 
	//inner.style.height="0px"; 
	nifty.style.height="0px"; 
	inner.style.padding="15px";
	inner.style.visibility="visible"; 
	//flash_div.style.visibility="hidden";
	//alert(window.innerWidth);
	doMove();
}

function closeDiv()
{
	document.getElementById('table_div').style.visibility = "hidden";
	document.getElementById('content_div').style.visibility = "hidden";
}

function doMove() 
{	
	var nifty = document.getElementById('table_div');
	var inner = document.getElementById('content_div');
	var close = document.getElementById('close_div');
	var height = parseInt(inner.style.height.replace(/px/, ""));
	var width = parseInt(inner.style.width.replace(/px/, ""));
	//var dist = (max_width-width)/5;
	var dist = max_width/15;
	if(dist < 10) { dist = 10; }
	width += dist;
	inner.style.width = width+'px';
	
	if(width < max_width) { setTimeout(doMove,20); }
	else 
	{ 
		inner.style.visibility="visible"; 
		var html = '';
		html += '<p align="center"><b>Student Reviews</b></p>';
		for(var i = 0; i < reviews.length; i++)
		{
			html += '<p>'+reviews[i]+'</p><br>';
		}
		inner.innerHTML = html;
		close.innerHTML = '<img src="/css/close_button2.jpg" onClick="javascript: closeDiv();">';
		inner.style.padding="1px";
		//close.style.margin = '10px';
	}
}

function lookupReviews(course_id) 
{
	http.open('get','http://www.gatlineducation.com/partner_system/objects/student_reviews.php?course_id='+course_id,true);
	http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	http.setRequestHeader("Connection", "close");
	http.onreadystatechange = handleResponse;
	http.send(true);
}

	
/*
handlePledgeResponse(action) 

Waits for response to request from savePurpose and responsds accordingly.
*/
function handleResponse(action) 
{
	if(http.readyState == 4)
	{
        var response = http.responseText;
		reviews = response.split('|');
	}
}

/*
createRequestObject()

Helper function to create browser safe request objects.
*/
function createRequestObject() {
    var ro;
    var browser = navigator.appName;
    if(browser == "Microsoft Internet Explorer"){
        ro = new ActiveXObject("Microsoft.XMLHTTP");
    }else{
        ro = new XMLHttpRequest();
    }
    return ro;
}

var http = createRequestObject();
