// JavaScript Document

//for use in Email Enquiry page (NOT staff email page)

function MM_goToURL() { //v3.0
  var i, args=MM_goToURL.arguments; document.MM_returnValue = false;
  for (i=0; i<(args.length-1); i+=2) eval(args[i]+".location='"+args[i+1]+"'");
}

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_showHideLayers() { //v6.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'display':(v=='hide')?'none':v; }
    obj.display=v; }
}

function MM_validateForm() { //v4.0
  var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
    if (val) { nm=val.name; if ((val=val.value)!="") {
      if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
        if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
      } else if (test!='R') { num = parseFloat(val);
        if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
        if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
          min=test.substring(8,p); max=test.substring(p+1);
          if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
    } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; }
  } if (errors) alert('Oops! Some fields are either missing or incorrectly entered:\n\n'+errors);
  document.MM_returnValue = (errors == '');
}
function checkemail() {
	if ((document.EmailEnquiry.Email.value !== document.EmailEnquiry.Email2.value)||((document.EmailEnquiry.Email.value == "")||(document.EmailEnquiry.Email2.value == ""))) {
		alert('The email addresses you have entered do not match.\n\nPlease check what you have entered.');
		return false;
	} else {
		return true;
	}
}

function check(i,c){
	if (c==true){
		var style1 = document.getElementById(i).style;
		style1.display = "block";
	} else {
		var style2 = document.getElementById(i).style;
		style2.display = "none";
	}
}
function overseas(m){
	if (m=="Injury") {
		var style1 = document.getElementById('Injury').style;
		style1.display = "block";
		var style2 = document.getElementById('Real Estate').style;
		style2.display = "none";
	} else if (m=="Real Estate") {
		var style3 = document.getElementById('Injury').style;
		style3.display = "none";
		var style4 = document.getElementById('Real Estate').style;
		style4.display = "block";
	} else if (m=="Personal Legals") {
		var style5 = document.getElementById('Injury').style;
		style5.display = "none";
		var style6 = document.getElementById('Real Estate').style;
		style6.display = "none";
	}
}
function compensation(n) {
	if (n=="Claims against deceased estates by potential beneficiaries") {
		var style1 = document.getElementById('Estate').style;
		style1.display = "block";
		var style2 = document.getElementById('Other').style;
		style2.display = "none";
	} else {
		var style1 = document.getElementById('Estate').style;
		style1.display = "none";
		var style2 = document.getElementById('Other').style;
		style2.display = "block";
	}
}
function business(o) {
	if (o!=="Business contract requirements") {
		var style1 = document.getElementById('Contracts').style;
		style1.display = "block";
	} else {
		var style1 = document.getElementById('Contracts').style;
		style1.display = "none";
	}
}

function personalinjury(p) {
	if (p=="Aircraft") {
		var style1 = document.getElementById('PI - Aircraft').style;
		style1.display = "block";
		var style2 = document.getElementById('PI - Other').style;
		style2.display = "none";
	} else {
		var style1 = document.getElementById('PI - Aircraft').style;
		style1.display = "none";
		var style2 = document.getElementById('PI - Other').style;
		style2.display = "block";
	}
}

/////////////////////////////////////////////////////////////

var divs = ["Conveyancing & Leasing", "Personal Injury Compensation", "Compensation - Commercial & Consumer", "Business Contracts & Disputes", "Wills & Estates", "Aviation", "Overseas Visitor & Tourism Services"];

function showme(){
	for (i=1;i<=7;i++){
		if (document.EmailEnquiry["Area"+i].checked==true) {
			check(divs[i-1], true)
		}
	}
}

var overseasdiv = ["Injury","Real Estate","Personal Legals"];

function resett(){
	for (i=0;i<=divs.length-1;i++){
		var style = document.getElementById(divs[i]).style;
		style.display = "none";
	}
	showme();
	overseas(document.getElementById("Overseas - Assistance Required").value);
	compensation(document.getElementById("Compensation - Type").value);
	business(document.getElementById("Business - Type").value);
	personalinjury(document.getElementById("PI - Type of Accident").value);
}

/////////////////////////////////////////////////////////////


//for referral form
function detector(val) {
		if (val=='Yes') {
			var style = document.getElementById('reff').style;
			style.display = "block";
			var style = document.getElementById('yourcontactdetails').style;
			style.display = "none";
		} else if (val=='No') {
			var style = document.getElementById('reff').style;
			style.display = "none";
			var style = document.getElementById('yourcontactdetails').style;
			style.display = "block";
		}
	}

