/**
 * @author swarnat
 * @version 2009.10.26
 */
    var gmarkers = [];
	function loadStelle(id) {
		containerLoadContent('/home/firmen/preview2.phtml?stellenid=' + id, '','inlinePlacement',false, function(text) {
			title = text.match(/<title>(.*)<\/title>/)
			
			document.getElementsByTagName('title')[0].innerHTML = title[1] + " - praktika.de";
		}, {trackUrl:'/praktikumsstelle/' + id});
	}
	function loadProfil(id) {
		containerLoadContent('/firmenprofil/0' + id + '/','','innerPlacement', false, function(text) {
			title = text.match(/<title>(.*)<\/title>/)
			
			document.getElementsByTagName('title')[0].innerHTML = title[1] + " - praktika.de";
		}, {trackUrl:'/firmenprofil/' + id, "cutBody_Post":true});
	}
	function loadAlleStellen(id) {
		containerLoadContent('/firmen/allestellen/0' + id + '/','','innerPlacement', false, function(text) {
			title = text.match(/<title>(.*)<\/title>/)
			
			document.getElementsByTagName('title')[0].innerHTML = title[1] + " - praktika.de";
		}, {trackUrl:'/alleStellen/' + id, "cutBody_Post":true});
	}
	function loadEmpfehlen(id) {
		smallbox.loadFrame('/firmen/empfehlen/0' + id + '/',{width:'600',height:'550'});
/*		containerLoadContent(,'','innerPlacement', "loadingScreen", function(text) {
			title = text.match(/<title>(.*)<\/title>/)
			
			document.getElementsByTagName('title')[0].innerHTML = title[1] + " - praktika.de";
		}, {trackUrl:'/empfehlen/' + id, "cutBody_Post":true});*/
	}
	
	function loadBewerbung(stellenID, firmenID) {
			var poststr = 'firmenid=' + firmenID + '&stellenid=' + stellenID;
			
			xhr(window.location.protocol + '//' + window.location.host + '/home/praktikanten/stelle_merken.phtml', poststr, function(text) {
				this.location.href = "/karriere/";				
			});		
	}
	
	function loadLogin(location, stellenID, firmenID){
		smallbox.loadLogin(function(text){
				if (text == "true") {
					loadBewerbung(this.stellenID, this.firmenID);
				}
		}.bind({
				stellenID: stellenID,
				firmenID: firmenID
		}));
	}
	
	function stelle_merken(firmenID, stellenID, taetigkeit) {
			var poststr = 'firmenid=' + firmenID + '&stellenid=' + stellenID;
			
			xhr(window.location.protocol + '//' + window.location.host + '/home/praktikanten/stelle_merken.phtml', poststr, function(text) {
				$('#merkzettelBox').css("display", '');

				if(bookmarked == true) {
					
					if(document.getElementById('mzEntry_' + this.stellenid) != undefined) {
						document.getElementById('mzEntry_' + this.stellenid).parentNode.removeChild(document.getElementById('mzEntry_' + this.stellenid));
					}
					$('#p_stelle_merken').attr("class", "show");
					$('#p_stelle_gemerkt').attr("class", "hide");
					// document.getElementById('stelleMerken').innerHTML = '<img class="icon" width="15" src="/styles/images/suche/merken.png" alt="Praktikumsstelle merken" />Stelle merken';
					bookmarked = false;
					
					
				} else {
					document.getElementById('merkzettelStellen').innerHTML = document.getElementById('merkzettelStellen').innerHTML + "<li id='mzEntry_" + this.stellenid + "'><a href='/home/firmen/preview2.phtml?stellenid="+this.stellenid+"' onclick=\"loadStelle("+this.stellenid+"); return false;\"  title='" + this.taetigkeit + "' onclick='top.scrollTo(0,0)'>"+this.taetigkeit+"</a></li>"
					$('#p_stelle_merken').attr("class", "hide");
					$('#p_stelle_gemerkt').attr("class", "show");

					// document.getElementById('stelleMerken').innerHTML = '<img class="icon" width="15" src="/styles/images/lebenslauf/ok.gif" alt="Praktikumsstelle merken" />Gemerkt';
					bookmarked = true;
				}
				// alert("TEST");
				
				if($('#noMZEntry') != undefined) $('#noMZEntry').css("display",'none');
				
				pageTracker._trackEvent('stellenanzeige', 'Stelle merken', 'Stelle ' + this.stellenid, this.stellenid);
			}.bind({stellenid:stellenID, taetigkeit:taetigkeit}));


			
			
			return false;		
	}
	
	  function createMarker(point,name,html) {
        var marker = new GMarker(point);

        var i = gmarkers.length;

        // The inactive version of the direction info

        GEvent.addListener(marker, "click", function() {
          marker.openInfoWindowHtml(html);
        });
        
        // save the info we need to use later for the side_bar
        gmarkers.push(marker);
        // add a line to the side_bar html
        return marker;
      }
	  	

/*

        //<![CDATA[
        
          var gmarkers = [];
          var htmls = [];
          // arrays to hold variants of the info window html with get direction forms open
          var to_htmls = [];
          var from_htmls = [];    
    	var map = new GMap2(document.getElementById("map"));
    	var geocoder = new GClientGeocoder();
    	
    	var gdir=new GDirections(map, document.getElementById("directions"));
    	
    	map.addControl(new GLargeMapControl());
    	map.addControl(new GMapTypeControl());
    	map.addMapType(G_HYBRID_MAP);
    	  
    	        var  point  =  new  GLatLng(<?=$lat ?>,<?=$lng ?>)
    	      	map.setCenter(point, 13);
    	        
    	        //var marker = new GMarker(point);
    	        //map.addOverlay(marker);
    	        //marker.openInfoWindowHtml("Firmenstandort");
    	        
                var marker = createMarker(point, "HIER", "<html><body style='font-family:Arial; font-size:14px;'>Einsatzort");
                map.addOverlay(marker);
                	        
    	        var gdir=new GDirections(map, document.getElementById("directions"));
    	        
    		      // === Array for decoding the failure codes ===
    		      var reasons=[];
    		      reasons[G_GEO_SUCCESS]            = "Success";
    		      reasons[G_GEO_MISSING_ADDRESS]    = "Missing Address: The address was either missing or had no value.";
    		      reasons[G_GEO_UNKNOWN_ADDRESS]    = "Unknown Address:  No corresponding geographic location could be found for the specified address.";
    		      reasons[G_GEO_UNAVAILABLE_ADDRESS]= "Unavailable Address:  The geocode for the given address cannot be returned due to legal or contractual reasons.";
    		      reasons[G_GEO_BAD_KEY]            = "Bad Key: The API key is either invalid or does not match the domain for which it was given";
    		      reasons[G_GEO_TOO_MANY_QUERIES]   = "Too Many Queries: The daily geocoding quota for this site has been exceeded.";
    		      reasons[G_GEO_SERVER_ERROR]       = "Server error: The geocoding request could not be successfully processed.";
    		      reasons[G_GEO_BAD_REQUEST]        = "A directions request could not be successfully parsed.";
    		      reasons[G_GEO_MISSING_QUERY]      = "No query was specified in the input.";
    		      reasons[G_GEO_UNKNOWN_DIRECTIONS] = "The GDirections object could not compute directions between the points.";
    		
    		      // === catch Directions errors ===
    		      GEvent.addListener(gdir, "error", function() {
    		        var code = gdir.getStatus().code;
    		        var reason="Code "+code;
    		        if (reasons[code]) {
    		          reason = reasons[code]
    		        } 
    		
    		        alert("Failed to obtain directions, "+reason);
    		      });	
    
          // A function to create the marker and set up the event window
          function createMarker(point,name,html) {
            var marker = new GMarker(point);
    
            var i = gmarkers.length;
    
            // The info window version with the "to here" form open
            to_htmls[i] = html + '<br>Directions: <b>To here<\/b> - <a href="javascript:fromhere(' + i + ')">From here<\/a>' +
               '<br>Start address:<form action="javascript:getDirections()">' +
               '<input type="text" SIZE=40 MAXLENGTH=40 name="saddr" id="saddr" value="" /><br>' +
               '<center><INPUT value="Get Directions" TYPE="SUBMIT" /></center><br>' +
               '<input type="hidden" id="daddr" value="'+name+"@"+ point.lat() + ',' + point.lng() + 
               '"/>';
            // The info window version with the "from here" form open
            from_htmls[i] = html + '<br>Directions: <a href="javascript:tohere(' + i + ')">To here<\/a> - <b>From here<\/b>' +
               '<br>End address:<form action="javascript:getDirections()">' +
               '<input type="text" SIZE=40 MAXLENGTH=40 name="daddr" id="daddr" value="" /><br>' +
               '<center><INPUT value="Get Directions" TYPE="SUBMIT" /></center><br>' +
               '<input type="hidden" id="saddr" value="'+name+"@"+ point.lat() + ',' + point.lng() +
               '"/>';
            // The inactive version of the direction info
            html = html + '<br><div style="font-size:12px; font-family:Arial;">Route berechnen: <a href="javascript:tohere('+i+')">Hierher<\/a> - <a href="javascript:fromhere('+i+')">Von hier<\/a></div>';
    
            GEvent.addListener(marker, "click", function() {
              marker.openInfoWindowHtml(html);
            });
            
            // save the info we need to use later for the side_bar
            gmarkers.push(marker);
            htmls[i] = html;
            // add a line to the side_bar html
            return marker;
          }
    
          // ===== request the directions =====
          function getDirections() {
            // ==== Set up the walk and avoid highways options ====
            var opts = {};
            // ==== set the start and end locations ====
            var saddr = document.getElementById("saddr").value
            var daddr = document.getElementById("daddr").value
            gdir.load("from: "+saddr+" to: "+daddr, opts);
          }
    
    
          // This function picks up the click and opens the corresponding info window
          function myclick(i) {
            gmarkers[i].openInfoWindowHtml(htmls[i]);
          }
    
          // functions that open the directions forms
          function tohere(i) {
            gmarkers[i].openInfoWindowHtml(to_htmls[i]);
          }
          function fromhere(i) {
            gmarkers[i].openInfoWindowHtml(from_htmls[i]);
          }	  
    	  
        //]]>
    
        */
