﻿var ddlFCCountryID='inc_FindCourse_ddlFCCountry';
var ddlFCStateID='inc_FindCourse_ddlFCState';

function makeHttpRequestFindCourse(url, element, calltype) 
{
  var http_request = false;
  if (window.XMLHttpRequest) { // Mozilla, Safari,...
    http_request = new XMLHttpRequest();
    if (http_request.overrideMimeType) {
      http_request.overrideMimeType('text/xml');
    }
  } else if (window.ActiveXObject) { // IE
    try {
      http_request = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
      try {
        http_request = new ActiveXObject("Microsoft.XMLHTTP");
      } catch (e) {}
    }
  }
  if (!http_request) {
    alert('Browser doesn\'t support Ajax. Site will NOT FULLY function properly.');
    return false;
  }
  http_request.onreadystatechange = function() {
    if (http_request.readyState == 4) {
      if (http_request.status == 200) {            
             loadXMLFindCourse(http_request.responseXML,calltype);
      } else {
        alert('There was a problem with the request. (Code: ' + http_request.status + ')');
      }
    }
  }
  http_request.open('GET', url, true);
  http_request.send(null);
}

function loadXMLFindCourse(xml,calltype)
{
	if(calltype == 'Country')
	{		
		var string = '';
 		var root = xml.getElementsByTagName('root')[0];
		var State = root.getElementsByTagName('State');		
        
        var objdrpState= document.getElementById(ddlFCStateID);
    	SelectedState = objdrpState.options[objdrpState.selectedIndex].value;
		objdrpState.options.length = 1;
		for (i = 0; i < State.length; i++)
		{
		    var city = State[i];
		    var Value = city.getElementsByTagName("Value")[0].firstChild.nodeValue; 
		    var Text = city.getElementsByTagName("Text")[0].firstChild.nodeValue;		     
		    addOption(objdrpState, Text, Value, false);	    		    	    
    	    
		}
		selectPreviousOption(objdrpState, SelectedState);
	}
}

function getFilterState(calltype)
{

    var SearchCountry = '';
    
    if(document.getElementById(ddlFCCountryID)!=null)
    {
      SearchCountry = document.getElementById(ddlFCCountryID).options[document.getElementById(ddlFCCountryID).selectedIndex].value;
    }
    var SearchState = '';
    if(document.getElementById(ddlFCStateID)!=null)
    {
        SearchState = document.getElementById(ddlFCStateID).options[document.getElementById(ddlFCStateID).selectedIndex].value;
    }   
    var url = "AjaxHelperFindCourse.aspx?CallType="+calltype+"&Country="+SearchCountry+"&State="+SearchState;               
    makeHttpRequestFindCourse(url,undefined,calltype);
}