var cookie_name = "shopNavigateToURL";
var navName = navigator.appName

function selectLang(idx) {
	hideLandLangPulldown();
	changelang(idx)
}

function hiLight(langImg, over) {
   if(over)
	langImg.className = "hiLight";
   else
	langImg.className = "lang_pulldown";
}

function createTooltip(id) {
   var tt = document.createElement("DIV");
   tt.id = id;
   tt.style.border='none';
   tt.style.position='absolute';
   document.body.appendChild(tt);
   return tt;
}

function findPos(obj) {
	var curleft = 0;
	var curtop = 0;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft
		curtop = obj.offsetTop
		while (obj = obj.offsetParent) {
			curleft += obj.offsetLeft
			curtop += obj.offsetTop
		}
	}
	return [curleft,curtop];
}

function getLangPulldownMenu(img) {
	var pdDiv = createTooltip('langselection');
	var top = img.clientY;
	var pos = findPos(img);
	pdDiv.style.left = (pos[0] + 0) + 'px';
	if (navName == 'Microsoft Internet Explorer')
		pdDiv.style.top = (pos[1]+ 27) + 'px';
	else
		pdDiv.style.top = (pos[1]+ 23) + 'px';
	return pdDiv;
}

function runLangPulldown(img) {
	clearTimeout(this.timer);
	var langPulldown = document.getElementById('langselection');
	if (langPulldown != null) {
		collapseLandLangPulldown()
	}
	else {
		expandLangPulldown(img);
	}
}

function collapseLandLangPulldown() {
	var langPulldown = document.getElementById('langselection');
	if (langPulldown != null) {
		langPulldown.style.visibility='hidden';
		document.body.removeChild(langPulldown);
		langPulldown = null;
	}
}

function expandLangPulldown(img) {
	var langPulldown = getLangPulldownMenu(img);
	langPulldown.innerHTML=document.getElementById('divData').innerHTML;
	langPulldown.style.visibility='visible';
}

function showExpandLandLangPulldown() {
	var langPulldown = document.getElementById('langselection');
	if (langPulldown != null) {
		langPulldown.style.visibility='visible';
	}
}

function hideLandLangPulldown(){
	clearTimeout(this.timer);
	this.timer=setTimeout("collapseLandLangPulldown()","500");
}

function showLandLangPulldown(){
	clearTimeout(this.timer);
	this.timer=setTimeout("showExpandLandLangPulldown()","1000");
}

function changelang(id)
{
	switch(id){
	case 0:
		checkCountry(id, 'en-au', 'http://www.visitbritaindirect.com/en-au/');
		break;
	case 1:
	case 16:
		checkCountry(id, 'nl-nl', 'http://www.visitbritaindirect.com/nl-nl/');
		break;
	case 2:
	case 9:
	case 24:
		checkCountry(id, 'fr-fr', 'http://www.visitbritaindirect.com/fr-fr/');
		break;
	case 3:
		checkCountry(id, 'en-ca', 'http://www.visitbritaindirect.com/en-ca/');
		break;
	case 4:
		navigateToURL (id, 'http://visitbritain.e-line.nu/servlet/us_pyra?wts.PAGE=h_ix3.htm&$GUEST=DK&wts.ACTION=loginguest&p=H');
		break;
	case 5:
	case 14:
	case 15:
	case 19:
	case 21:
		checkCountry(id, 'de-de', 'http://www.visitbritaindirect.com/de-de/');
		break;
	case 6:
		navigateToURL(id, 'http://www.enjoyenglanddirect.com/');
		break;
	case 7:
		checkCountry(id, 'es-es', 'http://www.visitbritaindirect.com/es-es/');
		break;
	case 8:
		navigateToURL(id, 'http://visitbritain.e-line.nu/servlet/us_pyra?wts.PAGE=h_ix3.htm&$GUEST=FI&wts.ACTION=loginguest&p=H');
		break;
	case 10:
		checkCountry(id, 'en-hk', 'http://www.visitbritaindirect.com/en-hk/');
		break;
	case 11:
		checkCountry(id, 'en-in', 'http://www.visitbritaindirect.com/en-in/');
		break;
	case 12:
	case 25:
		checkCountry(id, 'it-it', 'http://www.visitbritaindirect.com/it-it/');
		break;
	case 13:
		checkCountry(id, 'ja-jp', 'http://www.visitbritaindirect.com/ja-jp/');
		break;
	case 17:
		checkCountry(id, 'en-nz', 'http://www.visitbritaindirect.com/en-nz/');
		break;
	case 18:
		navigateToURL(id, 'http://visitbritain.e-line.nu/servlet/us_pyra?wts.PAGE=h_ix3.htm&$GUEST=NO&wts.ACTION=loginguest&p=H');
		break;
	case 20:
		checkCountry(id, 'pt-pt', 'http://www.visitbritaindirect.com/pt-pt/');
		break;
	case 22:
		checkCountry(id, 'en-sg', 'http://www.visitbritaindirect.com/en-sg/');
		break;
	case 23:
		checkCountry(id, 'en-za', 'http://www.visitbritaindirect.com/en-za/');
		break;
	case 26:
		navigateToURL(id, 'http://visitbritain.e-line.nu/servlet/us_pyra?wts.PAGE=h_ix3.htm&$GUEST=SE&wts.ACTION=loginguest&p=H');
		break;
	case 27:
		checkCountry(id, 'en-us', 'http://www.visitbritaindirect.com/en-us/');
		break;
	case 28:
		checkCountry(id, 'en-gb', 'http://www.visitbritaindirect.com/en-gb/');
		break;
	}
}

function checkCountry(id, varCountryName, varURL)
{
	var varShopName = document.getElementById('Shop_Name').value.toLowerCase();
	var varSameCountry= general_ChangeLanguage_SameCountry;
	if (varShopName== varCountryName)
		{
			alert(varSameCountry);
		}
		else
		{
			navigateToURL(id, varURL);
		}
}

function navigateToURL(id, varURL)
{
	var varWarning = general_ChangeLanguage_DefaultLanguage;
	if(confirm(varWarning))
		createCookie (varURL,365);
	document.location = varURL;
}

function createCookie(value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = cookie_name+"="+value+expires+"; path=/";
}

function readCookie() {
	var nameEQ = cookie_name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie() {
	createCookie(cookie_name,"",-1);
}

function checkCookieExists(){
	varURL=readCookie();
	if (varURL!=null && varURL!="")
	{
		alert(varURL);
		//document.location = varURL;
	}
}