zw = null;
ws = null;

function SG_SetFocus(){
	if (document.images){
		this.focus();
	}
}

function SG_openWaitScreen() {

  var winleft = (screen.width - 300) / 2;
  var wintop  = (screen.height - 120) / 2;
	ws = window.open("waitscreen.html","waitscreen","width=300,height=120,top="+wintop+",left="+winleft);
}

function SG_closeWaitScreen() {
	if ( ws != null ) {
		ws.close();
	}
}

function BrowserData(sUA) {
				var iMSIE = sUA.indexOf("MSIE");
				this.userAgent = sUA;
				this.browser = (-1 != iMSIE) ? "MSIE" : "Other";
				this.majorVer = parseInt(sUA.substring(iMSIE + 5, iMSIE + 6));
				this.getsMenus = ("MSIE" == this.browser && 4 <= this.majorVer);
}
var oBD = new BrowserData(navigator.userAgent);


function SG_saveSelect() {

	if (formBooking.region_code.options) {
		formBooking.restore_region_code.value = formBooking.region_code.options[formBooking.region_code.selectedIndex].value;
	} else {
		formBooking.restore_region_code.value = formBooking.region_code.value;
	}

	if (formBooking.subregion_code.options) {
		formBooking.restore_subregion_code.value = formBooking.subregion_code.options[formBooking.subregion_code.selectedIndex].value;
	} else {
		formBooking.restore_subregion_code.value = formBooking.subregion_code.value;
	}

	if (formBooking.location_code.options) {
		formBooking.restore_location_code.value = formBooking.location_code.options[formBooking.location_code.selectedIndex].value;
	} else {
		formBooking.restore_location_code.value = formBooking.location_code.value;
	}

}


function SG_loadSelect(sAction) {

	if(!sAction) { sAction = formBooking.action.value }
	
	alert(sAction);

	switch (sAction) {
	
		case 'init':
			
			SG_loadSelectRegion();
			if (formBooking.region_code.options && formBooking.restore_region_code.value != '') {
			
				nIndex = 0;

				for (var i = 0; i < formBooking.region_code.options.length; i++) {
					if (formBooking.restore_region_code.value == formBooking.region_code.options[i].value) {
						nIndex = i;
					}
				}
				
				formBooking.region_code.options[nIndex].selected = true;
			} 
			
			SG_loadSelectSubregion();
			if (formBooking.subregion_code.options && formBooking.restore_subregion_code.value != '') {
			
				nIndex = 0;

				for (var i = 0; i < formBooking.subregion_code.options.length; i++) {
				
					if (formBooking.restore_subregion_code.value == formBooking.subregion_code.options[i].value) {
						nIndex = i;
					}
				}
				formBooking.subregion_code.options[nIndex].selected = true;
			} 

			SG_loadSelectLocation();
			if (formBooking.location_code.options && formBooking.restore_location_code.value != '') {
			
				nIndex = 0;

				for (var i = 0; i < formBooking.location_code.options.length; i++) {
					if (formBooking.restore_location_code.value == formBooking.location_code.options[i].value) {
						nIndex = i;
					}
				}
				formBooking.location_code.options[nIndex].selected = true;
			} 

		break;

		case 'region':
			SG_loadSelectRegion();
		break;

		case 'subregion':
			SG_loadSelectSubregion();
		break;

		case 'location':
			SG_loadSelectLocation();
		break;
	}
}


function SG_loadSelectRegion() {

	if(!formBooking.region_code.options) { return }

	SG_resetSelectLocation();
	SG_resetSelectSubregion();
	SG_resetSelectRegion();	

	for (var i = 0; i < aRegionCode.length; i++) {
		oOption = new Option(aRegionDisplayname[(i)]);
		formBooking.region_code.options[(i+1)] = oOption;
		formBooking.region_code.options[(i+1)].value = aRegionCode[(i)];
	}
	formBooking.subregion_code.options[0].value = '';
	formBooking.subregion_code.options[0].selected = true;
}


function SG_loadSelectSubregion() {

	if(!formBooking.subregion_code.options) { return }

	var oOption;

	if(
		!formBooking.region_code.options || (
		formBooking.region_code.selectedIndex >= 0 &&
		formBooking.region_code.options[formBooking.region_code.selectedIndex].value != '')) {

		SG_resetSelectLocation();
		SG_resetSelectSubregion();

		oOption = new Option('beliebig');
		formBooking.subregion_code.options[0] = oOption;

		var sRegionCode = '';
		
		if (formBooking.region_code.options) {
			sRegionCode = formBooking.region_code.options[formBooking.region_code.selectedIndex].value;
		} else {
			sRegionCode = formBooking.region_code.value;
		}
		
		var nRegionIndex = 0;

		for (var i = 0; i < aRegionCode.length; i++) {
			if (sRegionCode == aRegionCode[i]) {
				nRegionIndex = i;
			}
		}

		for (var i = 0; i < aSubregionCode[nRegionIndex].length; i++) {
			oOption = new Option(aSubregionDisplayname[nRegionIndex][(i)]);
			formBooking.subregion_code.options[(i+1)] = oOption;
			formBooking.subregion_code.options[(i+1)].value = aSubregionCode[nRegionIndex][(i)];
		}

		formBooking.subregion_code.options[0].value = '';
		formBooking.subregion_code.options[0].selected = true;
		formBooking.location_code.options[0].value = '';
		formBooking.location_code.options[0].selected = true;

	} else {
		SG_resetSelectLocation();
		SG_resetSelectSubregion();
	}
}


function SG_loadSelectLocation() {

	if(!formBooking.location_code.options) { return }

	var oOption;

	if(
		(!formBooking.region_code.options || (
		formBooking.region_code.selectedIndex >= 0 &&
		formBooking.region_code.options[formBooking.region_code.selectedIndex].value != '')) &&
		(!formBooking.subregion_code.options || (
		formBooking.subregion_code.selectedIndex >= 0 &&
		formBooking.subregion_code.options[formBooking.subregion_code.selectedIndex].value != ''))) {

		SG_resetSelectLocation();

		var sRegionCode = '';
		var nRegionIndex = 0;
		
		if (formBooking.region_code.options) {
			sRegionCode = formBooking.region_code.options[formBooking.region_code.selectedIndex].value;
		} else {
			sRegionCode = formBooking.region_code.value;
		}

		for (var i = 0; i < aRegionCode.length; i++) {
			if (sRegionCode == aRegionCode[i]) {
				nRegionIndex = i;
			}
		}

		var sSubregionCode = '';
		var nSubregionIndex = 0;

		if (formBooking.subregion_code.options) {
			sSubregionCode = formBooking.subregion_code.options[formBooking.subregion_code.selectedIndex].value;
		} else {
			sSubregionCode = formBooking.subregion_code.value;
		}

		for (var i = 0; i < aSubregionCode[nRegionIndex].length; i++) {
			if (sSubregionCode == aSubregionCode[nRegionIndex][i]) {
				nSubregionIndex = i;
			}
		}

		for (var i = 0; i < aLocationCode[nRegionIndex][nSubregionIndex].length; i++) {
			oOption = new Option(aLocationDisplayname[nRegionIndex][nSubregionIndex][(i)]);
			formBooking.location_code.options[(i+1)] = oOption;
			formBooking.location_code.options[(i+1)].value = aLocationCode[nRegionIndex][nSubregionIndex][(i)];
		}

	} else {
		SG_resetSelectLocation();
	}
}


function SG_resetSelectRegion() {

	var nOptions = formBooking.region_code.options.length;

	for (var i = 0; i <= nOptions; i++) {
		formBooking.region_code.options[0] = null;
	}

	var oOption;
	oOption = new Option('beliebig');
	formBooking.region_code.options[0] = oOption;
	formBooking.region_code.options[0].value = '';
	formBooking.region_code.options[0].selected = true;
}


function SG_resetSelectSubregion() {

	var nOptions = formBooking.subregion_code.options.length;

	for (var i = 0; i <= nOptions; i++) {
		formBooking.subregion_code.options[0] = null;
	}

	var oOption;
	oOption = new Option('beliebig');
	formBooking.subregion_code.options[0] = oOption;
	formBooking.subregion_code.options[0].value = '';
	formBooking.subregion_code.options[0].selected = true;
}


function SG_resetSelectLocation() {

	var nOptions = formBooking.location_code.options.length;

	for (var i = 0; i <= nOptions; i++) {
		formBooking.location_code.options[0] = null;
	}

	var oOption;
	oOption = new Option('beliebig');
	formBooking.location_code.options[0] = oOption;
	formBooking.location_code.options[0].value = '';
	formBooking.location_code.options[0].selected = true;

}

function SG_SetFocus(){
	if (document.images){
		this.focus();
	}
}


function MM_swapImgRestore() { //v3.0
	var i,x,a=MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
	var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
		var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
		if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v3.0
	var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
		d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
	if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
	for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document); return x;
}

function MM_swapImage() { //v3.0
	var i,j=0,x,a=MM_swapImage.arguments; MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
	 if ((x=MM_findObj(a[i]))!=null){MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
	zw = window.open(theURL,winName,features);
}

function SG_closeBrWindow() { //v2.0
	if ( zw != null ) {
		zw.close();
	}
}

function MM_showHideLayers() { //v3.0
	var i,p,v,obj,args=MM_showHideLayers.arguments;
	for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
		if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v='hide')?'hidden':v; }
		obj.visibility=v; }
}

function MM_goToURL() { //v3.0
	var i, args=MM_goToURL.arguments; MM_returnValue = false;
	for (i=0; i<(args.length-1); i+=2) eval(args[i]+".location='"+args[i+1]+"'");
}

function MM_findObj(n, d) { //v4.0
	var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
		d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
	if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
	for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
	if(!x && getElementById) x=getElementById(n); return x;
}

function MM_changeProp(objName,x,theProp,theValue) { //v3.0
	var obj = MM_findObj(objName);
	if (obj && (theProp.indexOf("style.")==-1 || obj.style)) eval("obj."+theProp+"='"+theValue+"'");
}

