//Print page Functions

   function printWindow(){
     removeElements()
     var result = confirm("Print Page");
       if(result == true){
         window.print();
       }else{
         return false;
       }
   }
    
    function removeElements(){
      //store all elements with id_remove to remove_el
      var remove_el=document.all.remove;
      if(remove_el!=' ' && remove_el.length==null){
        remove_el.style.display='none';
      }else{
        for(i=0; i<remove_el.length;i++){
          remove_el[i].style.display='none';
        }
      }
     }

    function revertBack(){
      //window.location.reload()
      //setTimeout("window.location.reload()",50)
      location = "/cgi-bin/holidaySearch.cgi?username=admin&password=admin";
    }

   window.onbeforeprint=removeElements;

//End of print page functions


//Get archive year for log on page
function getArchiveYear(){
  var today = new Date(); 
  var day = today.getDate();
  if(day < 10){
    day = "0" +day;
  }
  var month = today.getMonth()+1;
  if(month < 10){
    month = "0" +month;
  }

  var year = today.getFullYear();
  var logonDate = day +"-" +month +"-" +year;
  document.holidaySearch.entitlementYrNo.value = logonDate;
}

//#####Functions to detect change on update page
function changefName(form){

  var firstName = document.updateMember.firstName.value;

	if(firstName == ""){
		alert('Please enter first name');
		document.updateMember.firstName.focus();
		return false;
	}

  var firstNameOld = document.updateMember.firstNameOld.value;
  //#####Get the reason for change
  var reasonfName = prompt("Enter reason for first name change" +'\n' +'Click "OK", then click "Update Team Member Details" button to Save',"");
  //#####While the reason has not been entered
  while(reasonfName == ""){
    reasonfName = prompt("A reason for the change is required","");
  }
  //#####If reason is null update has been cancelled
  if(reasonfName == null){
    alert('        You have cancelled this change.' +'\n'  +'\n' +'The database will not be updated with new value');
    //#####Populate the text box with old value
    document.updateMember.firstName.value = firstNameOld;
    document.updateMember.firstName.focus();
    return false;
  }else{
    //#####else write values to form
	reasonfName = reasonfName.replace(/\W/ig, ' ');	  
    document.updateMember.reasonfNameChange.value = reasonfName;
    document.updateMember.fNameChange.value = 6;
    document.updateMember.ifChange.value = "yes";
    return true;
  }//#####end if else
}

function changeSurname(form){

  var surname = document.updateMember.surname.value;

  if(surname == ""){
    alert('Please enter surname');
    document.updateMember.surname.focus();
    return false;
  }

  var surnameOld = document.updateMember.surnameOld.value;
  var reasonSurname = prompt("Enter reason for surname change" +'\n' +'Click "OK", then click "Update Team Member Details" button to Save',"");
  while(reasonSurname == ""){
    reasonSurname = prompt("A reason for the surname change is required","");
  }
  if(reasonSurname == null){
    alert('        You have cancelled this change.' +'\n'  +'\n' +'The database will not be updated with new surname value');
    document.updateMember.surname.value = surnameOld;
    document.updateMember.firstName.focus();
    return false;
  }else{
	reasonSurname = reasonSurname.replace(/\W/ig, ' ');
	document.updateMember.reasonSurnameChange.value = reasonSurname;
    document.updateMember.surnameChange.value = 7;
    document.updateMember.ifChange.value = "yes";
    return true;
  }
}

function changeEmail(form){
  var userName = document.updateMember.userName.value;
  var userNameOld = document.updateMember.userNameOld.value;  
	
 	if(userName == ""){
		alert('Please re-enter e-Mail address');
        document.updateMember.userName.focus();
		return false;
	}

     testForAt  = userName.indexOf("@");
     testForDot = userName.indexOf(".");

     if((testForAt == -1) || (testForDot == -1)){
       alert('Please enter correctly formated user eMail');
	   document.updateMember.userName.focus();
       document.updateMember.userName.select();
       return false; 
     }	
	 
     var reasonUserName = prompt("Enter reason for email change" +'\n' +'Click "OK", then click "Update Team Member Details" button to Save',"");
     while(reasonUserName == ""){
       reasonUserName = prompt("A reason for the email change is required","");
     }
     if(reasonUserName == null){
       alert('        You have cancelled this change.' +'\n'  +'\n' +'The database will not be updated with new value');
       document.updateMember.userName.value = userNameOld;
       document.updateMember.userName.focus();
       return false;
     }else{
       reasonUserName = reasonUserName.replace(/\W/ig, ' ');
       document.updateMember.reasonUserNameChange.value = reasonUserName;
       document.updateMember.userNameChange.value = 24;
       document.updateMember.ifChange.value = "yes";
       return true;
     }	 
}//end function changeEmail(form)

function changeDays(form){

  var standardDaysIn     = document.updateEntitlement.standardDaysIn.value;
  var benefitDaysIn      = document.updateEntitlement.benefitDaysIn.value;
  var standardDaysOld    = document.updateEntitlement.standardDaysOld.value;
  var benefitDaysOld     = document.updateEntitlement.benefitDaysOld.value;
  var returnStandardDays = "false";
  var returnBenefitDays  = "false";

	if(standardDaysIn == ""){
		alert('Please enter entitlement days due');
        document.updateEntitlement.standardDaysIn.value = 0;
		document.updateEntitlement.standardDaysIn.focus();
		return false;
	}

	if(isNumeric(standardDaysIn) == false){
		alert('Entitlement days due must be numeric');
        document.updateEntitlement.standardDaysIn.value = 0;
		document.updateEntitlement.standardDaysIn.focus();
		return false;
      }

	if(benefitDaysIn == ""){
		alert('Please enter benefit days due');
        document.updateEntitlement.benefitDaysIn.value = 0;
		document.updateEntitlement.benefitDaysIn.focus();
		return false;
	}

	if(isNumeric(benefitDaysIn) == false){
		alert('Benifit days due must be numeric');
        document.updateEntitlement.benefitDaysIn.value = 0;
		document.updateEntitlement.benefitDaysIn.focus();
		return false;
      }

  if(standardDaysIn != 0){
    var reasonEntDays = prompt("Reason for entitlement change" +'\n' +'Click "OK", then click "Update Holiday Details" button to Save',"");
    while(reasonEntDays == ""){
      reasonEntDays = prompt("A reason for entitlement change is required","");
    }//end while

    if(reasonEntDays == null){
      alert('        You have cancelled this holiday change.' +'\n'  +'\n' +'The database will not be updated with new value');
      document.updateEntitlement.standardDays.value = standardDaysOld;
      document.updateEntitlement.standardDays.focus();
      return false;
    }else{
      returnStandardDays = "true";
    }//end if else

  }//end if

  if(benefitDaysIn != 0){
    var reasonBenefitDays = prompt("Reason for benefit days change" +'\n' +'Click "OK", then click "Update Holiday Details" button to Save',"");
    while(reasonBenefitDays == ""){
      reasonBenefitDays = prompt("A reason for benefit days change is required","");
    }//end while
  
    if(reasonBenefitDays == null){ 
      alert('        You have cancelled this benefit change.' +'\n'  +'\n' +'The database will not be updated with new value');
      document.updateEntitlement.benefitDays.value = benefitDaysOld;
      document.updateEntitlement.benefitDays.focus();
      return false;
    }else{
      returnBenefitDays = "true";
    }//end if else

  }//end if

  if(returnStandardDays == "true" && returnBenefitDays  == "true"){
	reasonBenefitDays = reasonBenefitDays.replace(/\W/ig, ' ');
	document.updateEntitlement.reasonBenefitDaysChange.value = reasonBenefitDays;
    document.updateEntitlement.benefitDaysChange.value = 10;
    document.updateEntitlement.reasonEntDaysChange.value = reasonEntDays;
    document.updateEntitlement.standardDaysChange.value = 8;
    document.updateEntitlement.ifChange.value = "yes";
    return true;
  }else if(returnStandardDays == "true"){
	reasonEntDays = reasonEntDays.replace(/\W/ig, ' ');
	document.updateEntitlement.reasonEntDaysChange.value = reasonEntDays;
    document.updateEntitlement.standardDaysChange.value = 8;
    document.updateEntitlement.ifChange.value = "yes";
    return true;
  }else if(returnBenefitDays == "true"){
	reasonBenefitDays = reasonBenefitDays.replace(/\W/ig, ' ');
	document.updateEntitlement.reasonBenefitDaysChange.value = reasonBenefitDays;
    document.updateEntitlement.benefitDaysChange.value = 10;
    document.updateEntitlement.ifChange.value = "yes";
    return true;
  }//end if else

}//end changeDays()


function changedaysInLieu(form){
  var daysInLieuIn = document.updateEntitlement.daysInLieuIn.value;

	if(daysInLieuIn == ""){
		alert('Please enter days in lieu due');
		document.updateEntitlement.daysInLieuIn.focus();
		return false;
	}

	if(isNumeric(daysInLieuIn) == false){
		alert('Days in lieu due must be numeric');
		document.updateEntitlement.daysInLieuIn.focus();
		return false;
      }

  var daysInLieuOld = document.updateEntitlement.daysInLieuOld.value;
  var reasonDaysInLieu = prompt("Reason for days in lieu change" +'\n' +'Click "OK", then click "Update Holiday Details" button to Save',"");
  while(reasonDaysInLieu == ""){
    reasonDaysInLieu = prompt("A reason for days in lieu change is required","");
  }//end while
  if(reasonDaysInLieu == null){
    alert('        You have cancelled this change.' +'\n'  +'\n' +'The database will not be updated with new value');
    document.updateEntitlement.daysInLieu.value = daysInLieuOld;
    document.updateEntitlement.daysInLieu.focus();
    return false;
  }else{
  reasonDaysInLieu = reasonDaysInLieu.replace(/\W/ig, ' ');
  document.updateEntitlement.reasonDaysInLieuChange.value = reasonDaysInLieu;
  document.updateEntitlement.daysInLieuChange.value = 9;
  document.updateEntitlement.ifChange.value = "yes";
  return true;
  }//end if else
}

function changeLeaderName(form){
  var leaderNameOld = document.updateMember.leaderNameOld.value;
  var reasonLeaderName = prompt("Reason for team leader change" +'\n' +'Click "OK", then click "Update Team Member Details" button to Save',"");
  while(reasonLeaderName == ""){
    reasonLeaderName = prompt("A reason for team leader change is required","");
  }//end while
  if(reasonLeaderName == null){
    alert('        You have cancelled this change.' +'\n'  +'\n' +'The database will not be updated with new value');
    document.updateMember.leaderName.value = leaderNameOld;
    document.updateMember.leaderName.focus();
    return false;
  }else{
	reasonLeaderName = reasonLeaderName.replace(/\W/ig, ' ');
    document.updateMember.reasonLeaderNameChange.value = reasonLeaderName;
    document.updateMember.leaderNameChange.value = 11;
    document.updateMember.ifChange.value = "yes";
    return true;
  }//end if else
}

function changeDepartment(form){
  var departmentOld = document.updateMember.departmentOld.value;
  var reasonDepartmentChange = prompt("Reason for department change" +'\n' +'Click "OK", then click "Update Team Member Details" button to Save',"");
  while(reasonDepartmentChange == ""){
    reasonDepartmentChange = prompt("A reason for department change is required","");
  }//end while
  if(reasonDepartmentChange == null){
    alert('        You have cancelled this change.' +'\n'  +'\n' +'The database will not be updated with new value');
    document.updateMember.department.value = departmentOld;
    document.updateMember.department.focus();
    return false;
  }else{ 
	reasonDepartmentChange = reasonDepartmentChange.replace(/\W/ig, ' ');
	document.updateMember.reasonDepartmentChange.value = reasonDepartmentChange;
    document.updateMember.departmentChange.value = 12;
    document.updateMember.ifChange.value = "yes";
    return true;
  }//end if else
}

function changeLeaderStatus(form){
  var leaderStatusOld = document.updateMember.leaderStatusOld.value;
  var reasonLeaderStatusChange = prompt("Reason for leader status change" +'\n' +'Click "OK", then click "Update Team Member Details" button to Save',"");
  while(reasonLeaderStatusChange == ""){
    reasonLeaderStatusChange = prompt("A reason for the leader status change is required","");
  }//end while
  if(reasonLeaderStatusChange == null){
    alert('        You have cancelled this change.' +'\n'  +'\n' +'The database will not be updated with new value');
    document.updateMember.leaderStatus.value = leaderStatusOld;
    document.updateMember.leaderStatus.focus();
    return false;
  }else{
  reasonLeaderStatusChange = reasonLeaderStatusChange.replace(/\W/ig, ' ');
  document.updateMember.reasonLeaderStatusChange.value = reasonLeaderStatusChange;
  document.updateMember.leaderStatusChange.value = 13;
  document.updateMember.ifChange.value = "yes";
  return true;
  }//end if else
}

//##### End functions to detect change on update page



function validateInput(element) {
   if (element.value == "") {
      alert('Please re-enter user name and/or password');
	holidaySearch.userName.focus();
	return false;
   }
}

function validateNewPassword() {
   var pass1 = document.changePassword.password1.value;
   var pass2 = document.changePassword.password2.value;

   if (pass1 == ""){
      alert('Please enter new password in both fields');
	document.changePassword.password1.focus();
	return false;
   }
 
  if (pass2 == ""){
      alert('Please enter new password in both fields');
	document.changePassword.password1.focus();
	return false;
   }
if (pass1 != pass2){
      alert('Please enter the same password in both fields');
	document.changePassword.password1.focus();
	return false;
   }
}

function validateAddMember(){

      var surname = document.addMember.surname.value;
	var firstName = document.addMember.firstName.value;
	var existingUserName = document.addMember.existingUserName.value;
	var userName = document.addMember.userName.value;
      var emailStr = document.addMember.eMail2.value;
	var password = document.addMember.password.value;
	var standardDays = document.addMember.standardDays.value;
	var teamID = document.addMember.teamID.value;
	var department = document.addMember.department.value;
	var teamLeader = document.addMember.teamLeader.value;
      var empty = "";
 

	if(firstName == ""){
		alert('Please enter first name');
		document.addMember.firstName.focus();
		return false;
	}

	if(surname == ""){
		alert('Please enter surname');
		document.addMember.surname.focus();
		return false;
	}

	if(userName == ""){
		alert('Please enter user name');
		document.addMember.userName.focus();
		return false;
	}

 	if(emailStr == ""){
		alert('Please re-enter e-Mail address');
		document.addMember.eMail2.focus();
		return false;
	}

 	if(emailStr != userName){
		alert('Different e-Mail addresses - please re-enter');
		document.addMember.userName.select();
		document.addMember.userName.focus();
		document.addMember.eMail2.value = empty;
		return false;
	}

     testForAt  = emailStr.indexOf("@");
     testForDot = emailStr.indexOf(".");

     if((testForAt == -1) || (testForDot == -1)){
       alert('Please enter correctly formated user eMail');
	 document.addMember.userName.focus();
       document.addMember.userName.select();
       return false; 
     }


     if(existingUserName.match(userName)){
		alert('User name already exists, Re-enter alternative');
		document.addMember.userName.focus();
		return false;
      }


	if(password == ""){
		alert('Please enter password');
		document.addMember.password.focus();
		return false;
	}

	if(standardDays == ""){
		alert('Please enter standard days due');
		document.addMember.standardDays.focus();
		return false;
	}

      if(standardDays <0){
		alert('Please enter Standard days');
		document.addMember.standardDays.value = 0;
		document.addMember.standardDays.focus();
		return false;
	}

	if(isNumeric(standardDays) == false){
		alert('Standard days due must be numeric');
		document.addMember.standardDays.value = 0;
		document.addMember.standardDays.focus();
		return false;
      }

	if(teamID == ""){
		alert('Please enter team leader');
		document.addMember.teamID.focus();
		return false;
	}

	if(department == ""){
		alert('Please enter department');
		document.addMember.department.focus();
		return false;
	}

	if(teamLeader == ""){
		alert('Please enter leader status');
		document.addMember.teamLeader.focus();
		return false;
	}

}//end validateAddMember

function validateUpdateEntitlement(){
  var standardDays = document.updateEntitlement.standardDays.value;
  var daysInLieuIn = document.updateEntitlement.daysInLieuIn.value;
  var benefitDaysIn = document.updateEntitlement.benefitDaysIn.value;

	if(standardDays == ""){
		alert('Please enter entitlement days due');
		document.updateEntitlement.standardDays.focus();
		return false;
	}

	if(isNumeric(standardDays) == false){
		alert('Entitlement days due must be numeric');
		document.updateEntitlement.standardDays.focus();
		return false;
      }

	if(daysInLieuIn == ""){
		alert('Please enter days in lieu due');
		document.updateEntitlement.daysInLieuIn.focus();
		return false;
	}

	if(isNumeric(daysInLieuIn) == false){
		alert('Days in lieu due must be numeric');
		document.updateEntitlement.daysInLieuIn.focus();
		return false;
      }

	if(benefitDaysIn == ""){
		alert('Please enter benefit days due');
		document.updateEntitlement.benefitDaysIn.focus();
		return false;
	}

	if(isNumeric(benefitDaysIn) == false){
		alert('Benifit days due must be numeric');
		document.updateEntitlement.benefitDaysIn.focus();
		return false;
      }

}//end validateUpdateEntitlement()

function validateUpdateMember(){

     	var surname = document.updateMember.surname.value;
	var firstName = document.updateMember.firstName.value;
	var leaderName = document.updateMember.leaderName.value;
	var department = document.updateMember.department.value;
	var teamLeader = document.updateMember.teamLeader.value;

	if(surname == ""){
		alert('Please enter surname');
		document.updateMember.surname.focus();
		return false;
	}

	if(firstName == ""){
		alert('Please enter first name');
		document.updateMember.firstName.focus();
		return false;
	}

	if(leaderName == ""){
		alert('Please enter team leader');
		document.updateMember.leaderName.focus();
		return false;
	}

	if(department == ""){
		alert('Please enter department');
		document.updateMember.department.focus();
		return false;
	}

	if(teamLeader == ""){
		alert('Please enter leader status');
		document.updateMember.teamLeader.focus();
		return false;
	}

}

function isNumeric(value){
    var decimalPoint = false;
    var minus = false;
    for(var i=0; i<value.length; i++){
      if(!isDigit(value.charAt(i))){
        if(value.charAt(i) == '.'){
          if(decimalPoint == true){
            return false; //Must already have come across a decimal point
          }else{
            decimalPoint = true;
          }
        }else if(value.charAt(i) == '-'){
          if(minus == true){
            return false; //Must already have come across a minus
          }else{
            minus = true;
          }
        }else{
          return false;
        }
      }
    }//end for
    return true;
}



function isDigit(number){
  var string = "1234567890";
  if(string.indexOf(number) != -1){
    return true;
  }
return false;
}

function todaysDate(){
  
  var d = new Date();
  var day = d.getDate();
  var month = d.getMonth()+1;
  var year = d.getFullYear();
  var fullDate = day +"-" +month +"-" +year;

  document.calendarForm.calendar.value = fullDate;

}












