


function showhide(layer_ref) {


hza = document.getElementById(layer_ref);
var test = hza.style.display;

if (test == 'none'){
hza.style.display = 'inline';
}
else
{
hza.style.display = 'none';
}

}



// QUICK HACK TO USE THIS ROUTINE FOR DIVs WHICH REQUIRE THE BLOCK DISPLAY STYLE
function showhide2(layer_ref) {


hza = document.getElementById(layer_ref);
var test = hza.style.display;

if (test == 'none'){
hza.style.display = 'block';
}
else
{
hza.style.display = 'none';
}

}



// DIVs WHICH REQUIRE THE BLOCK DISPLAY STYLE AND COOKIE REMEMBERING
function showhide3(layer_ref,cookieref) {

cookie_state = readCookie(cookieref);

hza = document.getElementById(layer_ref);
var test = hza.style.display;

if (test == 'none'){
hza.style.display = 'block';
}
else
{
hza.style.display = 'none';
}

}





// VERY SIMPLE AJAX LOADER
// onclick="javascript:getNewContent('update_id','content_src');"

var http = createRequestObject();

function run_ajax(idcode,contentfile){
getNewContent(idcode,contentfile);
}

function createRequestObject() {
	var objAjax;
	var browser = navigator.appName;
	if(browser == "Microsoft Internet Explorer"){
		objAjax = new ActiveXObject("Microsoft.XMLHTTP");
	}else{
		objAjax = new XMLHttpRequest();
	}
	return objAjax;
}

function getNewContent(idcode,contentfile){
openidcode = idcode;
document.getElementById(openidcode).innerHTML = '<img src="images/pleasewait.gif" width=32 height=32 alt="Please wait - loading...">';
http.open('get',contentfile);
http.onreadystatechange = updateNewContent;
http.send(null);
return false;
}

function updateNewContent(){
if(http.readyState == 4){
document.getElementById(openidcode).innerHTML = http.responseText;
}
}




function testpeople(){
hza = document.getElementById('other_people_block');
if (document.project_form.other_people[0].checked == true){
hza.style.display = 'block';
}
else
{
hza.style.display = 'none';
}
}


function testpeople2(){
hza = document.getElementById('scale_block');
if (document.project_form.feedback_scale.value > 0){
hza.style.display = 'block';
}
else
{
hza.style.display = 'none';
}
}


function testpeople3(){
hza = document.getElementById('other_people_why_block');
hzb = document.getElementById('other_people_why_block_desc');
message='';

scaleamount = (document.project_form.scale.value + document.project_form.organiser_scale.value)
feedback_scaleamount = (document.project_form.feedback_scale.value + document.project_form.feedback_organiser_scale.value)

if (scaleamount){
if (feedback_scaleamount){
perc = (feedback_scaleamount/scaleamount)*100;
if (perc > 100){message ='More than expected. ';}
if (perc > 150){message ='Excellent, many more than expected. ';}
if (perc > 250){message ='Wow! Loads more than expected. ';}
if (perc < 100){message ='Ok. Fewer than expected. ';}
if (perc == 100){message ='On target. ';}
}
}

if (old_message){
}
else
{
old_message = hzb.innerHTML;
}
if(message){
hza.style.display = 'block';
hzb.style.display = 'block';
hzb.innerHTML='<b>'+message+'</b>'+old_message;
}
else
{
hza.style.display = 'none';
hzb.style.display = 'none';
}
}



function testfundraising2(){
hza = document.getElementById('cash_target_block');
if (document.project_form.feedback_cash_target.value > 0){
hza.style.display = 'block';
}
else
{
hza.style.display = 'none';
}
}



function testfundraising3(){
hza = document.getElementById('fundraising_why_block');
hzb = document.getElementById('fundraising_why_desc');
fund_message='';

if (document.project_form.feedback_cash_target.value){
if (document.project_form.cash_target.value){
perc2 = (document.project_form.feedback_cash_target.value/document.project_form.cash_target.value)*100;
if (perc2 > 100){fund_message ='Well done, more than expected. ';}
if (perc2 > 150){fund_message ='Excellent, much more than expected. ';}
if (perc2 > 250){fund_message ='Wow! Loads more than expected. ';}
if (perc2 < 100){fund_message ='Ok. Less than expected. ';}
if (perc2 == 100){fund_message ='Well done. On target. ';}
}
}


if (old_fund_message){
}
else
{
old_fund_message = hzb.innerHTML;
}
if(fund_message){
hza.style.display = 'block';
hzb.style.display = 'block';
hzb.innerHTML='<b>'+fund_message+'</b>'+old_fund_message;
}
else
{
hza.style.display = 'none';
hzb.style.display = 'none';
}
}



function testfundraising(){
hza = document.getElementById('fundraising_block');
if (document.project_form.fundraising[0].checked == true){
hza.style.display = 'block';
}
else
{
hza.style.display = 'none';
}
}




function handleOnChange(dd1,doneonce,field,default_town)
{



var field=''+field+'';
  var idx = dd1.selectedIndex;
  var val = dd1[idx].value;
  valtext = dd1[idx].text;


  
  var par = document.forms["project_form"];
  var parelmts = par.elements;
  var countysel = parelmts['town'];
  var county = val;

listtext = ('<b>Can\'t see your town or village?</b><br><a style="padding-top:5px;margin-top:5px\;" href="javascript:handleOnChange(document.project_form.county,\'1\',\'village\')\;">Show more places in <b>' + valtext + '</b></a>');
document.getElementById('listmore').innerHTML=listtext;

  
  if (county ==''){county = '0';}
   var directory = ""+document.location;
   directory = directory.substr(0, directory.lastIndexOf('/'));

var urlcode = '';


hza = document.getElementById('town');

if (field == 'village'){
urlcode = "./data_files/towns/" +  county + ".dat"; 
hza.size = '4';
}
else
{
hza.size = '1';
urlcode = "./data_files/major_towns/" +  county + ".dat"; 
hza.size = '4';
}


   Http.get({
		url: urlcode,
		callback: fillCounty,
		cache: Http.Cache.Get
	}, [countysel], doneonce);


}



function fillCounty(xmlreply, countyelmt, doneonce)
{



  if (xmlreply.status == Http.Status.OK)
  {

var town_name = readCookie('enabler_town');

   var countyresponse = xmlreply.responseText;
   countyresponse = countyresponse;
   var countyar = countyresponse.split("\n");

countyelmt.length = 1;
countyelmt.length = countyar.length;

testlength = countyar.length;
startcount=0;

   for (o=startcount; o < testlength; o++)
   {
     countyelmt[o].text = countyar[o];


if (countyelmt[o].text){


testDrop = countyelmt[o].text.replace(/[^A-Za-z]/g, "");
testTown = town_name.replace(/[^A-Za-z]/g, "");


//alert(testTown);

if (testDrop == testTown){
//alert(town_name);
selected_town = town_name;
var selected_index = o;
// alert(o);
}}


   }


if (selected_index > 0){
var x=document.getElementById("town");
x.selectedIndex = selected_index;

//alert(selected_index);

}

}



  else
  {
   alert("Cannot handle the Ajax call");
  }





}







function taghighlight (tagfields){

// take the comma delimited list of tag type fields to check e.g. issue tags

var fields = tagfields.split(",");

// start a for loop for each tag type
for (var tagtype in fields) {

// get the content of the hidden tag list
this_tag_type = document.getElementById(fields[tagtype]);

if (this_tag_type){

var TestValue = this_tag_type.value ;

// put the tag list into an array
var arr = TestValue.split(", ");

// start a for loop testing each tag
for (var i in arr) {

// replace spaces with _ characters (to match the id="" on each text tag anchor) and put value into working_tag
var spc = " ";
var working_tag = arr[i].replace(new RegExp(/\W/g),'_');
//var working_tag = arr[i].replace(new RegExp(/^\W/g),'');

// alert(working_tag);

if (working_tag){
hza = document.getElementById(working_tag);
hza.style.color = 'rgb(255, 255, 255)';
hza.style.background = 'rgb(4, 145, 191)';
}
}

}

}

}

function tagswap(layer_ref,value,tagtype) {

hza = document.getElementById(layer_ref);
this_tag_type = document.getElementById(tagtype);

var test = hza.style.color;
if ((test == 'rgb(255, 255, 255)')||((test == 'rgb(255,255,255)'))){
hza.style.color = 'rgb(4, 145, 191)';
hza.style.background = 'rgb(255, 255, 255)';
var TestValue = value + ', ';
var ReplaceValue = this_tag_type.value ;
var NewValue = ReplaceValue.replace(new RegExp(TestValue,'g'),'');
this_tag_type.value = NewValue;
}
else
{
hza.style.color = 'rgb(255, 255, 255)';
hza.style.background = 'rgb(4, 145, 191)';
this_tag_type.value =  this_tag_type.value +  value + ', ';
}


}





/**
 * DHTML textbox character counter script. Courtesy of SmartWebby.com (http://www.smartwebby.com/dhtml/)
 */

maxL=160;
var bName = navigator.appName;
function taLimit(taObj) {
	if (taObj.value.length==maxL) return true;
	return true;
}

function taCount(taObj,Cnt) { 
	objCnt=createObject(Cnt);
	objVal=taObj.value;
	//if (objVal.length>maxL) objVal=objVal.substring(0,maxL);
	if (objCnt) {
remaining = maxL-objVal.length;
		   if (remaining > 10){ 
		   document.getElementById('charcounter').style.color='rgb(0, 128, 0)';
		   document.getElementById('charcounter').innerHTML=remaining;
		   document.getElementById('myCounter').innerHTML='';
		   }
		   if (remaining < 11){ 
		   document.getElementById('charcounter').style.color='rgb(240, 130, 70)';
		   document.getElementById('charcounter').innerHTML=remaining;
		   document.getElementById('myCounter').innerHTML='';
		   }
		   if (remaining < 0){ 
		   document.getElementById('charcounter').style.color='rgb(237, 37, 25)';
		   document.getElementById('charcounter').innerHTML=remaining;
		   document.getElementById('myCounter').innerHTML='Too much!<br>Please trim.';
		   }
		   

	}
	return true;
}
function createObject(objId) {
	if (document.getElementById) return document.getElementById(objId);
	else if (document.layers) return eval("document." + objId);
	else if (document.all) return eval("document.all." + objId);
	else return eval("document." + objId);
}






/**
 * DHTML textbox character counter script. Courtesy of SmartWebby.com (http://www.smartwebby.com/dhtml/)
 */

maxL=160;
var bName = navigator.appName;
function taLimit2(taObj) {
	if (taObj.value.length==maxL) return true;
	return true;
}

function taCount2(taObj,Cnt) { 
	objCnt=createObject2(Cnt);
	objVal=taObj.value;
	//if (objVal.length>maxL) objVal=objVal.substring(0,maxL);
	if (objCnt) {
remaining = maxL-objVal.length;
		   if (remaining > 10){ 
		   document.getElementById('charcounter2').style.color='rgb(0, 128, 0)';
		   document.getElementById('charcounter2').innerHTML=remaining;
		   document.getElementById('myCounter2').innerHTML='';
		   }
		   if (remaining < 11){ 
		   document.getElementById('charcounter2').style.color='rgb(240, 130, 70)';
		   document.getElementById('charcounter2').innerHTML=remaining;
		   document.getElementById('myCounter2').innerHTML='';
		   }
		   if (remaining < 0){ 
		   document.getElementById('charcounter2').style.color='rgb(237, 37, 25)';
		   document.getElementById('charcounter2').innerHTML=remaining;
		   document.getElementById('myCounter2').innerHTML='Too much!<br>Please trim.';
		   }
		   

	}
	return true;
}
function createObject2(objId) {
	if (document.getElementById) return document.getElementById(objId);
	else if (document.layers) return eval("document." + objId);
	else if (document.all) return eval("document.all." + objId);
	else return eval("document." + objId);
}





function checkEnter(e){ //e is event object passed from function invocation
var characterCode 

if(e && e.which){ //if which property of event object is supported (NN4)
e = e
characterCode = e.which //character code is contained in NN4's which property
}
else{
e = event
characterCode = e.keyCode //character code is contained in IE's keyCode property
}

if(characterCode == 13){ //if generated character code is equal to ascii 13 (if enter key)
return false
}
else{
return true
}

}




