function submitform() {
	// form validation
	var error = false;

	if (document.contact.name.value.length<1) {
		$("#contactname").html('<img src="/images/public/alert.gif" width="20" height="16" />');
		error=true;
	}
	if (!document.contact.type.selectedIndex) {
		$("#contacttype").html('<img src="/images/public/alert.gif" width="20" height="16" />');
		error=true;
	}
	if (!document.contact.how.selectedIndex) {
		$("#contacthow").html('<img src="/images/public/alert.gif" width="20" height="16" />');
		error=true;
	}
	if (!validEmail(document.contact.email.value)) {
		$("#contactemail").html('<img src="/images/public/alert.gif" width="20" height="16" />');
		error=true;
	}
	
	if (!error) {
		postData();
		displaySending();
	}
	
	return true;
	
}

function displaySending() {
	$("#contactform").html('<h1 style="text-align:center">Sending Enquiry</h1><p align="center"><img src="/images/public/loadingAnimation.gif" /></p><br /><br />');
	$("#getintouchbutton").css('background-image','none');
}

function postData() {
	$.post("/process-form.php", {
		name:document.contact.name.value,
		company:document.contact.company.value,
		type:document.contact.type.value,
		town:document.contact.town.value,
		email:document.contact.email.value,
		phone:document.contact.phone.value,
		website:document.contact.website.value,
		how:document.contact.how.selectedIndex,
		interest_news_in_a_hurry:document.contact.interest_news_in_a_hurry.checked,
		interest_web_page_videos:document.contact.interest_web_page_videos.checked,
		interest_company_news_desk:document.contact.interest_company_news_desk.checked,
		interest_sales_force_briefings:document.contact.interest_sales_force_briefings.checked,
		interest_education_and_training:document.contact.interest_education_and_training.checked,
		interest_virtual_events:document.contact.interest_virtual_events.checked,
		interest_script_writing:document.contact.interest_script_writing.checked,
		interest_powerpoint:document.contact.interest_powerpoint.checked,
		interest_presenter_training:document.contact.interest_presenter_training.checked,
		comments:document.contact.comments.value
	}, delayDisplayComplete);
}

function delayDisplayComplete() {
	setTimeout("displayComplete()", 1000);
}

function displayComplete() {
	$("#contactform").html('<h1>Thank You. Your enquiry has been sent successfully.</h1>');
	setTimeout("closePanel()", 4000);
}

function closePanel() {
	$("#contactform").slideUp("slow");
	$("#getintouchbutton").css('background-image','url(/images/public/getintouch-sent.gif)');
}

function checkvalid(ref, name) {
	switch (name) {
		case "contactname":
			if (ref.value.length>=1) $("#contactname").html('<img src="/images/public/tick.gif" width="20" height="16" />');
			else $("#contactname").html('<img src="/images/public/alert.gif" width="20" height="16" />');
			break;
		case "contacttype":
			if (ref.selectedIndex) $("#contacttype").html('<img src="/images/public/tick.gif" width="20" height="16" />');
			else $("#contacttype").html('<img src="/images/public/alert.gif" width="20" height="16" />');
			break;
		case "contactemail":
			if (validEmail(ref.value)) $("#contactemail").html('<img src="/images/public/tick.gif" width="20" height="16" />');
			else $("#contactemail").html('<img src="/images/public/alert.gif" width="20" height="16" />');
			break;
		case "contacthow":
			if (ref.selectedIndex) $("#contacthow").html('<img src="/images/public/tick.gif" width="20" height="16" />');
			else $("#contacthow").html('<img src="/images/public/alert.gif" width="20" height="16" />');
			break;
	}
}

function validEmail(s) {
	var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
	if(reg.test(s) == false) {
		return false;
	} else {
		return true;
	}
}

function toggleContactForm() {
	if ($("#contactform:first").is(":hidden")) {
		$("#contactform").html($("#contactformframe"));
		$("#contactformframe").show();
		$("#contactform").slideDown("slow");
		$("#getintouchbutton").css('margin-top', '6px');
		$("#getintouchbutton").css('background-image','url(/images/public/closeform.gif)'); 
		//pageTracker._trackPageview("/contact/step1.html");
	} else {
		$("#getintouchbutton").css('background-image','url(/images/public/getintouch.gif)'); 
		$("#getintouchbutton").css('margin-top', '-1px');
		$("#contactform").slideUp("slow");
	}
}

var names = new Array('tab1','tab2','tab3','tab4');
function changePanel(id) {
	for (var i=0; i<=3; i++) {
		if (i==id) {
			turnOn('homepage-panel-'+names[i]);
			changeBackgroundImage('homepage-tab-'+names[i], '/images/public/homepage-tabs/'+names[i]+'.jpg');
		} else {
			turnOff('homepage-panel-'+names[i]);
			changeBackgroundImage('homepage-tab-'+names[i], '/images/public/homepage-tabs/'+names[i]+'a.jpg');
		}
	}
}

function changeBackgroundImage(DivID, Image) {
	document.getElementById(DivID).style.backgroundImage = 'url('+Image+')';
}

// turn off function
function turnOff(DivID) {
	if (document.getElementById) { //gecko(NN6) & IE 5+
		document.getElementById(DivID).style.visibility = "hidden";
		document.getElementById(DivID).style.display = "none";
	} else if (document.all) { // IE 4+
		document.all[DivID].style.visibility = "hidden";
		document.all[DivID].style.display = "none";
	} else if (document.layers) { // NS4+
		document.layers[DivID].visibility = "hide";
		document.layers[DivID].display = "none";
	} else {
		// nothing
	}
}

// turn on function
function turnOn(DivID) {
	if (document.getElementById) { //gecko(NN6) & IE 5+
		document.getElementById(DivID).style.visibility = "visible";
		document.getElementById(DivID).style.display = "block";
	} else if (document.all) { // IE 4+
		document.all[DivID].style.visibility = "visible";
		document.all[DivID].style.display = "block";
	} else if (document.layers) { // NS4+
		document.layers[DivID].visibility = "show";
		document.layers[DivID].display = "block";
	} else {
	}
}

function carousel_this_bad_boy()
{
	$("#featured_carousel").jCarouselLite({
	    btnNext: "#featured-next",
	    btnPrev: "#featured-prev",
		scroll: 1,
		visible: 1,
		speed: 500
	});
	
	$(".carousel-logos").jCarouselLite({
		circular: true,
		scroll: 1,
	    visible: 5,
		auto: 2000,
		speed: 1000
	});
}

$(document).ready( function() {
	carousel_this_bad_boy();
	$('.slideshow').cycle();
});


