function swapImage(e, src){
  $(e).src = src;
}

function swapBkgImage(e, src){
  //alert_debug($(e));
  $(e).style.backgroundImage = 'url('+src+')';
  //alert("image swapped :"+$(e).style.backgroundImage+":");
}

function alert_debug(obj)
{
  // debugging function
  
  var str = "";
  for (var prop in obj) {
    str = str + prop + " = " + obj[prop] + ";";
  }
  //if($('debug')){
    //$('debug').innerHTML = str;
  //}else{
    alert("Debug: " + str);
  //}
}

function hide(el){
  el.style.display = "none";
}

function show(el){
  el.style.display = "block";
}

function show_option1(){
  hide($('option2'));
  hide($('option3'));
  hide($('option4'));
  show($('option1'));
}

function show_option2(){
  hide($('option1'));
  hide($('option3'));
  hide($('option4'));
  show($('option2'));
}

function show_option3(){
  hide($('option1'));
  hide($('option2'));
  hide($('option4'));
  show($('option3'));
}

function show_option4(){
  hide($('option1'));
  hide($('option2'));
  hide($('option3'));
  show($('option4'));
}



function show_answering_service_form()
{
  try {
    Element.show("answering_service_form");
    Element.hide("faxing_form");
    Element.hide("simple_form");
  }
  catch (e)
  {
    //alert('RJS error:\n\n' + e.toString()); alert('Element.show(\"new_form\");\nElement.hide(\"churn_form\");');
    throw e
  }
}

function show_simple_form()
{
  try {
    Element.show("simple_form");
    Element.hide("answering_service_form");
    Element.hide("faxing_form");
  }
  catch (e)
  {
    //alert('RJS error:\n\n' + e.toString()); alert('Element.show(\"new_form\");\nElement.hide(\"churn_form\");');
    throw e
  }
}

function show_faxing_form()
{
  try {
    Element.show("faxing_form");
    Element.hide("answering_service_form");
    Element.hide("simple_form");
  }
  catch (e)
  {
    //alert('RJS error:\n\n' + e.toString()); alert('Element.show(\"new_form\");\nElement.hide(\"churn_form\");');
    throw e
  }
}


function select_answer_point_type(type, value){

  document.getElementById('answer_point_type').value = type

  if( type == 'national'){
    Element.show("national_answer_point");
    Element.hide("mobile_answer_point");
    Element.hide("international_answer_point");
    if(value != '' && value != null){
      //alert(value);
      document.getElementById('area_code').value = value.substring(0,2);
      document.getElementById('inbound_numbers_national_answer_point').value = value.substring(2,10);
    }
    if(value == null){
      document.getElementById('inbound_numbers_national_answer_point').value = '';
    }
  }
  else if( type == 'mobile'){
    Element.hide("national_answer_point");
    Element.show("mobile_answer_point");
    Element.hide("international_answer_point");

    if(value != ''){
      document.getElementById('inbound_numbers_mobile_answer_point').value = value;
    }
    if(value == null){
      document.getElementById('inbound_numbers_mobile_answer_point').value = '04';
    }
  }
  else if( type == 'international'){
    Element.hide("national_answer_point");
    Element.hide("mobile_answer_point");
    Element.show("international_answer_point");
    if(value != ''){
      document.getElementById('inbound_numbers_int_answer_point').value = value;
    }
    if(value == null){
      document.getElementById('inbound_numbers_int_answer_point').value = '0011';
    }
  }
  else {
    Element.hide("national_answer_point");
    Element.hide("mobile_answer_point");
    Element.hide("international_answer_point");
  }

}


function select_answer_point_type_lo(type, value){
  //alert(type+":"+value);
  document.getElementById('answer_point_type_lo').value = type

  if( type == 'national'){
    Element.show("national_answer_point_lo");
    Element.hide("mobile_answer_point_lo");
    Element.hide("international_answer_point_lo");
    if(value != '' && value != null){
      // break it apart
      document.getElementById('area_code_la').value = value.substring(0,2);
      document.getElementById('inbound_numbers_national_answer_point_la').value = value.substring(2,10);
    }
    if(value == null){
      document.getElementById('inbound_numbers_national_answer_point_la').value = '';
    }
  }
  else if( type == 'mobile'){
    Element.hide("national_answer_point_lo");
    Element.show("mobile_answer_point_lo");
    Element.hide("international_answer_point_lo");
    if(value != ''){
      document.getElementById('inbound_numbers_mobile_answer_point_la').value = value;
    }
    if(value == null){
      document.getElementById('inbound_numbers_mobile_answer_point_la').value = '04';
    }
  }
  else if( type == 'international'){
    Element.hide("national_answer_point_lo");
    Element.hide("mobile_answer_point_lo");
    Element.show("international_answer_point_lo");
    if(value != ''){
      document.getElementById('inbound_numbers_int_answer_point_la').value = value;
    }
    if(value == null){
      document.getElementById('inbound_numbers_int_answer_point_la').value = '0011';
    }
  }
  else {
    Element.hide("national_answer_point_lo");
    Element.hide("mobile_answer_point_lo");
    Element.hide("international_answer_point_lo");
  }
}

function hide_existing_login()
{
  Element.hide("existing_customer_login");
  Element.show("signup");
}

function show_existing_login()
{
  Element.show("existing_customer_login");
  Element.hide("signup");
}


function hide_dd_form()
{
  try {
    Element.show("credit_card_form");
    Element.hide("direct_debit_form");
  }
  catch (e)
  {
    alert('RJS error:\n\n' + e.toString()); alert('Element.show(\"credit_card_form\");\nElement.hide(\"direct_debit_form\");');
    throw e
  }

}

function hide_cc_form()
{
  try {
    Element.hide("credit_card_form");
    Element.show("direct_debit_form");
  }
  catch (e)
  {
    alert('RJS error:\n\n' + e.toString()); alert('Element.hide(\"credit_card_form\");\nElement.show(\"direct_debit_form\");');
    throw e
  }
}

