﻿// JScript File

function CheckEmptyString(controlId,textcontrol,minValue,isDate)
    {
        var validateTextBox = document.getElementById(controlId);
        var dFlag = false;
        if( isDate == 1 ) {
            d = parseInt(validateTextBox.value);
            if( d <= 1800 ) {
                flag = true;
                validateTextBox.value = 1800;
            }
            
        }

        
        if( (dFlag && validateTextBox.value != "") || validateTextBox.value == "" || ( minValue > 0 && validateTextBox.value.length < minValue ) )
        {

            var error = controlId.replace(textcontrol,"ucError"); 
            var errorControl = document.getElementById(error);             
           
            var hfErrorValueId = controlId.replace(textcontrol,"hfErrorValue");
            var hfErrorValueControl =  document.getElementById(hfErrorValueId);
            
            if(MendatoryFieldCounter < mandatoryField && errorControl.className != "third error")
                MendatoryFieldCounter++;     
                
            errorControl.className = "third error";
            errorControl.innerHTML = hfErrorValueControl.value;
           
            var hidenfield = controlId.replace(textcontrol,"hfIsErrorVisible");
            var hfControl = document.getElementById(hidenfield); 
            hfControl.value = "false";   
                           
        }
        else
        {
            var error1 = controlId.replace(textcontrol,"ucError"); 
            var errorControl1 = document.getElementById(error1);
            
            if(MendatoryFieldCounter > 0 && errorControl1.className != "third ok")          
                MendatoryFieldCounter--;
                    
            errorControl1.className = "third ok";
           
            errorControl1.innerHTML = "";
            
            var hidenfield1 = controlId.replace(textcontrol,"hfIsErrorVisible");
            var hfControl1 = document.getElementById(hidenfield1)  ;         
            hfControl1.value = "true";
            
           
        }
        //showSaveButton();
    }
        
   function checkEmail(controlId,textcontrol) 
     {
        var email = document.getElementById(controlId);
        var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
        
        SetControlDisplay(controlId,textcontrol,filter.test(email.value));
        //showSaveButton();
    }
    
   function SetControlDisplay(controlId,textcontrol,istrue)
    {
        
        //var validateTextBox = document.getElementById(controlId);
        if(!istrue)
        {

            var error = controlId.replace(textcontrol,"ucError"); 
            var errorControl = document.getElementById(error);             
            //errorControl.style.display="block";
            if(MendatoryFieldCounter < mandatoryField && errorControl.className == "third")
                MendatoryFieldCounter++;   
           
            var hfErrorValueId = controlId.replace(textcontrol,"hfErrorValue");
            var hfErrorValueControl =  document.getElementById(hfErrorValueId);
            
            errorControl.className = "third error";
            errorControl.innerHTML = hfErrorValueControl.value;
           
            var hidenfield = controlId.replace(textcontrol,"hfIsErrorVisible");
            var hfControl = document.getElementById(hidenfield); 
            hfControl.value = "false";   
                             
        }
        else
        {
            var error1 = controlId.replace(textcontrol,"ucError"); 
            var errorControl1 = document.getElementById(error1);
            
            if(MendatoryFieldCounter > 0 && errorControl1.className != "third ok")          
                MendatoryFieldCounter--;
            if(MendatoryFieldCounter > 0 && errorControl1.className == "third error")          
                MendatoryFieldCounter--;    
                
            errorControl1.className = "third ok";
           
            errorControl1.innerHTML = "";
            
            var hidenfield1 = controlId.replace(textcontrol,"hfIsErrorVisible");
            var hfControl1 = document.getElementById(hidenfield1)  ;         
            hfControl1.value = "true";
            
        }
    }
    
   function CheckIsFirstElement(controlId)
    {
       
        var dropdowncontrol = document.getElementById(controlId);
        if(dropdowncontrol.selectedIndex == 0)
        {
            //Rise error
            
            var error = controlId.replace("ucDropDown","ucError"); 
            var errorControl = document.getElementById(error);
            errorControl.style.display="block";   
             if(MendatoryFieldCounter < mandatoryField && errorControl.className != "third error")
                MendatoryFieldCounter++;     
                
            errorControl.className = "third error"
            
            var hfErrorValueId = controlId.replace("ucDropDown","hfErrorValue");
            var hfErrorValueControl =  document.getElementById(hfErrorValueId);
             errorControl.innerHTML = hfErrorValueControl.value;
        
            var hidenfield = controlId.replace("ucDropDown","hfIsErrorVisible");
            var hfControl = document.getElementById(hidenfield) 
            hfControl.value = "false"
           
            //showSaveButton();
            return false;
        } 
        else
        {           
            var error1 = controlId.replace("ucDropDown","ucError"); 
            var errorControl1 = document.getElementById(error1);
            errorControl1.style.display="block";
            
            
             if(MendatoryFieldCounter > 0 && errorControl1.className != "third ok")          
                MendatoryFieldCounter--;
                
            errorControl1.className = "third ok"
            
            var hfErrorValueId1 = controlId.replace("ucDropDown","hfErrorValue");
            var hfErrorValueControl1 =  document.getElementById(hfErrorValueId1);
            errorControl1.innerHTML = "";
            
            var hidenfield1 = controlId.replace("ucDropDown","hfIsErrorVisible");
            var hfControl1 = document.getElementById(hidenfield1)           
            hfControl1.value = "true"
           
            //showSaveButton();
            return true;
        }
    }
