function write_cookie(name,value) {
  if(document.cookie) {
  index = document.cookie.indexOf(name);
  } else {
    index = -1;
  }
    document.cookie=name+"="+escape(value)+"; expires=Wednesday, 01-Aug-2040 08:00:00 GMT";
}

function delete_cookie(name,value) {
  if(document.cookie) {
  index = document.cookie.indexOf(name);
  } else {
    index = -1;
  }
    document.cookie=name+"="+escape(value)+"; expires=Sunday, 01-Feb-2009 08:00:00 GMT";
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function check() {
  var ext = document.f.largeimage.value;
  ext = ext.substring(ext.length-3,ext.length);
  ext = ext.toLowerCase();
  if(ext != 'jpg' && ext != 'gif' && ext != 'jpeg' && ext != '') {
    alert('You selected a .'+ext+' file in the Image field. Please select a .jpg, .jpeg or .gif file instead!');
    return false;
	}else{
    return true;
	}

  var ext = document.f.info_sheet.value;
  ext = ext.substring(ext.length-3,ext.length);
  ext = ext.toLowerCase();
  if(ext != 'pdf' && ext != 'PDF') {
    alert('You selected a .'+ext+' file in the Info Sheet field. Please select a .pdf file instead!');
    return false;
	}else{
    return true;
	}
}

// pop up window script
var WindowObjectReference = null;
var PreviousUrl;

function openRequestedSinglePopup(strUrl)
{
  if(WindowObjectReference == null || WindowObjectReference.closed)
  {
   WindowObjectReference = window.open(strUrl, "SingleSecondaryWindowName",
         "resizable=yes,scrollbars=yes,width=550,height=700");
  }
  else if(PreviousUrl != strUrl)
  {
   WindowObjectReference = window.open(strUrl, "SingleSecondaryWindowName",
      "resizable=yes,scrollbars=yes,width=550,height=700");
   WindowObjectReference.focus();
  }
  else
  {
    WindowObjectReference.focus();
  };
  PreviousUrl = strUrl;
}

// validate email address
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){
		   alert("Invalid email address!");
		   return false;
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert("Invalid email address!");
		   return false;
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    alert("Invalid email address!");
		    return false;
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    alert("Invalid email address!");
		    return false;
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    alert("Invalid email address!");
		    return false;
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    alert("Invalid email address!");
		    return false;
		 }
		
		 if (str.indexOf(" ")!=-1){
		    alert("Invalid email address!");
		    return false;
		 }

 		 return true;					
	}

function validate_form()
{
		if(document.form1.Name.value == ""){
                alert("Please enter your name");
				document.form1.Name.focus();
				document.form1.Name.style.background = 'Yellow';
				//this.form.submit();
				return false;
//		}else{
//			document.form1.form_check.value = "1";
		}
/*
		if(document.form1.booksurname.value == ""){
                alert("Please enter your surname");
				document.form1.booksurname.focus();
				document.form1.booksurname.style.background = 'Yellow';
                return false;
		}
		if(document.form1.bookorganisation.value == ""){
                alert("Please enter your organisation");
				document.form1.bookorganisation.focus();
				document.form1.bookorganisation.style.background = 'Yellow';
                return false;
		}
		if(document.form1.bookaddress.value == ""){
                alert("Please enter your address");
				document.form1.bookaddress.focus();
				document.form1.bookaddress.style.background = 'Yellow';
                return false;
		}
		if(document.form1.bookcity.value == ""){
                alert("Please enter a city/town");
				document.form1.bookcity.focus();
				document.form1.bookcity.style.background = 'Yellow';
                return false;
		}
		
		if(document.form1.bookcountry.value == "United Kingdom"){
		var myPostCode = document.getElementById('bookpostcode').value;
		if(myPostCode == ''){
			alert("Please enter your post code");
			document.form1.bookpostcode.focus();
			document.form1.bookpostcode.style.background = 'Yellow';
            return false;
		}
		
		if (checkPostCode (myPostCode)) {
		document.getElementById('bookpostcode').value = checkPostCode (myPostCode);
		} else {
		alert ("Postcode has invalid format")
		document.form1.bookpostcode.focus();
		document.form1.bookpostcode.style.background = 'Yellow';
		return false;
		}
		}
		
		if(document.form1.booktel.value == ""){
                alert("Please enter your telephone number");
				document.form1.booktel.focus();
				document.form1.booktel.style.background = 'Yellow';
                return false;
		}
		if(document.form1.bookposition.value == ""){
                alert("Please enter your position");
				document.form1.bookposition.focus();
				document.form1.bookposition.style.background = 'Yellow';
                return false;
		}

		if(document.form1.Email.value == ""){
                alert("Please enter your email address");
				document.form1.Email.focus();
				document.form1.Email.style.background = 'Yellow';
				return false;
		}
		if (echeck(document.form1.Email.value)==false){
		document.form1.Email.value="";
		document.form1.del1email.value="";
		document.form1.Email.focus();
		return false;
		}
		
		if(document.form1.del1name.value == ""){
                alert("Please enter the name of the first delegate");
				document.form1.del1name.focus();
				document.form1.del1name.style.background = 'Yellow';
				return false;
		}
		if(document.form1.del1surname.value == ""){
                alert("Please enter the surname of the first delegate");
				document.form1.del1surname.focus();
				document.form1.del1surname.style.background = 'Yellow';
				return false;
		}
		if(document.form1.del1position.value == ""){
                alert("Please enter the position of the first delegate");
				document.form1.del1position.focus();
				document.form1.del1position.style.background = 'Yellow';
				return false;
		}
		if(document.form1.del1email.value == ""){
                alert("Please enter the email of the first delegate");
				document.form1.del1email.focus();
				document.form1.del1email.style.background = 'Yellow';
				return false;
		}
		if (echeck(document.form1.del1email.value)==false){
		document.form1.del1email.value="";
		document.form1.del1email.focus();
		return false;
		}
		
		if((document.form1.streamdel1.value == "0") || (document.form1.streamdel1.selectedIndex == 0)){
                alert("Please select a stream");
				document.form1.streamdel1.focus();
				document.form1.streamdel1.style.background = 'Yellow';
				return false;
		}
		if(document.form1.del2surname.value != "" && document.form1.streamdel2.value == "0"){
                alert("Please select a stream for delegate 2");
				document.form1.streamdel2.focus();
				document.form1.streamdel2.style.background = 'Yellow';
				return false;
        }
		if(document.form1.del3surname.value != "" && document.form1.streamdel3.value == "0"){
                alert("Please select a stream for delegate 3");
				document.form1.streamdel3.focus();
				document.form1.streamdel3.style.background = 'Yellow';
				return false;
        }
		if(document.form1.del4surname.value != "" && document.form1.streamdel4.value == "0"){
                alert("Please select a stream for delegate 4");
				document.form1.streamdel4.focus();
				document.form1.streamdel4.style.background = 'Yellow';
				return false;
        }
		if(document.form1.del5surname.value != "" && document.form1.streamdel5.value == "0"){
                alert("Please select a stream for delegate 5");
				document.form1.streamdel5.focus();
				document.form1.streamdel5.style.background = 'Yellow';
				return false;
        }
*/
}

function reset() {
document.tellafriend.name.value="";
document.tellafriend.email.value="";
document.tellafriend.friendmail1.value="";
document.tellafriend.friendmail2.value="";
document.tellafriend.friendmail3.value="";
}

function validate() {
if (document.tellafriend.friendmail1.value.length==0) {
alert("please enter your friend's email address");
return false;
}

if (document.tellafriend.email.value.length==0) {
alert("please enter your email address");
return false;
}
if (document.tellafriend.name.value.length==0) {
alert("please enter your name");
return false;
}

document.tellafriend.submit()
return true;
}

