// JavaScript Document
// This page contains the following scripts:
// Click the text next to Check Box to activate Check Box
// This script converts text entered into a form to first letter capital ie, suffolk = Suffolk
// To control the maximum amount of characters which can be entered into a Text Field 
// This script prevents Google Toolbar from highlighting form fields which can be automatically filled
// To ensure fields starting with the word required are completed by the user
// To ensure two fields are identical
// To create additional input boxes when selecting appropriate radio button
// To create additional input boxes when required ie, select other for new text box to appear
// Email this page to a friend
// To ensure a Radio Button has been selected
// To upload a picture from a file on your hard drive



<!-- Click the text next to Check Box to activate Check Box -->
function changeBox(cbox) {
box = eval(cbox);
box.checked = !box.checked;
}


<!-- This script converts text entered into a form to first letter capital ie, suffolk = Suffolk -->
function changeCase(frmObj) {
var index;
var tmpStr;
var tmpChar;
var preString;
var postString;
var strlen;
tmpStr = frmObj.value.toLowerCase();
strLen = tmpStr.length;
if (strLen > 0)  {
for (index = 0; index < strLen; index++)  {
if (index == 0)  {
tmpChar = tmpStr.substring(0,1).toUpperCase();
postString = tmpStr.substring(1,strLen);
tmpStr = tmpChar + postString;
}
else {
tmpChar = tmpStr.substring(index, index+1);
if (tmpChar == " " && index < (strLen-1))  {
tmpChar = tmpStr.substring(index+1, index+2).toUpperCase();
preString = tmpStr.substring(0, index+1);
postString = tmpStr.substring(index+2,strLen);
tmpStr = preString + tmpChar + postString;
         }
      }
   }
}
frmObj.value = tmpStr;
}


<!-- To control the maximum amount of characters which can be entered into a Text Field --> 
function textCounter(field, countfield, maxlimit)
{
if (field.value.length > maxlimit)
field.value = field.value.substring(0, maxlimit);
else 
countfield.value = maxlimit - field.value.length;
}


<!-- This script prevents Google Toolbar from highlighting form fields which can be automatically filled -->
 if(window.attachEvent)
  window.attachEvent("onload",setListeners);

function setListeners(){
  inputList = document.getElementsByTagName("input");
  for(i=0;i<inputList.length;i++){
    inputList[i].attachEvent("onpropertychange",restoreStyles);
    inputList[i].style.backgroundColor = "";
  }
  selectList = document.getElementsByTagName("select");
  for(i=0;i<selectList.length;i++){
    selectList[i].attachEvent("onpropertychange",restoreStyles);
    selectList[i].style.backgroundColor = "";
  }
}

function restoreStyles(){
  if(event.srcElement.style.backgroundColor != "" && event.srcElement.style.backgroundColor != "#ffffff"){
    event.srcElement.style.backgroundColor = "#ffffff"; /* color of choice for AutoFill */
    document.all['googleblurb'].style.display = "block";
  }
}


<!-- To ensure fields starting with the word required are completed by the user -->
function checkrequired(which) {
var pass=true;
if (document.images) {
for (i=0;i<which.length;i++) {
var tempobj=which.elements[i];
if (tempobj.name.substring(0,8)=="required") {
if (((tempobj.type=="text"||tempobj.type=="textarea")&&
tempobj.value=='')||(tempobj.type.toString().charAt(0)=="s"&&
tempobj.selectedIndex==0)) {
pass=false;
break;
         }
      }
   }
}
if (!pass) {
shortFieldName=tempobj.id.substring(0,50).toUpperCase();
alert("Please ensure the "+shortFieldName+" field was completed in full");
return false;
}
else
return true;
}


<!-- To ensure two fields are identical -->
function tmt_compareField(f1,f2,rule,errorMsg){
	var myErr = "";
	if(eval("MM_findObj('"+f1+"').value"+rule+"MM_findObj('"+f2+"').value")){
		alert(unescape(errorMsg));myErr += 'errorMsg';}
	document.MM_returnValue = (myErr == "");
}


<!-- To create additional input boxes when selecting appropriate radio button -->
function toggleMe(obj, a){
  var e=document.getElementById(a);
  if(!e)return true;
    e.style.display="block"
  return true;
}

function toggleMe2(obj, a){
  var e=document.getElementById(a);
  if(!e)return true;
    e.style.display="none"
  return true;
}


<!-- To create additional input boxes when required ie, select other for new text box to appear -->
function testOther(obj){
  var val = obj.options[obj.selectedIndex].value; 
  document.getElementById('other').style.display = (val=='other') ? "":"none";
}


<!-- Email this page to a friend -->
function initMail(form) {
text = "Check out this page:  " + window.location;
form.message.value = "Hi " + form.sendto.value + " (" + form.to.value + "):\n\n"
 + text + "\n\nYour Friend,\n" + form.sendername.value + "(" + form.senderemail.value + ")";
return (form.to.value != "");
}


<!-- Checks that a radio button has been selected -->
function checkRadios() {
 var el = document.forms[0].elements;
 for(var i = 0 ; i < el.length ; ++i) {
  if(el[i].type == "radio") {
   var radiogroup = el[el[i].name]; // get the whole set of radio buttons.
   var itemchecked = false;
   for(var j = 0 ; j < radiogroup.length ; ++j) {
    if(radiogroup[j].checked) {
	 itemchecked = true;
	 break;
	}
   }
   if(!itemchecked) { 
    alert("Please choose an answer for "+el[i].name+".");
    if(el[i].focus)
     el[i].focus();
	return false;
   }
  }
 }
 return true;
} 

<!-- This scrip is for a field to choose a picture from your hard drive to upload -->
<!-- Picture variables should be entered into the Head of the web page -->
function preview(what){
  var source=what.value;
  var ext=source.substring(source.lastIndexOf(".")+1,source.length).toLowerCase();
  for (var i=0; i<fileTypes.length; i++) if (fileTypes[i]==ext) break;
  globalPic=new Image();
  if (i<fileTypes.length) globalPic.src=source;
  else {
    globalPic.src=defaultPic;
    alert("THAT IS NOT A VALID IMAGE\nPlease load an image with an extention of one of the following:\n\n"+fileTypes.join(", "));
  }
  setTimeout("applyChanges()",200);
}
var globalPic;
function applyChanges(){
  var field=document.getElementById(outImage);
  var x=parseInt(globalPic.width);
  var y=parseInt(globalPic.height);
  if (x>maxWidth) {
    y*=maxWidth/x;
    x=maxWidth;
  }
  if (y>maxHeight) {
    x*=maxHeight/y;
    y=maxHeight;
  }
  field.style.display=(x<1 || y<1)?"none":"";
  field.src=globalPic.src;
  field.width=x;
  field.height=y;
}

<!--    
/****************************************************************
 *  Suzy's Javascript Photo Album, version 1.0, April 2001      *
 *                                                              *
 *  This javascript code may be used on other Websites if:      *
 *  that the following conditions are met;                      *
 *  1) This notice is left unchanged                            *
 *  2) A link to http://www.kitykity.com is placed on that page *
 *  Please contact me at kitykity@usa.com for assistance.       *
 ****************************************************************/
current = 0;
PicVal = new Array(19);
DatVal = new Array(19);
TxtVal = new Array(19);

PicVal[0] = "../../images/Photos/Village/HighStreet.jpg";
DatVal[0] = "2001";
TxtVal[0] = "The busy High Street connects Welwyn Garden City to Stevenage and boasts a wide variety of local traders.";

PicVal[1] = "../../images/Photos/Village/Butchers.jpg";
DatVal[1] = "2001";
TxtVal[1] = "Trussells Family Butchers was owned and managed by the Trussel family for many years before being sold to the present owners in 1999";

PicVal[2] = "../../images/Photos/Village/PostOffice.jpg";
DatVal[2] = "2001";
TxtVal[2] = "The village Post Office sells not only stamps but greetings cards, sweets, toys and miscellaneous stationery as well.";

PicVal[3] = "../../images/Photos/Village/RecGround_PlayArea.jpg";
DatVal[3] = "2001";
TxtVal[3] = "The Recreation Ground is the venue for football matches, cricket and a play area for chidren which includes swings and a climber";

PicVal[4] = "/../../images/Photos/Village/RecGround_Pond.jpg";
DatVal[4] = "2001";
TxtVal[4] = "Tucked away in a corner of the 'Rec' is a small pond just waiting for a high flying cricket ball!";

PicVal[5] = "../../images/Photos/Village/StationPub.jpg";
DatVal[5] = "2001";
TxtVal[5] = "The Station Pub is literally opposite the station and entices the weary traveller in on their way home from work.";

PicVal[6] = "../../images/Photos/Village/TrinityChurch.jpg";
DatVal[6] = "2001";
TxtVal[6] = "This building (which was extended and refurbished in 2000) is the home of Trinity Church, Methodist/URC - formed by uniting the former Knebworth Methodist and Knebworth United Reformed Churches in 1996.";

PicVal[7] = "../../images/Photos/Village/VillageHall.jpg";
DatVal[7] = "2001";
TxtVal[7] = "The Village Hall underwent extensive renovation at this time and now boasts an extended kitchen area and improved sound system.";

PicVal[8] = "../../images/Photos/Village/CharacterShops.jpg";
DatVal[8] = "2001";
TxtVal[8] = "Just down the road from the Station Pub are some 'Character' buildings which tell of bygone days. Look at the Historical section of the Gallery and see what we mean!";

PicVal[9] = "../../images/Photos/Village/library.jpg";
DatVal[9] = "2004";
TxtVal[9] = "The library sits in a quiet residential road opposite St. Martin's church. It carries a wide selection of books that are frequently rotated";

PicVal[10] = "../../images/Photos/Village/coop.jpg";
DatVal[10] = "2004";
TxtVal[10] = "Knebworth is well serviced by a variety of shops";

PicVal[11] = "../../images/Photos/Village/shops.jpg";
DatVal[11] = "2004";
TxtVal[11] = "More shops";

PicVal[12] = "../../images/Photos/Village/swangley.jpg";
DatVal[12] = "2004";
TxtVal[12] = "Coming into the village from Swangleys Lane";

PicVal[13] = "../../images/Photos/Village/houses.jpg";
DatVal[13] = "2004";
TxtVal[13] = "View across the fields from Gipsy Lane";

PicVal[14] = "../../images/Photos/Village/oldkneb.jpg";
DatVal[14] = "2004";
TxtVal[14] = "View going into Old Knebworth from the direction of 'New' Knebworth";

PicVal[15] = "../../images/Photos/Village/memorial1.jpg";
DatVal[15] = "2004";
TxtVal[15] = "The War Memorial in Old Knebworth";

PicVal[16] = "../../images/Photos/Village/memorial2.jpg";
DatVal[16] = "2004";
TxtVal[16] = "Every year, poppies are placed at the base of the memorial on Remembrance Sunday";

PicVal[17] = "../../images/Photos/Village/lytton.jpg";
DatVal[17] = "2004";
TxtVal[17] = "The Lytton Arms pub in Old Knebworth, originally built in 1840 has recently been refurbished";

PicVal[18] = "../../images/Photos/Village/cricket.jpg";
DatVal[18] = "2004";
TxtVal[18] = "Village cricket played in the grand surroundings of Knebworth Park";

function ShowPic(newpic) {
  document.Pic.src = PicVal[newpic];
  document.Form.Text.value=TxtVal[newpic]; 
  document.Form.Date.value=DatVal[newpic];
  SelectionBox = document.Form.Dropdown;
  SelectionBox.options[newpic].selected = true;
  current = newpic;
}
function RandomPic() {
  TotalImages = document.Form.Dropdown.options.length;
  current = Math.floor(Math.random()*TotalImages);
  ShowPic(current);
}
function PreviousPic() {
  TotalImages = document.Form.Dropdown.options.length;
  current--;
  if(current<0) current = TotalImages - 1;
  ShowPic(current);
}
function NextPic() {  
  var TotalImages = document.Form.Dropdown.options.length;
  current++;
  if (current>=TotalImages) current = 0;
  ShowPic(current);
}
// -->

