/////////////////////////
// LINK DEFINITIONS
/////////////////////////
//Europe Links
var eur_default		= 'commerciaux/global/europe/index.html';
var eur_accounts 	= 'commerciaux/global/europe/index.html?sec=accounts';
var eur_exchange 	= 'commerciaux/global/europe/index.html?sec=exchange';
var eur_payments 	= 'commerciaux/global/europe/index.html?sec=payments';
var eur_receivables = 'commerciaux/global/europe/index.html?sec=receivables';
var eur_management 	= 'commerciaux/global/europe/index.html?sec=management';
var eur_funds 		= 'commerciaux/global/europe/index.html?sec=funds';
var eur_expenses 	= 'commerciaux/global/europe/index.html?sec=expenses';
//US Links
var us_default 		= 'commerciaux/global/us/index.html';
var us_accounts 	= 'commerciaux/global/us/index.html?sec=accounts';
var us_exchange 	= 'commerciaux/global/us/index.html?sec=exchange';
var us_payments 	= 'commerciaux/global/us/index.html?sec=payments';
var us_receivables  = 'commerciaux/global/us/index.html?sec=receivables';
var us_management 	= 'commerciaux/global/us/index.html?sec=management';
var us_funds 		= 'commerciaux/global/us/index.html?sec=funds';
var us_expenses 	= 'commerciaux/global/us/index.html?sec=expenses';
//Asia Links
var asia_default 	= 'commerciaux/global/asia/index.html';
var asia_accounts 	= 'commerciaux/global/asia/index.html?sec=accounts';
var asia_exchange 	= 'commerciaux/global/asia/index.html?sec=exchange';
var asia_payments 	= 'commerciaux/global/asia/index.html?sec=payments';
var asia_receivables= 'commerciaux/global/asia/index.html?sec=receivables';
var asia_management = 'commerciaux/global/asia/index.html?sec=management';
var asia_funds 		= 'commerciaux/global/asia/index.html?sec=funds';
var asia_expenses 	= 'commerciaux/global/asia/index.html?sec=expenses';
//Latin America Links
var lam_default		= 'commerciaux/global/latin/index.html';
var lam_accounts 	= 'commerciaux/global/latin/index.html?sec=accounts';
var lam_exchange 	= 'commerciaux/global/latin/index.html?sec=exchange';
var lam_payments 	= 'commerciaux/global/latin/index.html?sec=payments';
var lam_receivables = 'commerciaux/global/latin/index.html?sec=receivables';
var lam_management 	= 'commerciaux/global/latin/index.html?sec=management';
var lam_funds 		= 'commerciaux/global/latin/index.html?sec=funds';
var lam_expenses	= 'commerciaux/global/latin/index.html?sec=expenses';
//Other Links
var oth_default		= 'commerciaux/global/other/index.html';
var oth_accounts 	= 'commerciaux/global/other/index.html?sec=accounts';
var oth_exchange 	= 'commerciaux/global/other/index.html?sec=exchange';
var oth_payments 	= 'commerciaux/global/other/index.html?sec=payments';
var oth_receivables = 'commerciaux/global/other/index.html?sec=receivables';
var oth_management 	= 'commerciaux/global/other/index.html?sec=management';
var oth_funds 		= 'commerciaux/global/other/index.html?sec=funds';
var oth_expenses 	= 'commerciaux/global/other/index.html?sec=expenses';

function init(location, first_load) {
	//Set Service Drop Down to incoming parameter
	var section = getURLParam('sec');
	if (section=='accounts' || section=='exchange' || section=='payments' || section=='receivables' || section=='management' || section=='funds' || section=='expenses') {
		document.getElementById('service_id_1').value = section;
	}
	else {
		document.getElementById('service_id_1').value = '';
	}
	//Switch to currently selected section
	switchSection('location_id_1', location, 'service_id_1', '<!--#echo var="SERVER_NAME" -->/<!--#echo var="SESSION_ID" -->', first_load);
}

function getURLParam(strParamName) {	
	// GetURL Params value from querystring
	var qs = location.search.split('?');
	if (qs.length > 1) {
	var pairs = qs[1].split("&");
		for (var i=0; i<pairs.length; i++) {
			var namevalue = pairs[i].split("=", 2);
			var name = unescape(namevalue[0]);
			var value = unescape(namevalue[1]);
			if (name.toUpperCase() == strParamName.toUpperCase()) {
				return value;
				//break;
			}
		}
	}
	return null;
}

function switchSection(loc_next, current_loc, sec, server_name, first_load) {
	//Switch to Parameters
	var section_quote = document.getElementById('section_quote');
	var location = document.getElementById(loc_next).value;
	var section = document.getElementById(sec).value;
	var current_location = current_loc;

	//Go to Other Regions Page if the Location has changed
	if (location != current_location && first_load!=1) {
		navigateToNewCountry(loc_next, sec, server_name);
	}
	else {
		//All Possible Sections
		var sections = new Array();		
		sections[0]	= 'section_accounts';
		sections[1] = 'section_exchange'; 
		sections[2] = 'section_payments';
		sections[3] = 'section_receivables';
		sections[4] = 'section_management';
		sections[5] = 'section_funds';
		sections[6] = 'section_expenses';
		
		//Display section passed in parameter
		var temp = 'section_' + section;
		var counter=0;
		for (var x=0; x<sections.length; x++) {
			if (temp == sections[x]) { 
				document.getElementById(sections[x]).style.display = '';
				counter++;
			}
			else {
				document.getElementById(sections[x]).style.display = 'none';
			}
		}
		//Display/Hide Quote section 
		if (counter>0) section_quote.style.display = 'none';
		else section_quote.style.display = '';
		
	}
}

//Will forward page to appropriate link based on location and service
function navigate(location_box, service_box, server_name){
	var location = document.getElementById(location_box).value;
	var service = document.getElementById(service_box).value;
	var link_to = '';
	
	/////////////////////////
	// SET LINKS
	/////////////////////////	
	//Europe
	if (location == "europe") {
		if (service == "accounts") 			link_to = eur_accounts;
		else if (service == "exchange")		link_to = eur_exchange;
		else if (service == "payments")		link_to = eur_payments;
		else if (service == "receivables")	link_to = eur_receivables;
		else if (service == "management")	link_to = eur_management;
		else if (service == "funds")		link_to = eur_funds;
		else if (service == "expenses")		link_to = eur_expenses;
		else 								link_to = eur_default;
	}
	else if (location == "us") {
		if (service == "accounts") 			link_to = us_accounts;
		else if (service == "exchange")		link_to = us_exchange;
		else if (service == "payments")		link_to = us_payments;
		else if (service == "receivables")	link_to = us_receivables;
		else if (service == "management")	link_to = us_management;
		else if (service == "funds")		link_to = us_funds;
		else if (service == "expenses")		link_to = us_expenses;
		else 								link_to = us_default;		
	}
	else if (location == "asia") {
		if (service == "accounts") 			link_to = asia_accounts;
		else if (service == "exchange")		link_to = asia_exchange;
		else if (service == "payments")		link_to = asia_payments;
		else if (service == "receivables")	link_to = asia_receivables;
		else if (service == "management")	link_to = asia_management;
		else if (service == "funds")		link_to = asia_funds;
		else if (service == "expenses")		link_to = asia_expenses;	
		else 								link_to = asia_default;		
	}
	else if (location == "latin_america") {
		if (service == "accounts") 			link_to = lam_accounts;
		else if (service == "exchange")		link_to = lam_exchange;
		else if (service == "payments")		link_to = lam_payments;
		else if (service == "receivables")	link_to = lam_receivables;
		else if (service == "management")	link_to = lam_management;
		else if (service == "funds")		link_to = lam_funds;
		else if (service == "expenses")		link_to = lam_expenses;	
		else 								link_to = lam_default;		
	}
	else if (location == "other") {
		if (service == "accounts") 			link_to = oth_accounts;
		else if (service == "exchange")		link_to = oth_exchange;
		else if (service == "payments")		link_to = oth_payments;
		else if (service == "receivables")	link_to = oth_receivables;
		else if (service == "management")	link_to = oth_management;
		else if (service == "funds")		link_to = oth_funds;
		else if (service == "expenses")		link_to = oth_expenses;	
		else 								link_to = oth_default;		
	}	
	
	/////////////////////////
	// GO TO LINK
	/////////////////////////	
	if (link_to != '') document.location.href = 'http://' + server_name + link_to;
	else return void(0);
}
