function hiLite(d,obj,b){
 if(d==1){ //over
  obj.src = "images/button_" + b + ".png";
 }
 else{ //out
  obj.src = "images/button_" + b + "2.png";
 }
}

function adjContainer(){
 if(document.documentElement.clientHeight > 0){
  bHeight = document.documentElement.clientHeight;
  bWidth = document.documentElement.clientWidth; 
 }
 else{
  bHeight = document.body.clientHeight;
  bWidth  = document.body.clientWidth;
 }

 sStage = document.getElementById('stage');
 sStageTop = 0;
 sStageLeft = 0;
 
 // 1. Adjust Vertical Align //
 if(bHeight > 558){
  sStageTop = Math.ceil((bHeight - 558)/2);
  sStage.style.top = Math.ceil((bHeight - 558)/2) + "px";
 }
 // 1b. Adjust Horizontal align since FireFox decided to be a donkey
 if(bWidth > 887){
  sStageLeft = Math.ceil((bWidth - 887)/2); 
  sStage.style.left = Math.ceil((bWidth - 887)/2) + "px"; 
 }
 
 // 2. INTERNET EXPLORER TWEAKS/FIXES **//
 if(navigator.appName == "Microsoft Internet Explorer"){ 
  sStage.style.left = Math.ceil((bWidth - 877)/2) + "px"; //ie fix for it refusing to acknowledge centre alignment.
  document.getElementById('container').style.paddingLeft = "10px"; // ie fix as it's stupid
  document.getElementById('container').style.paddingTop = "10px"; // ditto
  if(navigator.userAgent.indexOf("MSIE 7") != -1){
	window.status = "Internet Explorer 7 - development purposes";	
	// adjust the screen
	document.getElementById('mainPart').style.paddingLeft = "140px";
	//document.getElementById('mainPart').style.paddingTop = "0px";
	
	// adjust all page positions
	 document.getElementById('page0').style.top = "2px";
	 document.getElementById('page0').style.left = "-14px";
  }
  if(navigator.userAgent.indexOf("MSIE 8") != -1){
	window.status = "Internet Explorer 8 - development purposes";
  }
 }
 
 // 3. Ensure QoTD is placed and visible
 //qotd = document.getElementById('qotd');
 document.getElementById('qotd').style.top = sStageTop + "px";
 document.getElementById('qotd').style.left = sStageLeft + 877 - 114 + "px";
 document.getElementById('qotdtxt').style.left = sStageLeft + 877 - 210 + "px" ;
 document.getElementById('qotdtxt').style.top = sStageTop + 42 + "px";

 // 4. Brings up the site on first load (it is hidden until positioned for smoothness //
 if(sStage.style.visibility == "hidden"){
  sStage.style.visibility = "visible";
  document.getElementById('qotd').style.visibility = "visible";
  document.getElementById('qotdtxt').style.visibility = "hidden"; //only visible on demand
 }

}

function changePage(x){
 n = 0;
 while(n<=4){ // hide all
  document.getElementById('page' + n).style.visibility = "hidden";
  document.getElementById('page' + n).style.zIndex = -2;
  n++;
 }
 document.getElementById('page' + x).style.visibility = "visible"; // show correct
 document.getElementById('page' + x).style.zIndex = 2;
 if(x == 0){ //hide the white box
  document.getElementById('whiteBox').style.visibility = "hidden";
 }
 else{ // show the white box
  document.getElementById('whiteBox').style.visibility = "visible";	
 }
 if(navigator.userAgent.indexOf("MSIE 8")!=-1){
  //alert('top: ' + document.getElementById('page' + x).style.top);
 }
}

function handleMessage(){
 var val = document.forms[0].elements['message'].value;
 if((val.length+1) > 200){ //adj for 1 as the first character is place zero
  adjVal = val.substring(0,199);
  document.forms[0].elements['message'].value = adjVal;
 }
 else{
  //document.forms[0].elements['chars'].value = 199 - val.length;
  //reinstate the above command if decide to use text box again
  document.getElementById('chars').innerHTML = "Characters Left: " + eval(199 - val.length) + "<br><br>";
 }
 
 // tweak to adjust for JS not being able to count 100%-100% = 0! :-) //
 if(val == ""){
  document.getElementById('chars').innerHTML = "Characters Left: 200<br><br>"; 
 }
}

function qotdAnim(tempWidth,quote_for_today){
 if(tempWidth<200){
  document.getElementById('qotdMessenger').innerHTML = "&nbsp;";
  document.getElementById('qotdtxt').style.width = tempWidth + 1 + "px";
  document.getElementById('qotdMessenger').style.width = tempWidth + 1 + "px";
  timer = setTimeout("qotdAnim(" + (tempWidth+1) + ",\"" + quote_for_today + "\")",0);
 }
 else{
  clearTimeout(timer);
  document.getElementById('qotdMessenger').innerHTML = "<div align=\"right\">[<a href=\"#\" onClick=\"document.getElementById('qotdtxt').style.visibility='hidden';document.getElementById('qotdMessenger').style.visibility='hidden';\" style=\"color:#000000;text-decoration:none;\">X</a>]</div>" + quote_for_today;
  document.getElementById('qotdMessenger').style.visibility = "visible";
 }
}

function qotd(){
 quotes = new Array(30);
 quotes[0] = "...he finds he does not have his identity papers. With hilarious consequences.(<em>Major Vasilin Smiroff</em>)";
 quotes[1] = "I blame the Koreans you know<br>(<em>Bloke in a White Shirt</em>)";
 quotes[2] = "Darcey Bussell! Pfworrr!<br>(<em>Bloke at a Picnic Table</em>)";
 quotes[3] = "Do I look like a bloomin' dwarf to you, Dopey?<br>(<em>Bloke at a Park Bench</em>)";
 quotes[4] = "I want to talk about cheese.<br>(<em>Radio show caller</em>)";
 quotes[5] = "We're here and you're not, so you can't and I probably shouldn't";
 quotes[6] = "Don't tell the wife.<br>(<em>Excuses.com publicity campaign</em>)";
 quotes[7] = "Are you happy with your doorstep?<br>(<em>ComedyHead Doorstep Challenge</em>)";
 quotes[8] = "You're not gonna start speaking Jewish are you?<br>(<em>Bloke in a White Shirt</em>)";
 quotes[9] = "Anyone here know the way to the A435?<br>(<em>Lost Man in a Car</em>)";
 quotes[10] = "Does Richard Stilgoe?<br>(<em>MasterMind</em>)";
 quotes[11] = "Bar Tat! That's not even proper English!<br>(<em>Conservative Voter</em>)";
 quotes[12] = "Death! It is under this Government!<br>(<em>Conservative Voter</em>)";
 quotes[13] = "Hypochondria - For the man who has everything<br>(<em>New product ad campaign</em>)";
 quotes[14] = "When you're in love with a beautiful woman, it's hard.<br>(<em>Dame Anna Grammatical</em>)";
 quotes[15] = "I've never eaten monkey. I'm not keen on foreign food.<br>(<em>Scouse Gal</em>)";
 quotes[16] = "Bang and your face is gone!<br>(<em>Gary Splott</em>)";
 quotes[17] = "Cinderella up the duff. I spy Billy Goat's Gruff.<br>(<em>Marcus, Happy House</em>)";
 quotes[18] = "Steve Davis was 175 for 4 in the 7.15 at Kempton Park.<br>(<em>Short Attention Span News</em>)";
 quotes[19] = "I'm happy. Seeing you here makes me happy!<br>(<em>Dodgy Bloke on a Park Bench</em>)";
 quotes[20] = "Thank you Vikram. We all hope you get better soon.<br>(<em>Calcutta Christian Radio</em>)";
 quotes[21] = "That was Brian with 'Do you Love Me?'. Well Brian, I like your music, but I hardly know you.<br>(<em>Calcutta Christian Radio</em>)";
 quotes[22] = "For months, I was convinced I was a man trapped in the body of a woman.<br>(<em>Hippy in the Park</em>)";
 quotes[23] = "Life backwards spells death.<br>(<em>Man doing Community Service</em>)";
 quotes[24] = "Everyone likes a bonfire! Just the bloke who hired the skip got a bit narked.<br>(<em>Man doing Community Service</em>)";
 quotes[25] = "Open top model, two tyres missing, no spare visible, no tax disc.<br>(<em>Police officer questioning suspect on a bike</em>)";
 quotes[26] = "Oi, over here you daft bint!<br>(<em>Cyril Black</em>)";
 quotes[27] = "Is that donkey you just fed me?<br>(<em>Anonymous</em>)";
 quotes[28] = "Saturday Kitchen with Hannibal Lector! Each week, he can cook with a couple of members of the studio audience.<br>(<em>The Creatives</em>)";
 quotes[29] = "Dyslexic Countdown. You get more points, the further you are from a recognisable word.(<em>The Creatives</em>)";
 quotes[30] = "I can feel the creative pixies working their magic now.(<em>The Creatives</em>)";
 
 var Now = new Date();
 today = Now.getDate() - 1;
 
 quote_for_today = quotes[today];
 
 //alert(today);
 document.getElementById('qotdtxt').style.width = "0px";
 document.getElementById('qotdMessenger').style.width = "0px";
 document.getElementById('qotdMessenger').style.visibility = "hidden";
 document.getElementById('qotdtxt').style.visibility = "visible";
 
 //fix for IE... number 7?
 
 qotdAnim(0,quote_for_today); 
}

function frmCheck(){
 x = 0;
 err = 0;
 empty_fields = "";
 full_address = "enquiries" + "@" + "comedyhead.co.uk";
 isS = "";
 while(x < 8){
  if(x > 2 && x < 7){
   if(document.forms[0].elements[x].value == ""){
    err += 1;
    empty_fields += document.forms[0].elements[x].name + ',';
   }
  }
  x++;
 } 
 if(err != 0){
  if(err > 1){ isS = "s"; } // make required fieldS
  empty_fields = empty_fields.substring(0,empty_fields.length-1); // trim the last trailing comma
  alert('You have left\n\n' + err + '\n\nrequired field' + isS + ' blank\n\n' + empty_fields + '\n\nPlease go back and fill them in!\nThank You!');
 }
 else{
  document.forms[0].elements['recipient'].value = full_address;
  //alert('E-Mail being sent to: '+ full_address + '\nThank you for your submission. I will do my best to answer your e-mail as quickly as possible :)');
  //document.forms[0].elements['subject'].value = "[ComedyHead Website] " + document.forms[0].elements['subject'].value;
  document.forms[0].action = "/cgi-bin/FormMail.pl";
  alert('Your form is now being sent to ' + full_address + '!\nIf successful, you will be redirected to our homepage.\nThanks for getting in touch!');
  document.forms[0].submit();
 }
}
