function confirmation(url,bericht) {
	var answer = confirm(bericht)
	if (answer){
		window.location = url;
	}
}

function glos(id, nolist) {
  var msg = window.open( DocRoot + 'know-how/glossary_popup.php?id=' + id + '&no_list=1',
                    'popup',
                    'toolbar=no,width=400,height=400,directories=no,resizable=yes,status=no,scrollbars=yes,menubar=no,location=no');
  msg.focus();
}

function bg(id) {
  var dialog = window.open( DocRoot + "home/bg_popup.php?id=" + id,
                       "popup",
                       "toolbar=no,scrollbars=yes,width=400,height=400,directories=no,resizable=yes,status=no,menubar=no,location=no");
  dialog.focus();
}


function disclaimer() {
	dialog = window.open("../about-us/disclaimer_popup.php?is_popup=1",
											 "popup",
											 "toolbar=no,scrollbars=yes,width=400,height=400,directories=no,resizable=yes,status=no,menubar=no,location=no");
	dialog.focus();
}

function privacy() {
	dialog = window.open("../about-us/privacy_rabomyride_popup.php?is_popup=1",
											 "popup",
											 "toolbar=no,scrollbars=yes,width=400,height=400,directories=no,resizable=yes,status=no,menubar=no,location=no");
	dialog.focus();
}

function glos(id, nolist) {
  msg = window.open(DocRoot +'know-how/glossary_popup.php?id=' + id + '&no_list=1',
                    'popup',
                    'toolbar=no,width=400,height=400,directories=no,resizable=yes,status=no,scrollbars=yes,menubar=no,location=no');
  msg.focus();
}

function exercise(id) {
  msg = window.open(DocRoot +'know-how/exercises_popup.php?id=' + id + '&is_popup=1',
                    'popup',
                    'toolbar=no,width=600,height=600,directories=no,resizable=yes,status=no,scrollbars=yes,menubar=no,location=no');
  msg.focus();
}

var t;

function emailCheck(str) {

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
			 return false
		}
		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
			 return false
		}
		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
				return false
		}
		 if (str.indexOf(at,(lat+1))!=-1){
				return false
		 }
		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
				return false
		 }
		 if (str.indexOf(dot,(lat+2))==-1){
				return false
		 }
		 if (str.indexOf(" ")!=-1){
				return false
		 }
 		 return true					
	}



function winOpen (adr, name, w, h, scr) {
	par = "left=" + Math.floor((screen.width-w)/2) + ",width=" + w;
	par += ",top=" + Math.floor((screen.height-h)/2) + ",height=" + h;
	par += ",scrollbars=" + (scr?"yes":"no");
	par += ",resizable=" + (scr?"yes":"no");
	par += ",status=no";
	return window.open (adr, name, par);
}

function setAlphaLo(element){
	var alpha = "0.55";
	element.firstChild.style.opacity = alpha;
	element.firstChild.style.htmlOpacity = alpha;
	element.firstChild.style.filter ='alpha(opacity=55)';
	element.firstChild.style.mozOpacity = alpha;
	if(document.getElementById('Beijing_name')){
	document.getElementById('Beijing_name').innerHTML=document.getElementById('Beijing_name').title;
	}
}

function setAlphaHi(element){
	var alpha = "1";
	element.firstChild.style.opacity = alpha;
	element.firstChild.style.htmlOpacity = alpha;
	element.firstChild.style.filter ='alpha(opacity=100)';
	element.firstChild.style.mozOpacity = alpha;
	if(document.getElementById('Beijing_name')){
	document.getElementById('Beijing_name').innerHTML= element.firstChild.title;
	}
}

function EventHandeler(element,functie,event,extra){
	if (!document.all){
		element.addEventListener(event, function(event) { functie(extra); }, false);
	}
	else{ 
		element.attachEvent('on'+event, function(event) { functie(extra); });
	}
}


function inputDate(field,evt){
	if (!evt) evt = window.event;
	charCode = (evt.which) ? evt.which : event.keyCode;
	fvalue = field.value;
if (((charCode > 47)&&(charCode < 59))||(charCode == 8)||((charCode > 37)&&(charCode < 59))||(charCode == 45)) {
	 if ((charCode > 47)&&(charCode < 59)) {
			if(fvalue.length == 2){
				if(fvalue>31){field.value=31;}
				field.value = field.value+'-';
			}
			if(fvalue.length == 5){
				if((fvalue[3]+fvalue[4])>12){field.value=fvalue[0]+fvalue[1]+'-12';}
				field.value = field.value+'-20';
			}
		if(fvalue.length == 10){
				if((fvalue[6]+fvalue[7]+fvalue[8]+fvalue[9])>2037){field.value=fvalue[0]+fvalue[1]+fvalue[2]+fvalue[3]+fvalue[4]+fvalue[5]+2037;}
				if((fvalue[6]+fvalue[7]+fvalue[8]+fvalue[9])<2000){field.value=fvalue[0]+fvalue[1]+fvalue[2]+fvalue[3]+fvalue[4]+fvalue[5]+2000;}
			}
			
		}
}
else{
	field.value = 'Alleen 0-9';
}
}

function getCookie(name) {
	var re = new RegExp(name + "=([^;]+)");
	var value = re.exec(document.cookie);
	return (value != null) ? unescape(value[1]) : null;
}

function UpdateFavorites( ){
	jQuery.getJSON( Map_Config.Url.FavRequest, [], function( Response ){

		document.getElementById( "MapWaypointList" ).innerHTML = Response.HTML;
		Route.Draw( Response.Routes, true, true, true );
		
	} );
}

function UpdateRecent( ){
	jQuery.getJSON( Map_Config.Url.RecentRequest, { Amount: 23 }, function( Response ){

		document.getElementById( "MapWaypointList" ).innerHTML = Response.HTML;
		Route.Draw( Response.Routes, true, true, true );

	} );
}

function getTarget(targetRef) {
	if(typeof targetRef == 'string') {
		targetRef = document.getElementById(targetRef);
	}
	return targetRef;
}

function exists(target) {
	var target = getTarget(target);
	if (target) return target;
	return false;
}

function isDefined(variable){
	return (typeof( variable ) == "undefined")? false : true;
}

function OnRouteItemOver( element ){
	element.parentNode.className = 'Up';
}

function OnRouteItemOut( element ){
	element.parentNode.className = '';
}

/* Logbook functions */
function showDay( day, mode ){
	mode = mode ? mode : "view";

	var infodiv = document.getElementById( 'LogbookInfo' );
	if ( infodiv ){
		jQuery.get( 'request_logbook.php', {day:day,mode:mode}, function(data){
			document.getElementById( 'LogbookInfo' ).innerHTML = data;
			UpdateWindowHeight();
		});
	} else {
		location.href = 'logbook.php?date=' + day;
	}
}

function showLogbookday( day ){
	location.href = '../home/logbook.php?date=' + day;
}

var WindowSizeUpdater = null;
function UpdateWindowHeight( ){
	if ( BaseHost ){
		var bd = document.getElementsByTagName( 'BODY' )[0];
		var h = bd.offsetHeight + 10;
		Set_Cookie( 'RaboMyRide_Height', h, 2, '/', BaseHost );
		clearInterval( WindowSizeUpdater );
		WindowSizeUpdater = setInterval( 'UpdateWindowHeight()', 500 );
	}
}

function LogbookIconInit( Nr, Active ){
	var icon = new GIcon();

	icon.shadow = null;
	
	if ( Nr < 10 ){
		Nr = '0' + Nr;
	}

	if ( Active == false ){
		icon.image = MediaRoot + 'logbook/blue' + '_' + Nr + '.png';
		icon.iconSize = new GSize( 28, 37 );
		icon.shadowSize = null;
		icon.iconAnchor = new GPoint( 14, 37 );
		icon.infoWindowAnchor = new GPoint( 14, 18 );
	} else {
		icon.image = MediaRoot + 'logbook/orange_' + Nr + '.png';
		icon.iconSize = new GSize( 42, 51 );
		icon.shadowSize = null;
		icon.iconAnchor = new GPoint( 21, 51 );
		icon.infoWindowAnchor = new GPoint( 21, 26 );
	}

	return icon;
}

function IsFramed( ){
	var IsFramed = true;
	try {
		IsFramed = top.location != document.location;
	} catch ( e ) {}
	return IsFramed;
}

function EmbedInFrame( baseFrame ){
	if ( IsFramed() == false ){
		location.href = DocRoot + 'home/escape_frame.php?return=' + escape( location.href );
	}
}

[].indexOf || (Array.prototype.indexOf = function(v){
	for(var i = this.length; i-- && this[i] !== v;);
	return i;
});

function SponsorStyleControl( input_value, control_id ){	
	this.InputValue = document.getElementById( input_value );

	this.Previous = document.getElementById( control_id + '_Previous' );
	this.Label = document.getElementById( control_id + '_Label' );
	this.Next = document.getElementById( control_id + '_Next' );

	var self = this;

	this.Previous.onclick = function(){
		self.Navigate( -1 );
	};

	this.Next.onclick = function(){
		self.Navigate( 1 );
	};

	this.div_Template = document.getElementById( 'Editor' );
	this.div_Style = document.getElementById( 'Style' );

}

SponsorStyleControl.prototype.Navigate = function( Direction ){
	var current_id = parseInt( this.InputValue.value );
	var Index = Styles_Keys.indexOf( current_id );	
	if ( Direction == 1 ){
		if ( Styles_Keys[ Index + 1 ] ){
			this.NavigateTo( Styles_Keys[ Index + 1 ] );
		} else {
			this.NavigateTo( Styles_Keys[ 0 ] );
		}		
	}	else {
		 if ( Styles_Keys[ Index - 1 ] ){
			this.NavigateTo( Styles_Keys[ Index - 1 ] );
		} else {
			this.NavigateTo( Styles_Keys[ Styles_Keys.length - 1 ] );
		}
	}
}

SponsorStyleControl.prototype.NavigateTo = function( id ){
	var Style = Styles[ id ];
	this.InputValue.value = id;
	this.Label.innerHTML = Styles[ id ].name;

	this.div_Template.className = 'Template Template_' + Style.template;
	this.div_Style.className = 'Style Style_' + Style.code;
}


var DoorLinker = {

	Count: function( id ){
		jQuery.get( DocRoot + 'home/linker.php', { id: id } );
	}

}

function SubmitForm( link, name, value ){
  var previous = link.previousSibling;
  while( previous !== null ){
    if ( previous.name == name ){
      previous.value = value;
      previous.click();
    }
    previous = previous.previousSibling;
  }
  return false;
}
