// JavaScript Document

function showDiv(div) {
	document.getElementById(div).style.display = 'block';
}

function hideDiv(div) {
	document.getElementById(div).style.display = 'none';
}

function testJquery() {
	var name = document.getElementById("CommentName").value;
	var comment = document.getElementById("CommentText").value;
	
	$.get("/ajax/test.php", { name: name, comment: comment }, function(data){
		alert("Data Loaded: " + data);
	});

}

function popUp(URL) {
	day = new Date();
	id = day.getTime();
	eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=0,width=600,height=400,left = 660,top = 400');");
}


function countTegn(q) {
	
	if(q == 'tittel') {
		var limit = 25;
		var i = document.getElementById("Tittel").value.length;
		var text = document.getElementById("Tittel").value;
		
		if(i >= 25) {
			text = text.substring(0, 25);
		}
		
		var count = (limit-i);
		
		document.getElementById("Tittel").value = text;
		document.getElementById("countTittel").innerHTML = (count < 0) ? 0 : count;
	}
	else if(q == 'tekst') {
		var limit = 135;
		var i = document.getElementById("Tekst").value.length;
		var text = document.getElementById("Tekst").value;
		
		if(i >= 135) {
			text = text.substring(0, 135);
		}
		
		var count = (limit-i);
		
		document.getElementById("Tekst").value = text;
		document.getElementById("countTekst").innerHTML = (count < 0) ? 0 : count;
	}
}

function testquery() {
	var name = document.getElementById("CommentName").value;
	var comment = document.getElementById("CommentText").value;
	$.post("/ajax/test.php", { name: name, comment: comment }, function(data){
		//$("div#testdiv").fadeIn("slow").before("<p>TEST</p>");
		$("div#newComment").append(data).hide().show("slow");
		//alert("Data Loaded: " + data);
	});
}

function submit_form(form) {
	switch (form) {
		case "kontakt":
			$.post("/ajax/kontakt.php", $("#kontakt_form").serialize(), function(data) { 
				$("div#response").empty();
				$("div#response").html(data).slideDown("slow");
			});
			//alert("Test");
			break;
		default:
			
			break;
	}
}

function doMenuMagic() {
	var windowWidth;
	var windowHeight;
	
	if(window.addEventListener) {
		windowWidth = window.innerWidth;
		windowHeight = document.body.innerHeight;
	}
	else {
		windowWidth = document.documentElement.clientWidth || document.body.clientWidth;
		windowHeight = document.documentElement.clientHeight || document.body.clientHeight;
	}
	
	windowHeight = windowHeight-75;
	document.getElementById("leftMenu").style.height = $(document).height() + 'px'; /*'100%'; /*windowHeight + 'px';*/
}


