﻿// JScript File
//########### JavaScript For TextBoxValidator Control################
var boolPage_IsValid = true;
var boolPage_IsValidDropDown = true;
//var boolPage_IsValidRegExp = true;
var boolCheckLength =true;
var boolCheckNotBlank =true;
var boolCheckRegularExpresion =true;
var boolCheckBLRegularExpresion = true;
var checkRegExpression = false;
var checkBLRegExpression = false;
var globalControlCheck=true;
var globalControlCheckIDPass = true;

    //Set if page is valid
    function setPageValid(argument){
        boolPage_IsValid = argument;
        boolPage_IsValidDropDown = argument;
        globalControlCheck=argument;
    }
    
    //Validating max Length. (Note: CustomMaxLength is an attribute added to the custom validator)
    //This will check if the text box of the user control is less than the max length
   function CheckLength(source,arguments)
   {
       if (arguments.Value.length > source.CustomMaxLength)
       {
            arguments.IsValid = false;
            boolCheckLength =false;
            ArgumentsNotValid(source.innerHTML, source.CustomlblClientErrorID, source.CustomimgWarningId, source.CustomtxtInputId, source.CustomTextBoxStyleError);
       }
       else
       {
            boolCheckLength =true;
            arguments.IsValid = true;
            //alert("length: lblClientErrorID : " + source.CustomlblClientErrorID);
            checkIfValid(source.CustomlblClientErrorID, source.CustomimgWarningId, source.CustomtxtInputId, source.CustomTextBoxStyle);
       }   
   }
   
   //Validate Not Blank
    function CheckNotBlank(source, arguments)
   {
      //checking if the current text box has also the check for regular expression, to apply it in the next step
      if (source.CustomRegExpEnabled)
      {
        checkRegExpression=true;      
         checkBLRegExpression=true;   
      }
      else
      {
        checkRegExpression=false;       
         checkBLRegExpression=false;     
      }
      
        if (arguments.Value == '')
      {
            arguments.IsValid = false;
            boolCheckNotBlank=false;           
           // alert(source.CustomlblClientErrorID);
            ArgumentsNotValid(source.innerHTML, source.CustomlblClientErrorID, source.CustomimgWarningId, source.CustomtxtInputId, source.CustomTextBoxStyleError);            
      }
      else
      {
            arguments.IsValid = true;
            boolCheckNotBlank = true;
            //alert("Blank: lblClientErrorID : " + source.CustomlblClientErrorID);
            checkIfValid(source.CustomlblClientErrorID, source.CustomimgWarningId, source.CustomtxtInputId, source.CustomTextBoxStyle);
      }
   }  
   
   //Validator which uses regular expression. (Note: CustomRegExp is an attribute added to the custom validator)
   function CheckRegularExpresion(source,arguments)
   {    
   //alert("sdsd2");
        if (checkRegExpression)
        {
           var reg = new RegExp(source.CustomRegExp);
           if (reg.test(arguments.Value.trim()) == true)
           {
                boolCheckRegularExpresion =  true;
                arguments.IsValid = true;
               // alert("Blank: lblClientErrorID : " + source.CustomlblClientErrorID);
                checkIfValid(source.CustomlblClientErrorID, source.CustomimgWarningId, source.CustomtxtInputId, source.CustomTextBoxStyle);
           }
           else
           {
                arguments.IsValid = false;
                boolCheckRegularExpresion=false;
                ArgumentsNotValid(source.innerHTML, source.CustomlblClientErrorID, source.CustomimgWarningId, source.CustomtxtInputId, source.CustomTextBoxStyleError);
           }
         }
         else
         {
            boolCheckRegularExpresion=true;
         }
   }
   
     //Validator which uses regular expression. (Note: CustomRegExp is an attribute added to the custom validator)
   function CheckBLRegularExpresion(source,arguments)
   {    
        if (checkBLRegExpression)
        {        
           var reg = new RegExp(source.CustomRegExp);   
              
           if (reg.test(arguments.Value.trim(), "i") == false)
           {
                boolCheckBLRegularExpresion = true;
                arguments.IsValid = true;
                checkIfValid(source.CustomlblClientErrorID, source.CustomimgWarningId, source.CustomtxtInputId, source.CustomTextBoxStyle);               
           }
           else
           {               
                arguments.IsValid = false;
                boolCheckBLRegularExpresion=false;
                ArgumentsNotValid(source.innerHTML, source.CustomlblClientErrorID, source.CustomimgWarningId, source.CustomtxtInputId, source.CustomTextBoxStyleError);
           }
         }
         else
         {
            boolCheckBLRegularExpresion=true;
         }
   }
   
   function checkglobalValidation()
   {  
    //this will check if the length, blank, and regular expression are all valid
     globalControlCheck = ((globalControlCheck) && (boolCheckLength) && (boolCheckNotBlank) && (boolCheckRegularExpresion) && (boolCheckBLRegularExpresion));
   //  displayPageValidator(!globalControlCheck);
   }
      
   //Final Check of validations to set the status
   function checkIfValid(lblClientErrorID, imgWarningId, txtInputId, TextBoxStyle)
   { 
        //checking that all fields are correct before switching off errors
       //alert("lblClientErrorID: " + lblClientErrorID + "boolCheckLength: " + boolCheckLength + " boolCheckNotBlank " + boolCheckNotBlank + " boolCheckRegularExpresion " + boolCheckRegularExpresion);

        checkglobalValidation();       
        if ((boolCheckLength) && (boolCheckNotBlank) && (boolCheckRegularExpresion) && (boolCheckBLRegularExpresion))
        {
            //alert(boolCheckBLRegularExpresion);
            ArgumentsValid(lblClientErrorID, imgWarningId, txtInputId, TextBoxStyle);
        }        
        boolPage_IsValid=globalControlCheck;              
   }
        
     
     //the paramiter textProperty is passed from another javascript which is a property from the code
     //behind containing the text of the error
     function ArgumentsNotValid(textPropertyErrorMessage, lblClientErrorID, imgWarningId, txtInputId, TextBoxStyleError)
     {         
    // alert("lblClientErrorID : " + lblClientErrorID);
         checkglobalValidation();
          document.getElementById(lblClientErrorID).style.display='block';
          document.getElementById(lblClientErrorID).innerHTML = textPropertyErrorMessage ;
          document.getElementById(imgWarningId).style.display='block';
          document.getElementById(txtInputId).className =TextBoxStyleError;
          displayPageValidator(true);
          boolPage_IsValid=globalControlCheck;     
     }
     
     //Setting error message and image to hidden
     function ArgumentsValid(lblClientErrorID, imgWarningId, txtInputId, TextBoxStyle)
     {      
         // alert("lblClientErrorID : " + lblClientErrorID);
          document.getElementById(lblClientErrorID).style.display='none';
          document.getElementById(imgWarningId).style.display='none';
          document.getElementById(txtInputId).className =TextBoxStyle;                  
      }
         
     
   //################### End TextBoxValidator #############################

     
   //################### Drop DownValidator #############################   
     
     
   //checks if drop down list is selected  
   function CheckDropDown(source,arguments)
   {
        //alert(source.CustomlblClientErrorID );
       if (arguments.Value == '-1')
        {
            arguments.IsValid = false;
            ArgumentsNotValidDropDown(source.innerHTML, source.CustomlblClientErrorID, source.CustomimgWarningId, source.CustomddlInputId, source.CustomDropDownStyleError);
        }
       else
        {
            arguments.IsValid = true;
            ArgumentsValidDropDown(source.CustomlblClientErrorID, source.CustomimgWarningId, source.CustomddlInputId, source.CustomDropDownStyle);
        }
   }
   
   
   
       //the paramiter textProperty is passed from another javascript which is a property from the code
     //behind containing the text of the error
     function ArgumentsNotValidDropDown(textPropertyErrorMessage, lblClientErrorID, imgWarningId, dropDownId, DropDownStyleError)
     {
          document.getElementById(lblClientErrorID).style.display='block';
          document.getElementById(lblClientErrorID).innerHTML = textPropertyErrorMessage;
          document.getElementById(imgWarningId).style.display='block';
          document.getElementById(dropDownId).className =DropDownStyleError;
          displayPageValidator(true);
          boolPage_IsValidDropDown = false;
     }
     
     //Setting error message and image to hidden
     function ArgumentsValidDropDown(lblClientErrorID, imgWarningId, dropDownId, DropDownStyle)
     {
          document.getElementById(lblClientErrorID).style.display='none';
          document.getElementById(imgWarningId).style.display='none';
          document.getElementById(dropDownId).className =DropDownStyle;
          boolPage_IsValidDropDown = true;
     }

  //################### End Drop Down Validator #############################


  //################### Hide all errors  #############################

function ClearErrors(){
        $("span[id$='lblClientError']").hide();
        $("img[id$='imgWarning']").hide();
        $("input[id$='txtInput']").removeClass("inputErr");
//        return false;
    }

  //################### End Hide all errors  #############################



  
//################### Begin Login Module Validator #############################
  
function ValUsername(source,arguments){
     if ((arguments.Value.length < 1)||(arguments.Value=="Username"))
      {
        arguments.IsValid = false;
        globalControlCheck = false;
        document.getElementById(source.CustomtxtUsernameId).value = "Username";
        document.getElementById(source.CustomtxtUsernameId).style.backgroundColor = "#F3B700";
        return false;
       }
       else if(RegularExpressionVal('^[0-9a-zA-Z-._]{3,16}$', source.CustomtxtUsernameId) == false){
        arguments.IsValid = false;
        globalControlCheck = false;
        document.getElementById(source.CustomtxtUsernameId).value = "Invalid";
        document.getElementById(source.CustomtxtUsernameId).style.backgroundColor = "#F3B700";
        return false;
       }
       else
       {

        globalControlCheck = true;
        arguments.IsValid = true;
        document.getElementById(source.CustomtxtUsernameId).style.backgroundColor = "#FFFFFF";
        return true;
       }
}

function ValPassword(source,arguments){
    if (document.getElementById(source.CustomtxtPasswordId).value.length < 1)
      {
        arguments.IsValid = false;
        globalControlCheck = false;
        document.getElementById(source.CustomtxtStylePasswordId).style.backgroundColor = "#F3B700";
        document.getElementById(source.CustomtxtPasswordId).style.backgroundColor = "#F3B700";
        document.getElementById(source.CustomtxtPasswordId).value = "";
        return false;
       }
       else
       {
        arguments.IsValid = true;
        //globalControlCheck = true;
        document.getElementById(source.CustomtxtStylePasswordId).style.backgroundColor = "#FFFFFF";
        document.getElementById(source.CustomtxtPasswordId).style.backgroundColor = "#FFFFFF";
        return true;
       }
}
//################### End Login Module Validator #############################



//################### Begin Temp Bundle Purchase Radio Button ###########################

   function CheckBundleRadioButtons(source,arguments)
    {
        var frm = document.aspnetForm; 
        var found_it;
        
         for (var i=1; i<frm.length; i++)   
         { 
             if(frm.elements[i].id )
             { 
                  if(frm.elements[i].id.indexOf("rbBoundles")!=-1) 
                   {
                       if (frm.elements[i].checked)
                        {
                        // Set the flag if any radio button is checked
                           found_it = true;
                           
                           break;
                        }
                    }
              }
        } 
        
         if(found_it){
         arguments.IsValid = true;
         globalControlCheck = true;
         document.getElementById(source.divErrorHolder).style.display='none';  
         displayPageValidator(false);      
         }
         else 
         {
         document.getElementById(source.divErrorHolder).style.display='block';  
            arguments.IsValid = false;
           globalControlCheck=false;
           displayPageValidator(true); 
         } 
      }

//################### End Temp Bundle Purchase Radio Button #############################

function RegularExpressionVal(strRegExp, controlID){
    var objRegExp = new RegExp(strRegExp);
    var blnCheck = objRegExp.test(document.getElementById(controlID).value.trim());
    return blnCheck;
}



  function validateGroup(validators, validationgroup) {
            ClearErrors();
            for (i = 0; i < validators.length; i++) {
                objValidator = document.getElementById(validators[i]);
                if (objValidator != null) {
                    objValidator.validationGroup = validationgroup;
                }
            }

            //alert(rfvMessage.ValidationGroup);
            return Page_ClientValidate(validationgroup);
        }

        function invalidateGroup(validators, validationgroup) {

            for (i = 0; i < validators.length; i++) {
                objValidator = document.getElementById(validators[i]);
                if (objValidator != null) {
                    objValidator.validationGroup = validationgroup;
                    objValidator.isvalid = true;
                    ValidatorUpdateDisplay(objValidator);
                }
                
            }

            return false;
        }
        
        
        
        
        
        //Validate that id number or passport are Not Blank
    function CheckIDPassportNotBlank(source, arguments)
   {
      //checking if the current text box has also the check for regular expression, to apply it in the next step
      if (source.CustomRegExpEnabled)
      {
        checkRegExpression=true;      
         checkBLRegExpression=true;   
      }
      else
      {
        checkRegExpression=false;       
         checkBLRegExpression=false;     
      }
        if ((arguments.Value == '') && (document.getElementById(source.OtherValue + '_txtInput').value==''))
      {
            arguments.IsValid = false;
            boolCheckNotBlank=false;           
           // alert(source.CustomlblClientErrorID);
            ArgumentsNotValid(source.innerHTML, source.CustomlblClientErrorID, source.CustomimgWarningId, source.CustomtxtInputId, source.CustomTextBoxStyleError);            
      }
      else
      {
            arguments.IsValid = true;
            boolCheckNotBlank = true;
            //alert("Blank: lblClientErrorID : " + source.CustomlblClientErrorID);
            checkIfValid(source.CustomlblClientErrorID, source.CustomimgWarningId, source.CustomtxtInputId, source.CustomTextBoxStyle);
      }
   }  