
// When opening the setup alert pages, we need to make sure the setup alert page gets refreshed,
// The only way to do this consitantly is to indicate this in a cookie.  We can then use an onmouseover
// in the pop up window, to check for this cookie, and if it's found refresh the page 
function setDoRefresh() {
	// Set cookie
	document.cookie = 'refreshAlertPage=Yes Please; path=/';
}
function clearRefresh() {
	document.cookie = 'refreshAlertPage=No Thanks; path=/';
}

function doRefresh() {
	var browser=navigator.appName;
	var b_version=navigator.appVersion;
	var version=parseFloat(b_version);
	
	if(browser == "Microsoft Internet Explorer" && version == 4) {
		// read cookie
		var myCookie = document.cookie;
		//alert(myCookie);
		// IF cookie found 
		if (myCookie.indexOf("refreshAlertPage=Yes Please") != -1) {
			// remove the cookie
			clearRefresh();
			// refresh the page
			history.go(0);
		} // ENDIF
	}
}


function openUrlWindow(id, type) {
	page = "/common/openUrl.jsp";
	if (id != null) {
		page += "?id=" + id + "&type=" + type;
	}
	windowPrefs = "toolbar=no,directories=no,status=yes,menubar=no,scrollbars=yes,resizable=yes,width=480,height=320";
	urlWindow = window.open(page, "openUrl", windowPrefs);
	urlWindow.focus();
}

function durableUrl(id, type) {
	//var articleRoot = "http://gateway.proquest.com/openurl?url_ver=Z39.88-2004&res_dat=xri:prisma&rft_val_fmt=info:ofi/fmt:kev:mtx:article&rft_dat=xri:prisma:fullrec:"; 
	//var journalRoot = "http://gateway.proquest.com/openurl?url_ver=Z39.88-2004&res_dat=xri:prisma&rft_val_fmt=info:ofi/fmt:kev:mtx:journal&rft_dat=xri:prisma:journal:";
	//alert("123DurableUrl requested " + id + "," + type);
	//var url = "";
	//if (type == "fullrec") {
	//	url = articleRoot + id;
	//}
	//document.forms.copythis = url;
	
	//var f = document.forms;
	//alert(copythis);
	
	//var input = document.getElementById("durableContainer");
	//alert(input);
	
	//input.setAttribute("value", url);
}

function saveToMyArchive() {
	document.forms['StorableObjectForm'].submit();
}

function deleteAll(msg, url) {
	if (confirm(msg))
		window.location = url;
}

function pop_help(item_url)
{
	window.open(item_url,'pop_help','toolbar=no,location=no,directories=no,status=no,menubar=no,resizable=yes,copyhistory=no,scrollbars=yes,width=700,height=500');
} 

function change_page_size(pageSize, formobj)
{
	formobj["value(pageSize)"].value = pageSize;
	formobj.submit();
}

function launchSummaryWindow() {
	// I use 'open' to get the window, and then change the location, as
	// there's a 'feature' in IE which means that if the window is already
	// open, then 'open' doesn't change it's location.  Bloody thing.
	windowPrefs = "toolbar=no,directories=no,status=yes,menubar=no,scrollbars=yes,resizable=yes,width=480,height=600";
	urlWindow = window.open("", "summary", windowPrefs);
	urlWindow.location = "/search/overviewSummary.do";
	urlWindow.focus();
}

function back2main(url) 
	{
		// Make sure the main window hasn't been closed accidentally.
		if(opener && !opener.closed)
		{
		    	opener.location.replace(url);
		}
		else
		{
			var	sOptions = ",location=yes,menubar=yes,resizable=yes,status=yes,toolbar=yes,copyhistory=yes,directories=yes,scrollbars=yes";
			var	nWidth	= 800;
			var	nHeight	= 600;		
			opener = CreateSatellite(url, "", nWidth, nHeight, "center", sOptions);
			opener.opener = null;
		}
	}
	
	function doPopUps() {
		if (!document.getElementsByTagName) return false;
		var links = document.getElementsByTagName("a");
		for (var i=0; i < links.length; i++) {
			// attributes if single page only, e.g. end session - named 'popUp1'
			if (links[i].className && (' ' + links[i].className + ' ').indexOf(' popUp1 ') != -1) {
				links[i].onclick = function() {
					window.open(this.href,'PopUp1','menubar=yes,resizable=yes,status=yes,width=480,height=320');
					return false;
				}
			}	 
// attributes for multiple page Help popup - named 'PopUpHelp'
else if (links[i].className && (' ' + links[i].className + ' ').indexOf(' popUpHelp ') != -1) {
links[i].onclick = function() {
window.open(this.href,'PopUpHelp','toolbar=yes,menubar=yes,resizable=yes,status=yes,scrollbars=yes,width=518,height=480');
return false;
}
} 
// attributes for any other multiple page popup- named 'PopUpMulti'
else if (links[i].className && (' ' + links[i].className + ' ').indexOf(' popUpMulti ') != -1) {
links[i].onclick = function() {
	window.open(this.href,'PopUpMulti','toolbar=yes,menubar=yes,resizable=yes,status=yes,scrollbars=yes,width=790,height=580');
return false;
}
}

}
}

window.onload = doPopUps;

// ---------------------------------------------------------------------
//   Toggle visibility, from http://www.dustindiaz.com/dhtml-expand-and-collapse-div-menu/
// ---------------------------------------------------------------------

function switchVis(obj) {
	if(document.getElementById) {
		var el = document.getElementById(obj);
	}
	if ( el.style.display != "none" ) {
		el.style.display = 'none';
	}
	else {
		el.style.display = '';
	}
}


//new durable url layer
/***********************************************
* Drop Down/ Overlapping Content- © Dynamic Drive (www.dynamicdrive.com)
* This notice must stay intact for legal use.
* Visit http://www.dynamicdrive.com/ for full source code
***********************************************/
function getposOffset(overlay, offsettype){
	var totaloffset=(offsettype=="left")? overlay.offsetLeft : overlay.offsetTop;
	var parentEl=overlay.offsetParent;
	while (parentEl!=null){
		totaloffset=(offsettype=="left")? totaloffset+parentEl.offsetLeft : totaloffset+parentEl.offsetTop;
		parentEl=parentEl.offsetParent;
	}
	return totaloffset;
}

function overlay(curobj, subobjstr, opt_position){
	if (document.getElementById){
		var subobj=document.getElementById(subobjstr)
		subobj.style.display=(subobj.style.display!="block")? "block" : "none"
		var xpos=getposOffset(curobj, "left")+((typeof opt_position!="undefined" && opt_position.indexOf("right")!=-1)? -(subobj.offsetWidth-curobj.offsetWidth) : 0) 
		var ypos=getposOffset(curobj, "top")+((typeof opt_position!="undefined" && opt_position.indexOf("bottom")!=-1)? curobj.offsetHeight : 0)
		subobj.style.left=xpos+"px"
		subobj.style.top=ypos+"px"
		return false
	} else {
		return true
	}
}

function overlayclose(subobj){
	document.getElementById(subobj).style.display="none"
}  








//global variables that can be used by ALL the function son this page.
var inputs;
var imgFalse = '/images/false.png';
var imgTrue = '/images/true.png';

//this function runs when the page is loaded, put all your other onload stuff in here too.
function init() {
    //replaceChecks();
}

function replaceChecks() {
    
    //get all the input fields on the page
    inputs = document.getElementsByTagName('input');

    //cycle trough the input fields
    for(var i=0; i < inputs.length; i++) {

        //check if the input is a checkbox
        if(inputs[i].getAttribute('type') == 'checkbox') {
            
            //create a new image
            var img = document.createElement('img');
            
            //check if the checkbox is checked
            if(inputs[i].checked) {
                img.src = imgTrue;
            } else {
                img.src = imgFalse;
            }

            //set image ID and onclick action
            img.id = 'checkImage'+i;
            //set image
            img.onclick = new Function('checkChange('+i+')');
            //place image in front of the checkbox
            inputs[i].parentNode.insertBefore(img, inputs[i]);
            
            //hide the checkbox
            inputs[i].style.display='none';
        }
    }
}

//change the checkbox status and the replacement image
function checkChange(i) {

    if(inputs[i].checked) {
        inputs[i].checked = '';
        document.getElementById('checkImage'+i).src=imgFalse;

    } else {
        inputs[i].checked = 'checked';
        document.getElementById('checkImage'+i).src=imgTrue;
    }
}

function inc_stats_proc_req_change() {
	//dummy function	
}

// ajaxy stuff to increment pageimage stats.
function increment_stats() {
	if (window.XMLHttpRequest) {
		var request = new XMLHttpRequest();
		request.onreadystatechange = inc_stats_proc_req_change;
       		request.open("GET", "/imageserver/increment_stats.cgi", true);
       		request.setRequestHeader( "If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT" );
       		request.send(null);
	} else if (window.ActiveXObject) {
       		var request = new ActiveXObject("Microsoft.XMLHTTP");
        	if (request) {
        		request.onreadystatechange = inc_stats_proc_req_change;
            		request.open("GET", "/imageserver/increment_stats.cgi", true);
            		request.setRequestHeader( "If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT" );
               		request.send();
        	}
	}
	return true;
}

//this will increment counter stats, you need to pass it a jid and a colume (either fulltexts, or pageimages).
function increment_counter_stats(jid,column, articleid, cid ) {
	if (window.XMLHttpRequest) {
		var request = new XMLHttpRequest();
		request.onreadystatechange = inc_stats_proc_req_change;
    		request.open("GET", "/imageserver/increment_stats.cgi?type=counter&jid=" + jid  + "&articleid=" + articleid + "&cid=" + cid + "&column=" + column, true);
    		request.setRequestHeader( "If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT" );
    		request.send(null);
	} else if (window.ActiveXObject) {
    		var request = new ActiveXObject("Microsoft.XMLHTTP");
     	if (request) {
     		request.onreadystatechange = inc_stats_proc_req_change;
         		request.open("GET", "/imageserver/increment_stats.cgi?type=counter&jid=" + jid  + "&articleid=" + articleid + "&cid=" + cid + "&column=" + column, true);
         		request.setRequestHeader( "If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT" );
            		request.send();
     	}
	}
	return true;
}

