var btnlight = "btnlight";
var btn = "btn";
var win=null;
var formstatus = "invalid";

function initialDraw() {
	initialMenuDraw();
	if($('menulocation') != null){
		mItem = 'menuItem' + $('menulocation').value;
		if($(mItem) != null)
			$(mItem).setStyle({ fontWeight :'800'});
	}
	//$('image_line').src = "repository/" + $('imageheader').value;
	if($('captcha')) {
		doMoveCaptcha();
	}
}

function GetXmlHttpObject()
{
	var xmlHttp=null;
	try
	{
		// Firefox, Opera 8.0+, Safari
		xmlHttp=new XMLHttpRequest();
	}
	catch (e)
	{
		//Internet Explorer
		try
		{
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e)
		{
			xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
	}
	return xmlHttp;
}

function getSpan(Div_ID)
{
  if (window.document.all)
    return eval("window.document.all."+Div_ID);
  if (typeof(window.document.getElementById)=="function")
    return window.document.getElementById(Div_ID);
  return eval("window.document."+Div_ID);
}

function redirect(path)
{
	window.location = path;
}

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=1,width=450,height=380,left = 450,top = 382');");
}
function popUpSized(URL, width, height) {
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="+width+",height="+height+",left = 450,top = 382');");
}



function grayOut(vis, options) {  
	// Pass true to gray out screen, false to ungray  
	// options are optional.  This is a JSON object with the following (optional) properties  
	// opacity:0-100         
	// Lower number = less grayout higher = more of a blackout   
	// zindex: #             
	// HTML elements with a higher zindex appear on top of the gray out  
	// bgcolor: (#xxxxxx)    
	// Standard RGB Hex color code  
	// grayOut(true, {'zindex':'50', 'bgcolor':'#0000FF', 'opacity':'70'});  
	// Because options is JSON opacity/zindex/bgcolor are all optional and can appear  
	// in any order.  Pass only the properties you need to set.  
	var options = options || {};   
	var zindex = options.zindex || 50;  
	var opacity = options.opacity || 70;  
	var opaque = (opacity / 100);  
	var bgcolor = options.bgcolor || '#000000';  
	var dark=document.getElementById('darkenScreenObject');  
	if (!dark) {    
		// The dark layer doesn't exist, it's never been created.  So we'll    
		// create it here and apply some basic styles.    
		// If you are getting errors in IE see: http://support.microsoft.com/default.aspx/kb/927917    
		var tbody = document.getElementsByTagName("body")[0];    
		var tnode = document.createElement('div');          
		// Create the layer.        
		tnode.style.position='absolute';                 
		// Position absolutely        
		tnode.style.top='0px';                           
		// In the top        
		tnode.style.left='0px';                          
		// Left corner of the page        
		tnode.style.overflow='hidden';                   
		// Try to avoid making scroll bars                    
		tnode.style.display='none';                      
		// Start out Hidden        
		tnode.id='darkenScreenObject';                   
		// Name it so we can find it later    
		tbody.appendChild(tnode);                            
		// Add it to the web page    
		dark=document.getElementById('darkenScreenObject');  
		// Get the object.  
	}  if (vis) {    
		// Calculate the page width and height     
		if( document.body && ( document.body.scrollWidth || document.body.scrollHeight ) ) {        
			/*var pageWidth = document.body.scrollWidth+'px';        
			var pageHeight = document.body.scrollHeight+'px';    
		} else if( document.body.offsetWidth ) {      
			var pageWidth = document.body.offsetWidth+'px';      
			var pageHeight = document.body.offsetHeight+'px';    
		} else {     */  
			var pageWidth='100%';       
			var pageHeight='100%';  
		}       
		//set the shader to cover the entire page and make it visible.    
		dark.style.opacity=opaque;                          
		dark.style.MozOpacity=opaque;                       
		dark.style.filter='alpha(opacity='+opacity+')';     
		dark.style.zIndex=zindex;            
		dark.style.backgroundColor=bgcolor;      
		dark.style.width= pageWidth;    
		dark.style.height= pageHeight;    
		dark.style.display='block';                            
	} else {    
		dark.style.display='none';  
	}
}

var cMove = 2;
var cPos = 0;
var moving = true;
var valid = false;
function doMoveCaptcha() {
		setTimeout("moveCaptcha()", 40);
}
function validateCaptcha() {
	valid = true;
	$('mover').setStyle({visibility:"hidden"});
	$('captcha').setStyle({backgroundColor:"#99FF99"});
}	
function moveCaptcha() {
	finalPos = cPos+"px";
	$('mover').setStyle({left:finalPos});
	cPos = cPos + cMove;
	if(cPos == 88) {
		cMove = -2;
	} else if(cPos == 0) {
		cMove = 2;
	}
	setTimeout("moveCaptcha()", 55);
}



function mailto(s)	{
	var number=0;
	var result="";
	for(var i=0; i<s.length; i++) {
		number=s.charCodeAt(i);
		if (number>=8364) {
			number = 128;
		}
		result += String.fromCharCode(number-2); 
	}
	location.href="mailto:" + result;
}

function sendrequest() {
	validateMailForm();
	if(formstatus == "verified"){
		sendRequest();
	} else {
	}
}

function sendRequest() {
	ps_forename = $F('inp_forename');
	ps_name = $F('inp_name');
	ps_street= $F('inp_street');
	ps_plz = $F('inp_plz');
	ps_email = $F('inp_email');
	ps_request = $F('inp_request');

	ps_forename = formatPString(ps_forename);
	ps_name = formatPString(ps_name);
	ps_street = formatPString(ps_street);
	ps_plz = formatPString(ps_plz);
	ps_email = formatPString(ps_email);
	ps_request = formatPString(ps_request);
	new Ajax.Request("mailto.php", 
		{ 
		method: 'post', 
		postBody: "send_mail=confirmed&name=" + ps_name + "&forename=" + ps_forename + "&street=" + ps_street + "&plz=" + ps_plz  + "&email=" + ps_email + "&request=" + ps_request,
		onComplete: showMailResponse 
	});
}

function guestbookentry() {
	validateGuestbookForm();
	if(formstatus == "verified"){
		guestbookEntry();
	} else {
	}
}

function guestbookEntry() {
	ps_name = $F('inp_name');
	ps_location = $F('inp_location');
	ps_email = $F('inp_email');
	ps_message = $F('inp_message');

	ps_name = formatPString(ps_name);
	ps_location = formatPString(ps_location);
	ps_email = formatPString(ps_email);
	ps_message = encodeURIComponent(formatPString(ps_message));
	
	new Ajax.Request("postGuestbook.php", 
		{ 
		method: 'post', 
		postBody: "post_message=confirmed&name=" + ps_name + "&location=" + ps_location + "&email=" + ps_email + "&message=" + ps_message,
		onComplete: showGuestbookResponse 
	});
}


function formatPString(out) {
	
	out = out.replace(/&/g, "[amp]");
	
	return out;
}

function showGuestbookResponse(req){
	$('inp_name').value = "";
	$('inp_location').value = "";
	$('inp_email').value = "";
	$('inp_message').value = "";
	redirect('index.php?page=guestbook');
}

function showMailResponse(req){
	$('inp_forename').value = "";
	$('inp_name').value = "";
	$('inp_street').value = "";
	$('inp_plz').value = "";
	$('inp_email').value = "";
	$('inp_request').value = "";
	alert("Anfrage gesendet!");
	//redirect('competition.php?lang='+req.responseText);
}

function validateField(obj, filter) {
	var returnValue = false;
	$(obj).setStyle({backgroundColor:'#FFFFFF'});
	if ($(obj).getValue() == "") {
		$(obj).setStyle({backgroundColor:'#fac8b7'});
		returnValue = false;
	} else {
		returnValue = true;
	}
	if(filter != null) {
		if (!filter.test($(obj).getValue())) {
			$(obj).setStyle({backgroundColor:'#fac8b7'});
			returnValue = false;
		} else {
			returnValue = true;
		}
	}
	return returnValue;
}

function validateMailForm() {
	formstatus = "verified";
	var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	if(validateField('inp_forename', null) == false) { formstatus = "invalid" ;}
	if(validateField('inp_name', null) == false) { formstatus = "invalid";}
	if(validateField('inp_street', null) == false) { formstatus = "invalid";}
	if(validateField('inp_plz', null) == false) { formstatus = "invalid";}
	if(validateField('inp_email', filter) == false) { formstatus = "invalid";}
}

function validateGuestbookForm() {
	formstatus = "verified";
	var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	if(validateField('inp_name', null) == false) { formstatus = "invalid";}
	if(validateField('inp_location', null) == false) { formstatus = "invalid";}
	if(validateField('inp_email', filter) == false) { formstatus = "invalid";}
	if(valid==false) { formstatus = "invalid";}
}
// End -->