var isOver = false;
var oldSearchVal = '';

function hoverIn(){
	isOver = true;
	checkNavBar();
}

function hoverOut(){
	isOver = false;
}

function checkNavBar(){
	d_m = document.getElementById('download_menu');
	if (isOver == false){
		d_m.style.display = "none";
	}else{
		d_m.style.display = "block";
		setTimeout("checkNavBar()", 300);
	}
}

function inSearch(){
	s_b = document.getElementById('sq');
	if (s_b.value == "type your search here"){
		s_b.value = "";
	}
}

function outSearch(){
	s_b = document.getElementById('sq');
	if (s_b.value == ""){
		s_b.value = "type your search here";
	}
}

function hover(lightwhat){
	if (lightwhat.className == 'litrow'){
		lightwhat.className = 'title';
	}else{
		lightwhat.className = 'litrow';
	}
}


var http_request = false;

function tryIT(which){
	linkz = document.getElementById("link_" + which);
	linkz.href = "javascript: return false;";
	underrow = document.getElementById("xpand_" + which);
	undercell = document.getElementById("cell_" + which);
	var leHeight = underrow.offsetHeight;
	if (leHeight > 3){
			underrow.style.height = "0px";
			undercell.innerHTML = '';
	}else{
			tempval = '<div class="loading" align="center"><img src="/images/circle_loader.gif" /><br />';
			if (window.XMLHttpRequest) {
			} else {
				tempval = tempval + '<p>Internet Explorer 6 will take ~10 seconds to load. We appologize for Microsoft&acute;s shortcomings.</p>';
			}
			tempval = tempval + '</div>';
			undercell.innerHTML = tempval;
			underrow.style.height = null;
			getD(which);
	}
}

function makeSyncRequest(doiturl, poststr, id){
	http_request = false;
	
	if (window.XMLHttpRequest) { // Mozilla, Safari,...
		http_request = new XMLHttpRequest();
		if (http_request.overrideMimeType) {
			  http_request.overrideMimeType('text/xml');
			  // See note below about this line
		}
	} else if (window.ActiveXObject) { // IE
		try {
			  http_request = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			  try {
					http_request = new ActiveXObject("Microsoft.XMLHTTP");
			  } catch (e) {}
		}
	}
	if (!http_request) {
		alert('Giving up :( Cannot create an XMLHTTP instance');
		return false;
	}
	  

	http_request.onreadystatechange = function() { alertContents(http_request, id); };
	http_request.open('POST', doiturl, true);
	http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	http_request.setRequestHeader("Content-length", poststr.length);
	http_request.setRequestHeader("Connection", "close");
	http_request.send(poststr);	
}

function alertContents(hrequest, id){
	if (hrequest.readyState == 4) {
		if (hrequest.status == 200) {
			document.getElementById('cell_' + id).innerHTML = hrequest.responseText;
		} else {
			alert('There was a problem with the request.');
		}
	}
}

function doNoRefRedirect(url){
  // alert('hello!');
  
  hide_referer = window.open ("about:blank", "_blank", "");
  
  hide_referer.document.write("<html>");
  hide_referer.document.write("<head>");
  hide_referer.document.write("</head>");
  hide_referer.document.write("<body>");
  hide_referer.document.write("<meta http-equiv=\"refresh\" content=\"0;url=" + url + "\">");
  hide_referer.document.write("</body>");
  hide_referer.document.write("</html>");
  hide_referer.document.close ();
}

function copyIT(inElement) {
  if (inElement.createTextRange) {
    var range = inElement.createTextRange();
    if (range && BodyLoaded==1)
      range.execCommand('Copy');
  } else {
    var flashcopier = 'flashcopier';
    if(!document.getElementById(flashcopier)) {
      var divholder = document.createElement('div');
      divholder.id = flashcopier;
      document.body.appendChild(divholder);
    }
    document.getElementById(flashcopier).innerHTML = '';
    var divinfo = '<embed src="/_clipboard.swf" FlashVars="clipboard='+encodeURIComponent(inElement.value)+'" width="0" height="0" type="application/x-shockwave-flash"></embed>';
    document.getElementById(flashcopier).innerHTML = divinfo;
  }
  inElement.style.backgroundColor = "#d1dfe8";
  setTimeout('swapBack()', 250);
}


function submitSearch(){
	if (document.getElementById('sq').value == 'type your search here'){
		document.searchform.focus();
	}else{
		document.searchform.submit();
	}
}

function bookmarkit(title,url){
	if (window.sidebar)
		window.sidebar.addPanel(title, url, "");
	else if(window.opera && window.print){
		var elem = document.createElement('a');
		elem.setAttribute('href',url);
		elem.setAttribute('title',title);
		elem.setAttribute('rel','sidebar');
		elem.click();
	} 
	else if(document.all)
		window.external.AddFavorite(url, title);
}

function swapBack(){
	document.getElementById('linkCopy').style.backgroundColor = "#ffffff";
}