
// Variables with Page-level Scope:
var visDIV;  		           // Current Sub-Page name, default: "home"     
var PageNameArray = new Array();   // Array of Page Names, corresponds to Nav Buttons!
var oHome;		           // "home" DIV object, used to position Sub-Pages
var oCurtain;			   // Hides content while loading
var winWidth;		           // Track this ourselves due to browser differences
var winHeight;
var oWrapperDIV;
var oMidColDIV;
var oSponsorMsg;

// For showing enlarged pic... 
var oBigPic;
var BigPicOpacity = 0;

// Form Handling Vars
var htmlDoc = null ;
var oForm;
var temp = "";
var origFormHTML;
var origButtonColor; 

var InDatabase = false;
var oFname = "";
var oLname = "";
var oEmail = "";



// Special handling for times when User navigates while we're busy hiding/showing a page:
var Busy = false;		   // Busy Doing Fadein/Fadeout... Special handling
var QueueNextButton = '';	   // Queue Next Button to show if User Navs while Busy!


function ImagePreloader() {
  // Called from <head> before <body> starts loading... (Also loads PageNameArray!)
  var myimages = new Array();
  var Arg;
  var j=0;
  for (var i=0; i<ImagePreloader.arguments.length; i++) {
    // Grab parameter value from array of 'arguments' sent to this Function.
    Arg = ImagePreloader.arguments[i];
    if (Arg.indexOf(".") <= 0) {
      // 'Arguments' without ".jpg" or ".gif" are BUTTON & PAGE Names, all "GIFs"
      PageNameArray[i] = Arg;      // Add Page Name to the PageNameArray
      // Preload Button GIFs for both states, (0 and 1). ('1' has the ICON!)
      // And load a 'Page Label' for each Sub-Page, whether we need it or not!
      // (i is "argument index", j is "image array index")
      myimages[j] = new Image();
      myimages[j].src = "images/"+Arg+"0.gif";
      j++;
      myimages[j] = new Image();
      myimages[j].src = "images/"+Arg+"1.gif";
      j++;
      // Page Heading Label GIFs for the Top Left of each 'Sub-Page'
      myimages[j] = new Image();
      myimages[j].src = "images/"+Arg+"Label.gif";
      j++;
    } else {
      // Other Images to Preload, (".gif" and ".jpg" files)
      j++;
      myimages[j] = new Image();
      myimages[j].src = "images/"+Arg;
    }
  }
}

function winInit() {
  // Invoked when the HTML <body> is finished loading, (onLoad Event)
  // visDIV is the "visible DIV" -- Name of "Selected Page", default: "home"
  visDIV = 'home';
  oHome         = document.getElementById('home');
  oWrapperDIV   = document.getElementById('wrapper');
  oMidColDIV    = document.getElementById('midCol');
  oSponsorMsg   = document.getElementById('SponsorMessage');
  oBigPic       = document.getElementById('CavPtLng');

  oForm = document.pinput.elements;

  var sRoot;

  // Size Center Column for browser width...
  winResize();
  
  // Fade out the curtain object...
  GetWinSize();
  oCurtain = document.getElementById('curtain');
  // Kill scrollbars caused by size of 'curtain' exceeding browser's
  // inner dimensions, causing content to jump when curtain hides... 
  oCurtain.style.height = (winHeight - 50) + "px";
  oCurtain.style.width  = (winWidth - 50)  + "px";
  FadeCurtain(95);

  // Set Full Opacity of 'Home' button, the default 'Selected' button.
  oBtn = document.getElementById('b_home');
  SetButtonOpacity(oBtn,100);

  // Assign Event Handlers for Nav Buttons, ('childNodes' of DIV: "NavButtons") 
  var oDiv = document.getElementById('NavButtons');
  for (var i=0;i<oDiv.childNodes.length;i++) {
    if (oDiv.childNodes[i].id) {
      // Strip first 2 chars, the "b_"...
      sRoot = oDiv.childNodes[i].id.substring(2);
      oDiv.childNodes[i].onmouseover = new Function("mOver('"+sRoot+"');");
      oDiv.childNodes[i].onmouseout  = new Function("mOut('"+sRoot+"');");
      oDiv.childNodes[i].onclick     = new Function("mClick('"+sRoot+"');");
    }
  }

  //sw3 turn off the cookies 

  // See if COOKIES have been set for this Person, They MAY already be Registered!!!
  // CheckLogin()

  // GO TO THE REG PAGE WITH AN EMAIL ADDRESS TO LOOKUP IF QUERYSTRING IS SET PROPERLY -------------------->
  var target = querySt('t');
  if (!target) return;
  if (target=='reg') {
    // See if there is an Email Address in "k"
    temp = querySt('k');
      if (temp) { 
        USER_DATA = FindUser(temp);
      }
    GoPage(-1);
  }
}

// Get QueryString
function querySt(ji) {
  hu = window.location.search.substring(1);
  gy = hu.split("&");
  for (i=0;i<gy.length;i++) {
    ft = gy[i].split("=");
    if (ft[0] == ji) {
      return ft[1];
    }
  }

}

function winResize() {
  // User Resized the Browser Window
  var Dif;
  GetWinSize();

  // Default this to NOT SHOWING...
  document.getElementById('SponsorMessage').style.display = "none";

  // Increase width of 'wrapper' and 'midCol' by same amount
  // Min 'wrapper' 892px, Min 'midCol' 500px
  Dif = winWidth - 930
  if (winWidth < 930) {
    // Minimum Width
    oWrapperDIV.style.width = 892 + "px";
    oMidColDIV.style.width = 500 + "px";
    if (winWidth < 800) {
      oSponsorMsg.style.display = "block";
      oSponsorMsg.style.left =  (winWidth-300) + "px";
    }

  } else {
    // Greater than minimum...
    oWrapperDIV.style.width = (892+.4*Dif) + "px";
    oMidColDIV.style.width = (500+.4*Dif) + "px";
  }

  // If showing a Sub-Page, must move it 'manually'...
  if (visDIV != 'home') {
    // Move current Sub-Page DIV to 'follow' the invisible "home" DIV, (oHome).
    PosArray = GetPos(oHome);
    var oDiv = document.getElementById(visDIV);
    oDiv.style.top  = PosArray[0]+'px';
    oDiv.style.left = PosArray[1]+'px';
  }
}

function mOver(btn) {
  // BUTTON MOUSE OVER EVENT
  if (btn != visDIV) {
    // If Button isn't Currently Selected -- Set Medium Opacity
    SetButtonOpacity(document.getElementById('b_'+btn),75)
  }
}

function mOut(btn) {
  // BUTTON MOUSE OUT EVENT
  if (btn != visDIV) {
    // If Button isn't Currently Selected -- Set Low Opacity
    SetButtonOpacity(document.getElementById('b_'+btn),50)
  }
}

function mClick(NewButton) {
  // BUTTON CLICK EVENT
  // Exit if Button is Currently Selected...
  if (NewButton == visDIV) return;
  if (Busy) {
    // Capture Next Button to show when done showing this one...
    // (User navigated while we were busy Hiding/Showing a page)
    QueueNextButton = NewButton;
    return;
  }
  Busy = true;
  SetCursor('wait');

  // Deselect current 'Selected' button
  var OldButton = visDIV;
  visDIV = NewButton;
  var oBtn = document.getElementById('b_'+OldButton);
  if (oBtn) {
    oBtn.src = 'images/'+OldButton+'0'+'.gif';
    // Reset to Low Opacity
    SetButtonOpacity(oBtn,50)
  }

  // 'Select' this new Button, (make it 'dark', show the 'icon')
  oBtn = document.getElementById('b_'+NewButton);
  // Toggle Button Image Source (SHOW Logo Icon)
  oBtn.src = 'images/'+NewButton+'1'+'.gif';
  // Set Full Opacity
  SetButtonOpacity(oBtn,100)

  // Set Object variables
  var oOldDiv = document.getElementById(OldButton);
  var oNewDiv = document.getElementById(NewButton);

  // Place 'new' DIV on top of 'home' DIV. Always, because it moves on Window Resize!)
  PosArray = GetPos(oHome);
  oNewDiv.style.top  = PosArray[0]+'px';
  oNewDiv.style.left = PosArray[1]+'px';

  // Set initial attributes of 'new' DIV... 
  var opacity = 0;
  oNewDiv.style.visibility = "visible";
  oNewDiv.style.display = 'block';
  oNewDiv.style.height = '517px';

  // Slowly Hide Old and Show New SubPage DIV in a recursive process...
  CrossFade(OldButton, NewButton, opacity);

  // DeSelect all User 'Click-Dragged' Selection of Browser Window Objects, (all Browsers!)
  KillScreenSelection();
}

function SetCursor(val) {
  // Set Cursor for <body>
  document.body.style.cursor = val;
  // Set Cursor for each of the Nav Buttons, ('childNodes' of DIV: "NavButtons")
  if (val=='default') val='pointer';
  var oDiv = document.getElementById('NavButtons');
  for (var i=0;i<oDiv.childNodes.length;i++) {
    if (oDiv.childNodes[i].id) {
      oDiv.childNodes[i].style.cursor = val;
    }
  }
}

function ShowStatus(message) {
  window.status = message;
}

function DoKeyNav(e) {
  // sw3: this feature is shutdown... (there was code, here!)   
  return true;
}

function GoPage(Direction) {
  // Go to either Next or Previous Page of our site, (as to Nav Button order). 
  // Find where we are, then go up or down depending on 'Direction', (-1 or +1)...
  // Search PageNameArray for 'visDIV', (Current Page Name)
  for (var i=0; i<PageNameArray.length; i++) {
    if (PageNameArray[i] == visDIV) break;
  }
  var GoToPageNum = i + Direction;
  // Wrap around...
  if (GoToPageNum > PageNameArray.length-1) GoToPageNum = 0;
  if (GoToPageNum < 0) GoToPageNum = PageNameArray.length-1;

  // Here we go... (Simulate user click on Nav button)
  mClick(PageNameArray[GoToPageNum]);
}

function SetButtonOpacity(oBtn, opacity) {
  // Nav Buttons have 3 opacity levels:  Normal=Dim, Hover=Medium, Selected=Dark...
  oBtn.style.opacity = (opacity/100);
  oBtn.style.filter='progid:DXImageTransform.Microsoft.Alpha(Opacity=' + opacity + ')';
}

function CrossFade(OldDiv, NewDiv, opacity) {
  // Increment New object's opacity while decrementing the Old's... (Recursively!)
  var oOld = document.getElementById(OldDiv);
  var oNew = document.getElementById(NewDiv);
  // Inverse of opacity for object we're hiding...
  var inv_opacity = 100-opacity;
  if (opacity >= 100) {
    // Visibility of 'old one' must be set, even though its opacity renders it 'invisible'! 
    // (otherwise it may 'catch' MouseOver & Click events meant for the New visible layer)
    oOld.style.visibility = "hidden";
    if (OldDiv != 'home') {
      // Set display to 'none' for all but the 'home' DIV
      oOld.style.display = "none";
    }
    // Set "Busy" flag to false, we are done...
    Busy = false;
    SetCursor('default');
    if (QueueNextButton) {
      var temp = QueueNextButton;
      QueueNextButton = '';
      mClick(temp);
    }
  } else {
    oNew.style.filter='progid:DXImageTransform.Microsoft.Alpha(Opacity=' + opacity + ')';
    oNew.style.opacity=(opacity/100);
    oOld.style.filter='progid:DXImageTransform.Microsoft.Alpha(Opacity=' + inv_opacity + ')';
    oOld.style.opacity=(inv_opacity/100);
    opacity += 5;
    // Call this Function again, recursively, after a slight delay, till done...
    window.setTimeout("CrossFade('"+OldDiv+"','"+NewDiv+"',"+opacity+")", 1);
  }
}

function GetPos(obj) {
  // Return absolute TOP and LEFT of object, in pixels. (traverse obj heirarchy)
  var curtop = curleft = 0;
  if (obj.offsetParent) {
    do {
      curtop += obj.offsetTop;
      curleft += obj.offsetLeft;
    } while (obj = obj.offsetParent);
  }
  return [curtop,curleft];   // Return 2-element Array: [0]=Top, [1]=Left
}

function GetWinSize() {
  winHeight = 0;
  winWidth = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    winHeight = window.innerHeight;
    winWidth = window.innerWidth;
  } else if( document.documentElement && (document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    winHeight = document.documentElement.clientHeight;
    winWidth = document.documentElement.clientWidth;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    winHeight = document.body.clientHeight;
    winWidth = document.body.clientWidth;
  }
}

function FadeCurtain(opacity) {
  if (opacity > 0) {
    if (oCurtain.style.opacity!=null||document.all) {
      oCurtain.style.opacity = (opacity/100)-.001;
      oCurtain.style.filter = "alpha(opacity="+opacity+")";
    } else if (oCurtain.style.MozOpacity!=null) {
      oCurtain.style.MozOpacity = (opacity/100)-.001;
    }
  } else {
    oCurtain.style.display = "none";
    // Show the Supporters iFrame...... WHEN DONE!!!
    document.getElementById('iFSuppporters').style.display='block';
    document.getElementById('footer').style.display='block';
    return;
  }
  opacity -= 5;
  window.setTimeout("FadeCurtain("+opacity+")", 3);
}

function KillScreenSelection() {
  // Users can "Click-Drag" to "Select" screen objects. These selections serve no useful
  // purpose, and are a distraction. If we didn't 'Kill' these selections, they can
  // persist across Sub-Page viewings and make Sub-Pages look silly, at best...
  // This should handle the spectrum of browsers.
  var sel ;
  if(document.selection && document.selection.empty) {
    document.selection.empty() ;
  } else if(window.getSelection) {
    sel=window.getSelection();
    if(sel && sel.removeAllRanges)  {
      sel.removeAllRanges() ; 
    }
  }
}

function ShowBig(Mode) {
  // HIDE or SHOW the Big Pic... (DIV showing Enlargement)
  var OpacityIncrement;
  if (Mode==0) {
    // Get Position of Cav Pt. Pic & put Enlargement ABOVE it
    OpacityIncrement = 10;
    BigPicOpacity = 0;
    // Find where to show the Big Picture and show it there
    var PosArray = GetPos(document.getElementById('CavPt'));
    oBigPic.style.top  = (PosArray[0]-275)+'px';
    oBigPic.style.left = PosArray[1]+'px';
    oBigPic.style.display="block";
  } else {
    OpacityIncrement = -10;
  }
  // Call function to Fade IN/OUT the object

  BigFader(OpacityIncrement);

}

function BigFader(FadeFactor) {
  BigPicOpacity += FadeFactor;
  if (FadeFactor < 0 && BigPicOpacity <= 0) {
    // Kill Object once it's invisible
    oBigPic.style.display="none";
    return;
  } else if (FadeFactor > 0 && BigPicOpacity > 100) {
    // Object is Opaque now...
    return;
  }
  // Apply FadeFactor to Object's Opacity
  oBigPic.style.filter='progid:DXImageTransform.Microsoft.Alpha(Opacity=' + BigPicOpacity + ')';
  oBigPic.style.opacity=(BigPicOpacity/100);

  // Call ourself again recursively on a Timer... 
  window.setTimeout("BigFader("+FadeFactor+")", 1);
}




// ------------------------ FORM HANDLING CODE -------------------------------------
function FormSubmit() {

  // Grab values early...
  oFname = oForm["FirstName"].value;
  oLname = oForm["LastName"].value;
  oEmail = oForm["Email"].value;

  var ValError = "";

  if (oEmail.length > 0) {
    if (!IsEmail(oEmail)) {
      ValError = "Email Address appears to be invalid. ";
    }
  } else {
    ValError = "Email Address is a Required Field. ";
  }
  if (oFname.length == 0 || oLname.length == 0 ) {
    ValError += "First and Last Names are Required Fields...";
  }

  if (ValError.length == 0) {
    // Disable the Button
    oForm['submit'].disabled=true;
    origButtonColor = oForm['submit'].style.color;
    oForm['submit'].style.color='#DCDCDC';
    PostData();
  } else {
    SetMessageText(ValError, "warning");
    // Scroll the "ScrollReg" DIV to TOP where the WARNING IS!!!
    document.getElementById('ScrollReg').scrollTop = 0;
  }
}

function PostData() {
  // Call web service to add this data to the database

  SetMessageText("Processing request, please wait...", "black");
  document.body.style.cursor = 'wait';
  window.status = "Waiting for response from server...";

  // Specify Function Name for Processing Request
  CreateRequestObject('RegFormProcess');

  var QueryString = "";
  if(InDatabase) {
    QueryString = "?DATA_MODE=UPDATE";
  } else {
    QueryString = "?DATA_MODE=INSERT";
  }

  // The URL of our web service, Include QueryString...
  //var url = 'php/RegForm.php' + QueryString;

  var url = 'php/RegForm.php'

  // Construct sPOST string of key/value pairs to POST
  var sPOST = "";
  var FldName = "";
  var FldVal = "";
  // Loop thru the Form 'fields', prepending "&"...
  for (var i=0;i<=oForm.length-1;i++) {
    if (oForm[i].type != 'button') {

      if (oForm[i].type == 'checkbox') {
        sPOST += "&"+oForm[i].name+"="+oForm[i].checked;
      } else if (oForm[i].type == 'radio') {
        if (oForm[i].checked) {
          FldName = oForm[i].name;
          FldVal = oForm[i].value;
          FldVal = encodeURIComponent(FldVal);
          sPOST += "&"+FldName+"="+FldVal;
        }
      } else { 
        if (oForm[i].value.length > 0) {
          FldName = oForm[i].name;
          FldVal = oForm[i].value;
          FldVal = encodeURIComponent(FldVal);
          sPOST += "&"+FldName+"="+FldVal;
        }
      }
    }
  }

  // Set the IsComing Flag
  sPOST += "&IsComing=1";

  // Strip leading "&"...
  sPOST = sPOST.substr(1);

  // Invoke Request Object to call web service
  htmlDoc.open( 'POST', url, true );

  // Set HTTP header information before sending POST string
  htmlDoc.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
  htmlDoc.setRequestHeader("Content-length", sPOST.length);
  htmlDoc.setRequestHeader("Connection", "close");

  // Send POST string to web service
  htmlDoc.send(sPOST);
}

function RegFormProcess() {
  // Called asynchronously by the HttpRequest Object while 
  // it waits for stuff to be returned by the web service.
       
  // Exit function if the Request Object is still busy...
  if ( htmlDoc.readyState != 4 ) return ; 

  // This is the complete RESPONSE from the PHP web service
  var resp = trim(htmlDoc.responseText);

  // Restore default cursor & status text
  document.body.style.cursor = 'default';
  window.status = "Done";



  // Dispose Request Object...
  htmlDoc = null;

  // Scroll the "ScrollReg" DIV to TOP where the Message is...
  document.getElementById('ScrollReg').scrollTop = 0;

  if (resp == "1") {
    SetMessageText("You have been Registered! <br><br> Payment Options: ","normal");


    // Set the PayPal Attendance Option same as the RadioButton
    for (var i = 0;i<oForm['AttendanceOption'].length;i++) {
     if (oForm['AttendanceOption'][i].checked) {
        break;
      }
    }

    // Hide the FORM, Show the PAYMENT DIV

    //document.getElementById("pinput").style.display="none";
    //document.getElementById("PAYMENT").style.display="block";

    document.getElementById("ScrollReg").innerHTML = document.getElementById("PAYMENT").innerHTML;
    document.getElementById('os0').selectedIndex = i;

  } else {
    SetMessageText("Unknown Error! Please check your <br> info and try again.","warning");
    // Restore the Submit Button
    oForm['submit'].disabled=false;
    oForm['submit'].style.color=origButtonColor;
  }

return;



  //sw3 disable database stuff .....................................................
  //var UpdateMode = InDatabase;

  if (resp == "1") {

  //sw3 disable database stuff .....................................................
    // Save Cookies for User
    //createCookie("f",oFname,300);
    //createCookie("l",oLname,300);
    //createCookie("e",oEmail,300);

  //sw3 disable database stuff .....................................................
    // Set Flag that User is in our Database
    //InDatabase = true;

  //sw3 disable database stuff .....................................................
    //oForm['submit'].value = "Update Your Information";
    // Can't Edit Email Address once in the database because we use it for LOOKUP and UPDATE...
    //oForm['Email'].disabled=true;
    //oForm['Email'].title="Please email us if you need to change your Email Address in our Database."
    //oForm['submit'].value = "Update Your Info";

    if (UpdateMode) {
      SetMessageText("You are Registered and your info was updated!","normal");
    } else {
      SetMessageText("You have been Registered!","normal");
    }
  } else {
    SetMessageText(resp,"error");
  }

  // Dispose Request Object...
  htmlDoc = null;

  // Restore the Submit Button
  oForm['submit'].disabled=false;
  oForm['submit'].style.color=origButtonColor;
}

function CreateRequestObject(ProcName) {
  // Instantiate XMLHttpRequest Object
  if (typeof window.ActiveXObject != 'undefined' ) {
    // IE Browser
    htmlDoc = new ActiveXObject("Microsoft.XMLHTTP");
    htmlDoc.onreadystatechange = eval(ProcName) ;
  } else {
    // NON-IE Browsers
    htmlDoc = new XMLHttpRequest();
    htmlDoc.onload = eval(ProcName) ;
  }
}

function IsEmail(sVal) {
  // Test if it looks like an email:
  var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
  if (filter.test(sVal)) {
    return true;
  } else {
    return false;
  }
}

function SetMessageText(msg, status) {
  theMessage = document.getElementById("fMessage");
  if (!status || status=='normal') {
    theMessage.style.color = '#464A35';
  } else if (status=='black') {
    theMessage.style.color = 'black';
  } else if (status=='warning') {
    theMessage.style.color = 'red';
  } else if (status=='done') {
    theMessage.style.color = '#8B008B';
  } else {
    theMessage.style.color = '#E10000';
  }
 
  // Push Message Down a line if there's only one line...
  if (msg.length < 65) {
    // AND MAKE IT BIGGER!          
    theMessage.style.fontSize = "17px";
  } else {
    theMessage.style.fontSize = "12px";
  }

  theMessage.innerHTML = msg ;
}

function CheckLogin() {
  var Message = "";
  var sTemp = "";
  // Check Cookies to see if User has already Registered
  sTemp = readCookie("f");
  if (sTemp == null) sTemp=""
  if (sTemp.length > 0) { 
    oFname = sTemp;
  }
  sTemp = readCookie("l");
  if (sTemp == null) sTemp=""
  if (sTemp.length > 0) { 
    oLname = sTemp;
  }
  sTemp = readCookie("e");
  if (sTemp == null) sTemp=""
  if (sTemp.length > 5) { 
    // This may be a valid email address... Try to find the User in the Database!
    oEmail = sTemp;
    FindUser(oEmail);
  }
}


// Cookie Code
function createCookie(name,value,days) {
  if (days) {
    var date = new Date();
    date.setTime(date.getTime()+(days*24*60*60*1000));
    var expires = "; expires="+date.toGMTString();
  } else var expires = "";
    document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
  var nameEQ = name + "=";
  var ca = document.cookie.split(';');
    for(var i=0;i < ca.length;i++) {
      var c = ca[i];
      while (c.charAt(0)==' ') c = c.substring(1,c.length);
      if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
    }
    return null;
}


function trim(stringToTrim) {
  // Trim leading and trailing 'Space' chars from string
  if (stringToTrim) {
    return stringToTrim.replace(/^\s+|\s+$/g,"");
  } else {
    return "";
  }
}

// ------------------------ END FORM HANDLING CODE ---------------------------------



// FIND USER in Database

function FindUser(Email) {
  // Call web service to add Find this Person in the Database

  //sw3 disable database stuff .....................................................
return;

  SetMessageText("Performing Lookup, please wait...", "black");
  document.body.style.cursor = 'wait';
  window.status = "Waiting for response from server...";

  // Specify Function Name for Processing Request
  CreateRequestObject('FindUserProcess');

  // The URL of our web service
  var url = 'php/RegLookup.php';

  // Construct sPOST string of key/value pairs to POST
  var sPOST = "Email=" + Email;

  // Invoke Request Object to call web service
  htmlDoc.open( 'POST', url, true );

  // Set HTTP header information before sending POST string
  htmlDoc.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
  htmlDoc.setRequestHeader("Content-length", sPOST.length);
  htmlDoc.setRequestHeader("Connection", "close");

  // Send POST string to web service
  htmlDoc.send(sPOST);
}


function FindUserProcess() {
  // Called asynchronously by the HttpRequest Object while 
  // it waits for stuff to be returned by the web service.
       
  // Exit function if the Request Object is still busy...
  if ( htmlDoc.readyState != 4 ) return ; 

  // This is the complete RESPONSE from the PHP web service
  var resp = trim(htmlDoc.responseText);

  // Restore default cursor & status text
  document.body.style.cursor = 'default';
  window.status = "Done";

  var mTemp = "";

  if (resp.indexOf("|") >= 0 ) {
    var ta = resp.split("|");
    if (ta.length>0) {
      InDatabase = true;
      oForm['FirstName'].value = ta[3];
      oForm['LastName'].value = ta[4];
      oForm['Email'].value = ta[5];
      oForm['Organization'].value = ta[6];
      oForm['Title'].value = ta[7];
      oForm['HomePhone'].value = ta[8];
      //oForm['CellPhone'].value = ta[9];
      oForm['StreetAddr1'].value = ta[10];
      oForm['StreetAddr2'].value = ta[11];
      oForm['City'].value = ta[12];
      oForm['State'].value = ta[13];
      oForm['Country'].value = ta[14];
      oForm['PostalCode'].value = ta[15];
      //...//
      oForm['NightsAtCP'].value = ta[26];

      if (ta[18] > 0) {
        oForm['submit'].value = "Update Your Information";
        // Can't Edit Email Address once in the database because we use it for LOOKUP and UPDATE...
        oForm['Email'].disabled=true;
        oForm['Email'].title="Please email us if you need to change your Email Address in our Database."
        var lmsg = "You are already Registered. Please correct any errors and enter missing information, and press the 'Update' button..."
        SetMessageText(lmsg, "normal");
      } else {
        SetMessageText("Please enter your information and press the 'Register' button...", "normal");
      }

      // if (ta[19] > 0) mTemp += " Is a Speaker.";
      // if (ta[20] > 0) mTemp += " Is a Sponsor.";

      if (mTemp != "") {
	SetMessageText(mTemp, "normal");
      }

      // Set the Cookies 
      createCookie("f",oForm['FirstName'].value,300);
      createCookie("l",oForm['LastName'].value,300);
      createCookie("e",oForm['Email'].value,300);
    }
  } else {
     SetMessageText("Email Address not found. Please enter your information and press the 'Register' button...", "normal");
  }

  // Dispose Request Object...
  htmlDoc = null;
}


//------------------------------- Do Lookup From Form

function DoFormLookup() {

  //sw3 disable database stuff .....................................................
  return;

  if(!InDatabase) {
    FindUser(oForm['Email'].value);
  }
}

function FlipCheckboxState(cbName) {
  // Users can click on Checkbox Labels to Toggle them
  var cb = document.getElementById(cbName);
  cb.checked = !cb.checked;
  // Send Focus to the Checkbox in question
  cb.focus();
}

function FlipRB(rbName) {
  // Users can click on RadioButton Labels to Select them, (but not deselect)
  var rb = document.getElementById(rbName);

  if (!rb.checked) {
  rb.checked = !rb.checked;
  }

  // Send Focus to the Radiobutton in question
  rb.focus();
}



