// VARIABLE DECLARATIONS

var digits = "0123456789";
var lowercaseLetters = "abcdefghijklmnopqrstuvwxyz"
var uppercaseLetters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
var bag = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890_-/ "
// whitespace characters
var whitespace = " \t\n\r";

var mPrefix = "You did not enter a value into the "
var sPrefix = "You did not select a value from the "
var mSuffix = " field."
var sSuffix = " box."
var iEmail = "This field must be a valid email address (like joe.bloggs@google.com). Please enter it again now."
var iURL = "This field must be a valid web address (like http://www.google.co.uk). It must start with http:// or https:// and have at least one '.' in it. Please enter it again now."
var sdkAllPages = "You didn't check the all pages box or select a page to administer."
var iWorldPhone = "Please enter the international phone number in the format +442085554567, using no spaces or brackets."
var iPhone = "Please enter the phone number in the format 020 8555 4567, using only numbers and spaces."
var iConfirmPassword = "Your password and confirm password fields do not match. Please enter them again now."

// s is an abbreviation for "string"

var sTitle = "Title"
var sUSLastName = "Last Name"
var sUSFamilyName = "Family Name"
var sUSFirstName = "First Name"
var sFullName = "Full Name"
var sHouseNumber = "House name or number"
var sStreetName = "Street name"
var sTown = "Town"
var sCounty = "County"
var sPostcode = "Postcode"
var sCountry = "Country"
var sFax = "fax number"
var sPhone = "telephone number"
var sMobile = "Mobile Phone Number"
var sEmail = "Email"
var sdkEmail = "Email"
var sCompanyName = "Company Name"
var sDepartment = "Company Department"
var sJobTitle = "Job Title"
var sCompanyBuildingNumber = "Building name or number"
var sCompanyStreetName = "Company street name"
var sCompanyTown = "Company Town"
var sCompanyCounty = "Company County"
var sCompanypostcode = "Company Postcode"
var sCompanyCountry = "Company Country"
var sCompanyFax = "Company Fax"
var sCompanyTelephone = "Company Telephone"
var sTerms = "Terms and Conditions"


var sCompanySpeaker = "Company Speaker"
var sCompanyTopics = "Company Topics"
var sCompanyFunction = "function"
var sFirmType = "Firm Type"

// Not used in this example
var sDateOfBirth = "Date of Birth"
var sWorldLastName = "Family Name"
var sWorldFirstName = "Given Name"
var sStateCode = "State Code"
var sZIPCode = "ZIP Code"
var sExpirationDate = "Expiration Date"
var sWorldState = "State, Province, or Prefecture"
var sSSN = "Social Security Number"
var sCreditCardNumber = "Credit Card Number"
var sOtherInfo = "Other Information"
var sPassword = "Password"
var sConfirmPassword = "Confirm Password"
var sUsername = "Username"
var sLogon = "Network Logon"


var sspServiceName = "name of service"
var sspServiceOtherNames = "other name of service"
var sspServiceDescription = "service description"
var sspServiceDocumentLibrary = "service document library"
var sspServiceInternetUrl = "service internet web address"
var sspServiceIntranetUrl = "service intranet web address"

var sspProblemTitle = "title"
var sspProblemDescription = "description"
var sspAffected = "affected group"
var sspStaffID = "submitted by"
var sspJobRef = "job reference code"
var sspDepartment = "department"
var sspOrganisation = "organisation"
var sspLocationCode = "location code"
var sspDirectorate = "directorate";
var sspManager = "manager";
var sspAlternativeContact = "alternative contact";
var sspNHSCode = "NHS code"
var sspEmailName = "email name"
var sspMessage = "email message"
var sspEmailSubject = "email subject"
var sspEmailList = "group of email recipients"
var sspKeywords = "keywords"
var sspSearch = "search"
var sspSalary = "salary"
var sspGrade = "grade"
var sspType = "type"
var sspClosingDate = "closing date"
var sspDescFile = "job description file"
var sspInternal = "internal or external information"
var sspContactName = "contact name"
var sspRegion = "region"
var sspAddress = "address"
var sspAdditionalField = "additional field name"
var sspGeneral = ""
var sspPageTitle = "page title"

var sspPracticeCode = "practice code"
var sspSiteName = "web site title"
var sspDomainName = "web site title"
var sspAdministratorName = "name"
var sspAdministratorEmail = "email"
var sspPCT = "your PCT"
var sspTemplate = "site template"
var PageLink = "page link"
var Groups = "current groups"
var sspPluginPage = "plugin page"


var sdkDocumentName = "document to add"
var sdkNewDocument = "new document"
var sdkDocumentTitle = "document title"
var sdkDocumentFile = "file"
var sdkDocumentAuthorName = "document author name"
var sdkDocumentAuthorEmail = "document author email"
var sdkDocumentResourceType = "document resource type"
var DocumentDescription = "document description"
var DocumentKeywords = "document keywords"
var DocumentPublisher = "document publisher"
var DocumentFoiCategory = "document FOI category"
var DocumentFoiAnnotation = "document FOI annotation"
var sdkFeedbackType = "feedback type"

var sdkVoteQuestion = "vote question"
var sdkVoteAnswers = "vote answers"
var sdkVoteAnswers = "vote answers"

var sdkLinkTitle = "link title"
var sdkLinkText = "link text"
var sdkLinkURL = "link or external link"
var sdkLinkDesc = "link description"

var sdkBulletinTitle = "bulletin title"
var sdkBulletinMessage = "bulletin message"
var sdkBulletinAuthorName = "bulletin author name"
var sdkBulletinAuthorEmail = "bulletin author email"

var sdkNewsTitle = "news title"
var sdkNewsContents = "news contents"

var sdkLocation = "location"
var sdkOrganisation = "organisation"

var sdkGroupName = "group name"
var sdkGroupDescription = "group description"

var sdkAdditionalField = "additional field"

var sdkPages = "pages to administer"

var sdkPluginName = "plugin name"
var sdkPluginDescription = "plugin description"
var sdkPluginURL = "plugin web site address"
var sdkTemplate = "Please select one or more template components and choose a template for the page"
var sdkPluginMessage = "Please select a plug-in page. If there are no plug-in pages contact an administrator to add a plug-in."


var sdkImageTitle = "image title"
var sdkImageFile = "image file"
var sdkEvent = "event"
var sdkComments = "comments"
var pEntryPrompt = "Please enter a "
var defaultEmptyOK = false

var sdkBasepath = "BASEPATH"
var sdkDatabaseName = "database name"
var sdkDatabaseUsername = "database username"
var sdkDatabasePassword = "database password"
var sdkBasehref = "basehref"

var sdkEventTitle = "event title"
var sdkBriefSummary = "brief summary"
var sdkDetailedSummary = "detailed summary"
var sdkLocationName = "location name"
var sdfLocationAddress = "location address"
var sdkOrganiserTitle = "organiser title"
var sdkOrganiserFirstName = "organiser first name"
var sdkOrganiserLastName = "organiser last name"
var sdkOrganiserEmailAddress = "organiser email address"
var sdkOrganiserTelephone = "organiser telephone number"

var sdkEventHour = "hour"
var sdkEventMinute = "minute"
var sdkEventDay = "day"
var sdkEventMonth = "month"
var sdkEventYear = "year"

var sdkStaffMember = "staff member"
var sdkPeopleFinder = "people finder"

// Notify user that required field theField is empty.
// String s describes expected contents of theField.value.
// Put focus in theField and return false.

function warnEmpty (theField, s)
{   theField.focus()
    alert(mPrefix + s + mSuffix)
    return false
}

function warnSelectEmpty (theField, s)
{		alert(sPrefix + s + sSuffix)
    return false
}

function warnCheckBoxEmpty (theField, s)
{		alert(sPrefix + s + sSuffix)
    return false
}

function warnHiddenEmpty (theField, s)
{		alert(sPrefix + s + sSuffix)
    return false
}

// FUNCTIONS TO INTERACTIVELY CHECK VARIOUS FIELDS.

// checkString (TEXTFIELD theField, STRING s, [, BOOLEAN emptyOK==false])
//
// Check that string theField.value is not all whitespace.
//
// For explanation of optional argument emptyOK,
// see comments of function isInteger.

function checkString (theField, s, emptyOK)
{   // Next line is needed on NN3 to avoid "undefined is not a number" error
    // in equality comparison below.
    if(theField.name == "PageLink" || theField.name == "NewPageLink"){
    	theField.value =  stripCharsInBag (theField.value, "/");
    }
    if (checkString.arguments.length == 2) emptyOK = defaultEmptyOK;
    if ((emptyOK == true) && (isEmpty(theField.value))) return true;
    if (isWhitespace(theField.value))
       return warnEmpty (theField, s);
    else return true;
}

function checkSelect (theField, s, emptyOK)
{   // Next line is needed on NN3 to avoid "undefined is not a number" error
    // in equality comparison below.
    if (checkSelect.arguments.length == 2) emptyOK = defaultEmptyOK;
    if ((emptyOK == true) && (isEmpty(theField.value))) return true;
    if (isWhitespace(theField.value))
       return warnSelectEmpty (theField, s);
    else return true;
}

function checkHidden (theField, s, emptyOK)
{   // Next line is needed on NN3 to avoid "undefined is not a number" error
    // in equality comparison below.
    if (checkHidden.arguments.length == 2) emptyOK = defaultEmptyOK;
    if ((emptyOK == true) && (isEmpty(theField.value))) return true;
    if (isWhitespace(theField.value))
       return warnHiddenEmpty (theField, s);
    else return true;
}

// isInteger (STRING s [, BOOLEAN emptyOK])
//
// Returns true if all characters in string s are numbers.
//
// Accepts non-signed integers only. Does not accept floating
// point, exponential notation, etc.
//
// We don't use parseInt because that would accept a string
// with trailing non-numeric characters.
//
// By default, returns defaultEmptyOK if s is empty.
// There is an optional second argument called emptyOK.
// emptyOK is used to override for a single function call
//      the default behavior which is specified globally by
//      defaultEmptyOK.
// If emptyOK is false (or any value other than true),
//      the function will return false if s is empty.
// If emptyOK is true, the function will return true if s is empty.
//
// EXAMPLE FUNCTION CALL:     RESULT:
// isInteger ("5")            true
// isInteger ("")             defaultEmptyOK
// isInteger ("-5")           false
// isInteger ("", true)       true
// isInteger ("", false)      false
// isInteger ("5", false)     true

function isInteger (s){
		var i;

    if (isEmpty(s))
       if (isInteger.arguments.length == 1) return defaultEmptyOK;
       else return (isInteger.arguments[1] == true);

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

    for (i = 0; i < s.length; i++)
    {
        // Check that current character is number.
        var c = s.charAt(i);

        if (!isDigit(c)) return false;
    }

    // All characters are numbers.
    return true;
}

// Returns true if character c is an English letter
// (A .. Z, a..z).
//
// NOTE: Need i18n version to support European characters.
// This could be tricky due to different character
// sets and orderings for various languages and platforms.

function isLetter (c)
{   return ( ((c >= "a") && (c <= "z")) || ((c >= "A") && (c <= "Z")) )
}



// Returns true if character c is a digit
// (0 .. 9).

function isDigit (c)
{   return ((c >= "0") && (c <= "9"))
}



// Returns true if character c is a letter or digit.

function isLetterOrDigit (c)
{   return (isLetter(c) || isDigit(c))
}

// isEmail (STRING s [, BOOLEAN emptyOK])
//
// Email address must be of form a@b.c -- in other words:
// * there must be at least one character before the @
// * there must be at least one character before and after the .
// * the characters @ and . are both required
//
// For explanation of optional argument emptyOK,
// see comments of function isInteger.

function isEmail (s, isNHSEmail)
{   if (isEmpty(s))
       if (isEmail.arguments.length == 1) return defaultEmptyOK;
       else return (isEmail.arguments[1] == true);

    // is s whitespace?
    if (isWhitespace(s)) return false;

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

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

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

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

    // there must be at least one character after the .
    if ((i >= sLength - 1) || (s.charAt(i) != ".")) return false;
    //if (s.substr(sLength-6,6) != "nhs.uk" && isEmail.arguments.length == 2)  return false;
    else return true;
}

// Check whether string s is empty.

function isEmpty(s)
{   return ((s == null) || (s.length == 0))
}

// Returns true if string s is empty or
// whitespace characters only.

function isWhitespace (s)

{   var i;

    // Is s empty?
    if (isEmpty(s)) return true;

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

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

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

    // All characters are whitespace.
    return true;
}

// checkEmail (TEXTFIELD theField [, BOOLEAN emptyOK==false])
//
// Check that string theField.value is a valid Email.
//
// For explanation of optional argument emptyOK,
// see comments of function isInteger.

function checkEmailOld (theField, emptyOK)
{   if (checkEmail.arguments.length == 1) emptyOK = defaultEmptyOK;
    if ((emptyOK == true) && (isEmpty(theField.value))) return true;
    else if (!isEmail(theField.value, false))
       return warnInvalid (theField, iEmail);
    else return true;
}

function checkEmail (theField, emptyOK) {
  if (checkEmail.arguments.length == 1) emptyOK = defaultEmptyOK;
  if ((emptyOK == true) && (isEmpty(theField.value))) return true;
  var emailStr = theField.value;
  /* The following variable tells the rest of the function whether or not
  to verify that the address ends in a two-letter country or well-known
  TLD.  1 means check it, 0 means don't. */

  var checkTLD=1;

  /* The following is the list of known TLDs that an e-mail address must end with. */

  var knownDomsPat=/^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum)$/;

  /* The following pattern is used to check if the entered e-mail address
  fits the user@domain format.  It also is used to separate the username
  from the domain. */

  var emailPat=/^(.+)@(.+)$/;

  /* The following string represents the pattern for matching all special
  characters.  We don't want to allow special characters in the address.
  These characters include ( ) < > @ , ; : \ " . [ ] */

  var specialChars="\\(\\)><@,;:\\\\\\\"\\.\\[\\]";

  /* The following string represents the range of characters allowed in a
  username or domainname.  It really states which chars aren't allowed.*/

  var validChars="\[^\\s" + specialChars + "\]";

  /* The following pattern applies if the "user" is a quoted string (in
  which case, there are no rules about which characters are allowed
  and which aren't; anything goes).  E.g. "jiminy cricket"@disney.com
  is a legal e-mail address. */

  var quotedUser="(\"[^\"]*\")";

  /* The following pattern applies for domains that are IP addresses,
  rather than symbolic names.  E.g. joe@[123.124.233.4] is a legal
  e-mail address. NOTE: The square brackets are required. */

  var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;

  /* The following string represents an atom (basically a series of non-special characters.) */

  var atom=validChars + '+';

  /* The following string represents one word in the typical username.
  For example, in john.doe@somewhere.com, john and doe are words.
  Basically, a word is either an atom or quoted string. */

  var word="(" + atom + "|" + quotedUser + ")";

  // The following pattern describes the structure of the user

  var userPat=new RegExp("^" + word + "(\\." + word + ")*$");

  /* The following pattern describes the structure of a normal symbolic
  domain, as opposed to ipDomainPat, shown above. */

  var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");

  /* Finally, let's start trying to figure out if the supplied address is valid. */

  /* Begin with the coarse pattern to simply break up user@domain into
  different pieces that are easy to analyze. */

  var matchArray=emailStr.match(emailPat);

  if (matchArray==null) {

  /* Too many/few @'s or something; basically, this address doesn't
  even fit the general mould of a valid e-mail address. */

  alert("Email address seems incorrect (check @ and .'s)");
  return false;
  }
  var user=matchArray[1];
  var domain=matchArray[2];

  // Start by checking that only basic ASCII characters are in the strings (0-127).

  for (i=0; i<user.length; i++) {
  if (user.charCodeAt(i)>127) {
  alert("Ths username contains invalid characters.");
  return false;
     }
  }
  for (i=0; i<domain.length; i++) {
  if (domain.charCodeAt(i)>127) {
  alert("Ths domain name contains invalid characters.");
  return false;
     }
  }

  // See if "user" is valid

  if (user.match(userPat)==null) {

  // user is not valid

  alert("The username doesn't seem to be valid.");
  return false;
  }

  /* if the e-mail address is at an IP address (as opposed to a symbolic
  host name) make sure the IP address is valid. */

  var IPArray=domain.match(ipDomainPat);
  if (IPArray!=null) {

  // this is an IP address

  for (var i=1;i<=4;i++) {
  if (IPArray[i]>255) {
  alert("Destination IP address is invalid!");
  return false;
     }
  }
  return true;
  }

  // Domain is symbolic name.  Check if it's valid.

  var atomPat=new RegExp("^" + atom + "$");
  var domArr=domain.split(".");
  var len=domArr.length;
  for (i=0;i<len;i++) {
  if (domArr[i].search(atomPat)==-1) {
  alert("The domain name does not seem to be valid.");
  return false;
     }
  }

  /* domain name seems valid, but now make sure that it ends in a
  known top-level domain (like com, edu, gov) or a two-letter word,
  representing country (uk, nl), and that there's a hostname preceding
  the domain or country. */

  if (checkTLD && domArr[domArr.length-1].length!=2 && domArr[domArr.length-1].search(knownDomsPat)==-1) {
    alert("The address must end in a well-known domain or two letter " + "country.");
    return false;
  }

  // Make sure there's a host name preceding the domain.

  if (len<2) {
    alert("This address is missing a hostname!");
    return false;
  }

  // If we've gotten this far, everything's valid!
  return true;
}

// checkPhone (TEXTFIELD theField [, BOOLEAN emptyOK==false])
//
// Check that string theField.value is a valid UK Phone.
//
// For explanation of optional argument emptyOK,
// see comments of function isInteger.

// checkInternationalPhone (TEXTFIELD theField [, BOOLEAN emptyOK==false])
//
// Check that string theField.value is a valid International Phone.
//
// For explanation of optional argument emptyOK,
// see comments of function isInteger.

function checkInternationalPhone (theField, emptyOK)
{   if (checkInternationalPhone.arguments.length == 1) emptyOK = defaultEmptyOK;
    if ((emptyOK == true) && (isEmpty(theField.value))) return true;
    else
    {  if (!isInternationalPhoneNumber(theField.value, false))
          return warnInvalid (theField, iPhone);
       else return true;
    }
}

// new function to check phone numbers
/*
function checkPhone (theField, emptyOK){
	if (checkInternationalPhone.arguments.length == 1) emptyOK = defaultEmptyOK;
  if ((emptyOK == true) && (isEmpty(theField.value))) return true;
  else{
  	var newString = "";
  	newString = stripCharsNotInBag (theField.value, "0123456789 ");
  }
  if (theField.value.length > newString.length){
		return warnInvalid (theField, iPhone);
	}
	else{
     else return true;
  }
}
*/

// isInternationalPhoneNumber (STRING s [, BOOLEAN emptyOK])
//
// isInternationalPhoneNumber returns true if string s is a valid
// international phone number.  Must be digits only; any length OK.
// May be prefixed by + character.
//
// NOTE: A phone number of all zeros would not be accepted.
// I don't think that is a valid phone number anyway.
//
// NOTE: Strip out any delimiters (spaces, hyphens, parentheses, etc.)
// from string s before calling this function.  You may leave in
// leading + character if you wish.
//
// For explanation of optional argument emptyOK,
// see comments of function isInteger.

function isInternationalPhoneNumber (s){
	if (isEmpty(s))
		if (isInternationalPhoneNumber.arguments.length == 1) return defaultEmptyOK;
		else return (isInternationalPhoneNumber.arguments[1] == true);
  strippedNumber = stripCharsNotInBag(s, digits + whitespace);
  if(strippedNumber.length <  s.length) return false;
  return true;
}

// isPositiveInteger (STRING s [, BOOLEAN emptyOK])
//
// Returns true if string s is an integer > 0.
//
// For explanation of optional argument emptyOK,
// see comments of function isInteger.

function isPositiveInteger (s)
{   var secondArg = defaultEmptyOK;

    if (isPositiveInteger.arguments.length > 1)
        secondArg = isPositiveInteger.arguments[1];

    // The next line is a bit byzantine.  What it means is:
    // a) s must be a signed integer, AND
    // b) one of the following must be true:
    //    i)  s is empty and we are supposed to return true for
    //        empty strings
    //    ii) this is a positive, not negative, number

    return (isSignedInteger(s, secondArg)
         && ( (isEmpty(s) && secondArg)  || (parseInt (s) > 0) ) );
}


// isSignedInteger (STRING s [, BOOLEAN emptyOK])
//
// Returns true if all characters are numbers;
// first character is allowed to be + or - as well.
//
// Does not accept floating point, exponential notation, etc.
//
// We don't use parseInt because that would accept a string
// with trailing non-numeric characters.
//
// For explanation of optional argument emptyOK,
// see comments of function isInteger.
//
// EXAMPLE FUNCTION CALL:          RESULT:
// isSignedInteger ("5")           true
// isSignedInteger ("")            defaultEmptyOK
// isSignedInteger ("-5")          true
// isSignedInteger ("+5")          true
// isSignedInteger ("", false)     false
// isSignedInteger ("", true)      true

function isSignedInteger (s)

{   if (isEmpty(s))
       if (isSignedInteger.arguments.length == 1) return defaultEmptyOK;
       else return (isSignedInteger.arguments[1] == true);

    else {
        var startPos = 0;
        var secondArg = defaultEmptyOK;

        if (isSignedInteger.arguments.length > 1)
            secondArg = isSignedInteger.arguments[1];

        // skip leading + or -
        if ( (s.charAt(0) == "-") || (s.charAt(0) == "+") )
           startPos = 1;
        return (isInteger(s.substring(startPos, s.length), secondArg))
    }
}

// Removes all characters which appear in string bag from string s.

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++)
    {
        // Check that current character isn't whitespace.
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }

    return returnString;
}

// Removes all characters which do NOT appear in string bag
// from string s.

function stripCharsNotInBag (s, bag)

{   var i;
    var returnString = "";

    // Search through string's characters one by one.
    // If character is in bag, append to returnString.

    for (i = 0; i < s.length; i++)
    {
        // Check that current character isn't whitespace.
        var c = s.charAt(i);
        if (bag.indexOf(c) != -1) returnString += c;
    }

    return returnString;
}

// Removes all whitespace characters from s.
// Global variable whitespace (see above)
// defines which characters are considered whitespace.

function stripWhitespace (s)

{   return stripCharsInBag (s, whitespace)
}

// FUNCTIONS TO NOTIFY USER OF INPUT REQUIREMENTS OR MISTAKES. //

// Display data entry prompt string s in status bar.

function promptEntry (s){
	window.status = pEntryPrompt + s
}

// Notify user that contents of field theField are invalid.
// String s describes expected contents of theField.value.
// Put select theField, pu focus in it, and return false.

function warnInvalid (theField, s)
{   theField.focus()
    theField.select()
    alert(s)
    return false
}

// Display data entry prompt string s in status bar.

function promptEntry (s){
	window.status = pEntryPrompt + s
}

// Notify user that contents of field theField are invalid.
// String s describes expected contents of theField.value.
// Put select theField, pu focus in it, and return false.

function warnInvalid (theField, s)
{   theField.focus()
    theField.select()
    alert(s)
    return false
}

// Function to check to see if the two password fields match
function checkConfirmPassword (theField, theField2){
	if( (theField.value) != (theField2.value) ){
		theField.focus()
		alert(iConfirmPassword)
		return false
	}
  else{
  	return true
  }

}

function checkURL(TheURL) {
    if (checkURL.arguments.length == 1) emptyOK = defaultEmptyOK;
    if ((emptyOK == true) && (isEmpty(TheURL.value))) return true;
    else if (!isURL(TheURL.value, false))
       return warnInvalid (TheURL, iURL);
    else return true;
}


function isURL (s){
   if (isEmpty(s))
       if (isURL.arguments.length == 1) return defaultEmptyOK;
       else return (isURL.arguments[1] == true);

    // is s whitespace?
    if (isWhitespace(s)) return false;

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

		// look for http:// or https://

		if ( (s.slice(0, 7) != 'http://') && (s.slice(0, 8) != 'https://') ) return false;

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

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

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

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

function checkCheckBoxes(TheField, s) {
	if ( TheField.checked == false) {
		warnCheckBoxEmpty (TheField, s);
		return false;
	}
	else {
		return true;
	}
}

function checkPlugins (theField, s){   // Next line is needed on NN3 to avoid "undefined is not a number" error
    if (isWhitespace(theField.value))
       return warnSelectEmpty (theField, s);
    else return true;
}

function checkTemplates (theField, s, emptyOK){
    // Next line is needed on NN3 to avoid "undefined is not a number" error
    // in equality comparison below.
    if (checkTemplates.arguments.length == 2) emptyOK = defaultEmptyOK;
    if ((emptyOK == true) && (isEmpty(theField.value))) return true;
    if (isWhitespace(theField.value)){
    	alert(s);
      return false;
    }
    else{
    	return true;
    }
}

// ******************************
// DATE TIME VALIDATION FUNCTIONS
// ******************************

var day, month, year, day_week, flag = true;

function test_input_data(day, month, year) {
	switch(day) {
		case 29 : // tests for leap years
		  if(month == 2) { // only applies to February
		    if(((year / 4) - Math.floor(year / 4)) == 0) { // year divisible by 4
		      if(((year / 100) - Math.floor(year / 100)) == 0) { // year div by 100
			if(((year / 400) - Math.floor(year / 400)) == 0) { // year div by 400
			  break;
			} // year div by 400 so is a leap year
			else {
			  alert('That is not a leap year');
			  flag = false;
			  return flag;
			} // year div by 4 and 100 but not 400 so can't be a leap year
		       }
		       else { // year div by 4 but not by 100 so is a leap year
			 break;
		       }
		    }
		    else { // year not div by 4 so can't be a leap year
		      alert('That is not a leap year');
		      flag = false;
		      return flag;
		    }
		  }
		  else { // not February
	 	    break;
		  }

		case 30 :
		  if(month == 2) {
		    days_in_a_month();
		    flag = false;
		    return flag;
		  }
		  else {
		    break;
		  }

		case 31 :
		  if((month == 2)||(month == 4)||(month == 6)||(month == 9)||(month == 11)) {
		    days_in_a_month();
		    flag = false;
		    return flag;
		  }
		   else {
		    break;
		  }
	}
}

function days_in_a_month() {
	var m1 = "April, June, September, and November have 30 days.\n";
	var m2 = "All the rest have 31, except February, which has\n";
	var m3 = "28 days (29 in each leap year)";

	alert(m1 + m2 + m3);
	return;
}

function day_of_the_week(day, month, year) {
	var m, y, c, dd; 	// parameters used in the calculations

	var month_array = new Array(1, 4, 3, 6, 1, 4, 6, 2, 5, 0, 3, 5);
	m = month_array[month-1];

	if((month == 1)||(month == 2)) {
		year = year - 1;
	}

	y = (5 * (Math.floor((year % 100) / 4)) + year % 4)%7;
	c = (5 * ((Math.floor(year / 100)) % 4))%7;
	dd = (m + day + c + y)%7;

	var day_array = new Array("Saturday", "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday");
	day_week = day_array[dd];

	return day_week;
}

function day_of_week(year, month, day, day_name) {
	year = year*1;
	month = month*1;
	day = day*1;

	test_input_data(day, month, year);
	if(flag == false) {
	  flag = true;
	  return;
	}
	else {
		day_of_the_week(day, month, year);
	}
	if(day_name){
		document.forms[0].elements[day_name].value = day_week;
	}
}



/*
function checkIntExtUrl{

link1=PostForm.LinkUrl1.value;
link2=PostForm.LinkUrl2.value;

if (link1!='' && link2!='') {
alert('Please add either a local or external link, Not Both!.');
event.returnValue=false;
}

if (link1=='' && link2=='') {
alert('Please add either a local or external link!.');
event.returnValue=false;
}
}
*/