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("Sorry, the email address you have input is invalid. \n")
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert("Sorry, the email address you have input is invalid. \n")
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    alert("Sorry, the email address you have input is invalid. \n")
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    alert("Sorry, the email address you have input is invalid. \n")
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    alert("Sorry, the email address you have input is invalid. \n")
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    alert("Sorry, the email address you have input is invalid. \n")
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    alert("Sorry, the email address you have input is invalid. \n")
		    return false
		 }

 		 return true					
	}
        
function check_form(){
    var alertText = "";
    valid = true;
    
    if ( document.callbackForm.title.value == "" )
    {
        alertText += "Please select your title. \n";
        valid = false;
    }
    
    if ( document.callbackForm.forename.value == "" )
    {
        alertText += "Please fill in the 'Forename' box. \n";
        valid = false;
    }
    
    if ( document.callbackForm.surname.value == "" )
    {
        alertText += "Please fill in the 'Surname' box. \n";
        valid = false;
    }
    
    if ( document.callbackForm.organisation.value == "" )
    {
        alertText += "Please fill in the 'Organisation Name' box. \n";
        valid = false;
    }
    
    if ( document.callbackForm.employees.value == "" )
    {
        alertText += "Please enter the number of employees. \n";
        valid = false;
    }
    
    if ( document.callbackForm.emailReq.checked == "" & document.callbackForm.postReq.checked == "" )
    {
        alertText += "Please select a method of information delivery (post and/or email). \n";
        valid = false;
    }
    
    if ( document.callbackForm.postReq.checked != "")
    {
        if ( document.callbackForm.address1.value == "" )
        {
            alertText += "Please fill in the top line of the address box. \n";
            valid = false;
        }
        if ( document.callbackForm.city.value == "" )
        {
            alertText += "Please fill in the 'City' box. \n";
            valid = false;
        }
        if ( document.callbackForm.cb_postcode.value == "" )
        {
            alertText += "Please fill in the 'Postcode' box. \n";
            valid = false;
        }
    }    
    
    if ( document.callbackForm.emailReq.checked != "" & document.callbackForm.email.value == "" )
    {
        alertText += "Please fill in the 'Email' box. \n";
        valid = false;
    } else if( document.callbackForm.emailReq.checked != "" & document.callbackForm.email.value != "" ) {
        var emailID=document.callbackForm.email
	
	if ((emailID.value==null)||(emailID.value=="")){
		alert("Please Enter your Email address \n")
		emailID.focus()
	}
	if (echeck(emailID.value)==false){
		emailID.value=""
		emailID.focus()
		return false
	}
    }
    
	
    
    if ( alertText != "" )
    {
        alert(alertText);
        valid = false;
    } else {
        var div_ref = document.getElementById("subButton");
        div_ref.style.visibility = "hidden";
        sendSuggestion();
    }
}

function show_addr() {
var div_ref = document.getElementById("postAddress");
  div_ref.style.visibility = "visible";
}

function show_email() {
var div_ref = document.getElementById("postEmail");
  div_ref.style.visibility = "visible";
}

var sendSuggestionURL	= '/information/corporate-eyecare/callback/send.php';
function sendSuggestion ()
{
	
	var query	= 'title=' + encodeURI ($('title').value);
	
	if ($('forename').value != '')
	{
		query	+= '&forename=' + encodeURI ($('forename').value);
	}
	
	if ($('surname').value != '')
	{
		query	+= '&surname=' + encodeURI ($('surname').value);
	}
        
        if ($('organisation').value != '')
	{
		query	+= '&organisation=' + encodeURI ($('organisation').value);
	}
        
        if ($('employees').value != '')
	{
		query	+= '&employees=' + encodeURI ($('employees').value);
	}
        
        if ($('tel').value != '')
	{
		query	+= '&tel=' + encodeURI ($('tel').value);
	}
        
        if ($('postReq').checked != '')
	{
		query	+= '&postReq=' + encodeURI ($('postReq').value);
	}
        
        if ($('emailReq').checked != '')
	{
		query	+= '&emailReq=' + encodeURI ($('emailReq').value);
	}
	
        if ($('vduReq').checked != '')
	{
		query	+= '&vduReq=' + encodeURI ($('vduReq').value);
	}
	
	if ($('vsReq').checked != '')
	{
		query	+= '&vsReq=' + encodeURI ($('vsReq').value);
	}
	
        if ($('address1').value != '')
	{
		query	+= '&address1=' + encodeURI ($('address1').value);
	}
        
        if ($('address2').value != '')
	{
		query	+= '&address2=' + encodeURI ($('address2').value);
	}
        
        if ($('address3').value != '')
	{
		query	+= '&address3=' + encodeURI ($('address3').value);
	}
        
        if ($('city').value != '')
	{
		query	+= '&city=' + encodeURI ($('city').value);
	}
        
        if ($('county').value != '')
	{
		query	+= '&county=' + encodeURI ($('county').value);
	}
        
	if ($('cb_postcode').value != '')
	{
		query	+= '&cb_postcode=' + encodeURI ($('cb_postcode').value);
	}
        
	if ($('email').value != '')
	{
		query	+= '&email=' + encodeURI ($('email').value);
	}
	
	var objAjax		= new Ajax.Request (sendSuggestionURL, {method: 'post', parameters: query, onComplete: sendSuggestion_Return});
	
}

// sendSuggestion_Return function

function sendSuggestion_Return (response)
{
	
	switch (response.responseText)
	{
			
		case 'success':
			ajaxbox.goto ('/information/corporate-eyecare/callback/thanks.php');
			break;
			
		default:
			$('lightbox_message').innerHTML	= '<p>'+response.responseText+'</p>';
                        var div_ref = document.getElementById("subButton");
                        div_ref.style.visibility = "visible";
                        break;
		
	}
	
}