/*-----------------------------------------------------------------------------
	Script: beverly.js
	
	Dependancies:
		MooTools v1.11
	
	Author:
		Jochen Sengier, <http://www.celcius.be>
		
	Last Updated:
		Wednesday, 19th of September 2007, 09:00 AM
-----------------------------------------------------------------------------*/	


/*-----------------------------------------------------------------------------	
	Method: getWindowHeight
		Retrieve Browser window height

	Arguments:
		none.

	Example:
		getWindowHeight();
-----------------------------------------------------------------------------*/

	function getWindowHeight() {
		var windowHeight=0;
		if (typeof(window.innerHeight)=='number') {
			windowHeight = window.innerHeight;
		}
		else {
			if (document.documentElement && document.documentElement.clientHeight) {
				windowHeight = document.documentElement.clientHeight;
			}
			else {
				if (document.body && document.body.clientHeight) {
					windowHeight = document.body.clientHeight;
				}
			}
		}

		return windowHeight;
	}
	
/*-----------------------------------------------------------------------------	
	Method: setFooter
		Position the Footer

	Arguments:
		none.

	Example:
		setFooter();
-----------------------------------------------------------------------------*/

	function setFooter() {
		if (document.getElementById) {
			var windowHeight=getWindowHeight();

			if (windowHeight > 0 && $('gray_container') ) {
				var contentHeight = $('gray_container').offsetHeight + 128;
									
				if( contentHeight >= windowHeight){
					$('guardian').setStyle('height', contentHeight);
				}else{	
					$('guardian').setStyle('height', windowHeight);
				}
			}
		}
	}
	
/*-----------------------------------------------------------------------------	
	Method: fadeButtons
		Adds a sweeet hover effect :)

	Arguments:
		none.

	Example:
		fadeButtons();
-----------------------------------------------------------------------------*/	

	function fadeButtons(){
		$$('#nav img').each(function(e){
			var fade = new Fx.Style(e, 'opacity', {wait:false});
			fade.set(.75);

			
			e.addEvent('mouseover', function(){
				fade.start(1);
			});

			e.addEvent('mouseout', function(){
				fade.start(.75);
			});
		});

		$$('.imgPrint').each(function(e){
			var fade = new Fx.Style(e, 'opacity', {wait:false});
			fade.set(.75);

			
			e.addEvent('mouseover', function(){
				fade.start(1);
			});

			e.addEvent('mouseout', function(){
				fade.start(.75);
			});
		});
		
		$$('.imgInput').each(function(e){
			var fade = new Fx.Style(e, 'opacity', {wait:false});
			fade.set(.75);

			
			e.addEvent('mouseover', function(){
				fade.start(1);
			});

			e.addEvent('mouseout', function(){
				fade.start(.75);
			});
			
			e.onclick = function(){
				if( $('taal').value != '' && $('email').value != '' && $('gemeente').value != '' && checkMail( $('email').value ) ){
					postdata = "taal=" + $('taal').value + "&email=" + $('email').value + "&gemeente=" + $('gemeente').value;
					page = 'pages/optinout.php';
					new Ajax(page,{
						data: postdata,
						update:'updateSub',
						evalScripts: 'true'
					}).request();
					return false;				
				}else{
					alert('Gelieve alle velden correct in te vullen!');
					return false;
				}
			}
		});		
	}	

/*-----------------------------------------------------------------------------	
	Method: showFiche

	Arguments:
		movid:	record id of movie.

	Example:
		showFiche(2);
-----------------------------------------------------------------------------*/	

	function showFiche(movid){
		if( movid ){
			window.location = "http://www.beverlyscreens.be/?p=fiche&mov=" + movid;
		}
	}

	function showCine(){
		window.location = "http://www.beverlyscreens.be/?p=cineclub";
	}	


	function checkVal(el, type){
		if( type == "focus" ){
			document.getElementById(el).value= "";
		}else if( type == "gone" ){
			curVal = document.getElementById(el).value;
			if( curVal == '' ){
				if( el == "email" ){
					document.getElementById(el).value= "email";
				}else if( el == "gemeente" ){
					document.getElementById(el).value= "stad / ville";
				}
			}
		}
	}	

/*-----------------------------------------------------------------------------	
	Method: checkMail()
		checks input as a valid email address.

	Arguments:
		email_address : email (string) which you want to check.

	Example:
		checkMail("test@test.info");
-----------------------------------------------------------------------------*/	
	
	function checkMail(email_address){
		var validRegExp = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
		if (email_address.search(validRegExp) == -1){
			return false;
		}else{
			return true;
		}
	}
	
	function sendContact(){
		if( $('cEmail').value != '' && checkMail( $('cEmail').value ) ){
			postdata = "cEmail=" + $('cEmail').value + "&cNaam=" + $('cNaam').value + "&cMsg=" + $('cMsg').value + "&cTaal=" + $('cTaal').value;

			page = 'pages/mailContactForm.php';
			new Ajax(page,{
				data: postdata,
				update:'frmInfoBlok',
				evalScripts: 'true'
			}).request();
			return false;				
		}else{
			alert('Please enter a valid e-mail address!');
			return false;
		}	
	}
	
	function optout(){
		if( $('oMail').value != '' && checkMail( $('oMail').value ) ){
			postdata = "oMail=" + $('oMail').value + "&oTaal=" + $('oTaal').value;

			page = 'pages/opout.php';
			new Ajax(page,{
				data: postdata,
				update:'frmInfoBlok',
				evalScripts: 'true'
			}).request();
			return false;				
		}else{
			alert('Please enter a valid e-mail address!');
			return false;
		}	
	}
	
	function openDD(){
		$('sub_programma').setStyle("visibility", "visible");
	}

	function closeDD(){
		$('sub_programma').setStyle("visibility", "hidden");
	}	
