	// version 1.1

//Modified on the 23rd February 2004 to validate prepayment meter Directory

//==============================================================================

function chkFirstnameSurname(fld, lbl,intMin,intMax)
{ 
  fld.value = MakeOrder(fld.value);
  if (isMin(fld,intMin) || isMax(fld,intMax) || !Space(fld.value))
   { 
     alertMsg (fld,"Oops!\nInvalid entry for field ("+ lbl +").\n\nCheck the following...\nThat the field contains only letters (a-z, A-Z).");
     return false;
   }
   else
   {
   return true;
  }
} 


//==============================================================================
function chkPassword(fld, lbl,intSize)
{ 
  fld.value = MakeOrder(fld.value);

 if (!validInteger(fld.value) || (fld.value.length == 0))
   { 
     return alertMsg(fld,"Oops!\nInvalid entry for field ("+ lbl +").\n\nCheck the following...\nThat the field contains numbers (0-9).");
   }
   return true;
}     


//==============================================================================
function chkDate(fld,lbl)
{
 fld.value = MakeOrder(fld.value);
 var checkstr = "0123456789";
var DateField = fld;
var Datevalue = "";
var DateTemp = "";
var seperator = "/";
var day;
var month;
var year;
var leap = 0;
var err = 0;
var i;
   err = 0;
   DateValue = MakeOrder(DateField.value);
   
     
   /* Validate format */
   
   
   if((DateValue.substr(4,1) !="/") && (DateValue.substr(7,1) !="/"))
   {
     
	 return alertMsg(fld,"Oops!\nInvalid entry for field ("+ lbl +").\n\nCheck the following...\nThat the date format is (dd/mm/yyyy)");
	 Exit
   }
   
   if((DateValue.substr(6,4).length !=4) || (validInteger(DateValue)))
   {
    
	 return alertMsg(fld,"Oops!\nInvalid entry for field ("+ lbl +").\n\nCheck the following...\nThat the date format is (dd/mm/yyyy)");
	 
   }else{
  
   /* Delete all chars except 0..9 */
   for (i = 0; i < DateValue.length; i++) {
	  if (checkstr.indexOf(DateValue.substr(i,1)) >= 0) {
	     DateTemp = DateTemp + DateValue.substr(i,1);
	  }
   }
   DateValue = DateTemp;
   /* Always change date to 8 digits - string*/
   /* if year is entered as 2-digit / always assume 20xx */
   if (DateValue.length == 6) {
      DateValue = DateValue.substr(0,4) + '20' + DateValue.substr(4,2);
	 
	   }
    
   if (DateValue.length != 8) {
      err = 19;
	  
	  }
   /* year is wrong if year = 0000 */
   year = DateValue.substr(0,4);
  
   if (year == 0) {
      err = 20;
	   
   }
   /* Validation of month*/
   month = DateValue.substr(4,2);

   if ((month < 1) || (month > 12)) {
      err = 21;
	 
   }
   /* Validation of day*/
   day = DateValue.substr(6,2);
   if (day < 1) {
     
	 err = 22;
   }
   /* Validation leap-year / february / day */
   if ((year % 4 == 0) || (year % 100 == 0) || (year % 400 == 0)) {
      
	  leap = 1;
   }
   if ((month == 2) && (leap == 1) && (day > 29)) {
      err = 23;
   }
   if ((month == 2) && (leap != 1) && (day > 28)) {
      err = 24;
   }
   /* Validation of other months */
   if ((day > 31) && ((month == "01") || (month == "03") || (month == "05") || (month == "07") || (month == "08") || (month == "10") || (month == "12"))) {
      err = 25;
   }
   if ((day > 30) && ((month == "04") || (month == "06") || (month == "09") || (month == "11"))) {
      err = 26;
   }
   /* if 00 ist entered, no error, deleting the entry */
   if ((day == 0) && (month == 0) && (year == 00)) {
      err = 0; day = ""; month = ""; year = ""; seperator = "";
   }
   /* if no error, write the completed date to Input-Field (e.g. 13.12.2001) */
   if (err == 0) {
      DateField.value = year + seperator + month + seperator + day;
   }
   /* Error-message if err != 0 */
   else {
     
		return alertMsg(fld,"Oops!\nInvalid entry for field ("+ lbl +").\n\nCheck the following...\nThat the date format is (yyyy/mm/dd)");
      
   }
  }
  return true;
}

//==============================================================================
function chkDate_1(fld,lbl)
{
 fld.value = MakeOrder(fld.value);
 var checkstr = "0123456789";
var DateField = fld;
var Datevalue = "";
var DateTemp = "";
var seperator = "-";
var day;
var month;
var year;
var leap = 0;
var err = 0;
var i;
   err = 0;
   DateValue = MakeOrder(DateField.value);
   
     
   /* Validate format */
   
   
   if((DateValue.substr(4,1) !="-") && (DateValue.substr(7,1) !="-"))
   {
     
	 return alertMsg(fld,"Oops!\nInvalid entry for field ("+ lbl +").\n\nCheck the following...\nThat the date format is (yyyy-mm-dd)");
	 Exit
   }
   
   if((DateValue.substr(6,4).length !=4) || (validInteger(DateValue)))
   {
    
	 return alertMsg(fld,"Oops!\nInvalid entry for field ("+ lbl +").\n\nCheck the following...\nThat the date format is (yyyy-mm-dd)");
	 
   }else{
  
   /* Delete all chars except 0..9 */
   for (i = 0; i < DateValue.length; i++) {
	  if (checkstr.indexOf(DateValue.substr(i,1)) >= 0) {
	     DateTemp = DateTemp + DateValue.substr(i,1);
	  }
   }
   DateValue = DateTemp;
   /* Always change date to 8 digits - string*/
   /* if year is entered as 2-digit / always assume 20xx */
   if (DateValue.length == 6) {
      DateValue = DateValue.substr(0,4) + '20' + DateValue.substr(4,2);
	 
	   }
    
   if (DateValue.length != 8) {
      err = 19;
	  
	  }
   /* year is wrong if year = 0000 */
   year = DateValue.substr(0,4);
  
   if (year == 0) {
      err = 20;
	   
   }
   /* Validation of month*/
   month = DateValue.substr(4,2);

   if ((month < 1) || (month > 12)) {
      err = 21;
	 
   }
   /* Validation of day*/
   day = DateValue.substr(6,2);
   if (day < 1) {
     
	 err = 22;
   }
   /* Validation leap-year / february / day */
   if ((year % 4 == 0) || (year % 100 == 0) || (year % 400 == 0)) {
      
	  leap = 1;
   }
   if ((month == 2) && (leap == 1) && (day > 29)) {
      err = 23;
   }
   if ((month == 2) && (leap != 1) && (day > 28)) {
      err = 24;
   }
   /* Validation of other months */
   if ((day > 31) && ((month == "01") || (month == "03") || (month == "05") || (month == "07") || (month == "08") || (month == "10") || (month == "12"))) {
      err = 25;
   }
   if ((day > 30) && ((month == "04") || (month == "06") || (month == "09") || (month == "11"))) {
      err = 26;
   }
   /* if 00 ist entered, no error, deleting the entry */
   if ((day == 0) && (month == 0) && (year == 00)) {
      err = 0; day = ""; month = ""; year = ""; seperator = "";
   }
   /* if no error, write the completed date to Input-Field (e.g. 13.12.2001) */
   if (err == 0) {
      DateField.value = year + seperator + month + seperator + day;
   }
   /* Error-message if err != 0 */
   else {
     
		return alertMsg(fld,"Oops!\nInvalid entry for field ("+ lbl +").\n\nCheck the following...\nThat the date format is (yyyy/mm/dd)");
      
   }
  }
  return true;
}
//======================================================================================================

function DatePeriod(fld1,fld2,msg)
{
  fld1.value = MakeOrder(fld1.value);
  fld2.value = MakeOrder(fld2.value);
  var a = fld1.value.substr(0,4);
  var b = fld1.value.substr(5,2);
  var c = fld1.value.substr(8,2);
  var d = fld2.value.substr(0,4);
  var e = fld2.value.substr(5,2);
  var f = fld2.value.substr(8,2);;
  
  var start_date = new Date(a,b,c);
  var end_date = new Date(d,e,f);
  var days_diff = (end_date.getTime() - start_date.getTime())/1000/60/60/24;
  if(days_diff<0)
  {
     return alertMsg(fld2,msg);
  }
  return true;
}

//==================================================================================================
function chkKeywords(fld,lbl)
{
  fld.value=MakeOrder(fld.value);
  if(!Space(fld.value))
  {
   return alertMsg(fld,"Oops!\nInvalid entry for field("+ lbl +").\n\nCheck the following...\nThat you entered an entry with at least one character."); 
  }
  return true;	
}
//================================for vacancies==============================================

function chkIntLen(fld, lbl,intSize)
{ 
  fld.value = MakeOrder(fld.value);

 if (!validInteger(fld.value))// || (fld.value.length != intSize))
	{
		//if (fld.value.length != intSize)
			//{ 
				return alertMsg(fld,"Oops!\nInvalid entry for field ("+ lbl +").\n\nCheck the following...\nThat the field contains numbers only.");
			//}
				
	} 
	return true;
}

//===================for outages & vacancies=====================================================
function CompareDate(fld,msg)
{
//======

//get todays' date
    var now  = new Date();
    var currDay = now.getDay();
    var currMonth = now.getMonth();
    var currYear = now.getYear(); 
    var currDate = now.getDate();
    
   if (currDay == 0) {
     currDay = "Sunday"; 
   }else if (currDay == 1){
            currDay = "Monday";
           }else if (currDay == 2 ){
                   currDay = "Tuesday";
                   }else if (currDay == 3 ){
                            currDay = "Wednesday";
                           }else if (currDay = 4 ){
                                   currDay = "Thursday";
                                   }else if (currDay == 5 ){
                                           currDay = "Friday";
                                           }else if (currDay == 6 ){
                                                   currDay = "Saturday";
                                                   }      
 
        if (currMonth == 0) currMonth = "01";

	else if (currMonth == 1) currMonth = "02";

	else if (currMonth == 2) currMonth = "03";

	else if (currMonth == 3) currMonth = "04";

	else if (currMonth == 4) currMonth = "05";

	else if (currMonth == 5) currMonth = "06";

	else if (currMonth == 6) currMonth = "07";

	else if (currMonth == 7) currMonth = "08";

	else if (currMonth == 8) currMonth = "09";

	else if (currMonth == 9) currMonth = "10";

	else if (currMonth == 10) currMonth = "11";

	else if (currMonth == 11) currMonth = "12";

	//make day 2 digits long
	if (currDate == 1) currDate = "01";
	else if (currDate == 2) currDate = "02";
	else if (currDate == 3) currDate = "03";
	else if (currDate == 4) currDate = "04";
	else if (currDate == 5) currDate = "05";
	else if (currDate == 6) currDate = "06";
	else if (currDate == 7) currDate = "07";
	else if (currDate == 8) currDate = "08";
	else if (currDate == 9) currDate = "09";

	//this is today's date	
	var FullDate =  currYear  +"/"+ currMonth + "/" + currDate;
    //==============

		fld.value = MakeOrder(fld.value);
		var DateField = fld;
		var Datevalue = "";
		var DateTemp = "";
		DateValue = MakeOrder(DateField.value);

		year = DateValue.substr(0,4);
		month = DateValue.substr(5,2);
		day = DateValue.substr(8,2);
	//==============

		var TD = currYear + currMonth + currDate; //today's date eg 20050903
		var OT = year + month + day;              //outage date eg 20050906
           
		if(TD > OT)
			{
				return alertMsg(fld,msg)
			}
return true
}

//=================================================================
function RemoveSpace(passVal)
{
  var count;
  var temp;
  temp = ""
  for( i = 0 ; i < passVal.length; i ++)
  {
       if(passVal.charAt(i) !=" ")
       {
         temp = passVal.charAt(i)
		
         for( j = i + 1 ; j < passVal.length; j ++)
         {
           
		   if(passVal.charAt(j) !=" ")
           {
		     
			 temp = temp + passVal.charAt(j)  
			
		   }	 
         }  
        i = passVal.length + 1
       }  
  }
  return temp;

}

//===============================================================================================
function CompareTime(Hr1,Min1,Hr2,Min2,errMsg)
{
  Hr1.value = MakeOrder(Hr1.value);
  Min1.value = MakeOrder(Min1.value);
  Hr2.value = MakeOrder(Hr2.value);
  Min2.value = MakeOrder(Min2.value);
  
  var date1 = new Date(2004,01,01,Hr1.value,Min1.value);
  var date2 = new Date(2004,01,01,Hr2.value,Min2.value);
  
  var time_diff = ((date2.getTime()-date1.getTime())/1000/60);
  if(time_diff<1)
  {
   return alertMsg(Hr1,errMsg);
  }
  return true;
}


//===============================================================================================
function ckhTime(Hr,Min,lbl)
{
  Hr.value = MakeOrder(Hr.value);
  Min.value = MakeOrder(Min.value);
  if(!validInteger(Hr.value) || !validInteger(Min.value))
  {
    return alertMsg(Hr,"Oops!\nInvalid time for field ("+ lbl +")\n\nCheck the following..\nThat the hour is in 24 hour format (00-23)\nThat the minutes are valid (00-59). ");
  }else if((Hr.value<0) || (Hr.value>23) ||(Min.value<0) || (Min.value>59))
        {
          return alertMsg(Hr,"Oops!\nInvalid time for field ("+ lbl +")\n\nCheck the following..\nThat the hour is in 24 hour format (00-23)\nThat the minutes are valid (00-59). ");
        }
  		
  return true;
}
//===============================================================================================
function chkNumber(fld,lbl)
{
   if(!validInteger(fld.value))
   {
     return alertMsg(fld,"Oops!\nInvalid entry for field ("+ lbl +").");
   }	 
   return true;
}

function chkEmpNum(fld,lbl)
{

  if(!validInteger(fld.value))
  {
    return alertMsg(fld,"Oops!\nInvalid entry for field ("+ lbl +").");
  }
  return true;
}
function chkName(fld, lbl,intMin,intMax)
{ 
  fld.value = MakeOrder(fld.value);
  if (isMin(fld,intMin) || isMax(fld,intMax) || !Space(fld.value))
   { 
     return alertMsg(fld,"Oops!\nInvalid entry for field ("+ lbl +").\n\nCheck the following...\nThat the field contains only letters (a-z, A-Z).\nThat the field is at least "+ intMin +" characters and does not exceed "+ intMax +" characters");
   }
   return true;
}        
//==============================================================================

function chkAccountNo(fld, lbl)
{ 
  fld.value = MakeOrder(fld.value);

 if(!Space(fld.value))
   { 
     return alertMsg(fld,"Oops!\nInvalid entry for field ("+ lbl +").\n\nCheck the following...\nThat a valid Account No has been entered");
   }
   return true;
}     

//==============================================================================
function chkPin(fld, lbl,intSize)
{ 
  fld.value = MakeOrder(fld.value);

 if (!validInteger(fld.value) || (fld.value.length != intSize))
   { 
     return alertMsg(fld,"Oops!\nInvalid entry for field ("+ lbl +").\n\nCheck the following...\nThat the field contains numbers (0-9).\nThat the field is "+ intSize + " digits.");
   }
   return true;
}     
//==============================================================================
function chkLocation(fld, lbl)
{
  if (isEmpty(fld.value))
   { 
     return alertMsg(fld,"Oops!\nPlease select an entry for ("+ lbl +").");
   }
   return true;
}
//===============================================================================
function chkPhone(fld, lbl)
{

   if (!isPhone(fld.value))
   {
      return alertMsg(fld,"Oops!\nInvalid entry for field ("+ lbl +").\n\nCheck the following...\nThat an international format has been entered. e.g +266 22 312 236");
   }
   return true;
}

//=================================================================================
function chkEmail(fld,lbl)
{
	//alert(!validEmail(fld.value));
	if (!validEmail(fld.value))  
	{
	   return alertMsg(fld,"Oops!\nInvalid entry for field ("+ lbl +").\n\nCheck the following...\nThat a valid email format has been entered. e.g nna@lona.co.ls");
	}
	return true;
}

//=================================================================================


//=================================================================================

function isChecked(fld,lbl)
{
  if(fld.checked == false)
  {
   return alertMsg(fld,"Oops!\nYou have to agree to the terms and conditions if you wish to register.\nPlease read the Terms and Conditions before registering.");
  }
  return true;
}

//=================================================================================
function validInteger(str)
{
	//if (isInteger.arguments.length == 1)  emptyOK = false;
	//if ((emptyOK == true) && isEmpty(str)) return true;
	var re = /^\d+$/;
	return (re.test(str));
}
//=================================================================================
function validEmail(email)
  {
     invalidChars="/:,;"
     if(email=="")
     {
       return false
     }
     for(i=0; i < invalidChars.length; i++)
     {
       badChar=invalidChars.charAt(i)
       if(email.indexOf(badChar,0)> -1)
       {
         return false
       }
     }
     atPos=email.indexOf("@",1)
     if(atPos==-1)
     {
       return false
     }
     if(email.indexOf("@",atPos+1) != -1)
     {
       return false
     }
     periodPos=email.indexOf(".",atPos)
     if(periodPos== -1)
     {
        return false
     }
     if(periodPos+3>email.length)
     {
       return false
     }
     return true
  }  
  
//========================================================================

function checkValidDate(dateStr) {
    // dateStr must be of format month day year with either slashes
    // or dashes separating the parts. Some minor changes would have
    // to be made to use day month year or another format.
    // This function returns True if the date is valid.
    var slash1 = dateStr.indexOf("/");
    if (slash1 == -1) { slash1 = dateStr.indexOf("-"); }
    // if no slashes or dashes, invalid date
    if (slash1 == -1) { return false; }
    var dateMonth = dateStr.substring(0, slash1)
    var dateMonthAndYear = dateStr.substring(slash1+1, dateStr.length);
    var slash2 = dateMonthAndYear.indexOf("/");
    if (slash2 == -1) { slash2 = dateMonthAndYear.indexOf("-"); }
    // if not a second slash or dash, invalid date
    if (slash2 == -1) { return false; }
    var dateDay = dateMonthAndYear.substring(0, slash2);
    var dateYear = dateMonthAndYear.substring(slash2+1, dateMonthAndYear.length);
    if ( (dateMonth == "") || (dateDay == "") || (dateYear == "") ) { return false; }
    // if any non-digits in the month, invalid date
    for (var x=0; x < dateMonth.length; x++) {
        var digit = dateMonth.substring(x, x+1);
        if ((digit < "0") || (digit > "9")) { return false; }
    }
    // convert the text month to a number
    var numMonth = 0;
    for (var x=0; x < dateMonth.length; x++) {
        digit = dateMonth.substring(x, x+1);
        numMonth *= 10;
        numMonth += parseInt(digit);
    }
    if ((numMonth <= 0) || (numMonth > 12)) { return false; }
    // if any non-digits in the day, invalid date
    for (var x=0; x < dateDay.length; x++) {
        digit = dateDay.substring(x, x+1);
        if ((digit < "0") || (digit > "9")) { return false; }
    }
    // convert the text day to a number
    var numDay = 0;
    for (var x=0; x < dateDay.length; x++) {
        digit = dateDay.substring(x, x+1);
        numDay *= 10;
        numDay += parseInt(digit);
    }
    if ((numDay <= 0) || (numDay > 31)) { return false; }
    // February can't be greater than 29 (leap year calculation comes later)
    if ((numMonth == 2) && (numDay > 29)) { return false; }
    // check for months with only 30 days
    if ((numMonth == 4) || (numMonth == 6) || (numMonth == 9) || (numMonth == 11)) { 
        if (numDay > 30) { return false; } 
    }
    // if any non-digits in the year, invalid date
    for (var x=0; x < dateYear.length; x++) {
        digit = dateYear.substring(x, x+1);
        if ((digit < "0") || (digit > "9")) { return false; }
    }
    // convert the text year to a number
    var numYear = 0;
    for (var x=0; x < dateYear.length; x++) {
        digit = dateYear.substring(x, x+1);
        numYear *= 10;
        numYear += parseInt(digit);
    }
    // Year must be a 2-digit year or a 4-digit year
    if ( (dateYear.length != 2) && (dateYear.length != 4) ) { return false; }
    // if 2-digit year, use 50 as a pivot date
    if ( (numYear < 50) && (dateYear.length == 2) ) { numYear += 2000; }
    if ( (numYear < 100) && (dateYear.length == 2) ) { numYear += 1900; }
    if ((numYear <= 0) || (numYear > 9999)) { return false; }
    // check for leap year if the month and day is Feb 29
    if ((numMonth == 2) && (numDay == 29)) {
        var div4 = numYear % 4;
        var div100 = numYear % 100;
        var div400 = numYear % 400;
        // if not divisible by 4, then not a leap year so Feb 29 is invalid
        if (div4 != 0) { return false; }
        // at this point, year is divisible by 4. So if year is divisible by
        // 100 and not 400, then it's not a leap year so Feb 29 is invalid
        if ((div100 == 0) && (div400 != 0)) { return false; }
    }
    // date is valid
    return true;
}

//========================================================================
function CompareFields(fld1,fld2,msg)
{
  if(fld1.value != fld2.value)
  {
     return alertMsg(fld2,msg);
  }
  return true;
}

function ComparePassword(fld1,fld2)
{

}

                
//========================================================================
function Space(passVal)
{
    validChars="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890,./<>?:;[]{}|\`~!@#$%^&*()-_+='"
    Isnospace = 0
    for(i = 0 ; i < validChars.length; i ++)
    {
       if(passVal.indexOf((validChars.charAt(i)), 0 ) > -1)
       {
          Isnospace++
       }
    }
    if(Isnospace == 0 )
    {
       return false
    }else
         {
           return true
         }  
} 
//===============================================================================

function MakeOrder(passVal)
{
  var count;
  var temp;
  temp = ""
  for( i = 0 ; i < passVal.length; i ++)
    {
       if(passVal.charAt(i) !=" ")
       {
         temp = passVal.charAt(i)
		
         for( j = i + 1 ; j < passVal.length; j ++)
         {
           temp = temp + passVal.charAt(j)  
         }  
        i = passVal.length + 1
       }  
    }
  
  return temp    
}

//=================================================================


function isMin(fld,intVal)
{
  if(fld.value.length >= intVal)
  {
     return false;
  }else
      {
	    return true;
	  }	   	 
}
//=================================================================
function isMax(fld,intVal)
{
  if(fld.value.length <= intVal)
  {
     return false;
  }else
      {
	     return true;
      }	    	 
}
//=================================================================
function alertMsg(fld,msg)
{
     fld.focus();
     alert(msg);
     return false;
}
//=================================================================
function isEmpty(str)
{
	return ((str == null) || (str.length == 0));
}
//=================================================================
function isSpace(str)
{
	var re = /^\s+$/;
	return (re.test(str));	
}
//=================================================================

function isInteger(str,emptyOK)
{
	if (isInteger.arguments.length == 1)  emptyOK = false;
	if ((emptyOK == true) && isEmpty(str)) return true;
	var re = /^\d+$/;
	return (re.test(str));
}

//=====
function emailvalidate(emailad) 
{

	var exclude=/[^@\-\.a-zA-Z0-9_]|(@.+@)|^[@]|[@\.]{2}/;
	var check=/@[a-zA-Z0-9_\-]+\./;
	var checkend=/(\.[a-zA-Z]{2,3})$|(\.name)$/;

	if(((emailad.search(exclude) != -1)||(emailad.search(check)) == -1)||(emailad.search(checkend) == -1))
	{
		return false;
	}
	else {
			return true;
		 }
}

function isEmail (str) 
{
	var emailPat = /^(.+)@(.+)$/;
	var specialChars = "\\(\\)<>@,;:\\\\\\\"\\.\\[\\]";
	var validChars = "\[^\\s" + specialChars + "\]";
	var quotedUser = "(\"[^\"]*\")";
	var ipDomainPat = /^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;
	var atom = validChars + '+';
	var word = "(" + atom + "|" + quotedUser + ")";
	var userPat = new RegExp("^" + word + "(\\." + word + ")*$");
	var domainPat = new RegExp("^" + atom + "(\\." + atom +")*$");

	var matchArray = str.match(emailPat);
	if (matchArray == null) 
	{
		return(false);
	}
	
	var user = matchArray[1];
	var domain = matchArray[2];

	if (user.match(userPat) == null) 
	{
		return(false);
	}

	var IPArray = domain.match(ipDomainPat);
	if (IPArray != null) {
		for (var i = 1; i <= 4; i++) 
		{
		    if (IPArray[i] > 255) 
		    {
				return(false);
		    }
	    }
	    return(true);
	}

	var domainArray = domain.match(domainPat);
	if (domainArray == null) 
	{
		return(false);
	}

	var atomPat = new RegExp(atom,"g");
	var domArr = domain.match(atomPat);
	var len = domArr.length;
	if (domArr[domArr.length-1].length < 2 || 
	    domArr[domArr.length-1].length > 3) 
	{
	   return(false);
	}

	if (len < 2) {
	   return(false);
	}

	return(true);
}

function checkSunday(dayFld, monthFld, yearFld)
{	
	var myDate = new Date(yearFld.value, monthFld.value - 1, dayFld.value);
	if (myDate.getDay() != 0)
	{
		alert("Oops...\r\r" + dayFld.value + "/" + monthFld.value + "/" + yearFld.value + " does not fall on a Sunday.\rAre you sure you want to keep this Print Date?");
		return true;
	}
}

/*function checkYearRange(fld, lbl, minYear, maxYear)
{	
	var myDate = new Number();
	myDate = fld.value;
	if ((myDate >= minYear) && (myDate <= maxYear))
	{
		return true;
	}
		fld.focus();
		return warnInvalid("Oops...\r\r" + lbl + " must be within the range" + minYear + " and " + maxYear + ".");
}*/

function isURL (str) 
{	
	var URLPat = /http:\/\/(\w)+\.[\w\?\-=~\:\/]+(\.)*[\w\?\-=~\:\/]*/;
	return (URLPat.test(str));
}

function checkURL(fld, lbl, emptyOK)
{	
	if (checkURL.arguments.length == 2) emptyOK = false;
	if ((emptyOK == true) && isEmpty(fld.value)) return true;
	if ((isURL(fld.value) == false)) 
	{
		return warnInvalid(fld,'OOPS...\n\nPlease edit your entry in the ' + lbl.toUpperCase() + ' field.\nEnter the correct web address format, for example:\n\nhttp://www.somesite.co.za');
	}	
		return(true);
}

function checkWebLocation(fld, lbl, emptyOK)
{
	var re=/[^A-Za-z0-9+#&_\?\-=~\:\/\.]|(&#)/;
	if (checkWebLocation.arguments.length == 2) emptyOK = false;
	if ((emptyOK == true) && isEmpty(fld.value)) return true;
	if (re.test(fld.value))
	{
		return warnInvalid(fld,'OOPS...\n\nPlease edit your entry in the ' + lbl.toUpperCase() + ' field.\nEnter only letters and numbers (a-z, A-Z, 0-9), as well as:\n\n# & + _ ? - = . ~ : /');
	}
		return true;	
}

function isPhone(str)
{
	var re = /\+\d+ \d+ [0-9 ]+$/;
	return (re.test(str));
}

function isIntegerInRange(str,minval,maxval)
{
	if (!isInteger(str)) return false;
	var num = parseFloat(str);
	return ((num >= minval) && (num <= maxval));
}


function checkRange(fld, lbl, minval, maxval, emptyOK)
{
	if (checkRange.arguments.length == 4) emptyOK = false;
	if ((emptyOK == true) && isEmpty(fld.value)) return true;
	if (isIntegerInRange(fld.value, minval, maxval) == false)
	{
		fld.focus();
		return warnInvalid(fld,'OOPS...\n\nPlease edit your entry in the ' + lbl.toUpperCase() + ' field.\nEnter a value between ' + minval + ' and ' + maxval + '.');
	}
	else return true;
}	

function checkSelected(fld, lbl, emptyOK)
{
    
	if (checkSelected.arguments.length == 2) emptyOK == false;
	if ((emptyOK == true) && (fld.selectedIndex == 0)) return true;
	if (fld.selectedIndex == -1)
	{	
			fld.focus();
			alert('OOPS...\n\nPlease select an item in the ' + lbl.toUpperCase() + ' field.\nThis field is required.');
			return false;
	}
		return true;
}
	

function checkNoTags(fld, lbl)
{	
	var re=/[\<\>]/;
	if (re.test(fld.value))
	{
		return warnInvalid(fld,'Oops...\r\r' + lbl + ' cannot contain "<" or ">" characters. \rPlease edit your entry.');		
	}
	return true;
}

function checkText(fld, lbl, emptyOK)
{
	var re=/[^A-Za-z\-\s]/;
	if (checkText.arguments.length == 2) emptyOK = false;
	if ((emptyOK == true) && isEmpty(fld.value)) return true;
	if (re.test(fld.value))
	{
		return warnInvalid(fld,'OOPS...\n\nPlease edit your entry in the ' + lbl.toUpperCase() + ' field. Enter only spaces and letters, as well as:\n\n-');
	}
	return true;		
}

function checkTextNumeric(fld, lbl, emptyOK)
{
	var re=/[^A-Za-z-0-9\s]/;
	if (checkTextNumeric.arguments.length == 2) emptyOK = false;
	if ((emptyOK == true) && isEmpty(fld.value)) return true;
	if (re.test(fld.value))
	{
		return warnInvalid(fld,'Oops...\r\rPlease edit your entry. ' + lbl + ' can only contain alphabetic (A-Z and a-z),\rnumeric (0-9) and space characters, as well as:\n \n-');
	}
		return true;
}

function checkRef(fld, lbl, emptyOK)
{
	var re=/[^A-Za-z-0-9]/;
	if (checkRef.arguments.length == 2) emptyOK = false;
	if ((emptyOK == true) && isEmpty(fld.value)) return true;
	if (re.test(fld.value))
	{
		return warnInvalid(fld,'OOPS...\n\nPlease edit your entry in the ' + lbl.toUpperCase() + ' field.\nEnter only letters and numbers (a-z, A-Z, 0-9), as well as:\n\n-');
	}
		return true;
}


function checkTextNumericPlus(fld, lbl, emptyOK)
{
	var re=/[^A-Za-z0-9+\-\s]/;
	if (checkTextNumericPlus.arguments.length == 2) emptyOK = false;
	if ((emptyOK == true) && isEmpty(fld.value)) return true;
	if (re.test(fld.value))
	{
		return warnInvalid(fld,'Oops...\r\rPlease edit your entry. ' + lbl + ' can only contain alphabetic (A-Z and a-z),\rnumeric (0-9) and space characters, as well as:\n \n- +');
		
	}
		return true;
}

function checkTextNumericComma(fld, lbl, emptyOK)
{
	var re=/[^A-Za-z0-9,\-\s]/;
	if (checkTextNumericComma.arguments.length == 2) emptyOK = false;
	if ((emptyOK == true) && isEmpty(fld.value)) return true;
	if (re.test(fld.value))
	{
		return warnInvalid(fld,'Oops...\r\rPlease edit your entry. ' + lbl + ' can only contain alphabetic (A-Z and a-z),\rnumeric (0-9) and space characters, as well as:\n \n, -');
		
	}
		return true;
}

function checkTextNumericCommaPeriod(fld, lbl, emptyOK)
{
	var re=/[^A-Za-z0-9,\.\-\s]/;
	if (checkTextNumericCommaPeriod.arguments.length == 2) emptyOK = false;
	if ((emptyOK == true) && isEmpty(fld.value)) return true;
	if (re.test(fld.value))
	{
		return warnInvalid(fld,'Oops...\r\rPlease edit your entry. ' + lbl + ' can only contain alphabetic (A-Z and a-z),\rnumeric (0-9) and space characters, as well as:\n \n, . -');
		
	}
		return true;
}

function checkTextNumericBracket(fld, lbl, emptyOK)
{
	var re=/[^A-Za-z0-9\(\)\-\s]/;
	if (checkTextNumericBracket.arguments.length == 2) emptyOK = false;
	if ((emptyOK == true) && isEmpty(fld.value)) return true;
	if (re.test(fld.value))
	{
		return warnInvalid(fld,'Oops...\r\rPlease edit your entry. ' + lbl + ' can only contain alphabetic (A-Z and a-z),\rnumeric (0-9) and space characters, as well as:\n \n- ( )');
		
	}
		return true;
}

function checkNumeric(fld, lbl, emptyOK)
{
	var re=/[^0-9]/;
	if (checkNumeric.arguments.length == 2) emptyOK = false;
	if ((emptyOK == true) && isEmpty(fld.value)) return true;
	if (re.test(fld.value))
	{
		return warnInvalid(fld,'OOPS...\n\nPlease edit your entry in the ' + lbl.toUpperCase() + ' field.\nEnter only numbers (0-9).');
	}
		return true;
}

function checkAlpha(fld, lbl, emptyOK)
{	
	var re=/[^A-Za-z]/;
	if (checkAlpha.arguments.length == 2) emptyOK = false;
	if ((emptyOK == true) && isEmpty(fld.value)) return true;
	if (re.test(fld.value))
	{
		return warnInvalid(fld,'Oops...\r\rPlease edit your entry. ' + lbl + ' can only contain alphabetic characters (A-Z and a-z).');
	}
		return true;
}

function checkAlphaDash(fld, lbl, emptyOK)
{	
	var re=/[^A-Za-z\-]/;
	if (checkAlphaDash.arguments.length == 2) emptyOK = false;
	if ((emptyOK == true) && isEmpty(fld.value)) return true;
	if (re.test(fld.value))
	{
		return warnInvalid(fld,'Oops...\r\rPlease edit your entry. ' + lbl + ' can only contain alphabetic characters (A-Z and a-z), as well as:\n \n-');
	}
		return true;
}

function checkAlphaNumeric(fld, lbl, emptyOK)
{
	var re=/[^A-Za-z0-9]/;
	if (checkAlphaNumeric.arguments.length == 2) emptyOK = false;
	if ((emptyOK == true) && isEmpty(fld.value)) return true;
	if (re.test(fld.value))
	{
		return warnInvalid(fld,'OOPS...\n\nPlease edit your entry in the ' + lbl.toUpperCase() + ' field.\nEnter only letters and numbers (a-z, A-Z, 0-9).');
	}
		return true;		
}


function checkAlphaSpace(fld, lbl, emptyOK)
{	
	var re=/[^A-Za-z\s]/;
	if (checkAlphaSpace.arguments.length == 2) emptyOK = false;
	if ((emptyOK == true) && isEmpty(fld.value)) return true;
	if (re.test(fld.value))
	{
		return warnInvalid(fld,'Oops...\r\rPlease edit your entry. ' + lbl + ' can only contain alphabetic characters (A-Z and a-z) and space.');
	}
	 	return true;
		
}

function checkAlphaComma(fld, lbl, emptyOK)
{	
	var re=/[^A-Za-z,\s]/;
	if (checkAlphaComma.arguments.length == 2) emptyOK = false;
	if ((emptyOK == true) && isEmpty(fld.value)) return true;
	if (re.test(fld.value))
	{
		return warnInvalid(fld,'Oops...\r\rPlease edit your entry. ' + lbl + ' can only contain alphabetic (A-Z and a-z)\rand space characters, as well as:\n\n,');
	}
		return true;		
}

function checkName(fld, lbl, emptyOK)
{
	var re=/[^A-Za-z'\-\s]/;
	if (checkName.arguments.length == 2) emptyOK = false;
	if ((emptyOK == true) && isEmpty(fld.value)) return true;
	if (re.test(fld.value))
	{
		return warnInvalid(fld,'OOPS...\n\nPlease edit your entry in the ' + lbl.toUpperCase() + ' field.\nEnter only spaces and letters (a-z, A-Z), as well as:\n\n\' -');
	}
		return true;
}

function checkJobTitle(fld, lbl, emptyOK)
{
	var re=/[\"<>]|(&#)|(&amp;)|(&quot;)|(&gt;)|(&lt;)/;
	if (checkJobTitle.arguments.length == 2) emptyOK = false;
	if ((emptyOK == true) && isEmpty(fld.value)) return true;
	if (re.test(fld.value))
	{
		return warnInvalid(fld,'OOPS...\r\rPlease edit your entry in the ' + lbl.toUpperCase() + ' field.\nThe following characters are NOT allowed:\n\n" < >');
	}
		return true;	
}

function checkSkills(fld, lbl, emptyOK)
{
	var re=/[\"<>]|(&#)|(&amp;)|(&quot;)|(&gt;)|(&lt;)/;
	if (checkSkills.arguments.length == 2) emptyOK = false;
	if ((emptyOK == true) && isEmpty(fld.value)) return true;
	if (re.test(fld.value))
	{
		return warnInvalid(fld,'OOPS...\r\rPlease edit your entry in the ' + lbl.toUpperCase() + ' field.\nThe following characters are NOT allowed:\n\n" < >');
	}
		return true;	
}

function checkCourses(fld, lbl, emptyOK)
{
	var re=/[\"<>]|(&#)|(&amp;)|(&quot;)|(&gt;)|(&lt;)/;
	if (checkCourses.arguments.length == 2) emptyOK = false;
	if ((emptyOK == true) && isEmpty(fld.value)) return true;
	if (re.test(fld.value))
	{
		return warnInvalid(fld,'OOPS...\r\rPlease edit your entry in the ' + lbl.toUpperCase() + ' field.\nThe following characters are NOT allowed:\n\n" < >');	}
		return true;	
}

function checkCompany(fld, lbl, emptyOK)
{
	var re=/[\"\<>]|(&#)|(&amp;)|(&quot;)|(&gt;)|(&lt;)/;
	if (checkCompany.arguments.length == 2) emptyOK = false;
	if ((emptyOK == true) && isEmpty(fld.value)) return true;
	if (re.test(fld.value))
	{
		return warnInvalid(fld,'OOPS...\n\nPlease edit your entry in the ' + lbl.toUpperCase() + ' field.\nThe following characters are NOT allowed:\n\n" < > ');
	}
		 return true;	
}

function checkCity(fld, lbl, emptyOK)
{
	var re=/[\"<>]|(&#)|(&amp;)|(&quot;)|(&gt;)|(&lt;)/;
	if (checkCity.arguments.length == 2) emptyOK = false;
	if ((emptyOK == true) && isEmpty(fld.value)) return true;
	if (re.test(fld.value))
	{
		return warnInvalid(fld,'OOPS...\r\rPlease edit your entry in the ' + lbl.toUpperCase() + ' field.\nThe following characters are NOT allowed:\n\n" < >');
	}
		return true;	
}

function checkGeneric(fld, lbl, emptyOK)
{
	var re=/[\"<>]|(&#)|(&amp;)|(&quot;)|(&gt;)|(&lt;)/;
	if (checkGeneric.arguments.length == 2) emptyOK = false;
	if ((emptyOK == true) && isEmpty(fld.value)) return true;
	if (re.test(fld.value))
	{
		return warnInvalid(fld,'OOPS...\r\rPlease edit your entry in the ' + lbl.toUpperCase() + ' field.\nThe following characters are NOT allowed:\n\n" < >');
	}
		return true;	
}


function checkTemplate(fld, lbl, emptyOK)
{
	var re=/[\"<>]|(&#)|(&amp;)|(&quot;)|(&gt;)|(&lt;)/;
	if (checkTemplate.arguments.length == 2) emptyOK = false;
	if ((emptyOK == true) && isEmpty(fld.value)) return true;
	if (re.test(fld.value))
	{
		return warnInvalid(fld,'OOPS...\n\nPlease edit your entry in the ' + lbl.toUpperCase() + ' field.\nThe following characters are NOT allowed:\n\n" < >');
	}
		return true;	
}

function checkKeywords(fld, lbl, emptyOK, nwords)
{
	var re=/[\"<>]|(&#)|(&amp;)|(&quot;)|(&gt;)|(&lt;)/;
	if (checkKeywords.arguments.length == 2) emptyOK = false;
	if ((emptyOK == true) && isEmpty(fld.value)) return true;
	
	fld.value = stripSurroundComma(fld.value);
	
	//ensure no spurious punctuation:
	var puncRe = /[\/;\*&\.:\\\?\|!\+-]+/;
	if (puncRe.test(fld.value))
	{
		if (! confirm('JUST CHECKING...\n\nYou have entered additional punctuation symbols in your list of keywords.\n\nFor more accurate results:\n\n· Ensure that you have separated your keywords with COMMAS ONLY,\ne.g. Account Manager, Outlook, Access\n· No fullstop at the end of your list of keywords.\n· Do not add unecessary fullstops and other punctuation symbols,\ne.g. ; : / + &\n· Database query language syntax is not accommodated.\n\n- Click OK to continue, OR\n- Click CANCEL to edit your keywords for better results.'))
		{
			fld.focus();
			return false;
		} 
	}
	
	var puncStr = "|[/;\*&\.:\\\?\|!\+-]+";
	var nwordsRe = new RegExp("(" + nwords + puncStr + ")", "i");
			
	var arrayOfKeywords = fld.value.split(',');
	for (var i=0; i < arrayOfKeywords.length; i++) 
	{
		arrayOfKeywords[i] = stripSpace(arrayOfKeywords[i]);
		if (arrayOfKeywords[i] == '')
		{
			return warnInvalid(fld,'OOPS...\n\nPlease edit your entry in the ' + lbl.toUpperCase() + ' field.\nYou have entered an invalid keyword.');
		}
		
		if ((arrayOfKeywords[i].length == 1 && !(arrayOfKeywords[i] == "c" || arrayOfKeywords[i] == "C")) || arrayOfKeywords[i] == "as")
		{
			return warnInvalid(fld,'OOPS...\n\nPlease edit your entry in the ' + lbl.toUpperCase() + ' field.\nYou have entered an invalid keyword.');
		}
		
		if (nwordsRe.test(arrayOfKeywords[i]))
		{
			if (arrayOfKeywords[i] == RegExp.$1)
			{
				return warnInvalid(fld,'OOPS...\n\nPlease edit your entry in the ' + lbl.toUpperCase() + ' field.\nYou have entered the keyword "' + RegExp.$1 + '", which is not allowed.');
			}				
		}
		
		var thisPhraseArr = arrayOfKeywords[i].split(' ');
		if (thisPhraseArr.length > 1)
		{
			var nwCounter = 0;
			for (var cnt=0; cnt < thisPhraseArr.length; cnt++)
			{
				if (nwordsRe.test(thisPhraseArr[cnt]))	
				{						
					if (thisPhraseArr[cnt] == RegExp.$1)
					{
						nwCounter++;					
					}
				}				
			}
			
			if (nwCounter == thisPhraseArr.length)
			{
				return warnInvalid(fld,'OOPS...\n\nPlease edit your entry in the ' + lbl.toUpperCase() + ' field.\nYou have entered the keyword phrase "' + arrayOfKeywords[i] + '", which is not allowed.');
			}
		}
	}

	if (re.test(fld.value))
	{
		return warnInvalid(fld,'OOPS...\n\nPlease edit your entry in the ' + lbl.toUpperCase() + ' field.\nThe following characters are NOT allowed:\n\n" < >');
	}	
	
	
	
	return true;

	/*var i = 0;
	var numquotes = 0;
	
	for (i = 0; i < fld.value.length; i++)
	{
		if (fld.value.charAt(i) == "\"")
		numquotes++;
	}
	
	if (numquotes % 2 != 0)
	{
		return warnInvalid(fld,'Oops...\r\rIt appears that you have not closed all of your quotes.\rPlease edit your entry.');
	}
	
	reA = /\"{2,}/;
	reAB = /\"\s+\"/;
	if (reA.test(fld.value) || reAB.test(fld.value))
	{	
		return warnInvalid(fld,'Oops...\r\rThis error has arisen due to ANY of the following:\r- You have not separated your keywords using commas, OR\r- There are empty quotes in your search string.\r\rPlease edit your entry.');
	}
	
 	reB = /[A-Za-z0-9+\-:]\s{0,}"[A-Za-z0-9+\-:\s]/
	if (reB.test(fld.value))
	{	
		return warnInvalid(fld,'Oops...\r\rThis error has arisen due to ANY of the following:\r- You have not separated your keywords using commas, OR\r- There are empty quotes in your search string.\r\rPlease edit your entry.');
	}

	reC = /^"([A-Za-z0-9+\-:\s]*,+[A-Za-z0-9+\-:\s]*)+"$/;
	if (reC.test(fld.value))
	{
		return warnInvalid(fld,'Oops...\r\rYou have entered an invalid keyword.\rEnsure that commas do not appear between quotes.\r\rPlease edit your entry.');
	}
	else return true;*/
}

function checkTextArea(fld, lbl, emptyOK)
{
	var re=/[\"<>]|(&gt;)|(&lt;)|(&amp;)|(&quot;)|(&#)/;
	if (checkTextArea.arguments.length == 2) emptyOK = false;
	if ((emptyOK == true) && isEmpty(fld.value)) return true;
	if (re.test(fld.value))
	{
		return warnInvalid(fld,'OOPS...\n\nPlease edit your entry in the ' + lbl.toUpperCase() + ' field.\nThe following characters are NOT allowed:\n\n" < > ');
	}
		return true;	
}

function checkDayRange(fld, lbl, emptyOK)
{
	if (checkDayRange.arguments.length == 2) emptyOK = false;
	if ((emptyOK == true) && isEmpty(fld.value)) return true;
	if (fld.value > 0 && fld.value <= 31)
	{		
		return true;
	}
		return warnInvalid(fld,'OOPS...\n\nPlease edit your entry in the ' + lbl.toUpperCase() + ' field.\nEnter the correct day (1-31).');
}

function checkMonthRange(fld, lbl, emptyOK)
{
	if (checkMonthRange.arguments.length == 2) emptyOK = false;
	if ((emptyOK == true) && isEmpty(fld.value)) return true;
	if (fld.value > 0 && fld.value <= 12)
	{		
		return true;
	}
		return warnInvalid(fld,'OOPS...\n\nPlease edit your entry in the ' + lbl.toUpperCase() + ' field.\nEnter the correct month (1-12).');
}

function checkYearRange(fld, lbl, emptyOK)
{
	var d = new Date();
	if (checkYearRange.arguments.length == 2) emptyOK = false;
	if ((emptyOK == true) && isEmpty(fld.value)) return true;
	if (fld.value >= 1900 && fld.value <= d.getFullYear())
	{		
		return true;
	}
		return warnInvalid(fld,'OOPS...\n\nPlease edit your entry in the ' + lbl.toUpperCase() + ' field.\nEnter the correct year (1900-' + d.getFullYear() + ').');
}

function checkGivenYearRange(fld, lbl, minyear, maxyear, emptyOK)
{
	var d = new Date();
	if (checkGivenYearRange.arguments.length == 4) emptyOK = false;
	if ((emptyOK == true) && isEmpty(fld.value)) return true;
	if (fld.value >= minyear && fld.value <= maxyear)
	{		
		return true;
	}
		return warnInvalid(fld,'OOPS...\n\nPlease edit your entry in the ' + lbl.toUpperCase() + ' field.\nEnter the correct year (' + minyear + '-' + maxyear + ').');
}


function checkDate(fld, myDate, lbl, emptyOK)
{
	if (checkDate.arguments.length == 3) emptyOK = false;
	if ((emptyOK == true) && isEmpty(fld.value)) return true;
	if (isDate(myDate))
	{		
		return true;
	}
		return warnInvalid(fld,'OOPS...\n\nPlease edit your entry in the ' + lbl.toUpperCase() + ' field.\nYou have entered an incorrect date.');
}

function isDate(strDate) 
{
	//var strDatestyle = "US"; //United States date style
	var strDatestyle = "EU";  //European date style
	var strDateArray;
	var strDay;
	var strMonth;
	var strYear;
	var intday;
	var intMonth;
	var intYear;
	var booFound = false;
	var strSeparatorArray = new Array("-"," ","/",".");
	var intElementNr;
	var err = 0;
	var strMonthArray = new Array(12);
	
	strMonthArray[0] = "Jan";
	strMonthArray[1] = "Feb";
	strMonthArray[2] = "Mar";
	strMonthArray[3] = "Apr";
	strMonthArray[4] = "May";
	strMonthArray[5] = "Jun";
	strMonthArray[6] = "Jul";
	strMonthArray[7] = "Aug";
	strMonthArray[8] = "Sep";
	strMonthArray[9] = "Oct";
	strMonthArray[10] = "Nov";
	strMonthArray[11] = "Dec";
	
	if (strDate.length < 1) { return(false); }
	
	for (intElementNr = 0; intElementNr < strSeparatorArray.length; intElementNr++) 
	{
		if (strDate.indexOf(strSeparatorArray[intElementNr]) != -1) 
		{
			strDateArray = strDate.split(strSeparatorArray[intElementNr]);
			if (strDateArray.length != 3) 
			{
				err = 1;
				return(false);
			} else {
				strDay = strDateArray[0];
				strMonth = strDateArray[1];
				strYear = strDateArray[2];
			}
			booFound = true;
	   }
	}

	if (booFound == false) 
	{
		if (strDate.length>5) 
		{
			strDay = strDate.substr(0, 2);
			strMonth = strDate.substr(2, 2);
			strYear = strDate.substr(4);
	    }
	}
	if (strYear.length == 2) 
	{
		strYear = '20' + strYear;
	}
	// US style
	if (strDatestyle == "US") 
	{
		strTemp = strDay;
		strDay = strMonth;
		strMonth = strTemp;
	}

	intday = parseInt(strDay, 10);

	if (isNaN(intday)) 
	{
		err = 2;
		return false;
	}

	intMonth = parseInt(strMonth, 10);
	if (isNaN(intMonth)) 
	{
		for (i = 0;i<12;i++) {
			if (strMonth.toUpperCase() == strMonthArray[i].toUpperCase()) 
			{
				intMonth = i+1;
				strMonth = strMonthArray[i];
				i = 12;
		    }
		}
		if (isNaN(intMonth)) 
		{
			err = 3;
			return false;
        }
	}
	intYear = parseInt(strYear, 10);
	if (isNaN(intYear)) 
	{
		err = 4;
		return false;
	}
	if (intMonth>12 || intMonth<1) 
	{
		err = 5;
		return false;
	}
	if ((intMonth == 1 || intMonth == 3 || intMonth == 5 || intMonth == 7 || intMonth == 8 || intMonth == 10 || intMonth == 12) && (intday > 31 || intday < 1)) 
	{
		err = 6;
		return false;
	}
	if ((intMonth == 4 || intMonth == 6 || intMonth == 9 || intMonth == 11) && (intday > 30 || intday < 1)) 
	{
		err = 7;
		return false;
	}
	if (intMonth == 2) 
	{
		if (intday < 1) 
		{
			err = 8;
			return false;
		}
		if (LeapYear(intYear) == true) 
		{
			if (intday > 29) 
			{
				err = 9;
				return false;
			}
		} else 
		{
			if (intday > 28) 
			{
				err = 10;
				return false;
			}
		}
	}
	
	return(true);
}
function LeapYear(intYear) 
{
	if (intYear % 100 == 0) 
	{
		if (intYear % 400 == 0) { return(true); }
	} else {
		if ((intYear % 4) == 0) { return(true); }
	}
	return(false);
}


function DaysInMonth(month)
{
	switch (month)
	{
		case 0: return(31); break;
		case 1: return(28); break;
		case 2: return(31); break;
		case 3: return(30); break; 
		case 4: return(31); break;
		case 5: return(30); break;
		case 6: return(31); break;   
		case 7: return(31); break; 
		case 8: return(30); break; 
		case 9: return(31); break; 
		case 10: return(30); break; 
		case 11: return(31); break; 
		default: return (28);
	}
}
		


function checkFromTo(fld, strDateOne, strDateTwo) 
{
	if (Date.parse(strDateOne) <= Date.parse(strDateTwo)) 
	{
		return true;
	}
		return warnInvalid(fld, 'OOPS...\n\nPlease edit your entry in the TO DATE field.\nYou have entered a date prior to the FROM DATE field.');
}

function trim(str)
{
	if (! isEmpty(str))
	{
		while(''+str.charAt(0)==' ') str=str.substring(1,str.length);

		while(''+str.charAt(str.length-1)==' ') str=str.substring(0,str.length-1);
	}
	return(str);
}


function checkLength(fld,lbl,maxval,emptyOK)
{	
	if (checkLength.arguments.length == 3) { emptyOK = false };
	if ((emptyOK == true) && isEmpty(fld.value)) return true;
	fld.value = trim(fld.value);
	fld.value = trim(fld.value);
	if (isSpace(fld.value)) fld.value = "";
	if (isEmpty(fld.value)) return warnEmpty(fld,lbl);
	if (fld.value.length > maxval) 
	{
		return warnInvalid(fld,'OOPS...\n\nPlease edit your entry in the ' + lbl.toUpperCase() + ' field.\nYou have entered ' + fld.value.length + ' characters.\nThis field is limited to ' + maxval + ' characters (approx ' + (maxval/50) + ' lines).');
	} else 
	{
		return true;
	}
}

function checkMinLength(fld,lbl,minlen,emptyOK)
{	
	if (checkMinLength.arguments.length == 3) emptyOK = false;
	if ((emptyOK == true) && isEmpty(fld.value)) return true;
	fld.value = trim(fld.value);
	if (isSpace(fld.value)) fld.value = "";
	if (isEmpty(fld.value)) return warnEmpty(fld, lbl);
	if (fld.value.length < minlen) 
	{
		return warnInvalid(fld,'OOPS...\n\nPlease edit your entry in the ' + lbl.toUpperCase() + ' field.\nThis field must contain at least ' + minlen + ' characters.');
	} else 
	{
		return true;
	}
}


function checkPhone(fld,lbl,emptyOK)
{
	if (checkPhone.arguments.length == 2) emptyOK = false;
	if ((emptyOK == true) && isEmpty(fld.value)) return true;
	if (! isPhone(fld.value)) return warnInvalid(fld,'OOPS...\n\nPlease edit your entry in the ' + lbl.toUpperCase() + ' field.\nEnter the correct international format, for example:\n\n+27 21 659 2500');
	return true;
}

function checkEmail(fld,lbl,emptyOK)
{
	if (checkEmail.arguments.length == 2) { emptyOK = false };
	if ((emptyOK == true) && isEmpty(fld.value)) return true;  
	
	if (! emailvalidate(fld.value))  
		{
			return warnInvalid(fld,'OOPS...\n\nPlease edit your entry in the ' + lbl.toUpperCase() + ' field.\nEnter the correct email address format, for example:\n\nsomeone@somewhere.co.za');
		} else 
		{
			return true;
		}
}

function fixEmail(fld)
{	
	var result = '';
	result = fld.value.replace("hotmail.co.za", "hotmail.com");
	result = fld.value.replace("webmail.com", "webmail.co.za");
	result = fld.value.replace("yahoo.co.za", "yahoo.com");
	result = fld.value.replace("absa.freemail.co.za","freemail.absa.co.za");
	alert(result);
	return(result);
}

function warnEmpty(fld,lbl)
{
	fld.focus();
	alert('OOPS...\n\nPlease add an entry in the ' + lbl.toUpperCase() + ' field.\nThis field is required.');
	return false;
}

function warnInvalid(fld,msg)
{
	fld.focus();
	if ((fld.type == 'password') || (fld.type == 'text') || (fld.type == 'textarea')) fld.select();
	alert(msg);
	return false;
}

/*checks to see if Template Name already contained in Import Template dropdown:*/
/*function checkTemplateExists()
{	
	var i;
	for (i = 0; i < document.form.template.length; i++)
	{
		if (document.form.template.options[i].text == document.form.templatename.value)
		{
			document.form.templatename.focus();
			alert("Oops...\nThe template name you have chosen already exists.\nPlease choose another template name or leave the field blank\nif you do not wish to save this as a template.");
			return false;
		} 
	}
	return true;
}*/


function openWin (url,name,features)
{
	var mywin = window.open(url,name,features);
}

function closeWin()
{
	var mywin = window.close();
}

function checkDelete()
{
if (confirm('IMPORTANT!\r\rAre you sure you want to permanently delete\rall records of yourself?'))
	{
	document.form.action = "/careerseekers/portfolio/deleteme/deletemefrmupd";
	document.form.submit();
	}
}	

function stripComma(str)
{
	var reBegin = /^,+/;
	str = str.replace(reBegin, "");
	reBegin = null;

	var reEnd = /,+$/;
	str = str.replace(reEnd, "");
	reEnd = null;

	var reMid = /,{2,}/;
	str = str.replace(reMid, ",");
	reMid = null;

	return str;
}

function stripSurroundComma(str)
{
	var reBegin = /^\s*,+/;
	str = str.replace(reBegin, "");
	reBegin = null;

	var reEnd = /,+\s*$/;
	str = str.replace(reEnd, "");
	reEnd = null;

	return str;
}

function stripSpace(str)
{
	var reBegin = /^\s+/;
	str = str.replace(reBegin, "");
	reBegin = null;

	var reEnd = /\s+$/;
	str = str.replace(reEnd, ""); 
	reEnd = null;

	return str;
}

function getJavaVersion()
{		
	var agt=navigator.userAgent.toLowerCase();

     // *** BROWSER VERSION ***
     // Note: On IE5, these return 4, so use is_ie5up to detect IE5.
     var is_major = parseInt(navigator.appVersion);
     var is_minor = parseFloat(navigator.appVersion);

     // Note: Opera and WebTV spoof Navigator.  We do strict client detection.
     // If you want to allow spoofing, take out the tests for opera and webtv.
     var is_nav  = ((agt.indexOf('mozilla')!=-1) && (agt.indexOf('spoofer')==-1) && (agt.indexOf('compatible') == -1) && (agt.indexOf('opera')==-1) && (agt.indexOf('webtv')==-1) && (agt.indexOf('hotjava')==-1));
     var is_nav2 = (is_nav && (is_major == 2));
     var is_nav3 = (is_nav && (is_major == 3));
     var is_nav4 = (is_nav && (is_major == 4));
     var is_nav4up = (is_nav && (is_major >= 4));
     var is_navonly = (is_nav && ((agt.indexOf(";nav") != -1) || (agt.indexOf("; nav") != -1)) );
     var is_nav6 = (is_nav && (is_major == 5));
     var is_nav6up = (is_nav && (is_major >= 5));
     var is_gecko = (agt.indexOf('gecko') != -1); 

     var is_ie     = ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1));
     var is_ie3    = (is_ie && (is_major < 4));
     var is_ie4    = (is_ie && (is_major == 4) && (agt.indexOf("msie 5")==-1) );
     var is_ie4up  = (is_ie && (is_major >= 4));
     var is_ie5    = (is_ie && (is_major == 4) && (agt.indexOf("msie 5.0")!=-1) );
     var is_ie5_5  = (is_ie && (is_major == 4) && (agt.indexOf("msie 5.5") !=-1));
     var is_ie5up  = (is_ie && !is_ie3 && !is_ie4);
     var is_ie5_5up =(is_ie && !is_ie3 && !is_ie4 && !is_ie5);

     // KNOWN BUG: On AOL4, returns false if IE3 is embedded browser
     // or if this is the first browser window opened.  Thus the
     // variables is_aol, is_aol3, and is_aol4 aren't 100% reliable.
     var is_aol   = (agt.indexOf("aol") != -1);
     var is_aol3  = (is_aol && is_ie3);
     var is_aol4  = (is_aol && is_ie4);
     var is_aol5  = (agt.indexOf("aol 5") != -1);
     var is_aol6  = (agt.indexOf("aol 6") != -1);

     var is_opera = (agt.indexOf("opera") != -1);
     var is_opera2 = (agt.indexOf("opera 2") != -1 || agt.indexOf("opera/2") != -1);
     var is_opera3 = (agt.indexOf("opera 3") != -1 || agt.indexOf("opera/3") != -1);
     var is_opera4 = (agt.indexOf("opera 4") != -1 || agt.indexOf("opera/4") != -1);
     var is_opera5 = (agt.indexOf("opera 5") != -1 || agt.indexOf("opera/5") != -1);
     var is_opera5up = (is_opera && !is_opera2 && !is_opera3 && !is_opera4);

     var is_webtv = (agt.indexOf("webtv") != -1); 

     var is_TVNavigator = ((agt.indexOf("navio") != -1) || (agt.indexOf("navio_aoltv") != -1)); 
    var is_AOLTV = is_TVNavigator;

     var is_hotjava = (agt.indexOf("hotjava") != -1);
     var is_hotjava3 = (is_hotjava && (is_major == 3));
     var is_hotjava3up = (is_hotjava && (is_major >= 3));
	 // *** JAVASCRIPT VERSION CHECK ***
     var is_js;
     if (is_nav2 || is_ie3) is_js = 1.0;
     else if (is_nav3) is_js = 1.1;
     else if (is_opera5up) is_js = 1.3;
     else if (is_opera) is_js = 1.1;
     else if ((is_nav4 && (is_minor <= 4.05)) || is_ie4) is_js = 1.2;
     else if ((is_nav4 && (is_minor > 4.05)) || is_ie5) is_js = 1.3;
     else if (is_hotjava3up) is_js = 1.4;
     else if (is_nav6 || is_gecko) is_js = 1.5;
     // NOTE: In the future, update this code when newer versions of JS
     // are released. For now, we try to provide some upward compatibility
     // so that future versions of Nav and IE will show they are at
     // *least* JS 1.x capable. Always check for JS version compatibility
     // with > or >=.
     else if (is_nav6up) is_js = 1.5;
     // NOTE: ie5up on mac is 1.4
     else if (is_ie5up) is_js = 1.3

     // HACK: no idea for other browsers; always check for JS version with > or >=
     else is_js = 0.0;
     return is_js;
}	

function getBrowserDetails()
{			
	document.form.browserClient.value = navigator.appName;
	document.form.browserVersion.value = navigator.appVersion;
	document.form.browserMinorVersion.value = navigator.appMinorVersion;
	document.form.browserVersion.value = navigator.appVersion;
	document.form.browserAgent.value = navigator.userAgent;
	document.form.browserJavaScript.value = getJavaVersion();
}
	
function IPRangeValid(IPRange)
/*
	IPRangeValid routine
	
	Input	: IPRange - comma separated list of IP Addreses
			: in format 123.123.123.0-197, 123.123.123.123, 123,123,123,*
			: or *.*.*.* meaning any IP address is valid
	Output	: Boelean, indicating that the IPRange was formatted OK.
			: true means the IPRange is a validly formatted one
			: false means the IPRange is not validly formatted
*/
{
	var anyIPValid = '*.*.*.*';				
	// Check to see that we have something in the IPRange to check against
	if (IPRange == '') 
	{
		document.form.ipaddresses.focus();
		alert('Oops\r\rYou have entered an invalid IP Address range.');
		return(false);
	}
	//the pattern below is not allowed
	myRe = /(\-\*)|(\*\-)/;
	if (myRe.test(IPRange))
	{
		document.form.ipaddresses.focus();
		alert('Oops\r\rYou have entered an invalid IP Address range.');
		return(false);
	}	
	// If the range is any then exit OK.
	if (IPRange == anyIPValid) {return(true);} 
	// Check the client IP against the range
	var arr, cnt, i, re, rearr, nextvip;
	// Put the range into an array for easier checking
	arr = IPRange.split(',');
	// Count the number of items in the array
	cnt = arr.length;
	// Set the regular expression to validate the IPRange(s)
	re = /[0-9]{1,3}\.[0-9]{1,3}\.([0-9]{1,3}|\*)\.([0-9]{1,3}|[0-9]{1,3}\-[0-9]{1,3}|\*)/ig
	// For each IP entry in the array, do the check
	for (i=0; i < cnt; i++)
	{
		// Fetch the next valip ip address in the range
		nextvip = arr[i];
		// Try and match to the pattern required
		rearr = nextvip.match(re);
		// If no match found for this IP Address then Range is invalid
		if (rearr == null) 
		{
			document.form.ipaddresses.focus();
			alert('Oops\r\rYou have entered an invalid IP Address range.');
			return(false);
		}
	}
	// All IP Addresses in Range passed check then range is valid.
	return(true);
}