/******************************************************************************
* JsScripts.js                                                               *
*                                                                             *
* Provides JS functions                                            *
*                                                                             *
*                                                                             *
******************************************************************************/

// js global variables here
var ButtonClickedFlag = false;
var popupWindow;

/******************************************************************************/

  // We want to get out of a frame environment
   function FrameOut(ThisFile) {
     var ThisLocation = top.location.href;
     
     ThisLocation = ThisLocation.toLowerCase();
    
     // see if ThisFile is in the string
     if (ThisLocation.indexOf(ThisFile.toLowerCase()) < 0)
        top.location.href = ThisFile;
   }
   
   // si it inside a frame 
   function InFrame(ThisFile) {
     var ThisLocation = top.location.href;
     
     ThisLocation = ThisLocation.toLowerCase();
     
     // inside a frame
     if (ThisLocation.indexOf(ThisFile.toLowerCase()) < 0)
     	return true;
     else
     	 return false; 	
    	
   }

  // Check whether applet is enabled
  function Check_JavaApplet() {
    var result;
    result = false;
    
    if (navigator.javaEnabled())
    {
       result = true;
    
       if (Get_Browser() == 'NS4')
       {
          var appletMimeType = navigator.mimeTypes['application/x-java-applet'];

/*       
          if (appletMimeType.enabledPlugin)
             alert(appletMimeType.enabledPlugin.description);
*/       
          if (!appletMimeType || !appletMimeType.enabledPlugin)
             return false;
          
          var re = /Plug-in (\d\.\d(\.\d))/;
          var match = re.exec(appletMimeType.enabledPlugin.description);
       
          if (!match)
             return false;
          else 
          {
             var jreVersion = match[1];
             //alert('Java plugin enabled. The version is ' + jreVersion);
          }
       }
/*       
       else
       if (Get_Browser() == 'IE5')
       {
          var swf = new ActiveXObject("WScript.Shell");
          if (swf != null)
		  {
			try
			{
			    alert(shell.regRead("HKEY_LOCAL_MACHINE\\Software\\JavaSoft\\Java Runtime Environment\\CurrentVersion"));
 		    }
			catch(e)
            {
			 	alert("Error reading registry");
            }
		  }
       }
*/       
       else
       {
//          alert('Java is enabled');
            return true;
       }
    }
    else 
//       alert('Java is not enabled');
       result = false;
       
    return result;
  }
  
  // Get browser and version
  function Get_Browser() {
  
     // convert all characters to lowercase to simplify testing 
     var agt=navigator.userAgent.toLowerCase(); 
     
     // *** BROWSER VERSION *** 
     // Note: On IE5, these return 4, so use is_ie5up to detect IE5. 
     var is_major = parseInt(navigator.appVersion,10); 
     var is_minor = parseFloat(navigator.appVersion,10); 

    // Note: Opera and WebTV spoof Navigator.  We do strict client detection. 
    // If you want to allow spoofing, take out the tests for opera and webtv. 
    var is_nav  = ((agt.indexOf('mozilla')!=-1) && (agt.indexOf('spoofer')==-1) && 
                  (agt.indexOf('compatible') == -1) && (agt.indexOf('opera')==-1) && 
                  (agt.indexOf('webtv')==-1)); 
    var is_nav2 = (is_nav && (is_major == 2)); 
    var is_nav3 = (is_nav && (is_major == 3)); 
    var is_nav4 = (is_nav && (is_major == 4)); 
    var is_nav4up = (is_nav && (is_major >= 4)); 
    var is_navonly = (is_nav && ((agt.indexOf(";nav") != -1) || (agt.indexOf("; nav") != -1)) ); 
    var is_nav5 = (is_nav && (is_major == 5)); 
    var is_nav5up = (is_nav && (is_major >= 5)); 
    var is_nav6 = (is_nav && (is_major == 5));
    var is_nav6up = (is_nav && (is_major >= 5));
    
    var is_ie   = (agt.indexOf("msie") != -1); 
    var is_ie3  = (is_ie && (is_major < 4)); 
    var is_ie4  = (is_ie && (is_major == 4) && (agt.indexOf("msie 5.")==-1) );
    var is_ie4up  = (is_ie  && (is_major >= 4)); 
    var is_ie5  = (is_ie && (is_major == 4) && (agt.indexOf("msie 5.")!=-1) );
    var is_ie5up  = (is_ie && !is_ie3 && !is_ie4);
    var is_ie5_5    = (is_ie && (is_major == 4) && (agt.indexOf("msie 5.5")!=-1) );
    var is_ie5_5up =(is_ie && !is_ie3 && !is_ie4 && !is_ie5);
    var is_ie6    = (is_ie && (is_major == 4) && (agt.indexOf("msie 6.")!=-1) );
    var is_ie6up  = (is_ie && !is_ie3 && !is_ie4 && !is_ie5 && !is_ie5_5);
    var is_ie7    = (is_ie && (is_major == 4) && (agt.indexOf("msie 7.")!=-1) );
    var is_ie7up  = (is_ie && !is_ie3 && !is_ie4 && !is_ie5 && !is_ie5_5 && !is_ie6);
    var is_ie8    = (is_ie && (is_major == 4) && (agt.indexOf("msie 8.")!=-1) );
    var is_ie8up  = (is_ie && !is_ie3 && !is_ie4 && !is_ie5 && !is_ie5_5 && !is_ie6 && !is_ie7);
    
    // return browser type
    if ((is_nav4) && (is_minor < 4.7))
        return 'UNKNOWN';  // only netscape 4.7 upwards
    if (is_nav4)
        return 'NN4';
    else if (is_nav6 || is_nav6up)
    {
        //distinguish NN6 and NN7
         // return netscape 6
        var idx1 = agt.indexOf("netscape6/");
        
        if (idx1 < 0)
           return 'NN7';
        else 
           return 'NN6';
    }
    else if (is_ie5 || is_ie5up || is_ie5_5 || is_ie5_5up)
        return 'IE5';
    else if  (is_ie6 || is_ie6up)
        return 'IE6';
    else if  (is_ie7 || is_ie7up)
        return 'IE7';
    else if  (is_ie8 || is_ie8up)
        return 'IE8';
/*        
    else if (is_ie4)
        return 'IE4';
    else if (is_ie3)
        return 'IE3';
*/        
    else
        return 'UNKNOWN';
  }

  // Get browser and version
  function Get_BrowserVersion() {
  
     // convert all characters to lowercase to simplify testing 
     var agt=navigator.userAgent.toLowerCase(); 
     
     // *** BROWSER VERSION *** 
     // Note: On IE5, these return 4, so use is_ie5up to detect IE5. 
     var is_major = parseInt(navigator.appVersion,10); 
     var is_minor = parseFloat(navigator.appVersion,10); 

    // Note: Opera and WebTV spoof Navigator.  We do strict client detection. 
    // If you want to allow spoofing, take out the tests for opera and webtv. 
    var is_nav  = ((agt.indexOf('mozilla')!=-1) && (agt.indexOf('spoofer')==-1) && 
                  (agt.indexOf('compatible') == -1) && (agt.indexOf('opera')==-1) && 
                  (agt.indexOf('webtv')==-1)); 
    var is_nav2 = (is_nav && (is_major == 2)); 
    var is_nav3 = (is_nav && (is_major == 3)); 
    var is_nav4 = (is_nav && (is_major == 4)); 
    var is_nav4up = (is_nav && (is_major >= 4)); 
    var is_navonly = (is_nav && ((agt.indexOf(";nav") != -1) || (agt.indexOf("; nav") != -1)) ); 
    var is_nav5 = (is_nav && (is_major == 5)); 
    var is_nav5up = (is_nav && (is_major >= 5)); 
    var is_nav6 = (is_nav && (is_major == 5));
    var is_nav6up = (is_nav && (is_major >= 5));
    
    var is_ie   = (agt.indexOf("msie") != -1); 
    var is_ie3  = (is_ie && (is_major < 4)); 
    var is_ie4  = (is_ie && (is_major == 4) && (agt.indexOf("msie 5.")==-1) );
    var is_ie4up  = (is_ie  && (is_major >= 4)); 
    var is_ie5  = (is_ie && (is_major == 4) && (agt.indexOf("msie 5.")!=-1) );
    var is_ie5up  = (is_ie && !is_ie3 && !is_ie4);
    var is_ie5_5    = (is_ie && (is_major == 4) && (agt.indexOf("msie 5.5")!=-1) );
    var is_ie5_5up =(is_ie && !is_ie3 && !is_ie4 && !is_ie5);
    var is_ie6    = (is_ie && (is_major == 4) && (agt.indexOf("msie 6.")!=-1) );
    var is_ie6up  = (is_ie && !is_ie3 && !is_ie4 && !is_ie5 && !is_ie5_5);
    var is_ie7    = (is_ie && (is_major == 4) && (agt.indexOf("msie 7.")!=-1) );
    var is_ie7up  = (is_ie && !is_ie3 && !is_ie4 && !is_ie5 && !is_ie5_5 && !is_ie6);
    var is_ie8    = (is_ie && (is_major == 4) && (agt.indexOf("msie 8.")!=-1) );
    var is_ie8up  = (is_ie && !is_ie3 && !is_ie4 && !is_ie5 && !is_ie5_5 && !is_ie6 && !is_ie7 && !is_ie8);
    
    // return browser version
    if (is_nav4)
    {
         // return netscape 4
         
        return "Netscape " + is_minor;
        
    }
    else if (is_nav6 || is_nav6up)
    {
         // return netscape 6
        var idx1 = agt.indexOf("netscape6/");
        
        // must be netscape 7
        if (idx1 < 0)
        {
           idx1 = agt.indexOf("netscape/");
           var str = agt.substring(idx1, 999);
           str = str.replace("netscape/", "");
        }
        else
        {
           var str = agt.substring(idx1, 999);
           str = str.replace("netscape6/", "");
        }
        
        return "Netscape " + str;
    }
    else if (is_ie4 || is_ie4up || is_ie5 || is_ie5up || is_ie5_5 || is_ie5_5up || is_ie6 || is_ie6up || is_ie7 || is_ie7up || is_ie8 || is_ie8up)
    {
         // return IE version
         var idx1 = agt.indexOf("msie");
         var idx2 = agt.indexOf("; windows");
         var str = agt.substring(idx1, idx2);
         str = str.replace("msie ", "");
         
         return "IE " + str;
    }
    else
        return 'UNKNOWN';
  }

  // Get GMT Offset from Client Browser
  function GetGMTOffset() {
	var tDate = new Date();
	var GMTOffset =  tDate.getTimezoneOffset()/60;
    
    return GMTOffset;
  }  
  
  //Set a cookie given a name, value and expiration date.
  function SetCookie (name, value, expires) {
   /*                                                                              
    if (navigator.cookieEnabled) {
      // set the cookie
      var expdate = new Date();
      // 10 days expiry period for cookie
      expdate.setTime(expdate.getTime() + (10*24*60*60*1000));
      SetCookie('EVALU8_USERNAME', USER_NAME.value, expdate);
   */
     document.cookie = name + "=" + escape(value) + "; expires=" +
     expires.toGMTString() +  "; path=/";
  }

  // Returns the value of the named cookie.
  function GetCookie(name) {
     var search;

     search = name + "=";
     offset = document.cookie.indexOf(search);
     
     if (offset != -1) {
        offset += search.length;
        end = document.cookie.indexOf(";", offset);
        
        if (end == -1)
           end = document.cookie.length;
           
     return unescape(document.cookie.substring(offset, end));
     }
     else
       return "";
  }

  // find out which radio button is selected
  function getSelectedRadioButton(buttonGroup)
  {
         for (var i = 0; i < buttonGroup.length; i++)
             if (buttonGroup[i].checked)
                return i;
  }

  // find the index of Object
  function getComboIndex(ThisObject, ThisValue)
  {
         for (var i = 0; i < ThisObject.length; i++)
             if (ThisObject[i].value == ThisValue)
                return i;

        return 0;                
  }

  // get the list of selected Object
  function getSelectedComboList(ThisObject)
  {
       var ThisList = "";
       
         for (var i = 0; i < ThisObject.length; i++)
         {
             if (ThisObject.options[i].selected)
             {
                if (ThisList == "")
                   ThisList = ThisObject.options[i].value;
                else
                   ThisList += "," + ThisObject.options[i].value;
             }
         }
        return ThisList;                
  }

  // Toggle the selected on and off
  function ToggleSelectedCombo(ThisObject)
  {
     if (ThisObject)
     {           
         for (var i = 0; i < ThisObject.length; i++)
         {
             if (ThisObject.options[i].selected)
                ThisObject.options[i].selected = false;
         }
     }
  }

  // add item from FromObject into ToObject 
  function AddSelectedComboItem(FromObject, ToObject)
  {
           var eOption = document.createElement("OPTION");
           eOption.value = FromObject[FromObject.options.selectedIndex].value;
           eOption.text = FromObject[FromObject.options.selectedIndex].text;
           ToObject.options.add(eOption,ToObject.length);
  }

  // add item from FromObject into ToObject into a specific position
  function AddSelectedComboItemPos(FromObject, ToObject, Pos)
  {
           var eOption = document.createElement("OPTION");
           eOption.value = FromObject[FromObject.options.selectedIndex].value;
           eOption.text = FromObject[FromObject.options.selectedIndex].text;
           ToObject.options.add(eOption,Pos);
  }

  // add item To Object at the bottom of the list
  function AddComboItem(ThisObject, ThisValue, ThisText, ThisStyle)
  {
           var eOption = new Option(ThisText, ThisValue);
           ThisObject.options[ThisObject.options.length] = eOption;
/*           
           var eOption = document.createElement("OPTION");
           eOption.value = ThisValue;
           eOption.text = ThisText;
           eOption.className = ThisStyle;
           ThisObject.options.add(eOption,ThisObject.length);
*/           
  }

  // add item To Object at the specified location on the list
  function AddComboItemPos(ThisObject, ThisPos, ThisValue, ThisText, ThisStyle)
  {
           var eOption = document.createElement("OPTION");
           eOption.value = ThisValue;
           eOption.text = ThisText;
           eOption.className = ThisStyle;
           ThisObject.options.add(eOption,ThisPos);
  }

  // remove item from the object 
  function RemoveSelectedComboItem(ThisObject, ThisIndex)
  {
        // we have the item selected
         ThisObject.options[ThisIndex] = null;
/*         
         ThisObject.options.remove(ThisIndex);
*/         
  }

  // Modify items 
  function ModifyComboItem(ThisObject, ThisIndex, ThisValue, ThisText, ThisStyle)
  {
           ThisObject.options[ThisIndex].value = ThisValue;
           ThisObject.options[ThisIndex].text = ThisText;
           ThisObject.options[ThisIndex].className = ThisStyle;
  }

  // checks the object for value
  function ComboItemValueExists(ThisObject, ThisValue)
  {
          for (i=0; i < ThisObject.options.length; i++)
          {
             if (ThisObject.options[i].value == ThisValue)
                return true;                
          }
          return false;
  }
  
  // checks the object for text value
  function ComboItemTextExists(ThisObject, ThisText)
  {
          for (i=0; i < ThisObject.options.length; i++)
          {
             if (ThisObject.options[i].text == ThisText)
                return true;                
          }
          return false;
  }

  // resize the object 
  function ResizeCombo(ThisObject, MaxSize)
  {
           with (ThisObject)
           {
                var i = ThisObject.options.length;
                // only resize if less than MaxSize
                if (i < MaxSize)
                   ThisObject.size = i;
           }
  }
  
  /*************** IMAGE Manipulation routine **********************************/

  function PreloadImages()
  {
    if (document.images)
    {
/*
      // main next button
      next_up = new Image();	    next_up.src = "../images/next_up.gif";
      next_over = new Image();	    next_over.src = "../images/next_over.gif";
  	  next_down = new Image();		next_down.src = "../images/next_down.gif";
//  	  next_inactive = new Image();	next_inactive.src = "../images/next_inactive.gif";

*/
	}
  }

  // click button and set others to default
  function RollOver(imgName)
  {
	if (document.images)
	{
	   document.images[imgName].src=eval(imgName + "_over.src");
	}
    
    return true;
  }

  // button to default except the clicked
  function UnclickAll(imgName)
  {
    ButtonClickedFlag = false;

    for (var i=0; i < document.images.length; i++)
    {
        if (document.images[i].name != imgName)
           document.images[i].src = eval(document.images[i].name +  "_up.src");
    }
  }

  // button to default
  function RollOut(imgName)
  {
    if (!ButtonClickedFlag) {

    	if (document.images)
	    {
		   document.images[imgName].src=eval(imgName + "_up.src");
	    }
    }
  }

  // click the button
  function ShowClick(imgName)
  {
	if (document.images)
	{
        self.focus();
		document.images[imgName].src=eval(imgName + "_down.src");
	}
    ButtonClickedFlag = true;
  }
  
  // click the button
  function UnclickButton(imgName)
  {
    	if (document.images)
	    {
		   document.images[imgName].src=eval(imgName + "_up.src");
	    }
        ButtonClickedFlag = false;
  }
  
/*************** IMAGE Manipulation routine **********************************/


  // popup the window
  function OpenSmallWindow(ThisFile)
  {
    var ScreenX = 500;
    var ScreenY = 350;
    
    var posX = (screen.width - ScreenX) / 2;
    var posY = (screen.height - ScreenY) / 2;
    var ScreenStr = 'titlebar=0,scrollbars=1,menubar=0,status=1,resizable=1,width=' + ScreenX + ',height=' + ScreenY + ',left=' + posX + ',top=' + posY;
    
    popupWindow = window.open(ThisFile, 'popup_small', ScreenStr);

  }

  // popup the window
  function OpenBigWindow(ThisFile)
  {
    var ScreenX = 750;
    var ScreenY = 550;
    
    var posX = (screen.width - ScreenX) / 2;
    var posY = (screen.height - ScreenY) / 2;
    var ScreenStr = 'titlebar=0,scrollbars=1,menubar=0,status=1,resizable=1,width=' + ScreenX + ',height=' + ScreenY + ',left=' + posX + ',top=' + posY;
    
    popupWindow = window.open(ThisFile, 'popup_big', ScreenStr);

  }

  // popup the window
  function OpenWindow(ThisFile)
  {
    var ScreenStr = 'titlebar=0,scrollbars=1,menubar=0,status=1,resizable=1';
    
    popupWindow = window.open(ThisFile, 'popup', ScreenStr);

  }

  // popup a separate window
  function PrintPage()
  {
    var ScreenX = 640; // width of A4
    var ScreenY = 460;
    
    var posX = (screen.width - ScreenX) / 2;
    var posY = (screen.height - ScreenY) / 2;
    var ScreenStr = 'titlebar=0,scrollbars=1,menubar=0,resizable=1,width=' + ScreenX + ',height=' + ScreenY + ',left=' + posX + ',top=' + posY;
//    var ScreenStr = 'titlebar=0,menubar=0,width=' + ScreenX;
    
   window.open('../includes/PrintPage.asp', 'printpopup', ScreenStr);

  }

  // popup the report options
  function Open_Report_Options(ThisReportName)
  {
    var ScreenX = 400;
    var ScreenY = 200;
    
    var WindowName = 'popup';
    
    var posX = (screen.width - ScreenX) / 2;
    var posY = (screen.height - ScreenY) / 2;
    var ScreenStr = 'titlebar=0,menubar=0,status=0,scrollbars=0,resizable=1,width=' + ScreenX + ',height=' + ScreenY + ',left=' + posX + ',top=' + posY;
    
    popupWindow = window.open("Report_Options.asp?REPORTNAME=" + ThisReportName, WindowName, ScreenStr);
    
    return WindowName;    

  }        

  // popup the window
  function PrintPreview(ThisFile)
  {
  
    var ScreenX = 640; // width of A4
    var ScreenY = 460;

/*    
    var ScreenX = 480; // width of A4
    var ScreenY = 300;
*/    
    
    var posX = (screen.width - ScreenX) / 2;
    var posY = (screen.height - ScreenY) / 2;
    var ScreenStr = 'titlebar=0,scrollbars=1,menubar=0,status=1,resizable=1,width=' + ScreenX + ',height=' + ScreenY + ',left=' + posX + ',top=' + posY;

    popupWindow = window.open('', 'popup', ScreenStr);
    
    popupWindow.document.write('<HEAD><TITLE>Please Wait</TITLE>');
    popupWindow.document.write('</HEAD>');
    popupWindow.document.write('<body>');
    popupWindow.document.write('<BIG><div id="status" align=center>Processing Report...</div></BIG>');
    popupWindow.document.write('</body>');

    popupWindow.focus();
         
    // actual redirection here  
   popupWindow.location.href = ThisFile;  

  }

  // popup a window and return the name
  function MessageWindow()
  {
    var ScreenX = 500;
    var ScreenY = 350;
/*    
    var ScreenX = 640; // width of A4
    var ScreenY = 350;
*/    
    var WindowName = 'popup';
    
    var posX = (screen.width - ScreenX) / 2;
    var posY = (screen.height - ScreenY) / 2;
    var ScreenStr = 'titlebar=0,menubar=0,status=1,scrollbars=1,resizable=1,width=' + ScreenX + ',height=' + ScreenY + ',left=' + posX + ',top=' + posY;
    
    popupWindow = window.open("../includes/msg.asp", WindowName, ScreenStr);
    
    return WindowName;    
    
  }
  
  // closes the message window and refreshes the parent window
  function CloseReloadWindow()
  {
       CloseWindow();           
       window.location.reload(true);
       
  }

  // close the Window
  function CloseWindow()
  {
      if (popupWindow != null)
        popupWindow.close();
  }

/*--------------------- NEW STUFF FOR SINGLE LOGIN ------------------------*/  
  // main login 
  function General_Login() 
  {
       var ParameterString = "";
       var GMT_Offset = GetGMTOffset();
			
	   with (document.LOGIN_FORM)
	   {
		  var defaultURL = "login_post.asp";

          ParameterString = "GMT=" + GMT_Offset + "&";
          ParameterString = ParameterString + "UserID=" + UserID.value;
		  action =  defaultURL  + "?" +  ParameterString;
		  submit();
       }
  }

/******* Trigger the enter key for form submit ********/
function TriggerSubmit()
{
         if (document.layers)
            document.captureEvents(Event.KEYDOWN);
            
         document.onkeydown  = 
         function (evt) 
         {
                  var keyCode = evt ? (evt.which ? evt.which : evt.keyCode) : event.keyCode;
                  var eventTarget = evt ? evt.target : event.srcElement;
                  var textField = eventTarget.type == 'text' || eventTarget.type == 'textarea' || 
                                  eventTarget.type == 'password';
                  
                  // only when it's a text field
                  if (keyCode == 13 && textField) 
                  {
                     SubmitForm();
                     return false;
                  }
                  else
                     return true;
         }
}

function BookMarkWeb()
{
         var txt = "Bookmark This Web!";
         var url = "http://www.and.com.au";
         var who = "and";

         var ver = navigator.appName;
         var num = parseInt(navigator.appVersion,10);
         
         if ((ver == "Microsoft Internet Explorer")&&(num >= 4)) 
         {
            document.write('<A HREF="javascript:window.external.AddFavorite(url,who);" ');
            document.write('onMouseOver=" window.status=');
            document.write("txt; return true ");
            document.write('"onMouseOut=" window.status=');
            document.write("' '; return true ");
            document.write('">'+ txt + '</a>');
         }
         else
         {
            txt += "  (Ctrl+D)";
            document.write(txt);
         } 
}

// returns the full date in a standard format today
function Today(DateFormat)
{
   var ThisDate = new Date();
   var dow = new Array("Sunday", "Monday", "Tuesday", "Wednesday","Thursday", "Friday","Saturday");   
   var mmm = new Array("January", "February", "March", "April","May", "June", "July", "August", "September", "October", "November", "December");   
   
   var day = ThisDate.getDay();
   var dd = ThisDate.getDate();
   var mm = ThisDate.getMonth();
   var yyyy = ThisDate.getFullYear();   

   if (!DateFormat)
      DateFormat = "US";
      
   if (DateFormat == "US")  
      return (dow[day] + ", " + mmm[mm]  + " " + dd + ", " + yyyy)
   else
      return (dow[day] + ", " + dd + " " + mmm[mm]  + " " + yyyy)
            
}

// returns the full datetime in a standard format today
function Today_DateTime()
{
   var ThisDate = new Date();
   var dow = new Array("Sunday", "Monday", "Tuesday", "Wednesday","Thursday", "Friday","Saturday");   
   var mmm = new Array("January", "February", "March", "April","May", "June", "July", "August", "September", "October", "November", "December");   
   
   var day = ThisDate.getDay();
   var dd = ThisDate.getDate();
   var mm = ThisDate.getMonth();
   var yyyy = ThisDate.getFullYear();   
   var hrs = ThisDate.getHours();
   var mins = ThisDate.getMinutes();

   // patch
   if (mins < 10)
      mins = "0" + mins;
      
//      return ( mmm[mm]  + " " + dd + ", " + yyyy + " " + hrs + ":" + mins )
//      return ( dd + " " + mmm[mm]  + " " + yyyy + " " + hrs + ":" + mins)
      return ( mmm[mm]  + " " + dd + " "  + hrs + ":" + mins )
}

// returns the date in a standard format today
function Today_SQL(DateFormat)
{
   var ThisDate = new Date();
   var mmm = new Array("Jan", "Feb", "Mar", "Apr","May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");   
   
   var dd = ThisDate.getDate();
   var mm = ThisDate.getMonth();
   var yyyy = ThisDate.getFullYear();   

   if (!DateFormat)
      DateFormat = "US";

   if (DateFormat == "US")  
      return (mmm[mm] + " " + dd + " " + yyyy)
   else
      return (dd + " " + mmm[mm] + " " + yyyy)
            
}

// returns the date in a standard format incoming e.g. Mon Sept 20 2002
function FormatDate(ThisDate, DateFormat)
{
   var mmm = new Array("Jan", "Feb", "Mar", "Apr","May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");   
   var dd = ThisDate.getDate();
   var mm = ThisDate.getMonth();
   var yyyy = ThisDate.getFullYear();   

   if (!DateFormat)
      DateFormat = "US";

   if (DateFormat == "US")  
      return (mmm[mm] + " " + dd + " " + yyyy)
   else
      return (dd + " " + mmm[mm] + " " + yyyy)
}

// returns the date in a standard format incoming e.g. Mon Sept 20 2002
function FormatStartOfMonthDate(ThisDate, DateFormat)
{
   var mmm = new Array("Jan", "Feb", "Mar", "Apr","May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");   
   var dd = ThisDate.getDate();
   var mm = ThisDate.getMonth();
   var yyyy = ThisDate.getFullYear();   

   if (!DateFormat)
      DateFormat = "US";

   if (DateFormat == "US")  
      return (mmm[mm] + " 01 " + yyyy)
   else
      return ("01 " + mmm[mm] + " " + yyyy)
}



// fireup the client mail prog with the receiver email to
function Send_Email(EmailAddress)
{
   if (EmailAddress.length == 0)
      alert("Email address is blank");
   else
   {
      location.href = "mailto:" + EmailAddress;
   }
}


// open a new window with the SiteName
function Open_Web(SiteName)
{
   if (SiteName.length == 0)
      alert("WebSite is blank");
   else
   {
      window.open("http://" + SiteName);
   }
}

// tries to disable the back button effect
function NoHistory()
{
    location.replace(this.href); 
    event.returnValue=false; 
    event.cancelBubble=true;
}    

/*************** END JSCIPT.JS **********************************/

/* ----------------- rounded box -------------------------- */
function NiftyCheck(){
if(!document.getElementById || !document.createElement)
    return(false);
isXHTML=/html\:/.test(document.getElementsByTagName('body')[0].nodeName);
if(Array.prototype.push==null){Array.prototype.push=function(){
      this[this.length]=arguments[0]; return(this.length);}}
return(true);
}

function Rounded(selector,wich,bk,color,opt){
var i,prefixt,prefixb,cn="r",ecolor="",edges=false,eclass="",b=false,t=false;

if(color=="transparent"){
    cn=cn+"x";
    ecolor=bk;
    bk="transparent";
    }
else if(opt && opt.indexOf("border")>=0){
    var optar=opt.split(" ");
    for(i=0;i<optar.length;i++)
        if(optar[i].indexOf("#")>=0) ecolor=optar[i];
    if(ecolor=="") ecolor="#666";
    cn+="e";
    edges=true;
    }
else if(opt && opt.indexOf("smooth")>=0){
    cn+="a";
    ecolor=Mix(bk,color);
    }
if(opt && opt.indexOf("small")>=0) cn+="s";
prefixt=cn;
prefixb=cn;
if(wich.indexOf("all")>=0){t=true;b=true}
else if(wich.indexOf("top")>=0) t="true";
else if(wich.indexOf("tl")>=0){
    t="true";
    if(wich.indexOf("tr")<0) prefixt+="l";
    }
else if(wich.indexOf("tr")>=0){
    t="true";
    prefixt+="r";
    }
if(wich.indexOf("bottom")>=0) b=true;
else if(wich.indexOf("bl")>=0){
    b="true";
    if(wich.indexOf("br")<0) prefixb+="l";
    }
else if(wich.indexOf("br")>=0){
    b="true";
    prefixb+="r";
    }
var v=getElementsBySelector(selector);
var l=v.length;
for(i=0;i<l;i++){
    if(edges) AddBorder(v[i],ecolor);
    if(t) AddTop(v[i],bk,color,ecolor,prefixt);
    if(b) AddBottom(v[i],bk,color,ecolor,prefixb);
    }
}

function AddBorder(el,bc){
var i;
if(!el.passed){
    if(el.childNodes.length==1 && el.childNodes[0].nodeType==3){
        var t=el.firstChild.nodeValue;
        el.removeChild(el.lastChild);
        var d=CreateEl("span");
        d.style.display="block";
        d.appendChild(document.createTextNode(t));
        el.appendChild(d);
        }
    for(i=0;i<el.childNodes.length;i++){
        if(el.childNodes[i].nodeType==1){
            el.childNodes[i].style.borderLeft="1px solid "+bc;
            el.childNodes[i].style.borderRight="1px solid "+bc;
            }
        }
    }
el.passed=true;
}
    
function AddTop(el,bk,color,bc,cn){
var i,lim=4,d=CreateEl("b");

if(cn.indexOf("s")>=0) lim=2;
if(bc) d.className="artop";
else d.className="rtop";
d.style.backgroundColor=bk;
for(i=1;i<=lim;i++){
    var x=CreateEl("b");
    x.className=cn + i;
    x.style.backgroundColor=color;
    if(bc) x.style.borderColor=bc;
    d.appendChild(x);
    }
el.style.paddingTop=0;
el.insertBefore(d,el.firstChild);
}

function AddBottom(el,bk,color,bc,cn){
var i,lim=4,d=CreateEl("b");

if(cn.indexOf("s")>=0) lim=2;
if(bc) d.className="artop";
else d.className="rtop";
d.style.backgroundColor=bk;
for(i=lim;i>0;i--){
    var x=CreateEl("b");
    x.className=cn + i;
    x.style.backgroundColor=color;
    if(bc) x.style.borderColor=bc;
    d.appendChild(x);
    }
el.style.paddingBottom=0;
el.appendChild(d);
}

function CreateEl(x){
if(isXHTML) return(document.createElementNS('http://www.w3.org/1999/xhtml',x));
else return(document.createElement(x));
}

function getElementsBySelector(selector){
var i,selid="",selclass="",tag=selector,f,s=[],objlist=[];

if(selector.indexOf(" ")>0){  //descendant selector like "tag#id tag"
    s=selector.split(" ");
    var fs=s[0].split("#");
    if(fs.length==1) return(objlist);
    f=document.getElementById(fs[1]);
    if(f) return(f.getElementsByTagName(s[1]));
    return(objlist);
    }
if(selector.indexOf("#")>0){ //id selector like "tag#id"
    s=selector.split("#");
    tag=s[0];
    selid=s[1];
    }
if(selid!=""){
    f=document.getElementById(selid);
    if(f) objlist.push(f);
    return(objlist);
    }
if(selector.indexOf(".")>0){  //class selector like "tag.class"
    s=selector.split(".");
    tag=s[0];
    selclass=s[1];
    }
var v=document.getElementsByTagName(tag);  // tag selector like "tag"
if(selclass=="")
    return(v);
for(i=0;i<v.length;i++){
    if(v[i].className.indexOf(selclass)>=0){
        objlist.push(v[i]);
        }
    }
return(objlist);
}

function Mix(c1,c2){
var i,step1,step2,x,y,r=new Array(3);
if(c1.length==4)step1=1;
else step1=2;
if(c2.length==4) step2=1;
else step2=2;
for(i=0;i<3;i++){
    x=parseInt(c1.substr(1+step1*i,step1),16);
    if(step1==1) x=16*x+x;
    y=parseInt(c2.substr(1+step2*i,step2),16);
    if(step2==1) y=16*y+y;
    r[i]=Math.floor((x*50+y*50)/100);
    }
return("#"+r[0].toString(16)+r[1].toString(16)+r[2].toString(16));
} 

/* ----------------- end rounded box -------------------------- */

