function toggle(div_id, action) {
	var el = document.getElementById(div_id);
	if ( el.style.display == 'none' ) {
		el.style.display = 'block';
	}
	else
	{
	if(action){

	}else{
		el.style.display = 'none';
		}
	}
}
function blanket_size(popUpDivVar) {
	if (typeof window.innerHeight != 'undefined') {
		viewportheight = window.innerHeight;
	} else {
		viewportheight = document.documentElement.clientHeight;
	}
	if ((viewportheight > document.body.parentNode.scrollHeight) && (viewportheight > document.body.parentNode.clientHeight)) {
		blanket_height = viewportheight;
	} else {
		if (document.body.parentNode.clientHeight > document.body.parentNode.scrollHeight) {
			blanket_height = document.body.parentNode.clientHeight;
		} else {
			blanket_height = document.body.parentNode.scrollHeight;
		}
	}



	var blanket = document.getElementById('blanket');
	blanket.style.height = blanket_height + 'px';
	var popUpDiv = document.getElementById(popUpDivVar);





	//popUpDiv_height=blanket_height/2;
	//popUpDiv_height=popUpDiv_height-200;
	popUpDiv_height=100;
	popUpDiv_height=popUpDiv_height + getScrollHeight();
	//150 is half popup's height
	popUpDiv.style.top = popUpDiv_height + 'px';


}
function getScrollHeight()
{
   var h = window.pageYOffset ||
           document.body.scrollTop ||
           document.documentElement.scrollTop;

   return h ? h : 0;
}
function window_pos(popUpDivVar) {

/*	if (typeof window.innerWidth != 'undefined') {
		viewportwidth = window.innerWidth;
	} else {
		viewportwidth = document.documentElement.clientWidth;
	}
	if ((viewportwidth > document.body.parentNode.scrollWidth) && (viewportwidth > document.body.parentNode.clientWidth)) {
		window_width = viewportwidth;
	} else {
		if (document.body.parentNode.clientWidth > document.body.parentNode.scrollWidth) {
			window_width = document.body.parentNode.clientWidth;
		} else {
			window_width = document.body.parentNode.scrollWidth;
		}
	}
	*/
			if (document.documentElement && (!document.compatMode || document.compatMode=="CSS1Compat")) {
			window_width = document.documentElement.clientWidth;
		}
		else if (document.compatMode && document.body) {
			window_width = document.body.clientWidth;
		}


	var popUpDiv = document.getElementById(popUpDivVar);
	var window_width = window_width/2-200;

	popUpDiv.style.left = window_width + 'px';
}
function popup(windowname,id, action) {
	getData(id, action);
	blanket_size(windowname);
	window_pos(windowname);
	toggle('blanket',action);
	toggle(windowname, action);
}

//Gets the browser specific XmlHttpRequest Object
function getXmlHttpRequestObject() {
	if (window.XMLHttpRequest) {
		return new XMLHttpRequest();
	} else if(window.ActiveXObject) {
		return new ActiveXObject("Microsoft.XMLHTTP");
	} else {
		alert("Not supported, please upgrade your browser.");
	}
}

//Our XmlHttpRequest object to get the auto suggest
var searchReqPopup = getXmlHttpRequestObject();

//Called from keyup on the search textbox.
//Starts the AJAX request.
function getData(id, action) {

	if (searchReqPopup.readyState == 4 || searchReqPopup.readyState == 0) {
		searchReqPopup.open("GET", '/internal/credits/' + action +'/' + id, true);
		searchReqPopup.onreadystatechange = handleSearchRequest;
		searchReqPopup.send(null);

	}

}

//Called when the AJAX response is returned.
function handleSearchRequest() {
	if (searchReqPopup.readyState == 4) {
		var str = searchReqPopup.responseText;
		var pu = document.getElementById('pu_body');
		pu.innerHTML = str;



		}
}