﻿var menuIsClicked = false;

$(function() {

	$("a.external").bind("click", function() {
		
		window.open($(this).attr('href'),"","width=450,height=350,status=1,toolbar=1,location=1,menubar=1,directories=1,resizable=1,scrollbars=1");
		return false;
		
	});	
	if($("#customImg_flashHolder").length>0) {
		$("#customImg_flashHolder").css({ 'width':Math.ceil($("body").width())+'px', 'display' : 'block' });
		$(window).resize(function(){
			$("#holder_content").css({ display: 'none' });
			// resize flash
			$("#customImg_flashHolder").css({ 'width':Math.ceil($("body").width())+'px' });
			// position content
			$("#holder_content").css({
				left: Math.floor((($("body").width()-736)/2)+150) + 'px',
				top: Math.floor((($("body").height()-550)/2)+40) + 'px',
				display: 'block'
			});			
		});
	}	
	
	$("#holder_content").css({
		left: Math.floor((($("body").width()-736)/2)+150) + 'px',
		top: Math.floor((($("body").height()-550)/2)+40) + 'px',
		display: 'block'
	});
	
});﻿

var searchTimeout = "";
function ajaxSearch(inputKW,cmd) {
	switch(cmd) {
		case "init":
			$(inputKW)
			.attr('autocomplete','off')
			.bind('keyup', function() {
				clearTimeout(searchTimeout);
				if($(this).val().length > 0) {
					ajaxSearch(inputKW,"do");
				} else {
					ajaxSearch(inputKW,"clear");
				}
			});
		break;

		case "clear":
			$("#container_search_results").slideUp('normal',function() {
				$(this).find('p.container').html('');
			});
		break;
		case "do":
			searchTimeout = setTimeout("ajaxSearch('" + inputKW + "','doIt');",500);
		break;
		case "doIt":
			$.ajax({
			   type: "POST",
			   url: "/inc/modules/ajax/ajaxSearch.asp",
			   data: "t=ajax&q=" + htmlSecure($(inputKW).val()),
			   success: function(msg){			
					$("#container_search_results").find('p.container').html(msg);
					$("#container_search_results").slideDown('normal');
				}
			});
		break;
	}
}

function htmlSecure(str_tmp) {
	var tmp = str_tmp;
	if(tmp!=""&&tmp.length>0) {
		tmp = tmp.replace(/>/g,"&gt;");
		tmp = tmp.replace(/</g,"&lt;");
		tmp = tmp.replace(/[\r\n]+/g, " ");
		tmp = encodeURIComponent(tmp);
	}
	return tmp;
}

function validEmail(str) {
	var re = new RegExp(/[a-z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-z]{2,12}/ig);
	return (str.match(re)) ? true : false;
}


function init_dynForms() {
	jQuery.each($("form.dynForm div.dyn"), function() {
		var parentForm = $(this).parent('form');
		
		var this_id = $(this).attr('id');
		var this_name = $(this).html();
		var this_type = $(this).attr('class').replace(/dyn /ig,"");
		
		var new_input = $("<input type=\"" + this_type + "\" name=\"" + this_name + "\" id=\"" + this_id + "\" />");

		$(this).replaceWith(new_input);
	});
	// $("#fSend").bind('click', function() {
		// if($("#fName").val()!=""&&$("#fPhone").val()!="") {
			// $(this).parent('form').submit();
		// } else {
			// alert("Udfyld venligst navn og telefonnummer!");
		// }
	// });

}