function textCounter() 
{
      field = document.all.Message;
      countfield = document.all.remLentext;
      maxlimit = 160;
      if (field.value.length > maxlimit)
      {
          field.value = field.value.substring(0, maxlimit);
      }
      else
      {
          countfield.value = maxlimit - field.value.length;
      }

      return true;
}
function CheckSMSFields()
{
  if ( ( document.all.extra_numbers.value == "" ) &&
       ( document.all.Product_Type.value == "") )
  {   
          alert("Please enter atleast one criteria");
          return false;
  }

  if ( ( document.all.extra_numbers.value != "" ) &&
       ( document.all.Product_Type.value != "") )
  {   
          alert("Please enter ONE criteria ONLY");
          return false;
  }

  if (document.all.Message.value == "")
  {
    alert(" Message to be sent not entered");
    document.all.Message.focus();
    document.all.Message.select();
    return false;
  }

   if ( document.all.Message.value.length > 160 )
   {
         alert("Message must be less than 161 characters long, it is " + document.all.Message.value.length );
         document.all.Message.focus();
         document.all.Message.select();
         return false;
    }
    return true;
}

function CheckMailSubscribersFieldTs()
{

  if (document.all.MailBody.value == "")
  {
    alert("Please enter email body in an html format");
    document.all.MailBody.focus();
    document.all.MailBody.select();
    return false;
  }

  if (document.all.MailSubject.value == "")
  {
    alert("Please enter email SUBJECT");
    document.all.MailSubject.focus();
    document.all.MailSubject.select();
    return false;
  }

  return true;
}
function CheckFields()
{

  var hasAt = 0;
  var hasDot = 0;

  if (document.all.CustomerName.value == "")
  {
    alert("Please enter Customer Name");
    document.all.CustomerName.focus();
    document.all.CustomerName.select();
    return false;
  }

   if (document.all.ContactNo.value == "")
  {
    alert("Please enter a valid Contact Number");
    document.all.ContactNo.focus();
    document.all.ContactNo.select();
    return false;
  }
  if (document.all.Email.value == "")
  {
    alert("Please enter a valid eMail Address");
    document.all.Email.focus();
    document.all.Email.select();
    return false;
  }
  else
  {
    hasAt = document.all.Email.value.indexOf("@");
    hasDot = document.all.Email.value.indexOf(".");

    if ( hasDot == -1 || hasAt == -1)
    {
       alert("Please enter a valid email address");
      document.all.Email.focus();
      document.all.Email.select();
       return false;
    }
  }
  if (document.all.Comments.value == "")
  {
    alert("Please enter a valid Comments ");
    document.all.Comments.focus();
    document.all.Comments.select();
    return false;
  }

  return true;
}

function CheckQueryFields()
{

  if (document.all.q.value == "")
  {
    alert("Please enter a valid Text to search for");
    document.all.q.focus();
    document.all.q.select();
    return false;
  }

  return true;
}

function CheckSubFields2()
{
  var hasDot = 0;
  var fieldlength = 0;
  var hasAt  = 0;

  if (document.all.Subscriber.value == "")
  {
    alert("You must enter a valid Mobile Number or eMail address");
    document.all.Subscriber.focus();
    return false;
  }

  fieldlength = document.all.Subscriber.value.length;

  hasAt = document.all.Subscriber.value.indexOf("@");
  hasDot = document.all.Subscriber.value.indexOf(".");

  if ( (hasDot == -1 || hasAt == -1) && (fieldlength != 11) )
  {
     alert("Please enter a valid email address or Mobile number");
    document.all.Subscriber.focus();
    document.all.Subscriber.select();
     return false;
  }
  hasZero = document.all.Subscriber.value.indexOf("0");
  if ( (fieldlength == 11) && (hasZero == -1))
  {
     alert("Please enter a valid Mobile number");
     document.all.Subscriber.focus();
     document.all.Subscriber.select();
     return false;
  }

  return true;
}
function CheckQueryFields()
{

  if (document.all.q.value == "")
  {
    alert("Please enter a valid Text to search for");
    document.all.q.focus();
    document.all.q.select();
    return false;
  }

  return true;
}

function CheckSubFields()
{
  var hasDot = 0;
  var fieldlength = 0;
  var hasAt  = 0;

  if (document.all.Subscriber_Name.value == "")
  {
    alert("You must enter your NAME");
    document.all.Subscriber_Name.focus();
    return false;
  }

  if (document.all.action.value == "")
  {
    alert("Please enter a valid Mobile number e.g 0761223033  or email address info@gentlepassage.co.za");
    document.all.action.focus();
    return false;
  }
  fieldlength = document.all.action.value.length;

  hasAt = document.all.action.value.indexOf("@");
  hasDot = document.all.action.value.indexOf(".");

  if ( (hasDot == -1 || hasAt == -1) && (fieldlength != 10) )
  {
     alert("Please enter a valid Mobile number e.g 0761223033  or email address info@gentlepassage.co.za");
    document.all.action.focus();
    document.all.action.select();
     return false;
  }

  return true;
}
function getthedate()
{
  var dayarray=new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday");
  var montharray=new Array("January","February","March","April","May","June","July","August","September","October","November","December");
  var mydate=new Date();
  var year=mydate.getYear();
  if (year < 1000)
     year+=1900;
  var day=mydate.getDay();
  var month=mydate.getMonth();
  var daym=mydate.getDate();
  if (daym<10)
     daym="0"+daym;
  var hours=mydate.getHours();
  var minutes=mydate.getMinutes();
  var seconds=mydate.getSeconds();
  var dn="AM";
  if (hours>=12)
     dn="PM";
  if (hours>12)
  {
      hours=hours-12;
  }

if (hours==0)
     hours=12;
  if (minutes<=9)
     minutes="0"+minutes;
  if (seconds<=9)
     seconds="0"+seconds;

var cdate="<b>"+dayarray[day]+", "+montharray[month]+" "+daym+", "+year+" "+hours+":"+minutes+":"+seconds+" "+dn+"</b>";
//document.write(setInterval(cdate,1000));
//document.write(cdate);
// return (cdate);
if (document.all)
   document.all.clock.innerHTML=cdate;
else if (document.getElementById)
   document.getElementById("clock").innerHTML=cdate;
else
   document.write(cdate);
}

function goforit()
{
  if (document.all||document.getElementById)
    setInterval("getthedate()",1000);
}

function CheckLoginFields()
{

  if (document.all.username.value == "")
  {
    alert("Please enter a valid USERNAME to Login");
    document.all.username.focus();
    document.all.username.select();
    return false;
  }

  if (document.all.password.value == "")
  {
    alert("Please enter a valid PASSWORD to Login");
    document.all.password.focus();
    document.all.password.select();
    return false;
  }
  return true;
}
function CheckAddCustFields()
{
      if ( document.all.Customer_Id.value == "")
      {
         alert("CUSTOMER ID must be entered");
         document.all.Customer_Id.focus();
         document.all.Customer_Id.select();
         return false;
      }
      if ( document.all.Password_Id.value == "")
      {
         alert("PASSWORD ID must be entered");
         document.all.Password_Id.focus();
         document.all.Password_Id.select();
         return false;
      }

      return true;
}
function CheckUpdateCustFields()
{
  if (document.all.Customer_Id.value == "")
  {
    alert("Please enter at least CUSTOMER_ID");
    document.all.Customer_Id.focus();
    document.all.Customer_Id.select();
    return false;
  }

  return true;
}
function CheckRemoveCustFields()
{
   if (document.all.Customer_Id.value == "")
   {
      alert("Please enter at least CUSTOMER ID");
      document.all.Customer_Id.focus();
      document.all.Customer_Id.select();
      return false;
   }
   return true;
}
function CheckAddProdFields()
{
   if (document.all.Product_Id.value == "")
   {
      alert("Please enter at least PRODUCT ID");
      document.all.Product_Id.focus();
      document.all.Product_Id.select();
      return false;
   }
   if (document.all.Product_Name.value == "")
   {
      alert("Please enter at least PRODUCT NAME");
      document.all.Product_Name.focus();
      document.all.Product_Name.select();
      return false;
   }
   return true;
}
function CheckUpdateProdFields()
{
   if (document.all.Product_Id.value == "")
   {
      alert("Please enter at least PRODUCT ID");
      document.all.Product_Id.focus();
      document.all.Product_Id.select();
      return false;
   }
   return true;
}
function CheckRemoveProdFields()
{
   if (document.all.Product_Id.value == "")
   {
      alert("Please enter at least PRODUCT ID");
      document.all.Product_Id.focus();
      document.all.Product_Id.select();
      return false;
   }
   return true;
}
function CheckTestProdFields()
{
  if ( (document.all.action.value == "") && (document.all.cliMsgId.value == "0") )
  {
    alert("Please enter at least ACTION OR Order ID");
    document.all.action.focus();
    document.all.action.select();
    return false;
  }

  if ( (document.all.cliMsgId.value != "0") )
  {
     if ( (document.all.status.value == "") )
     {
       alert("You must provide the Status to update to");
       document.all.status.focus();
       document.all.status.select();
       return false;
     }
  }

  if (document.all.action.value != "")
  {
     if (document.all.from.value == "")
     {
       alert("Please enter the sender FROM number");
       document.all.from.focus();
       document.all.from.select();
       return false;
     }
  }

  if (document.all.from.value != "")
  {
     if (document.all.from.value == "")
     {
       alert("FROM number must ALWAYS be entered!!");
       document.all.from.focus();
       document.all.from.select();
       return false;
     }
  }
  return true;
}
function CheckSupportCustFields()
{
			     if (document.all.Customer_Id.value == "")
			     {
			        alert("Please enter at least CUSTOMER_ID");
				document.all.Customer_Id.focus();
				document.all.Customer_Id.select();
				return false;
			     }
  return true;
}

