/*
** (C)Copyright Internet Intuitive - a division of ADB Internet Services Limited
**
** All code (including but not limited to HTML, JavaScript and PHP) and images
** (C)Copyright 2001-2003 ADB Internet Services Limited - all rights reserved.
**
** Filename: mod_myaccount.js
** Version:  V1.00.a
** Date:     29-Jun-2004
*/

function MA_Form_Validate_Add(theForm)
{
  /*
  ** Validate Domain Name
  */
  if ( ( theForm.domainname.value == "--- please specify ---" )
    || ( theForm.domainname.value == "" ) )
  {
    alert("Please specify the domain name");
    theForm.domainname.focus();
    return (false);
  }

  /*
  ** Only check registrant and DNS if registering new
  ** ... domain "register" is first option (index 0)
  */
  if ( theForm.addaction[0].checked )
  {
    /*
    ** Validate Registrant
    */
    if ( MA_Form_Validate_Registrant(theForm) == false )
	{
	  return( false );
	}

    /*
	** Validate DNS
	*/
    if ( MA_Form_Validate_NS(theForm) == false )
	{
	  return( false );
	}
  }

  /*
  ** Got here... fields must be OK
  */
  return( true );
}

function Form_Change_AddDomainType( theSelection )
{
  /*
  ** Get current Contact_Type selection
  */
  add_type_selection = theSelection.value;

  if ( add_type_selection == "register"  )
  {
    theSelection.form.registrant.disabled		= false;
    theSelection.form.reg_type.disabled			= false;
    theSelection.form.reg_number.disabled		= false;
    theSelection.form.reg_tradingname.disabled	= false;
    theSelection.form.reg_contact.disabled		= false;
    theSelection.form.reg_address1.disabled		= false;
    theSelection.form.reg_address2.disabled		= false;
    theSelection.form.reg_town_city.disabled	= false;
    theSelection.form.reg_county.disabled		= false;
    theSelection.form.reg_postcode.disabled		= false;
    theSelection.form.reg_country.disabled		= false;

    theSelection.form.dns0.disabled				= false;
    theSelection.form.dns1.disabled				= false;
    theSelection.form.dns2.disabled				= false;
    theSelection.form.dns3.disabled				= false;

//    theSelection.form.dns0.value    = "--- please specify ---";
//    theSelection.form.dns1.value    = "--- please specify ---";
//    theSelection.form.dns2.value    = "--- optional ---";
//    theSelection.form.dns3.value    = "--- optional ---";
  }

  if ( add_type_selection == "add"  )
  {
    theSelection.form.registrant.disabled		= true;
    theSelection.form.reg_type.disabled			= true;
    theSelection.form.reg_number.disabled		= true;
    theSelection.form.reg_tradingname.disabled	= true;
    theSelection.form.reg_contact.disabled		= true;
    theSelection.form.reg_address1.disabled		= true;
    theSelection.form.reg_address2.disabled		= true;
    theSelection.form.reg_town_city.disabled	= true;
    theSelection.form.reg_county.disabled		= true;
    theSelection.form.reg_postcode.disabled		= true;
    theSelection.form.reg_country.disabled		= true;

    theSelection.form.dns0.disabled				= true;
    theSelection.form.dns1.disabled				= true;
    theSelection.form.dns2.disabled				= true;
    theSelection.form.dns3.disabled				= true;

//    theSelection.form.dns0.value    = "n/a";
//    theSelection.form.dns1.value    = "n/a";
//    theSelection.form.dns2.value    = "n/a";
//    theSelection.form.dns3.value    = "n/a";
  }

}


function MA_Form_Validate_RenewDomain(theForm)
{
  /*
  ** Validate renewal period
  */
  renewal_period_selection = theForm.period.options[theForm.period.selectedIndex].value;
  if ( renewal_period_selection == "0" )
  {
    alert("Please specify the renewal period!");
    theForm.period.focus();
    return (false);
  }

  /*
  ** Got here... must be OK
  */
  return (true);
}


function MA_Form_Validate_RenewHosting(theForm)
{
  /*
  ** Got here... must be OK
  */
  return (true);
}


function MA_Form_Validate_NS(theForm)
{
  /*
  ** Validate DNS servers
  */
  if ( ( theForm.dns0.value == "--- please specify ---" )
    || ( theForm.dns0.value == "" ) )
  {
    alert("Please specify the primary nameserver");
    theForm.dns0.focus();
    return (false);
  }

  if ( ( theForm.dns1.value == "--- please specify ---" )
    || ( theForm.dns1.value == "" ) )
  {
    alert("Please specify at least one secondary nameserver");
    theForm.dns1.focus();
    return (false);
  }

  if ( theForm.dns1.value == theForm.dns0.value )
  {
    alert("DNS1 is not unique");
    theForm.dns1.focus();
    return (false);
  }

  if ( ( theForm.dns2.value == "" )
    || ( theForm.dns2.value == "--- optional ---" ) )
  {
    /*
    ** Remove "optional" prompt
    */
    theForm.dns2.value = "n/a";
  }
  else if ( theForm.dns2.value == "n/a" )
  {
    /*
    ** Don't validate
    */
  }
  else if ( ( theForm.dns2.value == theForm.dns0.value )
         || ( theForm.dns2.value == theForm.dns1.value ) )
  {
    alert("DNS2 is not unique");
    theForm.dns2.focus();
    return (false);
  }

  if ( ( theForm.dns3.value == "" )
    || ( theForm.dns3.value == "--- optional ---" ) )
  {
    /*
    ** Remove "optional" prompts
    */
    theForm.dns3.value = "n/a";
  }
  if ( theForm.dns3.value == "n/a" )
  {
    /*
    ** Don't validate
    */
  }
  else if ( ( theForm.dns3.value == theForm.dns0.value )
         || ( theForm.dns3.value == theForm.dns1.value )
         || ( theForm.dns3.value == theForm.dns2.value ) )
  {
    alert("DNS3 is not unique");
    theForm.dns3.focus();
    return (false);
  }


  /*
  ** Got here... must be OK
  */
  return (true);
}


function MA_Form_Validate_Registrant(theForm)
{
  /*
  ** Get current Contact_Type selection
  */
  reg_type_selection = theForm.reg_type.options[theForm.reg_type.selectedIndex].value;

  if ( reg_type_selection == "" )
  {
    alert("Please select registrant type!");
    theForm.reg_type.focus();
    return (false);
  }

  if ( ( theForm.reg_number.value == "--- please specify ---" )
    || ( theForm.reg_number.value == "" ) )
  {
    alert("Please specify the registrant's registration number");
    theForm.reg_number.focus();
    return (false);
  }
  
  /*
  ** Validate contact details
  */
  if ( ( theForm.reg_contact.value == "--- please specify ---" )
    || ( theForm.reg_contact.value == "" ) )
  {
    alert("Please specify the registrant's contact name");
    theForm.reg_contact.focus();
    return (false);
  }

  if ( ( theForm.reg_email.value == "--- please specify ---" )
    || ( theForm.reg_email.value == "" ) )
  {
    alert("Please specify the registrant's email address");
    theForm.reg_email.focus();
    return (false);
  }

  if ( ( theForm.reg_address1.value == "--- please specify ---" )
    || ( theForm.reg_address1.value == "" ) )
  {
    alert("Please specify the registrant's address");
    theForm.reg_address1.focus();
    return (false);
  }

  if ( ( theForm.reg_town_city.value == "--- please specify ---" )
    || ( theForm.reg_town_city.value == "" ) )
  {
    alert("Please specify the registrant's town/city");
    theForm.reg_town_city.focus();
    return (false);
  }

  if ( ( theForm.reg_county.value == "--- please specify ---" )
    || ( theForm.reg_county.value == "" ) )
  {
    alert("Please specify the registrant's county");
    theForm.reg_county.focus();
    return (false);
  }

  if ( ( theForm.reg_postcode.value == "--- please specify ---" )
    || ( theForm.reg_postcode.value == "" ) )
  {
    alert("Please specify the registrant's postcode");
    theForm.reg_county.focus();
    return (false);
  }

  /*
  ** Got here... must be OK
  **
  ** ... remove "optional" prompts
  */
  if (                                             theForm.reg_address2.value    == "--- optional ---" )   { theForm.reg_address2.value    = "";    }
  if ( ( theForm.reg_tradingname.value == "" ) | ( theForm.reg_tradingname.value == "--- optional ---" ) ) { theForm.reg_tradingname.value = "n/a"; }

  return (true);
}


function Form_Change_RegType(theSelection)
{
  /*
  ** Get current Contact_Type selection
  */
  reg_type_selection = theSelection.options[theSelection.selectedIndex].value;

  if ( ( reg_type_selection == "IND"  )
	|| ( reg_type_selection == "FIND" ) )
  {
    theSelection.form.reg_tradingname.disabled = true;
    theSelection.form.reg_tradingname.value    = "n/a";
    theSelection.form.reg_number.disabled      = true;
    theSelection.form.reg_number.value         = "n/a";
  }
  
  if ( ( reg_type_selection == "LLP"   )
	|| ( reg_type_selection == "LTD"   )
	|| ( reg_type_selection == "PLC"   )
	|| ( reg_type_selection == "RCHAR" ) )
  {
    theSelection.form.reg_tradingname.disabled = false;
    theSelection.form.reg_tradingname.value    = "--- optional ---";
    theSelection.form.reg_number.disabled      = false;
    theSelection.form.reg_number.value         = "--- please specify ---";
  }
  
  if ( ( reg_type_selection == "STRA"   )
	|| ( reg_type_selection == "PTNR"   )
	|| ( reg_type_selection == "OTHER"  )
	|| ( reg_type_selection == "FCORP"  )
	|| ( reg_type_selection == "FOTHER" ) )
  {
    theSelection.form.reg_tradingname.disabled = false;
    theSelection.form.reg_tradingname.value    = "--- optional ---";
    theSelection.form.reg_number.disabled      = false;
    theSelection.form.reg_number.value         = "n/a";
  }
}


function MA_Form_Validate_DNSzone(theForm)
{
  /*
  ** Get current Contact_Type selection
  */
  dns_type_selection = theForm.dns_type.options[theForm.dns_type.selectedIndex].value;
  dns_prio_selection = theForm.dns_prio.options[theForm.dns_prio.selectedIndex].value;

  if ( dns_type_selection == "none" )
  {
    alert("Please select DNS zone type!");
    theForm.dns_type.focus();
    return (false);
  }

  if ( theForm.dns_ip.value == "" )
  {
    alert("Please specify the DNS zone address");
    theForm.dns_ip.focus();
    return (false);
  }

  if ( ( dns_type_selection == "mx" )
    && ( dns_prio_selection == "0"  ) )
  {
    alert("Please select MX record priority!");
    theForm.dns_prio.focus();
    return (false);
  }

  /*
  ** Got here... must be OK
  */
  return (true);
}

function Form_Change_DnsType(theSelection)
{
  /*
  ** Get current Contact_Type selection
  */
  dns_type_selection = theSelection.options[theSelection.selectedIndex].value;

  if ( dns_type_selection == "" )
  {
      theSelection.form.dns_type.value = "none";
  }

  if ( ( dns_type_selection == "none"  )
    || ( dns_type_selection == "a"     )
    || ( dns_type_selection == "cname" )
    || ( dns_type_selection == "txt"   ) )
  {
    theSelection.form.dns_prio.disabled = true;
    theSelection.form.dns_prio.value    = "0";
  }

  if ( ( dns_type_selection == "mx"    ) )
  {
    theSelection.form.dns_prio.disabled = false;
    theSelection.form.dns_prio.value    = "0";
  }
}



