try{
	Event.observe(document, 'click', function(event) { 
		var el = Event.element(event); 
		
	
		if(el.getAttribute("Widget")){
			d = Event.findElement(event, 'DIV');
			if(d){
				for(var i=0; i<10; i++){
					try{
						if($('widget' + i).id == d.id){
							var className = ($('widget' + i).className).replace('-False', '');
							className = (className).replace('-True', '');
							$('widget' + i).className = className + '-True';
							$('explain' + i).className = 'Widget-Explain-True';
						}else{
							var className = ($('widget' + i).className).replace('-False', '');
							className = (className).replace('-True', '');
							$('widget' + i).className = className + '-False';
							$('explain' + i).className = 'Widget-Explain-False';
						}	
					}	
					
					catch(e){}
				}
			}
		}
	});
}
catch(e){}

function showImage(url){
	window.open(url, "image")
}


function uploaderStatusChanged( uploader ) { 
	if (uploader.isReady()) { 
		HL.ReLoadForJumpLoader();
	} 
} 


function Tr_RollOver(id){
	var t = $(id)
	if(String(t.className).toLowerCase() == "image-border-link"){

		var span = document.createElement("div");	

		span.id = "rollover"
		span.style.position = "absolute";

		span.style.width = t.offsetWidth + 2 + "px";
		span.style.height = t.offsetHeight + 2 + "px";
		span.style.lineHeight = t.offsetHeight + 2 + "px";
		

		span.className = "image-border-link-rollover";
		span.innerHTML = '<img src="/media/zoom.png" align="absmiddle" /> Click to Zoom';

		try{
			t.insertAdjacentElement("beforeBegin",span);	
		}catch(e){}
	}

	t.className = t.className + "-hover"
} 

function Tr_RollOut(id){
	var t = $(id)
	hover = new RegExp ("-hover", "g")
	t.className = t.className.replace(hover,"")
	if(t.className == "image-border-link"){
		try{
			r = $("rollover")
			r.innerHTML = ''
			r.removeNode()
		}
		catch(e){}
	}
}


var HL = function(){
	var activeMenu;	//checks what menu item (top), isactive
	var Form; //for validation of a form, the form object is stored here
	var elementCount; //counts the validated form elements in validation
	var Url; //for jumploader and form update
	var map = '';	
	var parkingColor = "#16520a";
	var noKiteColor = "#c70000";
	var KiteColor = "#0054c7";
	var directions = "";
	var isEditable = false;
	var CarrousselOver = false;
	

	return{
		StrEmpty: function(str){
			return ((String(str).toLowerCase() == "false") || (String(str).toLowerCase() == "undefined") || (str == "") || (String(str).toLowerCase() == String(null)));
		},
		
		KiteBanner: function(event){
			var e = $('kiteBanner');
			var x = event.offsetX?(event.offsetX):event.pageX - e.offsetLeft;
   			var y = event.offsetY?(event.offsetY):event.pageY - e.offsetTop;
			if((x > 128 && x < 471) && (y > 87 && y < 123)){
				document.location = "/"
				return false;
			}else{
				return true;
			}

	
		},
		checkClick: function(e){
			if(e.getAttribute("checked")){e.value = 'true'}else{e.value = 'false'}
		},
		GalleryOpenImage: function(e){
			window.open(HL.MediaBaseUrl + "large" + e.getAttribute("picUrl"), "popup");
		},
		
		GalleryShowPreview: function(e){
			//clicked on the gallery page. when clicked, the clicked photo will be shown as the big photo.
			//$("largePreview").src = '/mediabase/itemgallery/small' + e.picUrl;
			new Ajax.Updater("largePreviewDiv", '/gallery/' + e.getAttribute("itemid") + '/showimage/?picurl=' + e.getAttribute("picUrl") + '&ridername=' + e.RiderName + '&photographername=' + e.PhotographerName, {
			onSuccess: function(){
					$("largePreviewDiv").setAttribute("picUrl", e.getAttribute("picUrl"));
				}																													
			});
			
		},
		showImage: function(e){
			
			//e = event.srcElement;
			var src = String(e.getAttribute("src")).replace("small", "large");
			window.open(src);
		},
		Tr_RollOut: function(){
			try{
				var t = $("rollover");
				t.parentNode.removeChild(t);
			}catch(e){}
		},
		Tr_RollOver: function(e){
			//if($("rollover")){
			//	var t = $("rollover");
			//	t.parentNode.removeChild(t);
			//}
			if(String(e.className).toLowerCase() == "image-border-link"){
				var span = document.createElement("div");	
		
				span.id = "rollover"
				span.style.position = "absolute";
				span.style.width = e.offsetWidth + 2 + "px";
				//span.style.left = e.offsetLeft + "px";
				//span.style.top = e.offsetTop + "px";
				span.style.height = e.offsetHeight + 2 + "px";
				span.style.lineHeight = e.offsetHeight + 2 + "px";
				span.className = "Image-Border-Link-rollover";
				span.innerHTML = '<img src="/media/zoom.png" align="absmiddle" /> Click to Zoom';
				e.insertAdjacentElement("beforeBegin",span);	

				
				//e.parentNode.insertBefore(span, e); 
				span.setAttribute("src", e.getAttribute("src"));
				//span.onclick = function() {HL.showImage(e)} ; 
				//span.onmouseout = function() {HL.Tr_RollOut(e)} ; 

			}
		},
		SetTagImage: function(e){
			$("SetTagImage").innerHTML = '<img src="/media/tag/' + e.getAttribute("picname") + '.jpg" />'; 
			$("SetTagImageName").value = e.getAttribute("picname"); 
		},
		
		NewRelatedSpot: function(itemid){
			var setspot = $("setspot");
			spotcounter ++;

			new Ajax.Updater("setspot", "/hotspot/" + itemid + "/edit/subscribe/setspot/?spotcounter=" + spotcounter, {
					insertion: Insertion.Bottom, evalScripts: true,
					onSuccess: function(){
						HL.countRelatedSpotsCosts();	
					}
			})
			
			
		},
		
		RemoveRelatedSpot: function(i){
			$("Spot" + i).remove();
			HL.countRelatedSpotsCosts();
		},
		
		
		SetRelatedSpotIsCommercial: function(id, bit){
			if(!HL.StrEmpty(bit)){
				$("IsCommercial" + id + "-1").style.display = "block";	
				$("IsCommercial" + id + "-0").style.display = "none";	
			}else{
				$("IsCommercial" + id + "-0").style.display = "block";	
				$("IsCommercial" + id + "-1").style.display = "none";	
			}
			
			HL.countRelatedSpotsCosts();
		},
		
		countRelatedSpotsCosts: function(){
			var w = $("setspot").getElementsByClassName("Widget-True");
			var totalcosts = 0;
			
			
			for(var i=0; i<w.length; i++){
				var counter = w[i].getAttribute("spotcounter");
				var spotid = $("SpotId" + counter).getAttribute("value");
				//check if commercial or not
				for(j=0; j<document.add["IsCommercial" + counter].length; j++){ 
					if(document.add["IsCommercial" + counter][j].checked){ 
						iscommercial = document.add["IsCommercial" + counter][j].value; 
					} 
				}
				//check costs per month if it iscommercal = 1
				if(iscommercial == 1 && !HL.StrEmpty(spotid)){
					for(j=0; j<document.add["Months" + counter].length; j++){ 
						if(document.add["Months" + counter][j].checked){ 
							totalcosts += Number(document.add["Months" + counter][j].getAttribute("cost")); 
							$("Cost" + counter).value = Number(document.add["Months" + counter][j].getAttribute("cost")); 
						} 
					} 
				}else{
					
					cost = 0;	
				}
				
				$("spotcounter").value = counter;
			}
			
			$("TotalCosts").innerHTML = totalcosts
		},
		
		setLocal: function(itemid){
			new Ajax.Updater("locals", '/kitespot/' + itemid + '/setlocal/?q=' + Math.random(), {evalScripts:true});
		},
		
		RemoveSearchAgent: function(itemid){
			new Ajax.Request('/secondhand/' + itemid + '/delete/?q=' + Math.random(), 
				{evalScripts:true,
				onSuccess : function(){
						new Ajax.Updater("sidesec", "/secondhand/side/?UpdateStr=SecondHandItemRemovedTitle&q=" + Math.random())
					}
				});
		},
		
		CombineTags: function(e){
			var tagtype = e.getAttribute("tagtype");
			$(tagtype).innerHTML = e.getAttribute("tagname");
			$(tagtype + "TagId").value = e.value;
		},
		
		MM_jumpMenu: function(targ,selObj,restore){ 
  			eval("document.location='"+selObj.options[selObj.selectedIndex].value+"'");
  			if (restore) selObj.selectedIndex=0;
		},
		
		openUserPopup: function(username, id, itemid){

			var e = $(username + id);
			if(e.className == "User-Header-DropDown-false"){
				e.className = "User-Header-DropDown-true";
				e.innerHTML = 'loading...';
				
				if(HL.StrEmpty(itemid)){
					new Ajax.Updater(username + id, '/user/' + username + '/popup/?q=' + Math.random());
				}else{
					if(String(id).substr(0,4) == 'item'){
						new Ajax.Updater(username + id, '/itemarchive/?itemid=' + itemid + '&q=' + Math.random());
					}else{
						new Ajax.Updater(username + id, '/reactarchive/?reactid=' + itemid + '&q=' + Math.random());
					}
				}
			}else{
				e.className = "User-Header-DropDown-false";
				e.innerHTML = '';
			}
		},
		
		OpenWindow: function(url, width, height){
			HL.StrEmpty(width)? width = 400 : '';
			HL.StrEmpty(height)? height = 800 : '';
			window.open(url, 'Admin', "height=" + height + ",width=" + width + ",status=no,scrollbars=1,toolbar=no,menubar=no,location=no");
		},
		
		popupSideMenu : function(id, clicked){
			var d = $("side" + id);
			switch(id){
				case "com":
					var idname = "community";
					break;
				case "pol":
					var idname = "poll";
					break;
				case "sec":
					var idname = "secondhand";
					break;
				case "whois":
					var idname = "whoisonline";
					break;
				case "wla":
					var idname = "waterland";
					break;
				case "new":
					var idname = "news";
					break;
				case "spo":
					var idname = "kitespot";
					break;
			}
			
			if(!HL.StrEmpty(clicked)){
				//document.location = '/setside/?pagecode=' + id + '&value=0&q=' + Math.random()
				if(d.className == "Display-true"){
					d.className = "Display-false";	
					d.innerHTML = "loading..."
					$("button-" + id).className = "small-icon-1";
					new Ajax.Request('/setside/?pagecode=' + id + '&value=&q=' + Math.random());
				}else{
					d.className = "Display-true";	
					$("button-" + id).className = "small-icon-0";
					new Ajax.Updater('side' + id, '/' + idname + '/side/?q=' + Math.random());
					new Ajax.Request('/setside/?pagecode=' + id + '&value=1&q=' + Math.random());
				}
			}else{
				if(HL["LoginIs" + id]){
					d.className = "Display-true";
					$("button-" + id).className = "small-icon-0";
					new Ajax.Updater('side' + id, '/' + idname + '/side/?q=' + Math.random());
				}else{
					d.className = "Display-false";
					$("button-" + id).className = "small-icon-1";
					d.innerHTML = "loading..."
				}
			}
		},
		
		activateArchive: function(e, itemid){
			
			var f = document[e.id]["History" + e.id];
			var value;
			for(var i=0; i<f.length; i++){
				if(f[i].checked){
					value = f[i].value;	
				}
			}
			if(value){
				if(itemid){
					//document.location = "/itemarchive/editdata/?itemid=" + e.itemid + "&historyid=" + value + "&q=" + Math.random()
					new Ajax.Request("/itemarchive/editdata/?itemid=" + e.itemid + "&historyid=" + value + "&q=" + Math.random(),{
						onSuccess: function(transport){
							alert(transport.responseText)
							document.location = transport.responseText;	
						}																										  
					});
				}else{
					new Ajax.Request("/reactarchive/editdata/?reactid=" + e.reactid + "&historyid=" + value + "&q=" + Math.random(),{
						onSuccess: function(transport){
							document.location = transport.responseText;	
						}																										  
					});
				}
			}
		},
		
		openArchiveHistory : function(e){
			var v = e.getAttribute("value");
			var h = document[e.formid]["History" + e.formid];
			for(var i=0; i<h.length; i++){
				if(h[i].getAttribute("value") != v){
					$(h[i].value).style.display = "none";	
				}else{
					$(h[i].value).style.display = "block";	
				}	
			}
		},
		
		SpamStopInit: function(){
			if($('widget9')){
				try{
					new Ajax.Updater('widget9', '/spamstopper/');	
				}
				catch(e){}
			}
		},
		
		SelectTimeZone: function(){
			var tz = $("TimeZoneId");
			$("TZMapOver").style.paddingLeft = tz.options[tz.selectedIndex].getAttribute("mapleft") + "px";	
			$("TZMapOver").src = "/media/template/tz/" + tz.options[tz.selectedIndex].getAttribute("code") + ".png";		
		},
		
		sendAbuse: function(itemid){
			var url = $F("AbuseURL");
			var remark = $F("AbuseRemark");
			
			if(HL.StrEmpty(remark)){
				$("WrongAbuse").innerHTML = strTextRequired;
				$("iconAbuse").className = 'button-icon-false';
			}else{

				new Ajax.Request('/abuse/?remark=' + remark + '&URL=' + url + '&q=' + Math.random(), {
					onSuccess: function(transport){
						Element.remove($("AbusePopupBack"));
						Element.remove($("Abuse"));
						
						new HLWindow({
							id: 'Abuse',
							title: strReportAbuseTitle,
							width: 500,
							height: 250,
							top: Element.positionedOffset($(itemid))[1]-5,
							closable : 1,
							html: strThankYouAbuseAlert
						});
		
					},
					onFailure: function(){
						Element.remove($("AbusePopupBack"));
						Element.remove($("Abuse"));
						
						new HLWindow({
							id: 'Abuse',
							title: strReportAbuseTitle,
							width: 500,
							height: 250,
							top: Element.positionedOffset($(itemid))[1]-5,
							closable : 1,
							html: strFailureAbuseAlert
						});
					}
				})

			}
		},
		
		reportAbuse: function(url, itemid){
			
			var str = '<form name="AbuseForm">';
				str += '<table>';
					str += '<tr>';
						str += '<td>';
							str += '<input type="hidden" id="AbuseURL" name="AbuseURL" value="' + url + '" />';
							str += strAbuseText
						str += '</td>';
					str += '</tr>';
					str += '<tr>';
						str += '<td>';
							str += '<span widget="true" class="button-icon-empty" id="iconAbuse">&nbsp;</span>';
							str += '<span widget="true" class="wrong" id="WrongAbuse"></span><br/>';
							str += '<textarea id="AbuseRemark" name="AbuseRemark" code="ReqText" style="width:480px; height:100px;"></textarea>';
						str += '</td>';
					str += '</tr>';
					str += '<tr>';
						str += '<td style="text-align:right;">';
							str += '<a class="light-button" href="javascript:HL.sendAbuse(' + "'" + itemid + "'" + ')">';
								str += '<span class="button-icon-true">&nbsp;</span>';
								str += strReportAbuse;
							str += '</a>';
						str += '</td>';
					str += '</tr>';
				str += '</table>';
			str += '</form>';
			
			new HLWindow({
					id: 'Abuse',
					title: strReportAbuseTitle,
					width: 500,
					height: 250,
					top: Element.positionedOffset($(itemid))[1]-5,
					closable : 1,
					html: str
				});
			
			
	
			
			/*
			
			*/
		},	
		setKudo: function(id, qc, direction, pagecode){
			//check if the kudos is given to a reaction or an item
			if(qc == 'react'){
				var div = "KudoCountReact" + id;
			}else{
				var div = "KudoCountItem" + id;
			}
			
			//document.location = '/setkudo/?itemid=' + id + '&qc=' + qc + '&direction=' + direction + '&pagecode=' + pagecode + '&q=' + Math.random()
			
			new Ajax.Request('/setkudo/?itemid=' + id + '&qc=' + qc + '&direction=' + direction + '&pagecode=' + pagecode + '&q=' + Math.random(),{
				onSuccess: function(transport){
							var a = String(transport.responseText).split(",");
							//a[0] : text
							//a[1] : kudo number
							if(!HL.StrEmpty(a[1])){
								var kudoColor = '0';
								if(a[1] < 0){kudoColor = '-1';}
								if(a[1] > 0){kudoColor = '1';}
								if(a[1] > 2){kudoColor = '2';}
								$(div).className = "User-Header-Kudos-" + kudoColor;
								$(div).innerHTML = a[1];
							}else{
								alert(a[0]);	
							}
						}
																																						
			})
		},
		initTopMenu: function(code){
			
			
			
			var e = $("Menu" + code);
			var code = code;
			if(HL.StrEmpty(e)){
				var code = 'new';
				var e = $("Menu" + code);
			}
				
				HL.activeMenu = $("Menu" + code);
				$("MenuRollOver").style.display = 'block';
				$("MenuRollOver").style.width = e.offsetWidth -10 + 'px';
				$("MenuRollOver").style.left = (e.offsetLeft + $("MenuBar").offsetLeft - $("Container").offsetLeft) + 'px';	
				$("MenuRollOver").innerHTML = e.innerHTML;
				$("SubMenu" + code).style.display = "block";
			
		
			//on the frontpage start right side
			try{
				new Ajax.Updater('SideMenu', '/sidemenu/?pagecode=' + HL.PageCode, {insertion: Insertion.Bottom});
				HL.Carroussel(1, 0);
				HL.popupSideMenu('com');
				HL.popupSideMenu('pol');
				HL.popupSideMenu('whois');
				
				
				
				HL.popupSideMenu('new');
				HL.popupSideMenu('spo');
				
				HL.popupSideMenu('sec');
				HL.popupSideMenu('wla');
				
			}
			catch(error){
				
			}
			
			if($("map")){
				HL.initGoogleMap(m);
			}
		},
		
		Carroussel: function(v){
			if(!CarrousselOver){
				var counter = $("CarrouselCounter").getAttribute("value");
				for(var i=1; i<=counter;i++){
					if(i == v){
						$("CarrouselDiv" + i).style.display = "block";	
						$("CarrouselTab" + i).className = "Carrousel-Tab-block";	
					}else{
						$("CarrouselDiv" + i).style.display = "none";	
						$("CarrouselTab" + i).className = "Carrousel-Tab-none";	
					}	
				}
				v++;
				v > counter ? v = 1 : '';
				if(!CarrousselOver){
					
				}
			}
			
			window.setTimeout("HL.Carroussel(" + v + ")", 10000);
		}, 
		
		CarrousselIn : function(v){
			CarrousselOver = true;
			var counter = $("CarrouselCounter").value;
			for(var i=1; i<=counter;i++){
				if(i == v){
					$("CarrouselDiv" + i).style.display = "block";	
					$("CarrouselTab" + i).className = "Carrousel-Tab-block";	
				}else{
					$("CarrouselDiv" + i).style.display = "none";	
					$("CarrouselTab" + i).className = "Carrousel-Tab-none";	
				}	
			}

			
		},

		
		CarrousselOut : function(v){
			CarrousselOver = false;
			//HL.Carroussel(v);
			
		},

		TopMenuRollOver: function(e){
			if(HL.activeMenu){
				$("Sub" + HL.activeMenu.id).style.display = "none";
				
				e.style.left = - Number(e.offsetWidth) + "px";
			$("MenuRollOver").style.display = 'block';
			$("MenuRollOver").style.width = e.offsetWidth -10 + 'px';
			$("MenuRollOver").style.left = (e.offsetLeft + $("MenuBar").offsetLeft - $("Container").offsetLeft) + 'px';
			$("MenuRollOver").innerHTML = e.innerHTML;
			$("Sub" + e.id).style.display = "block";
			HL.activeMenu = e;
			}

			
		},
		
		spotSetRemark: function(countrycode, itemid){
			new Ajax.Updater('Remark', '/kitespot/' + itemid + '/setremark/?c=' + countrycode);
		},
		
		spotSetForum: function(countrycode, itemid){
			new Ajax.Updater('Forum', '/kitespot/' + itemid + '/setforum/?c=' + countrycode);
		},
		
		spotSetReviews: function(countrycode, itemid){
			$("Reviews").innerHTML = 'loading...';
			new Ajax.Updater('Reviews', '/kitespot/' + itemid + '/setreviews/?c=' + countrycode);
		},
		

		
		showSideMenu: function(){
			for(var i=0; i<document.getElementsByTagName("object").length; i++){
				document.getElementsByTagName("object")[i].style.visibility= "hidden";
			}
			
			for(var i=0; i<document.getElementsByTagName("applet").length; i++){
				document.getElementsByTagName("applet")[i].style.visibility= "hidden";
			}
			
			$("SideBar").className = ($("SideBar").className).replace('-h', '');
			$("SideBar").className += '-h';
			$("SideBar").style.width = "270px";	
			$("SideMenu").style.maxWidth = "265px";	
		},
		
		hideSideMenu: function(){
			for(var i=0; i<document.getElementsByTagName("object").length; i++){
				document.getElementsByTagName("object")[i].style.visibility= "visible";
			}
			
			for(var i=0; i<document.getElementsByTagName("applet").length; i++){
				document.getElementsByTagName("applet")[i].style.visibility= "visible";
			}
			$("SideBar").className = ($("SideBar").className).replace('-h', '');
			$("SideBar").style.width = "143px";
			$("SideMenu").style.maxWidth = "138px";	
		},
		
		ElementOver: function(e){
			e.className = (e.className).replace('-h', '');
			e.className += '-h';
		},
		ElementOut: function(e){
			e.className = (e.className).replace('-h', '');
		},
		SearchFocus: function(e){
			if(e.getAttribute("text") == e.value){
				e.value = '';	
			}
		},
		
		SetValidationCSS : function(e, b){
				var cssreg = new RegExp ("-false", "g");
				if(!b){
					e.className = e.className.replace(cssreg,"");
					e.className += "-false";
				}else{
					e.className = e.className.replace(cssreg,"");
				}
		},
		
		getFormParameters: function(){
			var str = {};
			for(i=0; i<this.Form.elements.length; i++){
				var e = this.Form.elements[i];
				
				if(e.type == 'radio'){
					if(e.checked){
						str[e.name] = e.value;	
					}
				}else{
					str[e.name] = e.value;
				}
				
				//alert(e.name + ':' + e.value)

			}
			return str;
			
		
		},
		
		//function called, when jumploader is done with uploading photos
		ReLoadForJumpLoader: function(){
			window.location.href = this.Url; 
		},
		
		SubmitForm: function(att){
			//jumploader: als 1 = alleen return true; niet submitten.
			//url: deze url
			this.elementCount ++;
			
			if(this.elementCount >= this.Form.elements.length && att.jumploader){
				//als er fotos zijn geupload dan een andere submit dan met fotos
					//first edit the data
					//when data is edited, then upload the images.
					
					//check first if the minumupload quota is met.
					
					
					
					new Ajax.Request(this.Form.action, {
						parameters: this.getFormParameters(),
						onSuccess: function(t) {
							//document.JUpload.getUploaderConfig().uploadFormName
							var str = String(t.responseText).split(",")
							document.JUpload.getUploaderConfig().setUploadUrl(String(HL.DomainUrl + str[0]))
							HL.Url = str[1];
							if(document.JUpload.getUploader().getFileCount() > 0){
								document.JUpload.getUploader().startUpload();
							}else{
								window.location.href = str[1];
							}
						
						}
					})

				return false;
				
			}	
			
			if(this.elementCount >= this.Form.elements.length && !att.noSubmit){
				this.Form.submit()	
			}else{
				
			}
		},
		
		setRemark: function(f){
			if(f.myTextArea){
				var v = f.myTextArea.value;
				
				var reg = new RegExp('rel="nofollow"', 'g');
				v = v.replace(reg, '');
				var reg = new RegExp('rel=nofollow', 'g');
				v = v.replace(reg, '');
				var reg = new RegExp('target="_blank"', 'g');
				v = v.replace(reg, '');
				var reg = new RegExp('target=_blank', 'g');
				v = v.replace(reg, '');

				//check all <a> tags and put it rel="nofollow"
				var reg = new RegExp('(<a )[^>]*href\\s*=\\s*"[^"]*"[^>]*>', 'gi');
		
				try{
					var tags = v.match(reg);
					for(var i=0; i<tags.length; i++){
						v = v.replace(RegExp.$1, '<a&nbsp;rel="nofollow" target="_blank" ');
					}
				}catch(g){}
				//f.Remark.value = encodeURI(v);
				f.Remark.value = (v);
			}else{
				f.Remark.value = CKEDITOR.instances.Remark.getData()
			}
		},
		
		checkEmptyValue : function(str){
			//checked of een str ook echt niet leeg is.
			//een string is niet leeg als er echte text in staat
			//wel leeg als er alleen maar spaties in staan bijvoorbeeld
			str = unescape(str);
			var reg = new RegExp(' ', 'gi');
			str = str.replace(reg, '');
			var reg = new RegExp('&nbsp;', 'gi');
			str = str.replace(reg, '');
			var reg = new RegExp('null', 'gi');
			str = str.replace(reg, '');
			
			var reg = new RegExp("<p>", "g");
			str = str.replace(reg, "")
			var reg = new RegExp("<\/p>", "g")
			str = str.replace(reg, "")
			var reg = new RegExp("\/n", "g")
			str = str.replace(reg, "")
			return str;
		},
		
		Validation: function(form, att){
			HL.StrEmpty(att)? att = {} : '';
			this.elementCount = 0;

			this.Form = document[form];
	
			for(i=0; i<this.Form.elements.length; i++){
				var e = this.Form.elements[i];
				var code = e.getAttribute("code");
				var icon = $("icon" + e.name);
				var wrongtxt = $("Wrong" + e.name);
				switch(code){
					case "ReqUserName":
						var te = e;
						var ticon = icon;
						var twrong = wrongtxt;
						
						new Ajax.Request('/register/checkuser/?str=' + te.value + '&q=' + Math.random(),
									{method: 'POST', 
									contentType: 'text/html', 
									onSuccess: function(transport) {
										  var checkUser = transport.responseText;
											if(!HL.StrEmpty(checkUser)){
												HL.SetValidationCSS(te, 0);
												ticon.className = "button-icon-false";
												$("Wrong" + te.name).innerHTML = checkUser;
											}else{
												HL.SubmitForm(att);
												HL.SetValidationCSS(te, 1);
												ticon.className = "button-icon-true";
												$("Wrong" + te.name).innerHTML = '';
											}
										} 
		
									 }); 																									 	
					
						
						
						break;
					case "ReqImages":
						if(att.minimumUpload > document.JUpload.getUploader().getFileCount()){
							this.SetValidationCSS(e, 0);
							icon.className = "button-icon-false";
							new Ajax.Updater("Wrong" + e.name, '/getvarlan/?str=WrongAmountOfImagesSelectedText');
						}else{
							HL.SubmitForm(att);
							this.SetValidationCSS(e, 1);
							icon.className = "button-icon-true";
							wrongtxt.innerHTML = '';
						}
					
						break;
					case "ReqNumber":
						if((e.value != (e.value.match('\\d*\\.\\d{2}') || e.value.match('\\d*\\.\\d{1}')) && e.value != e.value.match('\\d*')) || HL.StrEmpty(e.value)){
							this.SetValidationCSS(e, 0);
							icon.className = "button-icon-false";
							new Ajax.Updater("Wrong" + e.name, '/getvarlan/?str=WrongNonReqNumberText');
						}else{
							HL.SubmitForm(att);
							this.SetValidationCSS(e, 1);
							icon.className = "button-icon-true";
							wrongtxt.innerHTML = '';
						}																						 	

						break;
					
					case "NonReqNumber":
						if((e.value != (e.value.match('\\d*\\.\\d{2}') || e.value.match('\\d*\\.\\d{1}')) && e.value != e.value.match('\\d*')) && !HL.StrEmpty(e.value)){
							this.SetValidationCSS(e, 0);
							icon.className = "button-icon-false";
							new Ajax.Updater("Wrong" + e.name, '/getvarlan/?str=WrongNonReqNumberText');
						}else{
							HL.SubmitForm(att);
							this.SetValidationCSS(e, 1);
							icon.className = "button-icon-true";
							wrongtxt.innerHTML = '';
						}																						 	

						break;
					
					case "ReqImage":
						vartempvalue = HL.checkEmptyValue(e.value);
						
						if(this.StrEmpty(vartempvalue)){
							this.SetValidationCSS(e, 0);
							icon.className = "button-icon-false";
							new Ajax.Updater("Wrong" + e.name, '/getvarlan/?str=WrongReqImageText');
						}else{
							HL.SubmitForm(att);
							this.SetValidationCSS(e, 1);
							icon.className = "button-icon-true";
							wrongtxt.innerHTML = '';
						}																						 	

						break;
						
					case "NonReqImage":
						vartempvalue = HL.checkEmptyValue(e.value);

							HL.SubmitForm(att);
							this.SetValidationCSS(e, 1);
							icon.className = "button-icon-true";
							wrongtxt.innerHTML = '';
												 	
							
						break;
					
					case "ReqText":
						vartempvalue = HL.checkEmptyValue(e.value);
						
						if(this.StrEmpty(vartempvalue)){
							this.SetValidationCSS(e, 0);
							icon.className = "button-icon-false";
							new Ajax.Updater("Wrong" + e.name, '/getvarlan/?str=WrongReqTextText');
						}else{
							HL.SubmitForm(att);
							this.SetValidationCSS(e, 1);
							icon.className = "button-icon-true";
							wrongtxt.innerHTML = '';
						}																						 	

						break;
						
					case "NonReqText":
							HL.SubmitForm(att);
							this.SetValidationCSS(e, 1);
							icon.className = "button-icon-true";
							wrongtxt.innerHTML = '';															 	

						break;
					
					case "ReqLink":
						e.value = String(e.value).replace("http://", "")
						if(this.StrEmpty(e.value)){
							this.SetValidationCSS(e, 0);
							icon.className = "button-icon-false";
							new Ajax.Updater("Wrong" + e.name, '/getvarlan/?str=WrongReqTextText');
						}else{
							HL.SubmitForm(att);
							this.SetValidationCSS(e, 1);
							icon.className = "button-icon-true";
							wrongtxt.innerHTML = '';
						}
			
						break;
					
					case "ReqTerms":	
						if(this.StrEmpty(e.checked)){
							this.SetValidationCSS(e, 0);
							icon.className = "button-icon-false";
							new Ajax.Updater("Wrong" + e.name, '/getvarlan/?str=WrongReqTermsText');
						}else{
							HL.SubmitForm(att);
							this.SetValidationCSS(e, 1);
							icon.className = "button-icon-true";
							wrongtxt.innerHTML = '';
						}
					
						break;
					
					case "NonReqLink":
						e.value = String(e.value).replace("http://", "")
							HL.SubmitForm(att);
							this.SetValidationCSS(e, 1);
							icon.className = "button-icon-true";
							wrongtxt.innerHTML = '';
						
			
						break;	
				
					case "ReqDropDown":
						if(this.StrEmpty(e.value)){
							this.SetValidationCSS(e, 0);
							icon.className = "button-icon-false";
							new Ajax.Updater("Wrong" + e.name, '/getvarlan/?str=WrongReqDropDownText');
						}else{
							HL.SubmitForm(att);
							this.SetValidationCSS(e, 1);
							icon.className = "button-icon-true";
							wrongtxt.innerHTML = '';
						}																						 	

						break;
						
					case "ReqRadio":
						var name = e.name;
						var checked = false;
						for(j=0; j<this.Form.elements.length; j++){
							if(this.Form.elements[j].name == name){
								if(this.Form.elements[j].checked == true){
									checked = true;
								}
							}
						}
						if(!checked){
							this.SetValidationCSS(e, 0);
							icon.className = "button-icon-false";
							new Ajax.Updater("Wrong" + e.name, '/getvarlan/?str=WrongNonReqRadioText');
						}else{
							HL.SubmitForm(att);
							this.SetValidationCSS(e, 1);
							icon.className = "button-icon-true";
							wrongtxt.innerHTML = '';
						}
							
						break;
				
					case "ReqDate":
						var codename = e.getAttribute("codename");
						var d = $(codename + "Date");
						var m = $(codename + "Month");
						var y = $(codename + "Year");
						var h = $(codename + "Hours");
						var mm = $(codename + "Minutes");
						
						var tempdate = new Date();
						var tempdate = new Date(tempdate.setMonth(Number(m.value-1)));
						var date = new Date(y.value,Number(m.value-1),d.value,h.value,mm.value);
						
						
						
						var valid = true;
						
						//if(tempdate.getMonth() != date.getMonth()){
						//	valid = false;
						//}

						
						if(date.getYear() < 1900){
							var yyyy = date.getYear() + 1900
							if(yyyy < 1900){
								valid = false;
							}
						}
						
	
						if(m.value > 12 || m.value <1){
							valid = false;
						}
						
		
						
						if(date.getHours() > 23 || date.getHours() < 0){
							valid = false;
						}
						
						if(date.getMinutes() > 59 || date.getMinutes() < 0){
							valid = false;
						}
						
						if(!valid){
							this.SetValidationCSS(d, 0);
							this.SetValidationCSS(m, 0);
							this.SetValidationCSS(y, 0);
							this.SetValidationCSS(h, 0);
							this.SetValidationCSS(mm, 0);
							icon.className = "button-icon-false";
							new Ajax.Updater("Wrong" + codename, '/getvarlan/?str=WrongNoValidDate');
						}else{
							HL.SubmitForm(att);
							this.SetValidationCSS(d, 1);
							this.SetValidationCSS(m, 1);
							this.SetValidationCSS(y, 1);
							this.SetValidationCSS(h, 1);
							this.SetValidationCSS(mm, 1);
							icon.className = "button-icon-true";
							$("Wrong" + codename).innerHTML = '';	
						}
						
						break;
						
					case "NonReqDate":
						var codename = e.getAttribute("codename");
						var d = $(codename + "Date");
						var m = $(codename + "Month");
						var y = $(codename + "Year");
						var h = $(codename + "Hours");
						var mm = $(codename + "Minutes");
						
						
						
						var tempdate = new Date();
						var tempdate = new Date(tempdate.setMonth(Number(m.value-1)));
						
						
						
						var valid = true;
						if(!HL.StrEmpty(d.value) && !HL.StrEmpty(m.value) && !HL.StrEmpty(y.value)){
							var date = new Date(y.value,Number(m.value-1),d.value,h.value,mm.value);

							
							//if(tempdate.getMonth() != date.getMonth()){
							//	valid = false;
							//}
							
						
							
							if(date.getYear() < 1900){
								var yyyy = date.getYear() + 1900
								if(yyyy < 1900){
									valid = false;
								}
							}
							
							if(m.value > 12 || m.value <1){
								valid = false;
							}
							
							if(date.getHours() > 23 || date.getHours() < 0){
								valid = false;
							}
							
							if(date.getMinutes() > 59 || date.getMinutes() < 0){
								valid = false;
							}
						}
						
						
						
						
						if(!valid){
							this.SetValidationCSS(d, 0);
							this.SetValidationCSS(m, 0);
							this.SetValidationCSS(y, 0);
							this.SetValidationCSS(h, 0);
							this.SetValidationCSS(mm, 0);
							icon.className = "button-icon-false";
							new Ajax.Updater("Wrong" + codename, '/getvarlan/?str=WrongNoValidDate');
						}else{
							
							HL.SubmitForm(att);
							this.SetValidationCSS(d, 1);
							this.SetValidationCSS(m, 1);
							this.SetValidationCSS(y, 1);
							this.SetValidationCSS(h, 1);
							this.SetValidationCSS(mm, 1);
							
							icon.className = "button-icon-true";
							
							$("Wrong" + codename).innerHTML = '';
							
						}
						
						break;
						
				
					case "ReqLogin":
						var username = this.Form.LoginUserName;
						var password = this.Form.LoginPassword;
						var wrongtxt = $("WrongLogin")
						if(this.StrEmpty(username.value) || this.StrEmpty(password.value)){
							this.SetValidationCSS(username, 0);
							this.SetValidationCSS(password, 0);
							new Ajax.Updater("WrongLogin", '/getvarlan/?str=WrongReqLoginText');
						}else{
							HL.SubmitForm(att);
							this.SetValidationCSS(username, 1);
							this.SetValidationCSS(password, 1);
							wrongtxt.innerHTML = '';	
						}
						
						break;
					case "ReqTextAreaV2":
						var tempvalue = HL.checkEmptyValue(e.value);
				
						if(this.StrEmpty(tempvalue)){
							this.SetValidationCSS(e, 0);
							icon.className = "button-icon-false";
							new Ajax.Updater("Wrong" + e.name, '/getvarlan/?str=WrongReqTextAreaText')
						}else{
							HL.SubmitForm(att);
							this.SetValidationCSS(e, 1);
							icon.className = "button-icon-true";
							wrongtxt.innerHTML = '';
						}
						break;
						
					case "NonReqTextAreaV2":

						var tempvalue = HL.checkEmptyValue(e.value);

							HL.SubmitForm(att);
							this.SetValidationCSS(e, 1);
							icon.className = "button-icon-true";
							wrongtxt.innerHTML = '';
						
						break;
	
					
					case "ReqTextAreaV3":
						var tempvalue = HL.checkEmptyValue(CKEDITOR.instances.Remark.getData());
						if(this.StrEmpty(tempvalue)){
							this.SetValidationCSS(e, 0);
							icon.className = "button-icon-false";
							new Ajax.Updater("Wrong" + e.name, '/getvarlan/?str=WrongReqTextAreaText')
						}else{
							HL.SubmitForm(att);
							this.SetValidationCSS(e, 1);
							icon.className = "button-icon-true";
							wrongtxt.innerHTML = '';
						}
						break;
						
					case "NonReqTextAreaV3":
						var tempvalue = HL.checkEmptyValue(CKEDITOR.instances.Remark.getData());
							HL.SubmitForm(att);
							this.SetValidationCSS(e, 1);
							icon.className = "button-icon-true";
							wrongtxt.innerHTML = '';
						
						break;	
			
					case "ReqPassWord":
						var p1 = e;
						var p2 = $(e.name + "2");
						if(String(p1.value).length < 6){
							this.SetValidationCSS(p1, 0);
							this.SetValidationCSS(p2, 0);
							icon.className = "button-icon-false";
							new Ajax.Updater("Wrong" + p1.name, '/getvarlan/?str=WrongPasswordsToShortText')
						}else{
							if(String(p1.value) != String(p1.value).match('[a-zA-Z0-9_\\-]*')){
								this.SetValidationCSS(p1, 0);
								this.SetValidationCSS(p2, 0);
								icon.className = "button-icon-false";
								new Ajax.Updater("Wrong" + p1.name, '/getvarlan/?str=WrongPasswordsInvalidCharactersText')
							}else{
								if(String(p1.value).toLowerCase() == 'undefined'
									|| String(p1.value).toLowerCase() == 'null'
									|| String(p1.value).toLowerCase() == '&nbsp;'
									|| String(p1.value).toLowerCase() == ' '
									){
										this.SetValidationCSS(p1, 0);
										this.SetValidationCSS(p2, 0);
										icon.className = "button-icon-false";
										new Ajax.Updater("Wrong" + p1.name, '/getvarlan/?str=WrongPasswordsNotAllowedText')
								}else{
									if(p1.value != p2.value){
										this.SetValidationCSS(p1, 0);
										this.SetValidationCSS(p2, 0);
										icon.className = "button-icon-false";
										new Ajax.Updater("Wrong" + p1.name, '/getvarlan/?str=WrongPasswordsNotEqualText')
									}else{
										HL.SubmitForm(att);
										this.SetValidationCSS(p1, 1);
										this.SetValidationCSS(p2, 1);
										icon.className = "button-icon-true";
										wrongtxt.innerHTML = '';
									}
								}
							}
						}
					
						break;
						
					case "NonReqPassWord":
						var p1 = e;
						var p2 = $(e.name + "2");
						
						if(!HL.StrEmpty(p1.value)){
							if(String(p1.value).length < 6){
								this.SetValidationCSS(p1, 0);
								this.SetValidationCSS(p2, 0);
								icon.className = "button-icon-false";
								new Ajax.Updater("Wrong" + p1.name, '/getvarlan/?str=WrongPasswordsToShortText')
							}else{
								if(String(p1.value) != String(p1.value).match('[a-zA-Z0-9_\\-]*')){
									this.SetValidationCSS(p1, 0);
									this.SetValidationCSS(p2, 0);
									icon.className = "button-icon-false";
									new Ajax.Updater("Wrong" + p1.name, '/getvarlan/?str=WrongPasswordsInvalidCharactersText')
								}else{
									if(String(p1.value).toLowerCase() == 'undefined'
										|| String(p1.value).toLowerCase() == 'null'
										|| String(p1.value).toLowerCase() == '&nbsp;'
										|| String(p1.value).toLowerCase() == ' '
										){
											this.SetValidationCSS(p1, 0);
											this.SetValidationCSS(p2, 0);
											icon.className = "button-icon-false";
											new Ajax.Updater("Wrong" + p1.name, '/getvarlan/?str=WrongPasswordsNotAllowedText')
									}else{
										if(p1.value != p2.value){
											this.SetValidationCSS(p1, 0);
											this.SetValidationCSS(p2, 0);
											icon.className = "button-icon-false";
											new Ajax.Updater("Wrong" + p1.name, '/getvarlan/?str=WrongPasswordsNotEqualText')
										}else{
											HL.SubmitForm(att);
											this.SetValidationCSS(p1, 1);
											this.SetValidationCSS(p2, 1);
											icon.className = "button-icon-true";
											wrongtxt.innerHTML = '';
										}
									}
								}
							}
						}else{
							HL.SubmitForm(att);
							this.SetValidationCSS(p1, 1);
							this.SetValidationCSS(p2, 1);
							icon.className = "button-icon-true";
							wrongtxt.innerHTML = '';
						}
					
						break;
						
					case "ReqTag":
						var n=0;
						var s;
						for(var l=1; l<=5;l++){
							var v = $("Tag" + l).value;
							if(!this.StrEmpty(v) && String(v).length >2){
								n++;
							}
							if(String(v).length <3 && String(v).length >0){
								s=true;
							}
						}
						
						
						
						if(s){
							this.SetValidationCSS($("Tag1"), 0);
							this.SetValidationCSS($("Tag2"), 0);
							this.SetValidationCSS($("Tag3"), 0);
							this.SetValidationCSS($("Tag4"), 0);
							this.SetValidationCSS($("Tag5"), 0);
							icon.className = "button-icon-false";
							new Ajax.Updater("Wrong" + e.name, '/getvarlan/?str=WrongReqTag2ShortText');
						}else{
							if(n>=2){
								HL.SubmitForm(att);
								this.SetValidationCSS($("Tag1"), 1);
								this.SetValidationCSS($("Tag2"), 1);
								this.SetValidationCSS($("Tag3"), 1);
								this.SetValidationCSS($("Tag4"), 1);
								this.SetValidationCSS($("Tag5"), 1);
								icon.className = "button-icon-true";
								wrongtxt.innerHTML = '';
							}else{
								this.SetValidationCSS($("Tag1"), 0);
								this.SetValidationCSS($("Tag2"), 0);
								this.SetValidationCSS($("Tag3"), 0);
								this.SetValidationCSS($("Tag4"), 0);
								this.SetValidationCSS($("Tag5"), 0);
								icon.className = "button-icon-false";
								new Ajax.Updater("Wrong" + e.name, '/getvarlan/?str=WrongReqTagNotEnoughText');
								
							}
						}
						
						
						
						
						break;
						

					case "ReqSpamStopper":
						var v = $("SpamCheck").value;
						if(v != String(e.value).toUpperCase()){
							this.SetValidationCSS(e, 0);
							icon.className = "button-icon-false";
							new Ajax.Updater("Wrong" + e.name, '/getvarlan/?str=WrongSpamText');
						}else{
							HL.SubmitForm(att);
							this.SetValidationCSS(e, 1);
							icon.className = "button-icon-true";
							wrongtxt.innerHTML = '';
						}
						break;
					case "ReqEmail":
						if(!e.value.match('[a-zA-Z0-9_\\.\\-]+@+[a-zA-Z0-9_\\.\\-]+\\.+[a-zA-Z0-9_\\.\\-]*')){
							this.SetValidationCSS(e, 0);
							icon.className = "button-icon-false";
							new Ajax.Updater("Wrong" + e.name, '/getvarlan/?str=WrongEmailText');
						}else{
							HL.SubmitForm(att);
							this.SetValidationCSS(e, 1);
							icon.className = "button-icon-true";
							wrongtxt.innerHTML = '';
						}
					
						break;	
					default:
						HL.SubmitForm(att);
						
				}
			}


			
		},
		
		
		SecondHandSetProductType: function(e){
			if(e.value == 1){
				$("KiteSize").style.display = "block";
			}else{
				$("KiteSize").style.display = "none";
			}
			
		},
		
		setNoFollowTag : function (){
		//haal eerst de attributes weg
			var reg = new RegExp('rel="nofollow"', 'g')
			$("myTextArea").value = $("myTextArea").value.replace(reg, '')
			var reg = new RegExp('rel=nofollow', 'g')
			$("myTextArea").value = $("myTextArea").value.replace(reg, '')
			var reg = new RegExp('target="_blank"', 'g')
			$("myTextArea").value = $("myTextArea").value.replace(reg, '')
			var reg = new RegExp('target=_blank', 'g')
			$("myTextArea").value = $("myTextArea").value.replace(reg, '')
	

	//check all <a> tags and put it rel="nofollow"
			var reg = new RegExp('(<a )[^>]*href\\s*=\\s*"[^"]*"[^>]*>', 'gi')
		
			try{
				tags = $("myTextArea").value.match(reg)
				
				for(var i=0; i<tags.length; i++){
					$("myTextArea").value = $("myTextArea").value.replace(RegExp.$1, '<a&nbsp;rel="nofollow" target="_blank" ')
				}
			}catch(f){}
			
			var reg = new RegExp('&nbsp;', 'gi')
			$("myTextArea").value = $("myTextArea").value.replace(reg, ' ')
			$("myTextArea").value = unescape($("myTextArea").value)

			
		},
		
		AddFilesUploadImages : function(){
			try{
				document.JUpload.js().clickAdd();
			}
			catch(e){
					alert('Wait for applet to load.');
				}
		},		
		StartUploadImages : function(formname){
			document.JUpload.js().toggleUpload();
		},
		
		CloseUpdateDiv : function(){
			$("Update-Div").remove();
		},
		AdminSelectAUser: function(){
			document.location = $("SelectAUser").options[$("SelectAUser").selectedIndex].value;
		},
		
		OpenEditor : function(id, siteid){
			window.open('/admin/siteadmin/translate/editor/?varid=' + id + '&tempsiteid=' + siteid, "editor", "height=500, width=1200, status=0, toolbar=0, resize=0, locationbar=0, scrollbars=1");
		},
		
		SetCenterCountry : function(c){
			map.setZoom(6);
			map.setCenter(new GLatLng(c.getAttribute("lat"),c.getAttribute("lng"))); 
			
			new Ajax.Updater("showspots", "/kitespot/country/" + c.getAttribute("countrycode") + "/?q=" + Math.random(), {evalScripts: true});
		},
			
		
		initGoogleMap : function(m){
	
			HL.StrEmpty(m.zoom)? m.zoom = 6 : '';
			
			var gMarkers = [];
			var pList = [];
			var POIMarkers = [];
			var newPolygon = null;
			var spotadmintype = '';
			
			
			map = new GMap2($("map"));
			if(!m.hidecontrols){
				map.addControl(new GMapTypeControl());
				map.addControl(new GSmallMapControl());
				map.addControl(new GScaleControl());
			}
	
			map.enableContinuousZoom();
			map.enableDoubleClickZoom(); 
			map.setCenter(new GLatLng(Number(m.lat), Number(m.lng)), Number(m.zoom));
			
			
			var countryicon = new GIcon();
			countryicon.shadow = "/media/template/map/country_s.png";
			countryicon.shadowSize = new GSize(23, 17);
			countryicon.iconSize = new GSize(16, 11);
			countryicon.iconAnchor = new GPoint(8, 5);
			
			var spoticon = new GIcon();
			//spoticon.shadow = "/media/template/map/country_s.png";
			//spoticon.shadowSize = new GSize(23, 17);
			spoticon.iconSize = new GSize(20, 20);
			spoticon.iconAnchor = new GPoint(10, 10);
			
			var weatherstationicon = new GIcon();
			weatherstationicon.image = "/media/template/map/weatherstation.png"; 
			weatherstationicon.iconSize = new GSize(6, 6);
			weatherstationicon.iconAnchor = new GPoint(3, 3);
			
			var POIicon = new GIcon();
			POIicon.shadow = "/media/template/map/poishadow.png";
			POIicon.shadowSize = new GSize(39, 29);
			POIicon.iconSize = new GSize(26, 26);
			POIicon.iconAnchor = new GPoint(13, 13);
		
			
		

			
			setWeatherStationIcon = function(mark, interactive){
				var p = new GLatLng(mark.lat, mark.lng);
				var icon = new GIcon(weatherstationicon);
				if(p.lat() != 0 || p.lng() != 0){
					var marker = new GMarker(p, icon);
					marker.id = mark.windfinderid;
					GEvent.addListener(marker,"mouseover", function(marker) {     
						$("weatherstation").innerHTML = mark.stationname;
					})
					GEvent.addListener(marker,"mouseout", function(marker) {     
						$("weatherstation").innerHTML = '';
					})
					
					
					
					if(!HL.StrEmpty(interactive)){
						
					
						GEvent.addListener(marker,"click", function(marker) {     
							$("WindFinderId").value = mark.windfinderid;
						
							for(var j=0; j<gMarkers.length; j++){
								if(gMarkers[j].id == $("WindFinderId").value){
									gMarkers[j].setImage("/media/template/map/weatherstation_s.png");	
								}else{
									gMarkers[j].setImage("/media/template/map/weatherstation.png");
								}	
							}
							
							
						})
					}
					
					gMarkers[gMarkers.length] = marker;
					map.addOverlay(marker);
					
					if(!HL.StrEmpty(interactive)){
						if(marker.id == $("WindFinderId").value){
							marker.setImage("/media/template/map/weatherstation_s.png");	
						}
					}
				}
			};
			
			setSpotIcon = function(m){

				var p = new GLatLng(m.lat, m.lng);
				var icon = new GIcon(spoticon);
				if(!HL.StrEmpty(m.winddirection)){
					icon.image = "/media/template/map/" + m.winddirection + "" + m.windcolor + ".png"; 
				}else{
					icon.image = "/media/template/map/0.png"; 
				}
				
				if(p.lat() != 0 || p.lng() != 0){
					var marker = new GMarker(p, icon);
					marker.name = m.name;
					marker.lat = m.lat;
					marker.lng = m.lng;
					marker.winddirection = m.winddirection;
					marker.windspeed = m.windspeed;
					marker.winddirectiontitle = m.winddirectiontitle;
					marker.windspeedtitle = m.windspeedtitle;
					marker.url = m.url;
					return marker;
				}
			};
			
			
			setPOIIcon = function(m){
				var p = new GLatLng(m.lat, m.lng);
				var icon = new GIcon(POIicon);
				icon.image = "/media/template/map/poi" + m.companytypeid + ".png"; 
				
				if(p.lat() != 0 || p.lng() != 0){
					var marker = new GMarker(p, icon);
					return marker;
				}else{
					var p = new GLatLng(0, 0);
					var marker = new GMarker(p, icon);
					return marker;	
				}
			};
			

			setCountryIcon = function(m){
				var p = new GLatLng(m.lat, m.lng);
				var icon = new GIcon(countryicon);
				if(p.lat() != 0 || p.lng() != 0){
					icon.image = "/media/flags/" + m.countrycode + ".gif";
					var marker = new GMarker(p, icon);
					marker.lat = m.lat;
					marker.lng = m.lng;
					marker.countrycode = m.countrycode;
					marker.countryname = m.countryname;
					return marker;
				}
			};
			
			
			function startDrawing(polygon) {
				map.addOverlay(polygon);
				polygon.enableDrawing();

				polygon.enableEditing({onEvent: "mouseover"});
				polygon.disableEditing({onEvent: "mouseout"});
				
								
				GEvent.addListener(polygon, "lineupdated", function() {
					str = '';
					for(var j=0; j<polygon.getVertexCount(); j++){
						p = polygon.getVertex(j);
						str += polygon.getVertex(j);
					}
					pList.push(polygon);
					$(spotadmintype).value = str;
					
				});
			};
			
			createPolygon = function(c){
				var tempArray = [];
				var pArray = c.split(")(");
					
				for(var j=0; j<pArray.length;j++){
					var reg = new RegExp("\\(", "g");
					pArray[j] = pArray[j].replace(reg, '');
					var reg = new RegExp("\\)", "g");
					pArray[j] = pArray[j].replace(reg, '');
					lArray = pArray[j].split(", ")
					point = new GLatLng(lArray[0], lArray[1]);
					if(!HL.StrEmpty(lArray[0]) && !HL.StrEmpty(lArray[1])){
						tempArray.push(point); 
					}
					
				}
				return tempArray;
			};
			
			
			
			createSpotAdminControls = function(){
				function ResetControl(){}
					ResetControl.prototype = new GControl();
					ResetControl.prototype.initialize = function(map){
						var container = document.createElement("div");  
						var resetButton = document.createElement("div");  
						this.setButtonStyle_(resetButton);  
						container.appendChild(resetButton);  
						resetButton.appendChild(document.createTextNode("Reset"));
						
						GEvent.addDomListener(resetButton, "click", function() {
							map.removeOverlay(newPolygon);
							pList = [];
							newPolygon = new GPolygon(pList, parkingColor, 2, 0.7, parkingColor, 0.2);
						});
						
						var editButton = document.createElement("div");  
						this.setButtonStyle_(editButton);  
						container.appendChild(editButton);  
						editButton.appendChild(document.createTextNode("Edit"));
						
						GEvent.addDomListener(editButton, "click", function() {
							startDrawing(newPolygon);
						});
						
						map.getContainer().appendChild(container);  
						return container;
					}
					
					ResetControl.prototype.getDefaultPosition = function(){  
						return new GControlPosition(G_ANCHOR_BOTTOM_LEFT, new GSize(7, 7));
					}
					
					ResetControl.prototype.setButtonStyle_ = function(button){
						button.style.textDecoration = "underline";  
						button.style.color = "#0000cc";  
						button.style.backgroundColor = "white";  
						button.style.font = "small Arial";  
						button.style.border = "1px solid black";  
						button.style.padding = "2px";  
						button.style.marginBottom = "3px";  
						button.style.textAlign = "center";  
						button.style.width = "6em";  
						button.style.cursor = "pointer";
					}
					
					map.addControl(new ResetControl());
				
			};
			
			
			MaphandleErrors = function(){
				
				if(directions.getStatus().code == G_GEO_UNKNOWN_ADDRESS){
					new Ajax.Updater("getStatus", "/getvarlan/?str=AddressNotFoundTitle")
				}
				if(directions.getStatus().code == G_GEO_SERVER_ERROR){
					new Ajax.Updater("getStatus", "/getvarlan/?str=GeoServerErrorTitle")
				}
				if(directions.getStatus().code == G_GEO_MISSING_QUERY){
					new Ajax.Updater("getStatus", "/getvarlan/?str=GeoMissingQueryTitle")
				}
				if(directions.getStatus().code == G_GEO_BAD_KEY){
					new Ajax.Updater("getStatus", "/getvarlan/?str=GeoBadKeyTitle")
				}
				if(directions.getStatus().code == G_GEO_BAD_REQUEST){
					new Ajax.Updater("getStatus", "/getvarlan/?str=GeoBadRequestTitle")
				}
				if(directions.getStatus().code == G_GEO_UNAVAILABLE_ADDRESS){
					new Ajax.Updater("getStatus", "/getvarlan/?str=GeoUnavailableAddressTitle")
				}
				if(directions.getStatus().code == G_GEO_UNKNOWN_DIRECTIONS){
					new Ajax.Updater("getStatus", "/getvarlan/?str=GeoUnknownDirectionsTitle")
				}
				if(directions.getStatus().code == G_GEO_TOO_MANY_QUERIES ){
					new Ajax.Updater("getStatus", "/getvarlan/?str=GeoTooManyQueriesTitle")
				}
				if(directions.getStatus().code == 200 ){
					new Ajax.Updater("getStatus", "/getvarlan/?str=GeoSuccesTitle")
				}
				
				//$("getStatus").innerHTML += "Error code: " + directions.getStatus().code
			};

			
			setPOIs = function(){
				
				//set POI's which are visible
				var bounds = String(map.getBounds()).split(",");
				var reg1 = new RegExp('\\(', "g");
				var reg2 = new RegExp('\\)', "g");
				var reg3 = new RegExp(' ', "g");
				
				var s = bounds[0].replace(reg1, '').replace(reg2, '').replace(reg3, '');
				var w = bounds[1].replace(reg1, '').replace(reg2, '').replace(reg3, '');
				var n = bounds[2].replace(reg1, '').replace(reg2, '').replace(reg3, '');
				var e = bounds[3].replace(reg1, '').replace(reg2, '').replace(reg3, '');
				
				for(var i=0;i<POIMarkers.length;i++){
					map.removeOverlay(POIMarkers[i]);	
				}
				
				new Ajax.Request("/hotspot/selectall/?s=" + s + "&e=" + e + "&n=" + n + "&w=" + w, {
						method:"get",
						onSuccess: function(transport){
							var xml = transport.responseXML;
							var pois = xml.getElementsByTagName('poi');
							for(var i=0; i<pois.length; i++){
								var poi = [];

								m.companytypeid = pois[i].childNodes[0].firstChild.nodeValue;	
								m.lat = pois[i].childNodes[1].firstChild.nodeValue;	
								m.lng = pois[i].childNodes[2].firstChild.nodeValue;	
								marker = setPOIIcon(m);
								
								map.addOverlay(marker);
								
								POIMarkers[POIMarkers.length] = marker;
								
								
								
								
							}	
						}	
					});
				
			};

			switch(String(m.scripttype).toLowerCase()){
				case "adminweathermap":
				
					map.clearOverlays();
					
					map.setZoom(10);
					marker = setSpotIcon(m);
					map.addOverlay(marker);
					
					new Ajax.Request("/xml/markers.xml", {method: 'get',
					onSuccess: function(transport){
							var xml = transport.responseXML;
							
							var markers = xml.getElementsByTagName("marker");
							//for(var i=0; i<10; i++){
							for(var i=0; i<markers.length; i++){
								var m = [];
								m.stationname = markers[i].getAttribute("name");	
								m.windfinderid = markers[i].getAttribute("id");	
								m.lat = markers[i].getAttribute("lat");	
								m.lng = markers[i].getAttribute("lng");	
								setWeatherStationIcon(m, true);
								
								
							}
						}														
					});
					
					break;
					
				case "smallspotmap":
					map.clearOverlays();
					marker = setSpotIcon(m);
					map.addOverlay(marker);
					
					GEvent.addListener(map,"click", function(marker) {     
						HL.OpenWindow("/kitespot/" + m.itemid + "/largemap/", 800, 600);
					})
					
					break;
				
				case "spotdefault":
					var zoomSpots = 5; //from what zoom level the spots are visible
					
					setSpots = function(){
						
						var bounds = String(map.getBounds()).split(",");
						var reg1 = new RegExp('\\(', "g");
						var reg2 = new RegExp('\\)', "g");
						var reg3 = new RegExp(' ', "g");
						
						var s = bounds[0].replace(reg1, '').replace(reg2, '').replace(reg3, '');
						var w = bounds[1].replace(reg1, '').replace(reg2, '').replace(reg3, '');
						var n = bounds[2].replace(reg1, '').replace(reg2, '').replace(reg3, '');
						var e = bounds[3].replace(reg1, '').replace(reg2, '').replace(reg3, '');

						

						new Ajax.Request("/kitespot/selectbycountry/xml/?s=" + s + "&e=" + e + "&n=" + n + "&w=" + w + '&q=' + Math.random(), {
								onSuccess: function(transport){
									map.clearOverlays();
									var xml = transport.responseXML;
									var spots = xml.getElementsByTagName('spot');
									for(var i=0; i<spots.length; i++){
										var spot = {};
										
										spot.name = spots[i].childNodes[0].firstChild.nodeValue;
										spot.windspeedtitle = spots[i].childNodes[8].firstChild.nodeValue;
										spot.winddirectiontitle = spots[i].childNodes[9].firstChild.nodeValue;
										
										
										spot.lat = spots[i].childNodes[1].firstChild.nodeValue;	
										spot.lng = spots[i].childNodes[2].firstChild.nodeValue;	
										try{
											spot.winddirection = spots[i].childNodes[3].firstChild.nodeValue;	
										}
										catch(e){
											spot.winddirection = '_';	
										}
										try{
											spot.windspeed = spots[i].childNodes[4].firstChild.nodeValue;
										}
										catch(e){}
										try{
											spot.isoktokite = spots[i].childNodes[6].firstChild.nodeValue;
										}
										catch(e){
											spot.isoktokite = 0	
										}
										try{
											spot.windcolor = spots[i].childNodes[7].firstChild.nodeValue;	
										}
										catch(e){
											spot.windcolor = 0;	
										}
										try{
											spot.url = spots[i].childNodes[10].firstChild.nodeValue;
											
										}
										catch(e){}
										
										
										switch(String(spot.winddirection).toLowerCase()){
											case "n":
												spot.winddirection = 'n';
												break;
											case "nne":
												spot.winddirection = 'n';
												break;	
											case "ne":
												spot.winddirection = 'ne';
												break;	
											case "ene":
												spot.winddirection = 'ne';
												break;
											case "e":
												spot.winddirection = 'e';
												break;
											case "ese":
												spot.winddirection = 'e';
												break;
											case "se":
												spot.winddirection = 'se';
												break;
											case "sse":
												spot.winddirection = 'se';
												break;
											case "s":
												spot.winddirection = 's';
												break;
											case "ssw":
												spot.winddirection = 's';
												break;
											case "sw":
												spot.winddirection = 'sw';
												break;
											case "wsw":
												spot.winddirection = 'sw';
												break;
											case "w":
												spot.winddirection = 'w';
												break;
											case "wnw":
												spot.winddirection = 'w';
												break;
											case "nw":
												spot.winddirection = 'nw';
												break;
											case "nnw":
												spot.winddirection = 'nw';
												break;
											
											
										}
										
										
										var marker = setSpotIcon(spot);
										GEvent.addListener(marker,"mouseover", function(marker) {  
											if(!HL.StrEmpty(this.windspeed) && !HL.StrEmpty(this.winddirection)){												
												$("Spotname").innerHTML = this.name + ' (' + this.windspeedtitle + ': ' + this.windspeed + 'knts. ' +  this.winddirectiontitle + ': ' + String(this.winddirection).toUpperCase() + ')';
											}else{
												$("Spotname").innerHTML = this.name;
											}
										})
										
										GEvent.addListener(marker,"mouseout", function(marker) {  
											$("Spotname").innerHTML = "";
										})
										
										GEvent.addListener(marker,"click", function(marker) {  
											document.location = this.url;
										})
										map.addOverlay(marker);

									
									}									
								}
							});
									
					}
					
					setFlags = function(){
						if(oldzoom > zoomSpots || HL.StrEmpty(oldzoom)){
							map.clearOverlays();
							new Ajax.Request("/kitespot/activecountries/xml/?q=" + Math.random(), {
								onSuccess: function(transport){
									var xml = transport.responseXML;
									var countries = xml.getElementsByTagName('country');
									for(var i=0; i<countries.length; i++){
										var m = [];
										m.countrycode = countries[i].childNodes[0].firstChild.nodeValue;	
										m.countryname = countries[i].childNodes[1].firstChild.nodeValue;	
										m.lat = countries[i].childNodes[2].firstChild.nodeValue;	
										m.lng = countries[i].childNodes[3].firstChild.nodeValue;	
										marker = setCountryIcon(m);
										
										GEvent.addListener(marker,"click", function(marker) {     
											oldzoom = zoomSpots;
											map.setZoom(zoomSpots + 1);
											map.setCenter(new GLatLng(this.lat,this.lng)); 
									
											new Ajax.Updater("showspots", "/kitespot/country/" + this.countrycode + "/?q=" + Math.random(), {evalScripts: true});
										})
										
										map.addOverlay(marker);
									}
								}
							})
						}
					}
										
							var newzoom = map.getZoom();
							var oldzoom = '';
							
							
							setFlags();
						
							
							GEvent.addListener(map,"move", function() {
								var center = map.getCenter();  
							})
							
							GEvent.addListener(map,"moveend", function(marker) {
								oldzoom = newzoom;
								newzoom = map.getZoom();

								if(newzoom < zoomSpots + 1){
									setFlags();
								}else{
									setSpots();
								}
							})
							
																				
					
					break;
				
				case "largespotmap":
					map.addControl(new GMapTypeControl());
					//map.addControl(new GSmallMapControl());
					//map.addControl(new GScaleControl());
					map.clearOverlays();
					marker = setSpotIcon(m);
					map.addOverlay(marker);
					
					map.setMapType(G_HYBRID_MAP);
					
					var pList1 = createPolygon(m.parkingcoordinates);
					var newPolygon = new GPolygon(pList1, parkingColor, 2, 0.7, parkingColor, 0.2);
					map.addOverlay(newPolygon);
					
					var pList2 = createPolygon(m.nokitecoordinates);
					var newPolygon = new GPolygon(pList2, noKiteColor, 2, 0.7, noKiteColor, 0.2);
					map.addOverlay(newPolygon);
					
					var pList3 = createPolygon(m.kitecoordinates);
					var newPolygon = new GPolygon(pList3, KiteColor, 2, 0.7, KiteColor, 0.2);
					map.addOverlay(newPolygon);
					
					setPOIs();
					
					
					GEvent.addDomListener(map, "moveend", function() {
						setPOIs();											 
					});
					


					break;	
					
				case "adminparking":
					spotadmintype = "ParkingCoordinates";
					map.clearOverlays();
					marker = setSpotIcon(m);
					map.addOverlay(marker);
			
					pList = createPolygon(m.parkingcoordinates);
					createSpotAdminControls();
					
					newPolygon = new GPolygon(pList, parkingColor, 2, 0.7, parkingColor, 0.2);
					map.addOverlay(newPolygon);

					break;
					
				case "adminnokite":
					spotadmintype = "NoKiteCoordinates";
					map.clearOverlays();
					marker = setSpotIcon(m);
					map.addOverlay(marker);
			
					pList = createPolygon(m.nokitecoordinates);
					createSpotAdminControls();
					
					newPolygon = new GPolygon(pList, noKiteColor, 2, 0.7, noKiteColor, 0.2);
					map.addOverlay(newPolygon);

					break;	
					
				case "adminkite":
					spotadmintype = "KiteCoordinates";
					map.clearOverlays();
					marker = setSpotIcon(m);
					map.addOverlay(marker);
			
					pList = createPolygon(m.kitecoordinates);
					createSpotAdminControls();
					
					newPolygon = new GPolygon(pList, KiteColor, 2, 0.7, KiteColor, 0.2);
					map.addOverlay(newPolygon);

					break;	
					
				case "adminspot":
					map.clearOverlays();
					
					map.setZoom(10);
					if(!HL.StrEmpty(m.lat) && !HL.StrEmpty(m.lng)){
						marker = setSpotIcon(m);
						map.addOverlay(marker);
					}
					
					GEvent.addListener(map, "click", function(marker, point) {
						map.clearOverlays();
						m.lat = point.lat();
						m.lng = point.lng();
						marker = setSpotIcon(m);
						map.addOverlay(marker);
						
						
						
						$("lat").value = point.lat();
						$("lng").value = point.lng();		

					});
					break;
					
				case "adminpoi":
					map.clearOverlays();
					if(HL.StrEmpty(m.lat)){
						map.setCenter(new GLatLng(Number(m.countrylat), Number(m.countrylng)), Number(7));
					}
					
					var marker2 = setPOIIcon(m);
					map.addOverlay(marker2);
					
					GEvent.addListener(map, "click", function(marker, point) {
						map.clearOverlays();
						m.lat = point.lat();
						m.lng = point.lng();
						
						var marker = setPOIIcon(m);
						map.addOverlay(marker);
						
						$("Lat").value = point.lat();
						$("Lng").value = point.lng();										 
					});
					break;
					
				case "setcountryadmin":

					marker = setCountryIcon(m);
					map.addOverlay(marker);
					GEvent.addListener(map, "click", function(marker, point) {
						map.clearOverlays();
						m.lat = point.lat();
						m.lng = point.lng();
						marker = setCountryIcon(m);
						map.addOverlay(marker);
						$("Lat").value = point.lat();
						$("Lng").value = point.lng();										 
					});
					break;
				
				case "allcountriesadmin":
					map.clearOverlays();
					
					new Ajax.Request("/admin/kitespot/country/allxml/?q=" + Math.random(), {
					onSuccess: function(transport){
							var xml = transport.responseXML;
							var countries = xml.getElementsByTagName('country');
							for(var i=0; i<countries.length; i++){
								var m = [];
								m.countrycode = countries[i].childNodes[0].firstChild.nodeValue;	
								m.countryname = countries[i].childNodes[1].firstChild.nodeValue;	
								m.lat = countries[i].childNodes[2].firstChild.nodeValue;	
								m.lng = countries[i].childNodes[3].firstChild.nodeValue;	
								marker = setCountryIcon(m);
								map.addOverlay(marker);
							}
						}														
					});
					break;
				case "routeplanner":
					if(!HL.StrEmpty(m.searchcity)){
						var geocoder = new GClientGeocoder();
						//geocoder.getLocations(address, createAddress)
						map.setMapType(G_NORMAL_MAP) 
						
					
						var directionsPanel = $("route-div");
						
						directions = new GDirections(map, directionsPanel);
						GEvent.addListener(directions, "load", MaphandleErrors);
						GEvent.addListener(directions, "error", MaphandleErrors);

						directions.load("from: " + m.searchstreet + ", " + m.searchcity + ", " + m.searchcountrycode + " to: " +  m.lat + ", " + m.lng, { "locale": m.lancode });
					
						
					
					}else{
						//var geocoder = new GClientGeocoder();
						//geocoder.getLocations(address, createAddress)
				
						
						
					}
					break;
				case "allweatherstations":
					map.clearOverlays();
					
					new Ajax.Request("/xml/markers.xml", {method: 'get',
					onSuccess: function(transport){
							var xml = transport.responseXML;
							
							var markers = xml.getElementsByTagName("marker");
							for(var i=0; i<markers.length; i++){
								var m = [];
								m.stationname = markers[i].getAttribute("name");	
								m.lat = markers[i].getAttribute("lat");	
								m.lng = markers[i].getAttribute("lng");	
								setWeatherStationIcon(m);
							}
						}														
					});
					break;
					
					
					
					
					
			}
			
			

			
		}
		
		
			
	};
	
	
	
	
}();




