function toUpper(inputid)
{
   inputid.value = inputid.value.toUpperCase();
}


function postcode_validation(del_postcode_value, allow_uk_postcodes)
{
   // returns -10 if valid format for North Ireland postcode, but the number part is invalid
   // returns -20 if valid format for Southern Ireland postcode, but the number part is invalid
   // returns -30 if invalid format for UK coverage postcodes
   // returns -99 regualr expression failed.

   var tmpstr = del_postcode_value;

   // Northern Ireland Postcodes are either BT1->BT99 or BT1 1AA to BT97 9ZZ
   var NIrelandPostcodeRegxp = /^([BT|bt]{2})([0-9]{1,2})([\s]{0,1})([0-9]{0,1})([A-Za-z]{0,2})$/
   // Southern Ireland Postcodes are either X1->X99. X or x
   var SIrelandPostcodeRegxp = /^([X|x]{1})([0-9]{1,2})$/

   var UKPostcodeRegxp = /^(TF|ST|DE|NG|WV|WS|WR|LE|DY|B|CV|NN|OX|MK|HP|LU|AL|SG)([0-9]{1,2})([\s]{0,1})([0-9]{0,1})([A-Za-z]{0,2})$/


   if (NIrelandPostcodeRegxp.test(tmpstr.toUpperCase()))
      {
         // valid format of a Northern ireland postcode.
         // Now we need to check if the numerical part of the postcode is between 1 and 97
         if (tmpstr.indexOf(' ') == -1)
            nums = tmpstr.slice(2); //slice from the 1st number to the end of the string
            else
            nums = tmpstr.slice(2, tmpstr.indexOf(' ')); //slice from the 1st number to the next space

         if ((nums > 0) && (nums <= 97))
            return true; //valid format, valid number.
         else
            return -10;  //valid format, but number part is either > 97 or <= 0
      }

   if (SIrelandPostcodeRegxp.test(tmpstr.toUpperCase()))
      {
         //valid format of a Sourthen ireland postcode.
         // Now we need to check if the numerical part of the postcode is between 1 and 26
         nums = tmpstr.slice(1); //slice from the 1st number to the end of the string
         if ((nums > 0) && (nums <= 26))
            return true; //valid format, valid number.
         else
            {
            return -20;  //valid format, but number part is either > 26 or <= 0
            }
      }

   if (allow_uk_postcodes == 'true')
      if (UKPostcodeRegxp.test(tmpstr.toUpperCase()))
         {
            // valid format of a UK postcode.
            return true;
         }
         else
           return -30;

   return -99;

}

//

function bookcollection_postcode_validation(postcode_value)
{
   // returns -10 if valid format for North Ireland postcode, but the number part is invalid
   // returns -20 if valid format for Southern Ireland postcode, but the number part is invalid
   // returns -30 if invalid format for UK coverage postcodes
   // returns -99 regualr expression failed.

   var tmpstr = postcode_value;

   // Northern Ireland Postcodes are either BT1->BT99 or BT1 1AA to BT97 9ZZ
   //var NIrelandPostcodeRegxp = /^([BT|bt]{2})([0-9]{1,2})([\s]{0,1})([0-9]{0,1})([A-Za-z]{0,2})$/
   // Southern Ireland Postcodes are either X1->X99. X or x
   //var SIrelandPostcodeRegxp = /^([X|x]{1})([0-9]{1,2})$/

   var UKPostcodeRegxp = /^(TF|ST|DE|NG|WV|WS|WR|LE|DY|B|CV|NN|OX|MK|HP|LU|AL|SG)([0-9]{1,2})([\s]{0,1})([0-9]{0,1})([A-Za-z]{0,2})$/

/*
   if (NIrelandPostcodeRegxp.test(tmpstr.toUpperCase()))
      {
         // valid format of a Northern ireland postcode.
         // Now we need to check if the numerical part of the postcode is between 1 and 97
         if (tmpstr.indexOf(' ') == -1)
            nums = tmpstr.slice(2); //slice from the 1st number to the end of the string
            else
            nums = tmpstr.slice(2, tmpstr.indexOf(' ')); //slice from the 1st number to the next space

         if ((nums > 0) && (nums <= 97))
            return true; //valid format, valid number.
         else
            return -10;  //valid format, but number part is either > 97 or <= 0
      }

   if (SIrelandPostcodeRegxp.test(tmpstr.toUpperCase()))
      {
         //valid format of a Sourthen ireland postcode.
         // Now we need to check if the numerical part of the postcode is between 1 and 26
         nums = tmpstr.slice(1); //slice from the 1st number to the end of the string
         if ((nums > 0) && (nums <= 26))
            return true; //valid format, valid number.
         else
            {
            return -20;  //valid format, but number part is either > 26 or <= 0
            }
      }

   if (allow_uk_postcodes == 'true')
*/
      if (UKPostcodeRegxp.test(tmpstr.toUpperCase()))
         {
            // valid format of a UK postcode.
            return true;
         }
         else
           return -30;

   return -99;

}



//
// IsNumeric();
//
function IsNumeric(sText)

{
   var ValidChars = "0123456789";
   var IsNumber=true;
   var Char;

   for (i = 0; i < sText.length && IsNumber === true; i++)
      {
      Char = sText.charAt(i);
      if (ValidChars.indexOf(Char) == -1)
         {
         IsNumber = false;
         }
      }

   return IsNumber;

   }


// converts 01/01/1980 to a dat obj
function datestr2dateobj(tmpstr)
{
   var tmp_year =  '';
   var tmp_month =  '';
   var tmp_day =  '';

   tmp_year = tmpstr.charAt(6) + tmpstr.charAt(7) + tmpstr.charAt(8) + tmpstr.charAt(9);
   tmp_month = tmpstr.charAt(3) + tmpstr.charAt(4);
   tmp_day = tmpstr.charAt(0) + tmpstr.charAt(1);


   //tmp_year = parseInt(tmp_year);
   //tmp_month = parseInt(tmp_month);
   //tmp_day = parseInt(tmp_day);


   var tmpdate = new Date();
   tmpdate.setFullYear(tmp_year,tmp_month - 1,tmp_day); // month 0 indexed array. ie Jan = 0, Feb = 1 etc

   return tmpdate;
}

function validate_coll_date(datefieldvalue)
{

   // convert date str to object.
   //var dateobj_coll = new Date(); // FF wants dateobj_coll given a type before assignment. IE doesn't!
   var dateobj_coll = datestr2dateobj(datefieldvalue);
   dateobj_coll.setHours(0);
   dateobj_coll.setMinutes(0);
   dateobj_coll.setSeconds(0);

   // get date object for now, right this second
   var dateobj_now = new Date();
   dateobj_now.setHours(0);
   dateobj_now.setMinutes(0);
   dateobj_now.setSeconds(0);

   // set grace period
   var dateobj_grace = new Date();
   dateobj_grace.setDate(dateobj_now.getDate()+14);
   dateobj_grace.setHours(0);
   dateobj_grace.setMinutes(0);
   dateobj_grace.setSeconds(0);

   //date in the past
   if (dateobj_coll < dateobj_now)
      {
      return -1;
      }

   //date in the future more than 14days
   if (dateobj_coll > dateobj_grace)
      {
      return -2;
      }

    //date is a weekend
    if (dateobj_coll.getDay() == 0 || dateobj_coll.getDay() == 6)
      {
      return -3;
      }

   return true;
}

function validate_bookcollection_date(datefieldvalue)
{

   // convert date str to object.
   //var dateobj_coll = new Date(); // FF wants dateobj_coll given a type before assignment. IE doesn't!
   var dateobj_coll = datestr2dateobj(datefieldvalue);
   dateobj_coll.setHours(0);
   dateobj_coll.setMinutes(0);
   dateobj_coll.setSeconds(0);

   // get date object for now, right this second
   var dateobj_now = new Date();
   dateobj_now.setHours(0);
   dateobj_now.setMinutes(0);
   dateobj_now.setSeconds(0);


   // set grace period
   var dateobj_grace = new Date();
   dateobj_grace.setDate(dateobj_now.getDate()+7);
   dateobj_grace.setHours(0);
   dateobj_grace.setMinutes(0);
   dateobj_grace.setSeconds(0);

   //date in the past
   if (dateobj_coll < dateobj_now)
      {
        return -1;
      }

   //date in the future more than 7days
   if (dateobj_coll > dateobj_grace)
      {
      return -2;
      }

    //date is a weekend
    if (dateobj_coll.getDay() == 0 || dateobj_coll.getDay() == 6)
      {
      return -3;
      }
   //date is today
   if (dateobj_coll.toString() == dateobj_now.toString())
      {
      return -4;
      }

   return true;
}