/*
* Add here new js. Change other js only if required.
*/ 
var resCache = new Hash();
var MIN_CHAR_INPUT = 3;
var ownLocationSearch = false;
var ESC=27; var TAB=9; var ALT=18; var UP=38; var DOWN=40; var LEFT=37; var RIGHT=39; var ENTER=13; var SHIFT=16; var DEL=46; var BACKSPACE=8;

//1
var mpbTemplate = "<table id='mpb' class='hoverpop' cellspacing='0' cellpadding='0'>" +
	"<tr><td class='tl'></td><td class='t'></td><td class='tr'></td></tr>" + 
	"<tr><td class='l'></td><td class='content'></td><td class='r'></td></tr>" +
	"<tr><td class='bl'></td><td class='b' align='center'></td><td class='br'></td></tr></table>";
//2
var mdaTemplate = "<table id='mda' class='hoverpop' cellspacing='0' cellpadding='0'>" +
"<tr><td class='dacontent'></td></tr></table>";
//3
var popupTemplate = "<table id='pop' class='hoverpop' cellspacing='0' cellpadding='0'>" +
	"<tr><td class='tl'></td><td class='t'></td><td class='tr'></td></tr>" + 
	"<tr><td class='l'></td><td class='content'></td><td class='r'></td></tr>" +
	"<tr><td class='bl'></td><td class='b' align='center'></td><td class='br'></td></tr></table>";

//4

jQuery.fn.maxlength = function(){
	 $("textarea[@maxlength]").keypress(function(event){
		 var key = event.which;
		 //all keys including return.
		 if(key >= 33 || key == 13) {
			 var maxLength = $(this).attr("maxlength");
			 var length = this.value.length;
			 if(length >= maxLength) {
				 event.preventDefault();
			 }
		 }
	 });
};

function removeTomTomRouteBox(event){
	if ($(event.target).parents(".tomTomRouteBox").length < 1) {
		$(".tomTomRouteBox").remove();
		$(document).unbind("click", removeTomTomRouteBox);
	}
};

function submitTomTomRoute() {
	if ($(".tomTomRouteBox .routeLocation").val().length > 0) {
		var url = $(".tomTomRouteBox form").attr("action");
		$(".tomTomRouteBox form").attr("action", url.replace("/home/", "/" + $(".tomTomRouteBox .routeLocation").val() + "/"));
		
		setTimeout(function() {
			$(".tomTomRouteBox").remove();
			$(document).unbind("click", removeTomTomRouteBox);
		}, 1000);
	}
};
function submitTomTomRouteLink() {
	if ($(".tomTomRouteBox .routeLocation").val().length > 0) {
		var url = $(".tomTomRouteBox form").attr("action");
		$(".tomTomRouteBox form").attr("action", url.replace("/home/", "/" + $(".tomTomRouteBox .routeLocation").val() + "/"));
		$(".tomTomRouteBox form").submit();
		
		setTimeout(function() {
			$(".tomTomRouteBox").remove();
			$(document).unbind("click", removeTomTomRouteBox);
		}, 1000);
	}
	return false;
};

$(document).ready(function(){	
	
	var ua = navigator.userAgent.toLowerCase();
	if ( ua.indexOf( "msie" ) != -1 ) {
		$("#addfavimag").show();
		$("#addfavtext").show();
	}
	if (navigator.userAgent.indexOf("Windows NT 6.0") != -1) {
		$("#vistaimag").show();
	}
	if (navigator.platform.indexOf("Mac") != -1) {
		$("#appleimag").show();
	}
	
	registerSignup();
	registerLogin();
	registerSendLink();
	registerLinkToPage();
	loadAutoLocationSuggest();
	
	//added for forget password new link
	$(".forgotUsernameNew").click(function() {
		$.ajax({
			url: "/ajax/forgot.jsp",
			type: "POST",
			success: function(html){
				$("#loginPopupNew .loginBox").css( {"margin-top":"-110px","margin-left":"132px"});
				$("#loginPopupNew .loginBox").css( {"position":"absolute"});
				$("#loginPopupNew .loginBox").css( {"width":"360px"});
				$("#loginPopupNew").show();
				$("#loginPopupNew").attr("name", "hover");
				$("#loginPopupNew .loginBox").html(html);
				ilLog('forgotpassword', 0, '-1',-1,-1,-1,'');	
				$("form.forgotUser .forgotBtn").click(function() { submitForgot(); });
			}
		});
	});
	
	$("#loginPopupNew").hover(function() {
		$("#loginPopupNew").attr("name", "hover");
	}, function() {
		$("#loginPopupNew").attr("name", "nohover");
		$("body").one("click", function() {
			if ($("#loginPopupNew").attr("name") == "nohover") {
				$("#loginPopupNew").hide("fast");
			}
		});
	});
	
	$(".tomTomRoute").click(function() {
		var offset = $(this).offset();
		$.ajax({
			url: "/ajax/tomtomroutebox.jsp",
			type: "POST",
			data: ({
				url : $(this).attr("href")
			}),
			success: function(html){
				$(".tomTomRouteBox").remove();
				$("body").append(html);
				$(".tomTomRouteBox").css("top", offset.top + "px");
				$(".tomTomRouteBox").css("left", offset.left + "px");
				
				$(".tomTomRouteBox form").submit(submitTomTomRoute);
				$(".tomTomRouteBox .planRouteButton").click(submitTomTomRouteLink);
				
				$(document).click(removeTomTomRouteBox);
			}
		});
		return false;
	});
	
	$(".showmorereview").click(function (){
		$(".showmorereview").hide();
		$(".hidemorereview").show();
		$(".otherReview").show();
	});
	$(".hidemorereview").click(function (){
		$(".otherReview").hide();
		$(".hidemorereview").hide();
		$(".showmorereview").show();
	});
	
	$(".phonelink").click(function() {
		$("#phone_" + $(this).attr("name") + "_a").hide();
		$("#phone_" + $(this).attr("name")).css("display", "inline");
	});
 
	if($("#centralLocDesc STRONG").html() != null && $("#centralLocDesc STRONG").html().length > 38){
		var centralLocDesc = $("#centralLocDesc STRONG").html().substring(0,38)+"..";
		$("#centralLocDesc STRONG").html(centralLocDesc);
	}

	$(".searchTerm").focus(function() {
		if ($(this).css("font-style") != "normal") {
			$(this).val("");
			$(this).css("font-style", "normal");
			$(this).css("color", "#000");
		}
	});
	$(".zipChange").click(function () {
		$("#userloc").remove();
		loadChangeLoc();
	});
	
	//generateVEToken();
	
	 $("#closeInfBar").click(function() {
		 $(".inf-bar").hide();
	 });
	 
	//functions for shopping guide create pages
	$("#btn-continue").click(function() { 
		ilLog('shoppingguide.create.save.click', 0, '-1',-1,-1,-1,'');
		makeShoppingGuide();
	});
	
	$("#linktosignup").click(function() {
		$("#login-area").hide();
		$("#signup-area").show();
		ilLog('registerprofile.form', 0, '-1',-1,-1,-1,'');
		
	});
	
	$(".login-submit").click(function() {
		ilLog('login.save.click', 0, '-1',-1,-1,-1,'');
		
		$.ajax({ 
			url: "/login",
			type: "POST",
			data: "pass="+$("#inp-password").val()+"&mail="+$("#inp-email").val(),
			success: function(returnValue) {
				if (returnValue.indexOf("ok")>-1){
					makeShoppingGuide();
				} else {
					ilLog('login.error', 0, '-1',-1,-1,-1,'');	
					$("#errormessageshowerror").show();
					
					var errorPageUrl = "/ajax/showerror.jsp?msg=" + returnValue;
					if (returnValue.indexOf("expired.account") > -1) {
						errorParams = returnValue.split("#");
						errorPageUrl = "/ajax/showerror.jsp?msg=" + errorParams[0] + "&userId=" + errorParams[1] + "&mail=" + errorParams[2];
					} 
					
					$("#errormessageshowerror").load(errorPageUrl);			
				}
			}
		});
	});
	
	$(".signup-submit").click(function() {
		ilLog('shoppingguide.create.save.click', 0, '-1',-1,-1,-1,'');
		ilLog('registerprofile.register.save.click', 0, '-1',-1,-1,-1,'');
		
		$.ajax({ 
			url: "/login/signup",
			type: "POST",
			data: "name="+$("#inp-name").val()+"&mail="+$("#inp-email-signup").val()+"&pass="+$("#inp-password-signup").val()+"&pass2="+$("#inp-repeate-password").val(),
			success: function(returnValue) { 
				if (returnValue.indexOf("ok")>-1) {
					returnValue = trim(returnValue);
					returnvalues = returnValue.split("//");
					$.cookie("il_sg_title", $("#sgtitle").val(), { path: '/'});
					$.cookie("il_sg_desc", $("#sgdescription").val(), { path: '/'});
					$.cookie("il_sg_cid", $("#cid").val(), { path: '/'});
					if($("#cb-item-01").attr("checked")){
						$.cookie("il_sg_recentcid1", $("#cb-item-01").val(), { path: '/'});
					} else {
						$.cookie("il_sg_recentcid1", "", { path: '/'});
					}
					if($("#cb-item-02").attr("checked")){
						$.cookie("il_sg_recentcid2", $("#cb-item-02").val(), { path: '/'});
					} else {
						$.cookie("il_sg_recentcid2", "", { path: '/'});
					}
					$.cookie("il_sg_cdesc", $("#companyDesc").val(), { path: '/'});
					$.cookie("il_sg_owner", returnvalues[1], { path: '/'});
					
					window.location = "/shoppingguide?id=-1&su=0";
				} else {
					ilLog('registerprofile.register.error', 0, '-1',-1,-1,-1,'');
					ilLog('shoppingguide.create.error', 0, '-1',-1,-1,-1,'');
					
					$("#errormessageshowerror").show();
					$("#errormessageshowerror").load("/ajax/showerror.jsp?msg=" + returnValue);
				}
			}
		});
	});
	
	$("#inp-name").focus(function() {
		if ($("#inp-email-signup").val() != null && $("#inp-email-signup").val().indexOf("@") > 0) {
			$("#inp-name").val($("#inp-email-signup").val().split("@")[0]);
		}
	});	
	
	$("#sgtitle, #sgdescription, #sgCompanyDesc").focus(function() {
		if ($(this).css("font-style") == "italic") {
			$(this).val("");
			$(this).css("font-style", "normal");
			$(this).css("font-size", "11px");
			$(this).css("color", "#000000");
		}	
	});
	
	//End -- functions for shopping guide create pages
	//functions for shopping guide detail page
	$(".phone_label").click(function() {
		$(this).hide();
		$(this).parents(".toolbar").find(".phone_nr").css("display", "inline");;
		return false;
	});
	
	$("#changeSG").click(function() {
		$("#sendSG").hide();
		$("#deleteSG").hide();
		$("#newSgBody").val($("#sgBody").html());
		$("#newSgBody").css("font-style", "normal");
		$("#editSgBody").show();
		$("#sgBody").hide();
		$("#changeSG").hide();
		$("#saveSG").show();
		$("#editSgTitle").show();
		$(".btn").show();
		return false;
	});
	
	$("#addSgDesc").click(function() {
		$("#editSgBody").show();
		$("#addSgDescTools").show();
		$(".tools").hide();
	});
	
	$("#cancelAddSgDesc").click(function() {
		location.reload(true);	
	});
	
	$("#btn-cancel").click(function() {
		location.reload(true);	
	});
	
	$("#newSgBody").focus(function(){
		if ($(this).css("font-style") == "italic") {
			$(this).css("font-style","normal");
			$(this).css("color", "black");
			$(this).val("");	
		}
	});
	
	$("#btn-save").click(function(){
		ilLog('shoppingguide.editdescription.save.click', 0, '-1',-1,-1,-1,'');
		var id = $("#sgid").val();
		var description = $("#newSgBody").val();
		var title = $("#newSgTitle").val();
		
		if (id != "" && id != null && title != "" && $("#newSgBody").css("font-style") != "italic") {
			var descriptionSent = description.replace(/([^\x01-\x7E])/g,function(word){return'&#'+word.charCodeAt(0)+ ';';});
			var titleSent = title.replace(/([^\x01-\x7E])/g,function(word){return'&#'+word.charCodeAt(0)+ ';';});
			$.ajax({ 
				url: "/shoppingguide/premoderate",
				type: "POST",
				data: "text=Title: " + title +" Shopping Guide description: " +description,
				success: function(returnValue) { 
					if (returnValue.indexOf("ok") > -1) {
						//$("#formShoppingGuide").submit();
						$.ajax({
							url: "/shoppingguide/edit",
							type: "POST",
							data: "title=" + escape(titleSent) + "&description=" + escape(descriptionSent) + "&id=" + $("#sgid").val(),
							success: function(returnValue) {
								if (returnValue.indexOf("ok") > -1) {
									window.location = "/shoppingguide?id="+$("#sgid").val()+"&editfeedback=updated";
								} else {
									ilLog('shoppingguide.editdescription.error', 0, '-1',-1,-1,-1,'');
								}
							}
						});
					} else {
						ilLog('shoppingguide.editdescription.error', 0, '-1',-1,-1,-1,'');
						$("#sginfoerror").html(returnValue);
						$("#sginfoerror").show();
					}
				}
			});
		} else {
			ilLog('shoppingguide.editdescription.warning', 0, '-1',-1,-1,-1,'');
			if (title == "") {
				$("#sginfoerror-emptytitle").show();
			}
		}
		
		return false;
	});
	
	$("#submitAddSgDesc").click(function(){ 
		ilLog('shoppingguide.editdescription.save.click', 0, '-1',-1,-1,-1,'');
		var id = $("#sgid").val();
		var description = $("#newSgBody").val();
		
		if (id != "" && id != null && $("#newSgBody").css("font-style") != "italic") {	
			var descriptionSent = description.replace(/([^\x01-\x7E])/g,function(word){return'&#'+word.charCodeAt(0)+ ';';});

			$.ajax({ 
				url: "/shoppingguide/premoderate",
				type: "POST",
				data: "text=Shopping Guide description: " +description,
				success: function(returnValue) { 

					if (returnValue.indexOf("ok") > -1) {
						$.ajax({
							url: "/shoppingguide/edit",
							type: "POST",
							data: "title=&description=" + escape(descriptionSent) + "&id=" + $("#sgid").val(),
							success: function(returnValue) {
								if (returnValue.indexOf("ok") > -1) {
									window.location = "/shoppingguide?id="+$("#sgid").val()+"&editfeedback=updated";
								} else {
									ilLog('shoppingguide.editdescription.error', 0, '-1',-1,-1,-1,'');
								}
							}
						});
					} else {
						ilLog('shoppingguide.editdescription.error', 0, '-1',-1,-1,-1,'');
						$("#sginfoerror").html(returnValue);
						$("#sginfoerror").show();
					}
				}
			});
		} else {
			ilLog('shoppingguide.editdescription.warning', 0, '-1',-1,-1,-1,'');
			if (title == "") {
				$("#sginfoerror-emptytitle").show();
			}
		}
		
		return false;
	});
	
	$(".sgCompanyChange a").click(function() {
		$(this).parents(".description").find(".description-show").hide();
		$(this).parents(".description").find(".sgCompanyChange").hide();
		$(this).parents(".description").find(".sgCompanySeperator").hide();
		$(this).parents(".description").find(".sgCompanyDelete").hide();

		$(this).parents(".description").find(".description-edit").show();
		$(this).parents(".description").find(".sgCompanyChangeSubmit").show();
		$(this).parents(".description").find(".sgCompanyCancel").show();
		$(this).parents(".description").find(".sgCompanyGetReview").show();
		
		
		return false;
	});
	$(".sgCompanyCancel a").click(function() {
		$(this).parents(".description").find(".description-show").show();
		$(this).parents(".description").find(".sgCompanyChange").show();
		$(this).parents(".description").find(".sgCompanySeperator").show();
		$(this).parents(".description").find(".sgCompanyDelete").show();

		$(this).parents(".description").find(".description-edit").hide();
		$(this).parents(".description").find(".sgCompanyChangeSubmit").hide();
		$(this).parents(".description").find(".sgCompanyCancel").hide();
		
		return false;
	});
	$(".sgCompanyGetReview a").click(function() {
		var companyId = $(this).parents(".companyDetail").find(".companyid").attr("name");
		var getReview = $("#getreview_"+companyId).val();
		var descriptionField = $(this).parents(".companyDetail").find(".description-edit");
		descriptionField.val('"'+ getReview + '"');
		descriptionField.css("font-style", "normal");
		
	});
	$(".description-edit").focus(function() {
		if ($(this).css("font-style") == "italic") {
			$(this).css("font-style", "normal");
			$(this).css("color", "black");
			$(this).val("");
		}
	});
	
	$(".addCompanyDesc a").click(function() {
		$(this).hide();
		$(this).parents(".description").find(".sgCompanyDelete").hide();
		$(this).parents(".description").find(".sgCompanyChangeSubmit").show();
		$(this).parents(".description").find(".addCompanyDescCancel").show();
		$(this).parents(".description").find(".description-edit").show();
	});
	
	$(".addCompanyDescCancel").click(function() {
		location.reload(true);
	});
	
	$(".sgCompanyChangeSubmit a").click(function() {
		var shoppingGuideId = $("#sgid").val();
		var companyId = $(this).parents(".companyDetail").find(".companyid").attr("name"); 
		var description = $(this).parents(".companyDetail").find(".description-edit").val();
		var fontStyle = $(this).parents(".companyDetail").find(".description-edit").css("font-style");
		var descriptionSent = description.replace(/([^\x01-\x7E])/g,function(word){return'&#'+word.charCodeAt(0)+ ';';});
		
		if (shoppingGuideId != "" && shoppingGuideId != null && companyId != null && companyId !="" && description != "" && description != null && fontStyle != "italic") {
			var data = "text="+description;
			$.ajax({ 
				url: "/shoppingguide/premoderate",
				type: "POST",
				data: data,
				success: function(returnValue) { 
					if (returnValue.indexOf("ok") > -1) {
						$.ajax({
							url: "/shoppingguide/company/description",
							type: "POST",
							data: "shoppingGuideId="+shoppingGuideId+"&companyId="+companyId+"&description="+escape(descriptionSent),
							success: function(returnValue) {
								if (returnValue.indexOf("ok") > -1) {
									ilLog('shoppingguide.editcompany.save', 0, '-1',-1,-1,-1,''); 
									window.location = "/shoppingguide?id="+$("#sgid").val()+"&editfeedback=updated";
								} else {
									ilLog('shoppingguide.editcompany.error', 0, '-1',-1,-1,-1,''); 
								}
							}
						});
					} else {
						ilLog('shoppingguide.editcompany.error', 0, '-1',-1,-1,-1,''); 
						$("#cinfoerror_"+companyId).html("Er klopt iets niet. Pas dit aan en probeer nog eens.");
						$("#cinfoerror_"+companyId).show();
					}
				}
			});
		} else {
			ilLog('shoppingguide.editcompany.warning', 0, '-1',-1,-1,-1,''); 
/* don't remove this code
			$(this).parents(".description").find(".description-show").show();
			$(this).parents(".description").find(".sgCompanyChange").show();

			$(this).parents(".description").find(".description-edit").hide();
			$(this).parents(".description").find(".sgCompanyChangeSubmit").hide();
			$(this).parents(".description").find(".sgCompanyCancel").hide();
*/
		}
		
		return false;
	});
	
	//End -- functions for shopping guide detail page
	//add company into a shopping guide
	$(".shoppingguidetitle").click(function(){
		var sgId = $(this).attr("name");
		$.ajax({ 
			url: "/shoppingguide/company/add",
			type: "POST",
			data: "shoppingGuideId="+sgId+"&companyId="+$("#sgcid").val(),
			success: function(returnValue) { 
					if (returnValue.indexOf("ok") > -1) {
						returnValue = trim(returnValue);
						var sgId = returnValue.substring(3);
						var url = "/shoppingguide?id="+sgId;
						$("#success").html("Bedankt! We hebben je een mail gestuurd, bevestig door op de likn te klikken. <a href ="+url+">Click Here></a>");
						$("#success").show();
						$("#shoppingguidelink").hide();
					} else {
						$("#ErrorMessage").html("*ERROR: " + returnValue);
						$("#ErrorMessage").show();
					}
			}
		});
		
	});
	$(".selectshoppingguide").click(function(){
		$("#popup-list").hide();
		$("#sgId").val($(this).attr("name"));
		$("#nameselectedsg").html($("#"+$(this).attr("name")+"-name").html());
		$("#popup1").show();
		return false;
	});

	var _btPopup = $('div.popup-holder a.open');
	var _popup = $('div.popup-normal');
	var _btPopupInnerLink = $('div.popup-list a');
	var _popupList = $('div.popup-list');
	var _popupCancel = $('#btn-cancel-popup');
	var _popupAdd = $('#btn-add');	
	var _id;
	
	_btPopup.click(function(){
		_popup.css("top", ($(this).offset().top + 10) + "px");
		_popup.css("left", $(this).offset().left);

		if($("#hyvesCreateTip").size() > 0 ) {
			Hyves.connect.tip({title: $(".title-area .holder h1").html(), body:'Ik tip dit bedrijf vanwege...\n\nMeer info op [url=' + window.location.href + ']ilocal.nl[/url]', category:'12'}, null, 'hyvesCreateTip');
			$("#hyvesCreateTip a").html("Voeg toe als Hyves tip");
			$("#hyvesCreateTip a").click(function() {
				$("#close_popup").click();
				ilLog('results.addtohyves', 19, $("#companyId").val(),-1,-1,-1,'');
			});
		}
		
		_popup.show();
		_popupList.show();
		return false;
	});
	$("#addToShoppingGuide, #shoppingguidelink2 a").click(function() {
		_popup.css("top", ($(this).offset().top + 10) + "px");
		_popup.css("left", $(this).offset().left);
		
		if($("#hyvesCreateTip").size() > 0 ) {
			Hyves.connect.tip({title: $(".title-area .holder h1").html(), body:'Ik tip dit bedrijf vanwege...\n\nMeer info op [url=' + window.location.href + ']ilocal.nl[/url]', category:'12'}, null, 'hyvesCreateTip');
			$("#hyvesCreateTip a").html("Voeg toe als Hyves tip");
			$("#hyvesCreateTip a").click(function() {
				$("#close_popup").click();
				ilLog('results.addtohyves', 19, $("#companyId").val(),-1,-1,-1,'');
			});
		}
		
		_popup.show();
		_popupList.show();
		return false;
	});
	
	$(".results-add-sg").mouseover(function() {
		$('#lessSGs').show();
		$('#moreSGs').hide();
		$("#popup-sg").hide();
		$("#popup1").hide();
		
		_popup.css("top", ($(this).offset().top + 10) + "px");
		_popup.css("left", $(this).offset().left - 30);
		var cid = $(this).parents(".item").find(".company-id").attr("name");
		var ecid = $(this).parents(".item").find(".company-id").attr("value");
		var cname = trim($(this).parents(".item").find(".company-title").html());
		var caddress = $(this).parents(".item").find(".company-address").html();
		var csrc = $(this).parents(".item").find(".company-title").attr("href");
		
		$("#addToSgLink").attr("href", "/shoppingguide/create?cid="+cid+"&cname="+cname+"&caddress="+caddress);
		$("#sgcid").val(cid);
		$(".sg-company-name").html(cname);
		
		if($("#hyvesCreateTip").size() > 0 ) {
			Hyves.connect.tip({title: cname, body:'Ik tip dit bedrijf vanwege...\n\nMeer info op [url=http://www.ilocal.nl' + csrc + ']ilocal.nl[/url]', category:'12'}, null, 'hyvesCreateTip');	
			$("#hyvesCreateTip a").html("Voeg toe als Hyves tip");
			$("#hyvesCreateTip a").click(function() {
				$("#close_popup").click();
				ilLog('results.addtohyves', 19, ecid,-1,-1,-1,'');
			});
		}
		
		_popup.show();
		_popupList.show();
		return false;
	});
	$(".results-add-sg").click(function() { return false; });
	
	_btPopupInnerLink.click(function(){
		_id = $(this).attr('href');
		_id = _id.substr(_id.indexOf('#'));
		_popupList.hide();
		$(_id).show();
	});
	_popupCancel.click(function(){
		$("textarea[name='sgdescr']").val("");
		_popup.hide();
		$(_id).hide();
		return false;
	});
	_popupAdd.click(function(){
		var descr = $("textarea[name='sgdescr']").val();
		var companyName = $(".sg-company-name").html();
		var sgTitle = $("#nameselectedsg").html();
		var newHref = "";
		if (descr == ''){
			// add company to sg
			$.ajax({ 
				url: "/shoppingguide/company/add",
				type: "POST",
				data: "shoppingGuideId="+$("#sgId").val()+"&companyId="+$("#sgcid").val(),
				success: function(returnValue) { 
					if (returnValue.indexOf("ok") > -1) {
						ilLog('addtoshoppingguide.addcompany.save', 0, '-1',-1,-1,-1,'');
						returnValue = trim(returnValue);
						var sgId = returnValue.substring(3);	
						if (window.location.href.indexOf("addsg")>-1) {
							window.location = window.location.href.replace(/addsg(.)*/,"addsg="+sgId+"&sgcname="+companyName+"&sgtitle="+sgTitle);
						} else {
							if (window.location.href.indexOf("?")>-1) {
								newHref = window.location.href.replace(/#(.)*/, "");
								window.location = newHref + "&addsg="+sgId+"&sgcname="+companyName+"&sgtitle="+sgTitle;
								
							} else {
								newHref = window.location.href.replace(/#(.)*/, "");
								window.location = newHref + "?addsg="+sgId+"&sgcname="+companyName+"&sgtitle="+sgTitle;
							}
						}
					} else {
						ilLog('addtoshoppingguide.addcompany.error', 0, '-1',-1,-1,-1,'');
						$("#createError").html("*ERROR: " + returnValue);
						$("#createError").show();
					}
				}
			});
		} else {
			// check text
			ilLog('addtoshoppingguide.explination', 0, '-1',-1,-1,-1,'');
	
			$.ajax({ 
				url: "/shoppingguide/premoderate",
				type: "POST",
				data: "text="+descr,
				success: function(returnValue) { 
					if (returnValue.indexOf("ok") > -1) {
						addCompanyToSG(descr, sgTitle, companyName);
					} else {
						ilLog('addtoshoppingguide.addcompany.error', 0, '-1',-1,-1,-1,'');
						$("#createError").html(returnValue);
						$("#createError").show();
					}
				}
			});			
		}
	});
	
	$(".undoshoppingguide").click(function(){
		$("#popup1").hide();
		$("#popup-list").show();
		$("textarea[name='sgdescr']").val("");
	})
	

	//End -- functions for adding company into shopping guide
	
	$("#closeSgFeedback").click(function() {		
		if (window.location.href.indexOf("?addsg")>-1) {
			window.location = window.location.href.replace(/\?addsg(.)*/,"");
		} else if (window.location.href.indexOf("&addsg")>-1){
			window.location = window.location.href.replace(/&addsg(.)*/,"");
		} else if (window.location.href.indexOf("shoppingguide")>-1) {
			if ($("#sgid").val() != null && $("#sgid").val() != '') {
				window.location = "/shoppingguide?id="+$("#sgid").val();
			} else {
				window.location = "/shoppingguide?id=-1";
			}
		} else {
			$(".inf-bar").hide();
		}
		 return false;
	});
	
	$("#popDcFeedback").click(function() {
		$("#dcFeedback").css("top", $(this).offset().top + 13 + "px");
		$("#dcFeedback").css("left", $(this).offset().left - 383 + "px");
		$("#dcFeedback").css("position", "absolute");
		$("#dcFeedback").css("z-index", "1000");
		$("#dcFeedback").slideDown(200);
	})
	
	$("#closeDCFeedback").click(function() {
		$("#dcFeedbackMessage").hide();
		$("#dcFeedbackDetails").show();	
		$("#dcFeedbackContent").val("");
		$(".dcFeedbackOptionBox").attr("checked","");
		$("#dcFeedbackError").html("&nbsp;");
		$("#dcFeedback").css("height", "280px");
		$("#dcFeedback").slideUp(200);
	});
	
	$("#submitDcFeedback").click(function() {
		var content = "";
		var subject= "";
		if ($("#dcFeedbackOptionBox1").attr("checked")) {
			subject += $("#dcFeedbackOption1").html();
		} 
		if ($("#dcFeedbackOptionBox2").attr("checked")) {
			if (subject == "") {
				subject += $("#dcFeedbackOption2").html();
			} else {
				subject += " en " + $("#dcFeedbackOption2").html();
			}		
		}		
		content = $("#dcFeedbackContent").val();
		
		if (subject == "") {
			$("#dcFeedbackError").html("*Kies een onderwerp zodat we weten waar je reactie over gaat.");
		} else if (content == "") {
			$("#dcFeedbackError").html("*Vul je reactie in.");
		} else {	
			$.ajax({
				url: "/ilocal/beta/defeedback/send",
				type:"POST",
				data:"subject="+subject+"&content="+content,
				success:function(returnValue){
					$("#dcFeedback").css("height", "180px");
					$("#dcFeedbackDetails").hide();
					$("#dcFeedbackMessage").html(returnValue);
					$("#dcFeedbackMessage").show();
				}
			});
		}
		
	})
	
	//home page
	/*
	$(".info-blocks .bg-top .more").hover(function() {
			$(this).find("a").css("color", "#fff");		
			$(this).find("a").css("background", "url(../images/dc/ico-more.gif) no-repeat 100% 0");	
		}, function() {
			$(this).find("a").css("color", "#FF6600");		
			$(this).find("a").css("background", "url(../images/dc/ico-more-grey.gif) no-repeat 100% 0");	
	});
	*/
	//end home page
	
	$("#headerlocationrefine").click(function(){
		if ($(this).attr("name").indexOf("street_id") > -1) {
			ilLog("choosestreet_open", 0, '-1',-1,-1,-1,'');
		} else if ($(this).attr("name").indexOf("neighbourhood_id") > -1 ) {
			ilLog("chooseneighbourhood_open", 0, '-1',-1,-1,-1,'');
		} else if ($(this).attr("name").indexOf("district_id") > -1) {
			ilLog("choosedistrict_open", 0, '-1',-1,-1,-1,'');
		} else if ($(this).attr("name").indexOf("city_id") > -1 ) {
			ilLog("choosecity_open", 0, '-1',-1,-1,-1,'');
		} else if ($(this).attr("name").indexOf("province_id") > -1) {
			ilLog("chooseprovince_open", 0, '-1',-1,-1,-1,'');
		}
		
		$("#headerLRHolder").css("top", $(this).offset().top + 20 + "px");
		$("#headerLRHolder").css("left", $(this).offset().left - 10 + "px");
		
		$("#headerLRHolder").html("<div id='headerLRLeak'></div><div id='headerLR'><div id='headerLRClose' onclick='closeHeaderLRHolder();'/>"+$("#div_refine_loc").html().replace(/refine_loc/g, "header_loc")+"</div>");
		
		$("#headerLRHolder").show();
	});
	
	$("#resultsFeedback").click(function() {
		$("body").append("<div id='feedbackForm' />");
		$("#feedbackForm").load("/ajax/feedback.jsp");
		$("#feedbackForm").css("top", $(window).height()/2 - 190 + $(window).scrollTop() + "px");
		$("#feedbackForm").css("left", $(window).width()/2 - 300 + $(window).scrollLeft() + "px");
	});

	
	if ($("body").attr("class") != "home"){
		//Set maxlength of all the textarea (call plugin)  
		$().maxlength(); 
		$("img[@src$=.png], .searchbutton, .search-suggest td, #pb_nose").ifixpng();
	}
	
});
//END document ready function

function closeHeaderLRHolder() {
	$("#headerLRHolder").html("");
	$("#headerLRHolder").hide();
}

function hideMore(obj) {
	$("#" + $(obj).attr("name") + "_less").show();
	$("#" + $(obj).attr("name") + "_more").hide();
	$("#div_" + $(obj).attr("name")).css("visibility", "hidden");
	$("#top_" + $(obj).attr("name")).hide();
	$("#bottom_" + $(obj).attr("name")).hide();
}

function showMore(obj) {
	$("#" + $(obj).attr("name") + "_more").show();
	$("#" + $(obj).attr("name") + "_less").hide();
	$("#div_" + $(obj).attr("name")).css("visibility", "visible");
	$("#top_" + $(obj).attr("name")).show();
	$("#bottom_" + $(obj).attr("name")).show();
}

function addfav(){
   if (document.all){
	   window.external.AddFavorite(location.href, document.title);
      }
}	

//5
function loadSendToMobile(nr, cid, cname, top) {
	loadReviewBox();
	$("#reviewWindow").css("top", top + "px");
	setReviewLoading();

	$.ajax({
		url: "/ajax/sendtomobile.jsp",
		type: "POST",
		success: function(html){
			$("#reviewContainer").html(html);
			$("#reviewContainer span.cname").html(cname);
			$("#reviewWindow").show();
			
			ilLog('sendtomobile.open', 0, '-1',-1,-1,-1,'');

			loadSendToMobileSubmit(nr, cid, cname);
		}
	});
}

//7
function popupWindow(url, name, x, y, options) {
	var detailWindow = null;
 	try {
		var x_val = x, y_val = y;
		if(x_val==0){ x_val=800; }
		if(y_val==0){ y_val=600; }
		y_pos = (y_val-480)/2;
		if(detailWindow!=null && !detailWindow.closed){
			detailWindow.location.href = url;
		} else if(navigator.appVersion.toLowerCase().indexOf('msie')!= -1){
			x_pos =  (x_val-750)/2;
			detailWindow=window.open(url,name,'top='+y_pos+',screenY='+y_pos+',left='+x_pos+',screenX='+x_pos+',height='+y_val+',width='+x_val+','+options+'');
		} else {
			x_pos =  (x_val-760)/2;
			detailWindow=window.open(url,name,'top='+y_pos+',screenY='+y_pos+',left='+x_pos+',screenX='+x_pos+',height='+y_val+',width='+x_val+','+options+'');
		}
		if(navigator.platform == "Win32" && navigator.userAgent.toLowerCase().indexOf("MSIE 4.0") < 0){
			if (window.focus){ detailWindow.focus(); }
		}
	} catch(e){
		alert(e)
	}
}

//8
function registerLinkToPage() {
	$(".linktopage").click(function (){
		
		loadReviewBox();
		setReviewLoading();

		$.ajax({
			url: "/ajax/linktopage.jsp",
			type: "POST",
			success: function(html){
			
				var linkToPageUrl = window.location.href;
				linkToPageUrl = linkToPageUrl.replace(/\%20/, "+");
				linkToPageUrl = linkToPageUrl.replace(/#/, "");

				linkToPageCode = "<a href=\""+linkToPageUrl+"\" target=\"_blank\">" +
					"ilocal.nl</a>";

				$("#reviewContainer").html(html);

				$("#linkToPageUrl").val(linkToPageUrl);
				$("#linkToPageCode").val(linkToPageCode);
			}
		});
		
		ilLog('linktopage', 0, '',-1,-1,-1,'');
	});
}

//9
function registerSendLink() {
	$(".sendlink").click(function (){
		var offset = $(this).offset();
		var pageDetail = $(this).attr("name");
		$("body").css("pointer", "wait");
		$.ajax({
			url: "/ajax/sendlinkbox.jsp",
			type: "POST",
			data: ({
				mobileDetails : $(this).attr("mobileDetails"),
				sendToTomTomUrl : $(this).attr("sendToTomTom")
			}),
			success: function(html){
				$("body").css("pointer", "default");
				$("body").append(html);
				$("#sendLinkBox").css("top", offset.top + "px");
				$("#sendLinkBox").css("left", offset.left + "px");
				
				$(".sendtomobile").click(function() {
					var top = $(this).offset().top - 100;
					var data = $(this).attr("name").split(",");
					loadSendToMobile(data[0], data[1], data[2], top);
				});
				$(".sendtomail").click(function (){
					loadReviewBox();
					setReviewLoading();

					$.ajax({
						url: "/ajax/sendlink.jsp",
						type: "POST",
						success: function(html){
							var sendLinkUrl = window.location.href;
							sendLinkUrl = sendLinkUrl.replace(/#/, "");
							$("#reviewContainer").html(html);
							$("#sendLinkUrl").val(sendLinkUrl);
							
							$("form.sendlink").submit(function() {
								if ($("#sname").val() == null || $("#sname").val() == "") {
							        $(".warning-bar").show(); 
							        $(".errormessage").hide();
							        $("#nosname").show();
							    } else if ($("#smail").val() == null || $("#smail").val() == "") {
							    	$(".warning-bar").show(); 
							        $(".errormessage").hide();
							        $("#nosmail").show();  
							    } else if ($("#rname").val() == null || $("#rname").val() == "") {
							    	$(".warning-bar").show(); 
							        $(".errormessage").hide();
							        $("#norname").show();
							    } else if ($("#rmail").val() == null || $("#rmail").val() == "") {
							    	$(".warning-bar").show(); 
							        $(".errormessage").hide();
							        $("#normail").show();
							    } else {
									var inputs = [];
				          			$(':input', this).each(function() {
				            			inputs.push(this.name + '=' + escape(this.value));
				          			});
				          			setReviewLoading();
				          			$.ajax({
										url: "/SendLink",
										type: "POST",
										data: inputs.join('&'),
										success: function(html){
					          				$("#reviewContainer").html(html);
										}
									});
							    }
							});
						}
					});

					if (pageDetail == 'detailpage') {
						ilLog('detail.stuurdoor', 0, '',-1,-1,-1,'');
					} else {//need to do more for static here! Yifan;
						ilLog('results.stuurdoor', 0, '',-1,-1,-1,'');
					}
				});
				
				$(document).one("click", function() {
					$("#sendLinkBox").remove();
				});
			}
		});
	});
}

//6
function loadSendToMobileSubmit(nr, cid, cname) {
	$(".sendToMobileRequest").submit(function() {
		var msisdn = $(".fill_pre").val() + $(".fill_post").val();
		var w = false;
		if ($(".sendToMobileRequest input:checked").length > 0) {
			w = true;
		}

		setReviewLoading();

		$.ajax({
			url: "/ajax/sendtomobile.jsp",
			type: "POST",
			data: "companyId=" + cid + "&msisdn=" + msisdn + "&phoneType=" + w,
			success: function(html){
				$("#reviewContainer").html(html);
				$("#reviewContainer span.cname").html(cname);

				if ($(".sendToMobileRequest input:checked").length > 0) {
					w = true;
				}

				$(".btnDownload").click(function() {
					setReviewLoading();
					$.ajax({
						url: "/ajax/sendtomobile.jsp",
						type: "POST",
						data: "companyId=" + cid + "&download=true&msisdn=" + msisdn + "&phoneType=" + w,
						success: function(html){
							$("#reviewContainer").html(html);
							$("#reviewContainer span.cname").html(cname);
						}
					});
				});

				loadSendToMobileSubmit(nr, cid, cname)
			}
		});
	});
}


//10
function registerLogin() {
	$(".loginPopup").click(function() {
		var pos = $("#loginlink a").offset();
		var right = $(window).width() - pos.left - $("#loginlink a").outerWidth() - 9;
		
		$("#loginPopup").css( {"top":(pos.top - 2) + "px","right":right + "px"});
		$("#loginPopup").attr("name", "hover");
		$("#loginPopup .loginBox").hide();
		$("#loginPopup .first").show();
		$("#loginPopup").show();
	});
	$("#loginPopup").hover(function() {
			$("#loginPopup").attr("name", "hover");
		}, function() {
			$("#loginPopup").attr("name", "nohover");
			$("body").one("click", function() {
				if ($("#loginPopup").attr("name") == "nohover") {
					$("#loginPopup").hide("slow");
				}
			});
	});
	$(".logoff").click(function() {
		$.ajax({
			url: "/logout",
			type: "POST",
			success: function(html){
				location.reload(true);
			}
		});
	});
	$(".loginReviewer").click(function () {
		$.ajax({
			url: "/ajax/login.jsp",
			type: "POST",
			success: function(html) {
				$("#loginPopup .first").hide();
				$("#loginPopup .loginBox").css("width", "360px");
				$("#loginPopup .loginBox").show();
				$("#loginPopup .loginBox").html(html);
				ilLog('loginscreen', 0, '-1',-1,-1,-1,'');
				$("form.login .loginBtn").click(function() { submitLogin(); });
				$("form.login").submit(function() { submitLogin(); });
			
				$(".forgotUsername").click(function() {
					$.ajax({
						url: "/ajax/forgot.jsp",
						type: "POST",
						success: function(html){	
							$("#loginPopup .loginBox").html(html);
							ilLog('forgotpassword', 0, '-1',-1,-1,-1,'');
							$("form.forgotUser .forgotBtn").click(function() { submitForgot(); });
						}
					});
				});
				registerSignup();
			}
		});
	});
}

//11
function registerSignup() {
	$("#loginPopup .signup, #loginPopup .updateProfile").click(function () {
		ilLog('registerprofile.form', 0, '-1',-1,-1,-1,'');
		$.ajax({
			url: "/ajax/signup.jsp",
			type: "POST",
			success: function(html) {
				$("#loginPopup .first").hide();
				$("#loginPopup .loginBox").css("width", "360px");
				$("#loginPopup .loginBox").show();
				$("#loginPopup .loginBox").html(html);

				$("form.signup .signupBtn").click(function() {
					submitSignup();
				});
				/*$("form.signup").submit(function() {
					submitSignup();
				});*/
			}
		});
	});
}

//12
function submitLogin() {
	$("#loginPopup .error").hide();
	ilLog('login.save.click', 0, '-1',-1,-1,-1,'');

	var mail = $("#loginMail").val();
	var pass = $("#loginPass").val();
	data = "mail=" + mail + "&pass=" + pass;
	$.ajax({
		url: "/login",
		type: "POST",
		data: data,
		success: function(returnValue) {
            returnValue = trim(returnValue);
            if (returnValue == 'ok') {
				location.reload(true);
			} else {	 
				ilLog('login.error', 0, '-1',-1,-1,-1,'');
				$("#loginPopup .error").show(); 
				
				var errorPageUrl = "/ajax/showerror.jsp?msg=" + returnValue;
				if (returnValue.indexOf("expired.account") > -1) {
					errorParams = returnValue.split("#");
					errorPageUrl = "/ajax/showerror.jsp?msg=" + errorParams[0] + "&userId=" + errorParams[1] + "&mail=" + errorParams[2];
				} 

				$("#loginPopup .error").load(errorPageUrl, function() {
					$(".forgotUsernameerror").click(function() {
						$.ajax({
							url: "/ajax/forgot.jsp",
							type: "POST",
							success: function(html){
								ilLog('forgotpassword', 0, '-1',-1,-1,-1,'');
								$("#loginPopup .loginBox").html(html);
								$("form.forgotUser .forgotBtn").click(function() { submitForgot(); });
							}
						});
					});
				});
			}
		}
	});
}

//13
function submitForgot() {
	$("#loginPopup .error").hide();
	
	var il_mail = $("#il_mail").val();
	if (il_mail != '') {
		$.ajax({
			url: "/forgetPass",
			type: "POST",
			data: "mail=" + il_mail,
			success: function(returnValue){
                returnValue = trim(returnValue);
                if (returnValue == 'ok') {
					$.ajax({
						url: "/ajax/pass_sent.jsp",
						type: "POST",
						data: "info=forgot.password",
						success: function(html){
							ilLog('passwordsend', 0, '-1',-1,-1,-1,'');
							$("#loginPopup .loginBox").html(html);
							$(".forgotConfirmBtn").click(function() {
								location.reload(true);
							});
							$("#loginPopupNew .loginBox").html(html);
							$(".forgotConfirmBtn").click(function() {
								location.reload(true);
							});
						}
					});
				} else {
					$("#loginPopup .error").show();
					$("#loginPopup .error").load("/ajax/showerror.jsp?msg=" + returnValue);
					$("#loginPopupNew .error").show();
					$("#loginPopupNew .error").load("/ajax/showerror.jsp?msg=" + returnValue);
				}
			}
		});
	}
}

//14
function submitSignup() {
	ilLog('registerprofile.register.save.click', 0, '-1',-1,-1,-1,'');
	
	$("#loginPopup .error").hide();

	var action = $("#loginAction").val();
	var name = $("#loginName").val();
	var mail = $("#loginMail").val();
	var pass = $("#loginPass").val();

	var cbDev = "false";
	var cbPartner = "false";
	if ($("input[@name='cbDev']:checked").val() == "on") {
		var cbDev = "true";
	}
	if ($("input[@name='cbPartner']:checked").val() == "on") {
		var cbPartner = "true";
	}

	data = "name=" + name
		+ "&mail=" + mail
		+ "&cbDev=" + cbDev
		+ "&cbPartner=" + cbPartner
		+ "&action=" + action;

    var url = "/login/signup";

    if (action == 'modify') {
		var newPass = $("#loginNewPass").val();
		var newPass2 = $("#loginNewPass2").val();
		var userId = $.cookie("il_uid");
		data += "&pass=" + newPass;
		data += "&pass2=" + newPass2;
		data += "&oldPass=" + pass;
        data += "&id=" + userId;
        url = "/login/modify";
    } else if (action == 'signup') {
		var pass2 = $("#loginPass2").val();
		data += "&pass=" + pass;
		data += "&pass2=" + pass2;
	}

	$.ajax({
		url: url,
		type: "POST",
		data: data,
		success: function(returnValue) {
            returnValue = trim(returnValue);
            if (returnValue.indexOf("ok//") > -1) {
            	$.ajax({
					url: "/ajax/signup_message.jsp",
					type: "POST",
					data: "info=submit.signup",
					success: function(html){
						$("#loginPopup .loginBox").html(html);
						$(".messageConfirmBtn").click(function() {
							location.reload(true);
						});
					}
				});
			} else {
				$("#loginPopup .error").show();
				if(returnValue.indexOf("username.suggest") > -1){
					var userName = returnValue.substring(30);
					$("#loginPopup .error").load("/ajax/jsError.jsp?username=" + userName);
				}else{
					$("#loginPopup .error").load("/ajax/showerror.jsp?msg=" + returnValue);
					if(returnValue == "error.mailexists"){
						$("#loginPopup .error").click(function() {
							$.ajax({
								url: "/ajax/forgot.jsp",
								type: "POST",
								success: function(html){
									$("#loginPopup .loginBox").html(html);
									ilLog('forgotpassword', 0, '-1',-1,-1,-1,'');
									$("form.forgotUser .forgotBtn").click(function() { submitForgot(); });
								}
							});
						});
					}
				}
			}
		}
	});
}
//20
function addLocCookie(loc, lat, lng, name) {
	loc = loc.replace(/ /, "");
	$.cookie('ownLocation_'+loc, lat+"//"+lng+"//"+name, {path: '/', expires: 3650 });
	
	centralCode = loc;
	centralName = name;
	addLatLngLocation(lat, lng);
}

//21
function validatePostalCode(strPC) {
	return typeof strPC=='string'
		?strPC.match(/[1-9][0-9]{3} ?[a-zA-Z]{2}/)==strPC
		:false;
}

//22
function centerOnMap(obj) {
	var top = ($("#maparea").height() / 2) - ($(obj).height() / 2);
	var left = ($("#maparea").width() / 2) - ($(obj).width() / 2);
	top += $("#maparea").offset().top;
	left += $("#maparea").offset().left;
	$(obj).css("top", top);
	$(obj).css("left", left);
}

function centerXOnMap(obj) {
	var left = ($("#maparea").width() / 2) - ($(obj).width() / 2);
	left += $("#maparea").offset().left;
	$(obj).css("left", left);
}

//23
function loadTimedMap() {
	if (typeof mapReady == 'function') {
		mapReady();
	} else {
		setTimeout('loadTimedMap()',500);
	}
}

//24
var VE_TOKEN_COOKIE = "VETOKEN"
function getVETokenURL() {
	var url = null;
	if(!document.location.hostname.match(/(\d){1,3}\.(\d){1,3}\.(\d){1,3}\.(\d){1,3}/)) {
		/* Not an IP Address */
		var port = "";
		if(document.location.port!="80" && document.location.port != null && document.location.port.length != 0) {
			port = ":" + document.location.port;
		}
		url = document.location.protocol + "//" +
			document.location.hostname +
			port +
			"/VEToken/generateToken.a";
	}
	return url;
}

//25
function getVEToken() {
	return getVEToken(true);
}

//26
function getVEToken(block) {
	var token = $.cookie(VE_TOKEN_COOKIE);
	if(token == null && block == true) {
		generateVEToken();
		sleep(500);
		token = $.cookie(VE_TOKEN_COOKIE);
	}
	return token;
}

//27
function generateVEToken() {
	var VETokenURL = getVETokenURL();
	if($.cookie(VE_TOKEN_COOKIE) == null && VETokenURL != null) {
		$.getJSON(VETokenURL,
			function(jsonData) {
				var token = null;
				var expireAfter = 1;
				if(jsonData != null) {
					if(jsonData.token != null && jsonData.token.length > 0) {
						token = jsonData.token;
					}
					if(jsonData.expireAfter != null) {
						expireAfter = parseInt(jsonData.expireAfter);
						if(isNaN(expireAfter)) {
							expireAfter = 5;
						}
					}
				}
				var date = new Date();
				date.setTime(date.getTime() + (expireAfter * 60 * 1000));
				$.cookie(VE_TOKEN_COOKIE, token, { path: '/', expires: date });
			}
		);
	}
}
//29
function removeSuggestionLocation(){
	$("#location").remove();
	$("#lat").remove();
	$("#lng").remove();
	$("#distance").remove();
	$("#sort").remove();
	
	ownLocationSearch = false;
}

//30
function viewErrorMessage(errorMsg) {
	$("body").append("<div id='mapErrorMessage'><div class='close'></div></div>");
	$.ajax({
		url: "/ajax/showerror.jsp",
		type: "POST",
		data: "msg=" + errorMsg,
		success: function(html) {
			$("#mapErrorMessage").append("<p><strong>Foutmelding</strong></p>");
			$("#mapErrorMessage").append(html);
			centerOnMap("#mapErrorMessage");
			$("#mapErrorMessage").show();
			$("#mapErrorMessage .close").click(function () {
				$("#mapErrorMessage").remove();
			});
		}
	});
}
//33
function loadChangeLoc() {
	$.ajax({
		url: "/ajax/userlocationbox.jsp",
		type: "POST",
		success: function(html) {
			$("body").append(html);
			$("#changeloc .close").click(function() {
				$("#changeloc").remove();
				$("#changeloctop").remove();
			});
			$(".addLocButton").click(function() {
				var loc = $(".il_location").val().replace(/ /, "");

				if (validatePostalCode(loc)) {
					$.ajax({
						url: "/ValidZipCode?zipCode="+loc+"&version=2",
						type: "GET",
						success: function(returnValue){
							returnValue = trim(returnValue);
							var latLong = returnValue.split("|");
							if (latLong[0] > 0 && latLong[1] > 0) {
								addLocCookie(loc,latLong[1],latLong[0],$(".il_location_name").val());
								location.reload(true);
							} else {
								viewErrorMessage("unknownZip");
							}
						}
					});
				} else {
					viewErrorMessage("noValidZip");
				}
			});
			$(".setDefaultLoc").click(function() {
				$("#lat").remove();
				$("#lng").remove();
				$("#distance").remove();
				$("#sort").remove();
				
				$("#search").append("<input id='lat' type='hidden' name='lat' value='"+$(this).attr("latitude")+"' />");
				$("#search").append("<input id='lng' type='hidden' name='lng' value='"+$(this).attr("longitude")+"' />");
				$("#search").append("<input id='distance' type='hidden' name='distance' value='3' />");
				$("#search").append("<input id='sort' type='hidden' name='sort' value='distance' />");
				
				$("#wherebox").val($(this).attr("zip"));
				$("#header form").submit();
			});
			$(".removeLoc").click(function(){
				loc = $(this).attr("name").replace(/ /, "");
				$.cookie("ownLocation_" + loc, null);
				$("div." + $(this).attr("name")).remove();
			});
			$(".il_location_name").focus(function() {
				if ($(this).val() == 'bijv. thuis') {
					$(this).val("");
				}
				$(this).css("font-style", "normal");
				$(this).css("color", "#000");
			});
			centerXOnMap("#changeloc");
			$("#changeloc").css("top", $(".zipChange").offset().top + 20 + "px");
			$("#changeloctop").css("top", $(".zipChange").offset().top + 15 + "px");
			$("#changeloctop").css("left", $(".zipChange").offset().left + 13 + "px");
			$("#changeloc .il_location").val(centralCode);		
			$("#changeloctop").show();
			$("#changeloc").slideDown(150);
		}
	});
}

//34
//////AUTO SUGGEST LOCATION //////
function setCleanSearch(obj) {
if (obj.attr("name").length > 0) {
	var termArray = obj.attr("name").split('~', 2);
	var lat = obj.attr("lat");
	var lng = obj.attr("lng");
	if (termArray != null && termArray.length > 0) {
		$("#wherebox").val(extract(cleanWord(termArray[1])));
		removeSuggestionLocation();
		
		$("#search").append("<input id='location' type='hidden' name='location' value='"+extract(termArray[0])+"' />");
		$("#search").append("<input id='lat' type='hidden' name='lat' value='"+lat+"' />");
		$("#search").append("<input id='lng' type='hidden' name='lng' value='"+lng+"' />");
	}
}
}

//35
function buildSuggestionBox(words, counts, points, longs, lats, isDYM, value){
if (words!=null && words.length>0 && !isDYM) {
	removeSuggestionLocation();
	
	value = unescape(value);
	if ($("#sb_wherebox").css("display") == "none") {
		showWhere();
	}

	//TODO: Implementation is not correct, now it doesn't work correctly without locations from cookies
	if ($("#whereboxcontent").attr("id") != 'whereboxcontent') {
		$("#sb_wherebox .main").append("<div id='whereboxcontent' class='content_nl'></div>");
	}
	
	$("#whereboxcontent .suggest").remove();
	$("#whereboxcontent").prepend("<div class='suggest'></div>");
	
	var topWordsLength = 0;
	if(words.length > 7){
		topWordsLength = 7;
	} else {
		topWordsLength = words.length;
	}

	for (var i=0;i<topWordsLength;i++){
		$("#whereboxcontent .suggest").append(
			'<a href="#" id="trC'+i+'" class="suggest_link" name="'+points[i]+'~'+words[i]+'" lat="'+lats[i]+'" lng="'+longs[i]+'">' +
			strongMatch(words[i],value)+
			'</a>'
		);
	}
	
	$("#whereboxcontent .suggest_link").click(function() {
		setCleanSearch($(this));
		this.blur();
	});
	$("#whereboxcontent .suggest_link").mouseover(function() {
		$("#whereboxcontent .suggest_link_selected").removeClass("suggest_link_selected");
	});
	$("#sb_wherebox td").height($("#whereboxcontent").height());
} else {
	$("#whereboxcontent .suggest").remove();
}
}

//36
function suggestSearch() {
var inputValue = $("#wherebox").val();

if (inputValue.length >= MIN_CHAR_INPUT) {
	inputValue = escape(inputValue);
	var res = resCache.getItem(inputValue);
	if ( typeof(res) != 'undefined' ){
		eval("buildSuggestionBox("+res+",'"+inputValue+"')");
	} else {
		$.ajax({
			url: "/suggestion?value=" + inputValue,
			type: "GET",
			success: function(script){
			 	eval("buildSuggestionBox("+script+",'"+inputValue+"')");
			}
		});
	}
} else {
	$("#whereboxcontent .suggest").remove();
}
}

//37
function loadAutoLocationSuggest() {
var timeoutId = 0;
var code;
var originalWhereTerm = "";

$("#search").submit(function() {
	submitToSearch();
});

$("#wherebox").keyup(function(e) { 
	clearTimeout(timeoutId);
	if (e.keyCode) { 
 		code = e.keyCode; 
 	} else if (e.which) { 
 		code = e.which; 
 	}
	switch (code) {
		case LEFT:
		case RIGHT:	
		case ENTER:
		case SHIFT:
			break;
		case ESC:
			hideWhere();
			$("#wherebox").val(originalWhereTerm);
			break;
		case DOWN:
			var active = $($("#whereboxcontent .suggest_link_selected")[0]);
			if (active.html() == null) {
				originalWhereTerm = $("#wherebox").val();
				active = $($("#whereboxcontent a")[0]);
				active.addClass("suggest_link_selected");
				setCleanSearch(active);
			} else {
				if ($(active.next("#whereboxcontent a")).length > 0) {
					active.removeClass("suggest_link_selected");
					$(active.next("#whereboxcontent a")).addClass("suggest_link_selected");
					setCleanSearch($(active.next("#whereboxcontent a")));
				}
			}
			break;
		case UP:
			var active = $($("#whereboxcontent .suggest_link_selected")[0]);
			if (active.length > 0) {
				active.removeClass("suggest_link_selected");
				$(active.prev("#whereboxcontent a")).addClass("suggest_link_selected");
				setCleanSearch($(active.prev("#whereboxcontent a")));
			}
			break;
		default:
			timeoutId = setTimeout(suggestSearch,10);
	}
});



$("#whatbox").focus(function() { showWhat(); });
$("#wherebox").focus(function() { showWhere(); });
$("#whatbox").blur(function() { hideWhat(); });
$("#wherebox").blur(function() { hideWhere(); });

$(".search-suggest a").click(function() {
	if (!$(this).hasClass("suggest_link")) {
		if ($(this).attr("id") == 'whatdel') {
			$.cookie('il_prev_what', '', { expires: -1 });
			$("#sb_whatbox").remove();
		} else if($(this).attr("id") == 'wheredel'){
			$.cookie('il_prev_where', '', { expires: -1 });
			$("#sb_wherebox .history").remove();
		} else {
			if ($(this).attr("name") == "wherebox") {
				removeSuggestionLocation();
			}
			
			if (typeof($(this).attr("latitude")) != "undefined" && typeof($(this).attr("longitude")) != "undefined") {
				if ($(this).attr("title") == 'BE') {
					$("#" + $(this).attr("name")).val($(this).html());
					ownLocationSearch = true;
				} else {
					$("#" + $(this).attr("name")).val($(this).attr("title"));
				}
				$("#search").append("<input id='lat' type='hidden' name='lat' value='"+$(this).attr("latitude")+"' />");
				$("#search").append("<input id='lng' type='hidden' name='lng' value='"+$(this).attr("longitude")+"' />");
				$("#search").append("<input id='distance' type='hidden' name='distance' value='3' />");
				$("#search").append("<input id='sort' type='hidden' name='sort' value='distance' />");
			} else {
				$("#" + $(this).attr("name")).val($(this).html());
			}
		}
	}
});
}

//38
function showWhere() {
	if ($("#home").length > 0) {
		$("#sb_wherebox").css("top", ($("#wherebox").offset().top + 21) + 'px');
		$("#sb_wherebox").css("left", ($("#wherebox").offset().left - 6) + 'px');
	} else {
		$("#sb_wherebox").css("top", ($("#wherebox").offset().top + 23) + 'px');
		$("#sb_wherebox").css("left", ($("#wherebox").offset().left - 7) + 'px');
	}

var whereHistory = $.cookie("il_prev_where");
if (whereHistory != null) {
	whereHistory = whereHistory.split("#");
	$("#sb_wherebox .history .items").html("");
	
	for (var i = 0; i < whereHistory.length; i++) {
		var historyItem = whereHistory[i].replace(/\+/g, " ").replace(/^\s+|\s+$/g,"");
		
		$("#sb_wherebox .history .items").append("<a href='#' rel='nofollow'>"+historyItem+"</a>");
	}
	$("#sb_wherebox .history .items a").click(function() {
		$("#wherebox").val($(this).html());
		return false;
	});
	
	$("#sb_wherebox .history").css("display", "block");
} else {
	$("#sb_wherebox .history").css("display", "none");
}

$("#sb_wherebox").slideDown(200);
}

//39
function showWhat() {
	if ($("#home").length > 0) {
		$("#sb_whatbox").css("top", ($("#whatbox").offset().top + 21) + 'px');
		$("#sb_whatbox").css("left", ($("#whatbox").offset().left - 6) + 'px');
	} else {
		$("#sb_whatbox").css("top", ($("#whatbox").offset().top + 23) + 'px');
		$("#sb_whatbox").css("left", ($("#whatbox").offset().left - 7) + 'px');
	}

var whatHistory = $.cookie("il_prev_what");
if (whatHistory != null) {
	whatHistory = whatHistory.split("#");
	$("#sb_whatbox .history .items").html("");
	
	for (var i = 0; i < whatHistory.length; i++) {
		var historyItem = whatHistory[i].replace(/\+/g, " ").replace(/^\s+|\s+$/g,"");
		$("#sb_whatbox .history .items").append("<a href='#' rel='nofollow'>"+historyItem+"</a>");
	}
	
	$("#sb_whatbox .history .items a").click(function() {
		$("#whatbox").val($(this).html().replace(/&amp;/g,'&').replace(/&lt;/g,'<').replace(/&gt;/g,'>'));
		return false;
	});
	
	$("#sb_whatbox").slideDown(200);
}
}

//40
function hideWhere() {
setTimeout('$("#sb_wherebox").slideUp(200)',100);
}

//41
function hideWhat() {
setTimeout('$("#sb_whatbox").slideUp(200)',100);
}

//42
function strongMatch(str, prefix) {
prefix = prefix.replace(/\s+/gi," ");
tempwords = str.replace(/<\/?[^>]+(>|$)/gi,"");

pos = tempwords.search(",");
var original= "";
var re="";
re = new RegExp("(^"+prefix+")|(\\s+("+prefix+"))|(^"+prefix+",\\s+)|(\\s+("+prefix+"),\\s+) ","gi");
tempwords = tempwords.replace(re, "<strong>$1$2</strong>");
return tempwords;
}

//43
function extract(str) {
return str.replace(/<\/?[^>]+(>|$)/g,"");
}

//44
function cleanWord(word){
return word.replace(/\s+\(.+\)/g,"");
}

//45
function Hash() {
this.length = 0;
this.items = new Array();
for (var i = 0; i < arguments.length; i += 2) {
	if (typeof(arguments[i + 1]) != 'undefined') {
		this.items[arguments[i]] = arguments[i + 1];
		this.length++;
	}
}

this.removeItem = function(in_key){
	var tmp_value;
	if (typeof(this.items[in_key]) != 'undefined') {
		this.length--;
		var tmp_value = this.items[in_key];
		delete this.items[in_key];
	}

	return tmp_value;
}

this.getItem = function(in_key) {
	return this.items[in_key];
}

this.setItem = function(in_key, in_value){
	if (typeof(in_value) != 'undefined') {
		try {
			if (typeof(this.items[in_key]) == 'undefined') {
				this.length++;
			}
		} catch(e) {
		}
		
		this.items[in_key] = in_value;
	}

	return in_value;
}

this.hasItem = function(in_key){
	return typeof(this.items[in_key]) != 'undefined';
}
}

//28
function submitToSearch(){
	if(($("#whatbox").val() == "" && $("#wherebox").val() == "") || ($("#whatbox").val() == $("#whatboxvalue").val() && $("#wherebox").val() == $("#whereboxvalue").val())){
		var lang = "";
		if($(".changelanguage").attr("name") != null){
			lang = $(".changelanguage").attr("name");
		}
	
		if(lang == "frTonl"){
			alert("Remplissez un terme de recherche ( chercher) et/ou un lieu (à ou près de)");
		} else if(lang == "enTonl") {
			alert("Fill in a searchterm (search for) and/or location (in or close to)");
		} else {
			alert("Vul een zoekterm (zoek naar) en/of locatie in (in of dichtbij)");
		}
		$("#whatbox").val("");
		$("#wherebox").val("");
		return false;
	} else {
	//	if($("#point").val()!=null && $("#point").val()!="" && $("#wherebox").val()!=""){
	//		var separator = $("#point").val().indexOf("=");
	//		var name = $("#point").val().substring(0,separator);
	//		if(name == "iv1"){
	//			$("#iv1").val($("#point").val().substring(separator+1));
	//			$("#tid").val("LocationAutosuggest");
	//		} else if(name == "iv11"){
	//			$("#iv11").val($("#point").val().substring(separator+1));
	//			$("#tid").val("LocationAutosuggest");
	//		}
	//	}
		if (ownLocationSearch) {
			$("#wherebox").val("");
		}
		if(($("#wherebox").val() != $("#whereboxvalue").val()) && ($("#whatbox").val() == $("#whatboxvalue").val())) {
			$("#whatbox").val("");
		}
		if(($("#whatbox").val() != $("#whatboxvalue").val()) && ($("#wherebox").val() == $("#whereboxvalue").val())) {
			$("#wherebox").val("");
		}
		$(this).parents("form").submit();
		return false;
	}
}

//29
function removeSuggestionLocation(){
$("#location").remove();
$("#lat").remove();
$("#lng").remove();
$("#distance").remove();
$("#sort").remove();

ownLocationSearch = false;
}

//31
function loadReviewBox() {
	$("body").append("<div id='reviewWindow'><table width='100%' cellspacing='0' cellpadding='0'><tr><td><div class='pop_main'><div class='closeBox'><div class='closeButton'></div></div><div id='reviewContainer'></div></div></td></tr></table></div>");
	$("#reviewWindow").css("left", ($(window).width() / 2) - ($("#reviewWindow").width() / 2) + "px");
	$(".closeButton").click(function (){
		$("#reviewWindow").remove();
	});
}

//32
function setReviewLoading() {
	$("#reviewContainer").html("<div style='height: 100px; background: transparent url(/images/loadingAnimation.gif) no-repeat center center;'></div>");
	$("#userloc").remove();
	$("#reviewWindow").show();
}

//functions for shopping guide create pages
function makeShoppingGuide() {
	var recentCid_1 = 0;
	var recentCid_2 = 0;
	var cid = 0;
	
/*	if($("#cb-item-01").attr("checked")) {
		recentCid_1=$("#cb-item-01").val().replace(/([^\x01-\x7E])/g,function(word){return'&#'+word.charCodeAt(0)+ ';';});
	}
	
	if($("#cb-item-02").attr("checked")) {
		recentCid_2=$("#cb-item-02").val().replace(/([^\x01-\x7E])/g,function(word){return'&#'+word.charCodeAt(0)+ ';';});
	}*/
	
	var companyIds="";
	if(document.shoppingguideinfo.list != null){
		for(var i=0; i < document.shoppingguideinfo.list.length; i++){
			if(document.shoppingguideinfo.list[i].checked){
				if(companyIds == ""){
					companyIds = "&companyIds="+document.shoppingguideinfo.list[i].value;
				}else{
					companyIds = companyIds + "&companyIds="+document.shoppingguideinfo.list[i].value;
				}
			}
		}
	}
	if($("#cid").val() != "" && $("#cid").val() != null) {
		cid = $("#cid").val().replace(/([^\x01-\x7E])/g,function(word){return'&#'+word.charCodeAt(0)+ ';';});
	}
	
	var title = $("#sgtitle").val().replace(/([^\x01-\x7E])/g,function(word){return'&#'+word.charCodeAt(0)+ ';';});
	if ($("#sgdescription").css("font-style") == "italic") {
		$("#sgdescription").val('');		
	}
	var description = $("#sgdescription").val().replace(/([^\x01-\x7E])/g,function(word){return'&#'+word.charCodeAt(0)+ ';';});
	
	var companyDesc = "";
	if ($("#sgCompanyDesc").val() != null) {
		if ($("#sgCompanyDesc").css("font-style") == "italic") {
			$("#sgCompanyDesc").val('');		
		}
		companyDesc = $("#sgCompanyDesc").val().replace(/([^\x01-\x7E])/g,function(word){return'&#'+word.charCodeAt(0)+ ';';});
	}	
	if (title != "" && $("#sgtitle").css("font-style") != "italic") {
/*		data = "title=" + escape(title) + "&description=" + escape(description) + 
					"&companyDesc=" + escape(companyDesc) + "&companyId=" + cid + "&recentCompanyId1=" + 
					recentCid_1 + "&recentCompanyId2=" + recentCid_2;*/
		data = "title=" + escape(title) + "&description=" + escape(description) + 
		"&companyDesc=" + escape(companyDesc) + "&companyId=" + cid + companyIds;
		data1 = "text=" + companyDesc + " " +title + " " +description;
		
		$("#title").val(title);
		$("#description").val(description);
		$("#companyDesc").val(companyDesc);
		$("#companyId").val(cid);
		$("#recentCompanyId1").val(recentCid_1);
		$("#recentCompanyId2").val(recentCid_2);
		
		$.ajax({ 
			url: "/shoppingguide/premoderate",
			type: "POST",
			data: data1,
			success: function(returnValue) { 
				if (returnValue.indexOf("ok") > -1) {
					if ($.cookie("il_mail") == null || $.cookie("il_dname") == null || $.cookie("il_pass") == null) {
						$("#shoppingguideinfo-area").hide();
						$("#errormessage").hide();
						$("#login-signup-area").show();
						$("#login-area").show();
						ilLog('loginscreen', 0, '-1',-1,-1,-1,'');	
					} else {
						if($.cookie("il_uid") == $.cookie("il_sg_owner")){
							$("#errormessage1").show();
							$("#shoppingguideinfo-area").show();
							$("#login-signup-area").hide();
						}else{
							$.ajax({ 
								url: "/shoppingguide/company/create",
								type: "POST",
								data: data,
								success: function(returnValue) { 
									if (returnValue.indexOf("ok") > -1) {
										returnValue = trim(returnValue);
										var sgId = returnValue.substring(3);
										var url = "/shoppingguide?id="+sgId;
										window.location = url + "&su=1";
									} else {
										ilLog('shoppingguide.create.error', 0, '-1',-1,-1,-1,'');
										$("#errormessageshowerror").load("/ajax/showerror.jsp?statusMessage=" + escape(returnValue));
										$("#errormessageshowerror").show();
									}
								}
							});
						}
					}
				} else {
					ilLog('shoppingguide.create.error', 0, '-1',-1,-1,-1,'');
					$("#errormessage").html(returnValue);
					$("#errormessage").show();
				}
			}
		});
	} else {
		ilLog('shoppingguide.create.warning', 0, '-1',-1,-1,-1,'');
		$("#errormessage-emptytitle").show();
	}
}
//End of functions for shopping guide create pages

function addCompanyToSG(descr, sgtitle, cname){
	$.ajax({ 
		url: "/shoppingguide/company/add",
		type: "POST",
		data: "shoppingGuideId="+$("#sgId").val()+"&companyId="+$("#sgcid").val(),
		success: function(returnValue) { 
			if (returnValue.indexOf("ok") > -1){
				ilLog('addtoshoppingguide.addcompany.save', 0, '-1',-1,-1,-1,'');
				returnValue = trim(returnValue);
				var sgId = returnValue.substring(3);
				addCompanyDescriptionToSG(sgId, descr, sgtitle, cname);
			}else{
				ilLog('addtoshoppingguide.addcompany.error', 0, '-1',-1,-1,-1,'');
				$("#createError").html("*ERROR: " + returnValue);
				$("#createError").show();
			}
		}
	});
}

function addCompanyDescriptionToSG(sgId, descr, sgtitle, cname){ 
	var newHref = "";
	$.ajax({ 
		url: "/shoppingguide/company/description",
		type: "POST",
		data: "page=resultsOrDetail&shoppingGuideId="+sgId+"&companyId="+$("#sgcid").val()+"&description="+escape(descr.replace(/([^\x01-\x7E])/g,function(word){return'&#'+word.charCodeAt(0)+ ';';})),
		success: function(returnValue) { 
			if (returnValue.indexOf("ok") > -1){		
				if (window.location.href.indexOf("addsg")>-1) {
					window.location = window.location.href.replace(/addsg(.)*/,"addsg="+sgId+"&sgcname="+cname+"&sgtitle="+sgtitle);
				} else {
					if (window.location.href.indexOf("?")>-1) {
						newHref = window.location.href.replace(/#(.)*/, "");
						window.location = newHref + "&addsg="+sgId+"&sgcname="+cname+"&sgtitle="+sgtitle;
						
					} else {
						newHref = window.location.href.replace(/#(.)*/, "");
						window.location = newHref + "?addsg="+sgId+"&sgcname="+cname+"&sgtitle="+sgtitle;
					}
				}
			}else{
				$("#createError").html("*ERROR: " + returnValue);
				$("#createError").show();
			}
		}
	});
	
//	$("#descriptionCompany").val(descr.replace(/([^\x01-\x7E])/g,function(word){return'&#'+word.charCodeAt(0)+ ';';}));
//	$("#companyId").val($("#sgcid").val());
//	$("#shoppingGuideId").val(sgId);
//	
//	$("#formShoppingGuideCompany").submit();
	
	/*$.ajax({ 
		url: "/shoppingguide/company/description",
		type: "POST",
		data: "shoppingGuideId="+sgId+"&companyId="+$("#sgcid").val()+"&description="+descr,
		success: function(returnValue) { 
			if (returnValue.indexOf("ok") > -1) {
				var url = "/shoppingguide?id="+sgId;
				$("#success").html("Bedankt! We hebben je een mail gestuurd, bevestig door op de likn te klikken. <a href ="+url+">Click Here></a>");
				$("#success").show();
				$("#showselectedsg").hide();
				$("#shoppingguidelink").hide();
			}else{
				$("#createError").html("*ERROR: " + returnValue);
				$("#createError").show();
			}
		}
	});*/
}

//46
//general functions
function trim(stringToTrim) {
	return stringToTrim.replace(/^\s+|\s+$/g,"");
}

//19
function showTopBanner() {
	if (!window.XMLHttpRequest) {
		$("#content .bar").css("height", "61px");
		$(".dcFeedbackGrayBarLabel").css("display", "none");
		$("#topbanner").css("margin", "0px 0px 0px 10px");
	} else {
		$("#content .bar").css("height", "73px");
		$("#topbanner").css("margin", "12px 0px 0px 10px");
		$(".dcFeedbackGrayBarLabel").css("padding-top", "43px");
	}
	$("#topbanner").css("width", ($("#header").width() - 20) + "px");
	$("#topbanner").css("border", "1px solid #d6d6d6");
	$("#topbanner").css("height", "30px");
}

function textCounter(field, maxlimit) {
    if (field.value.length > maxlimit) {
        field.value = field.value.substring(0, maxlimit);
        return false;
    }
    return true;
}

function submitResultsFeedback(){
	if ($("#fComment").val() == "") {
		$(".fErrorMsg").hide();
		$("#emptyComment").show();
	} else if ($("#fName").val() == "") {
		$(".fErrorMsg").hide();
		$("#emptyName").show();
	} else if ($("#fMail").val() == "" || $("#fMail").val().indexOf("@") < 0) {
		$(".fErrorMsg").hide();
		$("#emptyMail").show();
	} else {
		$.ajax({
			url: "/feedback/submit",
			type: "POST",
			data: "action=feedback&name="+$("#fName").val()+"&mail="+$("#fMail").val()+"&comment="+$("#fComment").val(),
			success: function(returnValue){
				if (returnValue.indexOf("ok") > 0) {
					$("#resultsFeedbackForm").remove();
					$("#fSubmitFinish").show();
				} else {
					$(".fErrorMsg").hide();
					$("#fSubmitError").show();
				}
			}
		});
	}
}
