//-------------------------------------------------------------------
function addLoadEvent(func)
{
    var oldonload = window.onload;
    if (typeof window.onload != 'function')
        window.onload = func;
    else 
    {
        window.onload = function() 
        {
            if (oldonload)
                oldonload();
            func();
        }
    }
}
//-------------------------------------------------------------------
// getPageSize()
// Returns array with page width, height and window width, height.
// Core code from - quirksmode.com.
// Edit for Firefox by pHaez.
function getPageSize() {
	var xScroll, yScroll;

	if (window.innerHeight && window.scrollMaxY) {
		xScroll = window.innerWidth + window.scrollMaxX;
		yScroll = window.innerHeight + window.scrollMaxY;
	}
	// All but Explorer Mac.
	else if (document.body.scrollHeight > document.body.offsetHeight) {
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	}
	// Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari.
	else {
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	
	if (self.innerHeight) { // All except Explorer.
		if (document.documentElement.clientWidth) {
			windowWidth = document.documentElement.clientWidth;
		}
		else {
			windowWidth = self.innerWidth;
		}
		windowHeight = self.innerHeight;
	}
	// Explorer 6 Strict Mode.
	else if (document.documentElement && document.documentElement.clientHeight) {
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	}
	else if (document.body) { // Other Explorers.
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}
	
	// For small pages with total height less then height of the viewport.
	if (yScroll < windowHeight) {
		pageHeight = windowHeight;
	}
	else {
		pageHeight = yScroll;
	}
	
	
	// For small pages with total width less then width of the viewport.
	if (xScroll < windowWidth) {
		pageWidth = xScroll;
	}
	else {
		pageWidth = windowWidth;
	}
	
	arrayPageSize = new Array(pageWidth, pageHeight, windowWidth, windowHeight);
	return arrayPageSize;
}
//-------------------------------------------------------------------
function show_overlay_element(id)
{
	var arrayPageSize = getPageSize();
	var w = '0px';
	
	var overlay = document.getElementById("overlay");
	if(overlay)
	{
		overlay.style.width = '100%';
		overlay.style.zIndex = '10090',
		overlay.style.height = arrayPageSize[1] + 'px',
		overlay.style.visibility = 'visible';
	}
	
	var element = document.getElementById(id);
	if(element)
	{
		element.style.position = 'absolute';
		element.style.left = '100px';
		element.style.top = '50px';
		element.style.width = (arrayPageSize[0]-250) + 'px';
		w = element.style.width;
		element.style.zIndex = '10091',
		element.style.height = (arrayPageSize[3]-150) + 'px',
		element.style.visibility = 'visible';
	}
	
	if(overlay && element)
	{
		overlay.onclick = function() {
			overlay.style.visibility = 'hidden';
			element.style.visibility = 'hidden';
			};
	}
	
	var close = document.getElementById("close_button");
	if(close)
	{
		close.onclick = function() {
			overlay.style.visibility = 'hidden';
			element.style.visibility = 'hidden';
			};
	}
	
	w = Number(w.substring(0, w.length-2));
	
	return w;
}
//-------------------------------------------------------------------
var import_links = new Array();
var import_divs = new Array();


function setupImportList(idList)
{
	import_links = new Array();
	import_divs = new Array();
	
	for( var i=0; i<idList.length; i++)
	{
		import_links.push(document.getElementById('button_'+idList[i]));
		import_divs.push(document.getElementById(idList[i]));
	}
	
	for( var i=0; i<idList.length; i++)
	{
		if(i!=0)
			import_divs[i].style.display = 'none';
		else
		{
			import_divs[i].style.display = 'block';
			import_links[i].parentNode.className = 'selected';
		}
		
		import_links[i].onclick = function(){
				for(var j=0; j<import_divs.length; j++)
				{
					if(this!=import_links[j])
					{
						import_divs[j].style.display = 'none';
						import_links[j].parentNode.className = '';
					}
					else
						import_divs[j].style.display = 'block';
				}
				
				this.parentNode.className = 'selected';
			};
	}
}



//-------------------------------------------------------------------
// For the duplicates
addLoadEvent(function(){
	var anchor_dupl = document.getElementById("anchor_dupl");
	if(anchor_dupl)
	{
		anchor_dupl.onclick = function(){
				var w = show_overlay_element("duplicates_list");
				
				var col1 = document.getElementById('duplicates_import');
				var col2 = document.getElementById('duplicates_db');
				if(col1 && col2)
				{
					col1.style.width = (w-100)/2 + 'px';
					col2.style.width = (w-100)/2 + 'px';
				}
			};
	}
});
//-------------------------------------------------------------------
// 1 Click to select
addLoadEvent(function(){
	var e = document.getElementsByName('list_citeref');
	
	if(e.length > 0)
	{
		for( var i=0; i<e.length; i++)
		{
			var curE = e[i];
			curE.onclick = function() {
				var sel;
				if (window.getSelection) {
					sel = window.getSelection();
				}
				else if (document.getSelection) {
					sel = document.getSelection();
				}
				
				var range = document.createRange();
				//range.setStartBefore(this);
				//range.setEndAfter(this);
				range.selectNodeContents( this );
				
				sel.addRange( range );
				
				//alert(this.selectionStart);
				//range.select();
				};
		}
	}
});
//-------------------------------------------------------------------
addLoadEvent(function(){
	var arrayPageSize = getPageSize();
	var body = document.getElementById("body");
	if(body)
		body.style.minHeight = arrayPageSize[1] + "px";
});

