// JavaScript Document
function mapinit(){
if (GBrowserIsCompatible()) {
 var map = new GMap2(document.getElementById("map"));
 map.setCenter(new GLatLng(53.848430, -1.838617), 17);
 var point = new GLatLng(53.848430, -1.838617);

 var info = "<DIV style='font-size: 0.7em;'>Illingworth McNair Limited<BR>164 Main Street<BR>Bingley<BR>West Yorkshire<BR>BD16 2HR</DIV>";
 var marker= new GMarker(point);
 GEvent.addListener(marker, "click", function(){marker.openInfoWindowHtml(info);});
 map.addOverlay(marker);

 map.addControl(new GLargeMapControl());
 map.addControl(new GMapTypeControl());

}
else
{
 document.getElementById("map").innerHTML = "<img src='images/map.gif'>";
 document.getElementById("map").style.marginLeft="0px";
 document.getElementById("map").style.width="500px";
 document.getElementById("map").style.height="295px";  
}
fullinit();
}

function fullinit(){
findAccessKeys();
externalLinks();
doProp();
}
function fullinitForm(field){
findAccessKeys();
externalLinks();
doProp();
if (field!="")
 {
  for (var i=0; i<document.forms[0].elements.length; i++) { 
    if (document.forms[0].elements[i].name==field)
    {
     document.forms[0].elements[i+1].focus();
     break;
    }   
  }   
 }
}

function doProp(){
 if (document.getElementById("rhcol")){
  lhheight=document.getElementById("lhcol").offsetHeight;
  rhheight=document.getElementById("rhcol").offsetHeight;
  if (lhheight>rhheight){
   footerpropheight=lhheight-rhheight;
   document.getElementById("footerprop").style.height=footerpropheight + "px";
  }
 }
}

function fieldchange(fieldspec){
var typeArray= new Array(["none","Not Specified"],["car", "Car"],["van", "Van"],["travel","Travel"],["home","Home and Contents"],["landlords","Landlords"],["commercial","Commercial"],["commercialcombined","Commercial Combined"],["liability","Liability"],["motortrade","Motor Trade"],["shop","Shop"],["office","Office"],["restaurant","Restaurant"],["engineering","Engineering"],["professionalindemnity","Professional Indemnity"],["marinetransit","Marine Transit"],["goodsintransit","Goods in Transit"],["directorsandofficers","Directors and Officers"],["employmentpractice","Employment Practice"],["terrorism","Terrorism"],["personalaccident","Personal Accident"],["life","Life and Pensions"]);

field=document.forms[0].InsuranceRequired;
insurancetype=field.options[field.selectedIndex].value;
for (var i=0; i<typeArray.length; i++){
 if (typeArray[i][1]==insurancetype){
  type=typeArray[i][0];
  }
 }
 var fieldspec1="";
 if (fieldspec != "none"){
 fieldspec1 = "&field="+fieldspec; 
 }

document.EnquiryForm.action = "enquiry.php?r=Yes&type="+type+fieldspec1;
document.EnquiryForm.submit();
}

function setrequired(required){
required1 = required.split(",");
for (var i=0; i<required1.length; i++)
 {
  required2=required1[i].split(":");
  labels=document.getElementsByTagName("label");
  for (var j=0; j<labels.length; j++) {
  labelfor=labels[j].getAttribute('for')?labels[j].getAttribute('for'):labels[j].getAttribute('htmlFor');
   if (labelfor==required2[0])
    {
     labels[j].style.fontStyle="italic";
     labels[j].style.fontWeight="bold";
    } 
  }
 }
}

function prizefieldchange(fieldspec){
 var fieldspec1="";
 if (fieldspec != "none"){
 fieldspec1 = "&field="+fieldspec;
 }

document.FeedbackForm.action = "prizedraw.php?renew=Yes"+fieldspec1;
document.FeedbackForm.submit();
}


function validate(required){
var nosubmit=0;
required1 = required.split(",");
for (var i=0; i<required1.length; i++)
 {
  required2=required1[i].split(":");
  labels=document.getElementsByTagName("label");
  for (var j=0; j<labels.length; j++) {
  labelfor=labels[j].getAttribute('for')?labels[j].getAttribute('for'):labels[j].getAttribute('htmlFor');
   if (labelfor==required2[0])
    {
     if (document.getElementById(required2[0]).value=="" || document.getElementById(required2[0]).value=="NotSpecified")
      {
       labels[j].style.color="#FF0000"; 
       nosubmit=1;
      }  
    } 
  }
 }
if (document.getElementById("Name").value=="")
 {
  labels[0].style.color="#FF0000"; 
  nosubmit=1;
 }  
if (nosubmit!=0){
 alert("Please complete all the fields shown in bold italics.");
}
else
{
 if (document.forms[0].InsuranceRequired)
 {
  type=document.forms[0].InsuranceRequired.selectedIndex;
  if (type==1 || type==2)
  {
   document.forms[0].recipients.value="jamieFG5CPRillingworth-mcnair.co.uk";
  }
  if (type>5 && type<20)
  {
   document.forms[0].recipients.value="jamieFG5CPRillingworth-mcnair.co.uk";
  }
  if (type==4)
  {
   document.forms[0].recipients.value="nicolFG5CPRillingworth-mcnair.co.uk";
  }
 }  
 document.forms[0].submit();
}
}



function gotoEnquiry(type){
location.href="enquiry.php?type="+type;
}

function gotoEnquiryHome(contents, buildings){
location.href="enquiry.php?type=home&contents="+contents+"&buildings="+buildings;
}



function calcfieldchange(fieldspec){
 var fieldspec1="";
 if (fieldspec != "none"){
 fieldspec1 = "&field="+fieldspec;
 }
document.ContentsCalculator.action = "calculator.php?r=Yes&continue=Yes"+fieldspec1;
document.ContentsCalculator.submit();
}

function continuecalc(){
document.ContentsCalculator.action = "calculator.php?r=Yes&continue=Yes";
document.ContentsCalculator.submit();
}

function calculate(){
document.ContentsCalculator.action = "calculator.php?r=Yes&continue=Yes&calculate=Yes";
document.ContentsCalculator.submit();
}


function findAccessKeys() { 
var fieldspecs = document.getElementsByTagName("a"); 
 for (var i=0; i<fieldspecs.length; i++) { 
  var fieldspec = fieldspecs[i]; 
  if (fieldspec.getAttribute("accesskey")) {
     highlightAccessKey(fieldspec, fieldspec.getAttribute("accesskey"));
   }
 }
} 
function highlightAccessKey(e, accessKey) {
    if (e.hasChildNodes()) {
        var childNode, txt;
        //find the first text node that contains the access character
        for (var i = 0; i < e.childNodes.length; i++) {
            txt = e.childNodes[i].nodeValue;
            if (e.childNodes[i].nodeType == 3 &&
                txt.toLowerCase().indexOf(accessKey.toLowerCase()) != -1) {
            
                childNode = e.childNodes[i];
                break;
            }
        }
        
        if (!childNode) {
            //access character was not found
            return;
        }

        var pos = txt.toLowerCase().indexOf(accessKey.toLowerCase());
        var span = document.createElement('span');
        var spanText = document.createTextNode(txt.substr(pos, 1));
        span.className = 'accesskey';
        span.appendChild(spanText);

        //the text before the access key
        var text1 = document.createTextNode(txt.substr(0, pos));
        //the text after the access key
        var text2 = document.createTextNode(txt.substr(pos + 1));
        
        if (text1.length > 0) e.insertBefore(text1, childNode);
        e.insertBefore(span, childNode);
        if (text2.length > 0) e.insertBefore(text2, childNode);

        e.removeChild(childNode);
    }
}

function externalLinks() { 
 if (!document.getElementsByTagName) return;
  if (document.getElementById("newwindowlinks")){
   document.getElementById("newwindowlinks").style.display="inline"; 
  }
 var fieldspecs = document.getElementsByTagName("a"); 
 for (var i=0; i<fieldspecs.length; i++) { 
   var fieldspec = fieldspecs[i]; 
   if (fieldspec.getAttribute("href") && 
       fieldspec.getAttribute("rel") == "external") 
       fieldspec.target = "_blank"; 
 } 
}
function externalLinksOff() { 
 if (!document.getElementsByTagName) return;
  if (document.getElementById("newwindowlinks")){
   document.getElementById("newwindowlinks").style.display="none"; 
  }
 var fieldspecs = document.getElementsByTagName("a"); 
 for (var i=0; i<fieldspecs.length; i++) { 
   var fieldspec = fieldspecs[i]; 
   if (fieldspec.getAttribute("href") && 
       fieldspec.getAttribute("rel") == "external") 
       fieldspec.target = "_self"; 
 }
 var images = document.getElementsByTagName("img");
 for (var i=0; i<images.length; i++) { 
   var image = images[i];
   var len = image.getAttribute("src").length;
   var firstchar = image.getAttribute("src").lastIndexOf("/") + 1;
   var filename = image.getAttribute("src").substring(firstchar,len);
   if (filename == "newwin.gif")
     image.style.display = "none";
    
 }  
} 

