
$(document).ready(function(){	
	$.facebox.settings.opacity = 0.5

	$('a[rel*=facebox]').facebox( {
		loading_image :'loading.gif',
		close_image :'closelabel.gif'
	});
	
	$(".phonelink").click(function() {
		$("#phone_" + $(this).attr("name") + "_a").hide();
		$("#phone_" + $(this).attr("name")).css("display", "inline");
	});
	
	registerLogin();
	registerSendLink();
	try{
		loadAutoLocationSuggest();
	}catch (e){}
	
	$("#headerlocationrefine").click(function(){
		$("#headerLRHolder").css("top", (($(this).position().top) + 100) + "px");
        $("#headerLRHolder").css("left",(($(this).position().left) + 170) + "px");		
		$("#headerLRHolder .popup-body").html("<div style='padding:0 10px'>"+$("#div_refine_loc").html().replace(/refine_loc/g, "header_loc")+"</div>");		
		$("#headerLRHolder").show();
	});
	
	$(".tomTomRoute").click(function() {
		var offset = $(this).offset();
		$.ajax({
			url: "/ajax/tomtomroutebox.jsp",
			type: "POST",
			data: ({
				url : $(this).attr("href"),
				companyId: $(this).attr("alt")
			}),
			success: function(html){
				$("#planRouteBox").remove();
				$("body").append(html);
				$("#planRouteBox").css("top", (offset.top+10) + "px");
				$("#planRouteBox").css("left", (offset.left-22) + "px");
				$("#planRouteBox form").submit(submitTomTomRoute);
				$("#planRouteBox #planRouteButton").click(submitTomTomRoute);
				$("#planRouteBox .popup-close").click(removeTomTomRouteBox);
				$(document).click(removeTomTomRouteBox);
				

			}
		});
		return false;
	});
	
	
	$(".callmeNowLink").click(function() {
		var offset = $(this).offset();
		var xss = $(this).attr("rel");
		$("#phone_" + $(this).attr("name") + "_a").hide();
		$("#phone_" + $(this).attr("name")).css("display", "inline");
		$.ajax({
			url:  xss,
			type: "POST",			
			success: function(html){
				$("#callmeNowBox").remove();
				$("body").append(html);
				$("#callmeNowBox").css("z-index", "99");
				$("#callmeNowBox").css("position", "absolute");
				$("#callmeNowBox").css("top", (offset.top+10) + "px");
				$("#callmeNowBox").css("left", (offset.left-22) + "px");
				$("#callmeNowBox form").submit(submitTomTomRoute);
				$("#callmeNowBox #planRouteButton").click(submitTomTomRoute);
				$("#callmeNowBox .popup-close").click(removeCallmeNowBox);
				$(document).click(removeCallmeNowBox);
			}
		});
		return false;
	});
	
	$(".distanceRefineOpen").click(function () {
        $("#distanceRefine").css("top", (($(this).position().top)+($(this).height())-8) + "px");
        $("#distanceRefine").css("left",(($(this).position().left) - 26) + "px");
        $("#distanceRefine").show();

	});
	$("#distanceRefine .close").click(function(){
		$("#distanceRefine").hide()
	}); 
	
	registerFaqMail();
	registerFaqToggle();
	registerFaqCallUsToggle();
});

function closeHeaderLRHolder() {
	$("#headerLRHolder .popup-body").html("");
	$("#headerLRHolder").hide();
}

function hideMore(obj) {
	$("#" + $(obj).attr("name") + "_less").show();
	$("#" + $(obj).attr("name") + "_more").hide();
	$("#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 loadTimedMap() {
	if (typeof mapReady == 'function') {
		mapReady();
	} else {
		setTimeout('loadTimedMap()',500);
	}
}
function registerLogin() {
	$(".loginPopup").click(function() {
		var pos = $("#login-to-ilocal a").offset();
		var right = $(window).width() - pos.left -340;
		
		$("#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);
				$("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);
							$("form.forgotUser .forgotBtn").click(function() { submitForgot(); });
						}
					});
				});
				registerSignup();
			}
		});
	});
}

function registerSignup() {
	$("#loginPopup .signup, #loginPopup .updateProfile").click(function () {
		$.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();

	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 {	 
				$("#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){
								$("#loginPopup .loginBox").html(html);
								$("form.forgotUser .forgotBtn").click(function() { submitForgot(); });
							}
						});
					});
				});
			}
		}
	});
}

//13
function submitForgot() {
	$("#forgotPasswordBox .error").hide();
	var il_mail = $("#il_mail").val();
	if (il_mail == '') {
		$("#forgotPasswordBox .error").show();
		$("#forgotPasswordBox .error").load("/ajax/showerror.jsp?msg=" + 'ir.invalidmail');
	} else {
		$.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){
							$(".loginBox").html(html);
							$(".forgotConfirmBtn").click(function() {
								location.reload(true);
							});
						}
					});
				} else {
					$("#forgotPasswordBox .error").show();
					$("#forgotPasswordBox .error").load("/ajax/showerror.jsp?msg=" + returnValue);
					
				}
			}
		});
	}
}

//14
function submitSignup() {
	
	$("#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);
									$("form.forgotUser .forgotBtn").click(function() { submitForgot(); });
								}
							});
						});
					}
				}
			}
		}
	});
}

function submitToSearch(){
	if(( $("#wherebox").val() == "" ) || (  $("#wherebox").val() == $("#whereboxvalue").val())){
		$("#whereemptyerror").show();
		
		if($("#search-box").length>0){
			$("#search-box").addClass('error').find('.secInput').addClass('error');
		} else{
		$("#wherebox").addClass('error');
		}
		if($("#whatbox").val() == $("#whatboxvalue").val()){
			$("#whatbox").val("");
		}
		$("#wherebox").val("");
		return false;
	} else {
		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 true;
	}
}

function registerSendLink() { 
	$(".sendtomail").click(function (){
		loadPopupBox($(".sendtomail").attr('title'));
		showPopupBoxLoading();
		var companyName = $(this).attr("name"); 
		
		$.ajax({
			url: "/ajax/sendlink.jsp",
			data: "companyName="+companyName,
			type: "POST",
			success: function(html){
				var sendLinkUrl = window.location.href;
				sendLinkUrl = sendLinkUrl.replace(/#/, "");
				$("#reviewContainer").html(html);
				$("#sendLinkUrl").val(sendLinkUrl);
				$("#popupWindow").show();
				
				$("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));
	          			});
	          			showPopupBoxLoading();
	          			$.ajax({
							url: "/SendLink",
							type: "POST",
							data: inputs.join('&'),
							success: function(html){
		          				$("#reviewContainer").html(html);
							}
						});
				    }
				     return false;
				});
			}
		});
		
		dcsMultiTrack('DCS.dcsuri','/places/send_by_mail_Start','WT.si_n', 'Send by Mail','WT.si_x','2');
	});
}
function loadReviewBox() {
	
}
function loadPopupBox(popupTitle) {
	$("#popupWindow").remove();
	var popupHtml = "<div class='middle-grey' id='popupWindow'><table width='100%' cellspacing='0' cellpadding='0'><tr><td class='top-left'>&nbsp;</td><td class='top-middle'><div class='top-middle-body' style='position:relative; height:52px;'><div class='popup-title'>&nbsp;</div><div class='popup-close'>&nbsp;</div></div></td><td class='top-right'>&nbsp;</td></tr><tr><td class='left-repeat'>&nbsp;</td><td class='popup-body'><div id='reviewContainer'>&nbsp;</div></td><td class='right-repeat'>&nbsp;</td></tr><tr><td class='bottom-left'>&nbsp;</td><td class='bottom-middle'>&nbsp;</td><td class='bottom-right'>&nbsp;</td></tr></table></div>"	
	$("body").append(popupHtml);
	$("#popupWindow .popup-title").html(popupTitle);
	$("#popupWindow").css("left", ($(window).width() / 2) - ($("#popupWindow").width() / 2) + "px");
	$(".popup-close").click(function (){
		$("#popupWindow").remove();
	});
}
function showPopupBoxLoading() {
	$("#reviewContainer").html("<div style='height: 100px; background: transparent url(/img/loadingAnimation.gif) no-repeat center center;'></div>");
	$("#userloc").remove();
	$("#reviewWindow").show();
}

function removeTomTomRouteBox(event){
	if ($(event.target).parents("#planRouteBox").length < 1) {
		$("#planRouteBox").remove();
		$(document).unbind("click", removeTomTomRouteBox);
	}
};

function removeCallmeNowBox(event){
	//if ($(event.target).parents("#callmeNowBox").length < 1) {
		$("#callmeNowBox").remove();
	//	$(document).unbind("click", removeCallmeNowBox);
	//}
};

function submitTomTomRoute() {
	if ($("#routeBoxForm .routeLocation").val().length > 0) {
		var url = $("form#routeBoxForm").attr("action");
		$("form#routeBoxForm").attr("action", url.replace("/home/", "/" + $("#routeBoxForm .routeLocation").val() + "/"));
		
		dcsMultiTrack('DCSext._hit_type','click','DCSext.linktype', 'route from','WT.dl','99');
		
		setTimeout(function() {
			$("#planRouteBox").remove();
			$(document).unbind("click", removeTomTomRouteBox);
		}, 1000);
	}
};

function registerDetailInfoRequestClick(){	
	$("#detailInfoRequest").click(function() {
		var sendType = $(this).attr("name");
	    var showSendType = null;
	    if (sendType == "mail") {
	        showSendType = "mail naar";
	    }
	    else if (sendType == "fax") {
	        showSendType = "";
	    }
	    else {
	        showSendType = sendType;
	    }
	    
	    var hrefValue = $(this).attr("href");
	    var secondIndex = hrefValue.indexOf("#",1);
	    var lastIndex = hrefValue.lastIndexOf("#");
	    
	    var cid = hrefValue.substring(1, secondIndex);
	    var compName = escape(hrefValue.substring(secondIndex+1, lastIndex));
	    var sendContent = " "+hrefValue.substring(lastIndex+1, hrefValue.length);
	    loadPopupBox($("#detailInfoRequest").attr('title'));
	    $("#popupWindow").css("width",450);
	    $("#reviewContainer").load("/ajax/resultsinformationrequest.jsp", {showsendtype: showSendType, sendtype: sendType, sendcontent: sendContent, companyId: cid, companyName: compName}, function() {
	    	
	    	$("#informationRequest .title").html(unescape(compName));
	    	$("#toCompany").val(unescape(compName));

	        $("form.writeInforRequest").submit(function() {
	            var inputs = [];
	            $(':input', this).each(function() {
	            	if (($(this).attr("name") != "nameDropDown") && ($(this).attr("name") != "optIn")) {
		                var val = this.value;
		                val = val.replace(/\n/g, "<br>").replace(/\n\n+/g, '<br><br>');
		                
		                if ($(this).attr("name") == "subject") {
		                	if (val == "op0")
		                		val = "";
		                }

		                inputs.push(this.name + '=' + val);
	            	}
	            });
	            inputs.push("gender=" + $("#nameDropDown").val());

	        	if ($("#optIn").attr("checked"))
	                inputs.push("optIn=true");
	        	else
	                inputs.push("optIn=false");
	        	
	        	inputs.push("resultsPage=true");
	        	var message = $("#message").val();
	        	
	        	if(message != ''){
	        		$.ajax({ 
	    				url: "/checkbadwords",
	    				type: "POST",
	    				data: "text=" + message,
	    				success: function(returnValue) { 
	    					if (returnValue.indexOf("ok") > -1) {
	    						sendInformation(inputs, cid);
	    					} else {
	    						$("#inforRequestErrorLine").load("/ajax/showerror.jsp?badWord=" + escape(returnValue));
	                            $("#inforRequestErrorLine").show();
	    					}
	    				}});	
	        	} else {
	        		sendInformation(inputs, cid);
	        	}
	        	
	        });
		    
		    
	    });
	    $("#userloc").remove();
	    $("#popupWindow").show();
	    
	});
} 

function registerResultsInfoRequestClick(){	
	$(".infoRequest").click(function() {
		var top= $(this).offset().top;
		var left = $(this).offset().left;
		var sendType = $(this).attr("name");
	    var showSendType = null;
	    if (sendType == "mail") {
	        showSendType = "mail naar";
	    }
	    else if (sendType == "fax") {
	        showSendType = "";
	    }
	    else {
	        showSendType = sendType;
	    }
	    
	    var hrefValue = $(this).attr("href");
	    var secondIndex = hrefValue.indexOf("#",1);
	    var lastIndex = hrefValue.lastIndexOf("#");
	    
	    var cid = hrefValue.substring(1, secondIndex);
	    var compName = escape(hrefValue.substring(secondIndex+1, lastIndex));
	    var sendContent = " "+hrefValue.substring(lastIndex+1, hrefValue.length);
	    loadPopupBox($(".infoRequest").attr('title'));
	    $("#popupWindow").css("width",450);
	    $("#reviewContainer").load("/ajax/resultsinformationrequest.jsp", {showsendtype: showSendType, sendtype: sendType, sendcontent: sendContent, companyId: cid, companyName: compName}, function() {
	    	
	    	$("#informationRequest .title").html(unescape(compName));
	    	$("#toCompany").val(unescape(compName));

	        $("form.writeInforRequest").submit(function() {
	            var inputs = [];
	            $(':input', this).each(function() {
	            	if (($(this).attr("name") != "nameDropDown") && ($(this).attr("name") != "optIn")) {
		                var val = this.value;
		                val = val.replace(/\n/g, "<br>").replace(/\n\n+/g, '<br><br>');
		                
		                if ($(this).attr("name") == "subject") {
		                	if (val == "op0")
		                		val = "";
		                }
		                
		                inputs.push(this.name + '=' + val);
	            	}
	            });
	            inputs.push("gender=" + $("#nameDropDown").val());

	        	if ($("#optIn").attr("checked"))
	                inputs.push("optIn=true");
	        	else
	                inputs.push("optIn=false");
	        	
	        	inputs.push("resultsPage=true");
	        	var message = $("#message").val();
	        	
	        	if(message != ''){
	        		$.ajax({ 
	    				url: "/checkbadwords",
	    				type: "POST",
	    				data: "text=" + message,
	    				success: function(returnValue) { 
	    					if (returnValue.indexOf("ok") > -1) {
	    						sendInformation(inputs, cid);
	    					} else {
	    						$("#inforRequestErrorLine").load("/ajax/showerror.jsp?badWord=" + escape(returnValue));
	                            $("#inforRequestErrorLine").show();
	    					}
	    				}});	
	        	} else {
	        		sendInformation(inputs, cid);
	        	}
	        	
	        });
	    });
	    $("#userloc").remove();
	    $("#popupWindow").css("top", top - 80 + "px");
	    $("#popupWindow").css("left", left);
	    $("#popupWindow").show();
	});
} 

function sendInformation(inputs, cid){
	$.ajax({
        url: "/SendInformationRequest",
        type: "POST",
        data: inputs.join('&'),
        success: function(returnValue) {
            returnValue = trim(returnValue);
            if (returnValue.match("ir.mailsend") != null) {
                if ($("#language").val() == 'fr') {	
                	$("#reviewContainer").html("<div style='padding: 0px 10px 20px 10px; text-align: center;'><h3 style='font-size: 14px; font-weight: bold;'>Merci, votre demande a &eacute;t&eacute; envoy&eacute;</h3><input type='button' value='Fermer' style='background:transparent url(../images/dc/btn-close-bg.gif) no-repeat scroll 0 0; width:88px; height:21px; margin:0 0 0 12px; padding:0 0 20px; border:0; color:#fff; font:bold 11px; cursor:pointer;' id='btnCloseReview'/></div>");
                }else if ($("#language").val() == 'en'){
                	$("#reviewContainer").html("<div style='padding: 0px 10px 20px 10px; text-align: center;'><h3 style='font-size: 14px; font-weight: bold;'>Thanks, your request is sent</h3><input type='button' value='Close' style='background:transparent url(../images/dc/btn-close-bg.gif) no-repeat scroll 0 0; width:88px; height:21px; margin:0 0 0 12px; padding:0 0 20px; border:0; color:#fff; font:bold 11px; cursor:pointer;' id='btnCloseReview'/></div>");
                }else {
                	$("#reviewContainer").html("<div style='padding: 0px 10px 20px 10px; text-align: center;'><h3 style='font-size: 14px; font-weight: bold;'>Bedankt, je aanvraag is verzonden</h3><input type='button' value='Sluiten' style='background:transparent url(../images/dc/btn-close-bg.gif) no-repeat scroll 0 0; width:88px; height:21px; margin:0 0 0 12px; padding:0 0 20px; border:0; color:#fff; font:bold 11px; cursor:pointer;' id='btnCloseReview'/></div>");
                }

                $("#btnCloseReview").click(function() {
                    $("#reviewWindow").remove();
                });
                
                dcsMultiTrack('DCSext._hit_type','click','DCSext.linktype', 'email form success','WT.dl', '99');
                
            } else {
            	$("#inforRequestErrorLine").load("/ajax/showerror.jsp?msg=" + returnValue);
                $("#inforRequestErrorLine").show();
                dcsMultiTrack('DCSext._hit_type','click','DCSext.linktype', 'email form failure','WT.dl', '99');
                switch (returnValue) {
                    case "rir.invalidsubject":
                        $("#subject").css("border-color", "red");
                        $("#message").css("border-color", "#D1D1D1");
                        $("#name").css("border-color", "#D1D1D1");
                        $("#email").css("border-color", "#D1D1D1");
                        break;
                    case "rir.invalidmessage":
                        $("#subject").css("border-color", "#D1D1D1");
                        $("#message").css("border-color", "red");
                        $("#name").css("border-color", "#D1D1D1");
                        $("#email").css("border-color", "#D1D1D1");
                        break;
                    case "rir.invalidname":
                        $("#subject").css("border-color", "#D1D1D1");
                        $("#message").css("border-color", "#D1D1D1");
                        $("#name").css("border-color", "red");
                        $("#email").css("border-color", "#D1D1D1");
                        break;
                    case "rir.invalidmail":
                        $("#subject").css("border-color", "#D1D1D1");
                        $("#message").css("border-color", "#D1D1D1");
                        $("#name").css("border-color", "#D1D1D1");
                        $("#email").css("border-color", "red");
                        break;
                    default:
                        //alert("Information Error!");
                }
            }
        }
    });	
}

function showTopBanner() {
	if (!window.XMLHttpRequest) {
		$("#content .bar").css("height", "30px");
	} else {
		$("#content .bar").css("height", "30px");
	}
	$("#topbanner").css("width", "1240px");
	$("#topbanner").css("border", "1px solid #d6d6d6");
	$("#topbanner").css("height", "30px");
}

function registerFaqToggle(){
	$('.faq_que').toggle( 
		function() {
			$(this).next('div.faq_ans').slideDown('slow');
		},
		function() {
			$(this).next('div.faq_ans').slideUp('slow');
		});
	$('.faq_ans').hide(); 
}
function registerFaqCallUsToggle(){
	$('.callus').toggle( 
		function() {
			$('.oh').slideDown('slow');
		},
		function() {
			$('.oh').slideUp('slow');
		});
}
function registerFaqMail(){
	$(".faqmail").click(function() {
	    var sendType = $(this).attr("name");
	    var showSendType = null;
	    if (sendType == "mail") {
	        showSendType = "mail naar";
	    }
	    else if (sendType == "fax") {
	        showSendType = "";
	    }
	    else {
	        showSendType = sendType;
	    }

	    var subject = ($(this).attr("title"));
	    var hrefValue = $(this).attr("href");
	    var secondIndex = hrefValue.indexOf("#",1);
	    var lastIndex = hrefValue.lastIndexOf("#");
	    
	    var cid = hrefValue.substring(1, secondIndex);
	    var compName = escape(hrefValue.substring(secondIndex+1, lastIndex));
	    var sendContent = " "+hrefValue.substring(lastIndex+1, hrefValue.length);
	    loadPopupBox("E-mail");
        $("#popupWindow").css("width",460);
	    $("#reviewContainer").load("/ajax/faqmailform.jsp", function() {
	    	
	    	$("#toCompany").val(unescape(compName));
	    	$("#subject").val(subject);

	        $("form.faqmailform").submit(function() {
	        	var inputs = [];
	      		$(':input', this).each(function() {
			    	if (($(this).attr("name") != "nameDropDown") && ($(this).attr("name") != "optIn")) {
			        	var val = this.value;
			        	val = val.replace(/\n/g, "<br>").replace(/\n\n+/g, '<br><br>');
			        	if ($(this).attr("name") == "subject") {
				        	if (val == "op0") val = "";
			        	}
			        	inputs.push(this.name + '=' + escape(val));
		        	}
	        	});
	        	inputs.push("gender=" + $("#nameDropDown").val());
	        	
	        	if ($("#optIn").attr("checked"))
	        	 	inputs.push("optIn=true");
	        	else
	        	 	inputs.push("optIn=false");
	        	
	        	var message = $("#message").val();
	        	
	        	if(message != ''){
	        		$.ajax({
	        	 		url: "/checkbadwords",
	        	 		type: "POST",
	        	 		data: "text=" + message,
	        	 		success: function(returnValue) {
		        	 		if (returnValue.indexOf("ok") > -1) {
		        	 			sendMail(inputs, cid);
		        	 		} else {
		        	 			$("#inforRequestErrorLine").load("/ajax/showerror.jsp?badWord=" + escape(returnValue));
		        	 			$("#inforRequestErrorLine").show();
		        	 		}
	        	 		}
	        	 	});
	        	 } else {
	        	 	sendMail(inputs);
	        	 }
	        }); 
	        $("#userloc").remove();
	        $("#popupWindow").show();
	    });
	});
}

function sendMail(inputs){
	$.ajax({
        url: "/SendFAQMailForm",
        type: "POST",
        data: inputs.join('&'),
        success: function(returnValue) {
            returnValue = trim(returnValue);
            if (returnValue.match("ir.mailsend") != null) {
                if ($("#language").val() == 'fr') {	
                	$("#reviewContainer").html("<div style='padding: 0px 10px 20px 10px; text-align: center;'><h3 style='font-size: 14px; font-weight: bold;'>Merci, votre demande a &eacute;t&eacute; envoy&eacute;</h3><input type='button' value='Fermer' style='background:transparent url(../images/dc/btn-close-bg.gif) no-repeat scroll 0 0; width:88px; height:21px; margin:0 0 0 12px; padding:0 0 20px; border:0; color:#fff; font:bold 11px; cursor:pointer;' id='btnCloseReview'/></div>");
                }else if ($("#language").val() == 'en'){
                	$("#reviewContainer").html("<div style='padding: 0px 10px 20px 10px; text-align: center;'><h3 style='font-size: 14px; font-weight: bold;'>Thanks, your request is sent</h3><input type='button' value='Close' style='background:transparent url(../images/dc/btn-close-bg.gif) no-repeat scroll 0 0; width:88px; height:21px; margin:0 0 0 12px; padding:0 0 20px; border:0; color:#fff; font:bold 11px; cursor:pointer;' id='btnCloseReview'/></div>");
                }else {
                	$("#reviewContainer").html("<div style='padding: 0px 10px 20px 10px; text-align: center;'><h3 style='font-size: 14px; font-weight: bold;'>Bedankt, je aanvraag is verzonden</h3><input type='button' value='Sluiten' style='background:transparent url(../images/dc/btn-close-bg.gif) no-repeat scroll 0 0; width:88px; height:21px; margin:0 0 0 12px; padding:0 0 20px; border:0; color:#fff; font:bold 11px; cursor:pointer;' id='btnCloseReview'/></div>");
                }

                $("#btnCloseReview").click(function() {
                    $("#popupWindow").remove();
                });
            } else {
            	$("#inforRequestErrorLine").load("/ajax/showerror.jsp?msg=" + returnValue);
                $("#inforRequestErrorLine").show();
                
                $(".textfield").css("border-color", "#CCCCCC");
                $(".inputfield").css("border-color", "#CCCCCC");
                switch (returnValue) {
                    case "rir.invalidsubject":
                        $("#subject").css("border-color", "red");
                        break;
                    case "rir.invalidmessage":
                        $("#message").css("border-color", "red");
                        break;
                    case "rir.invalidcompanyname":
                        $("#companyName").css("border-color", "red");
                        break;
                    case "rir.invalidkvknumber":
                        $("#kvkNumber").css("border-color", "red");
                        break;
                    case "rir.invalidname":
                        $("#name").css("border-color", "red");
                        break;
                    case "rir.invalidmail":
                        $("#email").css("border-color", "red");
                        break;
                    default:
                        //alert("Information Error!");
                }
            }
        }
    });	
}
function textCounter() {
}
function trim(stringToTrim) {
	return stringToTrim?stringToTrim.replace(/^\s+|\s+$/g,""):null;
}

function RNTchangeLocale(locale) {
	var lang="";
	var Lid="";
	
	if(locale=="es_AR"){lang="es";  Lid="47"; }
	if(locale=="en_AU"){lang="en";  Lid="8"; }
	if(locale=="fr_BE"){lang="fr";  Lid="13"; }
	if(locale=="nl_BE"){lang="nl";  Lid="12"; }
	if(locale=="pt_BR"){lang="pt";  Lid="30"; }
	if(locale=="en_CA"){lang="en";  Lid="22"; }
	if(locale=="fr_CA"){lang="fr";  Lid="27"; }
	if(locale=="cz_CZ"){lang="cz";  Lid="10"; }
	if(locale=="da_DK"){lang="da";  Lid="14"; }
	if(locale=="de_DE"){lang="de";  Lid="3"; }
	if(locale=="ee_EE"){lang="ee";  Lid="1"; }
	if(locale=="es_ES"){lang="es";  Lid="6"; }
	if(locale=="fr_FR"){lang="fr";  Lid="2"; }
	if(locale=="en_IE"){lang="en";  Lid="25"; }
	if(locale=="it_IT"){lang="it";  Lid="7"; }
	if(locale=="la_LA"){lang="la";  Lid="37"; }
	if(locale=="li_LI"){lang="li";  Lid="38"; }
	if(locale=="fr_LU"){lang="fr";  Lid="15"; }
	if(locale=="hu_HU"){lang="hu";  Lid="31"; }
	if(locale=="en_MS"){lang="en";  Lid="42"; }
	if(locale=="fr_MA"){lang="fr";  Lid="49"; }
	if(locale=="es_ME"){lang="es";  Lid="40"; }
	if(locale=="nl_NL"){lang="nl";  Lid="5"; }
	if(locale=="en_NZ"){lang="en";  Lid="29"; }
	if(locale=="no_NO"){lang="no";  Lid="16"; }
	if(locale=="de_AT"){lang="de";  Lid="11"; }
	if(locale=="po_PO"){lang="po";  Lid="9"; }
	if(locale=="pt_PT"){lang="pt";  Lid="17"; }
	if(locale=="ru_RU"){lang="ru";  Lid="32"; }
	if(locale=="de_CH"){lang="de";  Lid="20"; }
	if(locale=="en_SG"){lang="en";  Lid="51"; }
	if(locale=="en_ZA"){lang="en";  Lid="28"; }
	if(locale=="fr_CH"){lang="fr";  Lid="19"; }
	if(locale=="fi_FI"){lang="fi";  Lid="24"; }
	if(locale=="sv_SE"){lang="sv";  Lid="18"; }
	if(locale=="tr_TR"){lang="tr";  Lid="26"; }
	if(locale=="en_GB"){lang="en";  Lid="1"; }
	if(locale=="en_US"){lang="en";  Lid="4"; }
	if(locale=="gr_GR"){lang="gr";  Lid="48"; }
	if(locale=="zh_HK"){lang="zh";  Lid="48"; }
	if(locale=="zh_TW"){lang="zh";  Lid="48"; }
 
	var newAdditionalURL = "";
	var tempArray = document.location.href.split("?");
	var tempHashArray	=tempArray[0].split("#");
	var baseURL = tempHashArray[0];
	if(tempArray[1]){
		var aditionalURL = tempArray[1].split("#")[0];
	}
	var temp = "";
	
	if (aditionalURL) {
		var tempArray = aditionalURL.split("&");
		for ( var i in tempArray) {
			if (tempArray[i].indexOf("lang") == 0
					|| tempArray[i].indexOf("Lid") == 0
					|| tempArray[i].indexOf("locale") == 0) 
			{
				
			} else {
				newAdditionalURL += temp + tempArray[i];
				temp = "&";
			}
		}
	}
	
	if (locale) {
		newAdditionalURL += temp + "locale=" + locale;
		temp = "&";
	}
	document.location = baseURL +"?"+newAdditionalURL;
 }
