blank_EMAIL   = "";
blank_MESSAGE = "";

function GCS_Build_Email_Form() {
  var cell1 = "";
  cell1 += '<TR><TD style="text-align: right; vertical-align: top; padding-right: 1ex;" NOWRAP>';

  var cell2 = "";
  cell2 += '    </TD><TD style="text-align: left; vertical-align: top;">';

  var theHTML = "";
  theHTML += '<FORM NAME="EmailDataForm"';
  theHTML += '      style="margin: 0px; padding: 0px; border: 0px;">';
  theHTML += '<CENTER>';
  theHTML += '<TABLE cellpadding=0 cellspacing=4px style="width: inherit;">';
  theHTML += '<COLGROUP SPAN=2>';

  theHTML += cell1;
  theHTML += 'Full Name:';
  theHTML += cell2;
  theHTML += '<INPUT TYPE="text" NAME="from_name"  COLS=50 SIZE=50>';
  theHTML += '</TD></TR>';

  theHTML += cell1;
  theHTML += 'Your Email Address:';
  theHTML += cell2;
  theHTML += '<INPUT TYPE="text" NAME="from_email" COLS=50 SIZE=50>';
  theHTML += '</TD></TR>';

  theHTML += cell1;
  theHTML += 'Your Phone Number:';
  theHTML += cell2;
  theHTML += '<INPUT TYPE="text" NAME="from_phone" COLS=50 SIZE=50>';
  theHTML += '</TD></TR>';

  theHTML += cell1;
  theHTML += 'I Agree to pay the $10 Registration Fee at the door:';
  theHTML += cell2;
  theHTML += '<DIV style="border: solid #000000 1px; padding: .5ex;">';
  theHTML += '<TABLE CELLPADDING=0 CELLSPACING=0 style="border: 0px;">';
  theHTML += '<COLGROUP SPAN=2>';
  theHTML += '<TR><TD style="font-size: 12pt;">';
  theHTML += '<INPUT TYPE="checkbox" NAME="yes"     VALUE="YES" UNCHECKED> YES<BR>';
  theHTML += '</TD><TD style="padding-left: 10ex; font-size: 12pt;">';
  theHTML += '</TD></TR></TABLE>';
  theHTML += '</DIV>';
  theHTML += '</TD></TR>';

  theHTML += cell1;
  theHTML += 'What Division?';
  theHTML += cell2;
  theHTML += '<DIV style="border: solid #000000 1px; padding: .5ex;">';
  theHTML += '<TABLE CELLPADDING=0 CELLSPACING=0 style="border: 0px;">';
  theHTML += '<COLGROUP SPAN=2>';
  theHTML += '<TR><TD style="font-size: 12pt;">';
  theHTML += '<INPUT TYPE="checkbox" NAME="interested_in_junior"     VALUE="YES" UNCHECKED> Junior Division (Middle School)<BR>';
  theHTML += '<INPUT TYPE="checkbox" NAME="interested_in_senior"     VALUE="YES" UNCHECKED> Senior Division (High School)<BR>';
  theHTML += '<INPUT TYPE="checkbox" NAME="interested_in_adult"   VALUE="YES" UNCHECKED> Adult Division (College and Adult)<BR>';
  theHTML += '</TD><TD style="padding-left: 10ex; font-size: 12pt;">';
  theHTML += '</TD></TR></TABLE>';
  theHTML += '</DIV>';
  theHTML += '</TD></TR>';

  theHTML += cell1;
  theHTML += 'What Category?';
  theHTML += cell2;
  theHTML += '<DIV style="border: solid #000000 1px; padding: .5ex;">';
  theHTML += '<TABLE CELLPADDING=0 CELLSPACING=0 border=0>';
  theHTML += '<COLGROUP SPAN=2>';
  theHTML += '<TR><TD style="font-size: 12pt;">';
  theHTML += '<INPUT TYPE="checkbox" NAME="windsolo"     VALUE="YES" UNCHECKED> Wind Solo<BR>';
  theHTML += '<INPUT TYPE="checkbox" NAME="windduet"  VALUE="YES" UNCHECKED> Wind Duet<BR>';
  theHTML += '<INPUT TYPE="checkbox" NAME="windensemble" VALUE="YES" UNCHECKED> Wind Ensemble<BR>';
  theHTML += '<BR>';
  theHTML += '<INPUT TYPE="checkbox" NAME="percussionsolo"    VALUE="YES" UNCHECKED> Percussion Solo<BR>';
  theHTML += '<INPUT TYPE="checkbox" NAME="percussionduet"   VALUE="YES" UNCHECKED> Percussion Duet<BR>';
  theHTML += '<INPUT TYPE="checkbox" NAME="percussionensemble"  VALUE="YES" UNCHECKED> Percussion Ensemble<BR>';
  theHTML += '</TD><TD style="padding-left: 3ex; font-size: 12pt; vertical-align: top;">';
  theHTML += '<INPUT TYPE="checkbox" NAME="guardsolo"  VALUE="YES" UNCHECKED> Color Guard Solo<BR>';
  theHTML += '<INPUT TYPE="checkbox" NAME="guardduet"       VALUE="YES" UNCHECKED> Color Guard Duet<BR>';
  theHTML += '<INPUT TYPE="checkbox" NAME="guardensemble"       VALUE="YES" UNCHECKED> Color Guard Ensemble<BR>';
  theHTML += '<BR>';
  theHTML += '<INPUT TYPE="checkbox" NAME="chorus"   VALUE="YES" UNCHECKED> Chorus<BR>';

  theHTML += '</TD></TR></TABLE>';
  theHTML += '</DIV>';
  theHTML += '</TD></TR>';

  var theTEXT = "";
  theTEXT += 'LIST FULL NAMES OF ALL COMPETITORS (Each person must pay $10).\n'; 
  theTEXT += 'Competitor 1: \n';
  theTEXT += 'Competitor 2: \n';
  theTEXT += 'Competitor 3: \n';
  theTEXT += 'Competitor 4: \n';
  theTEXT += 'Competitor 5: \n';
  theTEXT += 'Competitor 6: \n';
  theTEXT += 'Competitor 7: \n';
  theTEXT += 'Competitor 8: \n';
  theTEXT += 'Competitor 9: \n';
  theTEXT += 'Competitor 10: \n';
  theTEXT += ' \n';
  theTEXT += 'Name of Ensemble or Duet: \n';
  theTEXT += ' \n';
  theTEXT += 'Additional comments if any.\n';
  theTEXT += ' \n';
  theTEXT += 'How did you hear about us?\n';



//  theHTML += cell1;
  theHTML += '<TR><TD COLSPAN=2>';
  theHTML += '<DIV style="margin: 0px; padding: 0px; text-align:center;">';
  theHTML += '<TEXTAREA NAME="comments" ROWS=10 COLS=90 SIZE=90 wrap=virtual>';
  theHTML += theTEXT;
  theHTML += '</TEXTAREA>';
  theHTML += '</DIV>';
  theHTML += '</TD></TR>';
  theHTML += '</TABLE>';
  theHTML += '</CENTER>';
  theHTML +='</FORM>';
  document.write(theHTML);

  theHTML = "";
  theHTML += '<DIV style="margin: 0px; margin-bottom: 4px; padding: 0px; border: 0px;';
  theHTML += '            text-align: center; vertical-align: top; font-size: 10pt;">';
  theHTML += '<FORM NAME="EmailSubmitForm" METHOD="POST" ENCTYPE="text/plain" onSubmit="return false;"';
  theHTML += '      style="margin: 0px; padding: 0px; border: 0px;">';
  theHTML += '<INPUT TYPE="SUBMIT" value=" Submit Using Your Email Client  "';
  theHTML += '       onClick="SendEmailFromForm();"';
  theHTML += '       style="margin: 0px; margin-right: 30px;">';
  theHTML += '<INPUT TYPE="BUTTON" value=" Reset Form  "';
  theHTML += '       onclick="ResetForm();"';
  theHTML += '       style="margin: 0px;">';
  theHTML += '<INPUT TYPE="SUBMIT" value=" Generate Psuedo Email Below  "';
  theHTML += '       onClick="GenerateEmailFromForm();"';
  theHTML += '       style="margin: 0px; margin-left: 30px;">';
  theHTML += '</FORM>';
  theHTML += '</DIV>';

  document.write(theHTML);

  theHTML = "";
  theHTML += '<div ID="EMAIL" style="border: 0px; margin: 0px; padding: 0px;">';
  theHTML += '</div>';
  document.write(theHTML);

  Set_Blank_Globals();
}

function ResetForm() {
  document.EmailDataForm.reset();
  document.EmailSubmitForm.reset();
  Dynamic_Content('EMAIL', '');
}

function SendEmailFromForm() {
//  theACTION += '&CC=';
//  theACTION += '&BCC=';

  var theACTION = "";

//To:
  theACTION += 'mailto:info@gulfcoastsound.org';

//Subject
  theACTION += '?';  // Only one ? per mailto: tag
//  theACTION += '&';  // Use & if ? already used
  theACTION += 'SUBJECT=Individual and Ensemble Competition Registration Form';
  theACTION = theACTION.replace(/\ /g, "%20");
//Message
//  theACTION += '?';  // Only one ? per mailto: tag
  theACTION += '&';  // Use & if ? already used
  theACTION += 'BODY=';

  var theBODY = "";
  theBODY += GetEmailBody();
  if (theBODY == blank_EMAIL) {
    alert('Please try entering something first');
    return false;
  }
  theBODY = theBODY.replace(/\%/g, "%25"); // kind of have to do this one first. 
  theBODY = theBODY.replace(/\ /g, "%20");
  theBODY = theBODY.replace(/\!/g, "%21");
  theBODY = theBODY.replace(/\"/g, "%22"); // " (fix syntax highlighting on stupid editor)
  theBODY = theBODY.replace(/\#/g, "%23");
  theBODY = theBODY.replace(/\$/g, "%24");
  theBODY = theBODY.replace(/\&/g, "%26");
  theBODY = theBODY.replace(/\'/g, "%27"); // ' (fix syntax highlighting on stupid editor)
  theBODY = theBODY.replace(/\(/g, "%28");
  theBODY = theBODY.replace(/\)/g, "%29");
  theBODY = theBODY.replace(/\*/g, "%2a");
  theBODY = theBODY.replace(/\+/g, "%2b");
  theBODY = theBODY.replace(/\,/g, "%2c");
  theBODY = theBODY.replace(/\-/g, "%2d");
  theBODY = theBODY.replace(/\./g, "%2e");
  theBODY = theBODY.replace(/\//g, "%2f");
  theBODY = theBODY.replace(/\:/g, "%3a");
  theBODY = theBODY.replace(/\;/g, "%3b");
  theBODY = theBODY.replace(/\</g, "%3c");
  theBODY = theBODY.replace(/\=/g, "%3d");
  theBODY = theBODY.replace(/\>/g, "%3e");
  theBODY = theBODY.replace(/\?/g, "%3f");
  theBODY = theBODY.replace(/\@/g, "%40");
  theBODY = theBODY.replace(/\n/g, "&BODY=");
  theACTION += theBODY;
  if (GetPlatform() == "Mac") {
    theACTION = theACTION.replace(/\&BODY=/g,  "%0d");  //Convert all body='s
    theACTION = theACTION.replace("%0d",    "&BODY=");  //Convert the 1st one back.
  } else {
    if (GetPlatform() == "*nix") {
      theACTION = theACTION.replace(/\&BODY=/g,  "%0a");  //Convert all body='s
      theACTION = theACTION.replace("%0a",    "&BODY=");  //Convert the 1st one back.
    } else {
      theACTION = theACTION.replace(/\&BODY=/g,  "%0d%0a");  //Convert all body='s
      theACTION = theACTION.replace("%0d%0a",    "&BODY=");  //Convert the 1st one back.
    }
  }

  var theHTML2 = theACTION;
  theHTML2 = theHTML2.replace(/\?SUBJECT=/g, "<BR>?SUBJECT=");
  theHTML2 = theHTML2.replace(/\&BODY=/g,    "<BR>&BODY=");
  if (GetPlatform() == "Mac") {
    theHTML2 = theHTML2.replace(/\%0d/g,   "<BR>%0d");
  } else {
    if (GetPlatform() == "*nix") {
      theHTML2 = theHTML2.replace(/\%0a/g,   "<BR>%0a");
    } else {
      theHTML2 = theHTML2.replace(/\%0d\%0a/g,   "<BR>%0d%0a");
    }
  }
//  theHTML2 = theHTML2.replace(/\%20/g,       " ");
  theHTML2 = theHTML2.replace(/\&/g,         "^AMP^");
  theHTML2 = theHTML2.replace(/\^AMP\^/g,    "&amp;");
  theHTML2 = theHTML2.replace(/\"/g,         "&quot;");  // " correct syntax highlighting in editor

  var theHTML = "";
  theHTML += '<div style="padding: .4ex; margin-bottom: 1ex; border: solid #000000 1px; background-color: #AAAAAA;">';
  theHTML += 'Email Request Made.&nbsp; Transaction code below.';
  theHTML += '</div>';
  theHTML += '<div style="padding: .4ex; border: solid #000000 1px; background-color: #AAAAAA;">';
  theHTML += theHTML2;
  theHTML += '</div>';
  
  Dynamic_Content('EMAIL', theHTML);
  Bottom_of_the_Page();

//--- SEND THE EMAIL
  try { parent.location.href = theACTION; }
  catch (error) { return false; }
  return true;
}

function GenerateEmailFromForm() {
// Pushing the button resets the form.  Unless we do something about it.
  var theHTML = "";
  theHTML += '<div style="padding: .4ex; margin-bottom: 1ex; border: solid #000000 1px; background-color: #AAAAAA;">';
  theHTML += 'TO: info@gulfcoastsound.org';
  theHTML += '</div>';
  theHTML += '<div style="padding: .4ex; margin-bottom: 1ex; border: solid #000000 1px; background-color: #AAAAAA;">';
  theHTML += 'SUBJECT: Information Request from gulfcoastsound.org';
  theHTML += '</div>';
  theHTML += '<div style="padding: .4ex; border: solid #000000 1px; background-color: #AAAAAA;">';

  var theEMAIL = "";
  theEMAIL = GetEmailBody();
  theEMAIL = theEMAIL.replace(/\n/g, "<BR>");  //Convert \n to <BR> for HTML purposes

  theHTML += theEMAIL;
  theHTML += '</div>';

  Dynamic_Content('EMAIL', theHTML);
  Bottom_of_the_Page();
  return false;
}

function GetEmailBody() {
  var ReturnValue   = '';
//
  ReturnValue += "FULL NAME: ";
  ReturnValue += GetTextData('EmailDataForm', 'from_name');
  ReturnValue += "\n";
  ReturnValue += "EMAIL ADDRESS: ";
  ReturnValue += GetTextData('EmailDataForm', 'from_email');
  ReturnValue += "\n";
  ReturnValue += "PHONE NUMBER: ";
  ReturnValue += GetTextData('EmailDataForm', 'from_phone');
  ReturnValue += "\n\n";


//--- Fee
  ReturnValue += "Registration Fee: ";
  var Separator = "";
  if (GetCheckboxData('EmailDataForm', 'yes')) {
    ReturnValue += Separator;
    ReturnValue += "Yes - I agree to pay the $10 Registration Fee";
    Separator = ", ";
  }
  ReturnValue += "\n\n";


//--- INTERESTS
  ReturnValue += "DIVISION: ";
  var Separator = "";
  if (GetCheckboxData('EmailDataForm', 'interested_in_junior')) {
    ReturnValue += Separator;
    ReturnValue += "Junior Division";
    Separator = ", ";
  }
  if (GetCheckboxData('EmailDataForm', 'interested_in_senior')) {
    ReturnValue += Separator;
    ReturnValue += "Senior Division";
    Separator = ", ";
  }
  if (GetCheckboxData('EmailDataForm', 'interested_in_adult')) {
    ReturnValue += Separator;
    ReturnValue += "Adult Division";
    Separator = ", ";
  }
  ReturnValue += "\n\n";

//--- SKILLS
  ReturnValue += "CATEGORY: ";
  var Separator = "";
  if (GetCheckboxData('EmailDataForm', 'windsolo')) {
    ReturnValue += Separator;
    ReturnValue += "Wind Solo";
    Separator = ", ";
  }
  if (GetCheckboxData('EmailDataForm', 'windduet')) {
    ReturnValue += Separator;
    ReturnValue += "Wind Duet";
    Separator = ", ";
  }
  if (GetCheckboxData('EmailDataForm', 'windensemble')) {
    ReturnValue += Separator;
    ReturnValue += "Wind Ensemble";
    Separator = ", ";
  }
  if (GetCheckboxData('EmailDataForm', 'percussionsolo')) {
    ReturnValue += Separator;
    ReturnValue += "Percussion Solo";
    Separator = ", ";
  }
  if (GetCheckboxData('EmailDataForm', 'percussionduet')) {
    ReturnValue += Separator;
    ReturnValue += "Percussion Duet";
    Separator = ", ";
  }
  if (GetCheckboxData('EmailDataForm', 'percussionensemble')) {
    ReturnValue += Separator;
    ReturnValue += "Percussion Ensemble";
    Separator = ", ";
  }
  if (GetCheckboxData('EmailDataForm', 'guardsolo')) {
    ReturnValue += Separator;
    ReturnValue += "Color Guard Solo";
    Separator = ", ";
  }
  if (GetCheckboxData('EmailDataForm', 'guardduet')) {
    ReturnValue += Separator;
    ReturnValue += "Color Guard Duet";
    Separator = ", ";
  }
  if (GetCheckboxData('EmailDataForm', 'guardensemble')) {
    ReturnValue += Separator;
    ReturnValue += "Color Guard Ensemble";
    Separator = ", ";
  }
  if (GetCheckboxData('EmailDataForm', 'chorus')) {
    ReturnValue += Separator;
    ReturnValue += "Chorus";
    Separator = ", ";
  }
    ReturnValue += "\n\n";

//--- MESSAGE
  var Message = "";
  Message = GetTextareaData('EmailDataForm', 'comments');
  if (Message == blank_MESSAGE) {
    Message = "NONE";
  }
  ReturnValue += "MESSAGE: ";
  if (Message != "NONE") {
    ReturnValue += "\n\n";
  }
  ReturnValue += Message;
  
//
  return ReturnValue;
}

function Set_Blank_Globals() {
  blank_MESSAGE = GetTextareaData('EmailDataForm', 'comments');
  blank_EMAIL = GetEmailBody();  // Do this after message, since it affects content
}

function GetTextData(form, name) {
  var ReturnValue = null;
  eval('ReturnValue = document.'+form+'.elements[\''+name+'\'].value;');
  if ((blank_EMAIL == "") || (blank_MESSAGE == "")) { ReturnValue = ""; }
  return ReturnValue;
}

function GetCheckboxData(form, name) {
  var ReturnValue = null;
  eval('ReturnValue = document.'+form+'.elements[\''+name+'\'].checked;');
  if ((blank_EMAIL == "") || (blank_MESSAGE == "")) { ReturnValue = false; }
  return ReturnValue;
}

function GetSelectData(form, name) {
  var ReturnValue = null;
  eval('ReturnValue = document.'+form+'.elements[\''+name+'\'].selectedIndex;');
  if ((blank_EMAIL == "") || (blank_MESSAGE == "")) { ReturnValue = ""; }
  return ReturnValue;
}

function GetTextareaData(form, name) {
  var ReturnValue = null;
  eval('ReturnValue = document.'+form+'.'+name+'.value;');
  return ReturnValue;
}

//--- *********************************************//--- * Some Functions to Modify HTML Dynamically *//--- *********************************************
Browser = "unknown";

function GetBrowser()
{
  if (Browser == "unknown")
  {
    var userAgent=navigator.userAgent.toLowerCase();
    var appVersion=navigator.appVersion.toLowerCase();
    var dom_capable=document.getElementById?1:0;
    var netscape_yes=userAgent.indexOf('mozilla')!=-1&&userAgent.indexOf('compatible')==-1?1:0;
    var ie_yes=userAgent.indexOf('msie')!=-1?1:0;
    var opera_yes=userAgent.indexOf('opera')!=-1?1:0;
    var opera_pre6_yes=window.opera && navigator.userAgent.search(/opera.[1-6]/i)!=-1;
    var netscape4_yes=netscape_yes&&!dom_capable&&document.layers?1:0;
    var ie4_yes=ie_yes&&!dom_capable&&document.all?1:0;
    var ie6_yes=(appVersion.indexOf("msie 6")!= -1||appVersion.indexOf("msie 7")!= -1)?1:0
    if ((netscape_yes) || (netscape4_yes)) {
      if (!(netscape4_yes)) {
        Browser = "ns5";
      } else {
        Browser = "ns";
      }
    }
    if ((opera_yes) || (opera_pre6_yes)) {
      Browser = "opera";
    }
    if ((ie_yes) || (ie6_yes) || (ie4_yes) || (Browser == "unknown")) {
      Browser = "ie";
    }
  }
}

function GetLayer(layer_id)
{
  GetBrowser();
  var ReturnLayer = null;
  if (layer_id != null) {
    if (Browser == "ns5") {
      ReturnLayer = document.getElementById(layer_id);
    } else if (Browser == "ie") {
      eval('ReturnLayer = document.all.' + layer_id + ';');
    } else {
      eval('ReturnLayer = document.' + layer_id + ';');
    }
  }
  return ReturnLayer;
}

function GetPlatform() {
  var userAgent = navigator.userAgent.toLowerCase();
  var ReturnValue = "Win32";
  if (userAgent.indexOf("mac") != -1)
  { ReturnValue = "Mac"; }
  if ((userAgent.indexOf("linux") != -1) || (userAgent.indexOf("unix") != -1))
  { ReturnValue = "*nix"; }
  return ReturnValue;
}

function Dynamic_Content(ID, HTML)
{
  layer = GetLayer(ID);
  if (layer != null)
  {
    if (Browser == "ns4") {
      layer.document.open();
      layer.document.write(DATA);
      layer.document.close();
    } else {
      if (Browser == "ns5") {
        layer.innerHTML = HTML;
      } else {
        layer.innerHTML = HTML;
//      layer.innerText = HTML;
      }
    }
  }
}

function Bottom_of_the_Page() {
  window.scroll(0, document.body.scrollHeight);
}

