function copyDataToBilling() {
	$("#billing_gender").val($("#owner_gender").val());
	$("#billing_company").val($("#company_name").val());
	$("#billing_firstname").val($("#owner_firstname").val());
	$("#billing_lastname").val($("#owner_lastname").val());
	$("#billing_street").val($("#company_street").val());
	$("#billing_housenumber").val($("#company_housenumber").val());
	$("#billing_zipcode").val($("#company_zipcode").val());
	$("#billing_city").val($("#company_city").val());
}

function bookmark(sbService) {
	referer = encodeURIComponent(location.href);
	title = encodeURIComponent(document.title);

	switch(sbService) {
		case '01':
			window.open('http://www.blinklist.com/index.php?Action=Blink/addblink.php&Description=&Url=' + referer + '&Title=' + title);
		break;
		case '02':
			window.open('http://del.icio.us/post?url=' + referer + '&title=' + title);
		break;
		case '03': 		
			window.open('http://www.digg.com/submit?phase=2&url=' + referer);
		break;
		case '04':
			window.open('http://www.folkd.com/submit/page/' + referer);
		break;
		case '05':
			window.open('http://www.furl.net/storeIt.jsp?u=' + referer + '&t=' + title);
		break;
		case '06': 		
			window.open('http://www.google.com/bookmarks/mark?op=add&hl=de&bkmk=' + referer + '&title=' + title);
		break;
		case '07':	
			window.open('http://linkarena.com/bookmarks/addlink/?url=' + referer + '&title=' + title + '&desc=&tags=');
		break;
		case '08':
			window.open('http://www.mister-wong.de/index.php?action=addurl&bm_url=' + referer + '&bm_description=' + title);
		break;
		case '09':
			window.open('http://beta.oneview.de:80/quickadd/neu/addBookmark.jsf?URL=' + referer + '&title=' + title);			
		break;
		case '10': 		
			window.open('http://www.webnews.de/einstellen?url=' + referer + '&title=' + title);
		break;
		case '11':
			window.open('http://myweb2.search.yahoo.com/myresults/bookmarklet?u=' + referer + '&t=' + title);
		break;
		case '12':
			window.open('http://yigg.de/neu?exturl=' + referer + '&exttitle=' + title);
		break;	
	}
}

function loadGoogleMaps() {
	if (GBrowserIsCompatible()) {
		google_map= new GMap2(document.getElementById("map"));
		google_map.addControl(new GSmallMapControl());
		google_map.addControl(new GMapTypeControl());
		google_map.setCenter(new GLatLng(50.764259,11.096191), 5);
		google_geocoder = new GClientGeocoder();
	}
}

function showGoogleAddress(address) {
	if (google_geocoder) {
		google_geocoder.getLatLng(
			address,
			function(point) {
				if (!point) { }
				else {
					google_map.setCenter(point, 13);
					var blueIcon = new GIcon(G_DEFAULT_ICON);
					markerOptions = {};
					var marker = new GMarker(point, markerOptions);
					google_map.addOverlay(marker);
					glob_point = point;
				}
			}
		);
	}
}

function showGoogleRoute(address, startpoint) {
	if (startpoint != "") {
		locale = "de_DE";
		gdir = new GDirections(google_map, document.getElementById("directions"));
		GEvent.addListener(gdir, "addoverlay", onGDirectionsLoad);
		GEvent.addListener(gdir, "error", handleErrors);
		gdir.load("from: " + startpoint + " to: " + glob_point, { "locale": locale });
	}
}

function handleErrors(){
	   if (gdir.getStatus().code == G_GEO_UNKNOWN_ADDRESS)
	     alert("No corresponding geographic location could be found for one of the specified addresses. This may be due to the fact that the address is relatively new, or it may be incorrect.\nError code: " + gdir.getStatus().code);
	   else if (gdir.getStatus().code == G_GEO_SERVER_ERROR)
	     alert("A geocoding or directions request could not be successfully processed, yet the exact reason for the failure is not known.\n Error code: " + gdir.getStatus().code);
	   else if (gdir.getStatus().code == G_GEO_MISSING_QUERY)
	     alert("The HTTP q parameter was either missing or had no value. For geocoder requests, this means that an empty address was specified as input. For directions requests, this means that no query was specified in the input.\n Error code: " + gdir.getStatus().code);
	   else if (gdir.getStatus().code == G_GEO_BAD_KEY)
	     alert("The given key is either invalid or does not match the domain for which it was given. \n Error code: " + gdir.getStatus().code);
	   else if (gdir.getStatus().code == G_GEO_BAD_REQUEST)
	     alert("A directions request could not be successfully parsed.\n Error code: " + gdir.getStatus().code);
	   else alert("An unknown error occurred.");
	    }

function onGDirectionsLoad() { 
	var poly = gdir.getPolyline();
	if (poly.getVertexCount() > 100) {
		return;
	}
	var baseUrl = "http://maps.google.com/staticmap?";

	var params = [];
	params.push("center=" + google_map.getCenter().lat().toFixed(6) + "," + google_map.getCenter().lng().toFixed(6));

	var markersArray = [];
	markersArray.push(poly.getVertex(0).toUrlValue(5) + ",greena");
	markersArray.push(poly.getVertex(poly.getVertexCount()-1).toUrlValue(5) + ",greenb");
  
	params.push("markers=" + markersArray.join("|"));
	var polyParams = "rgba:0x0000FF80,weight:5|";
	var polyLatLngs = [];
	for (var j = 0; j < poly.getVertexCount(); j++) {
		polyLatLngs.push(poly.getVertex(j).lat().toFixed(5) + "," + poly.getVertex(j).lng().toFixed(5));
	}
	params.push("path=" + polyParams + polyLatLngs.join("|"));
	params.push("zoom=" + google_map.getZoom());
	params.push("size=310x400");
}

var openingnewday = 0;
function handleOPeningTimesDay(day){

    $('input[wochentag]').attr('checked', false);
        $('div[id^=opening_day_]').css('display','none');
        $('div[id=opening_day_'+day+']').css('display','block');
        $('input[wochentag='+day+']').attr('checked', 'checked');

}

function handleRegionToCountry(country, region, regiondata, currentregion){
	
	var c = (!country)?'country':country;
	var r = (!region)?'region':region;
	var curCountry = $('select[id='+c+']').val();
	
	if(curCountry == 0){
		$('#'+r).attr('disabled',true);
	}else{
		$('#'+r).attr('disabled',false);
	}

	
	if(typeof regiondata != 'object'){$('#'+r).attr('disabled','disabled');return false;}	
	var options = "";
	$('select[id='+c+']').bind('change', function(){
		curCountry = $(this).val();
		$(this).unbind();
		handleRegionToCountry(country, region, regiondata, currentregion);
	});	
	
	var firstopt = $('select[id='+c+']').children(":first").clone();
	
	if(curCountry != 0){
	$.each(regiondata[curCountry], function(i, val){
		var addAttr = "";
		if(i == currentregion){
			addAttr = ' selected="selected"';
		}
		options +='<option value="'+i+'"'+addAttr+'>'+val+'</option>';
	});
	
	options = $.merge($(firstopt), $(options));
	
	$('select[id='+r+']').html(options);
	}
	return true;
}

function handleMetatypeSwitch(element, breast){
	if(!breast){
		breast = '#category_breast';
	}
	if($(element).val() == 3){
		$(breast).css("display", "none");
	}else {
		$(breast).css("display", "block");
	}
}

function bhcbhandler(elem, i){
	if(elem == "#sameopeningtimes"){
		handleOPeningTimesDay(1);
		
		if($("#sameopeningtimes").attr("checked") == true){
			//ausblenden
			for(var c = 2; c<=7;c++){
				$('input[wochentag='+c+']').css('display', 'none');
				$('label[for=dayofweek_'+c+']').css('display', 'none');
			}
		}
		else{
			//einblenden
			for(var c = 1; c<=7;c++){
				$('input[wochentag='+c+']').css('display', 'block');
				$('label[for=dayofweek_'+c+']').css('display', 'block');
			}
		}
	}else{
		if(elem != "#fromtocheckbox_"){
			$('input[clock='+i+']').val("");
		}
		$('#fromtocheckbox_'+i).attr("checked", false);
		$('#dayof_'+i).attr("checked", false);
		$('#appointment_'+i).attr("checked", false);
		$(elem+i).attr("checked", "checked");
	}
}
function initMapDE(title){
	$("#mapDE").dialog({
        bgiframe: true,
        resizable: false,
        autoOpen:false,
        modal: true,
        title: title,
		width: "630px",
        overlay: {
            backgroundColor: '#000',
            opacity: 70
        }
    });
}

function showMapDE() {
	$("#mapDE").dialog("open");
}

function nltooltip(image, text){
	
	if($('body').find('div[id=blacktip]').length == 0){
		$('body').append("<div id=\"blacktip\"><div class=\"blacktip_top\"></div><div class=\"blacktip_middle\"><p id=\"blacktipcontnet\"></p></div><div class=\"blacktip_bottom\"></div></div>");
	}
	
	if(text == undefined){
		text = $('#'+image).attr('title');
	}
	
	$('#'+image).bind('mouseenter', function(){
		$('#blacktipcontnet').html(text);
	});
	
	
		$('#'+image).tooltip({
				tip: '#blacktip',
				relative: false,
				offset: [-10,0],
				delay: 0
			}).dynamic({
			bottom: {
				direction: 'down',
				bounce: true 
			} 
		});
}

function voteStars(){
	var checked = 0;
	
	$('img[point]').bind('mouseenter mouseleave click', function(e){
		switch(e.type){
		case 'mouseenter':
			for(var i  = 1; i <= 6; i++){
				if(i <= $(this).attr('point')){
					$('img[point='+i+']').attr('src', '/image/star.gif');
				}else{
					$('img[point='+i+']').attr('src', '/image/star_white.gif');
				}
			}
			break;
		case 'mouseleave':
			for(var i  = 1; i <= 6; i++){
				if(i <= checked){
					$('img[point='+i+']').attr('src', '/image/star.gif');
				}else{
					$('img[point='+i+']').attr('src', '/image/star_white.gif');
				}
			}
			break;
		case 'click':
			checked = $(this).attr('point');
			$('input[name=points]').val(checked);
			break;
		default:
			// do nothing
		}
	});
}

function nltooltipspecial(){
	if($('body').find('div[id=blacktip]').length == 0){
		$('body').append("<div id=\"blacktip\"><div class=\"blacktip_top\"></div><div class=\"blacktip_middle\"><p id=\"blacktipcontnet\"></p></div><div class=\"blacktip_bottom\"></div></div>");
	}
	
	$.each($('p[id=services] > a'), function(){
	var target = this;
	if($(this).attr('title') != ""){
		$(this).tooltip({
				tip: '#blacktip',
				relative: false,
				offset: [-10,0],
				delay: 0,
				onBeforeShow: function(q){
					$('#blacktipcontnet').html($(target).attr('title'));
				},
				cancelDefault: false
			}).dynamic({
			bottom: {
				direction: 'down',
				bounce: true 
			} 
		});
	}
	});
}
