// JavaScript Document
menus_array = new Array ('home', 'ourcompany','whatwedo', 'whatwecare', 'news', 'perspective', 'contact', 'legalinformation');
menus_status_array = new Array ();
function toggleSheet(theid) {
  if (document.getElementById) {
    var switch_id = document.getElementById(theid);
    var imgid = theid+'Button';
    var button_id = document.getElementById(imgid);
    if (menus_status_array[theid] != 'show') {
      //button_id.className = 'rolldown';
      switch_id.className = 'showSwitch';
	  menus_status_array[theid] = 'show';
    } else {
      //button_id.className = 'rollup';
      switch_id.className = 'hideSwitch';
	  menus_status_array[theid] = 'hide';
    }
  }
}
function setMenu() {
  if (document.getElementById) {
    for (var i=0; i < menus_array.length; i++) {
      var idname = menus_array[i];
      if (document.getElementById(idname)) {
		var switch_id = document.getElementById(idname);
		var imgid = idname+'Button';
		var button_id = document.getElementById(imgid);
		//button_id.className = 'rollup';
		switch_id.className = 'hideSwitch';
		menus_status_array [idname] = 'hide';
	  }
    }
  }
}
// Form checking elements
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){
		   return false
		}
		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   return false
		}
		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		   return false
		}
		if (str.indexOf(at,(lat+1))!=-1){
		   return false
		}
		if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		   return false
		}
		if (str.indexOf(dot,(lat+2))==-1){
		   return false
		}
		if (str.indexOf(" ")!=-1){
		   return false
		}
 		return true					
}
function fcheck() {
	var reg = new RegExp("^.+@.+\\..+$","g"); // Regular expression to test email address. Test it with if (!reg.test(email))
	var missing = ""; // List of fields not completed. If it's empty by the end of the test, all fields have been completed (doh!)
	// Get form field values
	var title = document.CONTACTUSFORM.title.selectedIndex;
	var forename = document.CONTACTUSFORM.forename.value.length;
	var surname = document.CONTACTUSFORM.surname.value.length;
	var email = document.CONTACTUSFORM.email.value;
	var comments = document.CONTACTUSFORM.comments.value.length;
	
	// Test the form values
	if (title == 0) {
		missing += 'Title\n';
	}
	if (forename == 0) {
		missing += 'Forename(s)\n';
	}
	if (surname == 0) {
		missing += 'Surname\n';
	}
	if (echeck(email)==false){
		missing += 'Email address\n';
		//emailID.value=""
		//emailID.focus()
		//return false
	}
	if (comments == 0) {
		missing += 'Your enquiry\n';
	}
	
	if (missing.length) {	
		var err = 'You must complete the entire form.\n\nThe following fields have not been completed : \n\n'+missing;
		alert(err) ;
	} else {
		document.CONTACTUSFORM.submit() ;
	}
}
// Div drops
function toggleDiv( elemID )
{
    var elem = document.getElementById( elemID );
    if( elem.style.position != 'absolute' )
    {
        elem.style.position = 'absolute';
        elem.style.left = '-4000px';
    }
    else
	{
		elem.style.position = 'relative';
        elem.style.left = '0px';
    }
}