﻿// JScript File
String.prototype.trim = function()
{
	return this.replace(/^\s+|\s+$/g,"");
}
String.prototype.ltrim = function()
{
	return this.replace(/^\s+/,"");
}
String.prototype.rtrim = function()
{
	return this.replace(/\s+$/,"");
}
function isEven(num)
{
  return !(num % 2);
}
function isOdd(num)
{
  return !isEven(num);
}
function setCookieValue(cookieName,cookieValue)
{
	document.cookie = cookieName + "=" + escape(cookieValue);
}
function getCookieValue(cookieName)
{
	//Read the cookie property
	var allCookies = document.cookie;
	//Look for the start of the cookie
	var sCookieName = cookieName + "=";
	var pos = allCookies.indexOf(sCookieName);
	//If we find a cookie with this name, return that value
	if (pos != -1)
	{
		var start = pos + sCookieName.length;
		var end = allCookies.indexOf(";", start);
		if (end == -1) end = allCookies.length;
		var value = allCookies.substring(start, end);
		value = unescape(value);
		return value;
	}
	else
	{
		return "";
	}
}
function getWindowWidth()
{
	var windowWidth = 0;
	if (typeof(window.top.innerWidth) == 'number') {
		windowWidth = window.top.innerWidth;
	}
	else {
		if (window.top.document.documentElement && window.top.document.documentElement.clientWidth) {
			windowWidth = window.top.document.documentElement.clientWidth;
		}
		else {
			if (window.top.document.body && window.top.document.body.clientWidth) {
				windowWidth = window.top.document.body.clientWidth;
			}
		}
	}
	windowWidth -= 5;
	return windowWidth;
}
function getWindowHeight()
{
	var windowHeight = 0;
	if (typeof(window.top.innerHeight) == 'number') {
		windowHeight = window.top.innerHeight;
	}
	else {
		if (window.top.document.documentElement && window.top.document.documentElement.clientHeight) {
			windowHeight = window.top.document.documentElement.clientHeight;
		}
		else {
			if (window.top.document.body && window.top.document.body.clientHeight) {
				windowHeight = window.top.document.body.clientHeight;
			}
		}
	}
	windowHeight -= 5;
	return windowHeight;
}
function setHeight(elid)
{
	document.getElementById(elid).style.height = getWindowHeight() + "px";
}
function setHeight_offset(elid,ioffset)
{
	var pxHeight = getWindowHeight();
	pxHeight -= ioffset;
	if (pxHeight < 100)
		pxHeight = 100;
	document.getElementById(elid).style.height = pxHeight + "px";
}
function checkWidth(elid,defaultHeight)
{
	if (document.all)	//IE
	{
		//alert("scrollHeight = " + window.document.documentElement.scrollHeight + "\nclientHeight = " + window.document.documentElement.clientHeight);
		//alert("scrollWidth = " + window.document.documentElement.scrollWidth + "\nclientWidth = " + window.document.documentElement.clientWidth);
		if (document.documentElement.scrollHeight > document.documentElement.clientHeight)
		{
			adjWidth = window.document.documentElement.clientWidth - 10;
			document.getElementById(elid).style.width = adjWidth + "px";
		}
	}
	else
	{
		if (window.document.documentElement.scrollHeight > window.document.documentElement.clientHeight)
		{
			adjWidth = window.document.documentElement.clientWidth + 5;
			document.getElementById(elid).style.width = adjWidth + "px";
		}
		document.getElementById(elid).style.height = defaultHeight + "px";
	}
}
function showElement(elid)
{
	document.getElementById(elid).className = "clsShow";
}
function hideElement(elid)
{
	if (elid == "mystuff_viewer")
		resetAccountCartTabs();
	document.getElementById(elid).className = "clsHide";
}
function openMyStuff(url)
{
	resetAccountCartTabs();
	var currentLinkTab = document.getElementById("navtab_searching").lastChild;
	var currentLink = currentLinkTab.firstChild;
	var currentOpenedTab = currentLinkTab.previousSibling;
	currentOpenedTab.className = "clsHide";
	hideElement("page_content_container");
	currentLinkTab.className = "clsShow";
	currentLinkTab.className = "navtab";
	if (document.getElementById("book_viewer"))
	{
		if (document.getElementById("book_viewer").className == "clsShow")
		{
			hideElement("navtab_book_current");
			showElement("navtab_book_link");
			document.getElementById("navtab_book_link").className = "navtab";
		}
		strResultLink = currentLink.href;
		// If the result tab link has been changed to force s re-submit, then we do not want to change it
		// So only change it if "submitForm" is not in the link text
		if (strResultLink.indexOf("submitForm") == -1)
		{
			currentLink.href = "javascript:closeMyStuff();closeBook();";
		}
	}
	else
	{
		currentLink.href = "javascript:closeMyStuff();";
	}
	if (url == "shoppingCart.asp")
	{
		document.getElementById("link_cart").className = "clsHide";
		document.getElementById("img_cart_current").className = "clsShow";
	}
	if ((url == "account.asp") || (url == "subscriptionForm.asp"))
	{
		document.getElementById("link_account").className = "clsHide";
		document.getElementById("img_account_current").className = "clsShow";
	}
	showElement("mystuff_viewer");
	window.frames["mystuff_frame"].window.document.open();
	window.frames["mystuff_frame"].window.document.write("<html><body><br><br><center><img src=\"images/loading.gif\" /></center></body></html>");
	window.frames["mystuff_frame"].window.document.close();
	document.getElementById("mystuff_frame").src = url;
}
function closeMyStuff()
{
	if (document.getElementById("navtab_book_current"))
	{
		//alert(document.getElementById("navtab_book_current").className);
		if (document.getElementById("navtab_book_current").className == "clsHide")
		{
			hideElement("navtab_book_link");
			showElement("navtab_book_current");
		}
	}
	else
	{
		var currentLinkTab = document.getElementById("navtab_searching").lastChild;
		var currentOpenedTab = currentLinkTab.previousSibling;
		currentLinkTab.className = "clsHide";
		showElement("page_content_container");
		currentOpenedTab.className = "clsShow";
	}
	hideElement("mystuff_viewer");
}
function openHelp(strTitle,strLocation)
{
	showElement("help_viewer");
	document.getElementById("helpTitle").innerHTML = strTitle;
	document.getElementById("help_frame").src = strLocation;
}
function openImageByID(iRecordID,imageForm,imageFormAction)
{
	var currentRecordID = imageForm.iRecordID.value;
	window.top.showElement("image_viewer");
	window.frames["image_frame"].document.open();
	window.frames["image_frame"].document.write("<html><body><br><br><center><img src=\"images/loading.gif\" /></center></body></html>");
	window.frames["image_frame"].document.close();
	imageForm.iRecordID.value = iRecordID;
	imageForm.action = "viewImage.asp";
	imageForm.target = "image_frame";
	imageForm.submit();
	//must reset the form values so the user can still use the original form
	imageForm.iRecordID.value = currentRecordID;
	imageForm.action = imageFormAction;
	imageForm.target = "";
}
function resetAccountCartTabs()
{
	document.getElementById("link_account").className = "clsShow";
	document.getElementById("img_account_current").className = "clsHide";
	if (document.getElementById("link_cart"))
	{
		document.getElementById("link_cart").className = "clsShow";
		document.getElementById("img_cart_current").className = "clsHide";
	}
}
function closeContact()
{
	hideElement("contact_viewer");
	document.getElementById("contact_frame").src = "ContactUs.asp";
}
function btn_submit_mouseover(elid)
{
	document.getElementById(elid).src = "images/" + elid + "_rd.gif";
}
function btn_submit_mouseout(elid)
{
	document.getElementById(elid).src = "images/" + elid + "_bu.gif";
}
function closePricingWindow()
{
	document.getElementById("pricingContainer").className = "clsHide";
}
// Capturing The Mouse Position in IE4-6 & NS4-6
// (C) 2000 www.CodeLifter.com
// Free for all users, but leave in this  header
// Detect if the browser is IE or not.
var mousecapIE = document.all?true:false;

// If !IE -- then set up for mouse capture
if (!mousecapIE) document.captureEvents(Event.MOUSEMOVE);

// Temporary variables to hold mouse x-y pos.s
var tempX = 0;
var tempY = 0;

// Main function to retrieve mouse x-y pos.s
function getMouseXY(e) {
  if (mousecapIE) { // grab the x-y pos.s if browser is IE
    tempX = event.clientX + document.documentElement.scrollLeft;
    tempY = event.clientY + document.documentElement.scrollTop;
  } else {  // grab the x-y pos.s if browser is NS
    tempX = e.pageX;
    tempY = e.pageY;
  }  
  // catch possible negative values in NS4
  if (tempX < 0){tempX = 0}
  if (tempY < 0){tempY = 0}  
  
  return true;
}
// Set-up to use getMouseXY function onMouseMove
//document.onmousemove = getMouseXY;

/********************************************************
	AJAX FUNCTIONS - AJAX FUNCTIONS - AJAX FUNCTIONS
********************************************************/
function createXMLHttpRequest(){
	if (typeof XMLHttpRequest != 'undefined') {
		return new XMLHttpRequest();
	}
	try {
		return new ActiveXObject("Msxml2.XMLHTTP");
	} catch (e) {
		try {
			return new ActiveXObject("Microsoft.XMLHTTP");
		} catch (e) { }
	}
	return false;
}
function getFormValues(obj) {
  var getstr = "?";
  for (i=0; i<obj.getElementsByTagName("input").length; i++) {
        if (obj.getElementsByTagName("input")[i].type == "hidden") {
           getstr += obj.getElementsByTagName("input")[i].name + "=" + 
                   obj.getElementsByTagName("input")[i].value + "&";
        }
        if (obj.getElementsByTagName("input")[i].type == "text") {
           getstr += obj.getElementsByTagName("input")[i].name + "=" + 
                   obj.getElementsByTagName("input")[i].value + "&";
        }
        if (obj.getElementsByTagName("input")[i].type == "checkbox") {
           if (obj.getElementsByTagName("input")[i].checked) {
              getstr += obj.getElementsByTagName("input")[i].name + "=" + 
                   obj.getElementsByTagName("input")[i].value + "&";
           }/* else {
              getstr += obj.getElementsByTagName("input")[i].name + "=&";
           }*/
        }
        if (obj.getElementsByTagName("input")[i].type == "radio") {
           if (obj.getElementsByTagName("input")[i].checked) {
              getstr += obj.getElementsByTagName("input")[i].name + "=" + 
                   obj.getElementsByTagName("input")[i].value + "&";
           }
     }  
     if (obj.getElementsByTagName("input")[i].tagName == "SELECT") {
        var sel = obj.getElementsByTagName("input")[i];
        getstr += sel.name + "=" + sel.options[sel.selectedIndex].value + "&";
     }
     
  }
  return getstr;
}
/********************************************************
	END END END END END END END END END END END END
	AJAX FUNCTIONS - AJAX FUNCTIONS - AJAX FUNCTIONS
********************************************************/

/*****************************************************************************
The following functions are empty because they are not used in non-IE browsers
*****************************************************************************/
function btn_mouseover(elid)
{
	//document.getElementById(elid).style.top = "-21px";
}
function btn_search_mouseover(elid)
{
	//document.getElementById(elid).style.top = "-33px";
}
function icon_mouseover(elid)
{
	//document.getElementById(elid).style.top = "-30px";
}
function icon_mouseover_20(elid)
{
	/*
	document.getElementById(elid).style.position = "absolute";
	document.getElementById(elid).style.left = "0px";
	document.getElementById(elid).style.top = "-20px";
	*/
}
function tab_mouseover(elid)
{
	//document.getElementById(elid).style.top = "-20px";
}
function btn_mouseout(elid)
{
	//document.getElementById(elid).style.top = "0px";
}