/*_ep00*/

function printWindow(obj){
  obj.print();
}

function submitTrolley(form,trolleyType){
  form.submit();
}


function processTrolleyItem(form,type){
  form.tri_type.value = type;
  form.submit();
}

/*---- e005_genJS.js ------- START ------- */


// whitespace characters
var whitespace = " \t\n\r";


//Check whether string s is empty.
function isEmpty(s){
  return ( (s == null) || (s.length == 0) );
}


// Returns true if string s is empty or
// whitespace characters only.
function isWhitespace(s){
  // Is s empty?
  if ( isEmpty(s) )
    return true;

  // Search through string's characters one by one
  // until we find a non-whitespace character.
  // When we do, return false; if we don't, return true.

  for ( var i=0; i<s.length; i++ ){
    // Check that current character isn't whitespace.
    var c = s.charAt(i);

    if ( whitespace.indexOf(c) == -1 )
      return false;
  }

  // All characters are whitespace.
  return true;
}


// Check whether string field is number.
function isNumber(value){
  myReint = /\D/;
  return myReint.test(value);
}


// Displays an alert box with the passed in string...
function promptErrorMsg(field,showFieldName,strError){
  alert("You have entered an invalid value for " + showFieldName + ".\n" + strError);
  eval(field).focus();
}


function checkForceMoney(form,field,display){
  var formName="document." + form;
  var fieldName="document." + form + "." + field;

  return ForceMoney(eval(fieldName),display);
}


// Returns true if the string passed in is a valid money
// (no alpha characters except a decimal place),
// else it displays an error message
function ForceMoney(objField, FieldName){
  var strField = new String(objField.value);

  if ( isWhitespace(strField) ){
    alert("You need to enter information for ( " + FieldName + " ) as this is a required field.");
    objField.focus();
    return false;
  }

  for ( var i=0; i<strField.length; i++ ){
    if ( (strField.charAt(i) < '0' || strField.charAt(i) > '9') && (strField.charAt(i) != '.') && (strField.charAt(i) != '-') ){
      alert(FieldName + " must be a valid numeric entry. Please do not use commas or dollar signs or any non-numeric symbols.");
      objField.focus();
      return false;
    }
  }

  return true;
}


// Checks to see if a required field is blank.  If it is, a warning  message is displayed...
function checkForceEntry(form,field,display){
  var formName = "document." + form;
  var fieldName = "document." + form + "." + field;

  if ( eval(fieldName) )
    return ForceEntry(eval(fieldName),display);

  return true;
}


// Checks to see if a required field is blank.  If it is, a warning message is displayed...
function ForceEntry(objField, FieldName){
  var strField = objField.value;

  if ( isWhitespace(strField) ){
    alert("You need to enter information for ( " + FieldName + " ) as this is a required field.");
    objField.focus();
    return false;
  }

  return true;
}


//For use with any telephone numbers
function SYMBOL_CHECK(TheObjValue){
  var lengthof = TheObjValue.length;

  if ( TheObjValue.match(/[\$$\*'`~!#%^_&\)\(\{\}\]\[\";:?<>,+=]/) ){
    return true;
  }

  if ( TheObjValue.match(/[a-z]/) ){
    return true;
  }

  if ( TheObjValue.match(/[A-Z]/) ) {
    return true;
  }

  return false;
}


function checkForceNumber(form,field,display){
  var formName = "document." + form;
  var fieldName = "document." + form + "." + field;
  var value = eval(fieldName).value;

  if ( !ForceNumber(value,display) ){
    eval(fieldName).focus();
    return false;
  }

  return true;
}


function ForceNumber(value, FieldName){
  if ( isNumber(value) ){
    alert("You need to enter only Numbers for ( " + FieldName + " ).");
    return false;
  }

  return true;
}


function isValidCCExpiry(month,year){
  var today = new Date();
  var todayMonth = today.getMonth() + 1; //starts from 0
  var todayYear  = today.getYear() + ""; //convert to string

  // should get the last two digits of the returned year as netscape and ie are not returing the same values
  var length = todayYear.length;
  var todayYear = todayYear.substring( length, 2);
  var todayYear = eval(todayYear); //convert to integer

  var monthInteger = month.selectedIndex;
  var monthValue   = month.options[monthInteger].value;

  var yearInteger = year.selectedIndex;
  var yearValue   = year.options[yearInteger].value;
  //alert(todayMonth + '/' + todayYear + ' ----- ' + monthValue + '/' + yearValue);

  if ( (yearValue < todayYear) || ((yearValue == todayYear) && (monthValue < todayMonth)) ){
    alert('Your Credit Card has been expired.\nPlease select a valid Expiry Date.');
    month.focus();
    return false;
  } else{
    return true;
  }
}


function checkPasswordsSame(form,password1,password2){
  var formName = "document." + form;
  var fieldName1 = "document." + form + "." + password1;
  var fieldName2 = "document." + form + "." + password2;
  var value1 = eval(fieldName1).value;
  var value2 = eval(fieldName2).value;

  if ( value1 != value2 ){
    alert("Your passwords are not the same.");
    eval(fieldName1).focus();
    return false;
  }

  return true;
}


//validating a image
function validateImage(file_location){
  var regexp = /\.(gif|jpg|jpeg|bmp)$$/i;
  var resultArray = (eval(file_location).value).match(regexp);

  if ( !resultArray ){
    promptErrorMsg(file_location,'File Location','Please select only GIF, JPG, JPEG or BMP images.');
    return false;
  }

  return true;
}


function giveMeTrue(){
  return true;
}


function ForcePhoneNumbers(objField,type,phone_type){
  var value = objField.value;

  //required number or filled optional number
  if ( (type == "RN") || ((type == 'ON') && (value != '')) ){
    if ( isNumber(value) ){
      alert("Phone, Fax and Mobile should be only numbers - Digits [0-9] has to be entered.");
      objField.focus();
      return false;
    }

    if ( value.length != 10 ){
      alert("Phone,Fax and Mobile Numbers should be 10 digits.");
      objField.focus();
      return false;
    }
  }

  return true;
}


function checkForcePhoneNumbers(form,field,type,phone_type){
  var fieldName = "document." + form + "." + field;

  if ( !ForcePhoneNumbers(eval(fieldName),type,phone_type) ){
    return false;
  }

  return true;
}


function ForceCountryPhoneNumbers(objField,type,phone_type,countryField){
  var value = objField.value;

  if ( (countryField.value == '049') || (countryField.value == '041') || (countryField.value == '031') ){
    //allowed to have 6 - 15 numbers

    //required number or filled optional number
    if ( (type == "RN") || ((type == 'ON') && (value != '')) ){
      if ( isNumber(value) ){
        alert("Phone, Fax and Mobile should be only numbers - Digits [0-9] has to be entered.");
        objField.focus();
        return false;
      }

      if ( value.length < 6 ){
        alert("Phone,Fax and Mobile Numbers should be at least 6 digits.");
        objField.focus();
        return false;
      }
    }
  } else{
    if ( !ForcePhoneNumbers(objField,type,phone_type) ){
      return false;
    }
  }

  return true;
}


function checkForceCountryPhoneNumbers(form,field,type,phone_type,countryField){
  var fieldName = "document." + form + "." + field;
  var countryFieldName = "document." + form + "." + countryField;

  if ( !ForceCountryPhoneNumbers(eval(fieldName),type,phone_type,eval(countryFieldName)) ){
    return false;
  }

  return true;
}


//Loads the previous URL in the history list
function back(){
  history.go(-1);
}


function ForceEmail(field, FieldName){
  if ( !isValidEmail(field.value) ){
    alert("You need to enter valid Email Address for ( " + FieldName + " ).");
    field.focus();
    return false;
  }

  return true;
}


function isValidEmail(s){
  // is s whitespace?
  if ( s == '' )
    return false;

  // there must be >= 1 character before @ , so we start looking at character position 1 (i.e. second character)
  var i = 1;
  var sLength = s.length;

  // look for @
  while ( (i < sLength) && (s.charAt(i) != "@") ){
    i++
  }

  if ( (i >= sLength) || (s.charAt(i) != "@") )
    return false;
  else
    i += 2;

  // look for .
  while ( (i < sLength) && (s.charAt(i) != ".") ){
    i++
  }

  // there must be at least one character after the .
  if ( (i >= sLength - 1) || (s.charAt(i) != ".") )
    return false;
  else
    return true;
}


function validateDateTime(field,display){
  var datetime = field.value;
  if ( datetime.length != 19 ){
    alert('( ' +display +' ) is invalid. Length is not correct.');
    field.focus();
    return false;
  }

  var year = datetime.substr(0,4);
  if ( isNumber(year) ){
    alert('Year in ( ' +display+ ' ) is invalid. Not a number.');
    field.focus();
    return false;
  }
  if ( (year < 1700) || (year > 3000) ){
    alert('Year in ( ' +display+ ' ) is invalid. Too big or small.');
    field.focus();
    return false;
  }

  if ( datetime.substr(4,1) != '-' ){
    alert('Year-Month separator in ( ' +display+ ' ) is invalid.\nPlease enter -');
    field.focus();
    return false;
  }

  var month = datetime.substr(5,2);
  if ( isNumber(month) ){
    alert('Month in ( ' +display+ ' ) is invalid. Not a number.');
    field.focus();
    return false;
  }
  if ( (month < 1) || (month > 12) ){
    alert('Month in ( ' +display+ ' ) is invalid. Too big or small.');
    field.focus();
    return false;
  }

  if ( datetime.substr(7,1) != '-' ){
    alert('Month-Day separator in ( ' +display+ ' ) is invalid.\nPlease enter -');
    field.focus();
    return false;
  }

  var day = datetime.substr(8,2);
  if ( isNumber(day) ){
    alert('Day in ( ' +display+ ' ) is invalid. Not a number.');
    field.focus();
    return false;
  }
  if ( (day < 1) || (day > 31) ){
    alert('Day in ( ' +display+ ' ) is invalid. Too big or small.');
    field.focus();
    return false;
  }

  if ( datetime.substr(10,1) != ' ' ){
    alert('Date-Time separator in ( ' +display+ ' ) is invalid.\nPlease enter space.');
    field.focus();
    return false;
  }


  var hour = datetime.substr(11,2);
  if ( isNumber(hour) ){
    alert('Hour in ( ' +display+ ' ) is invalid. Not a number.');
    field.focus();
    return false;
  }
  if ( hour > 23 ){
    alert('Hour in ( ' +display+ ' ) is invalid. Too big.');
    field.focus();
    return false;
  }

  if ( datetime.substr(13,1) != ':' ){
    alert('Hour-Minute separator in ( ' +display+ ' ) is invalid.\nPlease enter :');
    field.focus();
    return false;
  }

  var minute = datetime.substr(14,2);
  if ( isNumber(minute) ){
    alert('Minute in ( ' +display+ ' ) is invalid. Not a number.');
    field.focus();
    return false;
  }
  if ( minute > 59 ){
    alert('Minute in ( ' +display+ ' ) is invalid. Too big.');
    field.focus();
    return false;
  }

  if ( datetime.substr(16,1) != ':' ){
    alert('Minute-Second separator in ( ' +display+ ' ) is invalid.\nPlease enter :');
    field.focus();
    return false;
  }

  var second = datetime.substr(17,2);
  if ( isNumber(second) ){
    alert('Second in ( ' +display+ ' ) is invalid. Not a number.');
    field.focus();
    return false;
  }
  if ( second > 59 ){
    alert('Second in ( ' +display+ ' ) is invalid. Too big.');
    field.focus();
    return false;
  }

  return true;
}


function Trim(inputString){
  return LTrim(RTrim(inputString));
}


function LTrim(inputString){
  return inputString.replace(/^\s+/,'');
}


function RTrim(inputString){
  return inputString.replace(/\s+/,'');
}


/*END_ep00*/
