function swapImage(e, src){
  get_id(e).src = src;
}

function swapBkgImage(e, src){
  //alert_debug(get_id(e));
  get_id(e).style.backgroundImage = 'url('+src+')';
  //alert("image swapped :"+get_id(e).style.backgroundImage+":");
}

function alert_debug(obj)
{
  // debugging function
  
  var str = "";
  for (var prop in obj) {
    str = str + prop + " = " + obj[prop] + ";";
  }
  //if(get_id('debug')){
    //get_id('debug').innerHTML = str;
  //}else{
    alert("Debug: " + str);
  //}
}

function my_hide(el){
  el.style.display = "none";
}

function my_show(el){
  el.style.display = "block";
}

function get_id(str){
  return document.getElementById(str);
}

function show_option1(){
  my_hide(get_id('option2'));
  my_hide(get_id('option3'));
  my_hide(get_id('option4'));
  my_show(get_id('option1'));
}

function show_option2(){
  my_hide(get_id('option1'));
  my_hide(get_id('option3'));
  my_hide(get_id('option4'));
  my_show(get_id('option2'));
}

function show_option3(){
  my_hide(get_id('option1'));
  my_hide(get_id('option2'));
  my_hide(get_id('option4'));
  my_show(get_id('option3'));
}

function show_option4(){
  my_hide(get_id('option1'));
  my_hide(get_id('option2'));
  my_hide(get_id('option3'));
  my_show(get_id('option4'));
}



function show_answering_service_form()
{
  try {
    my_show(get_id("answering_service_form"));
    my_hide(get_id("faxing_form"));
    my_hide(get_id("simple_form"));
  }
  catch (e)
  {
    //alert('RJS error:\n\n' + e.toString()); alert('my_show(\"new_form\");\nny_hide(\"churn_form\");');
    throw e
  }
}

function show_simple_form(){
  try {
    my_show(get_id("simple_form"));
    my_hide(get_id("answering_service_form"));
    my_hide(get_id("faxing_form"));
  }
  catch (e)
  {
    //alert('RJS error:\n\n' + e.toString()); alert('my_show(\"new_form\");\nny_hide(\"churn_form\");');
    throw e
  }
}

function show_faxing_form()
{
  try {
    my_show(get_id("faxing_form"));
    my_hide(get_id("answering_service_form"));
    my_hide(get_id("simple_form"));
  }
  catch (e)
  {
    //alert('RJS error:\n\n' + e.toString()); alert('my_show(\"new_form\");\nny_hide(\"churn_form\");');
    throw e
  }
}


function select_answer_point_type(type, value){

  document.getElementById('answer_point_type').value = type

  if( type == 'national'){
    my_show(get_id("national_answer_point"));
    my_hide(get_id("mobile_answer_point"));
    my_hide(get_id("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'){
    my_hide(get_id("national_answer_point"));
    my_show(get_id("mobile_answer_point"));
    my_hide(get_id("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'){
    my_hide(get_id("national_answer_point"));
    my_hide(get_id("mobile_answer_point"));
    my_show(get_id("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 {
    my_hide(get_id("national_answer_point"));
    my_hide(get_id("mobile_answer_point"));
    my_hide(get_id("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'){
    my_show(get_id("national_answer_point_lo"));
    my_hide(get_id("mobile_answer_point_lo"));
    my_hide(get_id("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'){
    my_hide(get_id("national_answer_point_lo"));
    my_show(get_id("mobile_answer_point_lo"));
    my_hide(get_id("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'){
    my_hide(get_id("national_answer_point_lo"));
    my_hide(get_id("mobile_answer_point_lo"));
    my_show(get_id("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 {
    my_hide(get_id("national_answer_point_lo"));
    my_hide(get_id("mobile_answer_point_lo"));
    my_hide(get_id("international_answer_point_lo"));
  }
}

function hide_existing_login()
{
  my_hide(get_id("existing_customer_login"));
  my_show(get_id("signup"));
}

function show_existing_login()
{
  my_show(get_id("existing_customer_login"));
  my_hide(get_id("signup"));
}


function hide_dd_form()
{
  try {
    my_show(get_id("credit_card_form"));
    my_hide(get_id("direct_debit_form"));
  }
  catch (e)
  {
    alert('RJS error:\n\n' + e.toString()); alert('my_show(\"credit_card_form\");\nny_hide(\"direct_debit_form\");');
    throw e
  }

}

function hide_cc_form()
{
  try {
    my_hide(get_id("credit_card_form"));
    my_show(get_id("direct_debit_form"));
  }
  catch (e)
  {
    alert('RJS error:\n\n' + e.toString()); alert('ny_hide(\"credit_card_form\");\nmy_show(\"direct_debit_form\");');
    throw e
  }
}



function handle_dest_num_menu(obj){
  var type = obj.options[obj.selectedIndex].value;

  if( type == 'national'){
    document.getElementById('national_answer_point').style.display = '';
    document.getElementById('mobile_answer_point').style.display = 'none';
    document.getElementById('international_answer_point').style.display = 'none';
  }
  else if( type == 'mobile'){
    document.getElementById('national_answer_point').style.display = 'none';
    document.getElementById('mobile_answer_point').style.display = '';
    document.getElementById('international_answer_point').style.display = 'none';
  }
  else if( type == 'international'){
    document.getElementById('national_answer_point').style.display = 'none';
    document.getElementById('mobile_answer_point').style.display = 'none';
    document.getElementById('international_answer_point').style.display = '';
  }
  else {
    document.getElementById('national_answer_point').style.display = 'none';
    document.getElementById('mobile_answer_point').style.display = 'none';
    document.getElementById('international_answer_point').style.display = 'none';
  }
}


function handle_dest_num_menu_la(obj){
  var type = obj.options[obj.selectedIndex].value;

  if( type == 'national'){
    document.getElementById('national_answer_point_lo').style.display = '';
    document.getElementById('mobile_answer_point_lo').style.display = 'none';
    document.getElementById('international_answer_point_lo').style.display = 'none';
  }
  else if( type == 'mobile'){
    document.getElementById('national_answer_point_lo').style.display = 'none';
    document.getElementById('mobile_answer_point_lo').style.display = '';
    document.getElementById('international_answer_point_lo').style.display = 'none';
  }
  else if( type == 'international'){
    document.getElementById('national_answer_point_lo').style.display = 'none';
    document.getElementById('mobile_answer_point_lo').style.display = 'none';
    document.getElementById('international_answer_point_lo').style.display = '';
  }
  else {
    document.getElementById('national_answer_point_lo').style.display = 'none';
    document.getElementById('mobile_answer_point_lo').style.display = 'none';
    document.getElementById('international_answer_point_lo').style.display = 'none';
  }
}


function show_click_to_call(){

  var screen = document.getElementById('clicktocall');
  if (screen.style.zIndex != "90000")
  {
  screen.style.position = "fixed";
  screen.style.zIndex   = "90000";
  screen.style.top      = "70px";
  
  screen.style.left     = ((document.body.offsetWidth/2)-175) + "px";
  }

  var blocker = document.getElementById( "blocker" );
  blocker.style.filter = "alpha(opacity=90)";
  blocker.style.MozOpacity = ".9";
  blocker.style.opacity = ".9";
  blocker.style.width   = "100%";
  //blocker.style.height  = "100%"; // not enough ..
  
  blocker.style.height  = document.getElementById('body_table').offsetHeight + "px";
  blocker.style.overflow= "hidden";
  blocker.style.left    = "0px";
  blocker.style.top     = "0px";
  blocker.style.position= "absolute";
  blocker.style.zIndex  = "89999"; //phew, just under 9000 ;)
  blocker.style.backgroundColor = "#EBECFF";
  
  my_show( blocker );
  my_show( screen );
}

function hide_click_to_call(){
  my_hide( document.getElementById( "blocker" ) );
  my_hide( document.getElementById( "clicktocall" ) );
}

