function updateStatus(user, order, status) {
	document.form1.userID.value = user;
	document.form1.orderID.value = order;
	document.form1.newStatus.value = status;
	document.form1.submit();
}

function stringTrim(strToTrim) {
	return(strToTrim.replace(/^\s+|\s+$/g, ''));
}

function checkAuthorizations() 
{
   one = stringTrim(document.form1.participantsRequestingTravel.value);
	two = stringTrim(document.form1.discountedFaresAuthorized.value);
	three = stringTrim(document.form1.nonRefundableFaresAuthorized.value);
	four = stringTrim(document.form1.saturdayNightStay.value);
	if (one != '' && one != 0 && (two == '' || three == '' || four == ''))
		{
		alert("You must make a selection for discounted fares authorized, non-refundable fares authorized, and saturday night stay allowed.");
		return false;
		}
}
	
function pviiClassNew(obj, new_style) {
    obj.className = new_style;
}

function MM_goToURL() { //v3.0
  var i, args=MM_goToURL.arguments; document.MM_returnValue = false;
  for (i=0; i<(args.length-1); i+=2) eval(args[i]+".location='"+args[i+1]+"'");
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function textCounter2(field2, countfield2, maxlimit2) 
{
	if (field2.value.length > maxlimit2) // if too long...trim it!
		{
		field2.value = field2.value.substring(0, maxlimit2);
		}
	// otherwise, update 'characters left' counter
	else
		{ 
		countfield2.value = maxlimit2 - field2.value.length;
		}
}
   
function startCalc1()
{ 
	interval = setInterval("calc1()",100); 
} 
	
function calc1()
{ 
	one = document.form3.domesticTravelers.value; 
	two = document.form3.nonDomesticTravelers.value;  
	document.form3.totalSponsoredTravelers.value = (one * 1) + (two * 1);
	if (document.form3.totalSponsoredTravelers.value == 'NaN')   
	{
	   document.form3.totalSponsoredTravelers.value = '';
	}
} 
	 
function stopCalc1()
{   
	clearInterval(interval);   
	if (document.form3.totalSponsoredTravelers.value == '')   
	{
	   alert('Please enter only integers in the domestic and non-domestic travelers fields.');
	} 
}

function startCalc2()
{ 
	interval = setInterval("calc2()",100); 
} 
	
function calc2()
{ 
	one = document.form3.localParticipants.value; 
	two = document.form3.nonLocalParticipants.value;  
	three = document.form3.federalParticipants.value;  
	document.form3.totalParticipants.value = (one * 1) + (two * 1) + (three * 1);
	if (document.form3.totalParticipants.value == 'NaN')   
	{
	   document.form3.totalParticipants.value = '';
	}
} 
	 
function stopCalc2()
{   
	clearInterval(interval);   
	if (document.form3.totalParticipants.value == '')   
	{
	   alert('Please enter only integers in the local, non-local, and federal participant fields.');
	} 
}

function startCalc3()
{ 
	interval = setInterval("calc3()",100); 
} 
	
function calc3()
{ 
	one = document.form1.nonSponsoredParticipants.value; 
	two = document.form1.sponsoredParticipants.value;  
	three = document.form1.federalParticipants.value;  
	document.form1.totalParticipants.value = (one * 1) + (two * 1) + (three * 1);
	if (document.form1.totalParticipants.value == 'NaN')   
	{
	   document.form1.totalParticipants.value = '';
	}
	
	if (document.form1.participantsRequestingTravel.value == 0 || document.form1.initParticipantsRequestingTravel.value == '')
	{
		document.form1.participantsRequestingTravel.value = document.form1.sponsoredParticipants.value;
	}
	
	if (document.form1.sleepingRoomsRequired.value == 0 || document.form1.initSleepingRoomsRequired.value == '')
	{
		document.form1.sleepingRoomsRequired.value = document.form1.sponsoredParticipants.value;
	}
} 
	 
function stopCalc3()
{   
	clearInterval(interval);   
	if (document.form1.totalParticipants.value == '')   
	{
	   alert('Please enter only integers in the sponsored, non-Sponsored, and federal participant fields.');
	} 
}

function show_calendar(str_target, str_datetime)
{

 var arr_months = ["January", "February", "March", "April", "May", "June",
		             "July", "August", "September", "October", "November", "December"];
 var week_days = ["Su", "Mo", "Tu", "We", "Th", "Fr", "Sa"];
 var n_weekstart = 1; // day week starts from (normally 0 or 1)

 if (str_datetime == null || str_datetime =="")
 {
   dt_datetime = new Date();
 }
 else
 {
    //mikes lame hack to convert from american to english dates
    firstnum = str_datetime.substring(0,str_datetime.indexOf('-',0));
    secondnum = str_datetime.substring(str_datetime.indexOf('-',0) + 1, str_datetime.indexOf('-',str_datetime.indexOf('-',0)+1));
    thirdnum = str_datetime.substring(str_datetime.lastIndexOf('-',str_datetime.length)+1,str_datetime.length);
    newnum = secondnum + '-' + firstnum + '-' + thirdnum + ' 00:00:00';
    dt_datetime = str2dt(newnum);
 }
 
 var dt_prev_month = new Date(dt_datetime);
	  dt_prev_month.setMonth(dt_datetime.getMonth()-1);
 var dt_next_month = new Date(dt_datetime);
	  dt_next_month.setMonth(dt_datetime.getMonth()+1);
 var dt_firstday = new Date(dt_datetime);
	  dt_firstday.setDate(1);
	  dt_firstday.setDate(1-(7+dt_firstday.getDay()-n_weekstart)%7);
 var dt_lastday = new Date(dt_next_month);
	  dt_lastday.setDate(0);
	
 // html generation (feel free to tune it for your particular application)
 // print calendar header
 var str_buffer = new String 
 (
	 "<html>\n"+
	 "<head>\n"+
	 "	<title>Calendar</title>\n"+
	 "</head>\n"+
	 "<body bgcolor=\"White\">\n"+
	 "<table class=\"clsOTable\" cellspacing=\"0\" border=\"0\" width=\"100%\">\n"+
	 "<tr><td bgcolor=\"#9999CC\">\n"+
	 "<table cellspacing=\"1\" cellpadding=\"3\" border=\"0\" width=\"100%\">\n"+
	 "<tr>\n	<td bgcolor=\"#9999CC\"><a href=\"javascript:window.opener.show_calendar('"+
	 str_target+"', '"+ dt2dtstr(dt_prev_month)+"'+document.cal.time.value);\">"+
	 "<img src=\"images/prev.gif\" width=\"16\" height=\"12\" border=\"0\""+
	 " alt=\"previous month\"></a></td>\n"+
	 " <td align=\"center\" bgcolor=\"#9999CC\" colspan=\"5\">"+
	 "<font color=\"white\" face=\"tahoma, verdana\" size=\"2\">"
	 +arr_months[dt_datetime.getMonth()]+" "+dt_datetime.getFullYear()+"</font></td>\n"+
	 "	<td bgcolor=\"#9999CC\" align=\"right\"><a href=\"javascript:window.opener.show_calendar('"
	 +str_target+"', '"+dt2dtstr(dt_next_month)+"'+document.cal.time.value);\">"+
	 "<img src=\"images/next.gif\" width=\"16\" height=\"12\" border=\"0\""+
	 " alt=\"next month\"></a></td>\n</tr>\n"
 );

 var dt_current_day = new Date(dt_firstday);
 // print weekdays titles
 str_buffer += "<tr>\n";
 
 for (var n=0; n<7; n++)
	 str_buffer += "	<td bgcolor=\"#CCCCCC\">"+
	 "<font color=\"white\" face=\"tahoma, verdana\" size=\"2\">"+
	 week_days[(n_weekstart+n)%7]+"</font></td>\n";
 
 // print calendar table
 str_buffer += "</tr>\n";
 
 while (dt_current_day.getMonth() == dt_datetime.getMonth() || dt_current_day.getMonth() == dt_firstday.getMonth()) 
 {
  // print row heder
  str_buffer += "<tr>\n";
  for (var n_current_wday=0; n_current_wday<7; n_current_wday++) 
  {
	if (dt_current_day.getDate() == dt_datetime.getDate() && dt_current_day.getMonth() == dt_datetime.getMonth())
	 // print current date
	 str_buffer += "	<td bgcolor=\"#FFB6C1\" align=\"right\">";
	else if (dt_current_day.getDay() == 0 || dt_current_day.getDay() == 6)
	 // weekend days
	 str_buffer += "	<td bgcolor=\"#EEEEEE\" align=\"right\">";
	else
	 // print working days of current month
	 str_buffer += "	<td bgcolor=\"white\" align=\"right\">";

	if (dt_current_day.getMonth() == dt_datetime.getMonth())
	 // print days of current month
	 str_buffer += "<a href=\"javascript:window.opener."+str_target+
	 ".value='"+dt2dtstr(dt_current_day)+"'+document.cal.time.value; window.close();\">"+
	 "<font color=\"black\" face=\"tahoma, verdana\" size=\"2\">";
	else 
	 // print days of other months
	 str_buffer += "<a href=\"javascript:window.opener."+str_target+
	 ".value='"+dt2dtstr(dt_current_day)+"'+document.cal.time.value; window.close();\">"+
	 "<font color=\"gray\" face=\"tahoma, verdana\" size=\"2\">";
	 str_buffer += dt_current_day.getDate()+"</font></a></td>\n";
	 dt_current_day.setDate(dt_current_day.getDate()+1);
  }
  // print row footer
  str_buffer += "</tr>\n";
 }
 // print calendar footer
 str_buffer +=
  "<form name=\"cal\">\n"+
  "<tr><td colspan=\"7\" bgcolor=\"#CCCCCC\">"+
  "<input type=\"hidden\" name=\"time\" value=\"\" size=\"10\" maxlength=\"10\">\n" +
  "</form>\n</td></tr>\n</table>\n" +
  "</tr>\n</td>\n</table>\n" +
  "</body>\n" +
  "</html>\n";

  var vWinCal = window.open("", "Calendar", "width=200,height=220,status=no,resizable=no,top=250,left=650");
  vWinCal.focus(); // Added DNB: 6/26/05 to display calendar window on top if it is already open
	   vWinCal.opener = self;
  var calc_doc = vWinCal.document;
	   calc_doc.write (str_buffer);
	   calc_doc.close();
}
// datetime parsing and formatting routimes. modify them if you wish other datetime format
function str2dt (str_datetime) 
{
//   var re_date = /^(\d+)\-(\d+)\-(\d+)\s$/;
   //var re_date = /^(\d+)\-(\d+)\-(\d+)\s+/;
  	var re_date = /^(\d+)\-(\d+)\-(\d+)\s+(\d+)\:(\d+)\:(\d+)$/;
   if (!re_date.exec(str_datetime))
  return alert("Invalid Datetime format: "+ str_datetime);  
  return (new Date (RegExp.$3, RegExp.$2-1, RegExp.$1, RegExp.$4, RegExp.$5, RegExp.$6));
}

function dt2dtstr (dt_datetime) 
{
  	
	// make 1 digit month and day 2 digits 01 as opposed to 1
	var fullmonth = new String(dt_datetime.getMonth()+1);
	if (fullmonth.length ==1){
		fullmonth = '0' + fullmonth;
	}
	
	var fullday =   new String(dt_datetime.getDate());
	if(fullday.length == 1){
			fullday = '0' + fullday;
	}
	
  return (new String (fullmonth +"-"+ fullday +"-"+dt_datetime.getFullYear()));
}

function dt2tmstr (dt_datetime) 
{
  return (new String (dt_datetime.getHours()+":"+dt_datetime.getMinutes()+":"+dt_datetime.getSeconds()));
}

