Element.observe(document, 'dom:loaded', initSubscribe);

function initSubscribe() {
  $('hasaccount_yes').observe('click', function(event) {
    showLogin();
  });
  $('hasaccount_no').observe('click', function(event) {
	  showCreateAccount();
  });
  $('login').observe('click', function(event) {	  
    login(Event.findElement(event).up('form'));
    Event.stop(event);
  });
  $('create_account').observe('click', function(event) {
    createAccount(Event.findElement(event).up('form'));
    Event.stop(event);
  });
}

function showLogin() {
  if ($('newaccount_form_wrapper').visible()) {
    $('newaccount_form_wrapper').hide();
    $('login_form_wrapper').show();
  } else if (!$('login_form_wrapper').visible()) {
    $('login_form_wrapper').blindDown({ duration: .6 });
  }
}

function showCreateAccount() {
  if ($('login_form_wrapper').visible()) {
    $('login_form_wrapper').hide();
    $('newaccount_form_wrapper').show();
  } else if (!$('newaccount_form_wrapper').visible()) {
    $('newaccount_form_wrapper').blindDown({ duration: .6 });
  }
}

function loginSuccess() {
  window.location='myaccount.php';
}

function createAccountSuccess() {
  window.location='myaccount.php';
}
  

// function submitform(){
//  var query = Form.serialize($('subscribe_form'));
//  query += '&action=' + method;
//  //$('subscribepage').appendChild(document.createTextNode(query));
//  new Ajax.Request('subscribe_remote.php', {parameters:query,onSuccess:submitform_results});
// }
// 
// function submitform_results(t){
//  //alert(t.responseText);
//  eval("var response = " + t.responseText);
//  if(response.error) {
//    $('errormsg').style.display = 'block';
//    $('errormsg').innerHTML = response.error;
//  }
//  else if(response.success) {
//    if(response.location) window.location.href = response.location;
//    else window.location.href = 'home.php';
//  }
// }

