﻿// JScript File
function validateSearchPostcodes(ctrid)
{
  var txtPostCode;  
  txtPostCode = document.getElementById(ctrid+"_txtPostCode");  
  if(TRIM(txtPostCode.value) == "")
  {
    alert("Please Enter PostCode");            
    txtPostCode.value="";
    txtPostCode.focus();
    return false;        
  } 
  if(txtPostCode.value!="")
  {     
    if(isInteger(txtPostCode.value))
      {
     
      }
      else
      {
       alert("PostCode must be Integer only!");       
      txtPostCode.value="";
      txtPostCode.focus();
     return false;
    }
 }     
  if(txtPostCode.value.length != 4 )
    {
   alert("PostCode Must Be Four Digit");
   txtPostCode.value="";
   txtPostCode.focus();
    return false;
    }  
}

  function isInteger(val)
{
      if(val==null)
      {
        return false;
      }
      if (val.length==0)
      {
        return false;
      }
      for (var i = 0; i < val.length; i++) 
      {
            var ch = val.charAt(i);            
            if (ch < "0" || ch > "9") 
            {
                return false;
            }
       }       
      return true;
}


//Start function to validate textBoxes
function validateTextBoxeSubCat()
{
    txtBox =  document.getElementById("UcAddEditSubCategory1_txtSubCategoryName");
    if(TRIM(txtBox.value) == "")
    {
      alert("Please enter sub category name.");
      txtBox.value="";
      txtBox.focus();
      return false; 
    }        
 }
 function validateTextBoxeCat()
{
    txtBox =  document.getElementById("UcAddEditCategory1_txtCategoryName");
    if(TRIM(txtBox.value) == "")
    {
      alert("Please enter category name.");
      txtBox.value="";
      txtBox.focus();
      return false; 
    }        
 }
//Start AddEdit PostCode Vlidation

function validatePostCodes()
{  
  var txtPostCode;
  var txtDesc;
  txtPostCode = document.getElementById("ucAddEditPostCodes_txtPostCodes");
  txtDesc = document.getElementById("ucAddEditPostCodes_txtDescription");  
  if(TRIM(txtPostCode.value) == "")
  {
    alert("Please Enter PostCode");            
    txtPostCode.value="";
    txtPostCode.focus();
    return false;        
  }  
  if(txtPostCode.value!="")
   {
      var anum=/(^\d+$)|(^\d+\.\d+$)/;
      var matchno=txtPostCode.value.match(anum);
      if (matchno==null)
     {
       alert("PostCode must be Integer only!");       
       txtPostCode.value="";
       txtPostCode.focus();
       return false;
     }
  }          
  if(txtPostCode.value.length != 4 )
    {
    alert("PostCode Must Be Four Digit");
    txtPostCode.value="";
    txtPostCode.focus();
    return false;
    }    
  if(txtDesc.value.length > 256)
  {
    alert("Description must be less than 256 Charector");    
    txtDesc.value="";
    txtDesc.focus();
    return false;
  }
}

//End validation
    
    
    
    
    
//Start function to validate ucLogin control textBoxes

function validateTextBoxes(ctrName)
{  
  var txtUserNameValue;
  var txtPasswordValue;
  txtUserNameValue = document.getElementById(ctrName+"_txtUserName");
  txtPasswordValue = document.getElementById(ctrName+"_txtPassword");
  if(txtUserNameValue.value == "" && txtPasswordValue.value =="")
  {
    alert("Please Enter User Name and Password");
    txtUserNameValue.value="";
    txtUserNameValue.focus();
    return false;  
  }
  if(TRIM(txtUserNameValue.value) == "")
  {
    alert("Please Enter User Name");
    txtUserNameValue.value="";
    txtUserNameValue.focus();
    return false; 
  }      
  if(txtPasswordValue.value == "")
  {
    alert("Please Enter Password");
    txtPasswordValue.value="";
    txtPasswordValue.focus();
    return false;
  }  
  
}

//End function to validate ucLogin control textBoxes
function validateTextBoxesClient(ctrName)
{   
  var txtUserNameValue;
  var txtPasswordValue;
  txtUserNameValue = document.getElementById(ctrName+"_txtUserName");
  txtPasswordValue = document.getElementById(ctrName+"_txtPassword");
  if(txtUserNameValue.value == "" && txtPasswordValue.value =="")
  {
    alert("Please Enter Email Id and Password");
    txtUserNameValue.value="";
    txtUserNameValue.focus();
    return false;  
  }
  if(TRIM(txtUserNameValue.value) == "")
  {
    alert("Please Enter Email Id");
    txtUserNameValue.value="";
    txtUserNameValue.focus();
    return false; 
  }      
  if(txtPasswordValue.value == "")
  {
    alert("Please Enter Password");
    txtPasswordValue.value="";
    txtPasswordValue.focus();
    return false;
  }    
}
//Start Manage Admin Validation
function validateChangePassword()
{ 
  var txtUserName;   
  txtUserName = document.getElementById("UcManageAdmin1_txtUserName");
  txtOldPsw = document.getElementById("UcManageAdmin1_txtOldPsw");
  txtNewPsw = document.getElementById("UcManageAdmin1_txtNewPsw");
  txtConfirmPsw = document.getElementById("UcManageAdmin1_txtConfirmPsw");    
  if(TRIM(txtUserName.value) == "")
  {
    alert("Please Enter User Name");
    txtUserName.value="";
    txtUserName.focus();
    return false; 
  }      
   if(TRIM(txtOldPsw.value) == "")
  {
    alert("Please Enter Old Password");
    txtOldPsw.value="";
    txtOldPsw.focus();
    return false; 
  }
  if(TRIM(txtNewPsw.value) == "")
  {
    alert("Please Enter New Password");
    txtNewPsw.value="";
    txtNewPsw.focus();
    return false; 
  } 
  if(TRIM(txtNewPsw.value).length < 6 || TRIM(txtNewPsw.value).length > 20)
       {
            alert("Password should be within 6 to 20 characters.");           
            txtNewPsw.value="";
            txtConfirmPsw.value="";
            txtNewPsw.focus();
            return false;
       }  
  if(TRIM(txtConfirmPsw.value) == "")
  {
    alert("Please Confirm Password");
    txtConfirmPsw.value="";
    txtConfirmPsw.focus();
    return false; 
  }    
  if(TRIM(txtNewPsw.value)!= TRIM(txtConfirmPsw.value))
  {
    alert("Your new password entries did not match.");   
    txtNewPsw.value="";    
    txtConfirmPsw.value="";    
    txtNewPsw.focus();
    return false; 
  }
}
//End Manage Admin Validation



                var grid;  
                function GridCreated()  
                {  
                    grid = this;  
                } 
                
                //Start :   Function for multiselection for Grid 
                  
                function RowSelected()  
                {                
               
                 
                    if (grid.MasterTableView.SelectedRows.length == grid.MasterTableView.Rows.length-1)  
                    {  
                        setCheckBox(true);  
                    }  
                    
                } 
                //End :   Function for multiselection for Grid
                
                 //Start :   Function for multiselection for Grid 
                function RowSelected1()  
                {                
               
                 
                    if (grid.MasterTableView.SelectedRows.length == grid.MasterTableView.Rows.length)  
                    {  
                        setCheckBox(true);  
                    }  
                    
                }   
                
                   //End :   Function for multiselection for Grid
                
                //Start :   Function for multiselection for Grid 
                  
                function RowDeselected()  
                {  
               
                    if (grid.MasterTableView.SelectedRows.length < grid.MasterTableView.Rows.length)  
                    {  
                        setCheckBox(false);  
                    }  
                }  
                   //End :   Function for multiselection for Grid
                   
                function setCheckBox(toCheck)  
                {  
                
                    var checkBoxID = document.getElementById("hf1").value;  
                    var checkBox = document.getElementById(checkBoxID);  
                    checkBox.checked = toCheck;  
                }  

function GetRadWindow()
{
    var oWindow = null;
    if (window.radWindow) oWindow = window.radWindow; //Will work in Moz in all cases, including clasic dialog
    else if (window.frameElement.radWindow) oWindow = window.frameElement.radWindow;//IE (and Moz az well)
    return oWindow;
}

function TRIM(STRING)
{
STRING = LTrim(STRING);
return RTrim(STRING);
}
function RTrim(STRING){
while(STRING.charAt((STRING.length -1))==" "){
STRING = STRING.substring(0,STRING.length-1);
}
return STRING;
}
function LTrim(STRING){
while(STRING.charAt(0)==" "){
STRING = STRING.replace(STRING.charAt(0),"");
}
return STRING;
}


//End validation
