/*

	The contents of this file may neither be used nor distributed without written permission by S.A.W. Solutions!

	Copyright (C)2010 S.A.W. Solutions

	Author of this file: Niklas Tewes

*/

function contactFormCheck() {

	var company = encodeURI(document.contact_form.company.value);
	var name = encodeURI(document.contact_form.name.value);
	var email = encodeURI(document.contact_form.zipcode.value);
	var message = encodeURI(document.contact_form.message.value);
	var zipcode = encodeURI(document.contact_form.email.value);
	var error = '0';

	
	if(name.length<4){ var error = '1';
		document.contact_form.name.className ='input_false';
		new Effect.Highlight(document.contact_form.name, { startcolor: '#ffdede', endcolor: '#f7f9f8', duration: 0.5 });
	}else{	document.contact_form.name.className ='';	}
	
	if(email.length<7){ var error = '1';
		document.contact_form.zipcode.className ='input_false';
		new Effect.Highlight(document.contact_form.zipcode, { startcolor: '#ffdede', endcolor: '#f7f9f8', duration: 0.5 });
	}else{	document.contact_form.zipcode.className ='';	}
	
	if(message.length<10){ var error = '1';
		document.contact_form.message.className ='input_false';
		new Effect.Highlight(document.contact_form.message, { startcolor: '#ffdede', endcolor: '#f7f9f8', duration: 0.5 });
	}else{	document.contact_form.message.className ='';	}
	
	if(error == '0'){
		//alert('Transmission successful!');
		

		// Initiate AJAX send routine
		if (window.ActiveXObject || document.all) {request = new ActiveXObject("Msxml2.XMLHTTP");}else {request = new XMLHttpRequest();}
			
			//Effect.Opacity('white', { duration: 2.0, transition: Effect.Transitions.linear, from: 0, to: 1 });
			
			Effect.Appear('white', { duration: 0.5 });
			request.open("POST", "ajax.php?module=contact", false);
			request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
			request.send( 'company=' + company + '&name=' + name + '&email=' + email +'&message=' + message +'&zipcode=' + zipcode);
			ServerResponse = request.responseText;
			
			if(request.readyState == 4){
				setTimeout("Effect.Appear('white2', { duration: 0.5 });", 2500);
				setTimeout("new Effect.Highlight('success_text', { startcolor: '#c9ffc9', endcolor: '#f7f9f8', duration: 0.6 });", 3000);
				document.getElementById('kontakt_formular').innerHTML = '';
			}
			

	}
	
	
	//if(error=='1') {
		//document.getElementById('updater').innerHTML = '<div id="updatertext" style="display: none;">Bitte f&uuml;llen Sie alle ben&ouml;tigten Felder aus!</div>';
		//Effect.Appear('updatertext', { duration: 0.4 });
	//}else{document.getElementById('updater').innerHTML = '';}
	
	//onmousedown="Effect.Appear('white_container', { duration: 0.1 })"
}





function clearContactForm() {
	Effect.Shake('kontakt_formular', { duration: 0.3, distance: 13 }); 
	document.contact_form.name.className ='';
	document.contact_form.zipcode.className ='';
	document.contact_form.message.className ='';
}

var clear = '1'; 
function switchContent () {
	// clear to initiate?

	if(clear != '0'){ // forestall doubleclick
		new Effect.Parallel([
			new Effect.Opacity('dynamic', { sync: true, from: 1, to: -1 }),
			new Effect.SlideUp('dynamic', { sync: true }) 
		], { 
			duration: 1.3,
			delay: 0
		});
		
		return clear = '0';
	}
}

function dim(element) {
		new Effect.Opacity(element,{ duration: 0.2, transition: Effect.Transitions.linear, from: 1.0, to: 0.6 }); 
}

function enlight(element) {
		 new Effect.Opacity(element,{ duration: 0.2, transition: Effect.Transitions.linear, from: 0.6, to: 1 });  
}


var visible = '0';
function check() {
    	

    if(scrollY<-1){
    	//document.getElementById('position').innerHTML = '';
    	if(visible == '1') {
    		window.setTimeout("Effect.Fade('menubar', { duration: 0.3 })" , 00);
    		Effect.Fade('dings', { duration: 0.3 });
    		return visible = '0';
    	}
    }else{
    	//document.getElementById('position').innerHTML = 'Position: ' + scrollY;
    	if(visible == '0') {
    		Effect.Appear('menubar', { duration: 0.3 });
    		window.setTimeout("Effect.Appear('dings', { duration: 0.3 })" , 200);
    		return visible = '1';
    	}
    }
    //window.setTimeout('check()', 2000);
}


//window.setInterval('contactFormCheck()', 500);
