﻿var	addEvent = function( obj, type, fn ) {
	if (obj.addEventListener)
			obj.addEventListener(type, fn, false);
	else if (obj.attachEvent)
			obj.attachEvent('on' + type, function() { return fn.apply(obj, new Array(window.event));});
}


var website = function() {
	{	// Private functions
		var highlightActiveMenuItem, checkInputField, getQueryVariable;
		var initOnLoad;
		var initSearchBox,searchSubmit,initLoginBox;
		var initFormValidation;
		
		/* Disable enters - dotnet*/
		addEvent(document,"keydown",function(e) {
				if (!e) e=window.event;
				if (e.keyCode == 13){
					return false;
				}
		});
			
		initSearchBox = function( ) {
			
			var el = document.getElementById('txtContentSearch');
			addEvent(el,"keydown",function(e) {
				if (!e) e=window.event;
				if (e.keyCode == 13){
					searchSubmit();
			}
			} );
			var el = document.getElementById('btnContentSearch');
			addEvent(el,"click",searchSubmit);
			
		}
		$(".cycle").cycle({
				fx: 'fade',
				timeout: 3000,
				//delay: -3000,
				speed: 0
			});

		/* -- */
		searchSubmit = function() {
			searchTerm = encodeURIComponent(document.getElementById('txtContentSearch').value);
			var currentLocation = window.location.href ;
			if (searchTerm.length>1) {
			
				document.forms[0].onsubmit = function() { return false }
				var searchUrl = '/cms/showpage.aspx?id=14&search=';

				if (document.body.className =='ledennet') {
					searchUrl = '/cms/showpage.aspx?id=xxx&search=';
				}
				searchUrl += searchTerm;
				window.location.href =  searchUrl;
				return false;
			} else {

				alert('Voer een zoekterm van minstens twee tekens in');
				window.location.href  = currentLocation ;
			}
		}
		
		checkInputField = function( id, value ) {
			if (!document.getElementById(id))
				return;
			var el = document.getElementById(id).getElementsByTagName("input")[0];
			if (el.value == '') el.value = value;
			
			addEvent(el,"focus",function(){
				if (this.value == value) {
					this.value= '';
					this.className = "active";
				}
			});
			addEvent(el,"blur",function() {
				if (this.value == '') {
					this.value = value;
					this.className = "";
				}
			});
		}
		getQueryVariable = function ( variable ) {
			var query = window.location.search.substring(1);
			var vars = query.split("&");

		  for (var i=0;i<vars.length;i++) {
		    var pair = vars[i].split("=");
		    if (pair[0] == variable) {
		      return pair[1];
		    }
		  } 
		  return;
		} 
		
		highlightActiveMenuItem = function( id ) {
                                   var pageId;
                                   if ( !document.getElementById( id ) )
                                               return;
                                   
                                   pageId = getQueryVariable('id');
                                   
                                   var menu = document.getElementById( id).getElementsByTagName("a");

                                   for (var i=0,j=menu.length ; i<j ; i++)
                                   {
                                               if ( menu[i].href.match(/id=(\d+)/)[1] == pageId  )
                                               {
                                                           menu[i].className = "active";
                                                           if (menu[i].parentNode.parentNode.parentNode.tagName =="LI") {
                                                                       menu[i].parentNode.parentNode.parentNode.className="childactive";
                                                           }
                                                           break;
                                               }
                                   }
                        }


		
		

		
		showGotoMyProfile = function( id ) {
			if (!document.getElementById( id ))
				return;
			var el = document.getElementById( id );
			el.innerHTML = '<a id="text_loggedin_vervanging" href="\/cms\/showpage.aspx?id=58">Naar het Ledennet</a>';
			el.style.visibility = "visible";
		
		}
		
		initOnLoad = function(){
			highlightActiveMenuItem("subnavigatie");
			// document.forms[0].reset();
			checkInputField("zoek","Zoek");
			//initSearchBox();
			showGotoMyProfile('text_loggedin');
			checkInputField("input_container_username","Gebruikersnaam");
			checkInputField("input_container_password","WACHTWOORD");

			
		}
	}
	{	// Public functions
		return ( {
			onLoad : function() {
				addEvent(window,"load",initOnLoad);
			}
			,
			submitFormToSendmail : function( fn ) {
				var submitFormHasErrors = false;

				if (typeof fn == 'function') {
					submitFormHasErrors = fn();
				} 
				if (submitFormHasErrors == false ) {

				}
			}
		});
	}
}();
website.onLoad();


function getElementbyContainerId( element )
{
	if (!document.getElementById(element)) return;
	
	return document.getElementById(element).getElementsByTagName('input')[0];
}



