// JavaScript Document
function isValidURL(url){
    var RegExp = /^(([\w]+:)?\/\/)?(([\d\w]|%[a-fA-f\d]{2,2})+(:([\d\w]|%[a-fA-f\d]{2,2})+)?@)?([\d\w][-\d\w]{0,253}[\d\w]\.)+[\w]{2,4}(:[\d]+)?(\/([-+_~.\d\w]|%[a-fA-f\d]{2,2})*)*(\?(&?([-+_~.\d\w]|%[a-fA-f\d]{2,2})=?)*)?(#([-+_~.\d\w]|%[a-fA-f\d]{2,2})*)?$/;
    if(RegExp.test(url)){
        return true;
    }else{
        return false;
    }
} 
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 E-mail address")
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert("Invalid E-mail address")
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    alert("Invalid E-mail address")
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    alert("Invalid E-mail address")
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    alert("Invalid E-mail address")
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    alert("Invalid E-mail address")
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    alert("Invalid E-mail address")
		    return false
		 }

 		 return true					
	}

function validate_form ( )
{
    valid = true;
    if ( document.adv_input.subj.value == "" )
    {
        alert ( "Please fill in the 'Subject' box." );
        valid = false;
    }
	if ( document.adv_input.cat.value == "" )
    {
        alert ( "Please make a selection in the 'category' box." );
        valid = false;
    }
	if ( document.adv_input.cat.value != "Venues" )
    {
     if (( document.adv_input.period.value == "" )|| (document.adv_input.period.value == "0"))
		{
			alert ( "Please make a selection in the 'period' box." );
			valid = false;
		}   
    }
	
	if ( document.adv_input.dept.value == "" )
    {
        alert ( "Please make a selection in the first 'Dept' box." );
        valid = false;
    }
	if ( document.adv_input.dept2.value == "" )
    {
        alert ( "Please make a selection in the second 'Dept' box." );
        valid = false;
    }
	if ( document.adv_input.dept3.value == "" )
    {
        alert ( "Please make a selection in the third 'Dept' box." );
        valid = false;
    }
	if ( document.adv_input.desc_s.value == "" )
    {
        alert ( "Please fill in the 'Short description' box." );
        valid = false;
    }
	if ( document.adv_input.desc_l.value == "" )
    {
        alert ( "Please fill in the 'Long description' box." );
        valid = false;
    }
	var emailID=document.adv_input.email
	if ((emailID.value==null)||(emailID.value=="")){
		alert("Please fill in the 'email' box.")
		emailID.focus()
		valid = false
	}
	if (echeck(emailID.value)==false){
		emailID.value=""
		emailID.focus()
		valid = false
	}
	/*if ( document.adv_input.email.value == "" )
    {
        alert ( "Please fill in the 'email' box." );
        valid = false;
    }*/
	if ( document.adv_input.fname.value == "" )
    {
        alert ( "Please fill in the 'Full Name' box." );
        valid = false;
    }
	if ( document.adv_input.street.value == "" )
    {
        alert ( "Please fill in the 'Address - street' box." );
        valid = false;
    }
	if ( document.adv_input.pcode.value == "" )
    {
        alert ( "Please fill in the 'Post code' box." );
        valid = false;
    }
	if ( document.adv_input.tel.value == "" )
    {
        alert ( "Please fill in the 'Telephone number' box." );
        valid = false;
    }
	/*if ( document.adv_input.file[0].value == "" )
    {
		alert ( "Please select a file." );
        valid = false;
    }*/
	
    return valid;
}

