function jump_menu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0; 
}

function MM_jumpMenu(targ,selObj,restore){ //v3.0 to maintain compatiblity - will be deprecated after June 01
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0; 
}

function openBrWindow(theURL,winName,features) { //v2.0
   window.open(theURL,winName,features);
  //if (newWind.opener == null) { // for Nav 2.0x 
   //newWind.opener = self // this creates and sets a new property 
//}
}

function composeToFOE (cand,subj) {
   var doc;
   var body = "Message sent from this page:\r\n"+window.location.href+"\r\n";
	if(cand!='' && cand.indexOf('@')==-1) {
		cand = cand+'@foe.co.uk';
	}
	if(subj==undefined) {
		subj = '';
		doc = "mailto:" + cand;

	} else {
		doc = "mailto:" + cand+ "?subject="+escape(subj)+"&body="+escape(body);
   }

   // POP UP EMAIL MESSAGE WINDOW
   window.location = doc;	
}

//line break to <br> conversion utils for textarea elements Chrisg 19.02.04
//Now generic to any field regards of name where output should be XHTML
function addBRtags(selObj){
	for (i=0; i < selObj.elements.length; i++){
	if (selObj.elements[i].type=="textarea"){
		if(selObj.elements[i].value.indexOf("<br />")==-1){
			selObj.elements[i].value = selObj.elements[i].value.replace(new RegExp("[\n\r]","g"),"<br />")
		}
	}
 }
}

function removeBRtags(selObj){
	if(selObj){
		selObj.value = selObj.value.replace(new RegExp("<br />","g"),"\r");
		selObj.value = selObj.value.replace(new RegExp("<br>","g"),"\r");
	}
}

//Clears form fields of accessibility text Chrisg 11.10.03
function clear_field(selObj){
//for when user focus on field	
if((selObj.value.indexOf("Enter ")!=-1)||(selObj.value.indexOf("Nodwch")!=-1)||(selObj.value.indexOf("Vul")!=-1)||(selObj.value.indexOf("Entrez")!=-1)||(selObj.value.indexOf("Inserisci")!=-1)||(selObj.value.indexOf("Introduce")!=-1)||(selObj.value.indexOf("Tragen")!=-1)||(selObj.value.indexOf("Tapez")!=-1)||(selObj.value.indexOf("Zadejte")!=-1)||(selObj.value.indexOf("Írja")!=-1)||(selObj.value.indexOf("Wpisz")!=-1)){
selObj.value='';
}
}

function clear_form(selObj){
//for use when user submits form without filling some fields
for (i=0; i < selObj.elements.length; i++){
	if ((selObj.elements[i].type=="text")||(selObj.elements[i].type=="textarea")){
		if((selObj.elements[i].value.indexOf("Enter ")!=-1)||(selObj.elements[i].value.indexOf("Nodwch")!=-1)||(selObj.elements[i].value.indexOf("Vul")!=-1)||(selObj.elements[i].value.indexOf("Entrez")!=-1)||(selObj.elements[i].value.indexOf("Inserisci")!=-1)||(selObj.elements[i].value.indexOf("Introduce")!=-1)||(selObj.elements[i].value.indexOf("Tragen")!=-1)||(selObj.elements[i].value.indexOf("Wpisz")!=-1)||(selObj.elements[i].value.indexOf("Írja")!=-1)||(selObj.elements[i].value.indexOf("Zadejte")!=-1)||(selObj.elements[i].value.indexOf("Tapez")!=-1)){
		selObj.elements[i].value='';
		}
	}
}
	
}

function check_email(selObj){
//checks if email address is present
var result = false;
for (i=0; i < selObj.elements.length; i++){
	if (selObj.elements[i].name.indexOf("email")!=-1){
		if((selObj.elements[i].value.indexOf(".")==-1)||(selObj.elements[i].value.indexOf("@")==-1)){
			//do nowt - result is already false
		}else{
			result= true;
		}
	}
}
if (result==false){
	alert("A valid email address is required")
}
return result;
}
/*
eg
urlPassParamCheck(document.forms.actionform)
see if any data has been passed in on the url querystring.
add it to form parameters if so
*/
function urlPassParamCheck (form,lookup) {
var el = '', loc = '', term = '';
var start = 0, end = 0;
if(lookup == undefined) { lookup = false; }
if(window.location.href.indexOf('ic_number')!=-1) {
 loc = window.location.href;
 start = loc.indexOf('ic_number=');
 if(start != -1) {
   start += 10; end = loc.indexOf('&',start);
   if(end==-1) { end = loc.length; }       
   term = loc.substring(start,end);
   term = term.toLowerCase();
   term = unescape(term);
   if(term.indexOf(' ') == -1) {
   if(form.im_incoming_contact_number!=undefined) {
    form.im_incoming_contact_number.value=term;
   } else if((el = document.getElementById('ic_number'))!=null) {
   if(el.type == 'text' || el.type == 'hidden') {
    el.value=term;
   } else {
    el.innerHTML=term;
   }
   }
   //if we got a contact number, we could do a address details look up in care
   if(lookup) {
    loadMe(term);
   }
   }
 } 
}
if(window.location.href.indexOf('m_sourcecode')!=-1) {
 loc = window.location.href;
 start = loc.indexOf('m_sourcecode=');
 if(start != -1) {
   start += 13; end = loc.indexOf('&',start);
   if(end==-1) { end = loc.length; }       
   term = loc.substring(start,end);
   term = term.toLowerCase();
   term = unescape(term);
   if(term.indexOf('%') == -1 && term.indexOf(' ') == -1 && form.im_interest_referral_m_sourcecode!=undefined) {
    form.im_interest_referral_m_sourcecode.value=term;
   } else if((el = document.getElementById('m_sourcecode'))!=null) {
   if(el.type == 'text' || el.type == 'hidden') {
    el.value=term;
   } else {
    el.innerHTML=term;
   }
   }
 } 
}
}


//set a form field from the currently selected menu option
//used for feedback comment form
function setCommentRecip (menu,field) {
if(menu != undefined && field != undefined) {
 if(menu.selectedIndex>0) {
  if(menu[menu.selectedIndex].value.indexOf('ink')!=-1) {
   field.value = "info@foe.co.uk";
   return;
  }
 }
 field.value = "info@foe.co.uk";
}
}

/*
similar to the above but generic
see if any data has been passed in on the url querystring with 'qs_param_name' parameter
use it to set the value of form element form_el
*/
function setFormValueFromQuerystring (form, qs_param_name, form_el) {
 var el = '', loc = '', term = '', origterm = '';
 var start = 0, end = 0, paramlen = 0;
 if(window.location.href.indexOf(qs_param_name)!=-1) {
  paramlen = qs_param_name.length;
  loc = window.location.href;
  start = loc.indexOf(qs_param_name+'=');
  if(start != -1) {
   start += paramlen+1; end = loc.indexOf('&',start);
   if(end==-1) { end = loc.length; }       
   origterm = loc.substring(start,end);
   origterm = unescape(origterm);
   term = origterm.toLowerCase();
   term = unescape(term);
   //if(term.indexOf(' ') == -1) {
    if(form_el!=undefined) {
     if(form_el.type.indexOf('select')!=-1) {
      //match the term to an option value
      var ife = 0;
      for(ife=0;ife<form_el.length;ife++) {
       if(form_el[ife].value.toLowerCase().match(term)!=null) {
         form_el[ife].selected = true;
         break;
       }
      }
     } else {
      form_el.value=origterm;
     }
    } else if((el = document.getElementById(qs_param_name))!=null) {
     if(el.type == 'text' || el.type == 'hidden') {
      el.value=origterm;
     } else {
      el.innerHTML=origterm;
     }
    }
   //}
  } 
 }
}

function getEnclosingForm(formEl) {
if(formEl != undefined && formEl != '') {
while((formEl = formEl.parentNode) != null && formEl.nodeName.indexOf('FORM')==-1) {
}
}
return formEl;
}
function getAddress(prem,pc,form,add1,add2,add3,add4,add5,wbpc,funcname,wbfuncname)
//fills in address when postcode given

{
if(pc != '' && pc.name != undefined && pc.name.indexOf('postcode')!=-1) {
} else {
 if((pc = document.getElementById('postcode'))==null && (pc = document.getElementById('rq_postcode'))==null) {  
  alert('postcode element not found');
 } 
 var pn = getEnclosingForm(pc);
 form = pn.name;
} 
if(form == undefined || form == null || form == '') {
 var pn = getEnclosingForm(pc);
 form = pn.name;
}

        if(pc!=undefined && pc.value == '') {
			  //alert('Please provide a postcode');
           //pc.value = 'enter postcode';
           if((message   = document.getElementById('sender_postcode'))!=null) {
            message.className = 'error';
           }
           return;
            
        }
        if((message   = document.getElementById('sender_postcode'))!=null) {
         message   = document.getElementById('sender_postcode');
         message.className = 'hidden';
        }
        var url = '/app/AddressServlet?template_park=templates/address&';

        if(prem != null && prem != '') {
                url = url + 'premises=' + prem.value + '&';
        }
        if(pc != null && pc.value != '') {
                url = url + 'postcode=' + pc.value + '&';
        }
        if(form != null && form != '') {
                url = url + 'formname=' + form+ '&';
        }
        if(add1 != null && add1 != '') {
                url = url + 'add1=' + add1 + '&';
        }
        if(add2 != null && add2 != '') {
                url = url + 'add2=' + add2 + '&';
        }
        if(add3 != null && add3 != '') {
                url = url + 'add3=' + add3 + '&';
        } 
        if(add4 != null && add4 != '') {
                url = url + 'add4=' + add4 + '&';
        }
        if(add5 != null && add5 != '') {
                url = url + 'add5=' + add5 + '&';
        }
        if(wbpc != null && wbpc != '') {
                url = url + 'wbpostcode=' + wbpc + '&';
        }
        if(funcname != null && funcname != '') {
                url = url + 'scriptname=' + funcname + '&';
        }
        if(wbfuncname != null && wbfuncname != '') {
                url = url + 'wbscriptname=' + wbfuncname + '&';
        }

        if(url.charAt(url.length) == '&')
                url = url.substring(0, url.length-2);

        window.open(url, 'blob', 'scrollbars,resizable,width=600,height=600');

        return true;
}
//plug in detection routines
// Copyright © 2000 by Apple Computer, Inc., All Rights Reserved.
//
// You may incorporate this Apple sample code into your own code
// without restriction. This Apple sample code has been provided "AS IS"
// and the responsibility for its operation is yours. You may redistribute
// this code, but you are not permitted to redistribute it as
// "Apple sample code" after having made changes.
var javascriptVersion1_1 = false;
javascriptVersion1_1 = true;


// initialize global variables
var detectableWithVB = false;
var pluginFound = false;


function goURL(daURL) {
    // if the browser can do it, use replace to preserve back button
    if(javascriptVersion1_1) {
	window.location.replace(daURL);
    } else {
	window.location = daURL;
    }
    return;
}

function redirectCheck(pluginFound, redirectURL, redirectIfFound) {
    // check for redirection
    if( redirectURL && ((pluginFound && redirectIfFound) || 
	(!pluginFound && !redirectIfFound)) ) {
	// go away
	goURL(redirectURL);
	return pluginFound;
    } else {
	// stay here and return result of plugin detection
	return pluginFound;
    }	
}

function canDetectPlugins() {
    if( detectableWithVB || (navigator.plugins && navigator.plugins.length > 0) ) {
	return true;
    } else {
	return false;
    }
}

function detectFlash(redirectURL, redirectIfFound) {
    pluginFound = detectPlugin('Shockwave','Flash'); 
    // if not found, try to detect with VisualBasic
    if(!pluginFound && detectableWithVB) {
	pluginFound = detectActiveXControl('ShockwaveFlash.ShockwaveFlash.1');
    }
    // check for redirection
    return redirectCheck(pluginFound, redirectURL, redirectIfFound);
}

function detectDirector(redirectURL, redirectIfFound) { 
    pluginFound = detectPlugin('Shockwave','Director'); 
    // if not found, try to detect with VisualBasic
    if(!pluginFound && detectableWithVB) {
	pluginFound = detectActiveXControl('SWCtl.SWCtl.1');
    }
    // check for redirection
    return redirectCheck(pluginFound, redirectURL, redirectIfFound);
}

function detectQuickTime(redirectURL, redirectIfFound) {
    pluginFound = detectPlugin('QuickTime');
    // if not found, try to detect with VisualBasic
    if(!pluginFound && detectableWithVB) {
	pluginFound = detectQuickTimeActiveXControl();
    }
    return redirectCheck(pluginFound, redirectURL, redirectIfFound);
}

function detectReal(redirectURL, redirectIfFound) {
    pluginFound = detectPlugin('RealPlayer');
    // if not found, try to detect with VisualBasic
    if(!pluginFound && detectableWithVB) {
	pluginFound = (detectActiveXControl('rmocx.RealPlayer G2 Control') ||
		       detectActiveXControl('RealPlayer.RealPlayer(tm) ActiveX Control (32-bit)') ||
		       detectActiveXControl('RealVideo.RealVideo(tm) ActiveX Control (32-bit)'));
    }	
    return redirectCheck(pluginFound, redirectURL, redirectIfFound);
}

function detectWindowsMedia(redirectURL, redirectIfFound) {
    pluginFound = detectPlugin('Windows Media Player');
    // if not found, try to detect with VisualBasic
    if(!pluginFound && detectableWithVB) {
	pluginFound = detectActiveXControl('MediaPlayer.MediaPlayer.1');
    }
    return redirectCheck(pluginFound, redirectURL, redirectIfFound);
}

function detectPlugin() {
    // allow for multiple checks in a single pass
    var daPlugins = detectPlugin.arguments;
    // consider pluginFound to be false until proven true
    var pluginFound = false;
    // if plugins array is there and not fake
    if (navigator.plugins && navigator.plugins.length > 0) {
	var pluginsArrayLength = navigator.plugins.length;
	// for each plugin...
	for (pluginsArrayCounter=0; pluginsArrayCounter < pluginsArrayLength; pluginsArrayCounter++ ) {
	    // loop through all desired names and check each against the current plugin name
	    var numFound = 0;
	    for(namesCounter=0; namesCounter < daPlugins.length; namesCounter++) {
		// if desired plugin name is found in either plugin name or description
		if( (navigator.plugins[pluginsArrayCounter].name.indexOf(daPlugins[namesCounter]) >= 0) || 
		    (navigator.plugins[pluginsArrayCounter].description.indexOf(daPlugins[namesCounter]) >= 0) ) {
		    // this name was found
		    numFound++;
		}   
	    }
	    // now that we have checked all the required names against this one plugin,
	    // if the number we found matches the total number provided then we were successful
	    if(numFound == daPlugins.length) {
		pluginFound = true;
		// if we've found the plugin, we can stop looking through at the rest of the plugins
		break;
	    }
	}
    }
    return pluginFound;
} // detectPlugin


// Here we write out the VBScript block for MSIE Windows
if ((navigator.userAgent.indexOf('MSIE') != -1) && (navigator.userAgent.indexOf('Win') != -1)) {
    document.writeln('<script language="VBscript">');

    document.writeln('\'do a one-time test for a version of VBScript that can handle this code');
    document.writeln('detectableWithVB = False');
    document.writeln('If ScriptEngineMajorVersion >= 2 then');
    document.writeln('  detectableWithVB = True');
    document.writeln('End If');

    document.writeln('\'this next function will detect most plugins');
    document.writeln('Function detectActiveXControl(activeXControlName)');
    document.writeln('  on error resume next');
    document.writeln('  detectActiveXControl = False');
    document.writeln('  If detectableWithVB Then');
    document.writeln('     detectActiveXControl = IsObject(CreateObject(activeXControlName))');
    document.writeln('  End If');
    document.writeln('End Function');

    document.writeln('\'and the following function handles QuickTime');
    document.writeln('Function detectQuickTimeActiveXControl()');
    document.writeln('  on error resume next');
    document.writeln('  detectQuickTimeActiveXControl = False');
    document.writeln('  If detectableWithVB Then');
    document.writeln('    detectQuickTimeActiveXControl = False');
    document.writeln('    hasQuickTimeChecker = false');
    document.writeln('    Set hasQuickTimeChecker = CreateObject("QuickTimeCheckObject.QuickTimeCheck.1")');
    document.writeln('    If IsObject(hasQuickTimeChecker) Then');
    document.writeln('      If hasQuickTimeChecker.IsQuickTimeAvailable(0) Then ');
    document.writeln('        detectQuickTimeActiveXControl = True');
    document.writeln('      End If');
    document.writeln('    End If');
    document.writeln('  End If');
    document.writeln('End Function');

    document.writeln('</scr' + 'ipt>');
}
/* ajax for populating page with contact details */
/* some variables for the calling page to use */
var meO = new Object();
meO.uid = '';
meO.givenname = '';
meO.contact_number = '';
meO.homephone = '';
meO.info = '';
meO.pic = '';
meO.remote = '';
meO.mail = '';

var xmlDoc;
var meXH;
function loadMe(cnum) {
alert('loading ajax with cnum'+cnum); 
 meXH=GetXmlHttpObject();
 if (meXH==null) {
  alert ("Your browser does not support AJAX!");
  return;
 } 
 if(cnum==undefined || cnum==null || cnum == "") {
  return;
 }
 var url="/app/cs?template_url=/Templates/contact.xml&template_output_type=text/xml&db_name=live_contacts&action=search&contactnumber="+cnum;
 meXH.onreadystatechange=stateChanged;
 meXH.open("GET",url,true);
 meXH.send(null);
}
function stateChanged() { 
 var idf = 0, elbt,el;
 if (meXH.readyState==4) { 
  xmlDoc=meXH.responseXML.documentElement;
  insertIfPoss("contact_number");
  if(!insertIfPoss("forenames")) { insertIfPoss("forenames","rq_fname"); }
  if(!insertIfPoss("surname")) { insertIfPoss("surname","rq_sname"); }
  insertIfPoss("title","rq_title");
  insertIfPoss("email_address","rq_email_address");
  if(!insertIfPoss("house_name")) { insertIfPoss("house_name","rq_address1"); }
  if(!insertIfPoss("address")) { insertIfPoss("address","rq_address2"); }
  if(!insertIfPoss("town")) { insertIfPoss("town","rq_town"); }
  if(!insertIfPoss("postcode")) { insertIfPoss("postcode","rq_postcode"); }
 }
}
function insertIfPoss(datalabel,pagelabel) {
  if(pagelabel==undefined) { pagelabel = datalabel; }
  var v = '',lv = '',elbt,el, r = false;
  if((elbt = xmlDoc.getElementsByTagName(datalabel))!=undefined && elbt[0]!=undefined && elbt[0].childNodes[0]!=undefined) { 
   v = elbt[0].childNodes[0].nodeValue; 
   if((el = document.getElementById(pagelabel))!=null) {
    //what if its a dropdown
    if(el.type!=undefined) {
    if(el.type.indexOf('select')!=-1) {
     //iterate list and look for element with same value
     var i = 0;
     lv = v.toLowerCase();
     for(i=0;i<el.length;i++) {
      if(el[i].value.toLowerCase() == lv) {
       el[i].selected = true;
       r = true;
       break;
      }
     }
    } else if(el.value!=undefined) {
     el.value=v; r = true;
    } 
    } else if(el.innerHTML!=undefined) {
     el.innerHTML=v; r = true;
    }
   }
  }
  return r;
}
function GetXmlHttpObject()
{
var meXH=null;
try
  {
  // Firefox, Opera 8.0+, Safari
  meXH=new XMLHttpRequest();
  }
catch (e)
  {
  // Internet Explorer
  try
    {
    meXH=new ActiveXObject("Msxml2.XMLHTTP");
    }
  catch (e)
    {
    meXH=new ActiveXObject("Microsoft.XMLHTTP");
    }
  }
return meXH;
}
