
function loadImages(){
    if (document.images) {
         button1 = new Image
         button2 = new Image
	 button3 = new Image
         button4 = new Image
    
         button1.src = 'images/email_us.png'
         button2.src = 'images/email_us-ovr.png'
	 button3.src = 'images/click_here.png'
         button4.src = 'images/click_here-ovr.png'
     }
 }
 
function swapOut(id) {
	switch(id){
		
		case 'emailus':
		document.getElementById(id).src = button2.src;
		break;
		
		case 'click':
		document.getElementById(id).src = button4.src;
		break;
	}
  return true;
} 

function swapBack(id){
	switch(id){
		
		case 'emailus':
		document.getElementById(id).src = button1.src;
		break;
		
		case 'click':
		document.getElementById(id).src = button3.src;
		break;
	}
  return true;
}

function valButton(btn) {
    var cnt = -1;
    for (var i=btn.length-1; i > -1; i--) {
        if (btn[i].checked) {cnt = i; i = -1;}
    }
    if (cnt > -1) return btn[cnt].value;
    else return null;
}

function ValidateForm(){
	var emailID = document.getElementById('email');
        var name = document.getElementById('name');
		var company = document.getElementById('company');
	    var contact = document.getElementById('contact');
		var area = document.getElementById('area');
        var selection = document.getElementsByName('selection[]');	
        var cnt = -1;
	
        for (var i=selection.length-1; i > -1; i--) {
            if (selection[i].checked) {cnt = i; i = -1;}
        }        
        if (cnt <= -1){
                alert("Please select which products and services you are interested in");
                return false
        }
        
        if ((name.value==null)||(name.value=="")){
		alert("Please enter name")
		name.focus()
		return false
	}
		
	if ((emailID.value==null)||(emailID.value=="")){
		alert("Please enter your email address")
		emailID.focus()
		return false
	}
		
	if (echeck(emailID.value)==false){               
		emailID.value=""
		emailID.focus()
		return false
	}
		
	if ((contact.value==null)||(contact.value=="")){
		alert("Please enter contact number")
		contact.focus()
		return false
	}
	
	if ((company.value==null)||(company.value=="")){
		alert("Please enter the name of your company")
		company.focus()
		return false
	}
	
	if ((area.value==null)||(area.value=="")){
		alert("Please advise of your parish/town of residence")
		area.focus()
		return false
	}
        
	return true
 }

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 ID")
		   return false
		}

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

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

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

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

 		 return true					
}