var bitrate, viewers, hd, error, pattern_username, pattern_email, pattern_publisher_point;

function switch_maximum_bitrate() {
  if (document.paypal_form.server_type[0].checked) {
    document.paypal_form.maximum_bitrate.options[3].value = "56";
    document.paypal_form.maximum_bitrate.options[3].text = "56 kbps";
    document.paypal_form.maximum_bitrate.options[4].value = "64";
    document.paypal_form.maximum_bitrate.options[4].text = "64 kbps";
    document.paypal_form.maximum_bitrate.options[9].value = "248";
    document.paypal_form.maximum_bitrate.options[9].text = "248 kbps";
  } else {
    document.paypal_form.maximum_bitrate.options[3].value = "64";
    document.paypal_form.maximum_bitrate.options[3].text = "64 kbps";
    document.paypal_form.maximum_bitrate.options[4].value = "80";
    document.paypal_form.maximum_bitrate.options[4].text = "80 kbps";
    document.paypal_form.maximum_bitrate.options[9].value = "256";
    document.paypal_form.maximum_bitrate.options[9].text = "256 kbps";
  }
}

function ExpandSection(idVariable)
{

if (idVariable.style.display=="none")
	idVariable.style.display="" ;
}

function ContractSection(idVariable){
if (idVariable.style.display==""){idVariable.style.display="none"}
}

function CheckType(IsLive)
{

 if(IsLive)
 {
  ExpandSection(sLive);
  ContractSection(sOnDemand);
 }
 else
 {
  ContractSection(sLive);
  ExpandSection(sOnDemand);
 }
}

function calculate_price() {
  bitrate = document.paypal_form.maximum_bitrate.value;
  viewers = document.paypal_form.maximum_concurrent_viewers.value;
  hd = document.paypal_form.diskquota.value;

  document.getElementById("total_monthly_cost").value = + shoutcast_price[bitrate][viewers] + diskquota[hd] + "0";
}

function showInfo()
{
var UH_acceptUHtos = document.getElementById('acceptUHtos'); 
var UH_acceptUHtos2 = document.getElementById('acceptUHtos2'); 
if(document.forms[0].accepttos.value == "NO" )
{
UH_acceptUHtos.style.display="inline";
UH_acceptUHtos2.style.display="none"; 
} else {  
UH_acceptUHtos2.style.display="inline";
UH_acceptUHtos.style.display="none";  
}
}
      

function switch_mode() {
  if (document.paypal_form.mode[0].checked) {
    document.getElementById("pull_mode_options").style.display = "none";
  } else {
    document.getElementById("pull_mode_options").style.display = "block";
  }
}

function check_form(form) {
  error = "";
  pattern_name = new RegExp("^[a-zA-Z0-9\-\._ ]{3,50}$");
  pattern_email = new RegExp("^[a-z0-9\-\._]+@[a-z0-9\-\.]+[\.][a-z]{2,}$");
  pattern_publisher_point = new RegExp("^[a-zA-Z0-9\-\._]{3,12}$");
  if (form == "1") {
    if (!document.paypal_form.terms_of_use.checked) { error += "\n- Accepting the Terms Of Use & Privacy Policy;"; }
    if (error != "") { alert("To continue, you have to do:" + error); return false; }
  }
  if (form == "2") {
    if (document.paypal_form.name.value == "") {error += "\n- Il tuo \Nome e Cognome\ "; }
    if (document.paypal_form.station_name.value == "") { error += "\n- Il nome della \Stazione Radio\ ";

    } else {
      if (!pattern_name.test(document.paypal_form.name.value)) { error += "\n- Filling the \"Username\" field with an username containing 3 to 8 characters;"; }
    }
    if (document.paypal_form.email.value == "") {
      error += "\n- L'indirizzo \E-mail\ ";
    } else {
      if (!pattern_email.test(document.paypal_form.email.value)) { error += "\n- L'indirizzo \E-mail\ ha un formato non valido "; }
    }
    if (document.paypal_form.email_confirm.value != document.paypal_form.email.value) { error += "\n- L'indirizzo \E-mail\ di conferma e' Errato "; }
    if (error != "") { alert("Per continuare devi inserire:" + error); return false; }
  }
  if (form == "2") {
    if (document.paypal_form.station_name.value == "") { error += "\n- Filling the \"Station name\" field;"; }
    if (document.paypal_form.name.value == "") {
      error += "\n- Filling the \"Username\" field;";
    } else {
      if (!pattern_name.test(document.paypal_form.name.value)) { error += "\n- Filling the \"Username\" field with an username containing 3 to 8 characters;"; }
    }
    if (document.paypal_form.email.value == "") {
      error += "\n- Filling the \"E-mail\" field;";
    } else {
      if (!pattern_email.test(document.paypal_form.email.value)) { error += "\n- Filling the \"E-mail\" field with a valid e-mail"; }
    }
    if (document.paypal_form.email_confirm.value != document.paypal_form.email.value) { error += "\n- Filling the \"E-mail (confirm)\" field with the same e-mail in the \"E-mail\" field;"; }
    if (document.paypal_form.publisher_point.value == "") {
      error += "\n- Filling the \"Publisher point\" field;";
    } else {
      if (!pattern_publisher_point.test(document.paypal_form.publisher_point.value)) { error += "\n- Filling the \"Publisher point\" field with a name containing 3 to 12 characters;"; }    
    }
    if (document.paypal_form.mode[1].checked) {
      if (document.paypal_form.ip_address.value == "") { error += "\n- Filling the \"IP address\" field;"; }
      if (document.paypal_form.streaming_port.value == "") { error += "\n- Filling the \"Streaming port\" field;"; }
    }
    if (error != "") { alert("Per continuare devi inserire:" + error); return false; }
  }
}



