/* =========================================================================

JavaScript Source File -- Created with SAPIEN Technologies PrimalScript 3.1

NAME: common.js

AUTHOR: Anthony Pollock , County of Henrico Public Library
DATE  : 4/16/2009

COMMENT: Javascript functions used by the default IIS error pages defined
in the /Common directory

============================================================================ */
function getURL(){
	var objForm = document.forms.theForm;
	var strReferrer = document.referrer;
	var strRequestedURL = location.href;
	var strRoot = "http://www.henricolibrary.org";
	var i
	
	if ( strRequestedURL.indexOf("?") > 0 ){	//This clears off any query after the "?" in the URL if any exists
		strRequestedURL = strRequestedURL.substr( 0, strRequestedURL.indexOf("?") )
	}
	
	var aryURL = strRequestedURL.split("/");  //This will be used to get the document name, which would end up in the last array element
	
	//These arrays must be kept in sync matching the bad document name with the new document name and path.
	aryOldURL = new Array( 'faqs.html',
							'meetingroom_policy.html',
							'adult.html',
							'du.htm',
							'du.html',
							'dudir.html',
							'fa.htm',
							'fa.html',
							'fadir.html',
							'ga.htm',
							'ga.html',
							'gadir.html',
							'gl.htm',
							'gl.html',
							'gldir.html',
							'libs.html',
							'np.htm',
							'np.html',
							'npdir.html',
							'tu.htm',
							'tu.html',
							'tudir.html',
							'tw.htm',
							'tw.html',
							'twdir.html',
							'mu.htm',
							'mu.html',
							'mudir.html',
							'sa.htm',
							'sa.html',
							'sadir.html',
							'va.htm',
							'va.html',
							'vadir.html',
							'hq.html',
							'Connections.pdf',
							'contact.html',
							'erefa.html',
							'getacard.html',
							'myaccount.html',
							'eAudioDirections.pdf',
							'09TU_strytime.pdf',
							'09TW_strytime.pdf',
							'yajobs.html',
							'renewal.html',
							'netlib.html',
							'application.html',
							'erpub.html',
							'vari.html',
							'policy.html',
							'TiaLolaDiscQues.pdf',
							'jamestown2007.html',
							'classdescriptions.html',
							'friends.html',
							'valueLineRemote.html',
							'ref.html',
							'genealogy.html',
							'colldev.pdf',
							'heritageqremote.html',
							'latinstruct.html',
							'allhenricoreads.html',
							'kidspage.html',
							'alphaList.html'
							);
							
	aryNewURL = new Array( '/about/faqs.html',
							'/roomRequest.html',
							'/',
							'/Libs/du.html',
							'/Libs/du.html',
							'/Libs/du.html',
							'/Libs/fa.html',
							'/Libs/fa.html',
							'/Libs/fa.html',
							'/Libs/ga.html',
							'/Libs/ga.html',
							'/Libs/ga.html',
							'/Libs/gl.html',
							'/Libs/gl.html',
							'/Libs/gl.html',
							'/Libs/locations.html',
							'/Libs/np.html',
							'/Libs/np.html',
							'/Libs/np.html',
							'/Libs/tu.html',
							'/Libs/tu.html',
							'/Libs/tu.html',
							'/Libs/tw.html',
							'/Libs/tw.html',
							'/Libs/tw.html',
							'/Libs/mu.html',
							'/Libs/mu.html',
							'/Libs/mu.html',
							'/Libs/sa.html',
							'/Libs/sa.html',
							'/Libs/sa.html',
							'/Libs/va.html',
							'/Libs/va.html',
							'/Libs/va.html',
							'/about/contactUs.html',
							'/pdfs/Connections.pdf',
							'/about/contactUs.html',
							'/Ask/eref.asp',
							'/CardReg/cardreg.asp',
							'/circ/account.html',
							'/pdfs/eAudioDirections.pdf',
							'/pdfs/strytime09tu.pdf',
							'/pdfs/strytime09tw.pdf',
							'/teens/jobs.html',
							'/CardReg/renewal.asp',
							'/ebooks/eaudioEbks.html',
							'/CardReg/CardReg.asp',
							'/onlinesrvcs/articlesInfo.html',
							'/',
							'/about/policies.html',
							'/pdfs/TiaLolaDiscQues.pdf',
							'/onlinesrvcs/jamestown.html',
							'/classes/classdesc.html',
							'/friends/friends.html',
							'/onlinesrvcs/valueLineRemote.html',
							'/onlinesrvcs/reftools.html',
							'/onlinesrvcs/genealogy.html',
							'/pdfs/colldev.pdf',
							'/onlinesrvcs/hqRemote.html',
							'/onlinesrvcs/learningExpInst.html',
							'/AHR/0910ahr.html',
							'/kids/index.html',
							'/onlinesrvcs/alphaList_onesearch.html'
							);
	
	if ( aryURL[aryURL.length - 1].toLowerCase() == "denial.htm" ) {
		document.location.href = strRoot + "/denial.html"; // This is the old filter denial page. We just want to automatically redirect to the new one with no message to the user.
	}
							
	document.getElementById("Message1").style.visibility = "visible"
	objForm.theURL.value = location.href;	//Store the broken link URL in the hidden field "theURL" of the form
	
	for( i = 0; i < aryOldURL.length; i++ ){
		if( aryOldURL[i].toLowerCase() == aryURL[aryURL.length - 1].toLowerCase() ){
			document.getElementById("Message1").style.visibility = "hidden";
			document.getElementById("SuggestedURL").innerHTML = "<p><b>The page you attempted to view has changed.</b>  The new page is:<br><br><center><b><a href=" + aryNewURL[i] + ">" + strRoot + aryNewURL[i] + "</a></b></center><br>Please click the link above to navigate to the new page.  Be sure to update any bookmarks you may have that reference this page!</p>";
		} 
	}
	
	//strReferrer is the URL from which the broken link was clicked.  If it has a length greater than zero
	//then store it the hidden field "theReferrer" on the form. 
	if( strReferrer.length > 0 ){
		objForm.theReferrer.value = strReferrer;
	} else {
		objForm.theReferrer.value = 'Direct Entry by User';
	}
}

function submitForm() {
	var objForm = document.forms.theForm;

	objForm.FS.value = "MailForm";
	objForm.submit();
}

function exitForm() {
	document.location.href = 'http://www.henricolibrary.org/';
}
