// JavaScript Document

//country phone code array
var intPhoneCodeArray = [];
intPhoneCodeArray["DZA"]="213"; intPhoneCodeArray["GRL"]="299"; intPhoneCodeArray["OMN"]="968"; intPhoneCodeArray["AND"]="376"; intPhoneCodeArray["GRD"]="1809"; intPhoneCodeArray["PAK"]="92"; intPhoneCodeArray["AGO"]="244"; intPhoneCodeArray["GLP"]="590"; intPhoneCodeArray["PAN"]="507"; intPhoneCodeArray["AIA"]="1264"; intPhoneCodeArray["GUM"]="671"; intPhoneCodeArray["PNG"]="675"; intPhoneCodeArray["ATG"]="1268"; intPhoneCodeArray["GTM"]="502"; intPhoneCodeArray["PRY"]="595"; intPhoneCodeArray["ANT"]="599"; intPhoneCodeArray["GIN"]="224"; intPhoneCodeArray["PER"]="51"; intPhoneCodeArray["ARG"]="54"; intPhoneCodeArray["GUY"]="592"; intPhoneCodeArray["PHL"]="63"; intPhoneCodeArray["ABW"]="297"; intPhoneCodeArray["HTI"]="509"; intPhoneCodeArray["POL"]="48"; intPhoneCodeArray["HND"]="504"; intPhoneCodeArray["PRT"]="351"; intPhoneCodeArray["AUS"]="61"; intPhoneCodeArray["HKG"]="852"; intPhoneCodeArray["PRI"]="1787"; intPhoneCodeArray["AUT"]="43"; intPhoneCodeArray["HUN"]="36"; intPhoneCodeArray["QAT"]="974"; intPhoneCodeArray["REU"]="262"; intPhoneCodeArray["BHS"]="1242"; intPhoneCodeArray["ISL"]="354"; intPhoneCodeArray["BHR"]="973"; intPhoneCodeArray["IND"]="91"; intPhoneCodeArray["ROU"]="40"; intPhoneCodeArray["BGD"]="880"; intPhoneCodeArray["IDN"]="62"; intPhoneCodeArray["RWA"]="250"; intPhoneCodeArray["BRB"]="1246"; intPhoneCodeArray["IRN"]="98"; intPhoneCodeArray["BEL"]="32"; intPhoneCodeArray["IRQ"]="964"; intPhoneCodeArray["LCA"]="1758"; intPhoneCodeArray["BLZ"]="501"; intPhoneCodeArray["SPM"]="508"; intPhoneCodeArray["BMU"]="1441"; intPhoneCodeArray["ISR"]="972"; intPhoneCodeArray["VCT"]="1809"; intPhoneCodeArray["BOL"]="591"; intPhoneCodeArray["ITA"]="39"; intPhoneCodeArray["ASM"]="684"; intPhoneCodeArray["BIH"]="387"; intPhoneCodeArray["JAM"]="1876"; intPhoneCodeArray["WSM"]="685"; intPhoneCodeArray["BWA"]="267"; intPhoneCodeArray["JPN"]="81"; intPhoneCodeArray["SMR"]="378"; intPhoneCodeArray["BRA"]="55"; intPhoneCodeArray["JOR"]="962"; intPhoneCodeArray["SAU"]="966"; intPhoneCodeArray["BRN"]="673"; intPhoneCodeArray["KEN"]="254"; intPhoneCodeArray["SEN"]="221"; intPhoneCodeArray["BGR"]="359"; intPhoneCodeArray["KIR"]="686"; intPhoneCodeArray["SRB"]="381"; intPhoneCodeArray["BDI"]="257"; intPhoneCodeArray["KOR"]="82"; intPhoneCodeArray["SYC"]="248"; intPhoneCodeArray["KHM"]="855"; intPhoneCodeArray["KWT"]="965"; intPhoneCodeArray["SLE"]="232"; intPhoneCodeArray["CMR"]="237"; intPhoneCodeArray["LSO"]="266"; intPhoneCodeArray["SGP"]="65"; intPhoneCodeArray["CAN"]="1"; intPhoneCodeArray["LBY"]="218"; intPhoneCodeArray["SLB"]="677"; intPhoneCodeArray["LIE"]="4175"; intPhoneCodeArray["SOM"]="252"; intPhoneCodeArray["CYM"]="1345"; intPhoneCodeArray["LUX"]="352"; intPhoneCodeArray["ZAF"]="27"; intPhoneCodeArray["CHL"]="56"; intPhoneCodeArray["MAC"]="853"; intPhoneCodeArray["ESP"]="34"; intPhoneCodeArray["CHN"]="86"; intPhoneCodeArray["MKD"]="389"; intPhoneCodeArray["LKA"]="94"; intPhoneCodeArray["CIS"]="7"; intPhoneCodeArray["MDG"]="261"; intPhoneCodeArray["SDN"]="249"; intPhoneCodeArray["COL"]="57"; intPhoneCodeArray["SUR"]="597"; intPhoneCodeArray["COG"]="242"; intPhoneCodeArray["SWZ"]="268"; intPhoneCodeArray["COD"]="243"; intPhoneCodeArray["MWI"]="265"; intPhoneCodeArray["SWE"]="46"; intPhoneCodeArray["COK"]="682"; intPhoneCodeArray["MYS"]="60"; intPhoneCodeArray["CHE"]="41"; intPhoneCodeArray["CRI"]="506"; intPhoneCodeArray["MDV"]="980"; intPhoneCodeArray["SYR"]="963"; intPhoneCodeArray["CIV"]="225"; intPhoneCodeArray["MLI"]="223"; intPhoneCodeArray["TWN"]="886"; intPhoneCodeArray["HRV"]="385"; intPhoneCodeArray["MLT"]="356"; intPhoneCodeArray["TZA"]="255"; intPhoneCodeArray["CUB"]="53"; intPhoneCodeArray["MNP"]="670"; intPhoneCodeArray["THA"]="66"; intPhoneCodeArray["CYP"]="357"; intPhoneCodeArray["MTQ"]="596"; intPhoneCodeArray["TGO"]="228"; intPhoneCodeArray["CZE"]="42"; intPhoneCodeArray["MRT"]="222"; intPhoneCodeArray["TON"]="676"; intPhoneCodeArray["DNK"]="45"; intPhoneCodeArray["MUS"]="230"; intPhoneCodeArray["TTO"]="1868"; intPhoneCodeArray["DJI"]="253"; intPhoneCodeArray["MEX"]="52"; intPhoneCodeArray["TUN"]="216"; intPhoneCodeArray["DMA"]="1809"; intPhoneCodeArray["FSM"]="691"; intPhoneCodeArray["TUR"]="90"; intPhoneCodeArray["DOM"]="1809"; intPhoneCodeArray["TCA"]="1649"; intPhoneCodeArray["ECU"]="593"; intPhoneCodeArray["MCO"]="377"; intPhoneCodeArray["UGA"]="256"; intPhoneCodeArray["EGY"]="20"; intPhoneCodeArray["MSR"]="1664"; intPhoneCodeArray["MMR"]="95"; intPhoneCodeArray["SLV"]="503"; intPhoneCodeArray["MAR"]="212"; intPhoneCodeArray["ARE"]="971"; intPhoneCodeArray["ETH"]="251"; intPhoneCodeArray["NAM"]="264"; intPhoneCodeArray["GBR"]="44"; intPhoneCodeArray["FLK"]="500"; intPhoneCodeArray["NRU"]="674"; intPhoneCodeArray["URY"]="598"; intPhoneCodeArray["FRO"]="298"; intPhoneCodeArray["NPL"]="977"; intPhoneCodeArray["USA"]="1"; intPhoneCodeArray["FJI"]="679"; intPhoneCodeArray["NLD"]="31"; intPhoneCodeArray["VUT"]="678"; intPhoneCodeArray["FIN"]="358"; intPhoneCodeArray["KNA"]="1869"; intPhoneCodeArray["VAT"]="39"; intPhoneCodeArray["FRA"]="33"; intPhoneCodeArray["NCL"]="687"; intPhoneCodeArray["VEN"]="58"; intPhoneCodeArray["GUF"]="594"; intPhoneCodeArray["NZL"]="64"; intPhoneCodeArray["VNM"]="84"; intPhoneCodeArray["PYF"]="689"; intPhoneCodeArray["NIC"]="505"; intPhoneCodeArray["VGB"]="1809"; intPhoneCodeArray["GAB"]="241"; intPhoneCodeArray["NER"]="227"; intPhoneCodeArray["VIR"]="1340"; intPhoneCodeArray["GMB"]="220"; intPhoneCodeArray["NGA"]="234"; intPhoneCodeArray["YEM"]="967"; intPhoneCodeArray["DEU"]="49"; intPhoneCodeArray["ZMB"]="260"; intPhoneCodeArray["GIB"]="350"; intPhoneCodeArray["NFK"]="672"; intPhoneCodeArray["ZWE"]="263"; intPhoneCodeArray["GRC"]="30"; intPhoneCodeArray["NOR"]="47"; 
intPhoneCodeArray["AFG"]="93"; intPhoneCodeArray["ALB"]="355"; intPhoneCodeArray["ATA"]="672"; intPhoneCodeArray["ARM"]="374"; intPhoneCodeArray["AZE"]="994"; intPhoneCodeArray["BLR"]="375"; intPhoneCodeArray["BEN"]="229"; intPhoneCodeArray["BTN"]="975"; intPhoneCodeArray["IOT"]="284"; intPhoneCodeArray["BFA"]="226"; intPhoneCodeArray["CPV"]="238"; intPhoneCodeArray["CAF"]="236"; intPhoneCodeArray["TCD"]="235"; intPhoneCodeArray["CXR"]="61"; intPhoneCodeArray["CCK"]="61"; intPhoneCodeArray["COM"]="269"; intPhoneCodeArray["TMP"]="670"; intPhoneCodeArray["GNQ"]="240"; intPhoneCodeArray["ERI"]="291"; intPhoneCodeArray["EST"]="372"; intPhoneCodeArray["ATF"]="689"; intPhoneCodeArray["FXX"]="33"; intPhoneCodeArray["GEO"]="995"; intPhoneCodeArray["GHA"]="233"; intPhoneCodeArray["GNB"]="245"; intPhoneCodeArray["IRL"]="353"; intPhoneCodeArray["KAZ"]="7"; intPhoneCodeArray["PRK"]="850"; intPhoneCodeArray["KGZ"]="996"; intPhoneCodeArray["LAO"]="856"; intPhoneCodeArray["LVA"]="371"; intPhoneCodeArray["LBN"]="961"; intPhoneCodeArray["LBR"]="231"; intPhoneCodeArray["LTU"]="370"; intPhoneCodeArray["MHL"]="692"; intPhoneCodeArray["MYT"]="269"; intPhoneCodeArray["MDA"]="373"; intPhoneCodeArray["MNG"]="976"; intPhoneCodeArray["MOZ"]="258"; intPhoneCodeArray["NIU"]="683"; intPhoneCodeArray["PLW"]="680"; intPhoneCodeArray["PCN"]="870"; intPhoneCodeArray["ROM"]="40"; intPhoneCodeArray["RUS"]="7"; intPhoneCodeArray["STP"]="239"; intPhoneCodeArray["SVK"]="421"; intPhoneCodeArray["SVN"]="386"; intPhoneCodeArray["SHN"]="290"; intPhoneCodeArray["TJK"]="992"; intPhoneCodeArray["TKL"]="690"; intPhoneCodeArray["TKM"]="993"; intPhoneCodeArray["TUV"]="688"; intPhoneCodeArray["UKR"]="380"; intPhoneCodeArray["UZB"]="998"; intPhoneCodeArray["UMI"]="340"; intPhoneCodeArray["WLF"]="681"; intPhoneCodeArray["YUG"]="381"; 

function changebox()
{
	document.getElementById("ddQuestions").style.display="none";
	document.getElementById("btn-go").style.display="none";

	document.getElementById("ddQuestions2").style.display="block";
	document.getElementById("btn-go2").style.display="block";
}

//this function checks for residence country cookies
function checkCookie()
{
	residence_country_code = getSearchCookieValue('RESIDENCE_COUNTRY_CODE');
	residence_country_name = getSearchCookieValue('RESIDENCE_COUNTRY_NAME');
	
	if (residence_country_code != null && residence_country_code != "")
	{
		for(var i = 0; i < document.forms.length; i++ )
		{
			document.forms[i].country.value = unescape(residence_country_code);
		}
	}
	autoSetDropDown();
}

//function to get a cookie value
function Get_Cookie( check_name )
{
	// split this cookie up into name/value pairs
	// note: document.cookie only returns name=value, not the other components
	var all_cookies = document.cookie.split( ';' );
	var temp_cookie = '';
	var cookie_name = '';
	var cookie_value = '';
	
	for ( i = 0; i < all_cookies.length; i++ )
	{
		// split apart each name=value pair
		temp_cookie = all_cookies[i].split( '=' );

		// trim left/right whitespace 
		cookie_name = temp_cookie[0].replace(/^\s+|\s+$/g, '');

		// if name matches passed check_name
		if ( cookie_name == check_name )
		{
			// cookie has no value but exists (no = sign, that is):
			if ( temp_cookie.length > 1 )
			{
				cookie_value = unescape( temp_cookie[1].replace(/^\s+|\s+$/g, '') );
			}
			break;
		}
		temp_cookie = null;
		cookie_name = '';
	}
	
	return cookie_value;
}

// get cookie value
function getSearchCookieValue(cookie_name)
{
	var cookie_value = '';
	//call main function to get cookie value with passed in cookie name
	cookie_value = Get_Cookie( cookie_name );
	
	if( cookie_value != '' )
	{
		return cookie_value;
	}
	else
	{
		return '';
	}
}

//function resets the country name and code
//called when changing residence country
function setIntPhoneCode(el)
{
	if(typeof(el) == "undefined")
	{
		el = document.mainform;
	}
	
	if( el.country.value != '' && intPhoneCodeArray[el.country.value] )
	{
		el.country_phone_code.value = intPhoneCodeArray[el.country.value];
	}
	else
	{
		el.country_phone_code.value = '';
	}
}

//function resets the country name and code
//called when changing residence country
function semCountryReset(el)
{
	if(typeof(el) == "undefined")
	{
		el = document.mainform;
	}
	if( el.country.value != '' )
	{
		for(var i = 0; i < document.forms.length; i++ )
		{
			var new_country_code = el.country.value;
			var new_country_name = el.country.options[el.country.selectedIndex].text;
			if( new_country_name != '' )
			{
				SetCookie('RESIDENCE_COUNTRY_CODE',new_country_code,1);
				SetCookie('RESIDENCE_COUNTRY_NAME',new_country_name,1);
			}
		}
	}
}

//function sets a cookie with name and value passed in
function SetCookie(cookieName,cookieValue,nDays)
{
	var today = new Date();
	var expire = new Date();
	if (nDays==null || nDays==0)
	{
		nDays=1;
	}
	expire.setTime(today.getTime() + 3600000*24*nDays);
	document.cookie = cookieName+"="+escape(cookieValue)
				 + ";expires="+expire.toGMTString();
}

//function to auto set/select the dropdowns
function autoSetDropDown(el)
{
	if(typeof(el) == "undefined")
	{
		el = document.mainform;
	}

	//get cookies
	var PC_MAIN_ID = getSearchCookieValue('PC_MAIN_ID');
	var PC_MAIN = getSearchCookieValue('PC_MAIN');
	var PC_ID = getSearchCookieValue('PC_ID');
	var DEST_COUNTRY = getSearchCookieValue('DEST_COUNTRY');

	getCareer();

	//auto select career dropdown value if there is a cookie set
	if( PC_MAIN != '' ||  PC_MAIN_ID != '' )
	{
		if( el.programcategory_main.type == 'select-one' )
		{
			for (var i = 0; i < el.programcategory_main.options.length; i++)
			{
				if( el.programcategory_main.options[i].value == PC_MAIN || el.programcategory_main.options[i].value == PC_MAIN_ID )
				{
					el.programcategory_main.options[i].selected=true;
				}
			}
		}
		//process the category/degree dropdown
		getDegree();
	}
	else
	{
		//no cookie, so process for dynamic category/degree dropdown
		getDegree();		
	}

	if( PC_ID != '' )
	{
		//auto select category/degree dropdown value since there is a cookie set
		if( el.programcategory_id.type == 'select-one' )
		{
			for (var i = 0; i < el.programcategory_id.options.length; i++)
			{
				if( el.programcategory_id.options[i].value == PC_ID )
				{
					el.programcategory_id.options[i].selected=true;
				}
			}
		}
	}
		
	if( DEST_COUNTRY != '' )
	{
		if( el.destination.type == 'select-one' )
		{
			for (var i = 0; i < el.destination.options.length; i++)
			{
				if( DEST_COUNTRY == el.destination.options[i].value )
				{
					el.destination.options[i].selected=true;
				}
			}
		}
	}
}

function addValue()
{
	if( document.getElementById('programcategory_main').type == 'select-one' )
		document.getElementById('campus_key').value = document.getElementById('programcategory_main').options[document.getElementById('programcategory_main').selectedIndex].text;
	if( document.getElementById('programcategory_id').type == 'select-one' )
		document.getElementById('program_key').value = document.getElementById('programcategory_id').options[document.getElementById('programcategory_id').selectedIndex].text;
}
