function rollover(image,source,folder,path) {
	document.getElementById(image).src=path+'/'+'images/'+folder+'/'+source+'_over.gif';
}
function rollout(image,source,folder,path) {
	document.getElementById(image).src=path+'/'+'images/'+folder+'/'+source+'.gif';
}

function rollover2(image,source,folder,path) {
//	alert(source);
	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 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 submitAppReq()
{		
	var errorAlert = "";	

	if(document.emailform.recipients_email.value == "")
	{
		errorAlert = "Please supply your friend's email address(es).";
	}
	else if(document.emailform.senders_name.value == "")
	{
		errorAlert = "Please enter your name.";
	} 
	else if(document.emailform.senders_email.value == "")
	{
		errorAlert = "Please enter your email address.";
	} 
	else if (document.emailform.recipients_email.value != "")
	{
		var toEmailString = document.emailform.recipients_email.value;
		var addAry = toEmailString.split(',');
		var addCount = addAry.length;
		
		for(i=0;i<addCount;i++)
		{
			var toEmailAddress = addAry[i];
			toEmailAddress = toEmailAddress.replace(/ /g, "");
			if (!emailCheckForMultipleEmails(toEmailAddress)=="")
			{
				emailError = emailCheckForMultipleEmails(toEmailAddress);
				if(addCount > 1)
				{					
					errorAlert = "One of the addresses you entered (" + toEmailAddress + ") for your friends does not appear to be valid:\n\n" + emailError;
				}
				else
				{
					errorAlert = "The email address you entered for your friend does not appear to be valid:\n\n" + emailError ;
				}
			}

		}
	}
	if(!emailCheckForMultipleEmails(document.emailform.senders_email.value)=="")
	{
		emailError = emailCheckForMultipleEmails(document.emailform.senders_email.value);
		errorAlert = "The email address you entered for yourself does not appear to be valid:\n\n" + emailError;
	}		

	if(errorAlert != "")
	{
		alert(errorAlert);
	}
	else
	{
		document.emailform.submit();
	}				
}


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 launch_window(url,name) {
	window.open(url,name,'width=510, height=600, scrollbars=yes, status=no, menubar=no, location=no, resizeable=no');
	return;
}
/* function preloader() {
	preloadImage = new Image(); 
	preloadImage.src ='{imageById id="894"}';
}	*/

function preloadImages() {
    var d=document; 
    if(d.images) { 
        d.preload=new Array();
        var i;
        var a=preloadImages.arguments;
        var webpath=a[a.length-1];
        for(i=0; i<a.length-1; i++) {
            d.preload[i]=new Image; 
            d.preload[i].src=webpath+'/images/dynamic/'+a[i]+'.gif';
        }
    }
}

function check_for_duplicates(id,flag,message) {
    var extra='';
    if(flag==1) {
        extra='_o';
    }
    var selected_value=document.getElementById('serialno'+extra+id).value;
    var success_flag=true;
    var i;
    
    if(selected_value!='') {
	    for(i=0;i<7;i++) {    
		    if(!(i == id && flag == 0) && document.getElementById('serialno'+i).value!='' && document.getElementById('serialno'+i).value==selected_value) {
		        success_flag=false;
		        break;
		    }
		    else if(!(i == id && flag == 1) && document.getElementById('serialno_o'+i).value!='' && document.getElementById('serialno_o'+i).value==selected_value) {
		        success_flag=false;
		        break;
		    }
	    }
	    if(!success_flag) {//alert(i+'-'+id);
	
		        alert(message);
		        document.getElementById('serialno'+extra+id).value=null;
	
	    }
    }
    return success_flag;
}