
////////////////////////////////////////////////////////////////////////////////////////
// Functions to calculate filename and return it to variable so it can be validated ....
////////////////////////////////////////////////////////////////////////////////////////

function populate_file_short_name(oform, oimgfile)
{
   var full_path = oimgfile;
   var shortname = oform[imgfile_shortname];

   // if the field is empty - do nothing.
   if (full_path == "")
   {
      shortname.value= " ";
   }
   else
   {
      var full_path_array=full_path.split("/");
      var part_num=0;
      while (part_num < full_path_array.length)
      {
         part_num+=1;
      }
      shortname.value=(full_path_array[part_num]);
   }

}

// Function     : detect_direct_load
// how to call  : <BODY onLoad="detect_direct_load()">
// Comments     :
// Function called from all body elements to ensure pages are called within correct frames.

function detect_direct_load()
{
   framesetpage="index.php";
   thispage=window.location.href;
   if (thispage.indexOf('://')<0) {thispage="://"+thispage;};
   prefix=thispage.substring(0,thispage.lastIndexOf('://'));
   suffix=thispage.substring(thispage.lastIndexOf('://')+3,thispage.length);
   // alert('the subpage is:['+prefix+']['+suffix+']');
   if (parent.location.href==window.location.href) {parent.location.href=framesetpage+"?"+prefix+"&&&"+suffix};
}

// Function     : Various
// how to call  : Called from menu systems
// Comments     :
// Function called from all navigation screens to control display of menu items.

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v3.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function MM_displayStatusMsg(msgStr) { //v1.0
  status=msgStr;
  document.MM_returnValue = true;
}

/***********************************************
* Bookmark site script- © Dynamic Drive DHTML code library (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit Dynamic Drive at http://www.dynamicdrive.com/ for full source code
***********************************************/

function add_to_favourites(title, url){
if (document.all)
window.external.AddFavorite(url, title);
else if (window.sidebar)
window.sidebar.addPanel(title, url, "")
}

///////////////////////////////////////////////////////
// Function : checkscreensize
// If screen resolution is under minimum give a "suggestion" on each main page.

function checkscreensize() {

var minwidth=1024
var minheight=768
if (screen.width<minwidth||screen.height<minheight)
document.write("<P width='80%'><CENTER><B><I>This webpage is bested viewed with a screen resolution of "+minwidth+"*"+minheight+
" or higher.Your current resolution is "+screen.width+"*"+screen.height+" which will make some of the pages difficult to read."+
" If possible, please change the resolution!</I></B></CENTER></P>")
}

function getresolutionheight()
{
var currheight= screen.height;
return currheight;
}

function getresolutionwidth()
{
var currwidth= screen.width;
return currwidth;
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Function : show_large_image
// Give a large view of selected image in new window without normal browser toolbars.
// Function will calculate the center of the screen and place image in central location.
// Currently expects 640 by 480 image.
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////

function show_large_image(image_name)
{

if (document.all)
  var xMax = screen.width, yMax = screen.height;
else
  if (document.layers)
     var xMax = window.outerWidth, yMax = window.outerHeight;
  else
     var xMax = 640, yMax=480;

var xOffset = (xMax - 640)/2, yOffset = (yMax - 480)/2;

window.open (image_name, 'large_picture', config='width=640,height=480,screenX='+xOffset+',screenY='+yOffset+',top='+yOffset+',left='+xOffset+',toolbar=no,menubar=no,hotkeys=no,scrollbars=no,resizable=no,location=no,directories=no,status=no,channelmode=no')
}


//////////////////////////////////////////////////////////////////////////////////////////////////
// Function : trim_field
// trims leading and trailing spaces from a field.
//////////////////////////////////////////////////////////////////////////////////////////////////

function trim_xxx(str)
{
    return str.replace(/(^\s+)([^\s]*)(\s+$)/, '$2');
}

function trim_field(s) {
  while (s.substring(0,1) == ' ') {
    s = s.substring(1,s.length);
  }
  while (s.substring(s.length-1,s.length) == ' ') {
    s = s.substring(0,s.length-1);
  }
  return s;
}

//////////////////////////////////////////////////////////////////////////////////
// Functions for formatting numeric / money fields
//////////////////////////////////////////////////////////////////////////////////
function Round(number, precision)
{ 
   number=parseFloat( number) + 0.5 * Math.pow(10, -precision); 
   number = Math.floor(number * Math.pow(10, precision));
   var res = (number * Math.pow(10, -precision)).toFixed(precision); 
   if (res.charAt(0) == ".") 
   {
      res = "0" + res; 
   }
   return parseFloat(res);
}

function formatAsMoney(ObjVal)
{
 //Obj.value = formatAsMny(Obj.value)
 mnt = ObjVal;
 mnt -= 0;
 mnt = (Math.round(mnt*100))/100;
 ObjVal = (mnt == Math.floor(mnt)) ? mnt + '.00' : ( (mnt*10 == Math.floor(mnt*10)) ? mnt + '0' : mnt);
 if (isNaN(ObjVal)) {ObjVal ="0.00";}
 return ObjVal;
}
//////////////////////////////////////////////////////////////////////////////////
// Functions for formatting / manipulating dates
//////////////////////////////////////////////////////////////////////////////////

function calc_offset_date(startdate, offset)
{
 //Obj.value = formatAsMny(Obj.value)
 startdate = startdate;
 offset    = offset;
 newdate   = setdate(startdate + offset);
 return newdate;
}
function addDays(myDate,days) {
    CalculatedDate = Date(myDate.getTime() + (days*24*60*60*1000));
    return CalculatedDate; 	
}

////////////////////////////////////////////////////////////////////////////////
// Proper case conversion
///////////////////////////////////////////////////////////////////////////////
 
function OLDProperCase(s) 
{ 
   return s.replace(/(\w)(\w*)/g,function 
   ( 
        strMatch, 
        strFirst, 
        strRest, 
        intMatchPos, 
        strSource 
    ) 
    { 
        return strFirst.toUpperCase() 
        +strRest.toLowerCase(); 
    }); 
} 
// This routine will deal with surnames such as MacDonald, McDonald etc..
function ProperCase(s)  
{  
   return s.toLowerCase().replace( /\b((m)(a?c))?(\w)/g,    
      function($1, $2, $3, $4, $5) 
		{ if($2){return $3.toUpperCase()+$4+$5.toUpperCase();}      
	      return $1.toUpperCase();  
        }
   );
} 

function copy_to_clipboard(text)   
  {   
      if(window.clipboardData)   
      {   
      window.clipboardData.setData('text',text);   
      }   
      else   
      {   
          var clipboarddiv=document.getElementById('divclipboardswf');   
      if(clipboarddiv==null)   
      {   
         clipboarddiv=document.createElement('div');   
             clipboarddiv.setAttribute("name", "divclipboardswf");   
         clipboarddiv.setAttribute("id", "divclipboardswf");   
         document.body.appendChild(clipboarddiv);   
      }   
          clipboarddiv.innerHTML='<embed src="clipboard.swf" FlashVars="clipboard='+   
  encodeURIComponent(text)+'" width="0" height="0" type="application/x-shockwave-flash"></embed>';   
      }   
      alert('The text is copied to your clipboard...');   
      return false;   
  } 


//////////////////////////////////////////////////////////////////////////////////
// Functions for PRINTING
//////////////////////////////////////////////////////////////////////////////////

