function validation(){
  var feedback;
  var browser = navigator.appName;
    if(browser == "Microsoft Internet Explorer"){
      feedback = new ActiveXObject("Microsoft.XMLHTTP");
    } else {
      feedback = new XMLHttpRequest();
    }
  
  return feedback;
}
var http = validation(); 

function handleitem(){
  if(http.readyState == 4){
    var response = http.responseText;
    document.getElementById('error').innerHTML=response;
      if(document.getElementById('error').innerHTML=='ok') document.newpage.submit();
  }
}
function validate(){
  http.open('get', 'validate.php?title='+document.newpage.title.value+'&body='+document.newpage.body.value);
  http.onreadystatechange = handleitem; 
  http.send(null);
}
function boldit(){
  var bold = prompt('Please enter the text you want to appear in bold', '');
    if(bold==null || bold=="") {
      alert("Nothing was entered");
    } else {
      var boldtext = '<b>'+bold+'</b>';
      document.newpage.body.value=document.newpage.body.value+boldtext;
    }
}
function underlineit(){
  var underlined = prompt('Please enter the text you want to appear underlined', '');
    if(underlined==null || underlined=="") {
      alert("Nothing was entered");
    } else {
      var underlinedtext = '<u>'+underlined+'</u>';
      document.newpage.body.value=document.newpage.body.value+underlinedtext;
    }
}
function italicit(){
  var italics = prompt('Please enter the text you want to appear in italics', '');
    if(italics==null || italics=="") {
      alert("Nothing was entered");
    } else {
      var italicstext = '<i>'+italics+'</i>';
      document.newpage.body.value=document.newpage.body.value+italicstext;
    }
}
function linkit(){
  var link = prompt('Please enter the URL of the link (E.g. http://www.msn.com)', '');
  var linktext = prompt('Please enter the word(s) you want to be displayed instead of the link (E.g. MSN)', '');
    if(link==null || link=="" || linktext==null || linktext=="") {
      alert("Nothing was entered");
    } else {
      var makelink = '<a href=\"'+link+'\">'+linktext+'</a>';
      document.newpage.body.value=document.newpage.body.value+makelink;
    }
}
function bolditu(){
  var bold = prompt('Please enter the text you want to appear in bold', '');
    if(bold==null || bold=="") {
      alert("Nothing was entered");
    } else {
      var boldtext = '<b>'+bold+'</b>';
      document.updatepage.body.value=document.updatepage.body.value+boldtext;
    }
}
function underlineitu(){
  var underlined = prompt('Please enter the text you want to appear underlined', '');
    if(underlined==null || underlined=="") {
      alert("Nothing was entered");
    } else {
      var underlinedtext = '<u>'+underlined+'</u>';
      document.updatepage.body.value=document.updatepage.body.value+underlinedtext;
    }
}
function italicitu(){
  var italics = prompt('Please enter the text you want to appear in italics', '');
    if(italics==null || italics=="") {
      alert("Nothing was entered");
    } else {
      var italicstext = '<i>'+italics+'</i>';
      document.updatepage.body.value=document.updatepage.body.value+italicstext;
    }
}
function linkitu(){
  var link = prompt('Please enter the URL of the link (E.g. http://www.msn.com)', '');
  var linktext = prompt('Please enter the word(s) you want to be displayed instead of the link (E.g. MSN)', '');
    if(link==null || link=="" || linktext==null || linktext=="") {
      alert("Nothing was entered");
    } else {
      var makelink = '<a href=\"'+link+'\">'+linktext+'</a>';
      document.updatepage.body.value=document.updatepage.body.value+makelink;
    }
}
function imageit(){
  var imgsrc1 = prompt('Please enter the URL for the image you want to be displayed all of the time. (e.g. http://www.msn.com/image1.gif)', '');
  var imgsrc2 = prompt('Please enter the URL for the image you want to be display when the mouse is over the image (e.g. http://www.msn.com/image2.gif', '');
    if(imgsrc1==null || imgsrc1=="" || imgsrc2==null || imgsrc2=="") {
      alert("Nothing was entered");
    } else {
      var makeimg = '<img src=\"'+imgsrc1+'\" onMouseOver=\"this.src=\''+imgsrc2+'\'\" onMouseOut=\"this.src=\''+imgsrc1+'\'\" />';
      document.newpage.body.value=document.newpage.body.value+makeimg;
    }
}
function imageitu(){
  var imgsrc1 = prompt('Please enter the URL for the image you want to be displayed all of the time. (e.g. http://www.msn.com/image1.gif)', '');
  var imgsrc2 = prompt('Please enter the URL for the image you want to be display when the mouse is over the image (e.g. http://www.msn.com/image2.gif)', '');
    if(imgsrc1==null || imgsrc1=="" || imgsrc2==null || imgsrc2=="") {
      alert("Nothing was entered");
    } else {
      var makeimg = '<img src=\"'+imgsrc1+'\" onMouseOver=\"this.src=\''+imgsrc2+'\'\" onMouseOut=\"this.src=\''+imgsrc1+'\'\" />';
      document.updatepage.body.value=document.updatepage.body.value+makeimg;
    }
}
function imagesubmit() {
  var formname = document.uploadimage;
  var filefield = formname.image.value;
  var textfield = formname.title.value;
  var submitbutton = document.uploadimage.upload;
    if(filefield=='' || filefield==null) alert("Please browse for an image to upload.");
      else {
        if(textfield=='' || textfield==null) alert("Please enter a title for the image");
          else {
            submitbutton.value = 'uploading';
            submitbutton.disabled = true;
            formname.submit();
          }
    }
}
/*function hide_event(event_name) {
  var event=document.getElementById(event_name).style;
    if(event.visibility=='visible') {
      event.visibility='hidden';
    }
}
function show_event(event_name) {
  var event=document.getElementById(event_name).style;
    if(event.visibility=='hidden') {
      event.visibility='visible';
    }
}*/
function show_div(image_src, caption) {
  the_div=document.getElementById('gallery');
  the_image=document.getElementById('gallery_picture');
  the_caption=document.getElementById('gallery_caption');
    if(the_div.style.visibility=='hidden') {
      the_div.style.visibility='visible';
      the_image.src=image_src;
      the_caption.innerHTML='<br>'+caption;
    }
    if(the_image.src!='') {
      the_image.src=image_src;
      the_caption.innerHTML='<br>'+caption;
    }
}
function hide_div() {
  var the_div=document.getElementById('gallery').style;
    if(the_div.visibility=='visible') {
      the_div.visibility='hidden';
    }
}
function add_box() {
  var item=document.contact_.contact_subject;
  var box=document.getElementById('contact_4');
  if(item.value=='4') {
    box.style.display='block';
    box.style.visibility='visible';
  } else {
    box.style.display='none';
    box.style.visibility='hidden';  
  }
}
function generate_text(dir_num,file_name) {
  var dir_num;
  var file_name;
    if(dir_num==0) var dir='images/thumbs/';
    if(dir_num==1) var dir='images/';
      var box=document.getElementById('code');
        box.innerHTML='<br/><br/><textarea rows=\"8\" cols=\"40\"><img src=\"'+dir+file_name+'\" /></textarea>';
}
function clear_text() {
      var box=document.getElementById('code');
        box.innerHTML='';

}
function advert() {
  window.open('http://www.joshanderson.co.uk');
}
function show_event(rating,layer) {
    var rating;
    var desc;
    var top=document.getElementById("top_rating");
    var bot=document.getElementById("bot_rating");
    var desc=document.getElementById(layer);
    var result=document.getElementById("event_result");
    if(result.style.visibility=='visible') {
      result.style.visibility='hidden';
      desc.style.visibility='hidden';
    }
    if(result.style.display=='block') {
      result.style.display='none';
      desc.style.display='none';
    }
    if(result.style.visibility=='hidden') {
      result.style.visibility='visible';
      desc.style.visibility='visible';
    }
    if(result.style.display=='none') {
      result.style.display='block';
      desc.style.display='block';
    }
    if(rating==1) top.src='http://www.smickus.org/cb/images/rating/rating_adu_02.gif';
    if(rating==1) bot.src='http://www.smickus.org/cb/images/rating/rating_adu_04.gif';
    if(rating==0) top.src='http://www.smickus.org/cb/images/rating/rating_fam_02.gif';
    if(rating==0) bot.src='http://www.smickus.org/cb/images/rating/rating_fam_04.gif';
}
function hide_event(layer) {
    var layer;
    var desc=document.getElementById(layer);
    var result=document.getElementById("event_result");
    if(result.style.visibility=='visible') {
      result.style.visibility='hidden';
      desc.style.visibility='hidden';
    }
    if(result.style.display=='block') {
      result.style.display='none';
      desc.style.display='none';
    }
}

