
var TotalCaseStudies = 3
var CurrentCaseStudy = 1;

var next = function()
{
	if(CurrentCaseStudy == TotalCaseStudies)
	{
	   CurrentCaseStudy = 1;
	}
	else
	{
	   CurrentCaseStudy++;
	}

	hideshow('case' + CurrentCaseStudy);
}

var prev = function()
{
	if(CurrentCaseStudy == 1)
	{
	   CurrentCaseStudy = TotalCaseStudies;
	}
	else
	{
	   CurrentCaseStudy--;
	}

	hideshow('case' + CurrentCaseStudy);
}

var hideshow = function(ElementToShow)
{
	// Hide all the visible case studies.
	$$('.visible').setStyle('display', 'none');

	// Fixes wierd bug.
	$$('.hidden').setStyle('display', 'none');

	// The element to show
	$(ElementToShow).setStyle('display', 'block');
}


window.addEvent('domready', function()
{
	$$('.roundedbox').addEvents({
		mouseenter: function()
		{
		 	this.setStyle('cursor','pointer');
			this.morph(new Fx.CSS().search('.roundedbox_hover'));
		},
		mouseleave: function()
		{
			this.morph(new Fx.CSS().search('.roundedbox'));
		}
	});

  
	$('caseprev').addEvent('click', prev);
	$('casenext').addEvent('click', next); 

});

function hideResult()
{
	document.getElementById('result').style.visibility = 'hidden';
}

function validateForm()
{
	var name = document.getElementById('name').value;
	var email = document.getElementById('email').value;
	var subject = document.getElementById('subject').value;
	var comment = document.getElementById('message').value;

	if (name==null||name=='') { alert('Please enter in all fields and ensure the email is valid'); return false; }
	else if (email==null||email=='') { alert('Please enter in all fields and ensure the email is valid'); return false; }
	else if (subject==null||subject=='') { alert('Please enter in all fields and ensure the email is valid'); return false; }
	else if (comment==null||comment=='') { alert('Please enter in all fields and ensure the email is valid'); return false; }
	else if (echeck(email)) { alert('Please enter in all fields and ensure the email is valid'); return false; }
	else { return true; }
}

function echeck(str) {

		var at="@";
		var dot=".";
		var lat=str.indexOf(at);
		var lstr=str.length;
		var ldot=str.indexOf(dot);
		if (str.indexOf(at)==-1){
		   return true;
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   return true;
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    return true;
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    return true;
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    return true;
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    return true;
		 }
		
		 if (str.indexOf(" ")!=-1){
		    return true;
		 }

 		 return false;
	}

function highlightMenu(str)
{
	document.getElementById(str).style.backgroundColor = '#3683cb';
}