function changeimg(layername,imgname,imgsrc) {
   if (document.layers)	{
      document.layers[layername].document[imgname].src=imgsrc;
   }else{
      document[imgname].src=imgsrc;
   }
}
/*
function writelayer(layerName,layerText) {
   if (document.getElementById) {
      document.getElementById(layerName).innerHTML=layerText;
   }else{
      if (document.layers)	{
         with (document.layers[layerName].document){
            open(); write(layerText); close();
         }
      }
   }
}
*/

function writelqyer(divId,html){
 var e=null;
 if (document.getElementById) {
     e=document.getElementById(divId);
          if(!e)return false;
          if("innerHTML" in e){
               e.innerHTML=html;return true
          }
          else if("firstChild" in e && "data" in e.firstChild){
               e.firstChild.data=html;return true;
          }
          else{
               return false;
          }
 }else if(document.layers){
     e=document.layers[divId];
          if(typeof e=="undefined"||!e){
               e=document[divId];
               if(typeof e=="undefined"||!e)return false;
          }
     e.document.open();
     e.document.write(html);
     e.document.close();
     return true;
 }else if(document.all){
     e=document.all[divId];
     if(typeof e=="undefined"||!e)return false;
     e.innerHTML=html;
     return true;
 }
 return false;
}






















//Crossword clues for use in function clue(h,v)   

var v9h23="9 down and 23 across: &nbsp; Temperatures in Britain were much colder during the last ___ ___ (3,3)"; 

var h1= "1. &nbsp; Cape Farewell expedition ship (12)<br/>";
var h2= " ";
var h3= " ";
var h4= " ";
var h5= " ";
var h6= "6. &nbsp; Coral ____ (4)";
var h7= "7. &nbsp; Rescue (4)";
var h8= "11. and 8. &nbsp;  Changes in Pacific Ocean that affect the weather (2, 4)<br/>"; 
var h9=" ";
var h10=" ";
var h11="11. and 8. &nbsp;  Changes in Pacific Ocean that affect the weather (2, 4)";
var h12="12. &nbsp; African river that flows into the Atlantic (5)";
var h13="13. &nbsp; Edge of the land (5)";
var h14="14. &nbsp; Abbreviation for South East (2)";
var h15=" ";
var h16="16. &nbsp; Heavy fraction of oil, also colloquial name for sailor (3)";
var h17=" ";
var h18="18. &nbsp; Tiny plants and animals that live floating in the ocean (8)";
var h19=" ";
var h20=" ";
var h21="21. &nbsp; Packet of light energy (6)";
var h22=" ";
var h23="See 9 down "; 
var h24="24. &nbsp; Scottish river that flows through Perth to the North Sea (3)";
var h25="25. &nbsp; End of river nearest sea (5)";
var h26="26. &nbsp; Visible radiation (5)";
var h27="27. &nbsp; 26 across travels as _____ (5)";

var v1="1. and 15. &nbsp; Ocean separating Europe and North America (5, 8)<br/> ";
var v2="2. &nbsp; Study of the oceans (12) ";
var v3="3. &nbsp; Direction clockwise from north (4) ";
var v4="14 and 4 down. &nbsp; Height of water in the ocean (3, 5) ";
var v5="5. &nbsp; The way plants make food (14) ";
var v6=" ";
var v7=" ";
var v8=" ";
var v9=" ";
var v10="10. &nbsp; Abbreviation for steamship (2) ";
var v11=" ";
var v12=" ";
var v13=" ";
var v14="14 and 4 down. &nbsp;  Height of water in the ocean (3, 5) ";
var v15="1. and 15. &nbsp; Ocean separating Europe and N America (5, 8) ";
var v16=" ";
var v17="17. &nbsp; Floats in  the water (4) ";
var v18=" ";
var v19="19. &nbsp; Abbreviation for North East (2) ";
var v20="20. &nbsp; Relating to tides (5) ";
var v21=" ";
var v22="22. &nbsp; Arab boat (4) ";
var v23=" ";
var v24=" ";
var v25="25. &nbsp; Tea or coffee ___ (3) ";
var v26=" ";
var v27=" ";

var changed=new Array(), count=0; 	//Array to take ID of images changed from wh.gif to py.gif

function clue(h,l1,c1,h1no,l2,c2,h2no,v,l3,c3,v1no,l4,c4,v2no) {
  row1=l1; row2=l2; row3=l3; row4=l4; col1=c1; col2=c2; col3=c3; col4=c4; 	//setting variables for compute() 
  for (var i=0; i<count; i++) {		//reset the highlighted squares from the last clue
     changeimg('xw0',changed[i],'wh.gif');  
  }  count=0;
  count=0;
  if (h==v9h23) {  //2 word clue using both down and across
      across="<b>DOWN AND ACROSS</b><br/>"; down=" ";
      var reverse=1;  
  }else{
      across="<b>ACROSS</b><br/>"; down="<b>DOWN</b><br/>";
      var reverse=0;
  }
  if (h=="no") across=" ";
  if (v=="no") down=" "; 
  c1max=c1+h1no; c2max=c2+h2no; l3max=l3+v1no; l4max=l4+v2no;  
  for (var i = c1; i < c1max; i++) {
     imgname1="b"+l1+"c"+i;
     changeimg('xw0',imgname1,'py.gif');
     changed[count]=imgname1; count++;
  }
  for (var i = c2; i < c2max; i++) {
     imgname2="b"+l2+"c"+i;
     changeimg('xw0',imgname2,'py.gif');
     changed[count]=imgname2; count++;
  }
  for (var i = l3; i < l3max; i++) {
     imgname3="b"+i+"c"+c3;
     changeimg('xw0',imgname3,'py.gif');
     changed[count]=imgname3; count++;
  }
  for (var i = l4; i < l4max; i++) {
     imgname4="b"+i+"c"+c4;
     changeimg('xw0',imgname4,'py.gif');
     changed[count]=imgname4; count++;
  }

  xwclue=""; w1= "no"; w2="no"; w3="no"; w4="no";     	//Reset textfields and forms
  xwclue+="<form id='xword'>";
  if (h!="no") {
     xwclue+= "<span>"+across+h+"</span>"
     if (l1!=0) {
        w1='word1';
        xwclue+= " &nbsp; <input type='text' id='word1' name='word1' size='";
        xwclue+=h1no;
        xwclue+="' value=''>";
     }
     if (l2!=0) {
        w2='word2';
        xwclue+="<input type='text' id='word2' name='word2' size='";
        xwclue+=h2no;
        xwclue+="' value=''>";
     }
  }
  if (v!="no") {
     if (h==v9h23) {
        xwclue+="";
     }else{
        xwclue+= "<br/><br/><span>"+down+v+"</span>";
     }
     if (l3!=0) {
        w3='word3';
        xwclue+= " &nbsp; <input type='text'  id='word3' name='word3' size='";
        xwclue+=v1no;
        xwclue+="' value=''>";

     }
     if (l4!=0) {
        w4='word4';
        xwclue+= " &nbsp; <input type='text' id='word4' name='word4' size='";
        xwclue+=v2no;
        xwclue+="' value=''>";
     }
  }
  if (reverse!=0) {
     xwclue+= "<br/><br/><input type='button' value='Enter' onclick='compute(\"xword\",w3,w4,w1,w2,row1,col1,row2,col2,row3,col3,row4,col4); this.form.reset()'>";  
  }else{
     xwclue+= "<br/><br/><input type='button' value='Enter' onclick='compute(\"xword\",w1,w2,w3,w4,row1,col1,row2,col2,row3,col3,row4,col4); this.form.reset()'>";
  }
  xwclue+="</form>";
  xwclue+= "</p>";
  writelayer('xwct',xwclue);
} 

function compute(formname,in1,in2,in3,in4,l1,c1,l2,c2,l3,c3,l4,c4) {
      if (document.layers) {
         if (in1!="no") input1=document.layers['xwct'].document.forms[formname].elements[in1].value
         if (in2!="no") input2=document.layers['xwct'].document.forms[formname].elements[in2].value;
         if (in3!="no") input3=document.layers['xwct'].document.forms[formname].elements[in3].value
         if (in4!="no") input4=document.layers['xwct'].document.forms[formname].elements[in4].value;
      }
      if (document.getElementById) {
         if (in1!="no") input1=document.getElementById(in1).value;
         if (in2!="no") input2=document.getElementById(in2).value;
         if (in3!="no") input3=document.getElementById(in3).value;
         if (in4!="no") input4=document.getElementById(in4).value;
      }else{
      if (in1!="no") input1=document.all[in1].value;
      if (in2!="no") input2=document.all[in2].value;
      if (in3!="no") input3=document.all[in3].value;
      if (in4!="no") input4=document.all[in4].value;
   }
   if (in1!="no") { 
      var i=c1;
      for (var j = 0; j < input1.length; j++) {
      	 imgsrc1="bl"+input1.charAt(j)+".gif"; 
         imgname1="l"+l1+"c"+i;
         changeimg('xw2',imgname1,imgsrc1);
          i++
      }
   }
   if (in2!="no") { 
      var k=c2;
      for (var j = 0; j < input2.length; j++) {
         imgsrc2="bl"+input2.charAt(j)+".gif";
         imgname2="l"+l2+"c"+k;
         changeimg('xw2',imgname2,imgsrc2);
         k++
      }
   }
   if (in3!="no") { 
      var i=l3;
      for (var j = 0; j < input3.length; j++) {
         imgsrc3="bl"+input3.charAt(j)+".gif";
         imgname3="l"+i+"c"+c3;
         changeimg('xw2',imgname3,imgsrc3);
         i++
      }
   }
   if (in4!="no") { 
      var k=l4;
      for (var j = 0; j < input4.length; j++) {
         imgsrc4="bl"+input4.charAt(j)+".gif";
         imgname4="l"+k+"c"+c4;
         changeimg('xw2',imgname4,imgsrc4);
         k++
      }
   }
}  

  
