// JavaScript Document


  jQuery(document).ready(function(){
jQuery("#ContactForm").validate({
						   rules: {
							 first_name: "required",
							 last_name: "required",
							   email_address: {
							   required: true,
							   email: true
							 },
							 zip: {
							   required: true,
							   digits: true,
							   minlength: 5
							 },
							 country: "required",
							 Field2180641: "required"
						   },
						   errorClass: "invalidLabel",
						   submitHandler: function(form) {
							   if(("$SubmitButton").css("display")=="inline"){form.submit()}
							   },
						   messages: {
							 first_name: "Required",
							 last_name: "Required",
							 email_address: {
								required: "Required",
								email: "Invalid Email"
							 },
							 zip: {
								required: "Required",
								digits: "Invalid Zip",
								minlength: "Invalid Zip"
							 },
							 country: "Required"
							 
						   },
						    highlight: function(element, errorClass) {
								 //$(element).effect('highlight');
								 jQuery(element).addClass('invalidField');
								 jQuery(element.form).find("label[for=" + element.id + "]")
												.addClass(errorClass);
							  },
							  unhighlight: function(element, errorClass) {
								 jQuery(element).removeClass('invalidField');
								 jQuery(element.form).find("label[for=" + element.id + "]")
												.removeClass(errorClass);
							  }
						  
							
						});

jQuery("#noThanks:checkbox").click(function(){if(jQuery(this).attr("checked")==true){jQuery("#checkBoxGroup :checkbox").attr('checked',false);}});
jQuery("#checkBoxGroup :checkbox").click(function(){if(jQuery(this).attr("checked")==true){jQuery("#noThanks:checkbox").attr('checked',false);}});
jQuery(".showHideMembers").toggle(function(){jQuery("#memberBox").animate({height: "195px"},500,function(){jQuery('.member').fadeIn(500)});},
function(){ jQuery('.member').fadeOut(500,function(){jQuery("#memberBox").animate({height: "0px"},500);}) });
jQuery("#nextButton").click(function(){if(jQuery("#ContactForm").valid()){jQuery(".firstPage").hide();jQuery(".secondPage").fadeIn();}});
jQuery("#backButton").click(function(){jQuery(".firstPage").fadeIn();jQuery(".secondPage").hide();});
jQuery("#SubmitButton").click(function(){jQuery("#ContactForm").validate().form()
});
  });
 
 // JavaScript Document
change = 0;
// declare a global  XMLHTTP Request object
var XmlHttpObj;
var proxyURL;
	proxyURL = "http://www.umcom.org/site/apps/rss/getpage.aspx?url="; //"qdata=Q3VycmVudFN1YnNjcmlwdGlvbklEPTE1Nw%3d%3d-FrcUlVd6sVo%3d&url=";
var serverDomain;
	serverDomain = "http://master.umc.org";
// create an instance of XMLHTTPRequest Object, varies with browser type, try for IE first then Mozilla

var selectedType;
var selectedState;
var selectedCity;


function CreateXmlHttpObj()
{
	// try creating for IE (note: we don't know the user's browser type here, just attempting IE first.)
	try
	{
		XmlHttpObj = new ActiveXObject("Msxml2.XMLHTTP");
	}
	catch(e)
	{
		try
		{
			XmlHttpObj = new ActiveXObject("Microsoft.XMLHTTP");
		} 
		catch(oc)
		{
			XmlHttpObj = null;
		}
	}
	// if unable to create using IE specific code then try creating for Mozilla (FireFox) 
	if(!XmlHttpObj && typeof XMLHttpRequest != "undefined") 
	{
		XmlHttpObj = new XMLHttpRequest();
	}
}

// called from onChange or onClick event of the continent dropdown list
function typeListOnChange() 
{	jQuery("select[name='stateNull']").attr("disabled",true);
	jQuery("select[name='cityNull']").attr("disabled",true);
	jQuery("select[name='company_name']").attr("disabled",true);
	
	var TypeList = document.getElementById("type");
	change = 1;	
	
    // get selected continent from dropdown list
    selectedType = TypeList.options[TypeList.selectedIndex].value;
    // url of page that will send xml data back to client browser
    var requestURL;
	
	var SourceURL;
	SourceURL = "/KintProc/orgdata/ajaxform/ajax/xml_regdata_provider.asp" + "?type=" + encodeURIComponent(selectedType);
	//alert('SourceURL: ' + SourceURL);
	if (document.domain == "www.umcom.org") {
		requestURL = proxyURL + serverDomain + SourceURL;
		}
	else {
		requestURL = SourceURL;
	    //alert ('local server: ' + requestURL);
		}
    var pbar1 = document.getElementById("pb1");
	pbar1.style.display = 'inline';
	pbar1.innerHTML = '<img src="http://archives.umc.org/KintProc/ajaxprogress.gif" width="16" height="16" />';
	CreateXmlHttpObj();	
	// verify XmlHttpObj variable was successfully initialized
	if(XmlHttpObj)
	{
        // assign the StateChangeHandler function ( defined below in this file)
        // to be called when the state of the XmlHttpObj changes
        // receiving data back from the server is one such change
	
		XmlHttpObj.onreadystatechange = StateChangeHandler;
		
		// define the iteraction with the server -- true for as asynchronous.
		XmlHttpObj.open("GET", requestURL,  true);
		
		// send request to server, null arg  when using "GET"
		XmlHttpObj.send(null);
		
	}
}


function stateListOnChange() 
{
	jQuery("select[name='cityNull']").attr("disabled",true);
	jQuery("select[name='company_name']").attr("disabled",true);
	var StateList = document.getElementById("stateNull");
    change = 2;
    selectedState = StateList.options[StateList.selectedIndex].value;
    var requestURL;
	
	var SourceURL;
	SourceURL = "/KintProc/orgdata/ajaxform/ajax/xml_citydata_provider.asp" + encodeURIComponent("?type=" + selectedType) + encodeURIComponent("&state=" + selectedState);
	if (document.domain == "www.umcom.org") {
		requestURL = proxyURL + serverDomain + SourceURL;
    	//alert ('Kintera Server: ' + requestURL);
		}
	else {
		requestURL = SourceURL;
	    //alert ('local server: ' + requestURL);
		}
	var pbar2 = document.getElementById("pb2");
	pbar2.style.display = 'inline';
	pbar2.innerHTML = '<img src="http://archives.umc.org/KintProc/ajaxprogress.gif" width="16" height="16" />';
	CreateXmlHttpObj();
	
	// verify XmlHttpObj variable was successfully initialized
	if(XmlHttpObj)
	{
        // assign the StateChangeHandler function ( defined below in this file)
        // to be called when the state of the XmlHttpObj changes
        // receiving data back from the server is one such change
		XmlHttpObj.onreadystatechange = StateChangeHandler;
		//alert ('onreadystatechange ' + XmlHttpObj.onreadystatechange);
		// define the iteraction with the server -- true for as asynchronous.
		XmlHttpObj.open("GET", requestURL,  true);
		
		// send request to server, null arg  when using "GET"
		XmlHttpObj.send(null);		
	}
}


function cityListOnChange() 
{
    jQuery("select[name='company_name']").attr("disabled",true);
	
	var CityList = document.getElementById("cityNull");
    change = 3;
    // get selected continent from dropdown list
    selectedCity = CityList.options[CityList.selectedIndex].value;
    var requestURL;
	
	var SourceURL;
	SourceURL = "/KintProc/orgdata/ajaxform/ajax/xml_orgdata_providerXXX.asp" + encodeURIComponent("?type=" + selectedType) + encodeURIComponent("&state=" + selectedState) + encodeURIComponent("&city=" + selectedCity);
	if (document.domain == "www.umcom.org") {
		requestURL = proxyURL + serverDomain + SourceURL;
		}
	else {
		requestURL = SourceURL;
		}
   
	var pbar3 = document.getElementById("pb3");
	pbar3.style.display = 'inline';
	pbar3.innerHTML = '<img src="http://archives.umc.org/KintProc/ajaxprogress.gif" width="16" height="16" />';
	CreateXmlHttpObj();
	
	// verify XmlHttpObj variable was successfully initialized
	if(XmlHttpObj)
	{
        // assign the StateChangeHandler function ( defined below in this file)
        // to be called when the state of the XmlHttpObj changes
        // receiving data back from the server is one such change
		XmlHttpObj.onreadystatechange = StateChangeHandler;
		//alert ('onreadystatechange ' + XmlHttpObj.onreadystatechange);
		// define the iteraction with the server -- true for as asynchronous.
		XmlHttpObj.open("GET", requestURL,  true);
		
		// send request to server, null arg  when using "GET"
		XmlHttpObj.send(null);			
	}
}

function StateChangeHandler()
{
	// state ==4 indicates receiving response data from server is completed
	if(XmlHttpObj.readyState == 4)
	{
		// To make sure valid response is received from the server, 200 means response received is OK
		//alert('this is StateChangeHandler( jumping in with response to XmlHttpObj.readyState , which is ' + XmlHttpObj.readyState);
		
		if(XmlHttpObj.status == 200)
		{			
			if (change == 1)
			
			{
				PopulateStateList(XmlHttpObj.responseXML.documentElement);
				return;
			}
			if (change == 2)
			
			{
				PopulateCityList(XmlHttpObj.responseXML.documentElement);
				return;
			}
			
			if (change == 3)
			
			{
				PopulateOrgList(XmlHttpObj.responseXML.documentElement);
				return;
			}		
		}
		else
		{
			alert("problem retrieving data from the server, status code: "  + XmlHttpObj.status);
		}
	}
}

// populate the contents of the country dropdown list
function PopulateStateList(StateNode)
{
        
	
	var StateList = document.getElementById("stateNull");
	// clear the country list 
	for (var count = StateList.options.length-1; count >-1; count--)
	{
		StateList.options[count] = null;
	}

	var StateNodes = StateNode.getElementsByTagName('state');
	var idValue;
	var textValue; 
	var optionItem;
	// populate the dropdown list with data from the xml doc
	for (var count = 0; count < StateNodes.length; count++)
	{
   		textValue = GetInnerText(StateNodes[count]);
		idValue = StateNodes[count].getAttribute("id");
		optionItem = new Option( textValue, idValue,  false, false);
		StateList.options[StateList.length] = optionItem;
	}
	jQuery("select[name='stateNull']").attr("disabled",false);

	var pbar1 = document.getElementById("pb1");
	pbar1.style.display = 'none';
	
}

// populate the contents of the city dropdown list
function PopulateCityList(CityNode)
{
    
	var CityList = document.getElementById("cityNull");
	// clear the country list 
	for (var count = CityList.options.length-1; count >-1; count--)
	{
		CityList.options[count] = null;
	}

	var CityNodes = CityNode.getElementsByTagName('city');
	var idValue;
	var textValue; 
	var optionItem;
	// populate the dropdown list with data from the xml doc
	for (var count = 0; count < CityNodes.length; count++)
	{   		
		textValue = GetInnerText(CityNodes[count]);
		idValue = CityNodes[count].getAttribute("id");
		optionItem = new Option( textValue, idValue,  false, false);
		CityList.options[CityList.length] = optionItem;			
	}
	jQuery("select[name='cityNull']").attr("disabled",false);
	
	var pbar2 = document.getElementById("pb2");
	pbar2.style.display = 'none';
}


// populate the contents of the org dropdown list
function PopulateOrgList(OrgNode)
{
    
	var OrgList = document.getElementById("company_name");
	// clear the country list 
	for (var count = OrgList.options.length-1; count >-1; count--)
	{
		OrgList.options[count] = null;
	}

	var OrgNodes = OrgNode.getElementsByTagName('org');
	var idValue;
	//var idValue2;
	var textValue; 
	var optionItem;
	// populate the dropdown list with data from the xml doc
	for (var count = 0; count < OrgNodes.length; count++)
	{
   		textValue = GetInnerText(OrgNodes[count]);
		idValue = OrgNodes[count].getAttribute("id2");
		optionItem = new Option( textValue, idValue,  false, false);
		OrgList.options[OrgList.length] = optionItem;
	}
	jQuery("select[name='company_name']").attr("disabled",false);
	var pbar3 = document.getElementById("pb3");
	pbar3.style.display = 'none';
}


// returns the node text value 
function GetInnerText (node)
{
	 return (node.textContent || node.innerText || node.text) ;
}

function TextChange ()
{
	 var SubSectionList = document.getElementById("SubSectionList");
    
    // get selected continent from dropdown list
    var selectedSubSection = SubSectionList.options[SubSectionList.selectedIndex].value;
    
	 document.form1.SiteSubSectionID.value = selectedSubSection;	 
	
}









