// PegaJax(tm) Javascript communications library
// Copyright 2006-2010 Pegasys Computer Technologies, Inc.
// All Rights Reserved

var WebDoxNotesTimeout;
var WebDoxNotesTimeoutPass=0;

var http = getHTTPObject(); // We create the HTTP Object

//START: function ProcessWebDoxNotesField()
// This function flashes and fades the transmitted message

function CollapseElement(ElementName)
{
  document.getElementById(ElementName).setAttribute("style", "visibility: collapse;");
  document.getElementById(ElementName).setAttribute("style", "display: none;");

  document.getElementById(ElementName).style.display = 'none';
}//END: function CollapseElement(ElementName)

function ShowElement(ElementName)
{
  document.getElementById(ElementName).setAttribute("style", "visibility: visible;"); 
  document.getElementById(ElementName).setAttribute("style", "display: block;");

  document.getElementById(ElementName).style.display = 'block';
}//END: function ShowElement(ElementName)

function IsElementVisible(obj)
{
	
    if (obj == document) return true
    
    if (!obj) return false
    if (!obj.parentNode) return false
    if (obj.style) 
    {
        if (obj.style.display == 'none') return false
        if (obj.style.visibility == 'hidden') return false
    }
    
    //Standard methodology
    if (window.getComputedStyle) 
    {
        var style = window.getComputedStyle(obj, "")
        if (style.display == 'none') return false
        if (style.visibility == 'hidden') return false
    }
    
    //IE methodology
    var style = obj.currentStyle
    if (style) 
    {
        if (style['display'] == 'none') return false
        if (style['visibility'] == 'hidden') return false
    }
    
    return IsElementVisible(obj.parentNode) //cascade up the doc tree
}//END: function IsElementVisible(obj)


function IsElementVisibleOld(ElementID)
{
 var divstyle = new String();
 divstyle = document.getElementById(document.getElementById(ElementID).parentNode.id  ).style.visibility;	
 alert('parent divstyle='+divstyle);
	
	ThisElement=document.getElementById(ElementID);
	if(document.getElementById(ElementID).style.visibility == 'hidden')
	   IsVisible=false;
	 else
	 	IsVisible=true;
	alert('Parent Visibility='+document.getElementById(ThisElement.parentNode.id).style.visibility+'  ThisElement.parentNode.id='+ThisElement.parentNode.id+' '+'ThisElement.id='+ThisElement.id+' '+ElementID+' visibility= '+document.getElementById(ElementID).style.visibility);
	return IsVisible;
}//END: function GetElementVisibility(ElementID)

function MakeInputWritable(ElementName)
{
 document.getElementById(ElementName).readOnly=false;
}

function MakeInputReadOnly(ElementName)
{
 document.getElementById(ElementName).readOnly=true;
}


function ProcessWebDoxNotesField()
{
 WebDoxNotesTimeoutPass++;

 if(WebDoxNotesTimeoutPass==1)
  {
   document.getElementById('WebDoxNotes').setAttribute("style", "background-color: #aaccaa;border: #406040 1px solid"); 
   document.getElementById('WebDoxNotes').style.cssText="background-color: #aaccaa;border:  #406040 1px solid";
   WebDoxNotesTimeout=setTimeout("ProcessWebDoxNotesField()",150);
  }
 else if(WebDoxNotesTimeoutPass==2)
  {
   document.getElementById('WebDoxNotes').setAttribute("style", "background-color: #bbddbb;border: #406040 1px solid"); 
   document.getElementById('WebDoxNotes').style.cssText="background-color: #bbddbb;border: #406040 1px solid";
   WebDoxNotesTimeout=setTimeout("ProcessWebDoxNotesField()",150);
  }
 else if(WebDoxNotesTimeoutPass==3)
  {
   document.getElementById('WebDoxNotes').setAttribute("style", "background-color: #cceecc;border: #406040 1px solid"); 
   document.getElementById('WebDoxNotes').style.cssText="background-color: #cceecc;border: #406040 1px solid";
   WebDoxNotesTimeout=setTimeout("ProcessWebDoxNotesField()",150);
 }
 else if(WebDoxNotesTimeoutPass==4)
  {
   document.getElementById('WebDoxNotes').setAttribute("style", "background-color: #ddffdd;border: #406040 1px solid"); 
   document.getElementById('WebDoxNotes').style.cssText="background-color: #ddffdd;border: #406040 1px solid";
   WebDoxNotesTimeout=setTimeout("ProcessWebDoxNotesField()",150);
  }
 else if(WebDoxNotesTimeoutPass==5)
  {
   document.getElementById('WebDoxNotes').setAttribute("style", "background-color: #f0fff0;border: #406040 1px solid"); 
   document.getElementById('WebDoxNotes').style.cssText="background-color: #f0fff0;border: #406040 1px solid";
   WebDoxNotesTimeout=setTimeout("ProcessWebDoxNotesField()",5000);
  }
 else if(WebDoxNotesTimeoutPass==6)
  {
   document.getElementById('WebDoxNotes').setAttribute("style", "background-color: #ffffff;border:#608060 1px solid;color: #7f7f7f;"); 
   document.getElementById('WebDoxNotes').style.cssText="background-color: #ffffff;border:#608060 1px solid;color: #7f7f7f;";
   WebDoxNotesTimeout=setTimeout("ProcessWebDoxNotesField()",150);
   }
 else if(WebDoxNotesTimeoutPass==7)
  {
   document.getElementById('WebDoxNotes').setAttribute("style", "background-color: #ffffff;border:#b0d0b0 1px solid;color: #bbbbbb;"); 
   document.getElementById('WebDoxNotes').style.cssText="background-color: #ffffff;border:#b0d0b0 1px solid;color: #bbbbbb;";
   WebDoxNotesTimeout=setTimeout("ProcessWebDoxNotesField()",150);
  }
   else if(WebDoxNotesTimeoutPass==8)
  {
   document.getElementById('WebDoxNotes').innerHTML='';
   document.getElementById('WebDoxNotes').setAttribute("style", "background-color: #ffffff;border:0;"); 
   document.getElementById('WebDoxNotes').style.cssText="background-color: #ffffff;border:0";
   WebDoxNotesTimeoutPass=0;
  }

}
//END:function ProcessWebDoxNotesField()

// Convert MM/DD/YYYY to YYYY-MM-DD
function DateUSAtoDB(ThisDate)
{
//alert(ThisDate);
 if(ThisDate=='Any Date')  //handle 'any date'
   NewDate='Any Date';
  else //convert the date
    {
      DateParts=ThisDate.split('/');
      NewDate=DateParts[2]+'-'+DateParts[0]+'-'+DateParts[1];
    }
 return NewDate;
}

function handleServerRequestResponse() 
{

  if (http.readyState == 4) 
   {

    //results = http.responseText.split(",");
    //document.getElementById('city').value = results[0];
    //document.getElementById('state').value = results[1];
    var ResponseLines=new Array();
    var LineFields=new Array();

    ServerResponse='';
    WebDoxMessage='';
    
    ServerResponse=http.responseText;
    
    //alert('line 176: '+"Raw Server Response:["+ServerResponse+"]");
    
    ResponseLines=ServerResponse.split('<!--LINE-->');
    
    //alert('line 86: '+ResponseLines.length); 
    
    for(Counter=0;Counter<ResponseLines.length-1;Counter++)
      {
       LineFields=ResponseLines[Counter].split('<!--FIELD-->');
       
       ActionType=LineFields[0].replace(/^\s*/, "");
       ObjectName=LineFields[1];
       UpdateType=LineFields[2];
       DataContent=LineFields[3];
       
       //alert('line 86: '+'Line['+Counter+'] Action is ['+ActionType+']');
       if(ActionType=='ALERT')
         {
	  alert(DataContent);
	 }
	else if(ActionType=='EXEC') //this is to fire off innerhtml event handlers
	 {
	  //alert('going to try to execute: ['+DataContent+']');
	  //eval(DataContent);
	  var TemporaryFunction=new Function(DataContent); //Chrome refuses to function with eval
	  TemporaryFunction();
	 }
        else if(ActionType=='UPDATE')
	 {
	  if(UpdateType=='HTML')
	    {
	     //alert('Update: '+ObjectName+'='+DataContent);	     
	     document.getElementById(ObjectName).innerHTML = DataContent;
	    }
	  else if(UpdateType=='VALUE')
	   {
	    document.getElementById(ObjectName).value = DataContent;
	   }
	  else if(UpdateType=='BACKGROUNDCOLOR')
	   {
	    //alert('backgroundcolor');
	    document.getElementById(ObjectName).style.backgroundColor = DataContent;
	   }
	  
	 }//else if(ActionType=='UPDATE')
	 
	else if(ActionType=='JUMP')
	  {
	   window.location.hash=DataContent; //"SERVICES";
	  }
	
	else if(ActionType=='ShowByClassName')
	  {
	   ShowByClassName(DataContent); //"SERVICES";
	  }
	  
	  
  	else if(ActionType=='HideByClassName')
	  {
	   HideByClassName(DataContent); //"SERVICES";
	  }	
	
	else if(ActionType=='MakeInputWritable')
	  {
	   MakeInputWritable(DataContent); //"SERVICES";
	  }	 
	 
	else if(ActionType=='FlashFade')
	  {
	  	ArgumentList=DataContent.split(';');
	   FlashFade(ArgumentList[0],ArgumentList[1],ArgumentList[2]); //"SERVICES";  'fe2389',4
	  }	 


	else if(ActionType=='SetFocusSelect')
	  {
	   SetFocusSelect(DataContent); //"SERVICES";
	  }	 

	 
   else if(ActionType=='NEW')
	 {
	  if(UpdateType=='DOCUMENT')
	    {
	     myWin= open("", "displayWindow", "status=yes,toolbar=yes,menubar=yes,scrollbars=yes");

	     myWin.document.write(DataContent);
	     
	     myWin.document.close();
	    }
	  
	 }//else if(ActionType=='NEW')

       else if(ActionType=='ALERT')
        {
	 alert(DataContent);
	}
       else if(ActionType=='MESSAGE')
        {
	 document.getElementById('WebDoxNotes').innerHTML = DataContent;
 	 WebDoxNotesTimeoutPass=0;
	 WebDoxNotesTimeout=setTimeout("ProcessWebDoxNotesField()",1000);
        }
       //alert(ResponseLines[Counter]);
      } //for (Counter...

    
//    document.getElementById('WebDoxNotes').innerHTML = "Message";
//    WebDoxNotesTimeoutPass=0;
//    WebDoxNotesTimeout=setTimeout("ProcessWebDoxNotesField()",1000);

    delete ResponseLines;
    delete LineFields;
    
  } //if (http.readyState == 4)

} //function handleServerRequestResponse() 

function ServerRequest(FunctionName,Data)
{
  //alert("In Javascript Server Request, requesting :["+FunctionName+"]");
  
  
  RequestString= "Remote=1&FunctionName="+escape(FunctionName)+Data;
  RequestString+='&RND='+Math.floor(Math.random()*1000000);
  RequestString+='&EndRequest=1';
  
  //alert(RequestString);
  //alert(ServiceURL);  
  http.open("POST", ServiceURL, true); //RequestString, true); 
  
  //alert('line 164');
  
  //return false;
  
  http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
  http.setRequestHeader("Content-length", RequestString.length);
  http.setRequestHeader("Connection", "close");
  
  http.onreadystatechange = handleServerRequestResponse; 
  
  http.send(RequestString);
  //http.send(null);
  
  return false;

} //function ServerRequest(FunctionName,Data)

function getHTTPObject() 
{ 
var xmlhttp; 
  /*@cc_on

  @if (@_jscript_version >= 5)

    try {

      xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");

    } catch (e) {

      try {

        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");

      } catch (E) {

        xmlhttp = false;

      }

    }
  @else

  xmlhttp = false;

  @end @*/

  if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {

    try {

      xmlhttp = new XMLHttpRequest();

    } catch (e) {

      xmlhttp = false;

    }

  }

  return xmlhttp;

}// END: function getHTTPObject() 

function FormHasEmptyField(FormName)
{
 //alert('Formname='+FormName);
 
var MyForm = document.getElementById(FormName).elements;

MyString='';
HasEmptyField=0;

for(var i = 0; i < MyForm.length; i++)
        {
          if(MyForm[i].type != 'submit')
              {
                MyString+='&'+MyForm[i].name+'='+MyForm[i].value;
                //MyForm[i].value= GetDefaultValueForField(FormName,MyForm[i].name);  //'';
                //alert('Name is :'+MyForm[i].name);
                //alert('value is :'+MyForm[i].value);
		//alert('length is:'+MyForm[i].value.length);
		if(MyForm[i].value.length==0)
		   HasEmptyField=1;
              }
        };

 //alert('HasEmptyField='+HasEmptyField);
 //alert(MyString);
 return HasEmptyField;
 
}

function HideByClassName(ThisClassName)
{
 matches=getElementsByClassNameScript(ThisClassName);
 for(ObjectLoopCounter=0;ObjectLoopCounter<matches.length;ObjectLoopCounter++)
	{
		CollapseElement(matches[ObjectLoopCounter].id);
	}
}

function ShowByClassName(ThisClassName)
{
 matches=getElementsByClassNameScript(ThisClassName);
 for(ObjectLoopCounter=0;ObjectLoopCounter<matches.length;ObjectLoopCounter++)
	{
		//alert('showing: '+matches[ObjectLoopCounter].id);
		ShowElement(matches[ObjectLoopCounter].id);
	}
}

function GetBackgroundColorRGB(ElementID)

{
	
 var ThisObject = document.getElementById(ElementID);
	
 //alert('129: bgColor='+ThisObject.bgColor);
	
 if (ThisObject.currentStyle)
		
 {
		 
 //alert('132 ThisObject.currentStyle true');
		 
 var RawStyle = ThisObject.currentStyle['backgroundColor'];
		 
 }
	
 else if (window.getComputedStyle)
	  
 {
	    
 //alert('137: window.getcomputedstyle is true');
		
 var RawStyle = document.defaultView.getComputedStyle(ThisObject,null).getPropertyValue('background-color');
		
 }
		
	
 if(RawStyle.indexOf('#')>-1)
	  
 {
	   
 //alert('143: return value in hex');
	   
 HexRed=RawStyle.substr(1,2);
	   	
 HexGreen=RawStyle.substr(3,2);
	   
 HexBlue=RawStyle.substr(5,2);
	   
	   
 //alert('HexRed='+HexRed+' HexGreen='+HexGreen+' HexBlue='+HexBlue);
	   
 RGBString=parseInt(HexRed,16)+';'+parseInt(HexGreen,16)+';'+parseInt(HexBlue,16);
	  
 }
	  
 else
	  
 {
	   
 //alert('147: return value in RGB');
	   
 RGBString='Not set yet';
	   
 TempArray=RawStyle.split('(');
	   
 Temp=TempArray[1];
	   
 TempArray=Temp.split(')');
	   
 Temp=TempArray[0];
	   
 //alert('Temp='+Temp);
	   
 TempArray=Temp.split(',');
	  
	   
 RGBString=parseInt(TempArray[0],10)+';'+parseInt(TempArray[1],10)+';'+parseInt(TempArray[2],10);
	  
 }
	
 //alert('bottom of GetBackgroundColorRGB: RGBSring='+RGBString);
	
 return RGBString;


 }//END: function GetBackgroundColorRGB(ElementID)


 
 function SetBackgroundColor(ElementID,HexColor)

 {
 
 document.getElementById(ElementID).setAttribute("style", "background-color: #"+HexColor+";"); 
 document.getElementById(ElementID).style.cssText="background-color: #"+HexColor+";"; 

 
}//END: SetBackgroundColor(ElementID,HexColor)


 
 //Function FlashFade changes a BG color of the specified element to a specified Hex color value for 

 //the specified number of seconds before reverting to the original color again
 
 function FlashFade(ElementID,FlashHexColor,HoldTime)

 {
  
 if(!IsElementVisible(  document.getElementById(ElementID)  ) )
    
   return;
 
   //alert('PegaJax: 415:  ElementID='+ElementID+' FlashHexColor='+FlashHexColor+' HoldTime='+HoldTime);
 
   OriginalRGB=GetBackgroundColorRGB(ElementID);
 
   SetBackgroundColor(ElementID,FlashHexColor); 
 
 
   FlashRGB=HexToRGB(FlashHexColor);
 
   StepNumber=0;
 
 setTimeout('FlashFadeStep("'+ElementID+'","'+OriginalRGB+'","'+FlashRGB+'",'+StepNumber+')',HoldTime); 
 

 }//END: function FlashFade(ElementID,FlashHexColor,HoldTime)


 
 function HexToRGB(HexValue)

 {
 
 HexRed=HexValue.substr(0,2);
 
 HexGreen=HexValue.substr(2,2);
 
 HexBlue=HexValue.substr(4,2);
 
 RGBString=parseInt(HexRed,16)+';'+parseInt(HexGreen,16)+';'+parseInt(HexBlue,16);
	   
 
 return RGBString;

 }//END: function HexToRGB(HexValue)


 
 function ToHex(ThisDecimal)

 {
 
 TempString=ThisDecimal.toString(16);
 
 if(TempString.length<2)
   
   HexString='0'+TempString;
  
  else
   
    HexString=TempString; 
 
 
    return HexString;

 }//END:  function ToHex(ThisDecimal)


 
 
 function FlashFadeStep(ElementID,OriginalRGB,FlashFadeRGB,StepNumber)

 {
  
 if(!IsElementVisible(  document.getElementById(ElementID)  ) )
    
   return;
    
     
 
  //alert('PegaJax: 449:  FlashFadeStep: ElementID='+ElementID+'  OriginalRGB='+OriginalRGB+'  FlashFadeRGB='+FlashFadeRGB+' StepNumber='+StepNumber);
 
  OriginalColorArray=OriginalRGB.split(';');
 
  FlashColorArray=FlashFadeRGB.split(';');
 
 
  RedStep=-Math.floor(  ((FlashColorArray[0]*1)-(OriginalColorArray[0]*1)   ) /10 );
 //alert('RedStep='+RedStep);
 
 
  GreenStep=-Math.floor( ( (FlashColorArray[1]*1)-(OriginalColorArray[1]*1)   ) /10 );
 //alert('GreenStep='+GreenStep   ); 

 
  BlueStep=-Math.floor(( (FlashColorArray[2]*1)-(OriginalColorArray[2]*1)   ) /10 );
 //alert('BlueStep='+BlueStep); 
 
 
  
  OriginalHex= ToHex(OriginalColorArray[0]*1)+', '+ ToHex(OriginalColorArray[1]*1)+', '+ ToHex(OriginalColorArray[2]*1) ;
 
 
  CurrentColorRGB=GetBackgroundColorRGB(ElementID);
 //alert('CurrentColorRGB='+CurrentColorRGB);
 
  
  CurrentColorArray=CurrentColorRGB.split(';');
 
 
  NewRed=(CurrentColorArray[0]*1.0)+RedStep;
 
  NewGreen=(CurrentColorArray[1]*1.0)+GreenStep;
 
  NewBlue=(CurrentColorArray[2]*1.0)+BlueStep;
 
 
  if(NewRed<0)
   
    NewRed=0;
  
    else if(NewRed>255)
   
    NewRed=255;
 
    

    if(NewGreen<0)
   
    NewGreen=0;
  
    else if(NewGreen>255)
   
    NewGreen=255;

 
    
    if(NewBlue<0)
   
    NewBlue=0;
  
    else if(NewBlue>255)
   
    NewBlue=255;

 
    
    NewHex= ToHex(NewRed)+ToHex(NewGreen)+ToHex(NewBlue) ;

 
    
    if(StepNumber==10)  //We're done; set back to the original color
   
    SetBackgroundColor(ElementID,OriginalHex);
  
    else
   
    {
    
    StepDelay=100;
    
    SetBackgroundColor(ElementID,NewHex);
    
    setTimeout('FlashFadeStep("'+ElementID+'","'+OriginalRGB+'","'+FlashRGB+'",'+((StepNumber*1)+1)+')',StepDelay);
   
    }
 //alert('NewRed='+NewRed+' NewGreen='+NewGreen+' NewBlue='+NewBlue);
 
 
    
    //StepDelay=100;  // 1 tenth of a second between color cross fade steps

    //setTimeout('FlashFadeStep("'+ElementID+'","'+OriginalRGB+'","'+FlashRGB+'",'+(StepNumber+1)+')',StepDelay);  

 

    }//END: FlashFadeStep()



    //Purpose:  shift focus to the specified element and select all text within the element

    
    function SetFocusSelect(ElementID)

    {
 
    var ThisObject = document.getElementById(ElementID);
 
 
    ThisObject.focus();
 
    ThisObject.select();

    }//END: function SetFocusSelect(ElementID)


    
function CheckTime(timeBox,RelativePosition,Partner)
{
 //Is there more than one time in a paired relationship?  If so, then RelativePosition != 0
 //If the relative position is 1, we are the first in a pair (say, the start time)
 //If the relative position is 2, we are the second in a pair (say, the end time)
 //The goal is to have the end later than the start
 if(!RelativePosition)
   {
    RelativePosition=0;
   }
 
 if( RelativePosition >0 ) //We may have a valid partner.  Get more information
   {
    PartnerValue=Partner.value;
    //alert('PartnerValue=[ '+PartnerValue+' ]');
    PartnerLength=PartnerValue.length;
    //alert('PartnerLength=[ '+PartnerLength+' ]');
    if(PartnerLength < 4) //This is  not a valid partner if the field is blank
      {
       //alert('No valid partner');
       RelativePosition=0;
      }
   }

 //alert('RelativePosition='+RelativePosition);
 
 //Now parse the partner- if they exist and are valid
 if(RelativePosition > 0)
  {
   timeraw=PartnerValue;
   timeraw=timeraw.split(' ');

   if( (timeraw[0].match('a')=='a') || timeraw[0].match('A')=='A') 
     {
      timeraw[0]=timeraw[0].replace(/am/gi,'');;
      timeraw[0]=timeraw[0].replace(/a/gi,""); //[timeraw[0].length-1]='*';
      timeraw[1]='a';
     }

   if( (timeraw[0].match('p')=='p') || timeraw[0].match('P')=='P')
     {
      timeraw[0]=timeraw[0].replace(/pm/gi,'');
      tempstring=timeraw[0].replace(/p/gi,''); //[timeraw[0].length-1]='*';
      timeraw[0]=tempstring;
      timeraw[1]='p';
      //alert(timeraw[0]);
     }

   PartnerAMPM=timeraw[1];
   //alert(timeraw[1]);

   time=timeraw[0];
 
   if (  
        ( !/\d{1}:\d{2}/.test(time)  )    
        &&
        ( !/\d{1}/.test(time)  )
      )
     {
      alert('Invalid time  format')
      timeBox.value='';
      return
     }
   time=time.split(':');
    
  }//END: if(RelativePosition > 0)

 timeraw=timeBox.value;
 //alert(time);
 

 timeraw=timeraw.split(' ');
 //alert(timeraw[0]+'~'+timeraw[1]);

 //fix p/a right after time w/out space
 //alert(timeraw[0]+' len='+timeraw[0].length);

 if( (timeraw[0].match('a')=='a') || timeraw[0].match('A')=='A') 
   {
     timeraw[0]=timeraw[0].replace(/am/gi,'');;
    timeraw[0]=timeraw[0].replace(/a/gi,""); //[timeraw[0].length-1]='*';
    timeraw[1]='a';
   }

 if( (timeraw[0].match('p')=='p') || timeraw[0].match('P')=='P')
   {
    timeraw[0]=timeraw[0].replace(/pm/gi,'');
    tempstring=timeraw[0].replace(/p/gi,''); //[timeraw[0].length-1]='*';
    timeraw[0]=tempstring;
    timeraw[1]='p';
    //alert(timeraw[0]);
   }

 time=timeraw[0];
 //if ( (!/\d{2}:\d{2}/.test(time)) && (!/\d{1}:\d{2}/.test(time)) )
 
 //if ( !/\d{1}:\d{2}/.test(time) )
 
 if (  
      ( !/\d{1}:\d{2}/.test(time)  )    
      &&
      ( !/\d{1}/.test(time)  )
    )
   {
    alert('Invalid time  format')
    timeBox.value='';
    return
   }
 time=time.split(':');
 
 //alert('time.length=['+time.length+']');
 
 if(time.length==1)
   {
    time[1]='00';
   }

 //alert('time.length=['+time.length+']');

 //alert('menu.php line 64 ==>  time[1]=['+time[1]+']');
 
 if (time[0] >12 || time[1]>59) 
   {
    alert('Invalid time format- time out of range')
    timeBox.value='';
    return
   }
  else
   {
    //alert('time[1]=='+time[1]);
    if((timeraw[1]=='pm') || (timeraw[1]=='am') || (timeraw[1]=='p') || (timeraw[1]=='a') )
      {
       if(timeraw[1]=='a')
         suffix='am';
       else if(timeraw[1]=='p')
         suffix='pm';
       else
         suffix=timeraw[1];
	 
       //Basic  Partner Driven correction #1A - am / pm specified
       //:: if the junior partner is PM, we can not be AM.  Set our value to PM.
       if( (RelativePosition==2) && (PartnerAMPM=='pm') )
         {
	  suffix='pm';
         }
       //END: Basic  Partner Driven Correction #1A
       
       timeBox.value=time[0]+':'+time[1]+' '+suffix;

       return;
      }
     else //guess at am/pm
      {
       // 12 = pm , 1=pm, 2pm, 3pm , 4pm, 5pm, 6pm, 7pm, 8am, 9am 10am 11am
       if( (time[0]==11) || (time[0]==8) || (time[0]==9) || (time[0]==10) )
          suffix= 'am';  //timeBox.value=time[0]+':'+time[1]+' am';
        else
          suffix= 'pm';

       //Basic  Partner Driven correction #1B - am / pm NOT specified
       //:: if the junior partner is PM, we can not be AM.  Set our value to PM.
       if( (RelativePosition==2) && (PartnerAMPM=='pm') )
         {
	  suffix='pm';
         }
       //END: Basic Partner Driven Correction #1B

       timeBox.value=time[0]+':'+time[1]+' '+suffix;
      }
   }

} //function CheckTime(timebox,RelativePosition,Partner))





function CheckDate(DateBox)
{
 RawDateValue=DateBox.value;
 
 DateParts=RawDateValue.split('/');
 
 var CurrentDate = new Date();
 var CurrentDay = CurrentDate.getDate();
 var CurrentMonth = CurrentDate.getMonth()+1;
 var CurrentYear = CurrentDate.getFullYear();
 
 IsValidDate=true;
 if(DateParts.length <2) //Does this have a chance of being a valid date?
   {
    IsValidDate=false;
    //alert('Not a valid date; too few elements');
   }
 //alert('CurrentYear='+CurrentYear);  
   
 MonthValue=(DateParts[0]*1.0);
 DayValue=(DateParts[1]*1.0);
 if(DateParts.length ==2)
   YearValue=CurrentYear;
  else
   YearValue=(DateParts[2]*1.0);

 if( YearValue<100)
   YearValue+= 2000;


 if(IsValidDate && (MonthValue>12) )  //complain if they put in a silly month
   IsValidDate=false;
 
 if(IsValidDate)
  {
   NumberOfDaysInMonth=0;
   switch(MonthValue)
   {
    case 1: case 3:  case  5 :  case  7:  case  8:  case  10:  case  12:
      NumberOfDaysInMonth=31;
      break;

    case 4:  case  6:  case  9:  case  11:
      NumberOfDaysInMonth=30;
      break;
      
    case 2:
      if (  (YearValue % 4 == 0) && ( (!(YearValue % 100 == 0) ) || (YearValue % 400 == 0)) )
        NumberOfDaysInMonth=29;
       else
        NumberOfDaysInMonth=28;
      break;
   }//END: switch(MonthValue)
   
  if(DayValue>NumberOfDaysInMonth) //complain if the put in a silly day of the month
    IsValidDate=false;
   
 }//END: if(IsValidDate)

 
 //alert('Month='+MonthValue+'  Day='+DayValue+'  Year='+YearValue+' NumberOfDaysInMonth='+NumberOfDaysInMonth);
 if(!IsValidDate)  //If the date is bogus, put in the current date and warn them with an error tone flashfade
   {
    DateBox.value=CurrentMonth+'/'+CurrentDay+'/'+CurrentYear;
    FlashFade(DateBox.id,'ff8090',5000);
   }
  else
   {
     DateBox.value=MonthValue+'/'+DayValue+'/'+YearValue;
   }
 
}//END: funciton CheckDate(DateBox)


function IsElementVisible(ElementName)
{
//alert(navigator.userAgent.toLowerCase());
  ReturnValue=false;

  isIE6 = navigator.userAgent.toLowerCase().indexOf('msie 6') != -1;
  isIE7 = navigator.userAgent.toLowerCase().indexOf('msie 7') != -1;
  if(!isIE6 && !isIE7)
  { 
    if(document.getElementById(ElementName).style.visibility == 'visible')
      ReturnValue=true;
  }
  else
  {
   if(document.getElementById(ElementName).style.display=='block')
     ReturnValue=true;
  }
  
  return ReturnValue;
  //document.getElementById(ElementName).style.display = 'block';
}//END: function IsElementVisible(ElementName)

function ToggleVisibility(ElementName)
{
 if( IsElementVisible(ElementName) )
   CollapseElement(ElementName);
  else
   ShowElement(ElementName);
   
}//END: function ToggleVisibility(ElementName)

function SetOpacity(ElementName,OpacityValue)
{
   ThisElement=document.getElementById(ElementName);
	ThisElement.style.filter = 'alpha(opacity=' + OpacityValue + ')';
 	ThisElement.style.opacity = OpacityValue/100;
}//END: function SetOpacity(ElementName,OpacityValue)


