// JavaScript Document
function loadXMLDoc(url)
{
	xmlhttp=null
		// code for Mozilla, etc.
		if (window.XMLHttpRequest)
		{
			xmlhttp=new XMLHttpRequest()
		}
	// code for IE
		else if (window.ActiveXObject)
		{
			xmlhttp=new ActiveXObject("Microsoft.XMLHTTP")
		}
	if (xmlhttp!=null)
	{
		xmlhttp.onreadystatechange=state_Change
			xmlhttp.open("GET",url,true)
			xmlhttp.send(null)
	}
	else
	{
		alert("Your browser does not support XMLHTTP.")
	}
}

function state_Change()
{
	// if xmlhttp shows "loaded"
	if (xmlhttp.readyState==4)
	{
		// if "OK"
		if (xmlhttp.status==200)
		{
			// alert("XML data OK")
			// document.getElementById('A1').innerHTML=xmlhttp.status
			// document.getElementById('A2').innerHTML=xmlhttp.statusText
			document.getElementById('layer2').innerHTML=xmlhttp.responseText
		}
		else
		{
			alert("Problem retrieving XML data:" + xmlhttp.statusText)
		}
	}
}
function loadHeaders()
{
	loadMenuBar();
	loadImage();
	loadSearchBar();
}
// load the menu bar on all pages
function loadMenuBar()
{
	var menuTag = document.getElementById("menuDivTag"); 
	menuTag.innerHTML = "<a href=\"/index.html\" class=\"menuLinkColors\">Home</a>" + 
		"| <a href=\"/ULIBAboutUs.htm\" class=\"menuLinkColors\" onMouseover=\"dropdownmenu(this, event, menu2, '100px')\" onMouseout=\"delayhidemenu()\">About Us</a> " +
		"| <a href=\"/ULIBProgressReport.htm\" class=\"menuLinkColors\">Progress Report</a> " +
		"| <a href=\"/ULIBMyBooksDL.htm\" class=\"menuLinkColors\">Personal DL</a> " +
		"| <a href=\"/ULIBDonations.htm\" class=\"menuLinkColors\">Donations</a> "  +
		"| <a href=\"/ULIBNewInitiatives.htm\" class=\"menuLinkColors\" onMouseover=\"dropdownmenu(this, event, menu3, '120px')\" onMouseout=\"delayhidemenu()\">New Initiatives</a>" +
		"| <a href=\"/ULIBFeedback.htm\" class=\"menuLinkColors\">Feedback</a>" +
		"| <a href=\"/ULIBHelp.htm\" class=\"menuLinkColors\" onMouseover=\"dropdownmenu(this, event, menu4, '120px')\" onMouseout=\"delayhidemenu()\">Help</a>" + 
		"| <a href=\"/ULIBCopyrights.htm\" class=\"menuLinkColors\">Copyright Policy</a>";
}

function loadImage()
{
	var imageTag = document.getElementById("imageDivTag");
	imageTag.innerHTML = "<a href=\"/\"><img src=\"/ULIBImages/ULIBsmall.gif\" alt=\"Go to UDL Home Page\" width=\"105\" height=\"60\" border=\"0\" title=\"Go to UDL Home Page\"></a>";
}

function loadSearchBar()
{
	var searchBarTag = document.getElementById("formId");
	searchBarTag.innerHTML = "<form name=page method=get action=/cgi-bin/udlcgi/ULIBSimpleSearch.cgi><input name=\"title1\" type=\"text\" size=\"45\"><input type=submit name=search value=\"Title Search\">&nbsp;&nbsp; <a href=\"/ULIBAdvSearch.htm\" target=\"_self\">Advanced Search</a>&nbsp;&nbsp; <a href=\"/ULIBOurCollections.htm\" target=\"_self\">Browse the Collections</a></form>";
}

// hover on Advanced search link to load the advanced search image 
function loadAdvSearchImage(x,y)
{
	document.getElementById('advSearchHover').style.top = y;
	document.getElementById('advSearchHover').style.left = x ;
	document.getElementById('advSearchHover').innerHTML = "<image src=\"ULIBImages/advsearch.png\"></img>";
}
function unLoadAdvSearchImage()
{
	document.getElementById('advSearchHover').innerHTML = "";
}
function openPage(pageName)
{
	window.location.href = pageName;
}

// button  mouse out code
function goLite(FRM,BTN)
{
	window.document.forms[FRM].elements[BTN].style.color = "#7F3D17";
	window.document.forms[FRM].elements[BTN].style.backgroundColor = "#B0E4AC";
}

// button  mouse over code
function goDim(FRM,BTN)
{
	window.document.forms[FRM].elements[BTN].style.color = "#FFFFFF";
	window.document.forms[FRM].elements[BTN].style.backgroundColor = "#177F75";
}

function loadBrowseCollecImage(x,y)
{
	document.getElementById('browseCollections').style.top = y;
	document.getElementById('browseCollections').style.left = x ;
	document.getElementById('browseCollections').innerHTML = "<image src=\"ULIBImages/browseCollections.PNG\"></img>";
}

function unLoadBrowseCollecImage()
{
	document.getElementById('browseCollections').innerHTML = "";
}

function loadHtml()
{
	var obj = document.getElementById('targetDiv');
	var list_obj = document.getElementById('ListID');
	var value = list_obj.value;
if (value == "TOE")
               {
                 var url = "ULIBHelp.htm";
        	 var htmldata = "<iframe width=100% height=100% src="+url+"></iframe>";
        	 //var htmldata = "<p>Have you checked this FAQ reagrding the problem; <a href="+url+">"+url+"></a></p>";
        	 obj.innerHTML = htmldata;
               }
               else if (value == "BNA")
               {
                 var url = "ULIBHelp.htm#q2";
                 var htmldata = "<iframe width=100% height=100% src="+url+"></iframe>";
        	 //var htmldata = "<p>Have you checked this FAQ reagrding the problem; <a href="+url+">"+url+"></a></p>";
                 obj.innerHTML = htmldata;

               }
               else if (value == "RFANB")
               {
                 var url = "ULIBHelp.htm#q5";
                 var htmldata = "<iframe width=100% height=100% src="+url+"></iframe>";
        	 //var htmldata = "<p>Have you checked this FAQ reagrding the problem; <a href="+url+">"+url+"></a></p>";
                 obj.innerHTML = htmldata;

               }
               else if (value == "NATRB")
               {
                 var url = "ULIBHelp.htm#q1";
                 var htmldata = "<iframe width=100% height=100% src="+url+"></iframe>";
        	 //var htmldata = "<p>Have you checked this FAQ reagrding the problem; <a href="+url+">"+url+"></a></p>";
                 obj.innerHTML = htmldata;

               }
               else if (value == "SP")
               {
                 var url = "ULIBHelp.htm#searchTipsBkMark";
                 var htmldata = "<iframe width=100% height=100% src="+url+"></iframe>";
        	 //var htmldata = "<p>Have you checked this FAQ reagrding the problem; <a href="+url+">"+url+"></a></p>";
                 obj.innerHTML = htmldata;

               }
               else if (value == "RP")
               {
                 var url = "ULIBHelp.htm#q1";
                 var htmldata = "<iframe width=100% height=100% src="+url+"></iframe>";
        	 //var htmldata = "<p>Have you checked this FAQ reagrding the problem; <a href="+url+">"+url+"></a></p>";
                 obj.innerHTML = htmldata;

               }
               else if (value == "C")
               { 
                 var url = "ULIBHelp.htm#q6";
                 var htmldata = "<iframe width=100% height=100% src="+url+"></iframe>";
        	 //var htmldata = "<p>Have you checked this FAQ reagrding the problem; <a href="+url+">"+url+"></a></p>";
                 obj.innerHTML = htmldata;

               }
	}

//Functions to check for name and email field mandatory status
function check()
	{
		var name = document.form1.namefield.value;
		var email = document.form1.mailfield.value;
		var retstring = true;
		if((name.length == 0) | (name == null) |(name == 'Name') | (name == ' '))
		{
			alert("Specify a Name");
			document.form1.namefield.style.backgroundColor='#fadfad';
			retstring = false;
		}
		else
		{
			document.form1.namefield.style.backgroundColor='white';
		}
		if((email.length == 0) | (email == null) |(checkemail(email) == false))
		{
			alert("Specify a Valid Email");
			document.form1.mailfield.style.backgroundColor='#fadfad';
			retstring = false;
		}
		else
		{
			document.form1.namefield.style.backgroundColor='white';
		}		
		return retstring;	
 	}
	function checkemail(email)
	{
		var str=email;
		var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
		if (filter.test(str))
		var testresults=true
		else{
				testresults=false
			}
		return (testresults)
	}

