function validateDateField(theValue, theObj)
{
   var theDate, isValide;

   dateStr = theValue;
   if (Trim(dateStr) == '')
     return true;

   nIndex = dateStr.indexOf('/');
   theMonth = dateStr.substring(0, nIndex);
   sRemain  = dateStr.substring(nIndex+1, dateStr.length);
   nIndex2 = sRemain.indexOf('/');
   theDay = sRemain.substring(0, nIndex2);
   theYear = sRemain.substring(nIndex2+1, sRemain.length);
   if (isNaN(theMonth) || isNaN(theDay) || isNaN(theYear))
   {
      alert('It is not a valid date!');
      theObj.focus();
      theObj.select();
      return false;
   }
   theDate = new Date(theYear, eval(theMonth-1), theDay);
   if (isNaN(theDate) || 
      (eval(theMonth)+'/'+eval(theDay)+'/'+eval(theYear)) != ((theDate.getMonth()+1)+'/'+theDate.getDate()+'/'+theDate.getFullYear()))
   {
      alert('It is not a valid date!');
      theObj.focus();
      theObj.select();
      return false;
   }
   if (theMonth.length > 2)
   {
      alert("Month can't be more than 2 digits!");
      theObj.focus();
      theObj.select();
      return false;
   }
   if (theDay.length > 2)
   {
      alert("Day can't be more than 2 digits!");
      theObj.focus();
      theObj.select();
      return false;
   }
   if (theYear.length != 4)
   {
      alert('Year must be 4 digits!');
      theObj.focus();
      theObj.select();
      return false;
   }
   return true;
 }

function Trim(theString) 
{ 
   var sTemp;

   sTemp = ""; 
   if (theString != null)  
      sTemp = theString.replace(/(^\s+)|(\s+$)/g, "");
   return sTemp;
}

function isANumber(theField)
{  
   if (isNaN(theField.value) || theField.value.indexOf('-') >= 0 || theField.value.indexOf('.') >= 0)
   {  
      alert ('Only number can be entered here.');
      theField.select(); 
      theField.focus();
      return false;
   }
   return true;
}

function CheckFieldLength(theField, theLength)
{  
   sStr = Trim(theField.value);
   if (sStr.length > 0 && sStr.length < theLength)
   {
      alert ('You must enter '+ theLength+ ' digits here.');
      theField.select(); 
      theField.focus();
      return false;
   }
   return true;
}

function CheckPhoneLength(theField)
{  
   sStr = Trim(eval('RepDetails.'+theField+'Part1.value'))+Trim(eval('RepDetails.'+theField+'Part2.value'))+Trim(eval('RepDetails.'+theField+'Part3.value'));
   if (sStr.length > 0 && sStr.length < 10)
   {  
      alert ('You must enter 10 digits for '+theField+' number.');
      eval('RepDetails.'+theField+'Part1').focus();
      return false;
   }
   return true;
}

function verifyTaskFields(theForm)
{
   var theSelProj = "";
   if (theForm.Category.value != 1 && theForm.action != 'SaveEditTask.asp')
   {
      for (i=0; i<theForm.length; i++) 
      {
         if (theForm.item(i).name.substring(0, 10) == 'AppProject')
            if (theForm.item(i).checked)
                theSelProj = theSelProj + theForm.item(i).value+" ";
//      alert(theForm.item(i).name + ' ** ' +theForm.item(i).value+ ' ** ' + theForm.item(i).checked);
      }
      theForm.SelProjects.value = Trim(theSelProj);
//   alert(theForm.SelProjects.value);
      if (Trim(theForm.SelProjects.value) == '') 
      {
         alert('At least one Project is required!');
         return false;
      }
   }
   if (Trim(theForm.Description.value) == '' && theForm.action != 'SaveEditTask.asp')
   {
      alert('Description is required!');
      theForm.Description.focus();
      theForm.Description.select();
      return false;
   }
//   theForm.DueDate.value=Trim(theForm.DueDatePart1.value)+'/'+Trim(theForm.DueDatePart2.value)+'/'+Trim(theForm.DueDatePart3.value); 
//   if (theForm.DueDate.value == '//')
//      theForm.DueDate.value = '';
//   if (!validateDateField(theForm.DueDate.value, theForm.DueDatePart1))
//      return false;
   return true;
}

function ClearOtherCheckBoxForAll(theForm, theBoxVlu)
{
   for (i=0; i<theForm.length; i++) 
   {
      tmpStr = theForm.elements(i).name 
      if (tmpStr.substring(0, 10) == 'AppProject')
      {
         if (theBoxVlu == 'ALL')
         {
            if (theForm.elements(i).value != 'ALL')
                theForm.elements(i).checked = false;
         }
         else
         {
            if (theForm.elements(i).value == 'ALL')
                theForm.elements(i).checked = false;
         }
      }
   }
}

function autoTab(input,len, e)
{
   var keyCode = e.keyCode;
   var filter = [0,8,9,16,17,18,37,38,39,40,46];
   if(input.value.length >= len && !containsElement(filter,keyCode))
   {
     input.value = input.value.slice(0,len);
     input.form[(getIndex(input)+1)%input.form.length].focus();
   }
   function containsElement(arr, ele)
   {
     var found = false, index = 0;
     while(!found && index < arr.length)
       if(arr[index]==ele)
         found = true;
       else
         index++;
     return found;
   }
   function getIndex(input){
     var index = -1, i = 0, found = false;
     while (i < input.form.length && index==-1)
       if (input.form[i] == input)index = i;
       else i++;
     return index;
   }
   return true;
}

function IsOKToEnableObject(theCondition, theObject)
{
   if (theCondition)
      theObject.disabled = false;
   else
      theObject.disabled = true;
}

function CheckRequiredField(theObj, theName)
{
   if (Trim(theObj.value) == '')
   {
      alert(theName+' is required!');
      theObj.focus();
      theObj.select();
      return false;
   }
   return true;
}

function CheckRequiredSelectBox(theObj, theName)
{
   if (theObj.options.length==0 || Trim(theObj.options[theObj.selectedIndex].text) == '')
   {
      alert(theName+' is required!');
      theObj.focus();
      return false;
   }
   return true;
}

function verifyMemberFields(theForm)
{
   if (!CheckRequiredField(theForm.FirstName, 'First Name'))
      return false;
   if (!CheckRequiredField(theForm.LastName, 'Last Name'))
      return false;
   if (!CheckRequiredField(theForm.LoginID, 'Login ID'))
      return false;
   if (!CheckRequiredField(theForm.eMail1, 'EMail 1'))
      return false;
   return true;
}

function verifyGroupFields(theForm)
{
   if (!CheckRequiredField(theForm.GroupName, 'Group Name'))
      return false;
   return true;
}

function showNotFinishedFeature()
{
   alert('It is under construction and will be available soon!!');
}


function showOnlyForGroupAdmin()
{
   alert('Only your group administrator can use this function!!');
}

function getLoginMemberName()
{
   return parent.parent.frames(0).LoginMember.LoginId.value;
}

function StrLowerAndNoSpace(theStr)
{
   return theStr.toLowerCase().replace(/\s/g, '');
}

function CheckMaxLength(theString, theMax, theObj)
{
   var tmpStr;
   
   if (theString.length > theMax)
   {
      tmpStr = theObj.value;
      theObj.value = tmpStr.substring(0, theMax);
      theObj.select();
      theObj.focus();
      alert("You've reached the maximum of " + theMax +" characters. You can not enter any more text!");
      return false;
   }
   return true;
}
