// Utility and global javascript methods for the ASMEDL site // 

/*********************************
* function changeFont
*********************************/
function changeFontSize(delta,scope) {
	var minfs = 9;
	var maxfs = 20;
	if (document.getElementById) {
		var obj = document.getElementById(scope);
		var fs;
		
		if(obj.style.fontSize)
			fs = obj.style.fontSize;
		else
			fs = 11;
			
		var fs = parseInt(fs);
		fs += delta;
		if (fs > maxfs) { 
			fs = maxfs;
			document.getElementById('increaseFont').src = "/journals/doc/ASMEDL-home/images/btn_textsize_larger_na.jpg";
		}
		else
			document.getElementById('increaseFont').src = "/journals/doc/ASMEDL-home/images/btn_textsize_larger.jpg";
		
		
		if (fs < minfs) { 
			fs = minfs;
			document.getElementById('decreaseFont').src = "/journals/doc/ASMEDL-home/images/btn_textsize_smaller_na.jpg";
		}
		else
			document.getElementById('decreaseFont').src = "/journals/doc/ASMEDL-home/images/btn_textsize_smaller.jpg";
		
		document.getElementById(scope).style.fontSize = fs + "px";
		setFontSize(obj, fs);
		//setCookie("wmfontsize", fs);
   }
}


/************************************
* function setFontSize
*
************************************/
var resizeTags = Array("p","li","h3","a");

function setFontSize(obj, fs) {
	if (!obj.innerHTML) { return false; }
	for(var i=0; i<resizeTags.length; i++){
		var tags = obj.getElementsByTagName(resizeTags[i]);
		for (var tag in tags) {
			if (tags[tag].style) {
				tags[tag].style.fontSize = fs + "px";
			}
			setFontSize(tags[tag], fs);
		}
	}
	if (obj.style) { 
		obj.style.fontSize = fs + "px";
	}
	return true;
}


//javascript check for quick search box
function jump2form() {
	document.search_form.possible1.select();
	document.search_form.possible1.focus();
}

function jump2form2() {
	document.search_form.queryText.select();
	document.search_form.queryText.focus();
}
		
function isblank(s) {
	for(var i = 0; i < s.length; i++) {
		var c = s.charAt(i);
		if ((c != ' ') && (c != '\n') && (c != '\t')) {
			return false;
		}
	}
	return true;
}

function searchformcheck() {
	var d = document.search_form.pjournals.options.selected;
	var e = document.search_form.possible1.value;
	if ((e == null) || (e == "") || (e == "Enter Any Word") || isblank(e)) {
		alert("Please enter word and click 'Go'.");
		jump2form();
	}
	else {
		return true;
	}
	return false;
}

function searchformcheck2() {
	//var d = document.search_form.pjournals.options.selected;
	var e = document.search_form.queryText.value;
	if ((e == null) || (e == "") || (e == "Enter Any Word") || isblank(e)) {
		alert("Please enter word and click 'Go'.");
		jump2form2();
	}
	else {
		return true;
	}
	return false;
}

function keywordFilled() {
	var s = document.search_form.possible1.value;
	if (s == "Enter Any Word")			
	document.search_form.possible1.value = "";
}

function keywordFilled2() {
	var s = document.search_form.queryText.value;
	if (s == "Enter Any Word")			
	document.search_form.queryText.value = "";
}

function updateValue() {
if (document.search_form.pjournals.options[document.search_form.pjournals.selectedIndex].value == '<%=coden%>' ) {
document.search_form.ACROSSASME.value = '';
} else {
document.search_form.ACROSSASME.value = 'YES';
}
} 

//**********************************************//





//Used to open a printer friendly window 
function openPrinterFriendlyWindow(url) { 
// openPrinterFriendly spawns a window with the printer friendly version of this page 
var x = 660; var y = 480; 

if (navigator.appVersion.indexOf("Mac") > 0) { 
openWindow(url, "width=" + x + ",height=" + y + ",toolbar=yes,resizable=yes,scrollbars=yes"); 
} else { openWindow(url, "width=" + x + ",height=" + y + ",status=yes,menubar=yes,toolbar=yes,resizable=yes,scrollbars=yes"); 
} 
} 

//Opens a window 

function openWindow(url, optionString) { 
window.open(url, "", optionString); 
} 
//closes a window 

function closeWindow() { 
window.close(); 
} 


//**********************************************//
// put footer on bottom of screen

		function getWindowHeight() {
			var windowHeight = 0;
			if (typeof(window.innerHeight) == 'number') {
				windowHeight = window.innerHeight;
			}
			else {
				if (document.documentElement && document.documentElement.clientHeight) {
					windowHeight = document.documentElement.clientHeight;
				}
				else {
					if (document.body && document.body.clientHeight) {
						windowHeight = document.body.clientHeight;
					}
				}
			}
			return windowHeight;
		}
		function setFooter() {
			if (document.getElementById) {
				var windowHeight = getWindowHeight();
				if (windowHeight > 0) {
					var contentHeight = document.getElementById('container').offsetHeight;
					var footerElement = document.getElementById('footer');
					var footerHeight  = footerElement.offsetHeight;
					if (windowHeight - (contentHeight + footerHeight) >= 0) {
						footerElement.style.position = 'relative';
						footerElement.style.top = (windowHeight - (contentHeight + footerHeight)) + 'px';
					}
					else {
						footerElement.style.position = 'static';
					}
				}
			}
		}
		//window.onload = function() {
		//	setFooter();
		//}
		window.onresize = function() {
			setFooter();
		}

		
		
/*
		
function setActiveStyleSheet(title) {
  var i, a, main;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) {
      a.disabled = true;
      if(a.getAttribute("title") == title) a.disabled = false;
    }
  }
}

function getActiveStyleSheet() {
  var i, a;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title") && !a.disabled) return a.getAttribute("title");
  }
  return null;
}

function getPreferredStyleSheet() {
  var i, a;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1
       && a.getAttribute("rel").indexOf("alt") == -1
       && a.getAttribute("title")
       ) return a.getAttribute("title");
  }
  return null;
}

function createCookie(name,value,days) {
//alert("test1:asmedl.js:"+name+value);
//alert("test1:asmedl.js:"+request.getRemoteUser());
  if (days) {
    var date = new Date();
    date.setTime(date.getTime()+(days*24*60*60*1000));
    var expires = "; expires="+date.toGMTString();
  }
  else expires = "";
  if(name.indexOf("style") != -1) {
        if(value == null) {
            //alert("test2:asmedl.js:"+name+value);
            value ="default";
            }
        }
  document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
  var nameEQ = name + "=";
  var ca = document.cookie.split(';');
  for(var i=0;i < ca.length;i++) {
    var c = ca[i];
    while (c.charAt(0)==' ') c = c.substring(1,c.length);
    if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
  }
  return null;
}

window.onload = function(e) {
  var cookie = readCookie("style");
  var title = cookie ? cookie : getPreferredStyleSheet();
  //var title = cookie ? cookie : 'default';
  //alert("title="+title);
  //createCookie("style", "default", 365);
  setActiveStyleSheet(title);
  setFooter();
}

window.onunload = function(e) {
  var title = getActiveStyleSheet();
  createCookie("style", title, 365);
}

var cookie = readCookie("style");
var title = cookie ? cookie : getPreferredStyleSheet();
setActiveStyleSheet(title);
*/
/************************************
* Volume/CID Search
************************************/
		function p_formcheck() {
			var u = document.login_form.vol.value;
			var p = document.login_form.pg.value;
			if ((u == null) || (u == "") || isblank(u)) {				
				showWarning('divAlertLogin', 'wrapper')
			}
			else if ((p == null) || (p == "") || isblank(p)) {
				showWarning('divAlertLogin', 'wrapper')
			}
			else {
				document.getElementById('go').className = 'off';
				return true;
			}
			return false;
		}
		
		function showWarning(el, container)
	     {
	       document.getElementById(el).style.visibility="visible";
	       if(container!=null && document.getElementById(container)!=null)
	         {
	            objContent = document.getElementById(container);
	            objContent.style.filter = "alpha(opacity:40)";
	            objContent.style.MozOpacity = .4;
	          }
	       }

	   function hideWarning(el, container)
	     {
	       document.getElementById(el).style.visibility="hidden";
	       if(container!=null && document.getElementById(container)!=null)
	         {
	            objContent = document.getElementById(container);
	            objContent.style.filter = "alpha(opacity:100)";
	            objContent.style.MozOpacity = 1;
	          }
	       if (el == "divAlert") jump2form();
		   if (el == "divAlertLogin") p_jump2form();
		   }