function LocationIndex_PremiumToggle(){
    var mag=$('.abcd4-location-premiumbox-magnifier');
    $('.abcd4-location-premiumbox img.abcd4-location-premiumbox-thumb').click(function(){
        if(mag.is(':visible')==true){
            var hndl=this;
            LocationIndexPremiumToggle_Close(function(){
                LocationIndexPremiumToggle_Open(hndl);
            })
        }else{
            LocationIndexPremiumToggle_Open(this);
        }
    });
}
function LocationIndexPremiumToggle_Close(fn){
    var mag=$('.abcd4-location-premiumbox-magnifier');
    if(mag.is(':visible')==true){
        mag.find('img').animate({
            width:0,
            height:0
        },1000,function(){
            mag.html('');
            mag.hide();
            if(typeof fn!='undefined'){
                fn.call();
            }
        });
    }
}
function LocationIndexPremiumToggle_Open(cl,fn){
    var mag=$('.abcd4-location-premiumbox-magnifier');
    mag.html($(cl).parent().find('.abcd4-location-premiumbox-big').clone());
    mag.show();
    mag.find('img').animate({
        width:620,
        height:410
    },1000,function(){
        mag.find('img').click(function(){
            LocationIndexPremiumToggle_Close();
        })
        if(typeof fn!='undefined'){
            fn.call();
        }
    });
}
function UserRegistration_Submit(){
    var s=true;
    var form=$('#abcd4-user-registration-form');
    form.find('input').css('border','1px #CCCCCC solid');
    form.find('input[title=required]').each(function(){
        if($(this).val()==''){
            $(this).css('border','1px red solid');
            s=false;
        }
    });
    if(form.find('input[name=password1]').val().length<8){
        form.find('input[name=password1]').css('border','1px red solid');
        s=false;
    }
    if(form.find('input[name=password1]').val()!=form.find('input[name=password2]').val()){
        form.find('input[name=password1]').css('border','1px red solid');
        form.find('input[name=password1]').css('border','1px red solid');
        s=false;
    }
    if(s==true){
        form.submit();
    }
}
function PreviewPicture(selector){
    $(selector).hover(function(){
        var h=$(this).height()+8;
        var w=$(this).width()+8;
        $(this).css('margin-bottom','-8px');
        $(this).width(w);
        $(this).height(h);
    },function(){
        var h=$(this).height()-8;
        var w=$(this).width()-8;
        $(this).width(w);
        $(this).height(h);
        $(this).css('margin-bottom','0px');
    });
}
function GoogleMap(){
    this.showAddress=function(id,address,zoom, text){
        /*var geocoder;
        var map;

        geocoder = new google.maps.Geocoder();
                
        var latlng = new google.maps.LatLng(-34.397, 150.644);
        var myOptions = {
            zoom: zoom,
            center: latlng,
            mapTypeId: google.maps.MapTypeId.ROADMAP,    
            navigationControl: true,
            navigationControlOptions: {
                style: google.maps.NavigationControlStyle.SMALL,
                position: google.maps.ControlPosition.TOP_LEFT
            },
            scaleControl: false,
            scaleControlOptions: {
                position: google.maps.ControlPosition.BOTTOM_RIGHT
            }     
        }
        map = new google.maps.Map(document.getElementById(id), myOptions);  
        
        //var address = document.getElementById("address").value;
        
        if (geocoder) {
            geocoder.geocode( {
                'address': address
            }, function(results, status) {
                if (status == google.maps.GeocoderStatus.OK) {
                    map.setCenter(results[0].geometry.location);
                    
                    var infowindow = new google.maps.InfoWindow({
                        content: text,
                        maxWidth: 150 

                    });
                    var marker = new google.maps.Marker({
                        map: map,
                        position: results[0].geometry.location
                    });
                    
                    infowindow.open(map,marker);
                   
                } else {
                    alert("Geocode was not successful for the following reason: " + status);
                }
            });
        }*/
    }
}

function OpenStreetMap() {
    this.showCompany = function(id, companyId, text, geocodeUri) {
        var scope = this;

        jQuery.ajax({
            url: geocodeUri,
            type: 'post',
            dataType: 'json',
            success: function(response) {
                if(response.success == true) {
                    scope.show(id, response.result.latitude, response.result.longitude, 13, text);
                }
            }
        })
    }


    this.show = function(id, lat, lon, zoom, text) {
        var map = new L.Map(id);
        var tileUrl = 'http://otile1.mqcdn.com/tiles/1.0.0/osm/{z}/{x}/{y}.png',
            tileAttrib = 'Map data (c) OpenStreetMap contributors, tiles courtesy of MapQuest',
            tile = new L.TileLayer(tileUrl, {maxZoom: 18, attribution: tileAttrib});

        var location = new L.LatLng(lat, lon); // geographical point (longitude and latitude)
        map.setView(location, zoom).addLayer(tile);

        var marker = new L.Marker(location);
        map.addLayer(marker);
        marker.bindPopup(text).openPopup();
    }

    this.showLatLon=function(id, geocodeUri, zoom, text) {
        var scope = this;

        jQuery.ajax({
            url: geocodeUri,
            type: 'post',
            dataType: 'json',
            success: function(response) {
                if(response.success == true) {
                    scope.show(id, response.result.latitude, response.result.longitude, 13, text);
                }
            }
        })
    }

    this.transformAddress = function(street, zip, city) {
        return street + ', '+ zip +' '+city;
    }
}

jQuery(function() {
	
	jQuery("#abcd4-search-form").submit(function() {
		var search=jQuery(this).find('input[name=search]').val();
	    var location=jQuery(this).find('input[name=search-location]').val();
	    if(location==''||location=='bitte Stadt eingeben'){
	    	jQuery(this).find('input[name=search-location]').val('bitte Stadt eingeben');
	        return false;
	    }else{
	        return true;
	    }
	})	
})

function Search_AutoFocus(){
    var searchForm=$('#abcd4-search-form');
    var extSearchForm=$('#abcd4-extended-search-form');
    extSearchForm.find('input').focus(function(){
        extSearchForm.find('input').each(function(){
            if($(this).val()==''){
                $(this).val($(this).attr('title'));
            }
        });
        if($(this).val()==$(this).attr('title')){
            $(this).val('');
        }
    });
    searchForm.find('input').focus(function(){
        extSearchForm.find('input').each(function(){
            if($(this).val()==''){
                $(this).val($(this).attr('title'));
            }
        });
        if($(this).val()==$(this).attr('title')){
            $(this).val('');
        }
    });
    searchForm.find('input[name=search]').focus();
}
function Search_IsValid(){
    var searchForm=$('#abcd4-search-form');
    var extSearchForm=$('#abcd4-extended-search-form');
    var s=searchForm.find('input[name=search]');
    var l=searchForm.find('input[name=search-location]');
    var c=extSearchForm.find('input[name=company]');
    var b=extSearchForm.find('select[name=branch]');
    if(s.val()!=''&&l.val()==''){
        searchForm.find('input[name=search-location]').val('bitte Stadt eingeben');
        return false;
    }
    if(c.val()!=''&&l.val()==''){
        searchForm.find('input[name=search-location]').val('bitte Stadt eingeben');
        return false;
    }
    if(b.find('option:selected').val()!=''&&l.val()==''){
        searchForm.find('input[name=search-location]').val('bitte Stadt eingeben');
        return false;
    }
    return true;
}

function bookmarkMe(url, title) {
		if (window.sidebar) { // Mozilla Firefox Bookmark
			window.sidebar.addPanel(title, url,"");
		} else if( window.external ) { // IE Favorite
			window.external.AddFavorite( url, title); }
		else if(window.opera && window.print) { // Opera Hotlist
			return true; }
}
