/*
*   File Name     : clientValidate.php
*   Created On    : 06/04/2004
*   Description   : This file Contains the functions to perform client side validation
    Modified By   : N. Sasikumar
    Modified Date : 19/12/2005
*/

var renamemustpat=/^[A-Za-z]+[A-Za-z\s.-]*$/;
var compnamepat=/^[A-Za-z]+[A-Za-z0-9\s.,&]*$/;
var renamepat=/^[A-Za-z]+$/;
var alphanumericdotpat=/^[A-Za-z0-9]+[A-Za-z0-9\.]*$/;
var realphanumericpat=/^[A-Za-z0-9]+$/;
var ressnopat =/^\d{4}$/;
var rephonepat =/^\d[\d-]+\d$/;
var phonepat =/^[\d-]+$/;
var rephonecodepat =/^\d{1,}$/;
var renumdotpat =/^[0-9]+[0-9\,.]+\d$/;
var reemailpat = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,4}))$/;
var usernamepat=/^\S{6,}$/;
var userpwdpat=/^\S{8,}$/;
var optSelectedPat=/^[^0][0-9a-zA-Z]*$/;
var nospacepat=/^\S+$/;
var notnullpat=/\w/;

//Function to trim a string
function trim(inputString)
{
  var retValue = inputString;
  var ch = retValue.substring(0, 1);
  // Check for spaces at the beginning of the string
  while (ch == " ")
  {
    retValue = retValue.substring(1, retValue.length);
    ch = retValue.substring(0, 1);
  }
  ch = retValue.substring(retValue.length-1, retValue.length);

  // Check for spaces at the end of the string
  while (ch == " ")
  {
    retValue = retValue.substring(0, retValue.length-1);
    ch = retValue.substring(retValue.length-1, retValue.length);
  }
  while (retValue.indexOf("  ") != -1)
  {
    // Note that there are two spaces in the string - look for multiple spaces within the string
    retValue = retValue.substring(0, retValue.indexOf("  ")) + retValue.substring(retValue.indexOf("  ")+1, retValue.length);
  }
  return retValue; // Return the trimmed string back to the user
}//trim

var calPopup;
function initpage()
{
  calPopup = new CalendarPopup();
  calPopup.showYearNavigation();
}//initpage

function checkSearchCriteria(sel_val)
{
  if(sel_val == 1)
  {
    oel = document.getElementById ("trreferenceno");
    oel.style.display = "none";
    oel = document.getElementById ("trconnoteno");
    oel.style.display = "block";
    document.frmUsersearch.opt.value = 1;
    document.frmUsersearch.connoteno.focus();
  }
  else
  {
    oel = document.getElementById ("trconnoteno");
    oel.style.display = "none";
    oel = document.getElementById ("trreferenceno");
    oel.style.display = "block";
    document.frmUsersearch.opt.value = 2;
    document.frmUsersearch.referenceno.focus();
  }
}//checkSearchCriteria

function funFormSubmit(name)
{
  switch (name)
  {
    case 'frmNewsPage':
      if(!fnCheckNull('frmNewsPage', 'newsdt', 'News Date'))
      {
        return false;
      }
      break;
    
    case 'frmgeneral':
      if(!fnCheckNull('frmgeneral', 'connoteno', 'Connote No'))
      {
        return false;
      }
      break;

    case 'frmlogin':
      if(!fnCheckNull('frmlogin', 'txtUserName', 'User Id'))
      {
        return false;
      }
      if(!fnCheckNull('frmlogin', 'txtPassword', 'Password'))
      {
        return false;
      }
      break;

    case 'frmUsersearch':
        if(document.frmUsersearch.opt.value == 1)
        {
          if(!fnCheckNull('frmUsersearch', 'connoteno', 'Connote No'))
          {
            return false;
          }
        }
        else if(document.frmUsersearch.opt.value == 2)
        {
          if(!fnCheckNull('frmUsersearch', 'referenceno', 'Reference No'))
          {
            return false;
          }
        }
      break;

    case 'frmPassword':
      if(!fnCheckNull('frmPassword', 'oldpwd', 'Old Password'))
      {
        return false;
      }
      else if(!fnCheckNull('frmPassword', 'newpwd', 'New Password'))
      {
        return false;
      }
      else if(!fnCheckNull('frmPassword', 'conpwd', 'Confirm Password'))
      {
        return false;
      }
      else if( frmPassword.newpwd.value.length < 6 )
      {
        alert("Password should be 6 chars.");
        frmPassword.newpwd.focus();
        return false;
      }
      else if( frmPassword.oldpwd.value == frmPassword.newpwd.value )
      {
        alert("Old Password & New Password should not be same.");
        frmPassword.newpwd.focus();
        return false;
      }
      else if( frmPassword.newpwd.value != frmPassword.conpwd.value )
      {
        alert("New Password & Confirm Password should be same.");
        frmPassword.newpwd.focus();
        return false;
      }
      break;

    case 'frmForgotPwd':
      if(!fnCheckNull('frmForgotPwd', 'userid', 'User Id'))
      {
        return false;
      }
      if(!fnCheckNull('frmForgotPwd', 'companyname', 'Company Name'))
      {
        return false;
      }
      break;

    case 'frmUserRegistration':
      if(!fnCheckNull('frmUserRegistration', 'username', 'User name'))
      {
        return false;
      }
      else if(!fnCheckNull('frmUserRegistration', 'designation', 'Designation'))
      {
        return false;
      }
      else if(!fnCheckNull('frmUserRegistration', 'companyname', 'Company name'))
      {
        return false;
      }
      else if(!fnCheckNull('frmUserRegistration', 'companyaddress', 'Company Address'))
      {
        return false;
      }
      else if(!fnCheckNull('frmUserRegistration', 'phone', 'Phone'))
      {
        return false;
      }
      else if(!fnNumeric('frmUserRegistration', 'phone', 'Phone Number'))
      {
        return false;
      }
      else if(!fnNumeric('frmUserRegistration', 'fax', 'Fax Number'))
      {
        return false;
      }
      else if(!fnCheckNull('frmUserRegistration', 'emailid', 'Email Id'))
      {
        return false;
      }
      else if(!fnCheckEmail('frmUserRegistration', 'emailid', 'Email Id'))
      {
        return false;
      }
      break;

    case 'frmdownload':
      if(!fnCheckNull('frmdownload', 'fromdt', 'Start Date'))
      {
        return false;
      }
      else if(!fnCheckNull('frmdownload', 'todt', 'End Date'))
      {
        return false;
      }
      break;

    return true;
  }
}//funFormSubmit


//Get Control Informations
//var intTotalCtrl = document.frmUsersearch.elements.length;
//for(i=0; i<intTotalCtrl; i++)
//{
//}

function fnAlert()
{
  alert('hi');
}