/* form */
function loadFlashes(){
	var flashvars = {};
	var params = { menu: "false", wmode: "transparent" };
	var attributes = {};

	swfobject.embedSWF("/layout/yougetitbydmv.swf", "flashfilm01", 800, 48,  "9.0.0", "/layout/expressInstall.swf", flashvars, params, attributes);
	swfobject.embedSWF("/flash/flash_navi2.swf",    "flashfilm02", 800, 150, "9.0.0", "/flash/expressInstall.swf", flashvars, params, attributes);
}

function sendForm(e, type){
	var error = "";
	
	switch(type){
		case "newsletter":
		{
			if($("name").value == ""){
				error = "Bitte geben Sie einen Namen an.";
				new Effect.Highlight($("name"), { startcolor: '#cc0000', endcolor: '#F5F5F5' });
			}
			if($("email").value == ""){
				error = "Bitte geben Sie eine E-Mail-Adresse an.";
				new Effect.Highlight($("email"), { startcolor: '#cc0000', endcolor: '#F5F5F5' });
			}
		}
		break;
		case "kontakt":
		{
			if($("name").value == ""){
				error = "Bitte geben Sie einen Namen an.";
				new Effect.Highlight($("name"), { startcolor: '#cc0000', endcolor: '#F5F5F5' });
			}
			if($("adresse").value == ""){
				error = "Bitte geben Sie eine Adresse an.";
				new Effect.Highlight($("adresse"), { startcolor: '#cc0000', endcolor: '#F5F5F5' });
			}
			if($("plz").value == ""){
				error = "Bitte geben Sie einen Ort an.";
				new Effect.Highlight($("plz"), { startcolor: '#cc0000', endcolor: '#F5F5F5' });
			}
			if($("telefon").value == ""){
				error = "Bitte geben Sie eine Telefonnumer an.";
				new Effect.Highlight($("telefon"), { startcolor: '#cc0000', endcolor: '#F5F5F5' });
			}
			if($("email").value == ""){
				error = "Bitte geben Sie eine E-Mail-Adresse an.";
				new Effect.Highlight($("email"), { startcolor: '#cc0000', endcolor: '#F5F5F5' });
			}
			if($("textarea").value == ""){
				error = "Bitte geben Sie eine Nachricht an.";
				new Effect.Highlight($("textarea"), { startcolor: '#cc0000', endcolor: '#F5F5F5' });
			}
		}
		break;
	}
	
	
	if(error)
		$("info").update("<span class='orange'>"+error+"</span>");
	else
		ajaxFormSender(e,"type="+type);
}


function ajaxFormSender(id,params){
	$("info").update("Einen moment bitte..");
	
	new Ajax.Request('/ajax/form.php?'+params,{
		method: 'post',
		postBody: $(id).serialize(),
		asynchronous: true,
		evalScript: true,
		onComplete: function(t) {
			$("info").update(t.responseText);
		},
		onFailure: function(t) {
			//$('content').update('Error ' + t.status + ' -- ' + t.statusText);
		}		
	});
}


function getKeyCode(e){
	if(window.event){//IE
		key = window.event.keyCode;
		if(window.event.ctrlKey) 
			top.isCtrl = true;
	}else{//FF
		key = e.which; 
		if(e.ctrlKey) 
			top.isCtrl = true;
	}
	
	return key;
}



function resizeTextArea(t, minRows, minCols, maxRows){	
	t.rows = minRows;
	t.setAttribute("wrap", "off");
	t.style.overflow = "auto";
	lines = t.value.split("\n");
	
	if(arguments.length > 2) 
	{
		if(minCols > 0)
			t.cols = minCols;
		maxChars = lines[0].length;
		for(i = 1; i < lines.length; i++) 
		{
			
			currentLength = lines[i].length;
			if (currentLength > maxChars) maxChars = currentLength;
		}
		
		t.cols = getMax(maxChars, minCols);
	}
	lin = lines.length+1;
	if(maxRows != undefined && lin > maxRows) 
	{
		lin = maxRows;
	}
	
	t.rows = getMax(lin, minRows);
}

function getMax(anumber, another) {	
	return((anumber> another) ? anumber : another);
}