// "onLoad" Stuff

// Include Correct CSS File
if (document.all) { // IE
  document.writeln("<link href=\"/includes/ie.css\" type=\"text/css\" rel=\"stylesheet\">");
} else { // Netscape
  document.writeln("<link href=\"/includes/ns.css\" type=\"text/css\" rel=\"stylesheet\">");
}

var Nav4 = ((navigator.appName == "Netscape") && (parseInt(navigator.appVersion) == 4));
var letterlist = new Array("a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z");
var mypass;

// ----------------------------------------------------------------------------------------

function checkEnter(e, formName) {

	var characterCode;

	if (e && e.which) {
		e = e;
		characterCode = e.which;
	} else {
		e = event;
		characterCode = e.keyCode;
	}

	if (characterCode == 13) {
		checkForm(formName);
		return false;
	} else {
		return true;
	}
}

// ----------------------------------------------------------------------------------------

function displayTime() {
  var tdate = new Date();
  myHour = tdate.getHours();
  myMins = tdate.getMinutes();
  mySecs = tdate.getSeconds();
  myYear = tdate.getFullYear();
  myYear += (myYear < 1900) ? 1900 : 0;

  document.write("<span class=\"onair_text\">Your Time Now:</span> " + ((myHour < 10) ? "0" + myHour.toString() : myHour.toString()) + ":" + ((myMins < 10) ? "0" + myMins.toString() : myMins.toString()) + ":" + ((mySecs < 10) ? "0" + mySecs.toString() : mySecs.toString()));
}

// ----------------------------------------------------------------------------------------

function downloadPlayer() {

  document.location = "http://www.sunlim.dsl.pipex.com/cmpradio/CMPPlayer2.exe";

}

// ----------------------------------------------------------------------------------------

function downloadBroadcaster(myFile) {

  switch(myFile) {
    case 1: // AuDEC Broadcaster
      document.location = "http://www.sunlim.dsl.pipex.com/cmpradio/BCaster111.exe";
      break;
    case 2: // Real Producer v8.51
      document.location = "http://www.sunlim.dsl.pipex.com/cmpradio/RealProducer851.exe";
      break;
  }

}

// ----------------------------------------------------------------------------------------

function getBroadcasterSize(myFile) {

  switch(myFile) {
    case 1: // AuDEC Broadcaster
      document.write("1.7M");
      break;
    case 2: // Real Producer v8.51
      document.write("4.4M");
      break;
  }

}

// ----------------------------------------------------------------------------------------

function getBroadcasterName(myFile) {

  switch(myFile) {
    case 1: // AuDEC Broadcaster
      document.write("AuDEC Broadcaster v1.11");
      break;
    case 2: // Real Producer v8.51
      document.write("Real Producer v8.51");
      break;
  }

}

// ----------------------------------------------------------------------------------------

function sendContact(emailnum) {

  var Mail1  = "onair@cmpradio.co.uk";
  var Mail2  = "shows@cmpradio.co.uk";
  var Mail3  = "news@cmpradio.co.uk";
  var Mail4  = "sales@cmpradio.co.uk";
  var Mail5  = "tech@cmpradio.co.uk";
  var Mail6  = "webcams@cmpradio.co.uk";
  var Mail7  = "webeditors@cmpradio.co.uk";

  document.location = "MAILTO:" + eval("Mail" + emailnum);

}

// ----------------------------------------------------------------------------------------

function addNewsletter() {
  if (document.newsletter.email.value != "") {
    mypass = "";
    for(var i=0; i<8; i++) {
      mypass = mypass + letterlist[(Math.floor(Math.random()*26))];
    }
    myemail = escape(document.newsletter.email.value)
    myurl = "http://www.cmpradio.co.uk/mailman/subscribe/cmpradionews_cmpradio.co.uk?email=" + myemail + "&pw=" + mypass + "&pw-conf=" + mypass + "&digest=0";
		
    openNewsletter(myurl, 410, 210, 1);
  } else {
    alert("Please make sure you have entered your e-mail address.");
  }
}

// ----------------------------------------------------------------------------------------
// Pop-Up Windows Section
// ----------------------------------------------------------------------------------------

var newsletterWin = new Object();

function openNewsletter(url, width, height, scrolls) {
  if (!newsletterWin.win || (newsletterWin.win && newsletterWin.win.closed)) {
		
    // Initialize properties of the modal dialog object.
    newsletterWin.url = url
    newsletterWin.width = width
    newsletterWin.height = height
		
    // Keep name unique so Navigator doesn't overwrite an existing dialog.
    newsletterWin.name = (new Date()).getSeconds().toString()
		
    // Assemble window attributes and try to center the dialog.
    if (Nav4) {
      // Center on the main window.
      newsletterWin.left = window.screenX + ((window.outerWidth - newsletterWin.width) / 2)
      newsletterWin.top = window.screenY + ((window.outerHeight - newsletterWin.height) / 2)
      if (scrolls == 0) {
        attr = "screenX=" + newsletterWin.left + ",screenY=" + newsletterWin.top + ",resizable=no,scrollbars=no,width=" + newsletterWin.width + ",height=" + newsletterWin.height
      } else {
        attr = "screenX=" + newsletterWin.left + ",screenY=" + newsletterWin.top + ",resizable=no,scrollbars=yes,width=" + newsletterWin.width + ",height=" + newsletterWin.height
      }
    } else {
      // The best we can do is center in screen.
      newsletterWin.left = (screen.width - newsletterWin.width) / 2
      newsletterWin.top = (screen.height - newsletterWin.height) / 2
    if (scrolls == 0) {
        attr = "left=" + newsletterWin.left + ",top=" + newsletterWin.top + ",resizable=no,scrollbars=no,width=" + newsletterWin.width + ",height=" + newsletterWin.height
      } else {
        attr = "left=" + newsletterWin.left + ",top=" + newsletterWin.top + ",resizable=no,scrollbars=yes,width=" + newsletterWin.width + ",height=" + newsletterWin.height
      }
    }
				
    // Generate the dialog and make sure it has focus.
    newsletterWin.win=window.open(newsletterWin.url, newsletterWin.name, attr)
    newsletterWin.win.focus()
  } else {
    newsletterWin.win.focus()
  }
}

var showWin = new Object();

function openShow(url, width, height, scrolls) {
  if (!showWin.win || (showWin.win && showWin.win.closed)) {
		
    // Initialize properties of the modal dialog object.
    showWin.url = url
    showWin.width = width
    showWin.height = height
		
    // Keep name unique so Navigator doesn't overwrite an existing dialog.
    showWin.name = (new Date()).getSeconds().toString()
		
    // Assemble window attributes and try to center the dialog.
    if (Nav4) {
      // Center on the main window.
      showWin.left = window.screenX + ((window.outerWidth - showWin.width) / 2)
      showWin.top = window.screenY + ((window.outerHeight - showWin.height) / 2)
      if (scrolls == 0) {
        attr = "screenX=" + showWin.left + ",screenY=" + showWin.top + ",resizable=no,scrollbars=no,width=" + showWin.width + ",height=" + showWin.height
      } else {
        attr = "screenX=" + showWin.left + ",screenY=" + showWin.top + ",resizable=no,scrollbars=yes,width=" + showWin.width + ",height=" + showWin.height
      }
    } else {
      // The best we can do is center in screen.
      showWin.left = (screen.width - showWin.width) / 2
      showWin.top = (screen.height - showWin.height) / 2
    if (scrolls == 0) {
        attr = "left=" + showWin.left + ",top=" + showWin.top + ",resizable=no,scrollbars=no,width=" + showWin.width + ",height=" + showWin.height
      } else {
        attr = "left=" + showWin.left + ",top=" + showWin.top + ",resizable=no,scrollbars=yes,width=" + showWin.width + ",height=" + showWin.height
      }
    }
				
    // Generate the dialog and make sure it has focus.
    showWin.win=window.open(showWin.url, showWin.name, attr)
    showWin.win.focus()
  } else {
    showWin.win.focus()
  }
}

var bookWin = new Object();

function openBook(url, width, height, scrolls) {
  if (!bookWin.win || (bookWin.win && bookWin.win.closed)) {
		
    // Initialize properties of the modal dialog object.
    bookWin.url = url
    bookWin.width = width
    bookWin.height = height
		
    // Keep name unique so Navigator doesn't overwrite an existing dialog.
    bookWin.name = (new Date()).getSeconds().toString()
		
    // Assemble window attributes and try to center the dialog.
    if (Nav4) {
      // Center on the main window.
      bookWin.left = window.screenX + ((window.outerWidth - bookWin.width) / 2)
      bookWin.top = window.screenY + ((window.outerHeight - bookWin.height) / 2)
      if (scrolls == 0) {
        attr = "screenX=" + bookWin.left + ",screenY=" + bookWin.top + ",resizable=no,scrollbars=no,width=" + bookWin.width + ",height=" + bookWin.height
      } else {
        attr = "screenX=" + bookWin.left + ",screenY=" + bookWin.top + ",resizable=no,scrollbars=yes,width=" + bookWin.width + ",height=" + bookWin.height
      }
    } else {
      // The best we can do is center in screen.
      bookWin.left = (screen.width - bookWin.width) / 2
      bookWin.top = (screen.height - bookWin.height) / 2
    if (scrolls == 0) {
        attr = "left=" + bookWin.left + ",top=" + bookWin.top + ",resizable=no,scrollbars=no,width=" + bookWin.width + ",height=" + bookWin.height
      } else {
        attr = "left=" + bookWin.left + ",top=" + bookWin.top + ",resizable=no,scrollbars=yes,width=" + bookWin.width + ",height=" + bookWin.height
      }
    }
				
    // Generate the dialog and make sure it has focus.
    bookWin.win=window.open(bookWin.url, bookWin.name, attr)
    bookWin.win.focus()
  } else {
    bookWin.win.focus()
  }
}

var cancelWin = new Object();

function openCancel(url, width, height, scrolls) {
  if (!cancelWin.win || (cancelWin.win && cancelWin.win.closed)) {
		
    // Initialize properties of the modal dialog object.
    cancelWin.url = url
    cancelWin.width = width
    cancelWin.height = height
		
    // Keep name unique so Navigator doesn't overwrite an existing dialog.
    cancelWin.name = (new Date()).getSeconds().toString()
		
    // Assemble window attributes and try to center the dialog.
    if (Nav4) {
      // Center on the main window.
      cancelWin.left = window.screenX + ((window.outerWidth - cancelWin.width) / 2)
      cancelWin.top = window.screenY + ((window.outerHeight - cancelWin.height) / 2)
      if (scrolls == 0) {
        attr = "screenX=" + cancelWin.left + ",screenY=" + cancelWin.top + ",resizable=no,scrollbars=no,width=" + cancelWin.width + ",height=" + cancelWin.height
      } else {
        attr = "screenX=" + cancelWin.left + ",screenY=" + cancelWin.top + ",resizable=no,scrollbars=yes,width=" + cancelWin.width + ",height=" + cancelWin.height
      }
    } else {
      // The best we can do is center in screen.
      cancelWin.left = (screen.width - cancelWin.width) / 2
      cancelWin.top = (screen.height - cancelWin.height) / 2
    if (scrolls == 0) {
        attr = "left=" + cancelWin.left + ",top=" + cancelWin.top + ",resizable=no,scrollbars=no,width=" + cancelWin.width + ",height=" + cancelWin.height
      } else {
        attr = "left=" + cancelWin.left + ",top=" + cancelWin.top + ",resizable=no,scrollbars=yes,width=" + cancelWin.width + ",height=" + cancelWin.height
      }
    }
				
    // Generate the dialog and make sure it has focus.
    cancelWin.win=window.open(cancelWin.url, cancelWin.name, attr)
    cancelWin.win.focus()
  } else {
    cancelWin.win.focus()
  }
}

var rulesWin = new Object();

function openRules(url, width, height, scrolls) {
  if (!rulesWin.win || (rulesWin.win && rulesWin.win.closed)) {
		
    // Initialize properties of the modal dialog object.
    rulesWin.url = url
    rulesWin.width = width
    rulesWin.height = height
		
    // Keep name unique so Navigator doesn't overwrite an existing dialog.
    rulesWin.name = (new Date()).getSeconds().toString()
		
    // Assemble window attributes and try to center the dialog.
    if (Nav4) {
      // Center on the main window.
      rulesWin.left = window.screenX + ((window.outerWidth - rulesWin.width) / 2)
      rulesWin.top = window.screenY + ((window.outerHeight - rulesWin.height) / 2)
      if (scrolls == 0) {
        attr = "screenX=" + rulesWin.left + ",screenY=" + rulesWin.top + ",resizable=no,scrollbars=no,width=" + rulesWin.width + ",height=" + rulesWin.height
      } else {
        attr = "screenX=" + rulesWin.left + ",screenY=" + rulesWin.top + ",resizable=no,scrollbars=yes,width=" + rulesWin.width + ",height=" + rulesWin.height
      }
    } else {
      // The best we can do is center in screen.
      rulesWin.left = (screen.width - rulesWin.width) / 2
      rulesWin.top = (screen.height - rulesWin.height) / 2
    if (scrolls == 0) {
        attr = "left=" + rulesWin.left + ",top=" + rulesWin.top + ",resizable=no,scrollbars=no,width=" + rulesWin.width + ",height=" + rulesWin.height
      } else {
        attr = "left=" + rulesWin.left + ",top=" + rulesWin.top + ",resizable=no,scrollbars=yes,width=" + rulesWin.width + ",height=" + rulesWin.height
      }
    }
				
    // Generate the dialog and make sure it has focus.
    rulesWin.win=window.open(rulesWin.url, rulesWin.name, attr)
    rulesWin.win.focus()
  } else {
    rulesWin.win.focus()
  }
}

var privacyWin = new Object();

function openPrivacy(url, width, height, scrolls) {
  if (!privacyWin.win || (privacyWin.win && privacyWin.win.closed)) {
		
    // Initialize properties of the modal dialog object.
    privacyWin.url = url
    privacyWin.width = width
    privacyWin.height = height
		
    // Keep name unique so Navigator doesn't overwrite an existing dialog.
    privacyWin.name = (new Date()).getSeconds().toString()
		
    // Assemble window attributes and try to center the dialog.
    if (Nav4) {
      // Center on the main window.
      privacyWin.left = window.screenX + ((window.outerWidth - privacyWin.width) / 2)
      privacyWin.top = window.screenY + ((window.outerHeight - privacyWin.height) / 2)
      if (scrolls == 0) {
        attr = "screenX=" + privacyWin.left + ",screenY=" + privacyWin.top + ",resizable=no,scrollbars=no,width=" + privacyWin.width + ",height=" + privacyWin.height
      } else {
        attr = "screenX=" + privacyWin.left + ",screenY=" + privacyWin.top + ",resizable=no,scrollbars=yes,width=" + privacyWin.width + ",height=" + privacyWin.height
      }
    } else {
      // The best we can do is center in screen.
      privacyWin.left = (screen.width - privacyWin.width) / 2
      privacyWin.top = (screen.height - privacyWin.height) / 2
    if (scrolls == 0) {
        attr = "left=" + privacyWin.left + ",top=" + privacyWin.top + ",resizable=no,scrollbars=no,width=" + privacyWin.width + ",height=" + privacyWin.height
      } else {
        attr = "left=" + privacyWin.left + ",top=" + privacyWin.top + ",resizable=no,scrollbars=yes,width=" + privacyWin.width + ",height=" + privacyWin.height
      }
    }
				
    // Generate the dialog and make sure it has focus.
    privacyWin.win=window.open(privacyWin.url, privacyWin.name, attr)
    privacyWin.win.focus()
  } else {
    privacyWin.win.focus()
  }
}

var listenWin = new Object();

function openListen(url, width, height, scrolls) {
  if (!listenWin.win || (listenWin.win && listenWin.win.closed)) {
		
    // Initialize properties of the modal dialog object.
    listenWin.url = url
    listenWin.width = width
    listenWin.height = height
		
    // Keep name unique so Navigator doesn't overwrite an existing dialog.
    listenWin.name = (new Date()).getSeconds().toString()
		
    // Assemble window attributes and try to center the dialog.
    if (Nav4) {
      // Center on the main window.
      listenWin.left = window.screenX + ((window.outerWidth - listenWin.width) / 2)
      listenWin.top = window.screenY + ((window.outerHeight - listenWin.height) / 2)
      if (scrolls == 0) {
        attr = "screenX=" + listenWin.left + ",screenY=" + listenWin.top + ",resizable=no,scrollbars=no,width=" + listenWin.width + ",height=" + listenWin.height
      } else {
        attr = "screenX=" + listenWin.left + ",screenY=" + listenWin.top + ",resizable=no,scrollbars=yes,width=" + listenWin.width + ",height=" + listenWin.height
      }
    } else {
      // The best we can do is center in screen.
      listenWin.left = (screen.width - listenWin.width) / 2
      listenWin.top = (screen.height - listenWin.height) / 2
    if (scrolls == 0) {
        attr = "left=" + listenWin.left + ",top=" + listenWin.top + ",resizable=no,scrollbars=no,width=" + listenWin.width + ",height=" + listenWin.height
      } else {
        attr = "left=" + listenWin.left + ",top=" + listenWin.top + ",resizable=no,scrollbars=yes,width=" + listenWin.width + ",height=" + listenWin.height
      }
    }
				
    // Generate the dialog and make sure it has focus.
    listenWin.win=window.open(listenWin.url, listenWin.name, attr)
    listenWin.win.focus()
  } else {
    listenWin.win.focus()
  }
}

var webcamWin = new Object();

function openWebcam(url, width, height, scrolls) {
  if (!webcamWin.win || (webcamWin.win && webcamWin.win.closed)) {
		
    // Initialize properties of the modal dialog object.
    webcamWin.url = url
    webcamWin.width = width
    webcamWin.height = height
		
    // Keep name unique so Navigator doesn't overwrite an existing dialog.
    webcamWin.name = (new Date()).getSeconds().toString()
		
    // Assemble window attributes and try to center the dialog.
    if (Nav4) {
      // Center on the main window.
      webcamWin.left = window.screenX + ((window.outerWidth - webcamWin.width) / 2)
      webcamWin.top = window.screenY + ((window.outerHeight - webcamWin.height) / 2)
      if (scrolls == 0) {
        attr = "screenX=" + webcamWin.left + ",screenY=" + webcamWin.top + ",resizable=no,scrollbars=no,width=" + webcamWin.width + ",height=" + webcamWin.height
      } else {
        attr = "screenX=" + webcamWin.left + ",screenY=" + webcamWin.top + ",resizable=no,scrollbars=yes,width=" + webcamWin.width + ",height=" + webcamWin.height
      }
    } else {
      // The best we can do is center in screen.
      webcamWin.left = (screen.width - webcamWin.width) / 2
      webcamWin.top = (screen.height - webcamWin.height) / 2
    if (scrolls == 0) {
        attr = "left=" + webcamWin.left + ",top=" + webcamWin.top + ",resizable=no,scrollbars=no,width=" + webcamWin.width + ",height=" + webcamWin.height
      } else {
        attr = "left=" + webcamWin.left + ",top=" + webcamWin.top + ",resizable=no,scrollbars=yes,width=" + webcamWin.width + ",height=" + webcamWin.height
      }
    }
				
    // Generate the dialog and make sure it has focus.
    webcamWin.win=window.open(webcamWin.url, webcamWin.name, attr)
    webcamWin.win.focus()
  } else {
    webcamWin.win.focus()
  }
}

var IMWin = new Object();

function openIM(url, width, height, scrolls) {
  if (!IMWin.win || (IMWin.win && IMWin.win.closed)) {
		
    // Initialize properties of the modal dialog object.
    IMWin.url = url
    IMWin.width = width
    IMWin.height = height
		
    // Keep name unique so Navigator doesn't overwrite an existing dialog.
    IMWin.name = (new Date()).getSeconds().toString()
		
    // Assemble window attributes and try to center the dialog.
    if (Nav4) {
      // Center on the main window.
      IMWin.left = window.screenX + ((window.outerWidth - IMWin.width) / 2)
      IMWin.top = window.screenY + ((window.outerHeight - IMWin.height) / 2)
      if (scrolls == 0) {
        attr = "screenX=" + IMWin.left + ",screenY=" + IMWin.top + ",resizable=no,scrollbars=no,width=" + IMWin.width + ",height=" + IMWin.height
      } else {
        attr = "screenX=" + IMWin.left + ",screenY=" + IMWin.top + ",resizable=no,scrollbars=yes,width=" + IMWin.width + ",height=" + IMWin.height
      }
    } else {
      // The best we can do is center in screen.
      IMWin.left = (screen.width - IMWin.width) / 2
      IMWin.top = (screen.height - IMWin.height) / 2
    if (scrolls == 0) {
        attr = "left=" + IMWin.left + ",top=" + IMWin.top + ",resizable=no,scrollbars=no,width=" + IMWin.width + ",height=" + IMWin.height
      } else {
        attr = "left=" + IMWin.left + ",top=" + IMWin.top + ",resizable=no,scrollbars=yes,width=" + IMWin.width + ",height=" + IMWin.height
      }
    }
				
    // Generate the dialog and make sure it has focus.
    IMWin.win=window.open(IMWin.url, IMWin.name, attr)
    IMWin.win.focus()
  } else {
    IMWin.win.focus()
  }
}

var RecommendWin = new Object();

function openRecommend(url, width, height, scrolls) {
  if (!RecommendWin.win || (RecommendWin.win && RecommendWin.win.closed)) {
		
    // Initialize properties of the modal dialog object.
    RecommendWin.url = url
    RecommendWin.width = width
    RecommendWin.height = height
		
    // Keep name unique so Navigator doesn't overwrite an existing dialog.
    RecommendWin.name = (new Date()).getSeconds().toString()
		
    // Assemble window attributes and try to center the dialog.
    if (Nav4) {
      // Center on the main window.
      RecommendWin.left = window.screenX + ((window.outerWidth - RecommendWin.width) / 2)
      RecommendWin.top = window.screenY + ((window.outerHeight - RecommendWin.height) / 2)
      if (scrolls == 0) {
        attr = "screenX=" + RecommendWin.left + ",screenY=" + RecommendWin.top + ",resizable=no,scrollbars=no,width=" + RecommendWin.width + ",height=" + RecommendWin.height
      } else {
        attr = "screenX=" + RecommendWin.left + ",screenY=" + RecommendWin.top + ",resizable=no,scrollbars=yes,width=" + RecommendWin.width + ",height=" + RecommendWin.height
      }
    } else {
      // The best we can do is center in screen.
      RecommendWin.left = (screen.width - RecommendWin.width) / 2
      RecommendWin.top = (screen.height - RecommendWin.height) / 2
    if (scrolls == 0) {
        attr = "left=" + RecommendWin.left + ",top=" + RecommendWin.top + ",resizable=no,scrollbars=no,width=" + RecommendWin.width + ",height=" + RecommendWin.height
      } else {
        attr = "left=" + RecommendWin.left + ",top=" + RecommendWin.top + ",resizable=no,scrollbars=yes,width=" + RecommendWin.width + ",height=" + RecommendWin.height
      }
    }
				
    // Generate the dialog and make sure it has focus.
    RecommendWin.win=window.open(RecommendWin.url, RecommendWin.name, attr)
    RecommendWin.win.focus()
  } else {
    RecommendWin.win.focus()
  }
}

var responseWin = new Object();

function openResponse() {
  if (!responseWin.win || (responseWin.win && responseWin.win.closed)) {
		
    // Setup form variables
    myrealname = escape(document.contact.realname.value)
    myemail = escape(document.contact.email.value)
    mysubject = escape(document.contact.subject.value)
    mycontent = escape(document.contact.content.value)
			
    // Initialize properties of the modal dialog object.
    responseWin.url = "contact.php?realname=" + myrealname + "&email=" + myemail + "&subject=" + mysubject + "&content=" + mycontent
    responseWin.width = 410
    responseWin.height = 175
		
    // Keep name unique so Navigator doesn't overwrite an existing dialog.
    responseWin.name = (new Date()).getSeconds().toString()
		
    // Assemble window attributes and try to center the dialog.
    if (Nav4) {
      // Center on the main window.
      responseWin.left = window.screenX + ((window.outerWidth - responseWin.width) / 2)
      responseWin.top = window.screenY + ((window.outerHeight - responseWin.height) / 2)
      attr = "screenX=" + responseWin.left + ",screenY=" + responseWin.top + ",resizable=no,scrollbars=no,width=" + responseWin.width + ",height=" + responseWin.height
    } else {
      // The best we can do is center in screen.
      responseWin.left = (screen.width - responseWin.width) / 2
      responseWin.top = (screen.height - responseWin.height) / 2
      attr = "left=" + responseWin.left + ",top=" + responseWin.top + ",resizable=no,scrollbars=no,width=" + responseWin.width + ",height=" + responseWin.height
    }
				
    // Generate the dialog and make sure it has focus.
    responseWin.win=window.open(responseWin.url, responseWin.name, attr)
    responseWin.win.focus()
  } else {
    responseWin.win.focus()
  }
}

var presentWin = new Object();

function openPresent() {
  if (!presentWin.win || (presentWin.win && presentWin.win.closed)) {
		
    // Setup form variables
    myfullname = escape(document.present.fullname.value)
    myemail = escape(document.present.email.value)
    myusername = escape(document.present.username.value)
    mypassword = escape(document.present.password.value)
			
    // Initialize properties of the modal dialog object.
    presentWin.url = "register.php?fullname=" + myfullname + "&email=" + myemail + "&username=" + myusername + "&password=" + mypassword
    presentWin.width = 410
    presentWin.height = 150
		
    // Keep name unique so Navigator doesn't overwrite an existing dialog.
    presentWin.name = (new Date()).getSeconds().toString()
		
    // Assemble window attributes and try to center the dialog.
    if (Nav4) {
      // Center on the main window.
      presentWin.left = window.screenX + ((window.outerWidth - presentWin.width) / 2)
      presentWin.top = window.screenY + ((window.outerHeight - presentWin.height) / 2)
      attr = "screenX=" + presentWin.left + ",screenY=" + presentWin.top + ",resizable=no,scrollbars=yes,width=" + presentWin.width + ",height=" + presentWin.height
    } else {
      // The best we can do is center in screen.
      presentWin.left = (screen.width - presentWin.width) / 2
      presentWin.top = (screen.height - presentWin.height) / 2
      attr = "left=" + presentWin.left + ",top=" + presentWin.top + ",resizable=no,scrollbars=yes,width=" + presentWin.width + ",height=" + presentWin.height
    }
				
    // Generate the dialog and make sure it has focus.
    presentWin.win=window.open(presentWin.url, presentWin.name, attr)
    presentWin.win.focus()
  } else {
    presentWin.win.focus()
  }
}

// ----------------------------------------------------------------------------------------
// Form Checking Section
// ----------------------------------------------------------------------------------------

function checkForm(formName) {

  formError = 0;
  errMsg = "The form submission cannot continue; the following fields are missing...\n\n";

  switch(formName) {
    case 'contact': // Studio Contact Form
      inputValue=document.contact.realname.value
      if (inputValue == "") {
        formError=1
        errMsg = errMsg + "* Your Name\n"
      }
      inputValue=document.contact.email.value
      if (inputValue == "") {
        formError=1
        errMsg = errMsg + "* Your E-Mail\n"
      }
      inputValue=document.contact.subject.value
      if (inputValue == "") {
        formError=1
        errMsg = errMsg + "* Enquiry Subject\n"
      }
      inputValue=document.contact.content.value
      if (inputValue == "") {
        formError=1
        errMsg = errMsg + "* Content of Enquiry\n"
      }
		
      if (formError == 1) {
        alert(errMsg);
      } else {
        openResponse();
      }
      break;

    case 'details': // Book Show Form
      inputValue=document.details.username.value
      if (inputValue == "") {
        formError=1
        errMsg = errMsg + "* Your UserName\n"
      }
      inputValue=document.details.password.value
      if (inputValue == "") {
        formError=1
        errMsg = errMsg + "* Your Password\n"
      }
      inputValue=document.details.showtitle.value
      if (inputValue == "") {
        formError=1
        errMsg = errMsg + "* Show Title\n"
      }
      inputValue=document.details.description.value
      if (inputValue == "") {
        formError=1
        errMsg = errMsg + "* Show Description\n"
      }

      if(document.details.description.value.length > 255){
        alert('Your show description must only be a maximum of 255 characters in length.');
      } else {
        if (formError == 1) {
          alert(errMsg)
        } else {
          document.details.submit();
        }
      }
      break;

    case 'cancel_details':
      inputValue=document.cancel_details.username.value
      if (inputValue == "") {
        formError=1
        errMsg = errMsg + "* Your UserName\n"
      }
      inputValue=document.cancel_details.password.value
      if (inputValue == "") {
        formError=1
        errMsg = errMsg + "* Your Password\n"
      }
      inputValue=document.cancel_details.receiptno.value
      if (inputValue == "") {
        formError=1
        errMsg = errMsg + "* Booking Receipt Number\n"
      }

      if (formError == 1) {
        alert(errMsg)
      } else {
        document.cancel_details.submit();
      }
      break;

    case 'present':
      userTest=/^[a-zA-Z]{1,}$/;
      emailTest=/\@{1,}/;
		
      inputValue=document.present.username.value
      if (inputValue == "") {
        formError=1
        errMsg = errMsg + "* Your UserName\n"
      } else if (!userTest.test(inputValue)) {
        formError=2
      }
      inputValue=document.present.email.value
      if (inputValue == "") {
        formError=1
        errMsg = errMsg + "* Your E-Mail\n"
      } else if (!emailTest.test(inputValue)) {
        formError=3
      }
      inputValue=document.present.password.value
      if (inputValue == "") {
        formError=1
        errMsg = errMsg + "* Your Password\n"
      }
      inputValue=document.present.fullname.value
      if (inputValue == "") {
        formError=1
        errMsg = errMsg + "* Your Full Name\n"
      }
		
      if (formError == 1) {
        alert(errMsg)
      } else {
        inputValue=document.present.password.value
        inputValue2=document.present.password2.value
        if (inputValue != inputValue2) {
          alert("Please make sure the passwords are identical.")
        } else {
          if (formError == 2) {
            alert("Your username must not contain any invalid characters or spaces.")
          } else if (formError == 3) { 
            alert("You must enter a valid e-mail address.")
          } else {
            openPresent()
          }
        }
      }
      break;

    case 'sendIM':
      if (document.sendIM.realname.value=='') {
        alert("Please make sure you have entered your name.");
      } else if (document.sendIM.message.value=='') {
        alert("Please make sure you have entered a valid message.");
      } else {
        document.sendIM.submit();
      }
      break;

    case 'login':
      inputValue=document.login.username.value
      if (inputValue == "") {
        formError=1
        errMsg = errMsg + "* Your UserName\n"
      }
      inputValue=document.login.password.value
      if (inputValue == "") {
        formError=1
        errMsg = errMsg + "* Your Password\n"
      }

      if (formError == 1) {
        alert(errMsg)
      } else {
        document.login.submit();
      }
      break;

    case 'remind':
      if (document.remind.email.value=='') {
        alert("Please make sure you have entered a valid e-mail address.");
      } else {
        document.remind.submit();
      }
      break;

  }
}
