/**
 *  Name:       common-functions-public.js
 *  Company:    DFT ICMS, IBM BCS
 *  @author:    All
 *  @version:   $Revision:$ $Date:$
 *
 *  Description: 
 *  This JavaScript include contains common functions. This file
 *  is similar to the internal commonfunctions.js
 **/

// Given the name of a list box, return
// false if no value was chosen. Sets focus on field
// but no message is displayed

function checkSelectListNoMsg(field)
{
    var bReturn = true;
    if (field.options[field.selectedIndex].value == "")
    {
        bReturn = false;
        field.focus();
    }
    return bReturn;
}

// Given the name of a multiselect list box, return
// false if no value was chosen. Sets focus on field
// but no message is displayed

function checkMultiSelectListNoMsg(field)
{
    var bReturn = true;
    if (field.selectedIndex == -1)
    {
        bReturn = false;
        field.focus();
    }
    return bReturn;
}


// Given the name of a list box, return
// false if no value was chosen. Display an error message
// and set focus on field

function checkSelectListFullMsg(field, msg)
{
    var bReturn = checkSelectListNoMsg(field);
    if (!bReturn)
    {
        alert(msg);
    }
    return bReturn;
}

// Checks that the contents of 'field' has an exact size of 'size'
// Uses a regular expression to check the string.

function exactNoMsg (size, field)
{
    var re= new RegExp("^.{"+size+","+size+"}$");
    var bReturn = false;
    if (re.test(field.value))
    {
        bReturn = true;
    }

    return bReturn;
}

// Checks that the contents of 'field' is a positive integer.

function isInteger(field)
{
    var bReturn = false;
    re = /^\d+$/
    if (re.test(field.value))
    {
        bReturn = true;
        field.select();
    }
    return bReturn;
}

// gets the selected value of the radio buttons or returns null
// if none is selected.

function getRadioValue(rdoButton)
{
    var sValue = null;
    for (i=0; i < rdoButton.length;i++)
    {
        if (rdoButton[i].checked)
        {
            sValue = rdoButton[i].value;
        }
    }
    return sValue;
}


// sets the value of the radio button

function setRadioValue(rdoButton, value)
{
    for (i=0; i < rdoButton.length;i++)
    {
        if (rdoButton[i].value==value)
        {
            rdoButton[i].checked=true;
        }
    }
}


// disables all elements in a radio set.

function onoffRadioValue(rdoButton, bTrueFalse)
{
    for (i=0; i < rdoButton.length; i++)
    {
        rdoButton[i].disabled=bTrueFalse;
    }
}

// clears all elements in a radio set.

function clearRadioValue(rdoButton)
{
    for (i=0; i < rdoButton.length; i++)
    {
        rdoButton[i].checked=false;
    }
}

// gets the selected value of the select box or returns null
// if none is selected.
function getSelectValue(select)
{
    if (select.selectedIndex != null &&
          select.selectedIndex >= 0)
    {
        return select.options[select.selectedIndex].value;
    }
    return null;
}


// gets the selected values of the multi select
// box in an Array or returns an empty Array
// if none is selected.
function getMultiSelectValue(field)
{

    var aSelected = new Array();

    for (var i=0; i<field.options.length; i++)
    {
        if (field.options[i].selected == true)
        {
            aSelected.push(field.options[i].value);
        }
    }

    return aSelected;

}


// Check field is not null - used for radio buttons
// Display message and return false / set focus if
// it is null

function checkNull(field, msg)
{
    var bReturn = checkNullFullMsg(field,"Please select a value for "+msg);

    return bReturn;
}

// Check field is not null - used for radio buttons
// Display message and return false / set focus if
// it is null

function checkNullFullMsg(field, msg)
{
    var bReturn = true;
    var bChosen = false;

    for (i=0; i<field.length;i++)
    {
        if (field[i].checked)
        {
            bChosen=true;
        }
    }
    if (!bChosen)
    {
        bReturn=false;
        alert(msg);
    }
    return bReturn;
}


// Returns true if string s is empty
function isEmpty(string)
{
    stringValue = string.value;
    return ((stringValue == null) || (stringValue.length == 0));
}


// Returns true if character c is an English letter (A .. Z, a..z)

function isLetter(character)
{
    return (((character >= "a") && (character <= "z")) || ((character >= "A") && (character <= "Z")));
}


// Returns true if character c is a digit (0 .. 9)

function isDigit(character)
{
    return ((character >= "0") && (character <= "9"));
}


// Returns true if string s is English letters (A .. Z, a..z) only

function isAlphabetic(field)
{
    var i;

    var string = field.value;

    if (isBlank(field))
    {
        return false;
    }

    // Search through string's chars one by one until we find a
    // non-alphabetic char, then return false; if we don't, return true

    for (i = 0; i < string.length; i++)
    {
        // Check that current character is letter
        var c = string.charAt(i);

        if ((!isLetter(c)) && (c !=' ') && (c !='\t'))
        return false;
    }

    // All characters are letters
    return true;
}


// Returns true if string s is English letters (A .. Z, a..z) and numbers only

function isAlphanumeric(field)
{
    var i;
    var string = field.value;

    if (isBlank(field))
    {
        return false;
    }

    // Search through string's chars one by one until we find a
    // non-alphanumeric char, then return false; if we don't, return true

    for (i = 0; i < string.length; i++)
    {
        // Check that current character is number or letter
        var cChar = string.charAt(i);

        if (! (isLetter(cChar) || isDigit(cChar) ) )
        {
            return false;
        }
    }

    // All characters are numbers or letters
    return true;
}


// Returns true if string contained in Text Object 'field' is empty or all blank chars
// Method checks for blanks ie " " and tabs.

function isBlank(field)
{
    // check if the field contains an Empty String
    var bReturn = isEmpty(field);

    // the field may contain white space
    if (bReturn == false)
    {
        fieldValue = field.value;

        // Search through string's chars one by one
        // Stop if we have found a non-whitespace char

        var blanks = " \t\n\r";
        var nCounter = 0;

        bReturn = true;
        while ((nCounter < fieldValue.length) && (bReturn == true))
        {
            // Check that current character isn't blank
            var cChar = fieldValue.charAt(nCounter);
            if (blanks.indexOf(cChar) == -1)
            {
                bReturn = false;
            } // end if

            nCounter++;
        } // end for
    } // end if

    return bReturn;
} // end method

// Trims white space from the start and end of a string.
// Uses a regular expression replace that skips over all white space at the start
// and end and only keeps the middle.

function trim(field)
{
    field.value = field.value.replace(/^\s*((\S|.)*\S)\s*$/, '$1');
}

// Checks that the contents of 'field' is a number.  The number may or may not contain
// a decimal place.  The number of decimal places is not limited.

function isNumeric (field)
{
    var bReturn = false;
    re = /^\d*\.?\d+$/
    if (re.test(field.value))
    {
        bReturn = true;
    }
    return bReturn;
}

// Checks if the date entered is greater than today's date. Returns false
// if this is true.

function afterToday(dayField, monthField, yearField, msg)
{
    var bReturn = afterTodayNoMsg(dayField, monthField, yearField);

    if (!bReturn)
    {
        alert(msg);
        dayField.focus();
    }

    return bReturn;
}

// Basically the same function as above, but you don't need to provide
// a message, and the focus can be set explicitly outside this function.

function afterTodayNoMsg(dayField, monthField, yearField)

{
    var bReturn = true;
    var today = new Date();
    var date = new Date(yearField.value, monthField.value-1, dayField.value);
    if (date > today)
    {
        bReturn = false;
    }
    return bReturn;
}

// Checks if the entered date adheres to the format DD/MM/YYYY
// and the date is before today's date.
// Uses isValidDateFormat.
function isValidDateAndBeforeToday(sDate)
{
 var bValid = false;
 var sDateValue = sDate.value;

 if (isValidDateFormat(sDateValue))
 {
     // Read in a date with a DD/MM/YYYY format.
     sDay = sDateValue.substring(0, 2);
     sMonth = sDateValue.substring(3, 5);
     sYear = sDateValue.substr(6);

     var formDate = new Date(sYear, sMonth - 1, sDay)
     var todaysDate = new Date()

     if (todaysDate > formDate)
     {
         bValid = true;
     }
 }

return bValid;
} // End isValidDateAndBeforeToday


// Checks if the entered date adheres to the format DD/MM/YYYY
// and the date is after today's date and optionally equal to
// today's date (based on bEqual parameter)
// Uses isValidDateFormat.
function isValidDateAndAfterToday(sDate, bEqual)
{
 var bValid = false;
 var sDateValue = sDate.value;

 if (isValidDateFormat(sDateValue))
 {
     // Read in a date with a DD/MM/YYYY format.
     sDay = sDateValue.substring(0, 2);
     sMonth = sDateValue.substring(3, 5);
     sYear = sDateValue.substr(6);

     var formDate = new Date(sYear, sMonth - 1, sDay)
     var todaysDate = new Date()

     todaysDate.setHours(0)
     todaysDate.setMinutes(0)
     todaysDate.setSeconds(0)
     todaysDate.setMilliseconds(0)


     if ((bEqual && (formDate >= todaysDate)) || (!bEqual && (formDate > todaysDate)))
     {
         bValid = true;
     }
 }

 return bValid;
} // End isValidDateAndAfterToday

// This function determines whether an email address is valid based on the
// following business rules:
// - must contain exactly one "@"
// - must contain at least one "." after the "@"
// - blank email address is counted as valid

function isValidEmailAddress(field)
{
    var bReturn = true;
    var value = field.value;

    if (value!="")
    {
        // Check at least one "@"
        if (value.indexOf("@") == -1)
        {
            bReturn = false;
        }
        else
        {
            var sEndOfEmail = value.substring(value.indexOf("@")+1, value.length);

            // Check only one "@"
            if (sEndOfEmail.indexOf("@")!=-1)
            {
                bReturn = false;
            }
            else
            {
                // Check at least one "." after "@"
                var nNumberPeriods = 0;
                while (sEndOfEmail.indexOf(".") != -1)
                {
                    sEndOfEmail = sEndOfEmail.substring(sEndOfEmail.indexOf(".")+1, sEndOfEmail.length);
                    nNumberPeriods++;
                }

                if (nNumberPeriods < 1)
                {
                     bReturn = false;
                }
            }
        }
    }
    return bReturn;
}




var dtCh= "/";
var minYear=1900;
var maxYear=9999; // AS 21/05/2003 TPR 568 - max year increased


// this function check if a string is an integer
function isInt(s){
    var i;
    for (i = 0; i < s.length; i++){
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}

function stripCharsInBag(s, bag){
    var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++){
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function daysInFebruary (year){
    // February has 29 days in any year evenly divisible by four,
    // EXCEPT for centurial years which are not also divisible by 400.
    return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}
function DaysArray(n) {
    for (var i = 1; i <= n; i++) {
        this[i] = 31
        if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
        if (i==2) {this[i] = 29}
   }
   return this
}

// expects date format of dd/mm/yyyy
// if the type is beforetoday it returns true if it is a valid date and the date is before today
// if the type is aftertoday then it returns true if it is a valid date and the date is after today
function isDate(dtStr, type)
{
    bReturn = true;

    var daysInMonth = DaysArray(12);
    var pos1=dtStr.indexOf(dtCh);
    var pos2=dtStr.indexOf(dtCh,pos1+1);
    var strDay=dtStr.substring(0,pos1);
    var strMonth=dtStr.substring(pos1+1,pos2);
    var strYear=dtStr.substring(pos2+1);
    strYr=strYear;

    var today = new Date();
    today.setHours(0);
    today.setMinutes(0);
    today.setSeconds(0);
    today.setMilliseconds(0);



    if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
    if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
    for (var i = 1; i <= 3; i++) {
        if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1);
    }
    month=parseInt(strMonth);
    day=parseInt(strDay);
    year=parseInt(strYr);

    if (pos1==-1 || pos2==-1){
        bReturn =  false;
    }
    else if (strMonth.length<1 || month<1 || month>12){
        bReturn =  false;
    }
    else if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
        bReturn =  false;
    }
    else if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
        bReturn =  false;
    }
    else if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInt(stripCharsInBag(dtStr, dtCh))==false){

        bReturn =  false;
    }

    if(type == "beforetoday")
    {
        var thisDate = new Date(year, month-1, day);
        if(thisDate > today)
        {
            bReturn = false;
        }

    }
    else if(type== "aftertoday")
    {
        var thisDate = new Date(year, month-1, day);
        if(thisDate < today)
        {
            bReturn = false;
        }

    }

return bReturn;
}



//  Checks if the entered time adheres to
//  the format h:mm a. Returns true if the
//  value is of the proper format, false otherwise.
//
//  @param  String  The time value to check.
function isTime(sTmp)
{
    iTmp1 = sTmp.indexOf(":");
    if (iTmp1 == -1)
    {
        bValid = false;
    }
    else
    {
        sTmp1 = sTmp.substr(0, iTmp1);
        sTmp2 = sTmp.substr(iTmp1 + 1);

        iTmp2 = sTmp2.toUpperCase().indexOf("AM");

        if (iTmp2 == -1)
        {
            iTmp2 = sTmp2.toUpperCase().indexOf("PM");
        }

        if (iTmp2 == -1)
        {
            bValid = false;
        }
        else
        {
            sTmp3 = sTmp2.substr(0, iTmp2);

            bValid = ((!isNaN(sTmp1)) &&
                     (!isNaN(sTmp3)) &&
                     (sTmp1>=0) &&
                     (sTmp1<13) &&
                     (sTmp3>=0) &&
                     (sTmp3<60));
        }
    }

    return bValid;
}


//  Checks if the entered date adheres to
//  the format DD/MM/YYYY. Returns true if the
//  value is of the proper format, false otherwise.
//
//  @param  String  The date value to check.
function isValidDateFormat(sDate)
{
    //var objRegExp = /^\d{1,2}(\-|\/|\.)\d{1,2}\1\d{4}$/;
    var objRegExp = /^\d{1,2}(\/)\d{1,2}\1\d{4}$/;

    return objRegExp.test(sDate);
} // End isValidDateFormat


// Moves a div identified by menuid to the top position specified by pos.
function moveMenu(menuid,pos)
{
    if (document.all[menuid]!=null && document.all[menuid].style!=null)
        document.all[menuid].style.top=pos;
}

// Invoked each time a new iframe gains focus or the user mouses over a layout table cell
function setTab(sTab, sImagePath)
{
  if (window.top && window.top.document.images['Administrative_Details'])
  {
      switch (sTab)
      {

        case "admin" :
            window.top.document.images['Administrative_Details'].src= sImagePath + "admintabselected.gif";
            window.top.document.images['Customer_Details'].src= sImagePath +"customertab.gif";
            window.top.document.images['Trader_Details'].src= sImagePath +"tradertab.gif";
            window.top.document.images['Complaint_Details'].src= sImagePath +"complainttab.gif";
        break;

        case "customer":
            window.top.document.images['Administrative_Details'].src= sImagePath + "admintab.gif";
            window.top.document.images['Customer_Details'].src= sImagePath + "customertabselected.gif";
            window.top.document.images['Trader_Details'].src= sImagePath + "tradertab.gif";
            window.top.document.images['Complaint_Details'].src= sImagePath + "complainttab.gif";
        break;

        case "trader":
            window.top.document.images['Administrative_Details'].src= sImagePath + "admintab.gif";
            window.top.document.images['Customer_Details'].src= sImagePath + "customertab.gif";
            window.top.document.images['Trader_Details'].src= sImagePath + "tradertabselected.gif";
            window.top.document.images['Complaint_Details'].src= sImagePath + "complainttab.gif";
        break;

        case "complaint":
            window.top.document.images['Administrative_Details'].src= sImagePath + "admintab.gif";
            window.top.document.images['Customer_Details'].src= sImagePath + "customertab.gif";
            window.top.document.images['Trader_Details'].src= sImagePath + "tradertab.gif";
            window.top.document.images['Complaint_Details'].src= sImagePath + "complainttabselected.gif";
        break;

        default:
            window.top.document.images['Administrative_Details'].src= sImagePath + "admintabselected.gif";
            window.top.document.images['Customer_Details'].src= sImagePath + "customertab.gif";
            window.top.document.images['Trader_Details'].src= sImagePath + "tradertab.gif";
            window.top.document.images['Complaint_Details'].src= sImagePath + "complainttab.gif";
        break;

      }
  }
}


//define global array to keep track of the windows open
ICMSOpenWindows = new Array();
// General method to launch a new Javascipt window in ICMS
function launchICMSWindow(windowURL)
{
    // todo window open options need to be modified
    var sWindowOptions = "dependant";
    var WINDOW_NAME_BASE="icmsWindow" + ICMSOpenWindows.length;
    var WINDOW_FEATURES ="scrollbars=no,resizable=yes";

    var newWindow = window.open(windowURL, WINDOW_NAME_BASE, WINDOW_FEATURES);
    ICMSOpenWindows[ICMSOpenWindows.length]= newWindow;

}
// AS 20/05/2003 TPR 455 - overloaded method to open admin windows with special needs.
function launchICMSWindow(windowURL,sWindowName,sOptions)
{      
    var newWindow = window.open(windowURL, sWindowName, sOptions);
    ICMSOpenWindows[ICMSOpenWindows.length]= newWindow;
    return newWindow;
}
// global variable required for setHelpId and icmsHelp functions
var sHelpId="";

// Invoked each time a new iframe gains focus or the user mouses over a layout table cell
function setHelpId(sHelp)
{
    sHelpId = sHelp;

}

// Invoked when the user presses the F1 key
function icmsHelp(icmsHelpUrl)
{
    // disable the IE F1 help event
    event.keyCode = 0;
    event.returnValue = false;
    event.cancelBubble = true;


    // open the ICMS Help window
    href = icmsHelpUrl + "?helpid=" + sHelpId;
    var icmsHelpWindow = window.open(href, "icmsHelp", 'width=500, height=500');

    return;
}
// This handler captures the F1 key press
document.onhelp = function() {
    var sPath = window.location.pathname;0
    var sAppPath = sPath.substring(0,sPath.indexOf("/",1));
    icmsHelp(sAppPath + '/common/pres/help.sjsp');
}

// This function invokes the Postcode-suburb lookup if applicable
function postcodeSuburbLookup(searchType, postcodeFieldName, suburbFieldName, stateFieldName, formName, frameName)
{
            var lookupValue;



           // if it is a postcode search
            if(searchType == "postcode")
            {
                lookupValue = document.forms[formName].elements[postcodeFieldName].value;
            }
            // if its not a postcode search
            else
            {
                lookupValue = document.forms[formName].elements[suburbFieldName].value;
            }
            // set the field on the hidden form
            document.PostcodeSuburbForm.hdnPostcodeField.value = postcodeFieldName;
            document.PostcodeSuburbForm.hdnSuburbField.value = suburbFieldName;
            document.PostcodeSuburbForm.hdnFormName.value = formName;
            document.PostcodeSuburbForm.hdnLookupValue.value = lookupValue;
            document.PostcodeSuburbForm.hdnSearchType.value = searchType;
            document.PostcodeSuburbForm.hdnStateField.value = stateFieldName;
            document.PostcodeSuburbForm.hdnFrameName.value = frameName;


            // submit the form
            document.PostcodeSuburbForm.submit();


 }


// This function enables/disables quickpicks
function setQuickPicksDisabled(bDisabledState)
{
    for (i = 0; i < window.top.document.all.quickPicksForm.elements.length; i++)
    {

        window.top.document.all.quickPicksForm.elements[i].disabled=bDisabledState;
        if (bDisabledState==true)
        {
            window.top.document.all.quickPicksForm.elements[i].className="quickpickbuttondisabled";
        }
        else
        {
            window.top.document.all.quickPicksForm.elements[i].className="quickpickbutton";
        }
    }
}


//
//  Deterines if the entered date is valid:
//  A valid date being dd/mm/yyy. And valid ie. not 55/05/2003.
//
function isValidDate(dtStr)
{
    bReturn = true;

    var daysInMonth = DaysArray(12);
    var pos1=dtStr.indexOf(dtCh);
    var pos2=dtStr.indexOf(dtCh,pos1+1);
    var strDay=dtStr.substring(0,pos1);
    var strMonth=dtStr.substring(pos1+1,pos2);
    var strYear=dtStr.substring(pos2+1);
    strYr=strYear;
    var today = new Date();
    if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
    if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
    for (var i = 1; i <= 3; i++) {
        if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1);
    }
    month=parseInt(strMonth);
    day=parseInt(strDay);
    year=parseInt(strYr);

    if (pos1==-1 || pos2==-1){
        bReturn =  false;
    }
    else if (strMonth.length<1 || month<1 || month>12){
        bReturn =  false;
    }
    else if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
        bReturn =  false;
    }
    else if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
        bReturn =  false;
    }
    else if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInt(stripCharsInBag(dtStr, dtCh))==false){

        bReturn =  false;
    }

    return bReturn;
} // End isValidDate


//
// Function that compares 2 dates. If Date 2 is >= Date 1
// then return true, else false.
//
function dateCompare(sDate1, sDate2)
{
    var daysInMonth = DaysArray(12);
    bReturn = true;

    // DATE 1 - Initial.
    var pos1=sDate1.indexOf(dtCh);
    var pos2=sDate1.indexOf(dtCh,pos1+1);
    var strDay1=sDate1.substring(0,pos1);
    var strMonth1=sDate1.substring(pos1+1,pos2);
    var strYear1=sDate1.substring(pos2+1);
    strYr1=strYear1;

    if (strDay1.charAt(0)=="0" && strDay1.length>1) strDay1=strDay1.substring(1)
    if (strMonth1.charAt(0)=="0" && strMonth1.length>1) strMonth1=strMonth1.substring(1)
    for (var i = 1; i <= 3; i++) {
        if (strYr1.charAt(0)=="0" && strYr1.length>1) strYr1=strYr1.substring(1);
    }
    month1=parseInt(strMonth1);
    day1=parseInt(strDay1);
    year1=parseInt(strYr1);

    // DATE 2 - Initial.
    pos1=sDate2.indexOf(dtCh);
    pos2=sDate2.indexOf(dtCh,pos1+1);
    var strDay2=sDate2.substring(0,pos1);
    var strMonth2=sDate2.substring(pos1+1,pos2);
    var strYear2=sDate2.substring(pos2+1);
    strYr2=strYear2;

    if (strDay2.charAt(0)=="0" && strDay2.length>1) strDay2=strDay2.substring(1)
    if (strMonth2.charAt(0)=="0" && strMonth2.length>1) strMonth2=strMonth2.substring(1)
    for (var i = 1; i <= 3; i++) {
        if (strYr2.charAt(0)=="0" && strYr2.length>1) strYr2=strYr2.substring(1);
    }
    month2=parseInt(strMonth2);
    day2=parseInt(strDay2);
    year2=parseInt(strYr2);

    //alert("dateCompare: Date1 - day = " + day1 + " - month = " + month1 + " - year = " + year1);
    //alert("dateCompare: Date2 - day = " + day2 + " - month = " + month2 + " - year = " + year2);

    var dteDate1 = new Date(year1, month1-1, day1);
    var dteDate2 = new Date(year2, month2-1, day2);

    if(dteDate1 > dteDate2)
    {
        //alert("dateCompare: DATE1 > DATE2");
        bReturn = false;
    }

    return bReturn;
} // End function dateCompare


// check minimunm size of phone numbers
function checkPhone(sType, fField)
{
    var bReturn = true;

    if (!isBlank(fField))
    {
        // Amanda Wong 13/5/04 WR58 minimum changed to 6
        var nMinLength = 6;
        // End WR58
        
        var sMessage   = "";

        if (sType == 'mobile')
        {
            nMinLength = 10;
            sMessage   = "Mobile phone numbers must be at least " + nMinLength + " digits long.";
        }
        else
        {
            // Amanda Wong 13/5/04 WR58 minimum changed to 6
            var nMinLength = 6;
            // End WR58
            
            var sMessage   = "Phone numbers must be at least " + nMinLength + " digits long.";
        } // end-if

        if (fField.value.length < nMinLength)
        {
            alert(sMessage);
            fField.focus();
            bReturn = false;
        } // end-if
    }

    return bReturn;
}

// Watches for the enter key. It will attempt to click on the Next
function listenEnterKey()
{
    var bReturn   = true;
    var nKeycode  = event.keyCode;

    if(nKeycode == 13)
    {
        var oCallingOject = event.srcElement;

        try
        {
            if (oCallingOject.type != "textarea" &&
                oCallingOject.className != "searchBox")
            {
                var oNextButton = document.getElementById("nextButton");
                // Submits Next if exists
                if (oNextButton != null)
                {
                    bReturn = false;
                    oNextButton.click();
                
                } // end-if
            } // end-if         
        }
        catch (eException)
        {
        } // end try

    }


    return bReturn;    
}

