﻿// JScript File
/* =================================================================================
' FILE: VendorEDIForm.js
' JIRA:BA-11357
' AUTHOR: conamuk2 -Cognizant 
' DATE: 09/25/2007
' DESCRIPTION: This is the java script file for Vendor EDI Form
'              When user selects US as country and has not selected
               a state from the state drop down then a message will
               be displayed to the user. If the user selects a different
               country other than US then the state drop down is hidden
               from user view.  
' 
'===================================================================*/
//This function fired on change event of country drop down will disable the State drop down control
// when the user selects a country different than United States. Also when the user selects again
// US and no state has been selected then a message box is displayed to select a state. 
var state;

function ValidateStateSelection(countryDropdown, stateDropDown)
{
          var cmbCountry = document.getElementById(countryDropdown);
          var cmbState   = document.getElementById(stateDropDown);
          var trState    = document.getElementById("trState");
          var selectedState = cmbState.options[cmbState.selectedIndex].text;
          var selectedCountry  = cmbCountry.options[cmbCountry.selectedIndex].text;
           cmbState.disabled=false;
          if(selectedCountry != "United States")
          {
	           cmbState.disabled=true;
	      }
         
  }
   
  //client side custom validation code for Country drop down.  
    function CountryCheck(sender,args)
        {
            var country;
            var state = document.getElementById('StateSelected')
            var cmbState   = document.getElementById(state.value);
            var selectedState = cmbState.options[cmbState.selectedIndex].text;
                   
            var statevalidator = document.getElementById('StateValidator').value;
            statevalidator = document.getElementById(statevalidator)
                   
            
             var countryvalidator = document.getElementById("CountryValidator").value;
            countryvalidator = document.getElementById(countryvalidator);
           if (args.Value =="United-States" && selectedState=="State")
            {
               args.IsValid = false;
               statevalidator.style.visibility = 'hidden';
               countryvalidator.style.visibility = 'visible';
                return;
            }
            args.IsValid = true;
            countryvalidator.style.visibility = 'hidden';
            statevalidator.style.visibility = 'hidden';
            
            
       }
       
       // client side custom validation code for state dropdown.
       function StateCheck(sender,args)
        {
           
            var country;
            var cmbCountry = document.getElementById('CountrySelected').value;
            cmbCountry = document.getElementById(cmbCountry)
            var selectedCountry =  cmbCountry.options[cmbCountry.selectedIndex].text//cmbCountry.options[cmbCountry.selectedIndex].text;
            var statevalidator = document.getElementById("StateValidator").value;
            statevalidator = document.getElementById(statevalidator);
            var countryvalidator = document.getElementById("CountryValidator").value;
            countryvalidator = document.getElementById(countryvalidator);
           
           if (args.Value =='State' && selectedCountry=='United States')
            {
                 args.IsValid = false;
                 countryvalidator.style.visibility = 'hidden';
                 statevalidator.style.visibility = 'visible';
                 
                            
                return;
            }
            args.IsValid = true;
            countryvalidator.style.visibility = 'hidden';
            statevalidator.style.visibility = 'hidden';
                  
       }
       
    //to reset the from controls.          
    function ResetForm()
    {
        document.forms[0].reset();
        return false;
    }
  
  


