function toggleDetails(strElement)	{
	if (document.getElementById(strElement).style.display == "none")	{
		document.getElementById(strElement).style.display = "block";
	}	else	{
		document.getElementById(strElement).style.display = "none";
	}
}

function validator()	{
	if (document.getElementById("keyword1").selectedIndex == 0) {
		alert('At Least One Keyword is Required');
		document.getElementById("keyword1").focus();
		return false;
	}
	if (document.getElementById("Comments").value == '')	{
		alert('Comments Are Required');
		document.getElementById("Comments").focus();
		return false;
	}
	return true;
}

function selectAll(strElementName)	{
	for (var intCounter	=	0; intCounter < document.getElementById(strElementName).options.length; intCounter++)	{
		document.getElementById(strElementName).options[intCounter].selected = true;
	}
}

function showCheckout()	{
	if (document.getElementById('selectedItem').value == '')	{
		document.getElementById('btnSubmit').style.display = 'none';
	}	else	{
		document.getElementById('btnSubmit').style.display = 'block';
	}
}

function dynamicShowCheckout()	{
	document.getElementById('btnSubmit').style.display = 'block';
}

function GetCookie (name) { 
	var arg = name + "="; 
	var alen = arg.length; 
	var clen = document.cookie.length; 
	var i = 0; 
	while (i < clen) { 
		var j = i + alen; 
		if (document.cookie.substring(i, j) == arg)	{
			return getCookieVal (j); 
		}
		i = document.cookie.indexOf(" ", i) + 1; 
		if (i == 0) break; 
	} 
	return null; 
}

function getCookieVal (offset) { 
	var endstr = document.cookie.indexOf (";", offset); 
	if (endstr == -1) 	{
		endstr = document.cookie.length; 
	}
	return unescape(document.cookie.substring(offset, endstr)); 
}

function getCookie(name)	{
	var dc = document.cookie;
	var prefix = name + "=";
	var begin = dc.indexOf("; " + prefix);

	if (begin == -1)	{
		begin = dc.indexOf(prefix);
		if (begin != 0) return null;
	}	else	{
		begin += 2;
	}

	var end = document.cookie.indexOf(";", begin);
	if (end == -1)	{
		end = dc.length;
	}
	return unescape(dc.substring(begin + prefix.length, end));
}

function SetCookie (name, value) { 
	var argv = SetCookie.arguments; 
    var argc = SetCookie.arguments.length; 
    var expires = (argc > 2) ? argv[2] : null; 
    var path = (argc > 3) ? argv[3] : null; 
    var domain = (argc > 4) ? argv[4] : null; 
    var secure = (argc > 5) ? argv[5] : false; 
    document.cookie = name + "=" + escape (value); 
} 

function addToCart(strSerialNo)	{
	var cookieValue;
	cookieValue = GetCookie('selectedItem');
	
	var strSerialNos = (cookieValue + ",").split(",");
	if (strSerialNos.length <= 5)	{

		if (document.getElementById('selectedItem').value != "")	{
			document.getElementById('selectedItem').value = document.getElementById('selectedItem').value + ",";
		}
		if (cookieValue != null)	{
			cookieValue += ",";
		}	else	{
			cookieValue = "";
		}

		document.getElementById(strSerialNo + 'add').style.display = 'none';
		document.getElementById(strSerialNo + 'remove').style.display = 'block';
		document.getElementById('selectedItem').value = document.getElementById('selectedItem').value + strSerialNo;
		document.cookie="selectedItem=" + cookieValue + strSerialNo;
	}	else	{
		alert('You May Only Request 5 Short Term Loan Kits at one time');
	}
	
	dynamicShowCheckout();
}

function removeFromCart(strSerialNo)	{
	var strSerialNos = document.getElementById('selectedItem').value.split(",");
	var strNewValue	= '';
	var cookieValue;
	cookieValue = GetCookie('selectedItem');
	
	for (intCounter = 0; intCounter <= (strSerialNos.length - 1); intCounter++)	{
		if (strSerialNo.replace(",", "") != strSerialNos[intCounter])	{
			strNewValue	+=	strSerialNos[intCounter] + ','
		}
	}

	document.getElementById('selectedItem').value = strNewValue;
	SetCookie("selectedItem", strNewValue);
	document.getElementById(strSerialNo + 'add').style.display = 'block';
	document.getElementById(strSerialNo + 'remove').style.display = 'none';
	dynamicShowCheckout();
}

function displayWarning()	{
	alert("You Will be Logged Out of the System in 5 minutes.\nPlease Save your Work to avoid the automatic logout.");
}

function setWarning()	{
	setTimeout('displayWarning()',2100000);
}

function moveUp(strElementName)	{
	if (document.getElementById(strElementName).selectedIndex >= 1)	{
		var selectIndex	=	document.getElementById(strElementName).selectedIndex;

		var tempValue	=	document.getElementById(strElementName).options[selectIndex - 1].value;
		var tempText	=	document.getElementById(strElementName).options[selectIndex - 1].text;

		document.getElementById(strElementName).options[selectIndex - 1].value	= document.getElementById(strElementName).options[selectIndex].value;
		document.getElementById(strElementName).options[selectIndex - 1].text	= document.getElementById(strElementName).options[selectIndex].text;

		document.getElementById(strElementName).options[selectIndex].value	= tempValue;
		document.getElementById(strElementName).options[selectIndex].text	= tempText;
	}
}


function Querystring(qs)	{
	this.params = new Object()
	this.get=Querystring_get
	if (qs == null)	{
		qs=location.search.substring(1,location.search.length);
	}
	if (qs.length == 0)	{
		return;
	}

	qs = qs.replace(/\+/g, ' ');

	var args = qs.split('&');

	for (var i=0;i<args.length;i++)	{
		var pair = args[i].split('=');
		name = unescape(pair[0]);

		var value;
		if (pair.length == 2)	{
			value = unescape(pair[1]);
		}	else	{
			value = name;
		}

		this.params[name] = value;
	}
}

function Querystring_get(key, default_) {
	if (default_ == null)	{
		default_ = null;
	}
	
	var value=this.params[key];
	
	if (value==null)	{
		value=default_;
	}

	return value;
}

function showPage(strPage, intPage)	{
	var	qs	=	new	Querystring
	var	strAction	=	strPage;
	
	strAction		+=	"?pageNumber=" + intPage;
	
	if (qs.get("AvailableHardCopy") !=	null)	{
		strAction	+=	"&AvailableHardCopy=Yes";
	}
	
	if (qs.get("AppealAuthor")	!=	null) {
		strAction	+= "&AppealAuthor="		+	qs.get("AppealAuthor");
	}
	
	if (qs.get("AppealPanel")	!=	null) {
		strAction	+= "&AppealPanel="		+	qs.get("AppealPanel");
	}
	
	if (qs.get("Category")		!=	null)	{
		strAction	+=	"&Category="		+	qs.get("Category");
	}
	
	if (qs.get("Contains")		!=	null)	{
		strAction	+=	"&Contains="		+	qs.get("Contains");
	}
	
	if (qs.get("ContentLocation")	!=	null)	{
		strAction	+=	"&ContentLocation="	+	qs.get("ContentLocation")
	}

	if (qs.get("County")		!=	null)	{
		strAction	+=	"&County="		+	qs.get("County");
	}
	
	if (qs.get("CreditType")	!=	null)	{
		strAction	+=	"&CreditType="		+	qs.get("CreditType");
	}
	
	if (qs.get("Date")		!=	null)	{
		strAction	+=	"&Date="		+	qs.get("Date");
	}
	
	if (qs.get("Day")		!=	null)	{
		strAction	+=	"&Day="		+	qs.get("Day");
	}
	
	if (qs.get("Description")	!=	null)	{
		strAction	+=	"&Description="		+	qs.get("Description");
	}
	
	if (qs.get("EventType")	!=	null)	{
		strAction	+=	"&EventType="		+	qs.get("EventType");
	}
	
	if (qs.get("FreeText")	!=	null)	{
		strAction	+=	"&FreeText="	+	qs.get("FreeText");
	}
	
	if (qs.get("From") != null) {
		strAction	+=	"&From="		+	qs.get("From");
	}

	if (qs.get("InterestArea")	!=	null)	{
		strAction	+=	"&InterestArea="	+	qs.get("InterestArea");
	}
	
	if (qs.get("ISBN")		!=	null)	{
		strAction	+=	"&ISBN="		+	qs.get("ISBN");
	}
	
	if (qs.get("ISDN")		!=	null)	{
		strAction	+=	"&ISDN="		+	qs.get("ISDN");
	}

	if (qs.get("IU")		!=	null)	{
		strAction	+=	"&IU="			+	qs.get("IU");
	}
	
	if (qs.get("Language")	!=	null)	{
		strAction	+=	"&Language="	+	qs.get("Language");
	}
	
	if (qs.get("LearningStage")	!=	null)	{
		strAction	+=	"&LearningStage="	+	qs.get("LearningStage");
	}

	if (qs.get("LName")		!=	null)	{
		strAction	+=	"&LName="		+	qs.get("LName");
	}
	
	if (qs.get("Location")	!=	null)	{
		strAction	+=	"&Location="	+	qs.get("Location");
	}

	if (qs.get("MaterialFormat")	!=	null)	{
		strAction	+=	"&MaterialFormat="	+	qs.get("MaterialFormat");
	}

	if (qs.get("MaterialType") 	!=	null)	{
		strAction 	+= 	"&MaterialType="	+	qs.get("MaterialType");
	}
	
	if (qs.get("maxCode")	!=	null)	{
		strAction	+=	"&maxCode="	+	qs.get("maxCode");
	}
	
	if (qs.get("maxDate") 	!=	null)	{
		strAction 	+= 	"&maxDate="	+	qs.get("maxDate");
	}
	
	if (qs.get("minCode")	!=	null)	{
		strAction	+=	"&minCode="	+	qs.get("minCode");
	}
	
	if (qs.get("minDate") 	!=	null)	{
		strAction 	+= 	"&minDate="	+	qs.get("minDate");
	}
	
	if (qs.get("Month")		!=	null)	{
		strAction	+=	"&Month="		+	qs.get("Month");
	}
	
	if (qs.get("Name")		!=	null)	{
		strAction	+=	"&Name="		+	qs.get("Name");
	}

	if (qs.get("OfficeLocation")	!=	null)	{
		strAction	+=	"&OfficeLocation="	+	qs.get("OfficeLocation");
	}
	
	if (qs.get("Presenter")		!=	null)	{
		strAction	+=	"&Presenter="	+	qs.get("Presenter");
	}
	
	if (qs.get("Principle")		!=	null)	{
		strAction	+=	"&Principle="	+	qs.get("Principle");
	}
	
	if (qs.get("Recipient")	!=	null)	{
		strAction	+=	"&Recipient="		+	qs.get("Recipient");
	}
	
	if (qs.get("SD") != null) {
		strAction	+=	"&SD="				+	qs.get("SD");
	}

	if (qs.get("Search")	!=	null)	{
		strAction	+=	"&Search="		+	qs.get("Search");
	}

	if (qs.get("SortBy")		!=	null)	{
		strAction	+=	"&SortBy="		+	qs.get("SortBy");
	}
	
	if (qs.get("Sponsor")		!=	null)	{
		strAction	+=	"&Sponsor="		+	qs.get("Sponsor");
	}
	
	if (qs.get("StartsWith")		!=	null)	{
		strAction	+=	"&StartsWith="		+	qs.get("StartsWith");
	}
	
	if (qs.get("SubCode")		!=	null)	{
		strAction	+=	"&SubCode="		+	qs.get("SubCode")
	}

	if (qs.get("Title")		!=	null)	{
		strAction	+=	"&Title="		+	qs.get("Title");
	}
	
	if (qs.get("Topic")		!=	null)	{
		strAction	+=	"&Topic="		+	qs.get("Topic");
	}
	
	if (qs.get("Type")		!=	null)	{
		strAction	+=	"&Type="		+	qs.get("Type");
	}
	
	if (qs.get("UniqueID")	!=	null)	{
		strAction	+=	"&UniqueID="	+	qs.get("UniqueID");
	}
	
	if (qs.get("Year")		!=	null)	{
		strAction	+=	"&Year="		+	qs.get("Year");
	}
	
	window.document.PaTTANForm.action=strAction;
	window.document.PaTTANForm.submit();
}

function noPostBack(sNewFormAction)	{
    window.document.PaTTANForm.action = sNewFormAction;
    window.document.PaTTANForm.__VIEWSTATE.name = 'NOVIEWSTATE';
	window.document.PaTTANForm.submit();
}

function Left(str, n)	{
	if (n <= 0)
		return "";
	else if (n > String(str).length)
		return str;
	else
		return String(str).substring(0,n);
}

function Mid(str, start, len)	{
	if (start < 0 || len < 0) return "";
	var iEnd, iLen = String(str).length;
	if (start + len > iLen)
		iEnd = iLen;
	else
		iEnd = start + len;
	return String(str).substring(start,iEnd);
}

function Right(str, n){
    if (n <= 0)
       return "";
    else if (n > String(str).length)
       return str;
    else {
       var iLen = String(str).length;
       return String(str).substring(iLen, iLen - n);
    }
}

function clearFormatting()	{
	pwCleanWord();
	var allText	=	document.getElementById('Content__ctl6').innerHTML
//	var sText 	=	document.selection.createRange().htmlText;
//	var oldText	=	document.getElementById('Content_TextWindow').innerHTML;
	var oldText	=	document.getElementById('Content__ctl6').innerHTML;
	
/*				var tempVar	=	""
	var fFound	=	0;

	while (sText.indexOf("<") > -1)	{
		fFound = 1;
		tempVar = tempVar + Left(sText, sText.indexOf("<") - 1)
		sText = Mid(sText, sText.indexOf(">") + 1)
	}
	tempVar = tempVar + sText;
	if (!(fFound))	{
		alert(sText);
	}	else	{
		alert(tempVar);
	}	*/
//	var re= /(<([^>]+)>)/ig;
//	var re= /(<([^>]+)>)/g;
//	var re=	/<&#91;^>&#93;*>/g;

 var re= /<\S[^><]*>/g;
//	sText = sText.replace(re,""); 
	
/*
	document.getElementById('Content_TextWindow').innerHTML	= document.getElementById('Content_TextWindow').innerHTML.replace("<P>", "~~~~", -1);
	document.getElementById('Content_TextWindow').innerHTML	= document.getElementById('Content_TextWindow').innerHTML.replace("</P>", "````", -1);
	document.getElementById('Content_TextWindow').innerHTML	= document.getElementById('Content_TextWindow').innerHTML.replace("<BR", "!!!!");
	document.getElementById('Content_TextWindow').innerHTML	= document.getElementById('Content_TextWindow').innerHTML.replace("<br>", "!!!!");
	document.getElementById('Content_TextWindow').innerHTML	= document.getElementById('Content_TextWindow').innerHTML.replace(re, "");
	document.getElementById('Content_TextWindow').innerHTML	= document.getElementById('Content_TextWindow').innerHTML.replace("~~~~", "<P>");
	document.getElementById('Content_TextWindow').innerHTML	= document.getElementById('Content_TextWindow').innerHTML.replace("````", "</P>");
	document.getElementById('Content_TextWindow').innerHTML	= document.getElementById('Content_TextWindow').innerHTML.replace("!!!!", "<BR>");
*/
//	alert('OldText: ' + oldText);
	oldText	=	oldText.replace(/&lt;/g, '<');
	oldText	=	oldText.replace(/&gt;/g, '>');
	
	oldText	=	oldText.replace(/<P>/g, '~~~~');
	oldText	=	oldText.replace(/<p>/g, '~~~~');
	oldText	=	oldText.replace(/<\/P>/g, '----');
	oldText	=	oldText.replace(/<BR>/g, '````');
	
//	oldText =	oldText.replace(/&lt;/g, '<');
//	oldText =	oldText.replace(/&gt;/g, '>');
	oldText	=	oldText.replace(re, '');
	oldText	=	oldText.replace(/~~~~/g, '<P>');
	oldText	=	oldText.replace(/----/g, '</P>');
	oldText	=	oldText.replace(/````/g, '<BR>');
//	alert('newText: ' + oldText);
	document.getElementById('Content__ctl5').innerHTML = oldText.replace(/</g, '&lt;').replace(/>/, '&gt;');
	document.getElementById('Content__ctl6').innerHTML = oldText; //.replace(/&lt;/g, '<').replace(/&gt;/g, '>');
}

function isValidEmail(objElement) {
	var str	=	objElement.value;
	if ( (str == '') || ( (str.indexOf(".") > 2) && (str.indexOf("@") > 0) ) )	{
		return true;
	}	else	{
		alert('Invalid Email Address');
		objElement.focus();
		return false;
	}
}

function isValidNumber(objElement)	{
	var str	=	objElement.value;
	if ( (str == '') || (!(isNaN(str))) )	{
		return true;
	}	else	{
		alert('Invalid Number');
		objElement.focus();
		return false;
	}
}

function isValidCurrency(objElement)	{
	var str = objElement.value;
	var elementName	=	objElement.name;
	var test = 0
	
	for (i = 0; i < str.length; i++)	{
		if (isNaN(str.substring(i, i + 1)))	{
			if ( (str.substring(i, i+1) != "$") && (str.substring(i, i+1) != ".") )	{
				test++;
			}
		}
	}
	if (test)	{
		alert(elementName + ' must be a valid currency.');
		return false;
	}	else	{
		return true;
	}
}

function isValidZip(objElement)	{
	var str = objElement.value;
	var elementName	=	objElement.name;
	var test = 0
	
	for (i = 0; i < str.length; i++)	{
		if (isNaN(str.substring(i, i + 1)))	{
			if (str.substring(i, i+1) != "-")	{
				test++;
			}
		}
	}
	if (test)	{
		alert(elementName + ' must be a valid zip code.');
		return false;
	}	else	{
		return true;
	}
}

function containsNoNumbers(objElement)	{
	var str = objElement.value;
	var elementName	=	objElement.name;
	var test = 0;
	for (i = 0; i < (str.length - 1); i++)	{
		if (!(isNaN(str.substring(i, i + 1))))	{
			if (str.substring(i, i + 1) != " ")	{
				test++;
			}
		}
	}
	if (test)	{
		alert(elementName + ' may not contain any numbers.');
		return false;
	}	else	{
		return true;
	}
}

function isRequired(objElement)	{
	var str	=	objElement.value;
	var elementName	=	objElement.name;
	if (str != '') {
		return true;
	}	else	{
		alert(elementName + ' is a Required Field');
		objElement.focus();
		return false;
	}
}

function refineSearch(strRefiningFactor)	{
	var sNewFormAction	=	"searchResults.aspx?search=" + strRefiningFactor;
	window.document.PaTTANForm.action = sNewFormAction;
	window.document.PaTTANForm.__VIEWSTATE.name = 'NOVIEWSTATE';
	window.document.PaTTANForm.submit();
}

function changeLanguage(strPageLocation)	{
	window.navigate(strPageLocation + '?PageNumber=0&Language=' + document.getElementById('txtLanguage').value);
}