var ua		 = navigator.userAgent.toLowerCase(); 
var isMac    = (ua.indexOf('mac') != -1);
var isUnix   = (ua.indexOf('unix') != -1 || ua.indexOf('sunos') != -1 || ua.indexOf('bsd') != -1 || ua.indexOf('x11') != -1)
var isLinux  = (ua.indexOf('linux') != -1);

// ****************************************************************************************
// Author:	Hans Jakob Gehring, Leonhardt Multimedia GmbH
// Date:	31.01.2006
// ****************************************************************************************
// Function clears inner HTML of assigned DIV
// ****************************************************************************************	
function clearDiv(strId)
{
	var	objDiv	= document.getElementById(strId);
	
	if (objDiv)
		objDiv.innerHTML = "";
}//function

// ****************************************************************************************
// Author:	Hans Jakob Gehring, Leonhardt Multimedia GmbH
// Date:	31.01.2006
// ****************************************************************************************
// Function detects the browser XMLHTTP (Ajax) compatibility
// ****************************************************************************************	
function detectXMLHTTP()
{
	try
	{	
		if (window.ActiveXObject)
		{
			var objXMLHTTP = new ActiveXObject('Microsoft.XMLHTTP');
		
			if (objXMLHTTP)
				return true;
		}
		else if (window.XMLHttpRequest)
			return true;
		else 
			return false;
	}
	catch (e)
	{
		return false;
	}
}//function

// ****************************************************************************************
// Author:	Hans Jakob Gehring, Leonhardt Multimedia GmbH
// Date:	31.01.2006
// ****************************************************************************************
// Function hides button to continue with "no javascript" version.
// Hiding does not take place, if browser does not support XMLHTTP (Ajax).
// ****************************************************************************************	
function hideButton()
{
	var objButton = document.getElementById('btnSubmit');
	
	if (objButton && detectXMLHTTP())
		objButton.style.visibility = 'hidden';
}//function

// ****************************************************************************************
// Author: Hans Jakob Gehring, Leonhardt Multimedia GmbH
// Date:   31.01.2006
// ****************************************************************************************
// Function shows flash
// ****************************************************************************************
function showFlash(strFlashPath)
{
	var objFlash = new FlashObject(strFlashPath,'swfLocationMap', '540', '196', '6');
	
	objFlash.addParam('movie', strFlashPath);
	objFlash.addParam('quality', 'best');
	objFlash.addParam('menu', 'false');
	objFlash.addParam('loop', 'true');
	objFlash.addParam('scale', 'true');
	objFlash.addParam('allowscriptaccess', 'sameDomain');
	objFlash.addParam('swLiveConnect', 'sameDomain');
	objFlash.addParam('FlashVars', 'movieid=swfLocationMap');
	objFlash.write('flash');
}//function

// ****************************************************************************************
// Author: Hans Jakob Gehring, Leonhardt Multimedia GmbH
// Date:   31.01.2006
// ****************************************************************************************
// Function show gateway flash.
// It is needed for javascript to flash communication on non-Windows os 
// ****************************************************************************************	
function insertFlashGateway(strCurrentState)
{
	clearDiv('flash_gateway');
	
	var objFlash = new FlashObject('../..' + strFolderApp + 'flash/gateway.swf','swfGateway', '0', '0', '6');
	
	objFlash.addParam('movie', '../..' + strFolderApp + 'flash/gateway.swf');
	objFlash.addParam('quality', 'best');
	objFlash.addParam('menu', 'false');
	objFlash.addParam('loop', 'true');
	objFlash.addParam('scale', 'true');
	objFlash.addParam('allowscriptaccess', 'sameDomain');
	objFlash.addParam('swLiveConnect', 'sameDomain');
	objFlash.addParam('FlashVars', 'lc=swfLocationMap&fq=' + escape('currentState=' + strCurrentState));
	objFlash.write('flash_gateway');
}//function

// ****************************************************************************************
// Author: Hans Jakob Gehring, Leonhardt Multimedia GmbH
// Date:   31.01.2006
// ****************************************************************************************
// Function refresh location dropdown
// ****************************************************************************************	
function switchState(cmbState)
{
	var strIdState	= cmbState.options[cmbState.selectedIndex].value
	
	clearDiv('dropdown_location');
	
	new ajax('../..' + strFolderApp + 'selection_location.asp?id_state=' + strIdState + '&lang_path=' + strLangPath, 
			{method: 'get', update: $('dropdown_location'), onComplete: switchLocation(null)});
	
	var objFlash = document.getElementById('swfLocationMap');

	if (objFlash)
	{
		if (!isLinux && !isMac && !isUnix)
			objFlash.SetVariable("currentState", strIdState == '' ? 'noState' : strIdState);
		else
			insertFlashGateway(strIdState == '' ? 'noState' : strIdState);
	}//if
}//function

// ****************************************************************************************
// Author: Hans Jakob Gehring, Leonhardt Multimedia GmbH
// Date:   31.01.2006
// ****************************************************************************************
// Function refresh location hint.
// ****************************************************************************************	
function refreshLocationHint(strIdState)
{
	clearDiv('header');
	clearDiv('body');
	clearDiv('selection_hint');

	new ajax('../..' + strFolderApp + 'selection_hint.asp?id_state=' + strIdState + '&lang_path=' + strLangPath, 
			{method: 'get', update: $('selection_hint')});
}//function

// ****************************************************************************************
// Author: Hans Jakob Gehring, Leonhardt Multimedia GmbH
// Date:   31.01.2006
// ****************************************************************************************
// Function refresh header of location page.
// ****************************************************************************************	
function switchLocation(cmbLocation)
{
	var cmbState = document.getElementById('cmbState');
		
	var strIdState	= cmbState.options[cmbState.selectedIndex].value
	
	if (cmbLocation == null)
	{
		cmbLocation = document.getElementById('cmbLocation');

		if (cmbLocation == null && strIdState != '')
		{
			setTimeout('switchLocation(null)', 100);
			return;
		}//if
	}//if		
	
	var strIdLocation	= cmbLocation == null ? '' : cmbLocation.options[cmbLocation.selectedIndex].value	
	
	if (strIdLocation != '')
	{	
		clearDiv('header');
		clearDiv('body');
		clearDiv('selection_hint');
		
		new ajax('../..' + strFolderApp + 'detail_header.asp?id_location=' + strIdLocation + '&lang_path=' + strLangPath, 
				{method: 'get', update: $('header'), onComplete: switchCategory(strIdLocation, '')});
	}
	else
		refreshLocationHint(strIdState);
}//function

// ****************************************************************************************
// Author: Hans Jakob Gehring, Leonhardt Multimedia GmbH
// Date:   31.01.2006
// ****************************************************************************************
// Function gets state and/or location id from flash and refreshs page.
// ****************************************************************************************
function switchLocationFlash(strIdState, strIdLocation)
{
	var cmbState	= document.getElementById('cmbState');
	var cmbLocation = document.getElementById('cmbLocation');

	if (cmbState && strIdLocation == null)
	{
		cmbState.options[cmbState.selectedIndex].selected = false;
		
		clearDiv('dropdown_location');
		
		strIdState = strIdState == 'null' ? '' : strIdState.toLowerCase();
		
		for(intI = 0; intI < cmbState.options.length; intI++)
		{
			if (cmbState.options[intI].value.toLowerCase() == strIdState)
			{
				cmbState.options[intI].selected = true;
				
				switchState(cmbState);
				
				break;
			}//if
		}//for
	}//if
	
	if (cmbLocation)
	{
		cmbLocation.options[cmbLocation.selectedIndex].selected = false;
		
		for(intI = 0; intI < cmbLocation.options.length; intI++)
		{
			if (cmbLocation.options[intI].value.toLowerCase() == String(strIdLocation).toLowerCase())
			{
				cmbLocation.options[intI].selected = true;
				
				switchLocation(cmbLocation);
				
				break;
			}//if
		}//for
	}//if
}//function

// ****************************************************************************************
// Author: Hans Jakob Gehring, Leonhardt Multimedia GmbH
// Date:   31.01.2006
// ****************************************************************************************
// Function refresh body of location page
// ****************************************************************************************	
function switchCategory(
	strIdLocation,
	strIdCategory)
{
	clearDiv('body');
		
	var strURL = '../..' + strFolderApp + 'detail_body.asp?id_location=' + strIdLocation + '&id_category=' + strIdCategory + '&lang_path=' + strLangPath
	
	if (strIdCategory == '')
		new ajax(strURL, {method: 'get', update: $('body')});
	else
		new ajax(strURL, {method: 'get', update: $('body'), onComplete: refreshHeader(strIdLocation, strIdCategory)});
}//function

// ****************************************************************************************
// Author: Hans Jakob Gehring, Leonhardt Multimedia GmbH
// Date:   31.01.2006
// ****************************************************************************************
// Function refresh only header of location page
// ****************************************************************************************	
function refreshHeader(strIdLocation, strIdCategory)
{
	new ajax('../..' + strFolderApp + 'detail_header.asp?id_location=' + strIdLocation + '&id_category=' + strIdCategory + '&lang_path=' + strLangPath, 
		{method: 'get', update: $('header')});
}//function