$('#jsoff').remove();

function rolloverlocal(image,source) {
	document.getElementById(image).src=source;
}
function rolloutlocal(image,source) {
	document.getElementById(image).src=source;
}
function rollover(image,source,folder,path,extension) {
	document.getElementById(image).src=path+'/'+'images/'+folder+'/'+source+'_over.'+extension;
}
function rollout(image,source,folder,path,extension) {
	document.getElementById(image).src=path+'/'+'images/'+folder+'/'+source+'.'+extension;
}

function rollover2(image,source,folder,path) {
	document.getElementById(image).src=path+'/'+'images/'+folder+'/'+source+'.gif';
}
function rollout2(image,source,folder,path) {
	document.getElementById(image).src=path+'/'+'images/'+folder+'/'+source+'.gif';
}
function preloadImages() {
	var d=document; 
	if(d.images) { 
		d.preload=new Array();
		var i;
		var a=preloadImages.arguments;
		for(i=0; i<a.length; i++) {
			d.preload[i]=new Image;
			d.preload[i].src=a[i];
		}
	}
}

function fieldCheck (mandatory) {
	check=false;
	message='';
		
	for (i in mandatory) {
		if (document.getElementById(i).value=="") {
			message=message+mandatory[i]+', ';
    		//alert ('One or more mandatory fields have not been completed. Please correct this to continue.');
    		check=false;
    		//break;
        }
        else {
        	check=true;
        }
	}
	if (message!='') {
		message='The following required fields have not been completed: \n\n'+message;
		message_object=new String(message);
		message=message_object.substr(0,message_object.length-2);
		alert(message);
		check=false;
	}
	return check;
}

function emailCheckForMultipleEmails (emailStr) {

	var emailError = null;	
	var emailPat=/^(.+)@(.+)$/;
	var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]";
	var validChars="\[^\\s" + specialChars + "\]";
	var quotedUser="(\"[^\"]*\")";
	var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;
	var atom=validChars + '+';
	var word="(" + atom + "|" + quotedUser + ")";
	var userPat=new RegExp("^" + word + "(\\." + word + ")*$");
	var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");
	var matchArray=emailStr.match(emailPat);
	if (matchArray==null)
	{
		emailError = "Email address seems incorrect (check @ and .'s)";
		return emailError;
	}
	var user=matchArray[1];
	var domain=matchArray[2];

	if (user.match(userPat)==null) 
	{
		emailError = "The username doesn't seem to be valid.";
		return emailError
	}
	var IPArray=domain.match(ipDomainPat);
	if (IPArray!=null)
	{
		for (var i=1;i<=4;i++) 
		{
			if (IPArray[i]>255) 
			{
				emailError = "Destination IP address is invalid!";
				return emailError;		
			}
		}
		return null;
	}
	var domainArray=domain.match(domainPat);
	if (domainArray==null) 
	{
		emailError = "The domain name doesn't seem to be valid.";
		return emailError;
	}

	var atomPat=new RegExp(atom,"g")
	var domArr=domain.match(atomPat)
	var len=domArr.length
	if (domArr[domArr.length-1].length<2 || domArr[domArr.length-1].length>3) 
	{
		emailError = "The address must end in a three-letter domain, or two letter country.";
		return emailError
	}
	if (len<2) 
	{
		emailError = "This address is missing a hostname.";	   
		return emailError
	}

	return null;
}

function emailCheck (emailStr) {
	
	var emailPat=/^(.+)@(.+)$/
	//var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]\\/\\?\\!\\£\\$\\%\\&\\#\\~\\*\\'\\|\\`\\=\\¬\\¦\\}\\{\\+\\^"
	//var validChars="\[\\s" + specialChars + "\]"
	var validChars="[a-zA-Z0-9_-]"
	var quotedUser="(\"[^\"]*\")"
	var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/
	var atom=validChars + '+'
	var word="(" + atom + "|" + quotedUser + ")"
	var userPat=new RegExp("^" + word + "(\\." + word + ")*$")
	var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$")
	var matchArray=emailStr.match(emailPat)
	if (matchArray==null) {
		alert("Email address seems incorrect (check @ and .'s)")
		return false
	}
	var user=matchArray[1]
	var domain=matchArray[2]

	if (user.match(userPat)==null) {
    		alert("Email address doesn't seem to be valid.")
    		return false
	}

	var IPArray=domain.match(ipDomainPat)
	if (IPArray!=null) {
	  for (var i=1;i<=4;i++) {
	    if (IPArray[i]>255) {
	        alert("Email address has an invalid destination IP.")
		return false
	    }
    	}
   	 return true
	}
	var domainArray=domain.match(domainPat)
	if (domainArray==null) {
		alert("Email address has an invalid domain name")
   		return false
	}

	var atomPat=new RegExp(atom,"g")
	var domArr=domain.match(atomPat)
	var len=domArr.length
	if (domArr[domArr.length-1].length<2 || 
    		domArr[domArr.length-1].length>4) {
  		alert("Email address must end in a three-letter or four-letter domain, or two letter country.")
   		return false
	}
	if (len<2) {
  		 var errStr="Email address doesn't have a hostname."
  		 alert(errStr)
   		return false
		}
	return true;
}

function setHTTPObject() {
	var xmlhttp=false;
	/*@cc_on @*/
	/*@if (@_jscript_version >= 5)
	// JScript gives us Conditional compilation, we can cope with old IE versions.
	// and security blocked creation of the objects.
	 try {
	  xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
	 } catch (e) {
	  try {
	   xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	  } catch (E) {
	   xmlhttp = false;
	  }
	 }
	@end @*/
	if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
		try {
			xmlhttp = new XMLHttpRequest();
		} catch (e) {
			xmlhttp=false;
		}
	}
	if (!xmlhttp && window.createRequest) {
		try {
			xmlhttp = window.createRequest();
		} catch (e) {
			xmlhttp=false;
		}
	}
	return xmlhttp;
}

function fadeImg(obj,t,t1,t2) {
	setTimeout(function(){ 
		$('#'+obj).animate({
			opacity : 1
			}, 
		t1);
		},
		t*t2);
}

function prepareForAnimation(element) {
	$(element).css('opacity',0).css('visibility','visible');
}
function noAnimation(element) {
	$(element).css('opacity',1).css('visibility','visible');
}


$(document).ready(function(){
	var timeloop = 0;
	prepareForAnimation('.imglinkholder img');
	//prepareForAnimation('#top_menu li');
	noAnimation('#top_menu li');
	$('.imglinkholder img.image-over').hover(
		function() {
			$(this).animate({
			opacity : 0
			}, 
			400);
		},
		function() {
			$(this).animate({
			opacity : 1
			}, 
			300);			
		}
	);
	$('.imglinkholder img.image-default').each(function(){
		objClassName = 'imglink-over'+(timeloop+1);
		fadeImg(objClassName,timeloop,1000,500);
		timeloop++;	
	});
	$('.imglinkholder img.image-over').each(function(){
		objClassName = 'imglink'+(timeloop+1);
		fadeImg(objClassName,timeloop,1000,500);
		timeloop++;	
	});
	/*
	$('#top_menu li').each(function(){
		fadeImg('menu_li_'+(timeloop),timeloop,750,500);
		timeloop++;	
	});
	*/
});