$(document).ready(function(){
	$(".productsTable img").mouseenter(function(){
		var url = $(this).attr("src");
		url = url.substring(0, url.lastIndexOf("/") + 1);
		url = url + $(this).attr("class") + "_o.jpg";
		$(this).attr("src", url);
	});
	$(".productsTable img").mouseleave(function(){
		var url = $(this).attr("src");
		url = url.substring(0, url.lastIndexOf("/") + 1);
		url = url + $(this).attr("class") + ".jpg";
		$(this).attr("src", url);
	});
	
	$("#erbjudande").parents('p').remove();
	// $("#erbjudande").prepend("<a href='/grundmalning' class='erbjudande' style='position:absolute;width:558px;height:288px;'></a>");
});

$(document).ready(function(){
	setTimeout("adjustLine()", 500);
});

function adjustLine(){
	var content = $("#content").height();
	var menu = $(".menu").height();
	
	if(parseInt(content) >= parseInt(menu)) {
		$(".menu").css('height', content);
		$(".logotyp").css("height", (content - menu) + 70);
	} else {
		$("#content").css('height', menu);
	}
}

function popUpWindow(file, url) {
	path = url + "/images/paneler/panel/" + file.attr('class') + ".html";
	window.open(path,"popup","width=520px,height=427px");
}

function popUpGalleryWindow(file, url) {
	path = url + "/images/bildgalleri/html/" + file.attr('class') + ".html";
	window.open(path,"popup","width=420px,height=355px");	
}

// Implementering av Mikael Prag webdesign 2001-05-25.

function checkform ( form )
{

	//Forward
	if(!form.tillval1.checked && form.antal1.value.length > 0) {
		showCheckedError("Förrådsdörr för kallgarage");
		return false;
	}
	
	if(!form.tillval2.checked && form.antal2.value.length > 0) {
		showCheckedError("Förrådsytterdörr");
		return false;
	}
	
	if(!form.tillval3.checked && form.antal3.value.length > 0) {
		showCheckedError("Fönster 100x60 cm");
		return false;
	}

	if(!form.tillval4.checked && form.antal4.value.length > 0) {
		showCheckedError("Fönster 80x100 cm");
		return false;
	}

	if(!form.tillval5.checked && form.antal5.value.length > 0) {
		showCheckedError("Halvmånefönster vitmålad 100x50 cm");
		return false;
	}	

	if(!form.tillval6.checked && form.antal6.value.length > 0) {
		showCheckedError("Lucka gavelspets");
		return false;
	}

	//Reverse
	if(form.tillval1.checked && form.antal1.value.length < 1) {
		showAntalError("Förrådsdörr för kallgarage");
		return false;
	}
	
	if(form.tillval2.checked && form.antal2.value.length < 1) {
		showAntalError("Förrådsytterdörr");
		return false;
	}
	
	if(form.tillval3.checked && form.antal3.value.length < 1) {
		showAntalError("Fönster 100x60 cm");
		return false;
	}

	if(form.tillval4.checked && form.antal4.value.length < 1) {
		showAntalError("Fönster 80x100 cm");
		return false;
	}

	if(form.tillval5.checked && form.antal5.value.length < 1) {
		showAntalError("Halvmånefönster vitmålad 100x50 cm");
		return false;
	}	

	if(form.tillval6.checked && form.antal6.value.length < 1) {
		showAntalError("Lucka gavelspets");
		return false;
	}
	
	//Ports
	
	if(getCheckedValue(form.port) != 3 && form.antal7.value.length > 0) {
		showCheckedError("Crawford g60Line 250x200 cm");
		return false;
	}

	if(getCheckedValue(form.port) == 3 && form.antal7.value.length < 1) {
		showAntalError("Crawford g60Line 250x200 cm");
		return false;
	}
	
	if(!form.portauto.checked && form.antal8.value.length > 0) {
		showCheckedError("Portautomatik");
		return false;
	}

	if(form.portauto.checked && form.antal8.value.length < 1) {
		showAntalError("Portautomatik");
		return false;
	}
  
	return true;
}

function showCheckedError(field){
	alert(field + " har antal, men sort inte vald");
}

function showAntalError(field) {
	alert(field + " är vald, men utan antal");
}

function getCheckedValue(radioObj) {
	if(!radioObj)
		return "";
	var radioLength = radioObj.length;
	if(radioLength == undefined)
		if(radioObj.checked)
			return radioObj.value;
		else
			return "";
	for(var i = 0; i < radioLength; i++) {
		if(radioObj[i].checked) {
			return radioObj[i].value;
		}
	}
	return "";
}

