﻿/*
//###########################################################################################################
// Description : Master Javascript validation methods.
// Author : JJL, NCS               Date : 24/04/2009
// Copyright 2009-2010 John Wiley and Sons Ltd
//-----------------------------------------------------------------------------------------------------------
// Change log:	Date		Reference		Author		Description
//-----------------------------------------------------------------------------------------------------------
//              20/05/2009  WO089.R01.P01   JJL, NCS    Member subscription alert message has changed.              
//              09/06/2009  WO089.R02       JJL, NCS    Added isAlphaNumeric(), ValidateRequiredFieldsContentUpdate(), isAlphaNumericWithPunctuations()
//              12/06/2009  WO089.R02       MJR, NCS    Added Subscription Form Client-Side Validation function
//              25-Aug-2009 WO089.R03       MJR,NCS     Added Iteration 3 js functions
//              01/02/2010  IM006684        BMA,NCS     Include VacancyCloseDate and rename VacancyDate to VacancyOpenDate
//              01/09/2010  IM031524        JJL,NCS     Updated RequiredFields_ClientValidate() removed Required validation
//###########################################################################################################
*/
function checkMaxLen(txt,maxLen) 
{
        try
        {
            if(txt.value.length > (maxLen-1)) 
            {
                var cont = txt.value;
                txt.value = cont.substring(0,(maxLen -1));
                return false;
            };
         }
         catch(e)
         {}
}

function isValidEmail(txt_email) {
    var emailFilter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;    
    return emailFilter.test(txt_email);
}

function ValidateCountry(source, args)
{
 var x = document.getElementById(GetClientId("ddlCountry")).value;
 if (x != 0)
  {
      args.IsValid = true;
  }
  else
  {
      args.IsValid = false;
  }

}


function ValidateUsername(source, args)
{
  var x = trim(document.getElementById(GetClientId("txtusername")).value);
  if ((x != "") && (x.length >= 1))
  {
      args.IsValid = true;
  }
  else
  {
      args.IsValid = false;
  }
}
function ValidatePassword(source, args)
{
    var x = trim(document.getElementById(GetClientId("txtpassword")).value);
    //only validate when there is a value
    if ((x.length > 0) && (x.length < 6))
    {
        document.getElementById(GetClientId("txtpassword")).className = "fielderror";
        args.IsValid = false;
    }
    else {
        args.IsValid = true;
    }
}


function ValidateConfirmPassword(source, args)
{
  var x = trim(document.getElementById(GetClientId("txtpasswordconfirm")).value);
  if ((x.length > 0) && (x.length < 6)) 
  {
      document.getElementById(GetClientId("txtpasswordconfirm")).className = "fielderror";
      args.IsValid = false;
  }
  else 
  {    
      args.IsValid = true;
  }
}


function CheckEmail(source, args)
{
    var x = trim(document.getElementById(GetClientId("txtemail")).value);
    var memID = trim(document.getElementById(GetClientId("hdnMemberId")).value);
    var postBody = "{email:'" + x + "', memberID:'" + memID + "'}";

    new Ajax.Request('/WebService/validators.asmx/ValidateMemberEmail',
	  {
	      postBody: postBody,
   	      asynchronous:false,
	      method: 'post', contentType:'application/json; charset=utf-8', dataType: "json",
	      onSuccess: function(transport) {
	          var json=transport.responseText.evalJSON(true);
	          var response = json.d;
	          if (response == 0)
	          {
                args.IsValid = true;
	          }
	          else
	          {
                document.getElementById(GetClientId("txtemail")).className = "fielderror";
                args.IsValid = false; 
	          }
	      },
	      onFailure: function() {
                document.getElementById(GetClientId("txtemail")).className = "fielderror";
                args.IsValid = false; 
	       }
	  });
}

function ValidateEmail(source, args)
{
    var x = trim(document.getElementById(GetClientId("txtemail")).value);

    //only validate when there is a value
    if ((x.length > 0) && (!isValidEmail(x)))
    {
        document.getElementById(GetClientId("txtemail")).className = "fielderror";
        args.IsValid = false; 
    }
    else
    {
        args.IsValid = true;
    }
}

function CheckAmendSubscription()
{
   Page_ClientValidate();
   
   if(Page_IsValid)
   {
        //Only execute when all client validation has done.
        t = document.getElementById(GetClientId("chkchgsub")).checked;
        if (!t)
        {
            //20/05/2009   WO089.R01.P01   JJL, NCS    Member subscription alert message has changed.
            var x= confirm("Apply changes to Journal delivery address?" );
            if (x)
            {
                document.getElementById(GetClientId("chkchgsub")).checked = true;
            }
        }
        return true;
   }
   else
   {
    return false;
   }
}

function ValidateComparePassword(source, args)
{
  var p1 = trim(document.getElementById(GetClientId("txtpassword")).value);
  var p2 = trim(document.getElementById(GetClientId("txtpasswordconfirm")).value);
  if (((p1.length = 0) && (p2.length = 0)) || (p1 == p2))
  {
      args.IsValid = true;
  }
  else {
      document.getElementById(GetClientId("txtpassword")).className = "fielderror";
      document.getElementById(GetClientId("txtpasswordconfirm")).className = "fielderror";
      args.IsValid = false;
  }
}


function ToggleDefault(obj,defaultValue) {
    var x = trim(obj.value);
    if (x == "")
        obj.value = defaultValue;
    else if (x == defaultValue)
        obj.value = "";
}

// 09/06/2009   WO089.R02 JJL, NCS Added Function to Validate Alphanumeric text starts
function isAlphaNumericWithPunctuations(str) {
    var re = /[^a-zA-Z0-9 \.\?\!\:\;\-\_\#\%\|\&\*\+\~\^\<\>\=\@\(\)\[\]\'\"\/\,\{\}]/g;
    if (re.test(str)) return false;
    return true;
}

function isAlphaNumeric(str) {
    var re = /[^a-zA-Z0-9 ]/g;
    if (re.test(str)) return false;
    return true;
}

// 09/06/2009   WO089.R02 JJL, NCS Added Function to Validate Alphanumeric text ends

// 09/06/2009   WO089.R02 JJL, NCS Added Function to Validate Content update form fields starts 
function ValidateRequiredFieldsContentUpdate(source, args) 
{
    var xx1 = trim(document.getElementById(GetClientId("txtTitle")).value);
    var xx2 = trim(document.getElementById(GetClientId("ceContent")).value);

    document.getElementById(GetClientId("txtTitle")).className = "";
    document.getElementById(GetClientId("ceContent")).className = "";
    if ((xx1 != "") && (xx2 != "") && (xx1.length >= 2))
    {
        args.IsValid = true;
    }
    else {
        if ((xx1 == "") || (xx1.length < 2))
        {
            document.getElementById(GetClientId("txtTitle")).className = "fielderror";
        }
        if (xx2 == "") 
        {
            document.getElementById(GetClientId("ceContent")).className = "fielderror";
        }
        args.IsValid = false;
    }
}

function ValidateAlphaNumeric(source, args)
 {
    var xx1 = trim(document.getElementById(GetClientId("txtTitle")).value);
    if ((xx1.length >= 2) && (isAlphaNumericWithPunctuations(xx1))) 
    {
        document.getElementById(GetClientId("txtTitle")).className = "";
        args.IsValid = true;
    }
    else {
        if (xx1.length < 2) {
            args.IsValid = true;
        }
        else {
            document.getElementById(GetClientId("txtTitle")).className = "fielderror";
            args.IsValid = false;
        }
    }
}
// 09/06/2009   WO089.R02 JJL, NCS Added Function to Validate Content update form fields ends


function ValidateRequiredFieldsMemberUpdate(source, args)
{
    var xx1 = trim(document.getElementById(GetClientId("txtfirstname")).value);
    var xx2 = trim(document.getElementById(GetClientId("txtsurname")).value);
    var xx3 = trim(document.getElementById(GetClientId("txtaddress1")).value);
    var xx4 = trim(document.getElementById(GetClientId("txttown")).value);
    var xx5 = trim(document.getElementById(GetClientId("ddlCountry")).value);
    var xx6 = trim(document.getElementById(GetClientId("txtemail")).value);
    var xx7 = trim(document.getElementById(GetClientId("txtpassword")).value);
    var xx8 = trim(document.getElementById(GetClientId("txtpasswordconfirm")).value);
    var xx = document.getElementById(GetClientId("hdnMemberType")).value;
    
    document.getElementById(GetClientId("txtfirstname")).className = "";
    document.getElementById(GetClientId("txtsurname")).className = "";
    document.getElementById(GetClientId("txtaddress1")).className = "";
    document.getElementById(GetClientId("txttown")).className = "";
    document.getElementById(GetClientId("txtemail")).className = "";
    document.getElementById(GetClientId("ddlCountry")).className = "";
    document.getElementById(GetClientId("txtpassword")).className = "";
    document.getElementById(GetClientId("txtpasswordconfirm")).className = "";
    if (xx=="e")
    {
        xx7 ="       ";
        xx8 ="       ";
    }
    if ((xx1 != "") && (xx2 != "") && (xx3 != "") && (xx4 != "") && (xx5 !=0) && (xx6 != "") && (xx7 != "") && (xx7.length >= 6) && (xx8 != "") && (xx8.length >= 6) ) 
    {
       args.IsValid = true;
    }
    else 
    {
        if (xx1 == "") 
        {
           document.getElementById(GetClientId("txtfirstname")).className =  "fielderror";
        }
      
        if (xx2 == "")
        {
            document.getElementById(GetClientId("txtsurname")).className =  "fielderror";
        }
        
        if (xx3 == "")
        {
            document.getElementById(GetClientId("txtaddress1")).className =  "fielderror";
        }
       
        if (xx4 == "")
        {
            document.getElementById(GetClientId("txttown")).className =  "fielderror";
        }
       
        if (xx5 == 0)
        {
            document.getElementById(GetClientId("ddlCountry")).className =  "fielderror";
        }
        if (xx6 == "")
        {
            document.getElementById(GetClientId("txtemail")).className =  "fielderror";
        }
        
        if (((xx7 == "") || (xx7.length < 6)) && ( xx ="m"))
        {
            document.getElementById(GetClientId("txtpassword")).className =  "fielderror";
        }

        if (((xx8 == "") || (xx8.length < 6)) && ( xx ="m"))
        {
            document.getElementById(GetClientId("txtpasswordconfirm")).className =  "fielderror";
        }
       
        args.IsValid = false;
    }
}

function trim(str) {
    return str.replace(/^\s\s*/, '').replace(/\s\s*$/, '');
}

//START: 12/06/2009   WO089.R02 MJR, NCS Added Subscription Form Client-Side Validation function
function Subscribe_ClientClick()
{
    Page_ClientValidate();
    
    if (Page_IsValid)
    {
        return true;
    }
    else
    {
        return false;
    }
}

function RequiredFields_ClientValidate(source, args)
{
    var txtJnlDiscount = document.getElementById(GetClientId("txtJnlDiscount"));
    var ddlPayCardType = document.getElementById(GetClientId("ddlPayCardType"));
    var ddlMonth = document.getElementById(GetClientId("ddlMonth"));
    var ddlYear = document.getElementById(GetClientId("ddlYear"));
    var txtPayCardVerification = document.getElementById(GetClientId("txtPayCardVerification"));
    var txtCourtesyTitle = document.getElementById(GetClientId("txtCourtesyTitle"));
    var txtFirstName = document.getElementById(GetClientId("txtFirstName"));
    var txtLastName = document.getElementById(GetClientId("txtLastName"));
    var txtDepartment = document.getElementById(GetClientId("txtDepartment"));
    var txtEstablishment = document.getElementById(GetClientId("txtEstablishment"));
    var txtStreet = document.getElementById(GetClientId("txtStreet"));
    var txtTown = document.getElementById(GetClientId("txtTown"));
    var txtState = document.getElementById(GetClientId("txtState"));
    var txtPostCode = document.getElementById(GetClientId("txtPostCode"));
    var ddlCountry = document.getElementById(GetClientId("ddlCountry"));
    var txtEmail = document.getElementById(GetClientId("txtEmail"));
    var txtEmailVerify = document.getElementById(GetClientId("txtEmailVerify"));
    var txtTelNo = document.getElementById(GetClientId("txtTelNo"));
    var txtFaxNo = document.getElementById(GetClientId("txtFaxNo"));
    var txtPayCustomerNo = document.getElementById(GetClientId("txtPayCustomerNo"));
    var txtPayCardNumber = document.getElementById(GetClientId("txtPayCardNumber"));
    var txtPayCardHolderName = document.getElementById(GetClientId("txtPayCardHolderName"));
    var txtVatNumber = document.getElementById(GetClientId("txtVatNumber"));
    var txtGstNumber = document.getElementById(GetClientId("txtGstNumber"));
    var radPayOrderType1 = document.getElementById(GetClientId("radPayOrderType1"));
    var radPayOrderType2 = document.getElementById(GetClientId("radPayOrderType2"));
    var radPayVatRegYes = document.getElementById(GetClientId("radPayVatRegYes"));
    var radPayGstRegYes = document.getElementById(GetClientId("radPayGstRegYes"));
    var divDiscountCodeAccepted = document.getElementById(GetClientId("divDiscountCodeAccepted"));
    var divDiscountCodeInvalid = document.getElementById(GetClientId("divDiscountCodeInvalid"));
    var hdnCountryRegion = document.getElementById(GetClientId("hdnCountryRegion"));
    
    //Initialize CssClass on controls
    txtJnlDiscount.className = "";
    ddlPayCardType.className = "naturalSize";
    ddlMonth.className = "naturalSize";
    ddlYear.className = "naturalSize";
    txtPayCardVerification.className = "";
    txtFirstName.className = "";
    txtLastName.className = "";
    txtStreet.className = "";
    txtTown.className = "";
    txtState.className = "";
    txtPostCode.className = "";
    ddlCountry.className = "";
    txtEmail.className = "";
    txtEmailVerify.className = "";
    txtPayCustomerNo.className = "";
    txtPayCardNumber.className = "";
    txtPayCardHolderName.className = "";    
    if(txtVatNumber != null) txtVatNumber.className = "";
    if(txtGstNumber != null) txtGstNumber.className = "";

    //Trim entry fields
    //01/09/2010 IM031524 JJL,NCS 
    //txtPayCustomerNo.value = trim(txtPayCustomerNo.value);
    txtJnlDiscount.value = trim(txtJnlDiscount.value);
    txtPayCardNumber.value = trim(txtPayCardNumber.value);
    txtPayCardVerification.value = trim(txtPayCardVerification.value);
    txtPayCardHolderName.value = trim(txtPayCardHolderName.value);
    txtCourtesyTitle.value = trim(txtCourtesyTitle.value);
    txtFirstName.value = trim(txtFirstName.value);
    txtLastName.value = trim(txtLastName.value);
    txtDepartment.value = trim(txtDepartment.value);
    txtEstablishment.value = trim(txtEstablishment.value);
    txtStreet.value = trim(txtStreet.value);
    txtTown.value = trim(txtTown.value);
    txtState.value = trim(txtState.value);
    txtPostCode.value = trim(txtPostCode.value);
    txtEmail.value = trim(txtEmail.value);
    txtTelNo.value = trim(txtTelNo.value);
    txtFaxNo.value = trim(txtFaxNo.value);
    hdnCountryRegion.value = trim(hdnCountryRegion.value);
    if(txtVatNumber != null) txtVatNumber.value = trim(txtVatNumber.value);
    if(txtGstNumber != null) txtGstNumber.value = trim(txtGstNumber.value);
    
    if ((radPayOrderType1.checked || radPayOrderType2.checked) &&
        ddlCountry.value != "" && ddlPayCardType.value != "" &&
        txtPayCardNumber.value != "" && ddlMonth.value != "-1" && ddlYear.value != "" &&
        txtPayCardHolderName.value != "" && txtFirstName.value != "" && txtLastName.value != "" &&
        txtStreet.value != "" && txtTown.value != "" && txtState.value != "" &&
        txtPostCode.value != "" && txtEmail.value != "" && txtEmailVerify.value != "")
    {
        args.IsValid = true;
    }
    else {
        //01/09/2010 IM031524 JJL,NCS commented existing validation code Starts
        //  if (radPayOrderType2.checked && txtPayCustomerNo.value == "")
        //  {
        //     txtPayCustomerNo.className = "fielderror";
        //  }
        //01/09/2010 IM031524 JJL,NCS commented existing validation code End
        if (txtPayCardNumber.value == "")
        {
            txtPayCardNumber.className = "fielderror";
        }
        if (txtPayCardHolderName.value == "")
        {
            txtPayCardHolderName.className = "fielderror";
        }
        if (ddlPayCardType.value == "")
        {
            ddlPayCardType.className = "fielderror";
        }
        if (ddlMonth.value == "-1")
        {
            ddlMonth.className = "fielderror";
        }
        if (ddlYear.value == "-1")
        {
            ddlYear.className = "fielderror";
        }
        if (txtPayCardVerification.value == "")
        {
            txtPayCardVerification.className = "fielderror";
        }
        if (txtFirstName.value == "")
        {
            txtFirstName.className = "fielderror";
        }
        if (txtLastName.value == "")
        {
            txtLastName.className = "fielderror";
        }
        if (txtStreet.value == "")
        {
            txtStreet.className = "fielderror";
        }
        if (txtTown.value == "")
        {
            txtTown.className = "fielderror";
        }
        if (txtState.value == "")
        {
            txtState.className = "fielderror";
        }
        if (txtPostCode.value == "")
        {
            txtPostCode.className = "fielderror";
        }
        if (ddlCountry.value == "")
        {
            ddlCountry.className = "fielderror";
        }
        if (txtEmail.value == "")
        {
            txtEmail.className = "fielderror";
        }
        if (txtEmailVerify.value == "")
        {
            txtEmailVerify.className = "fielderror";
        }        
        if (hdnCountryRegion.value == "EU")
        {
            txtVatNumber.value = trim(txtVatNumber.value);
            if (radPayVatRegYes.checked && txtVatNumber.value == "")
            {
                txtVatNumber.className = "fielderror";
            }
        }
        if (ddlCountry.options[ddlCountry.selectedIndex].text == "Australia" ||
            ddlCountry.options[ddlCountry.selectedIndex].text == "Canada")
        {
            txtGstNumber.value = trim(txtGstNumber.value);
            if (radPayGstRegYes.checked && txtGstNumber.value == "")
            {
                txtGstNumber.className = "fielderror";
            }
        }
        if (txtJnlDiscount.value == "")
        {
            if(divDiscountCodeAccepted != null) divDiscountCodeAccepted.style.display = "none";
            if(divDiscountCodeInvalid != null) divDiscountCodeInvalid.style.display = "none";
        }

        args.IsValid = false;
    }   
}

function CardVerificationMinimum_ClientValidate(source, args)
{
    args.IsValid = true;
    
    var txtPayCardVerification = document.getElementById(GetClientId("txtPayCardVerification"));
    
    if (txtPayCardVerification.value != "")
    {
        if (txtPayCardVerification.value.length < 3)
        {
            txtPayCardVerification.className = "fielderror";
            args.IsValid = false;
        }
        else
        {
            txtPayCardVerification.className = "";
        }
    }
}

function DiscountCodeAlphanumeric_ClientValidate(source, args)
{
    args.IsValid = true;
    
    var txtJnlDiscount = document.getElementById(GetClientId("txtJnlDiscount"));
    
    txtJnlDiscount.value = trim(txtJnlDiscount.value);
    
    if (txtJnlDiscount.value != "")
    {
        if (!isAlphaNumeric(txtJnlDiscount.value))
        {
            txtJnlDiscount.className = "fielderror";
            args.IsValid = false;
        }
        else
        {
            txtJnlDiscount.className = "";
        }
    }
}

function CardNumberAlphanumeric_ClientValidate(source, args)
{
    args.IsValid = true;
    
    var txtPayCardNumber = document.getElementById(GetClientId("txtPayCardNumber"));
    
    txtPayCardNumber.value = trim(txtPayCardNumber.value);
    
    if (txtPayCardNumber.value != "")
    {
        if (!isAlphaNumeric(txtPayCardNumber.value))
        {
            txtPayCardNumber.className = "fielderror";
            args.IsValid = false;
        }
        else
        {
            txtPayCardNumber.className = "";
        }
    }
}

function CardholderNameAlphanumeric_ClientValidate(source, args)
{
    args.IsValid = true;

    var txtPayCardHolderName = document.getElementById(GetClientId("txtPayCardHolderName"));
    
    txtPayCardHolderName.value = trim(txtPayCardHolderName.value);
    
    if (txtPayCardHolderName.value != "")
    {
        if (!isAlphaNumericWithPunctuations(txtPayCardHolderName.value))
        {
            txtPayCardHolderName.className = "fielderror";
            args.IsValid = false;
        }
        else
        {
            txtPayCardHolderName.className = "";
        }
    }
}

function WileyRefInvalid_ClientValidate(source, args)
{
    args.IsValid = true;
    
    var txtPayCustomerNo = document.getElementById(GetClientId("txtPayCustomerNo"));
    var radPayOrderType2 = document.getElementById(GetClientId("radPayOrderType2"));
    
    txtPayCustomerNo.value = trim(txtPayCustomerNo.value);
    
    if (radPayOrderType2.checked && txtPayCustomerNo.value != "")
    {
        if(isNaN(txtPayCustomerNo.value))
        {
            txtPayCustomerNo.className = "fielderror";
            args.IsValid = false;
        }
        else
        {
            txtPayCustomerNo.className = "";
        }        
    }
}

function VatNumberInvalid_ClientValidate(source, args)
{
    args.IsValid = true;
    
    var txtVatNumber = document.getElementById(GetClientId("txtVatNumber"));
    var radPayVatRegYes = document.getElementById(GetClientId("radPayVatRegYes"));
    var hdnCountryRegion = document.getElementById(GetClientId("hdnCountryRegion"));
    
    if (hdnCountryRegion.value == "EU")
    {
        txtVatNumber.value = trim(txtVatNumber.value);
        
        if (radPayVatRegYes.checked && txtVatNumber.value != "")
        {
            if(isNaN(txtVatNumber.value))
            {
                txtVatNumber.className = "fielderror";
                args.IsValid = false;
            }
            else
            {
                txtVatNumber.className = "";
            }
        }
    }
}

function GstNumberInvalid_ClientValidate(source, args)
{
    args.IsValid = true;
    
    var ddlCountry = document.getElementById(GetClientId("ddlCountry"));
    var txtGstNumber = document.getElementById(GetClientId("txtGstNumber"));
    var radPayGstRegYes = document.getElementById(GetClientId("radPayGstRegYes"));
    
    if (ddlCountry.options[ddlCountry.selectedIndex].text == "Australia" ||
        ddlCountry.options[ddlCountry.selectedIndex].text == "Canada")
    {
        txtGstNumber.value = trim(txtGstNumber.value);
        if (radPayGstRegYes.checked && txtGstNumber.value != "")
        {
            if(isNaN(txtGstNumber.value))
            {
                txtGstNumber.className = "fielderror";
                args.IsValid = false;
            }
            else
            {
                txtGstNumber.className = "";
            }            
        }
    }
}

function CardExpiryInvalid_ClientValidate(source, args)
{
    args.IsValid = true;
    
    var ddlMonth = document.getElementById(GetClientId("ddlMonth"));
    var ddlYear = document.getElementById(GetClientId("ddlYear"));
    
    var currentDate = new Date();
    var currYear = currentDate.getFullYear();
    var currMonth = currentDate.getMonth();
    
    if (ddlMonth.value != "-1" && ddlYear.value != "-1")
    {
        if (ddlMonth.value <= currMonth &&
            ddlYear.value <= currYear)
        {
            ddlMonth.className = "fielderror";
            ddlYear.className = "fielderror";
            args.IsValid = false;
        }
        else
        {
            ddlMonth.className = "naturalSize";
            ddlYear.className = "naturalSize";
        }
    }
}

function CardVerificationInvalid_ClientValidate(source, args)
{
    args.IsValid = true;

    var txtPayCardVerification = document.getElementById(GetClientId("txtPayCardVerification"));
    
    if (txtPayCardVerification.value != "")
    {
        if (isNaN(txtPayCardVerification.value))
        {
            txtPayCardVerification.className = "fielderror";
            args.IsValid = false;
        }
        else
        {
            txtPayCardVerification.className = "";
        }
    }
}

function EmailInvalid_ClientValidate(source, args)
{
    args.IsValid = true;
    
    var txtEmail = document.getElementById(GetClientId("txtEmail"));
    
    txtEmail.value = trim(txtEmail.value);
    
    if (txtEmail.value != "")
    {
        if (!isValidEmail(txtEmail.value))
        {
            txtEmail.className = "fielderror";
            args.IsValid = false;
        }
        else
        {
            txtEmail.className = "";
        }
    }
}

function EmailMismatch_ClientValidate(source, args)
{
    args.IsValid = true;
    
    var txtEmail = document.getElementById(GetClientId("txtEmail"));
    var txtEmailVerify = document.getElementById(GetClientId("txtEmailVerify"));
    
    txtEmail.value = trim(txtEmail.value);
    txtEmailVerify.value = trim(txtEmailVerify.value);
    
    if (txtEmail.value != "")
    {
        if (isValidEmail(txtEmail.value))
        {
            if (txtEmail.value != txtEmailVerify.value)
            {
                txtEmail.className = "fielderror";
                txtEmailVerify.className = "fielderror";
                args.IsValid = false;
            }
            else
            {
                txtEmail.className = "";
                txtEmailVerify.className = "";
            }
        }
    }
}

function popUp(URL) 
{
    day = new Date();
    id = day.getTime();
    eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=1,width=350,height=450,left = 490,top = 262');");
}
//END: 12/06/2009   WO089.R02 MJR, NCS

//START: 25-Aug-2009   WO089.R03 MJR, NCS
function ConfirmDelete(query)
{			
	if(confirm(query)) 
	{
		return true;			
    }
	else
	{
	    return false;			
	}
}

function Submit_ClientClick()
{
    Page_ClientValidate();
    
    if (Page_IsValid)
    {
        return true;
    }
    else
    {
        return false;
    }
}

//START: Meeting Client-Side Functions
var _isOkMeeting = true;
var _isValidStartDate = true;
var _isValidEndDate = true;
function MeetingRequiredFields_ClientValidate(source, args)
{
    var radIAVSType = document.getElementById(GetClientId("radIAVSType"));
    var radOtherType = document.getElementById(GetClientId("radOtherType"));
    var txtTitle = document.getElementById(GetClientId("txtTitle"));
    var txtLocation = document.getElementById(GetClientId("txtLocation"));
    var txtDayStart = document.getElementById(GetClientId("txtDayStart"));
    var ddlMonthStart = document.getElementById(GetClientId("ddlMonthStart"));
    var txtYearStart = document.getElementById(GetClientId("txtYearStart"));
    var txtDayEnd = document.getElementById(GetClientId("txtDayEnd"));
    var ddlMonthEnd = document.getElementById(GetClientId("ddlMonthEnd"));
    var txtYearEnd = document.getElementById(GetClientId("txtYearEnd"));
    var ceContent = document.getElementById(GetClientId("ceContent"));
    
    //Initialize className on controls
    txtTitle.className = "";
    txtLocation.className = "";
    txtDayStart.className = "search";
    ddlMonthStart.className = "search";
    txtYearStart.className = "search";
    txtDayEnd.className = "search";
    ddlMonthEnd.className = "search";
    txtYearEnd.className = "search";
    ceContent.className = "";
    
    //Trim entry fields
    txtTitle.value = trim(txtTitle.value); 
    txtLocation.value = trim(txtLocation.value); 
    txtDayStart.value = trim(txtDayStart.value); 
    txtYearStart.value = trim(txtYearStart.value); 
    txtDayEnd.value = trim(txtDayEnd.value); 
    txtYearEnd.value = trim(txtYearEnd.value); 
    ceContent.value = trim(ceContent.value); 
    
    var _isValid = true;
    
    if ((radIAVSType.checked || radOtherType.checked) && 
        txtTitle.value != "" && txtLocation.value != "" && 
        txtYearStart.value != "" && txtYearStart.value != "YYYY" && 
        txtYearEnd.value != "" && txtYearEnd.value != "YYYY" && 
        ceContent.value != "")
    {
        _isValid = true;
    }    
    else
    {
        if (txtTitle.value == "")
        {
            txtTitle.className = "fielderror";
        }
        if (txtLocation.value == "")
        {
            txtLocation.className = "fielderror";
        }
        if (ceContent.value == "")
        {
            ceContent.className = "fielderror";
        }
        if (txtYearStart.value == "" || txtYearStart.value == "YYYY")
        {
            txtYearStart.className = "fielderror";
        }
        if (txtYearEnd.value == "" || txtYearEnd.value == "YYYY")
        {
            txtYearEnd.className = "fielderror";
        }
        if (txtDayStart.value != "" && txtDayStart.value != "DD")
        {
            if (ddlMonthStart.value == "-1")
            {
                ddlMonthStart.className = "fielderror";                
            }
        }
        if (txtDayEnd.value != "" && txtDayEnd.value != "DD")
        {
            if (ddlMonthEnd.value == "-1")
            {
                ddlMonthEnd.className = "fielderror";
            }
        }
        
        _isValid = false;
    }
    if ((radIAVSType.checked || radOtherType.checked) && 
        txtTitle.value != "" && txtLocation.value != "" && 
        ((txtYearStart.value != "" && txtYearStart.value != "YYYY") && (txtDayStart.value != "" && txtDayStart.value != "DD")) && 
        ((txtYearEnd.value != "" && txtYearEnd.value != "YYYY") && (txtDayEnd.value != "" && txtDayEnd.value != "DD")) && 
        ceContent.value != "")
    {
        if (ddlMonthStart.value == "-1")
        {
            ddlMonthStart.className = "fielderror";
            _isValid = false;
        }
        if (ddlMonthEnd.value == "-1")
        {
            ddlMonthEnd.className = "fielderror";
            _isValid = false;
        }
    }
    _isOkMeeting = _isValid;
    args.IsValid = _isValid;
}

function MeetingTitleAlphanumeric_ClientValidate(source, args)
{
    args.IsValid = true;
    
    var txtTitle = document.getElementById(GetClientId("txtTitle"));

    txtTitle.value = trim(txtTitle.value);    
    
    if (txtTitle.value != "")
    {
        if (!isAlphaNumericWithPunctuations(txtTitle.value))
        {
            txtTitle.className = "fielderror";
            args.IsValid = false;
        }
        else
        {
            txtTitle.className = "";
        }
    }
}

function MeetingLocationAlphanumeric_ClientValidate(source, args)
{
    args.IsValid = true;
    
    var txtLocation = document.getElementById(GetClientId("txtLocation"));

    txtLocation.value = trim(txtLocation.value);
    
    if (txtLocation.value != "")
    {
        if (!isAlphaNumericWithPunctuations(txtLocation.value))
        {
            txtLocation.className = "fielderror";
            args.IsValid = false;
        }
        else
        {
            txtLocation.className = "";
        }
    }
}

function MeetingStartDateInvalid_ClientValidate(source, args)
{
    var _isValid = true; 
    
    var txtDayStart = document.getElementById(GetClientId("txtDayStart"));
    var ddlMonthStart = document.getElementById(GetClientId("ddlMonthStart"));
    var txtYearStart = document.getElementById(GetClientId("txtYearStart"));
    var min_year = 1900; //SQL minimum year
    
    txtDayStart.value = trim(txtDayStart.value);
    txtYearStart.value = trim(txtYearStart.value);
    
    //if(txtYearStart.value != "" && txtYearStart.value != "YYYY")
    if(_isOkMeeting)
    {
        if (txtDayStart.value != "" && txtDayStart.value != "DD")
        {
            if(isNaN(txtDayStart.value))
            {
                _isValid = false;
            }
        }
        if (txtYearStart.value != "" && txtYearStart.value != "YYYY")
        {
            if(isNaN(txtYearStart.value))
            {
                _isValid = false;
            }
            else
            {
                if(txtYearStart.value < min_year)
                {
                    _isValid = false;
                }
            }
        }
        if ((txtDayStart.value != "" && txtDayStart.value != "DD") &&
            ddlMonthStart.value != "-1" &&
            (txtYearStart.value != "" && txtYearStart.value != "YYYY"))
        {
            try
            {
                ConvertStringToDate(txtYearStart.value, ddlMonthStart.value-1, txtDayStart.value);
            }
            catch(e)
            {
                _isValid = false;
            }
        }
    }
    
    if(!_isValid)
    {
        if (txtDayStart.value != "" && txtDayStart.value != "DD")
        {
            txtDayStart.className = "fielderror";  
            if(ddlMonthStart.value == "-1")
            {
                ddlMonthStart.className = "fielderror";
            }          
        }
        if(ddlMonthStart.value != "-1")
        {
            ddlMonthStart.className = "fielderror";
        }
        txtYearStart.className = "fielderror";
        _isValidStartDate = false;
    }
    
    args.IsValid = _isValid;
}

function MeetingEndDateInvalid_ClientValidate(source, args)
{
    var _isValid = true;
    
    var txtDayEnd = document.getElementById(GetClientId("txtDayEnd"));
    var ddlMonthEnd = document.getElementById(GetClientId("ddlMonthEnd"));
    var txtYearEnd = document.getElementById(GetClientId("txtYearEnd"));
    
    var _endDate = new Date();
    var min_year = 1900; //SQL minimum year
    
    txtDayEnd.value = trim(txtDayEnd.value);
    txtYearEnd.value = trim(txtYearEnd.value);
    
    //if(txtYearEnd.value != "" && txtYearEnd.value != "YYYY")
    if(_isOkMeeting)
    {
        if (txtDayEnd.value != "" && txtDayEnd.value != "DD")
        {
            if(isNaN(txtDayEnd.value))
            {
                _isValid = false;
            }
        }
        if (txtYearEnd.value != "" && txtYearEnd.value != "YYYY")
        {
            if(isNaN(txtYearEnd.value))
            {
                _isValid = false;
            }
            else
            {
                if(txtYearEnd.value < min_year)
                {
                    _isValid = false;
                }
            }
        }
        if ((txtDayEnd.value != "" && txtDayEnd.value != "DD") &&
            ddlMonthEnd.value != "-1" &&
            (txtYearEnd.value != "" && txtYearEnd.value != "YYYY"))
        {
            try
            {
                _endDate = ConvertStringToDate(txtYearEnd.value, ddlMonthEnd.value-1, txtDayEnd.value);
            }
            catch(e)
            {
                _isValid = false;
            }
        }
    }
    
    if(!_isValid)
    {
        if (txtDayEnd.value != "" && txtDayEnd.value != "DD")
        {
            txtDayEnd.className = "fielderror"; 
            if(ddlMonthEnd.value == "-1")
            {
                ddlMonthEnd.className = "fielderror";
            }
        }
        if(ddlMonthEnd.value != "-1")
        {
            ddlMonthEnd.className = "fielderror";
        }
        txtYearEnd.className = "fielderror";
        _isValidEndDate = false;
    }
    
    args.IsValid = _isValid;
}

function MeetingDateInvalid_ClientValidate(source, args)
{
    var _isValid = true;    
    
    var txtDayStart = document.getElementById(GetClientId("txtDayStart"));
    var ddlMonthStart = document.getElementById(GetClientId("ddlMonthStart"));
    var txtYearStart = document.getElementById(GetClientId("txtYearStart"));
    var txtDayEnd = document.getElementById(GetClientId("txtDayEnd"));
    var ddlMonthEnd = document.getElementById(GetClientId("ddlMonthEnd"));
    var txtYearEnd = document.getElementById(GetClientId("txtYearEnd"));
    
    var min_year = 1900; //SQL minimum year
    
    txtDayStart.value = trim(txtDayStart.value);
    txtYearStart.value = trim(txtYearStart.value);
    txtDayEnd.value = trim(txtDayEnd.value);
    txtYearEnd.value = trim(txtYearEnd.value);
    
    //Validate Both, if start and end date is valid, then compare
    if (_isValidStartDate && _isValidEndDate)
    {
        var _startDate = new Date();
        var _endDate = new Date();
        var _startDay = 1;
        var _startMonth = 0;
        var _startYear = 0;
        var _endDay = 1;
        var _endMonth = 0;
        var _endYear = 0;

        _startDay =   GetValue(txtDayStart.value, txtDayEnd.value, "DD");
        _startMonth = GetValue(ddlMonthStart.value, ddlMonthEnd.value, "-1");
        _startYear = txtYearStart.value;
        _endDay = GetValue(txtDayEnd.value, txtDayStart.value, "DD");
        _endMonth = GetValue(ddlMonthEnd.value, ddlMonthStart.value, "-1");
        _endYear = txtYearEnd.value;
        
        try
        {
            _startDate.setFullYear(_startYear, _startMonth, _startDay);
            _endDate.setFullYear(_endYear, _endMonth, _endDay);
            //alert(_startYear + " : " + _startMonth + " : " + _startDay);
            //alert(_endYear + " : " + _endMonth + " : " + _endDay);
            //alert(_startDate + " : " + _endDate);
            if (_startDate > _endDate)
            {
                if (txtDayEnd.value != "" && txtDayEnd.value != "DD")
                {
                    txtDayEnd.className = "fielderror"; 
                    if(ddlMonthEnd.value == "-1")
                    {
                        ddlMonthEnd.className = "fielderror";
                    }                   
                }
                if(ddlMonthEnd.value != "-1")
                {
                    ddlMonthEnd.className = "fielderror";
                }
                txtYearEnd.className = "fielderror";
                _isValid = false;
            }            
        }
        catch(e)
        {
            if (txtDayEnd.value != "" && txtDayEnd.value != "DD")
            {
                txtDayEnd.className = "fielderror";
                if(ddlMonthEnd.value == "-1")
                {
                    ddlMonthEnd.className = "fielderror";
                }
            }
            if(ddlMonthEnd.value != "-1")
            {
                ddlMonthEnd.className = "fielderror";
            }
            txtYearEnd.className = "fielderror";
            _isValid = false;
        }
    }
    
    args.IsValid = _isValid
}

function IsNumberKey()
{
    var keyCode = event.keyCode;

    if (event.shiftKey)
    {
        event.returnValue = false;
    }
    else if (keyCode > 31 &&(keyCode <48 || keyCode >57))
    {
        event.returnValue = false;
    }
    else
    {
        event.returnValue = true;
    }
}

function GetValue(value1, value2, textToCompare)
{
    var _returnValue = 1;
    
    if ((value1 == "" || value1 == textToCompare) || 
        (value2 == "" || value2 == textToCompare))
    {
        _returnValue = "1";
        if(textToCompare == "-1")
        {
            //this is due to month in javascript has first index of 0
            _returnValue = 0;
        }
    }
    else
    {
        _returnValue = value1;  
        if(textToCompare == "-1")
        {
            //this is due to month in javascript has first index of 0
            _returnValue = _returnValue - 1;
        }      
    }
    
    return _returnValue;
}

function ConvertStringToDate(year, month, day)
{
    var _date = new Date();
    _date.setFullYear(year, month, day)
    return _date;
}
//END: Meeting Client-Side Functions

//START: Notice Client-Side Functions
function NoticeRequiredFields_ClientValidate(source, args)
{
    var radMeetingType = document.getElementById(GetClientId("radMeetingType"));
    var radNewsType = document.getElementById(GetClientId("radNewsType"));
    var txtGoLiveDay = document.getElementById(GetClientId("txtGoLiveDay"));
    var ddlGoLiveMonth = document.getElementById(GetClientId("ddlGoLiveMonth"));
    var txtGoLiveYear = document.getElementById(GetClientId("txtGoLiveYear"));
    var ceContent = document.getElementById(GetClientId("ceContent"));
    
    //Initialize className on controls
    txtGoLiveDay.className = "search";
    ddlGoLiveMonth.className = "search";
    txtGoLiveYear.className = "search";
    ceContent.className = "";
    
    //Trim entry fields
    txtGoLiveDay.value = trim(txtGoLiveDay.value); 
    txtGoLiveYear.value = trim(txtGoLiveYear.value);
    ceContent.value = trim(ceContent.value);
    
    if ((radMeetingType.checked || radNewsType.checked) && 
        txtGoLiveDay.value != "" && txtGoLiveDay.value != "DD" && 
        ddlGoLiveMonth.value != "-1" && 
        txtGoLiveYear.value != "" && txtGoLiveYear.value != "YYYY" && 
        ceContent.value != "")
    {
        args.IsValid = true;
    }
    else
    {
        if (txtGoLiveDay.value == "" || txtGoLiveDay.value == "DD")
        {
            txtGoLiveDay.className = "fielderror";
        }
        if (ddlGoLiveMonth.value == "-1")
        {
            ddlGoLiveMonth.className = "fielderror";
        }
        if (txtGoLiveYear.value == "" || txtGoLiveYear.value == "YYYY")
        {
            txtGoLiveYear.className = "fielderror";
        }
        if (ceContent.value == "")
        {
            ceContent.className = "fielderror";
        }
        
        args.IsValid = false;
    }
}

function NoticeGoLiveDateInvalid_ClientValidate(source, args)
{
    args.IsValid = true;
    
    var txtGoLiveDay = document.getElementById(GetClientId("txtGoLiveDay"));
    var ddlGoLiveMonth = document.getElementById(GetClientId("ddlGoLiveMonth"));
    var txtGoLiveYear = document.getElementById(GetClientId("txtGoLiveYear"));
    var min_year = 1900; //SQL minimum year
    
//    var txtNoticeID = '<%=Request.QueryString("id")%>';
    
    if (txtGoLiveDay.value != "" && txtGoLiveDay.value != "DD" && 
        ddlGoLiveMonth.value != "-1" && 
        txtGoLiveYear.value != "" && txtGoLiveYear.value != "YYYY")
    {
        var _goLiveDate = new Date();
//        var _currentDate = new Date();
//        var _dateTimeNow = new Date();
        
        try
        {
            _goLiveDate.setFullYear(txtGoLiveYear.value, ddlGoLiveMonth.value-1, txtGoLiveDay.value);
//            _currentDate.setFullYear(_dateTimeNow.getFullYear(), _dateTimeNow.getMonth(), _dateTimeNow.getDate());
//            
//            if (txtNoticeID.value == "" || txtNoticeID.value == "0")
//            {
            if (txtGoLiveYear.value < min_year)
            {
                args.IsValid = false;
                txtGoLiveDay.className = "fielderror";
                ddlGoLiveMonth.className = "fielderror";
                txtGoLiveYear.className = "fielderror";
            }
//            }
        }
        catch(e)
        {
            args.IsValid = false;
            txtGoLiveDay.className = "fielderror";
            ddlGoLiveMonth.className = "fielderror";
            txtGoLiveYear.className = "fielderror";
        }
    }
}
//END: Notice Client-Side Functions

//START: Job Client-Side Functions
//IM006684 BMA, NCS - Start
function JobRequiredFields_ClientValidate(source, args)
{
    var txtVacancyOpenDay = document.getElementById(GetClientId("txtVacancyOpenDay"));
    var ddlVacancyOpenMonth = document.getElementById(GetClientId("ddlVacancyOpenMonth"));
    var txtVacancyOpenYear = document.getElementById(GetClientId("txtVacancyOpenYear"));
    var txtVacancyCloseDay = document.getElementById(GetClientId("txtVacancyCloseDay"));
    var ddlVacancyCloseMonth = document.getElementById(GetClientId("ddlVacancyCloseMonth"));
    var txtVacancyCloseYear = document.getElementById(GetClientId("txtVacancyCloseYear"));
    var txtLocation = document.getElementById(GetClientId("txtLocation"));
    var txtSummary = document.getElementById(GetClientId("txtSummary"));
    var ceContent = document.getElementById(GetClientId("ceContent"));
    
    //Initialize className on controls
    txtVacancyOpenDay.className = "search";
    ddlVacancyOpenMonth.className = "search";
    txtVacancyOpenYear.className = "search";
    txtVacancyCloseDay.className = "search";
    ddlVacancyCloseMonth.className = "search";
    txtVacancyCloseYear.className = "search";
    txtLocation.className = "";
    txtSummary.className = "";
    ceContent.className = "";
    
    //Trim entry fields
    txtVacancyOpenDay.value = trim(txtVacancyOpenDay.value);
    txtVacancyOpenYear.value = trim(txtVacancyOpenYear.value);
    txtVacancyCloseDay.value = trim(txtVacancyCloseDay.value);
    txtVacancyCloseYear.value = trim(txtVacancyCloseYear.value);
    txtLocation.value = trim(txtLocation.value);
    txtSummary.value = trim(txtSummary.value);
    ceContent.value = trim(ceContent.value);

    if (txtVacancyOpenDay.value != "" && txtVacancyOpenDay.value != "DD" &&
        ddlVacancyOpenMonth.value != "-1" &&
        txtVacancyOpenYear.value != "" && txtVacancyOpenYear.value != "YYYY" &&
        txtVacancyCloseDay.value != "" && txtVacancyCloseDay.value != "DD" &&
        ddlVacancyCloseMonth.value != "-1" &&
        txtVacancyCloseYear.value != "" && txtVacancyCloseYear.value != "YYYY" && 
        txtLocation.value != "" && txtSummary.value != "" && ceContent.value != "")
    {
        args.IsValid = true;
    }
    else
    {
        if (txtVacancyOpenDay.value == "" || txtVacancyOpenDay.value == "DD")
        {
            txtVacancyOpenDay.className = "fielderror";
        }
        if (ddlVacancyOpenMonth.value == "-1")
        {
            ddlVacancyOpenMonth.className = "fielderror";
        }
        if (txtVacancyOpenYear.value == "" || txtVacancyOpenYear.value == "YYYY")
        {
            txtVacancyOpenYear.className = "fielderror";
        }
        if (txtVacancyCloseDay.value == "" || txtVacancyCloseDay.value == "DD") {
            txtVacancyCloseDay.className = "fielderror";
        }
        if (ddlVacancyCloseMonth.value == "-1") {
            ddlVacancyCloseMonth.className = "fielderror";
        }
        if (txtVacancyCloseYear.value == "" || txtVacancyCloseYear.value == "YYYY") {
            txtVacancyCloseYear.className = "fielderror";
        }
        if (txtLocation.value == "")
        {
            txtLocation.className = "fielderror";
        }
        if (txtSummary.value == "")
        {
            txtSummary.className = "fielderror";
        }
        if (ceContent.value == "")
        {
            ceContent.className = "fielderror";
        }
        
        args.IsValid = false;
    }
}

function JobVacancyOpenDateInvalid_ClientValidate(source, args)
{
    args.IsValid = true;

    var txtVacancyOpenDay = document.getElementById(GetClientId("txtVacancyOpenDay"));
    var ddlVacancyOpenMonth = document.getElementById(GetClientId("ddlVacancyOpenMonth"));
    var txtVacancyOpenYear = document.getElementById(GetClientId("txtVacancyOpenYear"));
    var min_year = 1900; //SQL minimum year
    
//    var txtJobID = '<%=Request.QueryString("id")%>';

    if (txtVacancyOpenDay.value != "" && txtVacancyOpenDay.value != "DD" &&
        ddlVacancyOpenMonth.value != "-1" &&
        txtVacancyOpenYear.value != "" && txtVacancyOpenYear.value != "YYYY")
    {
        var _vacancyOpenDate = new Date();
//        var _currentDate = new Date();
//        var _dateTimeNow = new Date();
        
        try
        {
            _vacancyOpenDate.setFullYear(txtVacancyOpenYear.value, ddlVacancyOpenMonth.value, txtVacancyOpenDay.value);
//            _currentDate.setFullYear(_dateTimeNow.getFullYear(), _dateTimeNow.getMonth(), _dateTimeNow.getDate());
//            
//            if (txtJobID.value == "" || txtJobID.value == "0")
//            {
            if (txtVacancyOpenYear.value < min_year)
            {
                args.IsValid = false;
                txtVacancyOpenDay.className = "fielderror";
                ddlVacancyOpenMonth.className = "fielderror";
                txtVacancyOpenYear.className = "fielderror";
            }
//            }
        }
        catch(e)
        {
            args.IsValid = false;
            txtVacancyOpenDay.className = "fielderror";
            ddlVacancyOpenMonth.className = "fielderror";
            txtVacancyOpenYear.className = "fielderror";
        }
    }
}

function JobVacancyCloseDateInvalid_ClientValidate(source, args) {
    args.IsValid = true;

    var txtVacancyCloseDay = document.getElementById(GetClientId("txtVacancyCloseDay"));
    var ddlVacancyCloseMonth = document.getElementById(GetClientId("ddlVacancyCloseMonth"));
    var txtVacancyCloseYear = document.getElementById(GetClientId("txtVacancyCloseYear"));
    var min_year = 1900; //SQL minimum year

    //    var txtJobID = '<%=Request.QueryString("id")%>';

    if (txtVacancyCloseDay.value != "" && txtVacancyCloseDay.value != "DD" &&
        ddlVacancyCloseMonth.value != "-1" &&
        txtVacancyCloseYear.value != "" && txtVacancyCloseYear.value != "YYYY") {
        var _vacancyCloseDate = new Date();
        //        var _currentDate = new Date();
        //        var _dateTimeNow = new Date();

        try {
            _vacancyCloseDate.setFullYear(txtVacancyCloseYear.value, ddlVacancyCloseMonth.value, txtVacancyCloseDay.value);
            //            _currentDate.setFullYear(_dateTimeNow.getFullYear(), _dateTimeNow.getMonth(), _dateTimeNow.getDate());
            //            
            //            if (txtJobID.value == "" || txtJobID.value == "0")
            //            {
            if (txtVacancyCloseYear.value < min_year) {
                args.IsValid = false;
                txtVacancyCloseDay.className = "fielderror";
                ddlVacancyCloseMonth.className = "fielderror";
                txtVacancyCloseYear.className = "fielderror";
            }
            //            }
        }
        catch (e) {
            args.IsValid = false;
            txtVacancyCloseDay.className = "fielderror";
            ddlVacancyCloseMonth.className = "fielderror";
            txtVacancyCloseYear.className = "fielderror";
        }
    }
}

function JobVacancyDateCompare_ClientValidate(source, args) {
    args.IsValid = true;

    var txtVacancyOpenDay = document.getElementById(GetClientId("txtVacancyOpenDay"));
    var ddlVacancyOpenMonth = document.getElementById(GetClientId("ddlVacancyOpenMonth"));
    var txtVacancyOpenYear = document.getElementById(GetClientId("txtVacancyOpenYear"));

    var txtVacancyCloseDay = document.getElementById(GetClientId("txtVacancyCloseDay"));
    var ddlVacancyCloseMonth = document.getElementById(GetClientId("ddlVacancyCloseMonth"));
    var txtVacancyCloseYear = document.getElementById(GetClientId("txtVacancyCloseYear"));

    if (txtVacancyOpenDay.value != "" && txtVacancyOpenDay.value != "DD" &&
        ddlVacancyOpenMonth.value != "-1" &&
        txtVacancyOpenYear.value != "" && txtVacancyOpenYear.value != "YYYY" &&
        txtVacancyCloseDay.value != "" && txtVacancyCloseDay.value != "DD" &&
        ddlVacancyCloseMonth.value != "-1" &&
        txtVacancyCloseYear.value != "" && txtVacancyCloseYear.value != "YYYY") 
    {
        var _vacancyOpenDate = new Date();
        var _vacancyCloseDate = new Date();

        try {
            _vacancyOpenDate.setFullYear(txtVacancyOpenYear.value, ddlVacancyOpenMonth.value, txtVacancyOpenDay.value);
            _vacancyCloseDate.setFullYear(txtVacancyCloseYear.value, ddlVacancyCloseMonth.value, txtVacancyCloseDay.value);

            if (_vacancyOpenDate > _vacancyCloseDate) {
                args.IsValid = false;
                txtVacancyCloseDay.className = "fielderror";
                ddlVacancyCloseMonth.className = "fielderror";
                txtVacancyCloseYear.className = "fielderror";
            }
        }
        catch (e) { /*DDA*/ }
    }
}
//IM006684 BMA, NCS - End

function JobSummaryMaximum_ClientValidate(source, args)
{
    args.IsValid = true;
    
    var txtSummary = document.getElementById(GetClientId("txtSummary"));
    
    txtSummary.value = trim(txtSummary.value);
    
    if(txtSummary.value != "")
    {
        if(txtSummary.value.length > 1024)
        {
            args.IsValid = false;
        }
    }
}
//END: Job Client-Side Functions

//END: 25-Aug-2009   WO089.R03 MJR, NCS