
function showImage(url){
	window.open(url, "image")
}


function uploaderStatusChanged( uploader ) { 
	
	if (uploader.isReady()) {	 
		HL.ReLoadForJumpLoader();
	} 
} 


function openSMWindow(el){
	var win=false;
	try{
		win=window.open(el.href,'socialmedia popup','toolbar=0,location=0,menubar=0,scrollbars=1,width=820,height=500,resizable=1,status=0');
	}
	catch(e){};
	if(win){
		try{
			win.focus()
		}catch(e){};
	}
	return !!win
}



function Tr_RollOver(id){
	var t = Ext.get(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 = Ext.get(id)
	hover = new RegExp ("-hover", "g")
	t.className = t.className.replace(hover,"")
	if(t.className == "image-border-link"){
		try{
			r = Ext.getDom("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
	this.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;
	var loadingdata = false;
	

	return{
		StrEmpty: function(str){
			return ((String(str).toLowerCase() == "false") || (String(str).toLowerCase() == "undefined") || (str == "") || (String(str).toLowerCase() == String(null)));
		},
		
		
		GearShowAdvancedSearch: function(){
			if(Ext.get("AdvancedSearch").getStyle("display") == "none"){
				Ext.get("AdvancedSearch").setStyle("display", "block");
				Ext.get("GearContent").removeClass("width815");
			}else{
				Ext.get("AdvancedSearch").setStyle("display", "none");	
				Ext.get("GearContent").addClass("width815");
			}
		},
		
		VotePoll: function(itemid, optionid){
			Ext.get("sidepol").load({
					url: '/poll/' + itemid + '/vote/?isfront=1',
					params: {
						optionid: optionid
					},
					success: function ( result, request ) { 
						Ext.getDom("largePreviewDiv").setAttribute("picUrl", e.getAttribute("picUrl"));
					}
				});
		},
		
		GalleryChooseType: function(id, step){
			if(!HL.StrEmpty(id)){
				Ext.getDom("GalleryType").setAttribute("value",id);
				if(id == 1){
					Ext.getDom("GalleryButton-1").setAttribute("class", "green-button");
					Ext.getDom("GalleryButton-2").setAttribute("class", "light-button");
					Ext.get("GalleryType1").setStyle("display", "block");
					Ext.get("GalleryType2").setStyle("display", "none");
				}else{
					Ext.getDom("GalleryButton-1").setAttribute("class", "light-button");
					Ext.getDom("GalleryButton-2").setAttribute("class", "green-button");
					Ext.get("GalleryType2").setStyle("display", "block");
					Ext.get("GalleryType1").setStyle("display", "none");
				}	
			}
			
			if(step == 2){
				Ext.get("GalleryText").setStyle("display", "block");	
			}
			
			if(step == 3){
				Ext.get("GalleryTags").setStyle("display", "block");	
			}
			
			if(step == 4){
				Ext.get("SubmitBar").setStyle("display", "block");	
			}
			
			
		},
		
		
		RollOverStars: function(id){
			ratingvalue = Ext.getDom("RatingId").getAttribute("value");
				HL.StrEmpty(ratingvalue)? ratingvalue = 0 : '';
				
			for(var i=1; i<=5; i++){
				if(i<=id){
					Ext.getDom("star" + i).setAttribute("src", "/media/icons/star-1.png")
				}else{
					if(i<=ratingvalue){
						Ext.getDom("star" + i).setAttribute("src", "/media/icons/star-2.png")
					}else{
						Ext.getDom("star" + i).setAttribute("src", "/media/icons/star-0.png")
					}
				}
			}
		},
		
		makeStars: function(id){
			ratingvalue = Ext.getDom("RatingId").setAttribute("value", id);
			for(var i=1; i<=5; i++){
				if(i<=id){
					Ext.getDom("star" + i).setAttribute("src", "/media/icons/star-2.png")
				}else{
					Ext.getDom("star" + i).setAttribute("src", "/media/icons/star-0.png")
				}
			}
		},
		
		RollOutStars: function(id){
			ratingvalue = Ext.getDom("RatingId").getAttribute("value");
				HL.StrEmpty(ratingvalue)? ratingvalue = 0 : '';
			for(var i=1; i<=5; i++){
				if(i<=ratingvalue){
					Ext.getDom("star" + i).setAttribute("src", "/media/icons/star-2.png")
				}else{
					Ext.getDom("star" + i).setAttribute("src", "/media/icons/star-0.png")
				}
			}
		},
		
		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){
			Ext.Ajax.request({
						url: '/gallery/' + e.getAttribute("itemid") + '/showimage/?picurl=' + e.getAttribute("picUrl") + '&ridername=' + e.RiderName + '&photographername=' + e.PhotographerName,
						success: function ( result, request ) { 
							Ext.getDom("largePreviewDiv").innerHTML = result.responseText;
							Ext.getDom("largePreviewDiv").setAttribute("picUrl", e.getAttribute("picUrl"));
						}
					});	

			
			
			
		},
		
		
		
		SetHitForLink: function(linkid){
			Ext.Ajax.request({
						url: '/externallink/' + linkid + '/',
						method: 'GET'
			});	
		},
		
		SetHitForItem: function(itemid){
			Ext.Ajax.request({
						url: '/hotspot/' + itemid + '/hit/',
						method: 'GET'
			});	
		},
		
		showImage: function(e){
			var src = String(e.getAttribute("src")).replace("small", "large");
			window.open(src);
		},
		Tr_RollOut: function(){

			try{
				var t = Ext.getDom("rollover");
				t.parentNode.removeChild(t);
			}catch(e){}
		},
		Tr_RollOver: function(e){
			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.parentNode.insertBefore(span, e); 
				span.setAttribute("src", e.getAttribute("src"));
	
				//span.onClick = function() {HL.showImage(e)} ; 
				//span.onmouseout = function() {HL.Tr_RollOut(e)} ; 
				e.insertAdjacentElement("beforeBegin",span);	


			}
		},
		SetTagImage: function(e){
			Ext.getDom("SetTagImage").innerHTML = '<img src="/media/tag/' + e.getAttribute("picname") + '.jpg" />'; 
			Ext.getDom("SetTagImageName").value = e.getAttribute("picname"); 
		},
		
		openTab: function(id, isAjax){
			var a = Ext.query(".Tab");
			for(var i=0; i<a.length;i++){
				Ext.get("Div-" + a[i].id).applyStyles("display:none");
				Ext.get(a[i].id).removeClass("Tab-true");
			}
			Ext.get("Div-Tab-" + id).applyStyles("display:block");
			Ext.get("Tab-" + id).addClass("Tab-true");
			
			if(isAjax){
				Ext.get("Div-Tab-" + id).load({url: "/kitespot/" + id + "/frontpage/data/"
											,scripts: true
											});
			}
		},
		
		OpenWindowRelatedSpot: function(spotcounter, countrycode){
			var store = new Ext.data.JsonStore({
				root: 'Data',
				idProperty: 'ItemId',
				fields: [
					'ItemId', 'Name', 'CountryCode', 'SpotCounter'
				],
				url: '/hotspot/spotlist/?spotcounter=' + spotcounter
		 
			});	
			
			
			var grid = new Ext.grid.GridPanel({
				frame: false,
				border: true,
				width: '100%',
				store: store,
				enableColumnHide:false,
				enableColumnMove: false,
				enableDragDrop: false,
				autoHeight: true,
				loadMask:true,
				stripeRows: true,
				bodyStyle: 'padding: 0px;',
				
				columns: [
					{header: strCity, dataIndex: "Name", sortable: true, width: 250,
						renderer:  function(n, g, r) {
						  return '<img src="/media/icons/flag16/' + r.data.CountryCode + '.gif" >&nbsp;<a href="javascript:void(0)" onClick="HL.setSpot(' + "'" + n + "', '" + r.data.ItemId + "', '" + r.data.SpotCounter + "'" + ')">' + n + '</a>';
						}
					}
					]
			});	
			
			win = new Ext.Window({
				 width:300
				,id:'kitespots'
				,height:600
				,autoScroll:true
				,title:strChooseKiteSpots
				,items:[grid]
				
			});
			
			store.load();
			win.show();
		},
		
		 setSpot: function(s, id, counter){
			var spotcounter = counter;
			Ext.get("SpotName" + spotcounter).update(s);
			Ext.get("SpotId" + spotcounter).set({"value":id}); 
			HL.countRelatedSpotsCosts();
			win.close();	
		},
		
		NewRelatedSpot: function(itemid){
			var setspot = Ext.get("setspot");
			spotcounter ++;
			
			var spotdiv = Ext.DomHelper.append(setspot, [{
              id : "spot" + spotcounter
            }]);
			Ext.get("spot" + spotcounter).load({
					url: "/hotspot/" + itemid + "/edit/subscribe/setspot/",
					scripts: true,
					params: {
						spotcounter: spotcounter
					},
					text: strLoadingText,
					success: function ( result, request ) { 
						spotdiv.update(result.responseText, true);
						
					
					}
			});
			HL.countRelatedSpotsCosts();

			
			
		},
		
		RemoveRelatedSpot: function(i){
			Ext.get("spot" + i).remove();
			HL.countRelatedSpotsCosts();
		},
		
		
		SetRelatedSpotIsCommercial: function(id, bit){
			if(!HL.StrEmpty(bit)){
				Ext.get("IsCommercial" + id + "-1").setStyle("display", "block");	
				Ext.get("IsCommercial" + id + "-0").setStyle("display", "none");	
			}else{
				Ext.get("IsCommercial" + id + "-0").setStyle("display", "block");	
				Ext.get("IsCommercial" + id + "-1").setStyle("display", "none");	
			}
			
			HL.countRelatedSpotsCosts();
		},
		
		countRelatedSpotsCosts: function(){
			//var w = Ext.get("setspot").getElementsByClassName("Widget-True");
			var w = Ext.query("#setspot *[class=Widget-True]")
			var totalcosts = 0;
			
			for(var i=0; i<w.length; i++){
				var counter = w[i].getAttribute("spotcounter");
				var spotid = Ext.get("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")); 
							Ext.get("Cost" + counter).set({"value": Number(document.add["Months" + counter][j].getAttribute("cost"))}); 
						} 
					} 
				}else{
					
					cost = 0;
					totalcosts += cost;	
				}
				Ext.get("spotcounter").set({"value":counter});
			}
			
			Ext.get("TotalCosts").update(totalcosts)
		},
		
		setLocal: function(itemid){
			Ext.get("locals").load({
				url: '/kitespot/' + itemid + '/setlocal/',
				scripts: true
			});
		},
		
		CombineTags: function(e){
			var tagtype = e.getAttribute("tagtype");
			Ext.getDom(tagtype).innerHTML = e.getAttribute("tagname");
			Ext.getDom(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 = Ext.getDom(username + id);
			if(e.className == "User-Header-DropDown-false"){
				e.className = "User-Header-DropDown-true";
				e.innerHTML = 'loading...';
				
				if(HL.StrEmpty(itemid)){
					Ext.get(username + id).load('/user/' + username + '/popup/')
				}else{
					if(String(id).substr(0,4) == 'item'){
						Ext.get(username + id).load('/itemarchive/?itemid=' + itemid)
					}else{
						Ext.get(username + id).load('/reactarchive/?reactid=' + itemid)
					}
				}
			}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 = Ext.getDom("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 "new":
					var idname = "news";
					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..."
					Ext.getDom("button-" + id).className = "small-icon-1";
					
					Ext.Ajax.request({
						url: '/setside/?pagecode=' + id + '&value='
					});	
				}else{
					d.className = "Display-true";	
					Ext.getDom("button-" + id).className = "small-icon-0";
					Ext.get('side' + id).load({
						url: '/' + idname + '/side/'
					});
					
					Ext.Ajax.request({
						url: '/setside/?pagecode=' + id + '&value=1'
					});	
				}
			}else{
				if(HL["LoginIs" + id]){
					d.className = "Display-true";
					Ext.getDom("button-" + id).className = "small-icon-0";
					Ext.get('side' + id).load({
						url: '/' + idname + '/side/'
					});
				}else{
					d.className = "Display-false";
					Ext.getDom("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){
					Ext.Ajax.request({
						url: "/itemarchive/editdata/?itemid=" + e.getAttribute("itemid") + "&historyid=" + value,
						success: function ( result, request ) { 
							location.reload(true);
						}
					});	
				}else{
					Ext.Ajax.request({
						url: "/reactarchive/editdata/?reactid=" + e.getAttribute("reactid") + "&historyid=" + value,
						success: function ( result, request ) { 
							location.reload(true);
						}
					});	
				}
			}
		},
		
		openArchiveHistory : function(e){
			var v = e.getAttribute("value");
			var h = document[e.getAttribute("formid")]["History" + e.getAttribute("formid")];
			for(var i=0; i<h.length; i++){
				if(h[i].getAttribute("value") != v){
					Ext.getDom(h[i].value).style.display = "none";	
				}else{
					Ext.getDom(h[i].value).style.display = "block";	
				}	
			}
		},
		
		SpamStopInit: function(){
			
			if(Ext.getDom('widget9')){
				
				try{
					Ext.get("widget9").load({
						url:	'/spamstopper/'
					});	
				}
				catch(e){}
			}
		},
		
		SelectTimeZone: function(){
			var tz = Ext.getDom("TimeZoneId");
			Ext.getDom("TZMapOver").style.paddingLeft = tz.options[tz.selectedIndex].getAttribute("mapleft") + "px";	
			Ext.getDom("TZMapOver").src = "/media/template/tz/" + tz.options[tz.selectedIndex].getAttribute("code") + ".png";		
		},
		
		sendAbuse: function(itemid){
			var url = Ext.getDom("AbuseURL").getAttribute("value");
			var remark =  Ext.getDom("AbuseRemark").value;
			if(HL.StrEmpty(remark)){
				windowI.close();
			}else{

				Ext.Ajax.request({
					url: '/abuse/?remark=' + remark + '&URL=' + url,
					success: function ( result, request ) { 
						Ext.MessageBox.alert(strWarning, strThankYouAbuseAlert);	
						windowI.close();
					},
					fail: function ( result, request ) { 
						Ext.MessageBox.alert(strWarning, strFailureAbuseAlert);	
						windowI.close();
					}
				});
				

			}
		},
		
		reportAbuse: function(url, itemid){
			
			var str = '<form name="AbuseForm" style="background-color:#f0f6fb;">';
				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; border:1px solid black;"></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="Btn-icon btn-i-true">&nbsp;</span>';
								str += strReportAbuse;
							str += '</a>';
						str += '</td>';
					str += '</tr>';
				str += '</table>';
			str += '</form>';
			
			
			
			
			windowI = new Ext.Window({
				id: 'Abuse',
				frame: true,
				border: true,
				title: strReportAbuseTitle,
				width:500,
				height:260,
				border: false,
				modal: true,
				closeAction: 'close',
				html: str
				
			});
			
			
			windowI.show(document);

		},
		AddGear: function(att){
			Ext.get("gearinfo").applyStyles({display:"block"});
			Ext.get("gearinfo").load({
					url: "/gear/selectbox/", 
					scripts: true,
					params: {
						UserItemId: att.UserItemId,
						UserName: att.UserName,
						HideMisc: 1,
						ShowSinceDate: 1
					},
					text: strLoadingText
			});	

			var i = new Ext.Window({
				title: strEditMyGear,
				contentEl: 'gearinfo',
				width:500,
				height:475,
				border: false,
				frame: true,
				modal: true,
				closeAction: 'hide',
				tbar: [
							{
								text : strSave,
								cls: 'x-btn-text-icon',
								icon: '/media/icons/disk.png',
								type: 'Submit',
								handler : function(){
	
									if(Ext.getDom("BuildYear") && Ext.get("GearSizeId")){
										var ItemId = Ext.getDom("BuildYear").options[Ext.getDom("BuildYear").selectedIndex].getAttribute("ItemId");
										var GearSizeId = Ext.get("GearSizeId").getValue();
										var SinceDateDate = Ext.get("SinceDateDate").getValue();
										var SinceDateMonth = Ext.get("SinceDateMonth").getValue();
										var SinceDateYear = Ext.get("SinceDateYear").getValue();
										var EndDateDate = Ext.get("EndDateDate").getValue();
										var EndDateMonth = Ext.get("EndDateMonth").getValue();
										var EndDateYear = Ext.get("EndDateYear").getValue();

										if(!HL.StrEmpty(ItemId) && !HL.StrEmpty(GearSizeId)){
											//save the form
											Ext.Ajax.request({
												url: '/user/' + att.UserName + '/gear/editdata/',
												method: 'POST',
												params:{
													UserItemId : att.UserItemId,
													ItemId: ItemId,
													GearSizeId: GearSizeId,
													SinceDateDate: SinceDateDate,
													SinceDateMonth: SinceDateMonth,
													SinceDateYear: SinceDateYear,
													SinceDateHours: "00",
													SinceDateminutes: "00",
													EndDateDate: EndDateDate,
													EndDateMonth: EndDateMonth,
													EndDateYear: EndDateYear,
													EndDateHours: "00",
													EndDateminutes: "00"
												},
												success: function ( result, request ) { 
								 					i.hide();
													store.load();
													try{
														retiredstore.load();	
													}
													catch(e){}
													Ext.MessageBox.alert(strWarning, strSaveSuccess);	
													
												}
											});	
											
										}else{
											Ext.MessageBox.alert(strWarning, strFormIsNotValid);
										}
										
										
									}else{
										Ext.MessageBox.alert(strWarning, strFormIsNotValid);
									}
									
									return false;
									if(WebLinkForm.form.isValid()){
										WebLinkForm.form.submit({
											url: '/kitespot/' + itemid + '/edit/links/editdata/',
											waitMsg: 'Saving...',
											success: function(frm, act) {
												frm.reset();
												//try{
													frm.setValues(act.result.data);
													Ext.MessageBox.alert(strWarning, strSaveSuccess);
													i.destroy();
													store.load();
												//}
												//catch(e){}
												
												
												
											}
										});
									}else{
										Ext.MessageBox.alert(strWarning, strFormIsNotValid);
									}
								}
							},
							{
								text : strRequestGear,
								cls: 'x-btn-text-icon',
								icon: '/media/icons/kite.png',
								type: 'Submit',
								handler : function(){
									document.location = "/gear/request/"
								}
							}
						]
				
			});
			
			
			i.show(document.body);	
		},
		AddWebLink: function(itemid, linkid){
			

			
			var i = new Ext.Window({
				title: strAddWebLink,
				width:500,
				height:280,
				border: false,
				modal: true,
				closeAction: 'hide',
				items: [
					WebLinkForm = new Ext.form.FormPanel({
						id: 'WebLinkForm',
						width: '100%',
						method: "POST",
						monitorValid: true,
						border: false,
						frame: false,
						tbar: [
							{
								text : strSave,
								cls: 'x-btn-text-icon',
								icon: '/media/icons/disk.png',
								formBind: true,
								type: 'Submit',
								handler : function(){
									if(WebLinkForm.form.isValid()){
										WebLinkForm.form.submit({
											url: '/kitespot/' + itemid + '/edit/links/editdata/',
											waitMsg: 'Saving...',
											success: function(frm, act) {
												frm.reset();
												//try{
													frm.setValues(act.result.data);
													Ext.MessageBox.alert(strWarning, strSaveSuccess);
													i.destroy();
													store.load();
												//}
												//catch(e){}
												
												
												
											}
										});
									}else{
										Ext.MessageBox.alert(strWarning, strFormIsNotValid);
									}
								}
							}
						],
						items:[
							{
								xtype: 'hidden',
								fieldLabel: 'LinkId',
								name: 'LinkId'
							},{
								xtype: 'checkbox',
								fieldLabel: strIsActive,
								name: 'IsActive',
								checked: true
							},{
								xtype: 'textfield',
								fieldLabel: strTitle,
								name: 'Title',
								allowBlank: false,
								maxLength: 50	
							},{
								xtype: 'textfield',
								fieldLabel: strUrl,
								name: 'Url',
								allowBlank: false,
								maxLength: 100
							},{
								xtype: 'textarea',
								fieldLabel: strRemark, 
								width: '350px',
								name: 'Remark',
								maxLength: 1000
							}
						]
					})		
				]
			});
			
			if(linkid){
				WebLinkForm.getForm().load({
					url:"/kitespot/" + itemid + "/edit/links/" + linkid + "/data/", 
					waitMsg:"Loading",
					success: function(e,a){
						
					}
				})
			}
			
			i.show(document.body);
		},
		
		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;
			}

			
			Ext.Ajax.request({
				url: '/setkudo/?itemid=' + id + '&qc=' + qc + '&direction=' + direction + '&pagecode=' + pagecode,
				success: function ( result, request ) { 
					var a = String(result.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';}
						Ext.getDom(div).className = "User-Header-Kudos-" + kudoColor;
						Ext.getDom(div).innerHTML = a[1];
					}else{
						Ext.MessageBox.alert(strWarning, a[0]);		
					}
				}
			});
			
			
		},
		initTopMenu: function(code){
			if(Ext.get("map")){
				HL.initGoogleMap(m);
			}
		},
		
		Carroussel: function(v){
			if(!CarrousselOver){
				var counter = Ext.getDom("CarrouselCounter").getAttribute("value");
				for(var i=1; i<=counter;i++){
					if(i == v){
						Ext.getDom("CarrouselDiv" + i).style.display = "block";	
						Ext.getDom("CarrouselTab" + i).className = "Carrousel-Tab-block";	
					}else{
						Ext.getDom("CarrouselDiv" + i).style.display = "none";	
						Ext.getDom("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 = Ext.getDom("CarrouselCounter").value;
			for(var i=1; i<=counter;i++){
				if(i == v){
					Ext.getDom("CarrouselDiv" + i).style.display = "block";	
					Ext.getDom("CarrouselTab" + i).className = "Carrousel-Tab-block";	
				}else{
					Ext.getDom("CarrouselDiv" + i).style.display = "none";	
					Ext.getDom("CarrouselTab" + i).className = "Carrousel-Tab-none";	
				}	
			}

			
		},

		
		CarrousselOut : function(v){
			CarrousselOver = false;			
		},

		
		EmbedPopup: function(id){
			
			var str = '<!-- START: Hanglos Rankin Widget Code -->';
			str += '<div style="background-color: #FFFFFF; width: 300px; font-family: Verdana,sans-serif; font-size: 11px;">';
			str += '<script type="text/javascript" src="http://www.hanglos.net/widget/ranking/?g=1&l=en"></script>';
			str += '</div><!-- END: Hanglos Rankin Widget Code -->';

			
			var i = new Ext.Window({
				title: strEmbedRatingsTitle,
				width:500,
				height:220,
				border: false,
				modal: true,
				closeAction: 'hide',
				items: [
					WebLinkForm = new Ext.form.FormPanel({
						id: 'Embed',
						width: '100%',
						method: "POST",
						monitorValid: true,
						border: false,
						frame: false,
						items:[
							{
								xtype: 'hidden',
								fieldLabel: 'LinkId',
								name: 'LinkId'
							},{
								xtype: 'textarea',
								fieldLabel: strEmbedTitle,
								width: 300,
								hegith:150,
								value: str	
							}
						]
					})		
				]
			});
			
			i.show(document.body);
		},
		
		spotSetRemark: function(countrycode, itemid){
			Ext.get("Remark").load({
				url: '/kitespot/' + itemid + '/setremark/?c=' + countrycode
			});
		},
		
		spotSetForum: function(countrycode, itemid){
			Ext.get("Forum").load({
				url: '/kitespot/' + itemid + '/setforum/?c=' + countrycode
			});
		},
		
		spoSetReviews: function(countrycode, itemid){
			Ext.get("Reviews").load({
				url: '/kitespot/' + itemid + '/setreviews/?c=' + countrycode
			});
		},
		
		geaSetReviews: function(countrycode, itemid){
			Ext.get("Reviews").load({
				url: "/gear/" + itemid + "/setreviews/?c=" + countrycode
			});
			
		},
		

		
		
		
		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' || e.type == 'checkbox'){
					
					if(e.checked || e.selected){
						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; 
		},
		
		
		 createBox: function(id, tagid, tagname){	//create taginput box
							HL.StrEmpty(tagname)? tagname = "" : "";
							var tagCombo = new Ext.form.ComboBox({
								renderTo: 'Tag' + id,
								store: tagStore,
								fieldLabel: '',
								displayField:'TagName',
								valueField: 'TagId',
								name: 'Title' + id,
								value: tagid,
								typeAhead: true,
								loadingText: strLoadingText,
								width: 250,
	
								hideTrigger:true,
								allowBlank: true,
								tpl: tagTpl,
								itemSelector: 'div.search-item',
	
								
								listeners: {
									select: function(e, record){
										Ext.getDom("Tag" + id + "Id").setAttribute("value", record.data.TagId);
										Ext.getDom("Tag" + id + "Name").setAttribute("value", record.data.TagName);
									},
									blur: function(e, record){
										if(HL.StrEmpty(record)){
											if(this.value === this.getRawValue()){
												Ext.getDom("Tag" + id + "Id").setAttribute("value", "")
												Ext.getDom("Tag" + id + "Name").setAttribute("value", this.getRawValue())
											}else{
												Ext.getDom("Tag" + id + "Id").setAttribute("value", this.value)
												Ext.getDom("Tag" + id + "Name").setAttribute("value", this.getRawValue())
											}
										}else{
											Ext.getDom("Tag" + id + "Id").setAttribute("value", record.data.TagId);
											Ext.getDom("Tag" + id + "Name").setAttribute("value", record.data.TagName);
										}
									}	
								}
							});
							
							tagCombo.setValue(tagname);
						},	
		
		
		SubmitForm: function(att){
			//jumploader: als 1 = alleen return true; niet submitten.
			//url: deze url
			this.elementCount ++;
			
			//alert(this.elementCount + ':' + this.Form.elements.length + '-' + att.name)
			if(this.elementCount >= this.Form.elements.length && att.ShowMask){
				Ext.MessageBox.show({
				   msg: strSavingYourData,
				   progressText: strSaving,
				   width:300,
				   wait:true,
				   icon:'ext-mb-download', //custom class in msg-box.html
				   animEl: 'mb7'
			   });
			}

			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.
					att.noSubmit = 1;	

					//if(document.JUpload.getUploader().getFileCount() > 0){
						Ext.Ajax.request({
							url: this.Form.action + '?IsApplet=1',
							params: this.getFormParameters(),
							success: function ( result, request ) { 
								var str = String(result.responseText).split(",")
								HL.Url = str[1];
								try{
									document.JUpload.getUploaderConfig().setUploadUrl(String(HL.DomainUrl + str[0]))
									if(document.JUpload.getUploader().getFileCount() > 0){
										document.JUpload.getUploader().startUpload();
									}else{
										window.location.href = str[1];
									}
								}
								catch(e){
										window.location.href = str[1];
								}
							}
						});
					//}else{
						//this.Form.submit()	
					//}
					
					


				
			}	
			
			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{
				try{
					f.Remark.value = CKEDITOR.instances.Remark.getData()
				}
				catch(e){}
			}
		},
		
		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;
		},
		
		CheckLoadingData: function(e){
			if(HL.StrEmpty(this.data)){
				setTimeout(HL.CheckLoadingData, 1000); 
			}


				Ext.getDom("Title").setAttribute("value", this.data[0].title);
				Ext.getDom("VideoEmbedSmallThumb").setAttribute("value", this.data[0].thumbnail_small);
				Ext.getDom("VideoEmbedLargeThumb").setAttribute("value", this.data[0].thumbnail_medium);
			

				HL.SubmitForm({ShowMask:1});
				HL.SetValidationCSS(Ext.getDom("VideoEmbed"), 1);
				Ext.getDom("iconVideoEmbed").className = "Btn-icon btn-i-true";
				Ext.getDom("WrongVideoEmbed").innerHTML = '';	

		},
		
		UnTag: function(str){
			tag = new RegExp('<([^<>\s]*)(\s[^<>]*)?>', "g");
			tag2 = new RegExp('&nbsp;', "g");
			tag3 = new RegExp('[\\f\\n\\r\\t\\v]', "g");
			tag4 = new RegExp('\<a rel="nofollow" target="_blank"', "g");
			
			
			str = str.replace(tag2, " ");
			str = str.replace(tag3, "");
			str = str.replace(tag, "");
			str = str.replace(tag4, "");

			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];
				att.name = e.name
				var code = e.getAttribute("code");
				var icon = Ext.getDom("icon" + e.name);
				var wrongtxt = Ext.getDom("Wrong" + e.name);
				
				//alert(code + '-' + att.name)
				switch(code){
					case "ReqGalleryFill":
					
						var gallerytype = Ext.getDom("GalleryType").getAttribute("value");
						if(gallerytype == 2){
							
							var value = Ext.getDom("VideoEmbed").value;
							
							if(HL.StrEmpty(value)){
								this.SetValidationCSS(Ext.getDom("VideoEmbed"), 0);
								icon.className = "Btn-icon btn-i-false";
								wrongtxt.innerHTML = strEmbedVideo;			
							}else{
								var tempvalue = '';
								if(String(value).match("youtube")){
									VideoEmbedTypeId.setAttribute("value", 1);
									var regCode = new RegExp("youtube.com\\/v\\/([^?/]*)", "g");
									regCode.exec(value);
									var tempvalue = RegExp.$1;
		
								}
								
								
								if(String(value).match("vimeo")){
									VideoEmbedTypeId.setAttribute("value", 2);
									var regCode = new RegExp("vimeo.com\\/video\\/([0-9]*)", "g");
									regCode.exec(value);
									var tempvalue = RegExp.$1;
									
									
								}	
								
								if(HL.StrEmpty(tempvalue)){		
									this.SetValidationCSS(Ext.getDom("VideoEmbed"), 0);
									icon.className = "Btn-icon btn-i-false";
									wrongtxt.innerHTML = strEmbedVideo;			
								}else{
									HL.SubmitForm(att);
									this.SetValidationCSS(Ext.getDom("VideoEmbed"), 1);
									icon.className = "Btn-icon btn-i-true";
									wrongtxt.innerHTML = '';	
								}	
								
										
							}
						}
						
						
						if(gallerytype == 1){
							if(!navigator.javaEnabled()){
								icon.className = "Btn-icon btn-i-false";
								wrongtxt.innerHTML = strNoJavaIsntalled;			
							}else{
								var value = document.JUpload.getUploader().getFileCount()
								if(value == 0){
									icon.className = "Btn-icon btn-i-false";
									wrongtxt.innerHTML = strAddPhotoForUpload;			
								}else{
									HL.SubmitForm(att);
									icon.className = "Btn-icon btn-i-true";
									wrongtxt.innerHTML = '';			
								}
							}
						}
						
						break;
					case "NonReqEmbedText":
							var VideoEmbedId = Ext.getDom("VideoEmbedId");
							var VideoEmbedTypeId = Ext.getDom("VideoEmbedTypeId");
							
							//check videotype
							if(HL.StrEmpty(e.value)){
								HL.SubmitForm(att);
								this.SetValidationCSS(e, 1);
								icon.className = "Btn-icon btn-i-true";
								wrongtxt.innerHTML = '';			
							}
							
							if(String(e.value).match("youtube")){
								VideoEmbedTypeId.setAttribute("value", 1);
								var regCode = new RegExp("youtube.com\\/v\\/([^?/]*)", "g");
								regCode.exec(e.value);
								var tempvalue = RegExp.$1;
							
								VideoEmbedId.setAttribute("value", tempvalue);
	
								
								HL.SubmitForm(att);
								this.SetValidationCSS(e, 1);
								icon.className = "Btn-icon btn-i-true";
								wrongtxt.innerHTML = '';						
							}
							if(String(e.value).match("vimeo")){
								VideoEmbedTypeId.setAttribute("value", 2);
								var regCode = new RegExp("vimeo.com\\/video\\/([0-9]*)", "g");
								regCode.exec(e.value);
								var tempvalue = RegExp.$1;
								VideoEmbedId.setAttribute("value", tempvalue);
								
								//get the thumb info
								var headID = document.getElementsByTagName("head")[0];         
								var newScript = document.createElement('script');
								newScript.type = 'text/javascript';
								newScript.src = 'http://vimeo.com/api/v2/video/' + tempvalue + '.json?callback=getVimeoJson';
								headID.appendChild(newScript);
								
								this.data = '';								
								getVimeoJson = function(str){
									this.data = str;									
								}
								
								if(HL.StrEmpty(this.data)){
									setTimeout(HL.CheckLoadingData, 1000); 
								}
							}
								
								
													 	

						break;
					
					
					case "ReqUserName":
						var te = e;
						var ticon = icon;
						var twrong = wrongtxt;
						
						Ext.Ajax.request({
							url: '/register/checkuser/?str=' + te.value,
							success: function ( result, request ) { 
								var checkUser = result.responseText;
								if(!HL.StrEmpty(checkUser)){
									HL.SetValidationCSS(te, 0);
									ticon.className = "Btn-icon btn-i-false";
									Ext.getDom("Wrong" + te.name).innerHTML = checkUser;
								}else{
									HL.SubmitForm(att);
									HL.SetValidationCSS(te, 1);
									ticon.className = "Btn-icon btn-i-true";
									Ext.getDom("Wrong" + te.name).innerHTML = '';
								}
							}
						});
						
																													 	
					
						
						
						break;
					case "ReqExtDate":
						var ex = Ext.getCmp("SurfDate");
						if(!HL.StrEmpty(ex.getValue())){
							HL.SubmitForm(att);
							this.SetValidationCSS(e, 1);
							icon.className = "Btn-icon btn-i-true";
							wrongtxt.innerHTML = '';
						}else{
							this.SetValidationCSS(e, 0);
							icon.className = "Btn-icon btn-i-false";
							wrongtxt.innerHTML = strValidateDate;
						}	
						break;
						
					case "ReqExtBetweenOption":
						var start = Ext.getCmp(e.name + "Start");
						var end = Ext.getCmp(e.name + "End");
						if(!HL.StrEmpty(start.getValue()) && !HL.StrEmpty(end.getValue())){
							HL.SubmitForm(att);
							icon.className = "Btn-icon btn-i-true";
							wrongtxt.innerHTML = '';
						}else{
							icon.className = "Btn-icon btn-i-false";
							wrongtxt.innerHTML = strValidateBetweenOption;
						}	
						break;
					case "ReqImages":
						try{
							if(att.minimumUpload > document.JUpload.getUploader().getFileCount()){
								this.SetValidationCSS(e, 0);
								icon.className = "Btn-icon btn-i-false";
								wrongtxt.innerHTML = strWrongAmountOfImagesSelectedText;
							}else{
								HL.SubmitForm(att);
								this.SetValidationCSS(e, 1);
								icon.className = "Btn-icon btn-i-true";
								wrongtxt.innerHTML = '';
							}
						}
						catch(e){
							HL.SubmitForm(att);
						}
					
						break;
						
					case "ReqCoordinate":
						if(e.value != (e.value.match('[0-9].*')) || HL.StrEmpty(e.value)){
							this.SetValidationCSS(e, 0);
							icon.className = "Btn-icon btn-i-false";
							wrongtxt.innerHTML = strWrongReqCoordinateText;
						}else{
							HL.SubmitForm(att);
							this.SetValidationCSS(e, 1);
							icon.className = "Btn-icon btn-i-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 = "Btn-icon btn-i-false";
							wrongtxt.innerHTML = strWrongNonReqNumberText;
						}else{
							HL.SubmitForm(att);
							this.SetValidationCSS(e, 1);
							icon.className = "Btn-icon btn-i-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 = "Btn-icon btn-i-false";
							wrongtxt.innerHTML = strWrongNonReqNumberText;
						}else{
							HL.SubmitForm(att);
							this.SetValidationCSS(e, 1);
							icon.className = "Btn-icon btn-i-true";
							wrongtxt.innerHTML = '';
						}																						 	

						break;
					
					case "ReqImage":
						vartempvalue = HL.checkEmptyValue(e.value);
						
						if(this.StrEmpty(vartempvalue)){
							this.SetValidationCSS(e, 0);
							icon.className = "Btn-icon btn-i-false";
							wrongtxt.innerHTML = strWrongReqImageText;
						}else{
							HL.SubmitForm(att);
							this.SetValidationCSS(e, 1);
							icon.className = "Btn-icon btn-i-true";
							wrongtxt.innerHTML = '';
						}																						 	

						break;
						
					case "NonReqImage":
						vartempvalue = HL.checkEmptyValue(e.value);

							HL.SubmitForm(att);
							this.SetValidationCSS(e, 1);
							icon.className = "Btn-icon btn-i-true";
							wrongtxt.innerHTML = '';
												 	
							
						break;
					
					case "ReqText":
						vartempvalue = HL.checkEmptyValue(e.value);
						
						if(this.StrEmpty(vartempvalue)){
							this.SetValidationCSS(e, 0);
							icon.className = "Btn-icon btn-i-false";
							wrongtxt.innerHTML = strWrongReqTextText;
						}else{
							HL.SubmitForm(att);
							this.SetValidationCSS(e, 1);
							icon.className = "Btn-icon btn-i-true";
							wrongtxt.innerHTML = '';
						}																						 	

						break;
						
					case "NonReqText":
							HL.SubmitForm(att);
							this.SetValidationCSS(e, 1);
							icon.className = "Btn-icon btn-i-true";
							wrongtxt.innerHTML = '';															 	

						break;
					
					
					
					case "ReqLink":
						e.value = String(e.value).replace("http://", "")
						if(this.StrEmpty(e.value)){
							this.SetValidationCSS(e, 0);
							icon.className = "Btn-icon btn-i-false";
							wrongtxt.innerHTML = strWrongReqTextText;
						}else{
							HL.SubmitForm(att);
							this.SetValidationCSS(e, 1);
							icon.className = "Btn-icon btn-i-true";
							wrongtxt.innerHTML = '';
						}
			
						break;
					
					case "ReqTerms":	
						if(this.StrEmpty(e.checked)){
							this.SetValidationCSS(e, 0);
							icon.className = "Btn-icon btn-i-false";
							wrongtxt.innerHTML = strWrongReqTermsText;
						}else{
							HL.SubmitForm(att);
							this.SetValidationCSS(e, 1);
							icon.className = "Btn-icon btn-i-true";
							wrongtxt.innerHTML = '';
						}
					
						break;
					
					case "NonReqLink":
						e.value = String(e.value).replace("http://", "")
							HL.SubmitForm(att);
							this.SetValidationCSS(e, 1);
							icon.className = "Btn-icon btn-i-true";
							wrongtxt.innerHTML = '';
						
			
						break;	
				
					case "ReqDropDown":
						if(this.StrEmpty(e.value)){
							this.SetValidationCSS(e, 0);
							icon.className = "Btn-icon btn-i-false";
							wrongtxt.innerHTML = strWrongReqDropDownText;
						}else{
							HL.SubmitForm(att);
							this.SetValidationCSS(e, 1);
							icon.className = "Btn-icon btn-i-true";
							wrongtxt.innerHTML = '';
						}																						 	

						break;
					
					case "ReqSpotSelect":	//only used for adding session
						var checked = false;
						if(this.Form.LocalSpotId){
							for(j=0; j<this.Form.LocalSpotId.length; j++){
								if(this.Form.LocalSpotId[j].checked == true){
									checked = true;
								}
							}
						}else{
							
						}
						var ex = Ext.getDom("SpotId");
						if(!this.StrEmpty(ex.getAttribute("Value"))){
							checked = true;
						}
						
						if(!checked){
							icon.className = "Btn-icon btn-i-false";
							wrongtxt.innerHTML = strValidateSessionSpot;
						}else{
							HL.SubmitForm(att);
							icon.className = "Btn-icon btn-i-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 = "Btn-icon btn-i-false";
							wrongtxt.innerHTML = strWrongNonReqRadioText;
						}else{
							HL.SubmitForm(att);
							this.SetValidationCSS(e, 1);
							icon.className = "Btn-icon btn-i-true";
							wrongtxt.innerHTML = '';
						}
							
						break;
				
					case "ReqDate":
						var codename = e.getAttribute("codename");
						var d = Ext.getDom(codename + "Date");
						var m = Ext.getDom(codename + "Month");
						var y = Ext.getDom(codename + "Year");
						var h = Ext.getDom(codename + "Hours");
						var mm = Ext.getDom(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 = "Btn-icon btn-i-false";
							wrongtxt.innerHTML = strWrongNoValidDate;
						}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 = "Btn-icon btn-i-true";
							Ext.getDom("Wrong" + codename).innerHTML = '';	
						}
						
						break;
						
					case "NonReqDate":
						var codename = e.getAttribute("codename");
						var d = Ext.getDom(codename + "Date");
						var m = Ext.getDom(codename + "Month");
						var y = Ext.getDom(codename + "Year");
						var h = Ext.getDom(codename + "Hours");
						var mm = Ext.getDom(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 = "Btn-icon btn-i-false";
							wrongtxt.innerHTML = strWrongNoValidDate;
						}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 = "Btn-icon btn-i-true";
							
							Ext.getDom("Wrong" + codename).innerHTML = '';
							
						}
						
						break;
						
				
					case "ReqLogin":
						var username = this.Form.LoginUserName;
						var password = this.Form.LoginPassword;
						var wrongtxt = Ext.getDom("WrongLogin")
						if(this.StrEmpty(username.value) || this.StrEmpty(password.value)){
							this.SetValidationCSS(username, 0);
							this.SetValidationCSS(password, 0);
							Ext.getDom("WrongLogin").innerHTML = strWrongReqLoginText;
						}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 = "Btn-icon btn-i-false";
							Ext.getDom("Wrong" + e.name).innerHTML = strWrongReqTextAreaText;
						}else{
							HL.SubmitForm(att);
							this.SetValidationCSS(e, 1);
							icon.className = "Btn-icon btn-i-true";
							wrongtxt.innerHTML = '';
						}
						break;
						
					case "NonReqTextAreaV2":

						var tempvalue = HL.checkEmptyValue(e.value);

							HL.SubmitForm(att);
							this.SetValidationCSS(e, 1);
							icon.className = "Btn-icon btn-i-true";
							wrongtxt.innerHTML = '';
						
						break;
	
					
					case "ReqTextAreaV3":
						var tempvalue = HL.checkEmptyValue(CKEDITOR.instances.Remark.getData());
						if(this.StrEmpty(tempvalue)){
							this.SetValidationCSS(e, 0);
							icon.className = "Btn-icon btn-i-false";
							Ext.getDom("Wrong" + e.name).innerHTML = strWrongReqTextAreaText;
						}else{
							HL.SubmitForm(att);
							this.SetValidationCSS(e, 1);
							icon.className = "Btn-icon btn-i-true";
							wrongtxt.innerHTML = '';
						}
						break;
						
					case "NonReqTextAreaV3":
						var tempvalue = HL.checkEmptyValue(CKEDITOR.instances.Remark.getData());
							HL.SubmitForm(att);
							this.SetValidationCSS(e, 1);
							icon.className = "Btn-icon btn-i-true";
							wrongtxt.innerHTML = '';
						
						break;	
					case "ReqNoTagsArea":
						var tempvalue = this.UnTag(e.value);
						e.value = tempvalue;
						if(this.StrEmpty(tempvalue)){
							this.SetValidationCSS(e, 0);
							icon.className = "Btn-icon btn-i-false";
							Ext.getDom("Wrong" + e.name).innerHTML = strWrongReqTextAreaText;
						}else{
							HL.SubmitForm(att);
							this.SetValidationCSS(e, 1);
							icon.className = "Btn-icon btn-i-true";
							wrongtxt.innerHTML = '';
						}
						
						break;
					case "NotReqNoTagsArea":
						var tempvalue = this.UnTag(e.value);
						e.value = tempvalue;
						HL.SubmitForm(att);
							this.SetValidationCSS(e, 1);
							icon.className = "Btn-icon btn-i-true";
							wrongtxt.innerHTML = '';
						
						break;
					case "ReqPassWord":
						var p1 = e;
						var p2 = Ext.getDom(e.name + "2");
						if(String(p1.value).length < 6){
							this.SetValidationCSS(p1, 0);
							this.SetValidationCSS(p2, 0);
							icon.className = "Btn-icon btn-i-false";
							Ext.getDom("Wrong" + p1.name).innerHTML = strWrongPasswordsToShortText;
						}else{
							if(String(p1.value) != String(p1.value).match('[a-zA-Z0-9_\\-]*')){
								this.SetValidationCSS(p1, 0);
								this.SetValidationCSS(p2, 0);
								icon.className = "Btn-icon btn-i-false";
								Ext.getDom("Wrong" + p1.name).innerHTML = strWrongPasswordsInvalidCharactersText;
							}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 = "Btn-icon btn-i-false";
										Ext.getDom("Wrong" + p1.name).innerHTML = strWrongPasswordsNotAllowedText;
								}else{
									if(p1.value != p2.value){
										this.SetValidationCSS(p1, 0);
										this.SetValidationCSS(p2, 0);
										icon.className = "Btn-icon btn-i-false";
										Ext.getDom("Wrong" + p1.name).innerHTML = strWrongPasswordsNotEqualText;
									}else{
										HL.SubmitForm(att);
										this.SetValidationCSS(p1, 1);
										this.SetValidationCSS(p2, 1);
										icon.className = "Btn-icon btn-i-true";
										wrongtxt.innerHTML = '';
									}
								}
							}
						}
					
						break;
						
					case "NonReqPassWord":
						var p1 = e;
						var p2 = Ext.getDom(e.name + "2");
						
						if(!HL.StrEmpty(p1.value)){
							if(String(p1.value).length < 6){
								this.SetValidationCSS(p1, 0);
								this.SetValidationCSS(p2, 0);
								icon.className = "Btn-icon btn-i-false";
								Ext.getDom("Wrong" + p1.name).innerHTML = strWrongPasswordsToShortText;
							}else{
								if(String(p1.value) != String(p1.value).match('[a-zA-Z0-9_\\-]*')){
									this.SetValidationCSS(p1, 0);
									this.SetValidationCSS(p2, 0);
									icon.className = "Btn-icon btn-i-false";
									Ext.getDom("Wrong" + p1.name).innerHTML = strWrongPasswordsInvalidCharactersText;
								}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 = "Btn-icon btn-i-false";
											Ext.getDom("Wrong" + p1.name).innerHTML = strWrongPasswordsNotAllowedText;
									}else{
										if(p1.value != p2.value){
											this.SetValidationCSS(p1, 0);
											this.SetValidationCSS(p2, 0);
											icon.className = "Btn-icon btn-i-false";
											Ext.getDom("Wrong" + p1.name).innerHTML = strWrongPasswordsNotEqualText;
										}else{
											HL.SubmitForm(att);
											this.SetValidationCSS(p1, 1);
											this.SetValidationCSS(p2, 1);
											icon.className = "Btn-icon btn-i-true";
											wrongtxt.innerHTML = '';
										}
									}
								}
							}
						}else{
							HL.SubmitForm(att);
							this.SetValidationCSS(p1, 1);
							this.SetValidationCSS(p2, 1);
							icon.className = "Btn-icon btn-i-true";
							wrongtxt.innerHTML = '';
						}
					
						break;
						
					case "ReqTag":
						var n=0;
						var s;
						for(var l=1; l<=5;l++){
							var v = Ext.getDom("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(Ext.getDom("Tag1"), 0);
							this.SetValidationCSS(Ext.getDom("Tag2"), 0);
							this.SetValidationCSS(Ext.getDom("Tag3"), 0);
							this.SetValidationCSS(Ext.getDom("Tag4"), 0);
							this.SetValidationCSS(Ext.getDom("Tag5"), 0);
							icon.className = "Btn-icon btn-i-false";
							Ext.getDom("Wrong" + e.name).innerHTML = strWrongReqTag2ShortText;
						}else{
							if(n>=2){
								HL.SubmitForm(att);
								this.SetValidationCSS(Ext.getDom("Tag1"), 1);
								this.SetValidationCSS(Ext.getDom("Tag2"), 1);
								this.SetValidationCSS(Ext.getDom("Tag3"), 1);
								this.SetValidationCSS(Ext.getDom("Tag4"), 1);
								this.SetValidationCSS(Ext.getDom("Tag5"), 1);
								icon.className = "Btn-icon btn-i-true";
								wrongtxt.innerHTML = '';
							}else{
								this.SetValidationCSS(Ext.getDom("Tag1"), 0);
								this.SetValidationCSS(Ext.getDom("Tag2"), 0);
								this.SetValidationCSS(Ext.getDom("Tag3"), 0);
								this.SetValidationCSS(Ext.getDom("Tag4"), 0);
								this.SetValidationCSS(Ext.getDom("Tag5"), 0);
								icon.className = "Btn-icon btn-i-false";
								Ext.getDom("Wrong" + e.name).innerHTML = strWrongReqTagNotEnoughText;								
							}
						}
						
						
						
						
						break;
						

					case "ReqSpamStopper":
						var v = Ext.getDom("SpamCheck").value;
						if(v != String(e.value).toUpperCase()){
							this.SetValidationCSS(e, 0);
							icon.className = "Btn-icon btn-i-false";
							Ext.getDom("Wrong" + e.name).innerHTML = strWrongSpamText;	
						}else{
							HL.SubmitForm(att);
							this.SetValidationCSS(e, 1);
							icon.className = "Btn-icon btn-i-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 = "Btn-icon btn-i-false";
							Ext.getDom("Wrong" + e.name).innerHTML = strWrongEmailText;
						}else{
							HL.SubmitForm(att);
							this.SetValidationCSS(e, 1);
							icon.className = "Btn-icon btn-i-true";
							wrongtxt.innerHTML = '';
						}
					
						break;	
					default:
						HL.SubmitForm(att);
						
				}
			}


			
		},
		
		
		SecondHandSetProductType: function(e, issearch){
			Ext.get("GearBrandIdDiv").load({
					url: "/secondhand/json/brands/",
					scripts: true,
					params: {
						producttypeid: e.value,
						issearch: issearch
					},
					text: strLoadingText
			});
			
			if(issearch){
				if(e.value == 2 || e.value == 3){
					Ext.get("GearSizeIdTable").applyStyles({display:"none"});
				}else{
					Ext.get("GearSizeIdTable").applyStyles({display:"block"});
				}
				
				if(e.value == 3){
					Ext.get("GearTypeIdTable").applyStyles({display:"none"});
				}else{
					Ext.get("GearTypeIdTable").applyStyles({display:"block"});
				}
			}else{
			
				if(e.value == 3){
					Ext.get("GearSizeIdTable").applyStyles({display:"none"});
				}else{
					Ext.get("GearSizeIdTable").applyStyles({display:"block"});
				}
			}
			
			
			
			if(!issearch){
				Ext.get("ProductInfo").applyStyles({display:"block"});
				Ext.get("GearBuildYearDiv").update(strFirstSelectABrandTypeTitle);
				Ext.get("GearSizeDiv").update(strFirstSelectAYearTitle);
			}
			Ext.get("GearTypeIdDiv").update(strFirstSelectABrandTitle);
			
			
			
			
		
		},
		
		SecondHandSetProductBrand: function(e){
			Ext.get("GearTypeIdDiv").load({
					url: "/secondhand/json/types/",
					scripts: true,
					params: {
						brandid: e.options[e.selectedIndex].value,
						producttypeid: e.getAttribute("producttypeid")
					},
					text: strLoadingText
			});
			
			
			Ext.get("GearBuildYearDiv").update(strFirstSelectABrandTypeTitle);
			Ext.get("GearSizeDiv").update(strFirstSelectAYearTitle);
			
			
			//if misc dan alle velden meteen beschikbaar, want daar bestaat geen database van
			if(e.getAttribute("producttypeid") == 3){
				HL.SecondHandSetProductBrandType(e);
			}
			
		},
		
		SecondHandSetProductBrandType: function(e){
			Ext.get("GearBuildYearDiv").load({
					url: "/secondhand/json/years/",
					scripts: true,
					params: {
						brandtypeid: e.options[e.selectedIndex].value,
						brandid: e.getAttribute("brandid"),
						producttypeid: e.getAttribute("producttypeid")
					},
					text: strLoadingText
			});
			
			Ext.get("GearSizeDiv").update(strFirstSelectAYearTitle);
			
		},
		
		SecondHandSetProductBrandTypeSizes: function(e){
			Ext.get("GearSizeDiv").load({
					url: "/secondhand/json/sizes/",
					scripts: true,
					params: {
						itemid: e.options[e.selectedIndex].getAttribute("ItemId")
					},
					text: strLoadingText
			});
		},
		
		
		
		CloseUpdateDiv : function(){
			Ext.get("Update-Div").remove();
		},
		AdminSelectAUser: function(){
			document.location = Ext.getDom("SelectAUser").options[Ext.getDom("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");
		},
			
			
		ShowHotSpotOnMap: function(e){
			map.setCenter(new GLatLng(e.getAttribute("lat"), e.getAttribute("lng")), 15);
		},	
		
		initGoogleMap : function(m){
	
			HL.StrEmpty(m.zoom)? m.zoom = 6 : '';
			
			var gMarkers = [];
			var pList = [];
			var POIMarkers = [];
			var newPolygon = null;
			var spotadmintype = '';
			
			
			map = new GMap2(Ext.getDom("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 sessionicon = new GIcon();
			sessionicon.image = "/media/template/map/kitesession.png"; 
			sessionicon.iconSize = new GSize(20, 20);
			sessionicon.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.iconSize = new GSize(32, 37);
			POIicon.iconAnchor = new GPoint(8, 8);
			
			var SmallPOIicon = new GIcon();
			SmallPOIicon.iconSize = new GSize(24, 26);
			SmallPOIicon.iconAnchor = new GPoint(8, 8);
			
			var Hoticon = new GIcon();
			Hoticon.iconSize = new GSize(32, 37)
			Hoticon.iconAnchor = new GPoint(16, 37);
		
			
		
			setPOIIcon = function(m){
				var p = new GLatLng(m.Lat, m.Lng);
				var icon = new GIcon(POIicon);
				icon.image = "/media/icons/48/poitype" + m.POITypeId + ".png"; 
				
				if(p.lat() != 0 || p.lng() != 0){
					var marker = new GMarker(p, icon);
					marker.POIId = m.POIId;
					
					GEvent.addListener(marker,"mouseover", function(marker) {     
						Ext.getDom("POI").innerHTML = m.Name;
					});
					
					GEvent.addListener(marker,"mouseout", function(marker) {     
						Ext.getDom("POI").innerHTML = '&nbsp;';
					});
					
					GEvent.addListener(marker,"click", function(marker) {     
						SetPOI2Item(m);
					});
					
					map.addOverlay(marker);
				
				}
			}
			
			
			setSmallPOIIcon = function(m){
				var p = new GLatLng(m.lat, m.lng);
				var icon = new GIcon(SmallPOIicon);
				icon.image = "/media/icons/48/poitype" + m.poitypeid + ".png"; 
				if(p.lat() != 0 || p.lng() != 0){
					var marker = new GMarker(p, icon);
					
					
					return marker;
				
				}
			}
			
			
			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) {     
						Ext.getDom("weatherstation").innerHTML = mark.stationname;
					})
					GEvent.addListener(marker,"mouseout", function(marker) {     
						Ext.getDom("weatherstation").innerHTML = '';
					})
					
					
					
					if(!HL.StrEmpty(interactive)){
						
					
						GEvent.addListener(marker,"click", function(marker) {     
							Ext.getDom("WindFinderId").value = mark.windfinderid;
						
							for(var j=0; j<gMarkers.length; j++){
								if(gMarkers[j].id == Ext.getDom("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 == Ext.getDom("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;
				}
			};
			
			setSessionIcon = function(m){
				var p = new GLatLng(m.lat, m.lng);
				var icon = new GIcon(sessionicon);
				var marker = new GMarker(p, icon);
				return marker;

			};
			

			setHotIcon = function(hs){
					var p = new GLatLng(Number(hs.lat), Number(hs.lng));
					var icon = new GIcon(Hoticon);
					icon.image = "/media/icons/48/hot" + hs.companytypeid + ".png"; 
					if(p.lat() != 0 || p.lng() != 0){
						var marker = new GMarker(p, icon);
						
						GEvent.addListener(marker,"mouseover", function(marker) {     
							Ext.get("HotSpotTitle" + hs.itemid).addClass("TitleHot");
						});
						
						GEvent.addListener(marker,"mouseout", function(marker) {     
							Ext.get("HotSpotTitle" + hs.itemid).removeClass("TitleHot");
						});
						
						
						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.Title;
					
					
					
					
					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);
					Ext.getDom(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());
				
			};
			
			
			setPOIInBoundry = 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, '');
					
					Ext.Ajax.request({
						url: '/json/pointofinterest/',
						method: 'GET',
						params:{
							s: s,
							w: w,
							n: n,
							e: e	
						},
						success: function ( result, request ) { 
		 
							var jsonData = Ext.util.JSON.decode(result.responseText);
							for(var i=0; i<jsonData.Data.length; i++){
								var e = jsonData.Data[i];
								e.ItemId = m.ItemId
								setPOIIcon(e);
								
							}
							
						}
					});	
			}
			
			
			switch(String(m.scripttype).toLowerCase()){
				case "adminhot":
					map.clearOverlays();
					if(HL.StrEmpty(m.lat)){
						map.setCenter(new GLatLng(Number(m.countrylat), Number(m.countrylng)), Number(7));
					}
					
					var marker2 = setHotIcon(m);
					map.addOverlay(marker2);
					
					GEvent.addListener(map, "click", function(marker, point) {
						map.clearOverlays();
						m.lat = point.lat();
						m.lng = point.lng();
						
						var marker = setHotIcon(m);
						map.addOverlay(marker);
						
						Ext.getDom("Lat").value = point.lat();
						Ext.getDom("Lng").value = point.lng();										 
					});
					break;
				case "adminpoi":
					map.clearOverlays();
					
					map.setZoom(10);
					marker = setSpotIcon(m);
					map.addOverlay(marker);
					
					
					setPOIInBoundry();
					
					GEvent.addDomListener(map, "moveend", function() {
						map.clearOverlays();
						setPOIInBoundry(m);											 
					});
					
					
					break;
				case "adminweathermap":	//admin kitespot voor weatherspot
					map.clearOverlays();
					
					map.setZoom(10);
					marker = setSpotIcon(m);
					map.addOverlay(marker);
					 
					
					Ext.Ajax.request({
						url: "/xml/markers.xml",
						method: 'GET',
						success: function ( result, request ) { 
		 					var xml = result.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(){
						map.clearOverlays();	
						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, '');
	
	
						Ext.Ajax.request({
							url: "/kitespot/selectbycountry/json/",
							params:{
								s: s,
								e: e,
								w: w,
								n: n
							},
							method: 'POST',
							success: function ( result, request ) { 
								var jsonData = Ext.util.JSON.decode(result.responseText);
								
								if(jsonData.Data.length > 0){
									for(var i=0; i<jsonData.Data.length; i++){
										var e = jsonData.Data[i];
										var spot = {};
										spot.name = e.spotname;
										spot.windspeedtitle = e.windspeedtitle;
										spot.winddirectiontitle = e.winddirectiontitle;
										spot.lat = e.lat;
										spot.lng = e.lng;
										spot.winddirection = e.winddirection;
										spot.windspeed = e.windspeed;
										spot.isoktokite = e.isoktokite;
										spot.windcolor = e.windcolor;
										spot.url = e.url;
										
										
										
										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)){												
												Ext.getDom("Spotname").innerHTML = this.name + ' (' + this.windspeedtitle + ': ' + this.windspeed + 'knts. ' +  this.winddirectiontitle + ': ' + String(this.winddirection).toUpperCase() + ')';
											}else{
												Ext.getDom("Spotname").innerHTML = this.name;
											}
										});
										
										GEvent.addListener(marker,"mouseout", function(marker) {  
											Ext.getDom("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();
							
							
							Ext.Ajax.request({
									url: '/kitespot/activecountries/data/',
									method: 'POST',
									success: function ( result, request ) { 
										var jsonData = Ext.util.JSON.decode(result.responseText);
										for(var i=0; i<jsonData.Data.length; i++){
											var m = jsonData.Data[i];
											marker = setCountryIcon(m);
											
											GEvent.addListener(marker,"click", function(marker) {     
												oldzoom = zoomSpots;
												map.setZoom(zoomSpots + 1);
												map.setCenter(new GLatLng(this.lat,this.lng)); 
											})
											
											GEvent.addListener(marker,"mouseover", function(marker) {     
												Ext.getDom("Spotname").innerHTML = this.countryname;
											});
											
											GEvent.addListener(marker,"mouseout", function(marker) {     
												Ext.getDom("Spotname").innerHTML = '';
											});
											
											map.addOverlay(marker);
										}
									}
								});	
							
							
						}
					}
										
							var newzoom = map.getZoom();
							var oldzoom = '';

							if(m.zoom > zoomSpots){ 
								setSpots();
							}else{
								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);
					
					
					//hotspots
					if(m.hotspots){
						for(var j=0; j<m.hotspots.length; j++){
							var hs = m.hotspots[j];					
								var marker = setHotIcon(hs);
								map.addOverlay(marker);	
						}
					}
					

					//pois
					if(m.pois){
						for(var j=0; j<m.pois.length; j++){
							var poi = m.pois[j];		
										
							var marker = setSmallPOIIcon(poi);
							map.addOverlay(marker);	
						}
					}
					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);
						
						
						
						Ext.getDom("lat").setAttribute("value", point.lat());
						Ext.getDom("lng").setAttribute("value", point.lng());

					});
					break;
				
				case "smallkitesessionmap":
					map.setMapType(G_HYBRID_MAP);
					map.clearOverlays();
					if(!HL.StrEmpty(m.lat) && !HL.StrEmpty(m.lng)){
						marker = setSessionIcon(m);
						map.addOverlay(marker);
					}

					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);
						
				//		Ext.getDom("Lat").value = point.lat();
				//		Ext.getDom("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);
						Ext.getDom("Lat").value = point.lat();
						Ext.getDom("Lng").value = point.lng();										 
					});
					break;
				
				case "allcountriesadmin":	//shows all the countries, in admin
					map.clearOverlays();

					Ext.Ajax.request({
						url: '/admin/kitespot/country/alljson/',
						method: 'GET',
						success: function ( result, request ) { 
		 
							var jsonData = Ext.util.JSON.decode(result.responseText);
							for(var i=0; i<jsonData.Data.length; i++){
								var e = jsonData.Data[i];
								var m = [];
								m.CountryCode = e.CountryCode;	
								m.Title = e.Name;	
								m.Lat = e.Lat;	
								m.Lng = e.Lng;	
								var marker = setCountryIcon(m);
								map.addOverlay(marker);
								
							}
							
						}
					});	
					
					
					
					break;
				
				case "allweatherstations":	//in admin
					map.clearOverlays();
					Ext.Ajax.request({
						url: "/xml/markers.xml",
						method: 'GET',
						success: function ( result, request ) { 
		 					var xml = result.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;
					
					
					
					
					
			}
			
			

			
		}
		
		
			
	};
	
	
	
	
}();




Ext.onReady(function(){
		
		
		
		if(Ext.form.DateField){
			Ext.apply(Ext.form.DateField.prototype, {
				format				: "d/M/Y",
				valueFormat 		: "d/M/Y",
				altFormats			: "d/m/Y|j/n/Y|j/m/Y|d/n/Y",
				submitFormat		: "dMY",
				beforeBlur			: function(){
					var v = this.parseDate(this.getRawValue(), "dMY");
					if(v){
						this.setValue(v);
					}
				}
			});
		}
	})


