var gT = "http://translate.google.com/translate?u=%u&sl=en&tl=%tl";

function isLiscDotCom()
{
	return window.location.href.indexOf("http://www.londonisc.com") == 0;
}

function setupTranslate()
{
	$("img.tflag").click(function(e) {
		var href = encodeURIComponent(window.location.href);
		var tl = $(this).attr("tl");
		gT = gT.replace("%u", href);
		gT = gT.replace("%tl", tl);
		window.top.location.href = gT;
	});
}

$(document).ready(
	function(){
		$('.caption').innerfade({
			animationtype: 'fade',
			speed: 1000,
			timeout: 2500,
			type: 'sequence',
			containerheight: '1em'
		});
		$('#picbar').innerfade({
			animationtype: 'fade',
			speed: 2500,
			timeout: 4500,
			type: 'sequence',
			containerheight: '128px'
		});
		$(".flags a").each(function(i) {
			var attrStr = $(this).attr("href");
			attrStr = attrStr + jQuery.url.attr("relative");
			$(this).attr("href", attrStr);
		});
		if (isLiscDotCom()) {
			setupTranslate();
		}
	}
);

var nsite = "london";

function winop(str)
{
	var opts = 'resizable=yes,scrollbars=yes,width=515,height=500,top=60,left=60';
	h = window.open(str, null, opts);
	h.focus();
}

function msend(pbox)
{
	var compn = "isc";
	var mltxt = pbox + "@" + nsite + compn;
	document.write("<a href=" + "mail" + "to:" + mltxt + ".com" + ">" + mltxt + ".com" + "</a>");
}

function mtxtsend(pbox, stxt)
{
	var compn = "isc";
	var mltxt = pbox + "@" + nsite + compn;
	document.write("<a href=" + "mail" + "to:" + mltxt + ".com" + ">" + stxt + "</a>");
}

function checkForm()
{
	var filled = false;
	var emailcorrect = false;
	
	var email = document.forms.Form.emailaddress.value;
	
	if(document.forms.Form.firstname.value == "" ) {
		alert("First Name is required.");
		document.forms.Form.firstname.focus();
	} else if(document.forms.Form.secondname.value == "" ) {
		alert("Second Name is required.");
		document.forms.Form.secondname.focus();
	} else if(document.forms.Form.title.value == "" ) {
		alert("Title is required.");
		document.forms.Form.surname.focus();
	} else if(email == "") {
		alert("E-mail Address is required.");
		document.forms.Form.emailaddress.focus();
	} else if(!document.forms.Form.courseiec.checked &&
 		  !document.forms.Form.course1yi.checked &&
 		  !document.forms.Form.course1ya.checked &&
 		  !document.forms.Form.coursegal.checked &&
 		  !document.forms.Form.courseast.checked &&
 		  !document.forms.Form.courserc.checked &&
 		  !document.forms.Form.coursesas.checked &&
 		  !document.forms.Form.coursegsa.checked &&
 		  !document.forms.Form.coursepac.checked) {
		alert("Please tell us the programme you are interested in.");
		document.forms.Form.courseiec.focus();
	} else if(document.forms.Form.knowlisc.value == "" ) {
		alert("How did you learn about LISC is required.");
		document.forms.Form.knowse.focus();
	} else {
		filled = true;
	}
	
	if(email != "" && filled == true) {
		if(email.indexOf('@') == 0 || email.indexOf('@') == -1 || email.lastIndexOf('.') == -1 || email.indexOf('@') == email.lastIndexOf('.')-1 || email.indexOf('@') > email.lastIndexOf('.') || email.lastIndexOf('.') == email.length-1) {
			alert("E-mail is incorrect, please revise.");
			document.forms.Form.emailaddress.focus();
		} else {
			emailcorrect = true;
		}
	}
	
	if(filled == true && emailcorrect) {
		document.forms.Form.submit();
	}
}

function checkCallBack()
{
	var filled = false;
	var emailcorrect = true;

	var email = document.forms.Form.emailaddress.value;

	if(document.forms.Form.name.value == "" ) {
		alert("Name is required.");
		document.forms.Form.name.focus();
	} else if(document.forms.Form.tel.value == "" ) {
		alert("Telephone number is required.");
		document.forms.Form.tel.focus();
	} else {
		filled = true;
	}

	if(email != "" && filled == true) {
		if(email.indexOf('@') == 0 || email.indexOf('@') == -1 || email.lastIndexOf('.') == -1 || email.indexOf('@') == email.lastIndexOf('.')-1 || email.indexOf('@') > email.lastIndexOf('.') || email.lastIndexOf('.') == email.length-1) {
			alert("E-mail is incorrect, please amend.");
			document.forms.Form.emailaddress.focus();
			emailcorrect = false;
		}
	}
	
	if(filled == true && emailcorrect) {
		document.forms.Form.submit();
	}
}

function checkNewsletter()
{
	var filled = false;
	var emailcorrect = true;

	var email = document.forms.Form.email.value;

	if(document.forms.Form.name.value == "" ) {
		alert("Name is required.");
		document.forms.Form.name.focus();
	} else if(email == "") {
		alert("E-mail Address is required.");
		document.forms.Form.email.focus();
	} else {
		filled = true;
	}
	
	if(email != "" && filled == true) {
		if(email.indexOf('@') == 0 || email.indexOf('@') == -1 || email.lastIndexOf('.') == -1 || email.indexOf('@') == email.lastIndexOf('.')-1 || email.indexOf('@') > email.lastIndexOf('.') || email.lastIndexOf('.') == email.length-1) {
			alert("E-mail is incorrect, please revise.");
			document.forms.Form.email.focus();
		} else {
			emailcorrect = true;
		}
	}
	
	if(filled == true && emailcorrect) {
		document.forms.Form.submit();
	}
}
