function CalculateMLBParlay(form)
{
  if (ValidateAllFields(form.TeamPrice1) && ValidateAllFields(form.TeamPrice2) && ValidateAllFields(form.TeamPrice3) && ValidateAllFields(form.TeamPrice4) && ValidateAllFields(form.TeamPrice5) && ValidateAllFields(form.TeamPrice6) && ValidateAllFields(form.TeamPrice7) && ValidateAllFields(form.TeamPrice8) && ValidateAllFields(form.TeamPrice9) && ValidateAllFields(form.TeamPrice10) && ValidateAllFields(form.BetUnits))
  {
    TP1 = parseFloat(form.TeamPrice1.value);
    TP2 = parseFloat(form.TeamPrice2.value);
    TP3 = parseFloat(form.TeamPrice3.value);
    TP4 = parseFloat(form.TeamPrice4.value);
    TP5 = parseFloat(form.TeamPrice5.value);
    TP6 = parseFloat(form.TeamPrice6.value);
    TP7 = parseFloat(form.TeamPrice7.value);
    TP8 = parseFloat(form.TeamPrice8.value);
    TP9 = parseFloat(form.TeamPrice9.value);
    TP10 = parseFloat(form.TeamPrice10.value);

    BetUnits = parseFloat(form.BetUnits.value);
    ParlayPayout = parseFloat(form.ParlayPayout.value);

    if (TP1 < 0)	{	PF1 = (-TP1 + 100) / -TP1;	}
    else if (TP1 > 0)	{	PF1 = (TP1 + 100) / 100;	}
    else PF1 = 1;

    if (TP2 < 0)	{	PF2 = (-TP2 + 100) / -TP2;	}
    else if (TP2 > 0)	{	PF2 = (TP2 + 100) / 100;	}
    else PF2 = 1;

    if (TP3 < 0)	{	PF3 = (-TP3 + 100) / -TP3;	}
    else if (TP3 > 0)	{	PF3 = (TP3 + 100) / 100;	}
    else PF3 = 1;

    if (TP4 < 0)	{	PF4 = (-TP4 + 100) / -TP4;	}
    else if (TP4 > 0) {	PF4 = (TP4 + 100) / 100;	}
    else PF4 = 1;

    if (TP5 < 0)	{	PF5 = (-TP5 + 100) / -TP5;	}
    else if (TP5 > 0) {	PF5 = (TP5 + 100) / 100;	}
    else PF5 = 1;

    if (TP6 < 0)	{	PF6 = (-TP6 + 100) / -TP6;	}
    else if (TP6 > 0) {	PF6 = (TP6 + 100) / 100;	}
    else PF6 = 1;

    if (TP7 < 0)	{	PF7 = (-TP7 + 100) / -TP7;	}
    else if (TP7 > 0) {	PF7 = (TP7 + 100) / 100;	}
    else PF7 = 1;

    if (TP8 < 0)	{	PF8 = (-TP8 + 100) / -TP8;	}
    else if (TP8 > 0) {	PF8 = (TP8 + 100) / 100;	}
    else PF8 = 1;

    if (TP9 < 0)	{	PF9 = (-TP9 + 100) / -TP9;	}
    else if (TP9 > 0) {	PF9 = (TP9 + 100) / 100;	}
    else PF9 = 1;

    if (TP10 < 0)	{	PF10 = (-TP10 + 100) / -TP10;	}
    else if (TP10 > 0){	PF10 = (TP10 + 100) / 100;	}
    else PF10 = 1;

    ParlayPayout = ((PF1 * PF2 * PF3 * PF4 * PF5 * PF6 * PF7 * PF8 * PF9 * PF10) - 1) * BetUnits;

    form.ParlayPayout.value = ParlayPayout;
  }
  else form.ParlayPayout.value = '';
}

function ValidateAllFields(field)
{
  flag = 0;
  var str = field.value;

  for (i = 0; i < str.length; i++)
  {
    var chr = str.substring(i, i+1);
    if (((chr < "0") || (chr > "9")) && (chr != ".") && (chr != "-") && (chr != "+"))
    flag = 1;
  }

  if ((flag == 1) || (str.length == 0))
  {
    alert("You have typed an invalid character.\nPlease type numerical values only.");
    return false;
  }
  else return true;
}

function ResetAllValues(form)
{
  form.TeamPrice1.value = "0";
  form.TeamPrice2.value = "0";
  form.TeamPrice3.value = "0";
  form.TeamPrice4.value = "0";
  form.TeamPrice5.value = "0";
  form.TeamPrice6.value = "0";
  form.TeamPrice7.value = "0";
  form.TeamPrice8.value = "0";
  form.TeamPrice9.value = "0";
  form.TeamPrice10.value = "0";

  form.BetUnits.value = "1";
  form.ParlayPayout.value = "0";
}

var contador = 2;

function add_destiny()
{
	document.getElementById("destino"+contador).style.display = "block";
	contador++;
	if(contador>5)
		document.getElementById("addDestiny").style.display = "none";
}



function validacion_enlace(webId) 
{

  var caja = document.getElementById("validacion"+webId);


  var peticion_http = null;
  // Obtener la instancia del objeto XMLHttpRequest
  if(window.XMLHttpRequest) {
    peticion_http = new XMLHttpRequest();
  }
  else if(window.ActiveXObject) {
    peticion_http = new ActiveXObject("Microsoft.XMLHTTP");
  }
 
  // Preparar la funcion de respuesta
  peticion_http.onreadystatechange = muestraContenido;
 
  // Realizar peticion HTTP
  peticion_http.open('GET', 'validacion.php?id='+webId, true);
  peticion_http.send(null);
 
  function muestraContenido() 
  {
  
    if(peticion_http.readyState == 1)
    {
        caja.innerHTML="<center><img width='70' src='imagenes/loading.gif' alt='cargando...' /></center>";
		
    }
	
    if(peticion_http.readyState == 4) 
    {
      if(peticion_http.status == 200) 
     {


        if(peticion_http.responseText == 1)
        {

           
			caja.innerHTML= "<b>El enlace ha sido validado. La web tiene nuestro banner insertado. <a  style='color:blue;text-decoration:none' href='administracion_enlaces.html' title='Recargar datos'>Recargar esta página</a> para ver los datos actualizados.</b>";


        }
        else if(peticion_http.responseText == 2)
        {

			caja.innerHTML= "<b>Problemas de conexión con la web de destino, puede que esté mal escrita o que tenga restricción de acceso. <a  style='color:blue;text-decoration:none' href='administracion_enlaces.html' title='Recargar datos'>Recargar esta página</a> para ver los datos actualizados.</b>";

        }
        else if(peticion_http.responseText == 3)
        {

			caja.innerHTML= "<b>El banner está actualmente forzado, cambie el estado para poder comprobarlo. <a  style='color:blue;text-decoration:none' href='administracion_enlaces.html' title='Recargar datos'>Recargar esta página</a> para ver los datos actualizados.</b>";

        }
        else if(peticion_http.responseText == 0)
        {

			caja.innerHTML= "<b>No se ha encontrado nuestro enlace en la web de destino. <a style='color:blue;text-decoration:none' href='administracion_enlaces.html' title='Recargar datos'>Recargar esta página</a> para ver los datos actualizados.</b>";

        }
      }
    }
  }
}





