 
function open_win(url) {
	new_win = window.open(url,"new_win",'toolbar=1,location=1,directories=0,status=1,menubar=1,scrollbars=1,resizable=1,width=750,height=250');
	new_win.focus();
}
 
function open_bare_win(url) {
	new_b_win = window.open(url,"new_b_win",'toolbar=0,location=0,directories=0,status=1,menubar=0,scrollbars=1,resizable=1,width=620,height=450');
	new_b_win.focus();
}
 
function open_hyperion_image_win(url) {
	hyperion_image_win = window.open(url,"hyperion_image_win",'toolbar=0,location=0,directories=0,status=1,menubar=0,scrollbars=1,resizable=1,width=600,height=450,screenX=410,screenY=210');
}
 
function open_hyperion_info_win(url) {
	hyperion_info_win = window.open(url,"hyperion_info_win",'toolbar=0,location=0,directories=0,status=1,menubar=0,scrollbars=1,resizable=1,width=400,height=450,screenX=0,screenY=210');
}
 
function open_win_timeout(url,timeout) {
	new_win = window.open(url,"new_win",'toolbar=0,location=0,directories=0,status=1,menubar=1,scrollbars=1,resizable=1,width=750,height=250');
	setTimeout("new_win.close()",timeout);
}
 
function open_help_win(url) {
       new_win = window.open(url,"help_win",'toolbar=1,location=1,directories=0,status=1,menubar=1,scrollbars=1,resizable=1,width=750,height=250');
       new_win.focus();
}
 
function open_bounce_win(url) {
  new_win = window.open(url,"bounce_win",'toolbar=0,location=0,directories=0,status=1,menubar=0,scrollbars=1,resizable=1,width=620,height=450');
}
 
/* Function for icon-type search form action */
function orig_form_action()
{
	if (!document.searchform.search_type[0].checked)
	  {
	  return true;
	  }
	else
	  {
          document.url_form.url.value = "http://www.google.com/search?q=" + document.searchform.searchdata1.value + "&safe=vss&vss=1&sa=Google+Search";
          open_win(document.url_form.url.value);
	  return false;
	  }
}
 
/* Function for icon-type search form action */
function search_form_action()
{
	var search_engine_checked = 0;
	var temp_str;
 
	for (var i = 0; i < document.searchform.search_type.length; i++)
	  {
	  if (document.searchform.search_type[i].value == "searchengine")
	    if (document.searchform.search_type[i].checked)
	      search_engine_checked = 1;
	  }
 
	if (!search_engine_checked)
	  {
	  return true;
	  }
	else
	  {
          temp_str = document.searchform.searchdata1.value;
	  temp_str = temp_str.replace(/\s+/g,"+");
          document.url_form.url.value = "http://www.google.com/search?q=" + temp_str + "&safe=vss&vss=1&sa=Google+Search";
          open_win(document.url_form.url.value);
	  return false;
	  }
}
 
function clearSearchField(fieldname)
{
	var searchfield=document.getElementById(fieldname);
	if (searchfield.value!="Search the Catalog for...") return true;
	searchfield.value="";
	searchfield.className="searchcontent";
}

function setSearch(searchtype)
{
	document.forms.searchform.srchfield1.value=searchtype.replace(/S_ICON\^/,"");
	return true;
}
 
function getNonJavaHelpFileUrl(file)
{
	return "/iBistro_helps/English/" + file;
}
 
function put_help_button(file)
{
  document.writeln('<a href="javascript:open_help_win(getNonJavaHelpFileUrl(\'' + file + '\'))" title="HELP"><img src="/WebCat_Images/English/Buttons/Bistro/HELP.gif" border="0" alt="HELP"  title="HELP"><\/a>');
}
 
 
function put_keepremove_button(ckey,value)
{
  document.writeln('<img name="ckey-' + ckey + '"');
  document.writeln('src="/WebCat_Images/English/Other/Miscib/clear.gif"');
  document.writeln('alt="' + value + '" border="0">');
 
  document.writeln('<input type="button"');
  if (value == 'Keep')
    {
    document.writeln('class="itemdetails"');
    }
  else
    {
    document.writeln('class="itemdetails2"');
    }
  document.writeln('name="ckey-' + ckey + '"');
  document.writeln('value="' + value + '" alt="' + value + '"');
  document.writeln('onClick="javascript:updatekeptlist(this,' + ckey + ');">');
}
 
function updatekeptlist(myButton,ckey)
{
  key = myButton.name;
  if (myButton.value == 'Keep')
    {
    myImage = new Image();
    myImage.src = '/uhtbin/cgisirsi/jhXqrDsAJg/MAIN/310510006/125/ADD?kept-' + ckey + '=on';
    document.images[key].src=myImage.src;
    myImage = new Image();
    myImage.src = '/WebCat_Images/English/Other/Miscib/clear.gif';
    document.images[key].src=myImage.src;
    document.images[key].alt='Remove';
    myButton.value='Remove';
		myButton.className='itemdetails2';
    }
  else
    {
    myImage = new Image();
    myImage.src = '/uhtbin/cgisirsi/jhXqrDsAJg/MAIN/310510006/125/REMOVE?kept-' + ckey + '=on';
    document.images[key].src=myImage.src;
    myImage = new Image();
    myImage.src = '/WebCat_Images/English/Other/Miscib/clear.gif';
    document.images[key].src=myImage.src;
    document.images[key].alt='Keep';
    myButton.value='Keep';
		myButton.className='itemdetails';
  }
}
 
function do_history(form)
  {
  // Based on the value of the srch_history <select> list, set the search input fields.
  var opt_idx;
  var i = 0;
  opt_idx = form.srch_history.selectedIndex;
  // The history "value" is formatted:  "term^label^library"
  valueArray = form.srch_history.options[opt_idx].value.split("^");
  // Set the search term
  form.searchdata1.value = valueArray[0];
  // Set the search type - if it is present
  if (form.srchfield1 != null)
    {
    for (i<0; i<form.srchfield1.length; i++)
      {
      if (form.srchfield1.options[i].text == valueArray[1])
        {
        form.srchfield1.options[i].selected = true;
        break;
        }
      }
    }
  // Set the library
  form.library.value = valueArray[2];
  }
 
 
 
function sendOpenURL(inISBN,inTITLE,inISSN,inGENRE)
{
	aWindow = window.open('','','toolbar=1,location=1,directories=0,status=1,menubar=1,scrollbars=1,resizable=1,width=750,height=250');
	
	if (aWindow.document.body == null)
	  {
	  aBody = aWindow.document.createElement('body');
	  aWindow.document.appendChild(aBody);
	  }
 
        nFORM=aWindow.document.createElement('form');
	nFORM.action='';
	nFORM.target="_self";
	nFORM.method="post";
	nFORM.name="OpenURL";
 
	if (inISBN.length != 0)
	  {
	  nISBN=aWindow.document.createElement('input');
	  nISBN.name='isbn';
	  nISBN.value=inISBN;
	  nISBN.type='hidden';
 
	  nFORM.appendChild(nISBN);
	  }
 
	if (inTITLE.length != 0)
	  {
	  nTITLE=aWindow.document.createElement('input');
	  nTITLE.name='title';
	  nTITLE.value=inTITLE;
	  nTITLE.type='hidden';
 
	  nFORM.appendChild(nTITLE);
	  } 
 
	if (inISSN.length != 0)
	  {
	  nISSN=aWindow.document.createElement('input');
	  nISSN.name='issn';
	  nISSN.value=inISSN;
	  nISSN.type='hidden';
 
	  nFORM.appendChild(nISSN);
	  }
 
	if (inGENRE.length != 0)
	  {
	  nGENRE=aWindow.document.createElement('input');
	  nGENRE.name='genre';
	  nGENRE.value=inGENRE;
	  nGENRE.type='hidden';
 
	  nFORM.appendChild(nGENRE);
	  }
 
	aWindow.document.body.appendChild(nFORM);
 
	nFORM.submit();
 
	aWindow.document.body.removeChild(nFORM);
 
}
 
function sendPayPal(inUser,inLibrary,inBill,inTotal,inAmount)
{
 
	currencyStr = '$';
 
	if (currencyStr == "$")
	  {
	  currencyStr = "\\" + currencyStr;  
	  }
 
	re = new RegExp(currencyStr,"g");
 
	inTotal = inTotal.replace(re,"");
 
	inAmount = inAmount.replace(re,"");
 
	// convert the strings to numbers and 
        // test for minimum before opening window
	
	if (inAmount.indexOf(",") == -1)
	  {
	  floatAmount = parseFloat(inAmount);
	  }
	else
	  {
	    floatAmount = 0.0;
	    workstr = inAmount;
	    while (workstr.indexOf(",") != -1)
	      {
		partialstr = workstr.substr(0,workstr.indexOf(","));
		floatAmount = floatAmount + parseFloat(partialstr);
		workstr = workstr.substr(workstr.indexOf(",") + 1);
	      }
	    floatAmount = floatAmount + parseFloat(workstr);
	  }
 
	floatAmount = Math.round(floatAmount*100)/100;
 
	floatMinimum = parseFloat(0);
 
	if (floatAmount < floatMinimum)
	  {
	    alert ("The amount owed is less than the minimum for using PayPal");
	    return;
	  }	  
	
	aWindow = window.open('','','toolbar=1,location=1,directories=0,status=1,menubar=1,scrollbars=1,resizable=1,width=750,height=250');
	
	if (aWindow.document.body == null)
	  {
	  aBody = aWindow.document.createElement('body');
	  aWindow.document.appendChild(aBody);
	  }
 
 
        nFORM=aWindow.document.createElement('form');
	nFORM.action='';
	nFORM.target="_self";
	nFORM.method="post";
	nFORM.name="PayPal";
 
	nCustom=aWindow.document.createElement('input');
	nCustom.name='custom';
	nCustom.value='user=' + inUser + '&';
	nCustom.value=nCustom.value + 'library=' + inLibrary + '&';
	nCustom.value=nCustom.value + 'bill_number=' + inBill + '&';
	nCustom.value=nCustom.value + 'total_owed=' + inTotal + '&';
	nCustom.value=nCustom.value + 'amount_paid=' + inAmount;
	nCustom.type='hidden';
 
	nFORM.appendChild(nCustom);
 
	nAmount=aWindow.document.createElement('input');
	nAmount.name='amount';
	nAmount.value=floatAmount;
	nAmount.type='hidden';
 
	nFORM.appendChild(nAmount);
	
	nCmd=aWindow.document.createElement('input');
	nCmd.name='cmd';
	nCmd.value='_xclick';
	nCmd.type='hidden';
 
	nFORM.appendChild(nCmd);
	
	nBusiness=aWindow.document.createElement('input');
	nBusiness.name='business';
	nBusiness.value='';
	nBusiness.type='hidden';
 
	nFORM.appendChild(nBusiness);
	
	nItemName=aWindow.document.createElement('input');
	nItemName.name='item_name';
	nItemName.value='bill payment';
	nItemName.type='hidden';
 
	nFORM.appendChild(nItemName);
	
	nNotifyURL=aWindow.document.createElement('input');
	nNotifyURL.name='notify_url';
	nNotifyURL.value='';
	nNotifyURL.type='hidden';
 
	nFORM.appendChild(nNotifyURL);
	
	nCurrencyCode=aWindow.document.createElement('input');
	nCurrencyCode.name='currency_code';
	nCurrencyCode.value='USD';
	nCurrencyCode.type='hidden';
 
	nFORM.appendChild(nCurrencyCode);
 
	aWindow.document.body.appendChild(nFORM);
 
	nFORM.submit();
 
	aWindow.document.body.removeChild(nFORM);
}
 
function clearCreditCardFields()
{
	ouracct_number=document.getElementById("acct_number");
	ouracct_name=document.getElementById("acct_name");
	ourexp_date=document.getElementById("exp_date");
	ouracct_number.value="";
	ouracct_name.value="";
	ourexp_date.value="";
}
 
function submitVeriSign(inUser,inData)
{
	nFORM=document.createElement('form');
	document.body.appendChild(nFORM);
	nFORM.action='/uhtbin/cgisirsi/jhXqrDsAJg/MAIN/310510006/144';
	nFORM.target="_self";
	nFORM.method="post";
	nFORM.name="Payment";
	
	nUser=document.createElement('input');
	nUser.name='user_id';
	nUser.value=inUser;
	nUser.type='hidden';
 
	nFORM.appendChild(nUser);
 
	nData=document.createElement('input');
	nData.name='data';
	nData.value=inData;
	nData.type='hidden';
 
	nFORM.appendChild(nData);
 
	nFORM.submit();
}
 
function OpenGateway(inURL,inGateway)
{
	var need_to_replace = 0;
 
	
	  need_to_replace = 1;
	
	if (need_to_replace)
	  {
	  inURL = inURL.replace(":///","://"+location.host+"/");
	  }
 
	aWindow = window.open('','','toolbar=0,location=0,directories=0,status=1,menubar=0,scrollbars=1,resizable=1,width=600,height=600');
 
	inUserId = 'WEBSERVER';
	inPassword = '';
 
	if (aWindow.document.body == null)
	  {
	  aBody = aWindow.document.createElement('body');
	  aWindow.document.appendChild(aBody);
	  }
 
        nFORM=aWindow.document.createElement('form');
	nFORM.action=inURL;
	nFORM.target="_self";
	nFORM.method="post";
	nFORM.name="Gateway";
 
	if (inGateway.length != 0)
	  {
	  nGateway=aWindow.document.createElement('input');
	  nGateway.name='new_gateway_db';
	  nGateway.value=inGateway;
	  nGateway.type='hidden';
 
	  nFORM.appendChild(nGateway);
	  }
 
	if (inUserId.length != 0)
	  {
	  nUser=aWindow.document.createElement('input');
	  nUser.name='user_id';
	  nUser.value=inUserId;
	  nUser.type='hidden';
 
	  nFORM.appendChild(nUser);
	  } 
 
	if (inPassword.length != 0)
	  {
	  nPIN=aWindow.document.createElement('input');
	  nPIN.name='password';
	  nPIN.value=inPassword;
	  nPIN.type='hidden';
 
	  nFORM.appendChild(nPIN);
	  }
 
	aWindow.document.body.appendChild(nFORM);
 
	nFORM.submit();
 
	aWindow.document.body.removeChild(nFORM);
 
}
 
function OnlineUserRegistrationCheck(formobj){
	// Enter name of mandatory fields
	var fieldRequired = Array("firstname", "lastname", "street", "city", "state", "zip", "pin", "validatepin");
	// Enter field description to appear in the dialog box
	var fieldDescription = Array("First Name", "Last Name", "Street", "City", "State", "Zip", "PIN", "Re-Type PIN");
	// dialog message
	var alertMsg = "Please complete the following required fields" + ":\n";
 
	var l_Msg = alertMsg.length;
 
	for (var i = 0; i < fieldRequired.length; i++){
		var obj = formobj.elements[fieldRequired[i]];
		if (obj){
			switch(obj.type){
			case "select-one":
				if (obj.selectedIndex == -1 || obj.options[obj.selectedIndex].text == ""){
					alertMsg += " - " + fieldDescription[i] + "\n";
				}
				break;
			case "select-multiple":
				if (obj.selectedIndex == -1){
					alertMsg += " - " + fieldDescription[i] + "\n";
				}
				break;
			case "text":
			case "textarea":
				if (obj.value == "" || obj.value == null){
					alertMsg += " - " + fieldDescription[i] + "\n";
				}
				break;
			default:
			}
			if (obj.type == undefined){
				var blnchecked = false;
				for (var j = 0; j < obj.length; j++){
					if (obj[j].checked){
						blnchecked = true;
					}
				}
				if (!blnchecked){
					alertMsg += " - " + fieldDescription[i] + "\n";
				}
			}
		}
	}
 
	if (alertMsg.length == l_Msg){
		if(formobj.pin.value != formobj.validatepin.value) {
            alert ("The PIN numbers you entered do not match.  Please re-enter your PIN information.");
			return false;
		}
		return true;
	}else{
		alert(alertMsg);
		return false;
	}
}
 
 
function OnlineUserActivationCheck(formobj){
	// Enter name of mandatory fields
	var fieldRequired = Array("user_id", "pin", "new_user_id");
	// Enter field description to appear in the dialog box
	var fieldDescription = Array("Temporary ID", "PIN", "New User ID");
	// dialog message
	var alertMsg = "Please complete the following required fields:\n";
 
	var l_Msg = alertMsg.length;
 
	for (var i = 0; i < fieldRequired.length; i++){
		var obj = formobj.elements[fieldRequired[i]];
		if (obj){
			switch(obj.type){
			case "select-one":
				if (obj.selectedIndex == -1 || obj.options[obj.selectedIndex].text == ""){
					alertMsg += " - " + fieldDescription[i] + "\n";
				}
				break;
			case "select-multiple":
				if (obj.selectedIndex == -1){
					alertMsg += " - " + fieldDescription[i] + "\n";
				}
				break;
			case "text":
			case "textarea":
				if (obj.value == "" || obj.value == null){
					alertMsg += " - " + fieldDescription[i] + "\n";
				}
				break;
			default:
			}
			if (obj.type == undefined){
				var blnchecked = false;
				for (var j = 0; j < obj.length; j++){
					if (obj[j].checked){
						blnchecked = true;
					}
				}
				if (!blnchecked){
					alertMsg += " - " + fieldDescription[i] + "\n";
				}
			}
		}
	}
 
	if (alertMsg.length == l_Msg){
		return true;
	}else{
		alert(alertMsg);
		return false;
	}
}
 
//<!-- Javascript name: My Date Time Picker
// * Date created: 16-Nov-2003 23:19
// * Scripter: TengYong Ng
// * Copyright (c) 2003 TengYong Ng
// * FileName: DateTimePicker.js
// * Version: 0.8
// * Note: Permission given to use this script in ANY kind of applications if
// *        header lines are left unchanged.
// *
// * Modified by: SirsiDynix, 2004 - 2006
// --> 
 

var winCal;
var dtToday=new Date();
var Cal;
var docCal;
var MonthName=["January", "February", "March", "April",
        "May", "June", "July", "August", "September",
        "October", "November", "December"];
var WeekDayName=["Sunday","Monday","Tuesday","Wednesday",
        "Thursday","Friday","Saturday"];
var exDateTime;        /* Existing Date and Time */
 
/* Configurable parameters */
var cnTop="200";       /* Top coordinate of calendar window. */
var cnLeft="500";      /* Left coordinate of calendar window */
var WindowTitle ="Calendar";
var WeekChar=2;        /* Number of character for week day. If 2 
                        * then Mo,Tu,We. if 3 then Mon,Tue,Wed */
var CellWidth=20;      /* Width of day cell. */
var DateSeparator="/";
var TimeMode=24;       /* Default TimeMode value. 12 or 24 */
var ShowLongMonth=true;/* Show long month name in Calendar header. */
var ShowMonthYear=true;/* Show Month and Year in Calendar header. */
var MonthYearColor="#006699";  
var WeekHeadColor="#006699";   
var WeekendColor="#EFEFEF";   
var WeekDayColor="#FFFFFF"; 
var FontColor="#000000";         
var SelDateColor="#CCCCFF";  
var ThemeBg="";        /* Background image of Calendar window. */
/* End Configurable parameters */
 
function NewCal(pCtrl,pFormat,pShowTime,pTimeMode)
{
	Cal=new Calendar(dtToday);
	if ((pShowTime!=null) && (pShowTime))
	{
		Cal.ShowTime=true;
		if ((pTimeMode!=null) &&((pTimeMode=='12')||(pTimeMode=='24')))
		{
			TimeMode=pTimeMode;
		}		
	}	
	if (pCtrl!=null)
		Cal.Ctrl=pCtrl;
	if (pFormat!=null)
		Cal.Format=pFormat.toUpperCase();
	
	exDateTime=document.getElementById(pCtrl).value;
	if (exDateTime!="")    /* Parse Date String */
	{
		var Sp1;       /* Index of Date Separator 1 */
		var Sp2;       /* Index of Date Separator 2 */ 
		var tSp1;      /* Index of Time Separator 1 */
		var tSp2;      /* Index of Time Separator 2 */
		var strMonth;
		var strDate;
		var strYear;
		var intMonth;
		var YearPattern;
		var strHour;
		var strMinute;
		/* Parse month */
		Sp1=exDateTime.indexOf(DateSeparator,0)
		Sp2=exDateTime.indexOf(DateSeparator,(parseInt(Sp1)+1));
		if ((Cal.Format.toUpperCase()=="DDMMYYYY") || (Cal.Format.toUpperCase()=="DDMMMYYYY"))
		{
			strMonth=exDateTime.substring(Sp1+1,Sp2);
			strDate=exDateTime.substring(0,Sp1);
		}
		else if ((Cal.Format.toUpperCase()=="MMDDYYYY") || (Cal.Format.toUpperCase()=="MMMDDYYYY"))
		{
			strMonth=exDateTime.substring(0,Sp1);
			strDate=exDateTime.substring(Sp1+1,Sp2);
		}
		else if ((Cal.Format.toUpperCase()=="YYYYMMDD") || (Cal.Format.toUpperCase()=="YYYYMMMDD"))
		{
			strMonth=exDateTime.substring(Sp1+1,Sp2);
			strDate=exDateTime.substring(Sp2+1);
		}
		if (isNaN(strMonth))
			intMonth=Cal.GetMonthIndex(strMonth);
		else
			intMonth=parseInt(strMonth,10)-1;
		if ((parseInt(intMonth,10)>=0) && (parseInt(intMonth,10)<12))
			Cal.Month=intMonth;
 
		/* Parse Date */
		if ((parseInt(strDate,10)<=Cal.GetMonDays()) && (parseInt(strDate,10)>=1))
			Cal.Date=strDate;
 
		/* Parse Year */
		if ((Cal.Format.toUpperCase()=="YYYYMMDD") || (Cal.Format.toUpperCase()=="YYYYMMMDD"))
			strYear=exDateTime.substring(0,4);
		else
			strYear=exDateTime.substring(Sp2+1,Sp2+5);
		YearPattern=/^\d{4}$/;
		if (YearPattern.test(strYear))
			Cal.Year=parseInt(strYear,10);
 
		/* Parse Time */
		if (Cal.ShowTime==true)
		{
			tSp1=exDateTime.indexOf(":",0)
			tSp2=exDateTime.indexOf(":",(parseInt(tSp1)+1));
			strHour=exDateTime.substring(tSp1,(tSp1)-2);
			Cal.SetHour(strHour);
			strMinute=exDateTime.substring(tSp1+1,tSp2);
			Cal.SetMinute(strMinute);
		}	
	}
	winCal=window.open("","DateTimePicker","toolbar=0,status=0,menubar=0,fullscreen=no,width=200,height=275 ,resizable=0,top="+cnTop+",left="+cnLeft);
	docCal=winCal.document;
	RenderCal();
}
 
function RenderCal()
{
	var vCalHeader;
	var vCalData;
	var vCalTime;
	var i;
	var j;
	var SelectStr;
	var vDayCount=0;
	var vFirstDay;
 
	docCal.open();
	docCal.writeln("<html><head><title>"+WindowTitle+"</title>");
	docCal.writeln("<script>winMain=window.opener;</script\>");
	docCal.writeln("</head><body background='"+ThemeBg+"' link="+FontColor+" vlink="+FontColor+"><form name='Calendar'>");
 
	vCalHeader="<table border=1 cellpadding=1 cellspacing=1 width='100%' align=\"center\" valign=\"top\">\n";
 
	/* Month Selector */
	vCalHeader+="<tr>\n<td colspan='7'><table border=0 width='100%' cellpadding=0 cellspacing=0><tr><td align='left'>\n";
	vCalHeader+="<select name=\"MonthSelector\" onChange=\"javascript:winMain.Cal.SwitchMth(this.selectedIndex);winMain.RenderCal();\">\n";
	for (i=0;i<12;i++)
	{
		if (i==Cal.Month)
			SelectStr="Selected";
		else
			SelectStr="";
		vCalHeader+="<option "+SelectStr+" value >"+MonthName[i]+"\n";
	}
	vCalHeader+="</select></td>";
 
	/* Year selector */
	vCalHeader+="\n<td align='right'><a href=\"javascript:winMain.Cal.DecYear();winMain.RenderCal()\"><b><font color=\""+MonthYearColor+"\"><</font></b></a><font face=\"Verdana\" color=\""+MonthYearColor+"\" size=x-small><b> "+Cal.Year+" </b></font><a href=\"javascript:winMain.Cal.IncYear();winMain.RenderCal()\"><b><font color=\""+MonthYearColor+"\">></font></b></a></td></tr></table></td>\n";
	vCalHeader+="</tr>";
 
	/* Calendar header shows Month and Year */
	if (ShowMonthYear)
		vCalHeader+="<tr><td colspan='7'><font face='Verdana' size='x-small' align='center' color='"+MonthYearColor+"'><b>"+Cal.GetMonthName(ShowLongMonth)+" "+Cal.Year+"</b></font></td></tr>\n";
 
	/* Week day header */
	vCalHeader+="<tr bgcolor="+WeekHeadColor+">";
	for (i=0;i<7;i++)
	{
		vCalHeader+="<td align='center'><font face='Verdana' color='white' size='x-small'>"+WeekDayName[i].substr(0,WeekChar)+"</font></td>";
	}
	vCalHeader+="</tr>";
	docCal.write(vCalHeader);
	
	/* Calendar detail */
	CalDate=new Date(Cal.Year,Cal.Month);
	CalDate.setDate(1);
	vFirstDay=CalDate.getDay();
	vCalData="<tr>";
	for (i=0;i<vFirstDay;i++)
	{
		vCalData=vCalData+GenCell();
		vDayCount=vDayCount+1;
	}
	for (j=1;j<=Cal.GetMonDays();j++)
	{
		var strCell;
		vDayCount=vDayCount+1;
		if ((j==dtToday.getDate())&&(Cal.Month==dtToday.getMonth())&&(Cal.Year==dtToday.getFullYear()))
			strCell=GenCell(j,true,SelDateColor);
		else
		{
			if (j==Cal.Date)
			{
				strCell=GenCell(j,true,SelDateColor);
			}
			else
			{
				if ((vDayCount%7==0) | (vDayCount+6)%7==0)
					strCell=GenCell(j,false,WeekendColor);
				else
					strCell=GenCell(j,null,WeekDayColor);
			}		
		}
		vCalData=vCalData+strCell;
 
		if((vDayCount%7==0)&&(j<Cal.GetMonDays()))
		{
			vCalData=vCalData+"</tr>\n<tr>";
		}
	}
	docCal.writeln(vCalData);
 
	/* Time picker */
	if (Cal.ShowTime)
	{
		var showHour;
		showHour=Cal.getShowHour();
		vCalTime="<tr>\n<td colspan='7' align='center'>\n<label for='hour'></label>";
		vCalTime+="<input type='text' name='hour' id='hour' maxlength=2 size=xx-small style=\"WIDTH: 22px\" value="+showHour+" onchange=\"javascript:winMain.Cal.SetHour(this.value)\">";
		vCalTime+=" : <label for='minute'></label>";
		vCalTime+="<input type='text' name='minute' id='minute' maxlength=2 size=xx-small style=\"WIDTH: 22px\" value="+Cal.Minutes+" onchange=\"javascript:winMain.Cal.SetMinute(this.value)\">";
		if (TimeMode==12)
		{
			var SelectAm =(parseInt(Cal.Hours,10)<12)? "Selected":"";
			var SelectPm =(parseInt(Cal.Hours,10)>=12)? "Selected":"";
 
			vCalTime+="<select name=\"ampm\" onchange=\"javascript:winMain.Cal.SetAmPm(this.options[this.selectedIndex].value);\">";
			vCalTime+="<option "+SelectAm+" value=\"AM\">AM</option>";
			vCalTime+="<option "+SelectPm+" value=\"PM\">PM<option>";
			vCalTime+="</select>";
		}	
		vCalTime+="\n</td>\n</tr>";
		docCal.write(vCalTime);
	}
 
	docCal.writeln("\n</table>");
	docCal.writeln("</form></body></html>");
	docCal.close();
}
 
/* Generate table cell with value */
function GenCell(pValue,pHighLight,pColor)
{
	var PValue;
	var PCellStr;
	var vColor;
	var vHLstr1;    /* HighLight string */
	var vHlstr2;
	var vTimeStr;
	
	if (pValue==null)
		PValue="";
	else
		PValue=pValue;
	
	if (pColor!=null)
		vColor="bgcolor=\""+pColor+"\"";
	else
		vColor="";
	if ((pHighLight!=null)&&(pHighLight))
		{vHLstr1="color='red'><b>";vHLstr2="</b>";}
	else
		{vHLstr1=">";vHLstr2="";}
	
	if (Cal.ShowTime)
	{
		vTimeStr="winMain.document.getElementById('"+Cal.Ctrl+"').value+=''+"+"winMain.Cal.getShowHour()"+"+':'+"+"winMain.Cal.Minutes";
		if (TimeMode==12)
			vTimeStr+="+' '+winMain.Cal.AMorPM";
	}	
	else
		vTimeStr="";
	PCellStr="<td "+vColor+" width="+CellWidth+" align='center'><font face='verdana' size='x-small'"+vHLstr1+PValue+vHLstr2+"</font></td>";
	PCellStr="<td "+vColor+" width="+CellWidth+" align='center'><font face='verdana' size='x-small'"+vHLstr1+"<a href=\"javascript:winMain.document.getElementById('"+Cal.Ctrl+"').value='"+Cal.FormatDate(PValue)+"';"+vTimeStr+";window.close();\">"+PValue+"</a>"+vHLstr2+"</font></td>";
	return PCellStr;
}
 
function Calendar(pDate,pCtrl)
{
	/* Properties */
	this.Date=pDate.getDate();     /* Selected date */
	this.Month=pDate.getMonth();   /* Selected month number */
	this.Year=pDate.getFullYear(); /* Selected year in 4 digits */
	this.Hours=pDate.getHours();
	
	if (pDate.getMinutes()<10)
		this.Minutes="0"+pDate.getMinutes();
	else
		this.Minutes=pDate.getMinutes();
	
	this.MyWindow=winCal;
	this.Ctrl=pCtrl;
	this.Format="ddMMyyyy";
	this.Separator=DateSeparator;
	this.ShowTime=false;
	if (pDate.getHours()<12)
		this.AMorPM="AM";
	else
		this.AMorPM="PM";
}
 
function GetMonthIndex(shortMonthName)
{
	for (i=0;i<12;i++)
	{
		if (MonthName[i].substring(0,3).toUpperCase()==shortMonthName.toUpperCase())
		{	return i;}
	}
}
Calendar.prototype.GetMonthIndex=GetMonthIndex;
 
function IncYear()
{	Cal.Year++;}
Calendar.prototype.IncYear=IncYear;
 
function DecYear()
{	Cal.Year--;}
Calendar.prototype.DecYear=DecYear;
	
function SwitchMth(intMth)
{	Cal.Month=intMth;}
Calendar.prototype.SwitchMth=SwitchMth;
 
function SetHour(intHour)
{	
	var MaxHour;
	var MinHour;
	if (TimeMode==24)
	{	MaxHour=23;MinHour=0}
	else if (TimeMode==12)
	{	MaxHour=12;MinHour=1}
	else
		alert("TimeMode can only be 12 or 24");
	var HourExp=new RegExp("^\\d\\d$");
	if (HourExp.test(intHour) && (parseInt(intHour,10)<=MaxHour) && (parseInt(intHour,10)>=MinHour))
	{	
		if ((TimeMode==12) && (Cal.AMorPM=="PM"))
		{
			if (parseInt(intHour,10)==12)
				Cal.Hours=12;
			else	
				Cal.Hours=parseInt(intHour,10)+12;
		}	
		else if ((TimeMode==12) && (Cal.AMorPM=="AM"))
		{
			if (intHour==12)
				intHour-=12;
			Cal.Hours=parseInt(intHour,10);
		}
		else if (TimeMode==24)
			Cal.Hours=parseInt(intHour,10);
	}
}
Calendar.prototype.SetHour=SetHour;
 
function SetMinute(intMin)
{
	var MinExp=new RegExp("^\\d\\d$");
	if (MinExp.test(intMin) && (intMin<60))
		Cal.Minutes=intMin;
}
Calendar.prototype.SetMinute=SetMinute;
 
function SetAmPm(pvalue)
{
	this.AMorPM=pvalue;
	if (pvalue=="PM")
	{
		this.Hours=(parseInt(this.Hours,10))+12;
		if (this.Hours==24)
			this.Hours=12;
	}
	else if (pvalue=="AM")
		this.Hours-=12;
}
Calendar.prototype.SetAmPm=SetAmPm;
 
function getShowHour()
{
	var finalHour;
    if (TimeMode==12)
    {
    	if (parseInt(this.Hours,10)==0)
		{
			this.AMorPM="AM";
			finalHour=parseInt(this.Hours,10)+12;
		}
		else if (parseInt(this.Hours,10)==12)
		{
			this.AMorPM="PM";
			finalHour=12;
		}		
		else if (this.Hours>12)
		{
			this.AMorPM="PM";
			if ((this.Hours-12)<10)
				finalHour="0"+((parseInt(this.Hours,10))-12);
			else
				finalHour=parseInt(this.Hours,10)-12;
		}
		else
		{
			this.AMorPM="AM";
			if (this.Hours<10)
				finalHour="0"+parseInt(this.Hours,10);
			else
				finalHour=this.Hours;	
		}
	}
	else if (TimeMode==24)
	{
		if (this.Hours<10)
			finalHour="0"+parseInt(this.Hours,10);
		else	
			finalHour=this.Hours;
	}	
	return finalHour;
}			
Calendar.prototype.getShowHour=getShowHour;
 
function GetMonthName(IsLong)
{
	var Month=MonthName[this.Month];
	if (IsLong)
		return Month;
	else
		return Month.substr(0,3);
}
Calendar.prototype.GetMonthName=GetMonthName;
 
function GetMonDays()             /* Get number of days in a month */
{
	var DaysInMonth=[31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
	if (this.IsLeapYear())
	{
		DaysInMonth[1]=29;
	}	
	return DaysInMonth[this.Month];	
}
Calendar.prototype.GetMonDays=GetMonDays;
 
function IsLeapYear()
{
	if ((this.Year%4)==0)
	{
		if ((this.Year%100==0) && (this.Year%400)!=0)
		{
			return false;
		}
		else
		{
			return true;
		}
	}
	else
	{
		return false;
	}
}
Calendar.prototype.IsLeapYear=IsLeapYear;
 
function FormatDate(pDate)
{
	if (this.ShowTime)
	{
		if (this.Format.toUpperCase()=="DDMMYYYY")
			return (pDate+DateSeparator+(this.Month+1)+DateSeparator+this.Year+",");
		else if (this.Format.toUpperCase()=="DDMMMYYYY")
			return (pDate+DateSeparator+this.GetMonthName(false)+DateSeparator+this.Year+",");
		else if (this.Format.toUpperCase()=="MMDDYYYY")
			return ((this.Month+1)+DateSeparator+pDate+DateSeparator+this.Year+",");
		else if (this.Format.toUpperCase()=="YYYYMMDD")
			return (this.Year+DateSeparator+(this.Month+1)+DateSeparator+pDate+",");
		else if (this.Format.toUpperCase()=="MMMDDYYYY")
			return (this.GetMonthName(false)+DateSeparator+pDate+DateSeparator+this.Year);
	}
	else
	{
		if (this.Format.toUpperCase()=="DDMMYYYY")
			return (pDate+DateSeparator+(this.Month+1)+DateSeparator+this.Year);
		else if (this.Format.toUpperCase()=="DDMMMYYYY")
			return (pDate+DateSeparator+this.GetMonthName(false)+DateSeparator+this.Year);
		else if (this.Format.toUpperCase()=="MMDDYYYY")
			return ((this.Month+1)+DateSeparator+pDate+DateSeparator+this.Year);
		else if (this.Format.toUpperCase()=="YYYYMMDD")
			return (this.Year+DateSeparator+(this.Month+1)+DateSeparator+pDate);
		else if (this.Format.toUpperCase()=="MMMDDYYYY")
			return (this.GetMonthName(false)+DateSeparator+pDate+DateSeparator+this.Year);
	}
}
Calendar.prototype.FormatDate=FormatDate;	
 
