Event.observe(window, 'load', function() {
	$$('a[href="#"]').each(function (element) {
		if (element.up().hasClassName('expander') || element.rel.length > 0)
			return;
		element.addClassName('notimplemented');
		element.observe('click', function(event) {
			//alert('This functionality has not been implemented in the prototype. It will be part of the actual Central Version.');
			event.stop();
		});
	});
	
	$$('form:not([action])').each(function (form) {
		form.observe('submit', function(event) {
			//alert('This functionality has not been implemented in the prototype. It will be part of the actual Central Version.');
			event.stop();
		});
	});
	
	$$('.expander a').each(function (element) {
		element.observe('click', function(event) {
			var expander = event.element().up();
			if (expander.hasClassName('collapsed')) {
				new Effect.BlindDown(expander.next(), {duration: 0.5});
				expander.removeClassName('collapsed');
			} else {
				new Effect.BlindUp(expander.next(), {duration: 0.5});
				expander.addClassName('collapsed');
			}
			
			event.stop();
		});
	});
	
	$$('a[rel="facebox"]').each(function (element) {
		Facebox.facebox(element);
	});

	if (Prototype.Browser.IE) {
		// Workaround for IE6 not supporting :hover on anything other than <a>
		var menuitems = $$('#main-nav > li:not([class~=search])');
		menuitems.each(function (element) {
			element.observe('mouseover', function(event) {
				menuitems.invoke('removeClassName', 'hover');
				element.addClassName('hover');
			});
			element.observe('mouseout', function(event) {
				element.removeClassName('hover');
			});
		});
	}
});

FocusObserver = Class.create({
	initialize: function(element, defaultValue) {
		this.element = $(element);
		this.defaultValue = defaultValue;
		
		Event.observe(this.element, 'blur', this.onBlurEvent.bind(this));
		Event.observe(this.element, 'focus', this.onFocusEvent.bind(this));
	},

	onBlurEvent: function() {
		if (this.element.getValue() == '')
			this.element.value = this.defaultValue;
	},

	onFocusEvent: function() {
		if (this.element.getValue() == this.defaultValue)
			this.element.clear();
		else
			this.element.activate();
	}
});

var Map = {
	initializeMap: function() {
		this.map = new GMap2($('map'));
		this.map.setCenter(new GLatLng(0,0));
		this.map.addControl(new GSmallMapControl());
		this.map.addControl(new GMapTypeControl());
		this.map.enableScrollWheelZoom();
		Event.observe($('map'), 'DOMMouseScroll', function(event) {
			event.stop();
		});
		
		this.baseIcon = new GIcon();
		this.baseIcon.image = "http://www.google.com/mapfiles/gadget/markerSmall80.png";
		this.baseIcon.shadow = "http://www.google.com/mapfiles/gadget/shadow50Small80.png";
		this.baseIcon.iconSize = new GSize(16, 27);
	  this.baseIcon.shadowSize = new GSize(30, 28);
	  this.baseIcon.iconAnchor = new GPoint(8, 27);
	  this.baseIcon.infoWindowAnchor = new GPoint(5, 1);

		this.letteredIcons = new Array();
	  for (var i = 0; i < 20; i++) {
	    var icon = new GIcon(this.baseIcon);
	    var iconImageKey =
	    icon.image = "http://www.google.com/mapfiles/gadget/letters/marker" +
	                      String.fromCharCode(65+i) + ".png";
	    this.letteredIcons[i] = icon;
	  }

		this.locations = new Array();
		this.bounds = new GLatLngBounds();
	},
	
	addLocation: function(loc) {
		loc= $H(loc);

		var marker = new GMarker(new GLatLng(loc.get('lat'), loc.get('lng')), {
			icon: this.letteredIcons[this.locations.size()],
			title: loc.get('title')
		});
		var job_id = 'job_' + this.locations.size();
		
		this.locations.push(marker);
		
		GEvent.addListener(marker, 'click', function() {
			marker.openInfoWindow($('result_'+loc.get('id')).innerHTML, {maxWidth: '400'});
			marker.originalImage = marker.getIcon().image;
			marker.setImage('/images/marker-highlight.png');
			$('job_'+loc.get('id')).addClassName('highlight');
		});
		GEvent.addListener(marker, 'mouseover', function() {
			marker.originalImage = marker.getIcon().image;
			marker.setImage('/images/marker-highlight.png');
		});
		GEvent.addListener(marker, 'mouseout', function() {
			marker.setImage(marker.originalImage);
		});
		
		// Update map
		this.map.addOverlay(marker);
		this.bounds.extend(marker.getPoint());
		this.map.setZoom(Math.min(10, this.map.getBoundsZoomLevel(this.bounds)));
		this.map.setCenter(this.bounds.getCenter());
	}
};


document.onkeypress =  function(e)
{
    var key;
    if( typeof(window.event) != 'undefined' )
    {
        key = window.event.keyCode; 
    }
    else
    {
        key = e.which;
    }

    if ( key == 13 ) 
       return false;
}
	
	
function getElementPos(elementId) {
var ua = navigator.userAgent.toLowerCase();
var isOpera = (ua.indexOf('opera') != -1);
var isIE = (ua.indexOf('msie') != -1 && !isOpera); // not opera spoof
var el = document.getElementById(elementId);
if(el.parentNode === null || el.style.display == 'none') {
   return false;
}     
var parent = null;
var pos = [];    
var box;    
if(el.getBoundingClientRect)    //IE
{        
   box = el.getBoundingClientRect();
   var scrollTop = Math.max(document.documentElement.scrollTop, document.body.scrollTop);
   var scrollLeft = Math.max(document.documentElement.scrollLeft, document.body.scrollLeft);
   return {x:box.left + scrollLeft, y:box.top + scrollTop};
}else if(document.getBoxObjectFor)    // gecko   
{
   box = document.getBoxObjectFor(el);
   var borderLeft = (el.style.borderLeftWidth)?parseInt(el.style.borderLeftWidth):0;
   var borderTop = (el.style.borderTopWidth)?parseInt(el.style.borderTopWidth):0;
   pos = [box.x - borderLeft, box.y - borderTop];
} else    // safari & opera   
{
   pos = [el.offsetLeft, el.offsetTop];
   parent = el.offsetParent;    
   if (parent != el) {
    while (parent) {
   pos[0] += parent.offsetLeft;
   pos[1] += parent.offsetTop;
   parent = parent.offsetParent;
    }
   }  
   if (ua.indexOf('opera') != -1 || ( ua.indexOf('safari') != -1 && el.style.position == 'absolute' )) {
    pos[0] -= document.body.offsetLeft;
    pos[1] -= document.body.offsetTop;        
   }   
}             
if (el.parentNode) {
   parent = el.parentNode;
    } else {
   parent = null;
    }
while (parent && parent.tagName != 'BODY' && parent.tagName != 'HTML') { // account for any scrolled ancestors
   pos[0] -= parent.scrollLeft;
   pos[1] -= parent.scrollTop;
   if (parent.parentNode) {
    parent = parent.parentNode;
   } else {
    parent = null;
   }
}
return {x:pos[0], y:pos[1]};
}


function insertHtml(where, el, html){
    where = where.toLowerCase();
    if(el.insertAdjacentHTML){
        switch(where){
            case "beforebegin":
                el.insertAdjacentHTML('BeforeBegin', html);
                return el.previousSibling;
            case "afterbegin":
                el.insertAdjacentHTML('AfterBegin', html);
                return el.firstChild;
            case "beforeend":
                el.insertAdjacentHTML('BeforeEnd', html);
                return el.lastChild;
            case "afterend":
                el.insertAdjacentHTML('AfterEnd', html);
                return el.nextSibling;
        }
        throw 'Illegal insertion point -> "' + where + '"';
    }
    var range = el.ownerDocument.createRange();
    var frag;
    switch(where){
        case "beforebegin":
            range.setStartBefore(el);
            frag = range.createContextualFragment(html);
            el.parentNode.insertBefore(frag, el);
            return el.previousSibling;
        case "afterbegin":
            if(el.firstChild){
                range.setStartBefore(el.firstChild);
                frag = range.createContextualFragment(html);
                el.insertBefore(frag, el.firstChild);
                return el.firstChild;
            }else{
                el.innerHTML = html;
                return el.firstChild;
            }
        case "beforeend":
            if(el.lastChild){
                range.setStartAfter(el.lastChild);
                frag = range.createContextualFragment(html);
                el.appendChild(frag);
                return el.lastChild;
            }else{
                el.innerHTML = html;
                return el.lastChild;
            }
        case "afterend":
            range.setStartAfter(el);
            frag = range.createContextualFragment(html);
            el.parentNode.insertBefore(frag, el.nextSibling);
            return el.nextSibling;
    }
    throw 'Illegal insertion point -> "' + where + '"';
}

function openMail(uid) {
    var m = siter.GetMail(uid).value;
    window.location = "mailto:" + m;
 }
 
 function openMail2(mail) {
    var m = mail.replace("#^^","@");    // info#^^randstad.cn
    window.location = "mailto:" + m;
 }
 
