
var regions = new Array();

function loadRegions(select_src, select_dst, dependencies)
{
	var id 		= select_src[select_src.selectedIndex].value;
	
	if (id != 'choose')
	{
		var data 	= "/libs/js/regions/"+id+".js";

	 	regions = new Array();
		$.getScript(data, function()
		{
	     	var options = '<option value="choose">Bitte wählen</option>';
	     	if (regions.length > 0)
	     	{
				for (var key in regions) 
		   		{
		     		options += '<option value="' + key + '">' + regions[key] + '</option>';
		   		}
		   		$("select#"+select_dst).html(options);
		   		$("select#"+select_dst).show();
	   			$("."+select_dst).show();
	     	}
	     	else
	     	{
	       		$("select#"+select_dst).html('');
	       		$("select#"+select_dst).hide();
	    		$("."+select_dst).hide();
	     	}
		});
	}
	else
	{
   		$("select#"+select_dst).html('');
   		$("select#"+select_dst).hide();
		$("."+select_dst).hide();
	}
	
	for (var key in dependencies)
	{
		$("select#"+dependencies[key]).html('');
   		$("select#"+dependencies[key]).hide();
   		$("."+dependencies[key]).hide();
	}
}

function loadOptions(funcname, select_src, select_dst)
{
	var id 		= document.getElementById(select_src)[document.getElementById(select_src).selectedIndex].value;
	if (id != 'choose')
	{
		$("select#"+select_dst).load("ajax", {func: funcname, selected: id}, function()
		{
	   		$("select#"+select_dst).show();
   			$("."+select_dst).show();
		});
	}
	else
	{
   		$("select#"+select_dst).html('');
   		$("select#"+select_dst).hide();
		$("."+select_dst).hide();
	}
	
}

function hideOptionsOn(cond, select_src, select_dst)
{
	var id 		= document.getElementById(select_src)[document.getElementById(select_src).selectedIndex].value;
	if (id != cond)
	{
   		$("select#"+select_dst).show();
		$("."+select_dst).show();
	}
	else
	{
   		$("select#"+select_dst).hide();
		$("."+select_dst).hide();
	}
}

function hideInputOn(cond, select_src, dst)
{
	var id 		= document.getElementById(select_src)[document.getElementById(select_src).selectedIndex].value;
	if (id == cond)
	{
   		$("#"+dst).show();
	}
	else
	{
   		$("#"+dst).hide();
	}
}

function changeOnValue(select_src, key_src, select_dst, key_dst)
{
	var id = document.getElementById(select_src)[document.getElementById(select_src).selectedIndex].value;
	
	if (id == key_src)
	{
		$("select#"+select_dst).val(key_dst);
	}
}

function loadUrl(url, dst)
{
	$("#"+dst).load(url);
	return false;
}

function loadBlock(block, dst)
{
	var argv = loadBlock.arguments;
	var argc = argv.length;

	url = location.href.split(/\?|#/)[0];
	//$("#"+dst).load(url+'?block='+block);
	
	for (var i = 0; i < argc; i+=2)
	{
		$("#"+argv[i+1]).load(url+"?block="+argv[i]);
	}

	return false;
}




function swapFade(old_div, new_div)
{
	$("#"+old_div).hide();
	$("#"+new_div).show();
}

function selectTab(tab_id, idx)
{
	$('#'+tab_id).tabs('select', idx);
}

function makeBold(me, off)
{
	$("a."+off).removeClass("bold");
	$(me).addClass("bold");
}

function toggleBold(me, off)
{
	if (off !== undefined)
	{
		$("a."+off).removeClass("bold");
	}
	
	if ($(me).hasClass("bold"))
	{
		$(me).removeClass("bold");
	}
	else
	{
		$(me).addClass("bold");
	}
	
}

function showInputExamples()
{
	$("input,textarea").labelify({labelledClass: "embedded_default_text"});
}


function gmLoad()
{
	if (gm_script_exec !== undefined)
	{
		document.body.appendChild(gm_script_exec);
	}
	
	$(window).unload( function () { GUnload(); } );
}

function findValue(li) 
{
	/*
	  if( li == null ) return alert("No match!");

		// if coming from an AJAX call, let's use the CityId as the value
		if( !!li.extra ) var sValue = li.extra[0];

		// otherwise, let's just display the value in the text box
		else var sValue = li.selectValue;

		alert("The value you selected was: " + sValue);
		*/
	}

	function selectItem(li) {
		findValue(li);
	}

	function formatItem(row) {
		return row[0];
	}

	function autosuggest(must_match)
	{
		$("#SearchWhere").autocomplete(
				"/ajax",
				{
					delay:1,
					minChars:0,
					matchSubset:0,
					matchContains:0,
					cacheLength:10,
					onItemSelect:selectItem,
					onFindValue:findValue,
					formatItem:formatItem,
					autoFill:true,
					mustMatch: must_match,
					extraParams: {func: 'getAutoSuggestWhere' }
				}
			);

		$("#SearchWhat").autocomplete(
				"/ajax",
				{
					delay:1,
					minChars:0,
					matchSubset:0,
					matchContains:0,
					cacheLength:10,
					onItemSelect:selectItem,
					onFindValue:findValue,
					formatItem:formatItem,
					autoFill:true,
					mustMatch: must_match,
					extraParams: {func: 'getAutoSuggestWhat' }
				}
			);
	}

function confirmDialog()
{
	var agree=confirm("Fortfahren?");
	if (agree)
	return true ;
	else
	return false ;
}

function emailDialog(me)
{
	$('body').append('<div id="emaildialog" class="hidden"></div>')
	$("#emaildialog").load($(me).attr("href"));
	$("#emaildialog").dialog({modal: true, resizable: false, width: 600, height: 400, closeOnEscape: true, beforeClose: function(event, ui) 
	{
	}
	});
	return false;
}

$(document).ready(function() 
{
	/*
	if (gm_script !== undefined)
	{
		document.body.appendChild(gm_script);
	}
*/
	/*
	oStringMask = new Mask("(###) ###-####");
	if (document.getElementById('request_form'))
	{
		oStringMask.attach(document.request_form.phone);
	}
	
	if (document.getElementById('signup_form'))
	{
		oStringMask.attach(document.signup_form.phone);
	}
	*/

	$(".tabs").tabs().show();
	autosuggest(false);
	showInputExamples();

	$("#SearchWhat").blur(function()
	{
		if ($("#SearchWhat").attr('title') == $("#SearchWhat").val())
		{
			//$("#SearchWhat").css('color','black');
		}
	});
			
			

});

