﻿var gloCountryArg, gloParams, overCountries;
overCountries = false; // initializing overCountries and setting it to false
/* Page wide variables needed to redirect the page based on country selection.
// gloCountryArg (string:'[url]')
// gloParams (string:'[countryId]||[openMode]')
// overCountries (bool:overCountries)
*/
function dropDownClickEvent() { // drop down click events
    $('#countryListTopLeft').click(function() { 
	    toggleDropDown();
	    overCountries = true;
	});
    $('#countryListTopRight').click(function() { 
        toggleDropDown();
        overCountries = true;
    });
}
function linksMouseOverEvent() { // Mouseover effects on the links so they behave like 'drop-downs'
    var links = $('a.countryLink');
    links.mouseover(function() { 
        links.removeClass('countryLinkSelected');
        overCountries = true;
    });
}
function linksCloseDropDownEvents() {
    $('#countryListTopRight').mouseout(function() { overCountries = false; });
	$('#countryListTopLeft').mouseout(function() { overCountries = false; });
	$('a.countryLink').mouseout(function() { overCountries = false; });
}
function linksClickEvent() { // loading click events on links 
    $('a.countryLink').click(function() {
		$('#countryLabel').html(this.innerHTML);
		toggleDropDown();
	});
}
function toggleDropDown() { // drop down toggler. Turns it on or off and adds relevant logic to make it behave like a normal 'drop down'
	var dropDownUL = $('#dropDownUL');
	if (dropDownUL.css('display') == 'block') { // when the UL is expanded
		$('#countryListTopLeft').addClass('linkSelected');
		dropDownUL.hide();
	}
	else { // when the UL is NOT expanded
		$('#countryListTopLeft').removeClass('linkSelected');
		$('a.countryLink').filter(':contains(' + $('#countryLabel').text() + ')').addClass('countryLinkSelected');
		dropDownUL.show();
	}		
}
function countryLinkClick(o) { // o = the link object; function must always returns false as we need to process the (normal)visitors before sending them off.
    var jo = $(o);
    gloCountryArg = jo.attr('href'); 
    gloParams = jo.attr('id');
    return false;
}
function documentEvent() {
    $(document).click(function() { 
        if (!overCountries) { 
        	$('#dropDownUL').hide();
        	$('#countryListTopLeft').removeClass('linkSelected');
        }
    });
}
function launchHomeURL() {
	if ((gloCountryArg != '#' || gloCountryArg != '') && (gloParams != '')) {
		var cid, openMode, homeUrl, redirectUrl
		cid = gloParams.substr(0,gloParams.indexOf('||'));
		openMode = gloParams.substr(gloParams.indexOf('||')+2);
		redirectUrl = 'countries.asp?CID=' + cid + '&rp=' + escape(document.getElementById('rp').value);
		if (document.getElementById('chkStore').checked) { redirectUrl += '&s=1'; } // Checking if user wants to remember country selected.
		location.href = redirectUrl;
	}
	return false;
}