	
var SubmitAssignmentObject = function() {

	var lang 						= "en_US";
	var specializationValidationMsg = "Please select a Specialization";
	var countryValidationMsg		= "Please select a Country.";
	var phoneMsg 					= "If you have staffing needs, contact us at: ";
	
	var relativePath 				= "/External_Sites/content/Shared/Scripts/";	
		
	var specializationXMLDoc = null;	
	var specialityOptionItems;
	
	
	var loadXmlDoc = function()
	{
		//if variable "langCd_SubmitAssign" exists
		if(typeof langCd_SubmitAssign != 'undefined') 
		{
			lang = langCd_SubmitAssign;
		}
		var specializationXMLFile = loadSpecializationXML();		
		
		if(window.XMLHttpRequest&&!window.ActiveXObject)
		{    
			var Gz=new XMLHttpRequest();
			Gz.open('GET',specializationXMLFile,false);
			Gz.send(null);specializationXMLDoc=Gz.responseXML;
		}
		else
		{    
			specializationXMLDoc=new ActiveXObject("Microsoft.XMLDOM");
			specializationXMLDoc.async=false;
			specializationXMLDoc.load(specializationXMLFile);
		}
		
		setLanguage(lang);
		loadCountryOptions();	  
		
	}();

	function setLanguage(langCd)
	{
		if(langCd == "fr_CA")
		{
			specializationValidationMsg	= "S'il vous plait choisir une specialisation";
			countryValidationMsg		= "S'il vous plait choisir un Pays";
			phoneMsg 					= "Pour des besoins en recrutement, contactez-nous au: ";
		}
	}

	function loadSpecializationXML()
	{
		//default file
		var file = "specialization_mapping.xml"; 
	
		if(lang == "fr_CA")
		{
			file = "specialization_mapping_fr_CA.xml";
		} 
		else if (lang == "en_CA")
		{
			file = "specialization_mapping_en_CA.xml"
		}
		
		return relativePath + file;		
	}
	
	function loadCountryOptions()
	{
		//Hides country menu & submit button and shows speciality menu only, if USCA_SubmitAssignment is not null 
		if(USCA_SubmitAssignment != null)
		{
			findCountryIndex(USCA_SubmitAssignment);

			loadSpecialityOptions();

			document.getElementById("saCountryCell").style.display = "none";
			document.getElementById("saGoButtonCell").style.display  = "none";
			document.getElementById("saSpecialityCell").style.display = "block";

		}	
		else
		{
			var countryOptionItems = specializationXMLDoc.getElementsByTagName("specializations");
			var x = 0;
			for (var i=0; i<countryOptionItems.length; i++)
			{
				if(countryOptionItems[i].getAttribute("countryCode") != "CA-QC")
				{				
					document.submitAssignFrm.countryCmbo.options[x++] = new Option(countryOptionItems[i].getAttribute("country"),countryOptionItems[i].getAttribute("countryCode"));
				}
			}
	  }
	}

	function findCountryIndex(countryStr)
	{
		var countries = specializationXMLDoc.getElementsByTagName("specializations");
		var len = countries.length;
		for(var i=0; i<len; i++)
		{		
			if(countries[i].getAttribute("countryCode") == countryStr)
			{
				specialityOptionItems = countries[i].getElementsByTagName("speciality");
			}
		}
	}
	
	function loadSpecialityOptions()
	{
		var url = "";
		var len = specialityOptionItems.length;
		var x = 0; //options index

		for (var i=0; i<len; i++)
		{
			var urlPath = specialityOptionItems[i].getAttribute("submitAssignment");
			if(urlPath != null)
			{
				var phonenumber = /\d{1}[.-\\s]{1}\d{3}[.-\\s]{1}\d{3}[.-\\s]{1}\d{4}/;
				if(phonenumber.test(urlPath))
				{
					url = phoneMsg + urlPath;
				}
				else
				{
					url = specialityOptionItems[i].getAttribute("lobDomain") + urlPath;
				}
				document.submitAssignFrm.specialityCmbo.options[x++] = new Option(specialityOptionItems[i].getAttribute("lob"),url);
			}
		}

	}

	function toggleSpecialityDisplay(countryCd)
	{
	  var countriesList = specializationXMLDoc.getElementsByTagName("specializations");
	  for(var i=0; i<countriesList.length; i++)
	  {
	  	if(countriesList[i].getAttribute("countryCode") == countryCd)
	  	{
	  		specialityOptionItems = specializationXMLDoc.getElementsByTagName("specializations")[i].getElementsByTagName("speciality");
	  	}
	  }
	  
	  //clears options list
	  document.submitAssignFrm.specialityCmbo.options.length = 0;
		//initializes hidden field value
		document.submitAssignFrm.redirectURL.value = null;
			
	  //if more than 1 speciality exists
	  if(specialityOptionItems[0].getAttribute("lobDomain") == '' )
	  {
	  	loadSpecialityOptions();
	  	return true;
	  }
	  else
	  {
	  	//redirect url values come from speciality comboBox unless it's hidden then store in redirectURL hidden form field
			document.submitAssignFrm.redirectURL.value = specialityOptionItems[0].getAttribute("lobDomain") + specialityOptionItems[0].getAttribute("submitAssignment");
	  	return false;
  	}
	}

	function toggleGoButton()
	{ 
		if(document.submitAssignFrm.countryCmbo.value == "US" || document.submitAssignFrm.countryCmbo.value == "CA")
		{
			document.getElementById("saGoButtonCell").style.display  = "none";
		}
		else
		{
			document.getElementById("saGoButtonCell").style.display  = "block";
		}
	}
	function showPhoneNumbers()
	{
			if((USCA_SubmitAssignment == "US" || USCA_SubmitAssignment == "CA") || 
					(document.submitAssignFrm.countryCmbo.value == "US" || document.submitAssignFrm.countryCmbo.value == "CA"))		
			{
				if(document.submitAssignFrm.specialityCmbo.value != '')
				{
					document.getElementById("rhStarMsgCell").innerHTML = "<p>" + document.submitAssignFrm.specialityCmbo.value + "</p>";
					document.getElementById("rhStarMsgCell").style.display = "block";
				}
				else
				{			
					document.getElementById("rhStarMsgCell").style.display = "none";
					document.getElementById("rhStarMsgCell").innerHTML = "";
				}
			}
			else
			{			
				document.getElementById("rhStarMsgCell").style.display = "none";
				document.getElementById("rhStarMsgCell").innerHTML = "";
			}
	}
		
	return {
		/* Public API */
		
		showPhoneNumbers: function()
		{ 
			showPhoneNumbers();
		},
	
		showHideSpeciality: function()
		{
			//clear field
			document.getElementById("rhStarMsgCell").innerHTML = "";
			
			var selIndex = document.submitAssignFrm.countryCmbo.selectedIndex;
			var selectedCountry = document.submitAssignFrm.countryCmbo[selIndex].value;
			
			if (selIndex > 0)
			{
				if(toggleSpecialityDisplay(selectedCountry))
				{
					document.getElementById("saSpecialityCell").style.display = "block";
				}
				else
				{
					//hide speciality combobox
					document.getElementById("saSpecialityCell").style.display = "none";
				}
			}
			else
			{
				document.getElementById("saSpecialityCell").style.display = "none";
			}
			toggleGoButton();
		},

		validateForm: function()
		{
			if(document.submitAssignFrm.countryCmbo.selectedIndex == 0)
			{
				alert(countryValidationMsg);
				document.submitAssignFrm.countryCmbo.focus();
				return;
			}

			if(document.submitAssignFrm.specialityCmbo != null)
			{
				var specialityCmbo = document.submitAssignFrm.specialityCmbo;
				if(specialityCmbo.length > 1 && specialityCmbo.selectedIndex == 0)
				{
					alert(specializationValidationMsg);
					specialityCmbo.focus();
				}
				else
				{
					var redirect = document.submitAssignFrm.redirectURL.value;
					if(redirect == "null" || redirect == "")
					{
						redirect =  specialityCmbo.options[specialityCmbo.selectedIndex].value;
					}
					window.open(redirect);
				}
			}
		}
	};
	
}();