function compareOptionValues(a, b) 
{ 

  // Radix 10: for numeric values
  // Radix 36: for alphanumeric values

  var sA = parseInt( a.value, 10 );  
  var sB = parseInt( b.value, 10 );  
  return sA - sB;

}


function hasSpaces(s) {
    containsSpaces = false;
    for (i=0; i < s.length; i++){
        if (s.charAt(i) == " "){
            containsSpaces = true;
            break;
        }
    }
     return (containsSpaces);
}


// Compare two options within a list by TEXT

function compareOptionText(a, b) 
{ 

  // Radix 10: for numeric values
  // Radix 36: for alphanumeric values

  var sA = parseInt( a.text, 36 );  
  var sB = parseInt( b.text, 36 );  
  return sA - sB;

}



// Dual list move function

function moveDualList(direction,moveAll ) 

{

  if (direction == "add")
  {
        srcList  = form0.listLeft;
        destList = form0.listRight;
  }
  else
  {
        srcList  = form0.listRight;
        destList = form0.listLeft;
  }


  // Do nothing if nothing is selected

  if (( srcList.selectedIndex == -1 ) && ( moveAll == false ))
  {
    return;
  }



  newDestList = new Array( destList.options.length );
  var len = 0;

  for( len = 0; len < destList.options.length; len++ ) 
  {
    if ( destList.options[ len ] != null )
    {
      newDestList[ len ] = new Option( destList.options[ len ].text, destList.options[ len ].value, destList.options[ len ].defaultSelected, destList.options[ len ].selected );
    }
  }



  for( var i = 0; i < srcList.options.length; i++ ) 
  { 
    if ( srcList.options[i] != null && ( srcList.options[i].selected == true || moveAll ) )
    {
       // Statements to perform if option is selected
       // Incorporate into new list
       newDestList[ len ] = new Option( srcList.options[i].text, srcList.options[i].value, srcList.options[i].defaultSelected, srcList.options[i].selected );
       len++;
    }
  }



  // Sort out the new destination list
//  newDestList.sort( compareOptionValues );   // BY VALUES
newDestList.sort( compareOptionText );   // BY TEXT
  // Populate the destination with the items from the new array

  for ( var j = 0; j < newDestList.length; j++ ) 
  {
    if ( newDestList[ j ] != null )
    {
      destList.options[ j ] = newDestList[ j ];
    }
  }



  // Erase source list selected elements
  for( var i = srcList.options.length - 1; i >= 0; i-- ) 
  { 
    if ( srcList.options[i] != null && ( srcList.options[i].selected == true || moveAll ) )
    {
       // Erase Source
       //srcList.options[i].value = "";
       //srcList.options[i].text  = "";
       srcList.options[i]       = null;
    }
  }



} // End of moveDualList()
function DoInfo(infoid) 
{
        remote = window.open("","sub1","width=400,height=250,status=no,directories=no,location=no,menubar=no,resizable=no,scrollbars=auto,toolbar=no");
                remote.location.href = "http://www.generalmedical.co.uk/cgi-bin//info.cgi?infoid="+infoid;
                if (remote.opener == null) remote.opener = window;
                remote.opener.name = "opener";
        remote.focus();
}

function DoUnCheckedSubmit() 
{
        document.form0.submit(); 
}

function imageChange(imageID1,FileName1) 
{
        document.images[imageID1].src = "http://www.birdcollege.co.uk/images/" + FileName1;
}

function isEmpty(s)
{   
   return ((s == null) || (s.length == 0))
}


function isNumeric(s)

{   
    var i;

    var reNumeric = /^[0-9. ]+$/

    if (isEmpty(s))
       if (isNumeric.arguments.length == 1) return false;
       else return (isNumeric.arguments[1] == true);

    else 
    {
       return reNumeric.test(s)
    }
} 

function isAlphanumeric (s)
{   
    var i;
    var reAlphanumeric = /^[a-z0-9]+$/

    if (!isEmpty(s))
    { 
        return reAlphanumeric.test(s)
    }
    return true;
}


function isAlpha (s)
{   
    var i;
    var reAlpha = /^[a-zA-Z]+$/

    if (!isEmpty(s)) 
    {
       return reAlpha.test(s)
    }
    return true;
}

//---------------------------------------------------------------
function isValid(field) 
{
   var reValid = /^[a-zA-Z0-9-_.@' ]+$/;
    if (!isEmpty(field))
    {
        return reValid.test(field)
    }
    return true;
}
//---------------------------------------------------------------- 
function isemailValid(field) 
{
   var reValid = /^[a-zA-Z0-9-_.@ ]+$/;
    if (!isEmpty(field))
    {
       return reValid.test(field)
    }
    return true;
} 
function formatCurrency(num) 
{
   num = num.toString().replace(/$|,/g,'');
   if(isNaN(num)) num = "0";
   cents = Math.floor((num*100+0.5)%100);
   num   = Math.floor((num*100+0.5)/100).toString();
   if(cents < 10) cents = "0" + cents;
   for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
   num = num.substring(0,num.length-(4*i+3))+num.substring(num.length-(4*i+3));
   return (num + "." + cents);
}

//function for returning how many days there are in a month including leap years
function DaysInMonth(WhichMonth, WhichYear)
{
  var DaysInMonth = 31;
  if (WhichMonth == "4" || WhichMonth == "6" || WhichMonth == "9" || WhichMonth == "11") DaysInMonth = 30;
  if (WhichMonth == "2" && (WhichYear/4) != Math.floor(WhichYear/4))    DaysInMonth = 28;
  if (WhichMonth == "2" && (WhichYear/4) == Math.floor(WhichYear/4))    DaysInMonth = 29;
  return DaysInMonth;
}

function DoReload() 
{
        document.form0.reset(); 
}

function DoCheckedSubmit() 
{
        if (formCheck())
        {
                document.form0.submit(); 
        }
}

// swap fields
function swap(hideobj,showobj) {
        hidenon(hideobj)
        shownon(showobj)
}
// Show/Hide functions for non-pointer layer/objects
function shownon(showobj) {
        if (isNS4) document.layers[showobj].visibility = "show"
        else if (isIE4) document.all[showobj].style.visibility = "visible"
        else if (isIE5 || isNS6) 
        {
                elm = document.getElementById(showobj);
                elm.style.visibility = "visible";
        }
}
function hidenon(hideobj) {
        if (isNS4) document.layers[showobj].visibility = "hide"
        else if (isIE4) document.all[showobj].style.visibility = "hidden"
        else if (isIE5 || isNS6) 
        {
                elm = document.getElementById(hideobj);
                elm.style.visibility = "hidden";
        }
}

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_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_findObj(n, d) { //v4.01
  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);
  if(!x && d.getElementById) x=d.getElementById(n); 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];}
}
