var firstCode = 0; //used to display Music form
function DoTest(){
alert("this is a test");
}

function changeBox(cbox) {
box = eval(cbox);
box.checked = !box.checked;
}

var myWindow, windowLink, newWindow;
function openWindow(newWindow,newWindowName) {
// alert("Window's name is:  " + newWindowName);

    myWindow = window.open(newWindow,newWindowName, 'width = 500, height = 500, scrollbars, status, resizable');
    myWindow.focus();

} 

function openOutsideWindow(url, width, height) 
{
	outsideWin = window.open(url, 'remote','LOCATION=YES,MENUBAR=YES,STATUS=YES,RESIZABLE,SCROLLBARS=YES,DIRECTORY=YES,TOOLBAR=YES,width='+width+',height='+height+',left=50,top=20')
	//nextline allows focus to continue to go to the remote window
	outsideWin.focus(); 
}
function openPlainWindow(url, width, height) 
{
	outsideWin = window.open(url, 'remote','RESIZABLE,SCROLLBARS=YES,width='+width+',height='+height+',left=50,top=50')
	//nextline allows focus to continue to go to the remote window
	outsideWin.focus(); 
}
function popupWindow(url) {
  myWindow = window.open(url,'popupWindow','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,copyhistory=no,width=410,height=375,screenX=150,screenY=150,top=150,left=150');
  myWindow.focus();
}
//--------------

var valueRadio = null;
function getRadioValue(radioObject){
 valueRadio = null;
 //alert("this is getRadioValue function. RadioObjectLength is: "+ radioObject.length);
 for (var i=0; i<radioObject.length; i++){
    if(radioObject[i].checked){
	  valueRadio = radioObject[i].value;
	    //alert("valueRadio is: " + valueRadio);
	  break;
	}
 }
 //alert("valueRadio is: " + valueRadio);
 return valueRadio; /**/
}

//********************************************************************
// Vartiable settings and functions indirectly related to validation
//********************************************************************
var message = "";
var Country = "";
//******************************************************
//  4th level  General functions for validating fields
//******************************************************
//Alphanumeric with no odd characters (no spaces)
function isFieldAlphaNum(value) {
var RegExpr1 = /[^'A-Za-z-]/;  // all but these characters are the valid ones
var testResult = value.search(RegExpr1); // result must be -1 to be OK
  if (value.length < 2){
    message = "Your entry is not valid, it's too short";
  return false
  }
  if (testResult == -1){// there were no invalid characters
    return true;
  }else {
     message = "Your entry was not valid" 
     return false;
  }
}
//alpha with ' and -  (no spaces)
function isFieldAlpha(value) {
var RegExpr1 = /[^'A-Za-z\-]/;  // all but these characters are the valid ones
var testResult = value.search(RegExpr1); // result must be -1 to be OK
  if (testResult == -1){// there were no invalid characters
    return true;
  }else {
     message = "Your entry was not valid" 
     return false;
  }
}
//isFieldAlphaPhrases to include spaces
function isFieldAlphaPhrases(value) {
var RegExpr1 = /[^'A-Za-z\- ]/;  // all but these characters are the valid ones
var testResult = value.search(RegExpr1); // result must be -1 to be OK
  if (testResult == -1){// there were no invalid characters
    return true;
  }else {
     message = "Your entry was not valid" 
     return false;
  }
}
//------------
//isFieldAlphaPhrases to include spaces
function isFieldAlphaArea(value) {
var RegExpr1 = /[^'A-Za-z\- \r\n\(\)\:\;\!\#\$\%\&\+\"\?\/\,\.0-9\=]/;  // all but these characters are the valid ones
var testResult = value.search(RegExpr1); // result must be -1 to be OK
  if (testResult == -1){// there were no invalid characters
    return true;
  }else {
     message = "Your entry was not valid" 
     return false;
  }
}
//------------
// Numeric pure  - just numbers -no currency or phones
function isFieldNumeric(value) {  
var RegExpr1 = /[^0-9]/; // all but these characters are the valid ones
var testResult = value.search(RegExpr1); // check if invalid characters found
  if (testResult == -1){ // there were no invalid characters
    return true;
  }else {
    message = "Your entry was not valid";
	return false
  }	
}
// Phones allows for (,),-, and spaces
function isFieldPhone(value) {
var RegExpr1 = /[^0-9\(\)\-\s]/; // all but these characters are the valid ones
var testResult = value.search(RegExpr1); // check if invalid characters found
  if (testResult == -1){ // there were no invalid characters
    return true;
  }else {
    message = "Your entry was not valid";
	return false
  }	
}

// Mobiles - only allows for spaces and -
function isFieldMobile(value) {
var RegExpr1 = /[^0-9\s-]/; // all but these characters are the valid ones
var testResult = value.search(RegExpr1); // check if invalid characters found
  if (value.length < 12){
    message = "Entry as: XXXX XXX XXX";
  return false
  }
  if (testResult == -1){ // there were no invalid characters
    return true;
  }else {
    message = "Your entry was not valid";
	return false
  }	
}
// For filtering out odd characters
function FieldHasInvalidChars(value) { //mainly for strings like names
//var value = document.form1.testString.value;
var RegExpr1 = /[!~\@\`\#\$\%\^\&\*\(\)\_\+\+\|\\\<\>\,\.\/\:\;\"\{\}\[\]]/;
var testResult = value.search(RegExpr1);
  if (testResult == -1){
    return false; // no odd characters
  }
  message = "Field has odd characters";
  return true;	
}
// complements the main one below
function EmailHasInvalidChars(value) {
//var value = document.form1.testString.value;
var RegExpr1 = /[\~\`\!\#\$\%\^\&\*\(\)\=\|\\\{\[\}\]\:\;\"\'\/\<\>\,\s]/;
var testResult = value.search(RegExpr1);
  if (testResult == -1){
    return false; // no odd characters
  }
  message = "Invalid e-mail";
  return true;	
}

//  /^.+\@(\[?)[a-zA-Z0-9\-\.\_]+\.([a-zA-Z\.]{2,3}|[0-9]{1,3})(\]?)$/
function isFieldEmail(value) {
  var reg1 = /(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)/; // not valid
  var reg2 = /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z\-\_]{2,3}|[0-9]{1,6})(\]?)$/; // valid
                 
  if (!reg1.test(value) && reg2.test(value)) {
    return true;
  }
  message= "You entered an invalid e-mail!";
  return false;
}

//********************************************************************
// 3rd level functions - Templates for specific fields
//********************************************************************
function checkText(value){ //pure strings like names
  if (value == ""){
    message = "Your entry is not valid, it's empty";
  return false
  }
 if (isFieldAlpha(value) == false){
	 return false;
 }
 if (FieldHasInvalidChars(value) == true){
   return false;
  }
  return true;
}

function checkNumber(value){  //pure numbers - no currency or phones
  if (value == ""){
    message = "Your entry is not valid, it's empty";
  return false
  }
 if (isFieldNumeric(value) == false) {
	 return false;
 }
 if (FieldHasInvalidChars(value) == true){
  return false;
 } 

 return true;
}
//********************************************************************
// 2ndd level functions for specific form fields
//********************************************************************
function checkName(value){ //pure strings like names
  if (value == ""){
    message = "Your entry is not valid, it's empty";
  return false
  }
  if (value.length < 2){
    message = "Your entry is not valid, it's too short";
  return false
  }
 if (isFieldAlpha(value) == false){
	 return false;
 }
 if (FieldHasInvalidChars(value) == true){
   return false;
  }
  return true;
}
// to check text with spaces
function checkPhrase(value){ //pure strings like phrases
  if (value == ""){
    message = "Your entry is not valid, it's empty";
  return false
  }
  if (value.length < 2){
    message = "Your entry is not valid, it's too short";
  return false
  }
 if (isFieldAlphaPhrases(value) == false){
	 return false;
 }
 if (FieldHasInvalidChars(value) == true){
   return false;
  }
  return true;
}
// -------------
// to check text area with spaces and carriege returns
function checkTextArea(value){ //pure strings like phrases
  if (value == ""){
    message = "Your entry is not valid, it's empty";
  return false
  }
  if (value.length < 2){
    message = "Your entry is not valid, it's too short";
  return false
  }
 if (isFieldAlphaArea(value) == false){
	 return false;
 }

  return true;
}

// ------------------
function checkEmail(value){
  if (value == ""){
    message = "Your entry is not valid, it's empty";
  return false
  }
 if (isFieldEmail(value) == false){
   return false;
 } 
 if (EmailHasInvalidChars(value) == true){
  return false;
 }  
 return true;
}

function checkPhone(value){
  if (value == ""){
    message = "Your entry is not valid, it's empty";
  return false
  }
  if (value.length < 6){
    message = "Area code + number must be at least 10 digits";
  return false
  }
 if (isFieldPhone(value) == false){
   return false;
 } 
 return true;
}

function checkAreaCode(value){  
  if (value.length < 2){
    message = "Areacode must between 2 and 4 digits";
    return false
  }
  if (isFieldPhone(value) == false){
   message = "Your entry is not valid";
   return false;
  } 
 return true;
}


function checkZipCode(value){
  if (value == ""){
    message = "Your entry is not valid, it's empty";
  return false
  }
 if(Country == "Australia"){
  if ((value.length != 4) || (isFieldNumeric(value) == false)){
    message = "Your entry is not valid";
    return false
  }
  if(isFieldNumeric(value) == false){
    message = "Your entry is not valid";
	return false;
  }
 }
 return true;
}


//*************************************************************************
// 1st level function for calling specific form 1 field validation functions
//*************************************************************************
function validateForm1() {
Country = document.form1.Country.value;
//alert("this is validateForm1");
//alert("Country is: " + Country);
var emptyFields = "";
//alert("FirstName is: " + document.form1.FirstName.value);
 if (!checkName(document.form1.FirstName.value)){
  emptyFields += "\n First Name --> " + message;
  //emptyFields=emptyFields.fontcolor(red);
 } 
  if (!checkName(document.form1.LastName.value)){
  emptyFields += "\n Last Name --> " + message;
 } 
   if (!checkPhrase(document.form1.City.value)){
  emptyFields += "\n City --> " + message;
 } 
    if (!checkPhrase(document.form1.State.value)){
  emptyFields += "\n State or Province --> " + message;
 } 
 //Postcode
 if (!checkZipCode(document.form1.Postcode.value)){
  emptyFields += "\n Postal code --> " + message
  }
 // To validate numbers (without picture) - used to check area code
 if (!checkAreaCode(document.form1.Area.value)){
  emptyFields += "\n Area Code --> " + message
 }
 //To validate Phones
 if (!checkPhone(document.form1.Phone.value)){
  emptyFields += "\n Phone --> " + message;
 }

 var areaPlusPhone = (parseInt(document.form1.Area.value.length) + parseInt(document.form1.Phone.value.length))
 if(areaPlusPhone < 10 ){
   //alert("areaPlusPhone is: "+ areaPlusPhone);
   emptyFields += "\n AreaCode plus Phone -->  Area code plus Phone --> should be 10 digits";
 }
  
 //To validate e-mails
 if (!checkEmail(document.form1.EMail.value)){
  emptyFields += "\n E-mail --> " + message
 }

/**/
 if (emptyFields != "") {
   emptyFields = "Please correct the following fields: \n" 
   +             "---------------------------------------------------\n" 
   + emptyFields;
   alert(emptyFields);
   return false;
 }
 return true;
 
}

//*************************************************************************
// 1st level function for calling specific frm_log_in field validation functions
//*************************************************************************
function validatefrm_log_in() {
//alert("this is validateLogin");
//alert("Country is: " + Country);
var emptyFields = "";
//alert("FirstName is: " + document.form1.FirstName.value);
 if (!checkTextArea(document.frm_log_in.userName.value)){
  emptyFields += "\n UserName --> " + message;
  //emptyFields=emptyFields.fontcolor(red);
 } 
  if (!checkTextArea(document.frm_log_in.txt_psw.value)){
  emptyFields += "\n Password --> " + message;
 } 
  if (emptyFields != "") {
   emptyFields = "Please correct the following fields: \n" 
   +             "---------------------------------------------------\n" 
   + emptyFields;
   alert(emptyFields);
   return false;
 }
 return true;
 
}

//*************************************************************************
// 1st level function for calling specific bookingForm 1 field validation functions
//*************************************************************************
function validateBookingForm() {
Country = document.bookingForm.Country.value;
//alert("this is validateBookingForm");
//alert("Country is: " + Country);
var emptyFields = "";
//alert("FirstName is: " + document.form1.FirstName.value);
 if (!checkName(document.bookingForm.MemberFirstName.value)){
  emptyFields += "\n Member's First Name --> " + message;
  //emptyFields=emptyFields.fontcolor(red);
 } 
  if (!checkName(document.bookingForm.MemberLastName.value)){
  emptyFields += "\n Member's Last Name --> " + message;
  } 
  // Membership  checkNumber(
    if (!checkNumber(document.bookingForm.Membership.value)){
  emptyFields += "\n Membership # --> " + message;
  } 
  
   if (!checkPhrase(document.bookingForm.City.value)){
  emptyFields += "\n City --> " + message;
 } 
    if (!checkPhrase(document.bookingForm.State.value)){
  emptyFields += "\n State or Province --> " + message;
 } 
 //Postcode
 if (!checkZipCode(document.bookingForm.Postcode.value)){
  emptyFields += "\n Postal code --> " + message
  }
 // To validate numbers (without picture) - used to check area code
 if (!checkAreaCode(document.bookingForm.Area.value)){
  emptyFields += "\n Area Code --> " + message
 }
 //To validate Phones
 if (!checkPhone(document.bookingForm.Phone.value)){
  emptyFields += "\n Phone --> " + message;
 }

 var areaPlusPhone = (parseInt(document.bookingForm.Area.value.length) + parseInt(document.bookingForm.Phone.value.length))
 if(areaPlusPhone < 10 ){
   //alert("areaPlusPhone is: "+ areaPlusPhone);
   emptyFields += "\n AreaCode plus Phone -->  Area code plus Phone --> should be 10 digits";
 }
  
 //To validate e-mails
 if (!checkEmail(document.bookingForm.EMail.value)){
  emptyFields += "\n E-mail --> " + message
 }
/*
*/
 if (emptyFields != "") {
   emptyFields = "Please correct the following fields: \n" 
   +             "---------------------------------------------------\n" 
   + emptyFields;
   alert(emptyFields);
   return false;
 }
 return true;
 
}


function generate_address( username, hostname ) {
        var domain = "benalla.com.au";
        var atsign = "&#64;";
        var addr = username + atsign + hostname + domain;
        document.write(
          "<" + "a" + " " + "href=" + "mail" + "to:" + addr + ">" +
          addr +
          "<\/a>");
      }