
function contratacionDominio(valor,id,freetime,gratis) // Funcion que multiplica el numero de aņos por el costo del dominio
{
	//alert(gratis.value);
	//alert(valor);
	var precio = document.getElementById('precio'+id);
	var preciou = document.getElementById('preciou'+id).value;
	//alert(preciou);
	if((precio.innerHTML).charAt(4) != "G")
	{
		if(gratis == 0)
		{
			precio.innerHTML = (preciou * valor.value);
		}
		else
		{
			if(valor.value > 1)
			{
			// Si es gratis y la contratacion es mayor a 1 multiplicamos el precio(aņo - 1aņogratis)  / f(x) = a(x - b)
			//alert((preciou * ( parseInt(valor.value) - parseInt(freetime))));
				precio.innerHTML =  (preciou * ( parseInt(valor.value) - parseInt(freetime)));
			}
			else
			{
				precio.innerHTML = 0;
			}
		}
		//alert(precio.innerHTML);
		precio.className = '';
		document.getElementById('simbolo'+id).innerHTML = "\$" ;
		cotizarDominios();
		if(precio.innerHTML == 0)
		{	
			precio.innerHTML = "<strong class='tituloazul'>GRATIS</strong>";
			document.getElementById('simbolo'+id).innerHTML = "";
		}
	} 
	else // El dominio es gratis
	{
		if(valor.value > 1)
		{
			precio.innerHTML =  (preciou * ( parseInt(valor.value) - parseInt(freetime)));
			precio.className = '';
			document.getElementById('simbolo'+id).innerHTML = "\$" ;
			cotizarDominios();
		}
	}

}

function dominiox(dom,id)
{

	var dominio = document.getElementById('dominiol'+id).innerHTML;

	if(dom.checked)
	{
		
		xajax_addDominio(id,dominio);
	}
	else
	{
	
		xajax_eliminarDomain(id);
		xajax_generarTabla();
	}
}

function cotizarDominios()
{
// Funcion que saca el total en pesos mexicanos de los dominios pedidos.
	var totalprecio = 0;
	var totaldom = document.getElementById('totaldomain').value;
	//alert(totaldom);
	var x = "";
	for(i = 0; i <= totaldom; i++)
	{
	
		try
		{
			var preciou = document.getElementById('precio'+i).innerHTML;
		
			if(preciou.charAt(4) == "G" || preciou.charAt(28) == "R" || preciou == "GRATIS")
			{
				//alert("es gratis");
				// es gratis
			} else
			{
				//alert("no es gratis");
				if(preciou)totalprecio = parseInt(totalprecio) + parseInt(preciou);
			}	
	     } catch(x)
		 {
			continue;
		 }
		
		
	}
	document.getElementById('comdomain').innerHTML = totalprecio;
	getIva();
}

function getIva()
{	
	 var totaldominios = document.getElementById('comdomain');
	 var x ="";
	 try
	 {	
		var plan = document.getElementById('contratoplan');
	 
		document.getElementById('iva').innerHTML = Math.round(((parseInt(totaldominios.innerHTML) + parseInt(plan.innerHTML)) * 0.16) * 100) / 100;
	 }catch(x)
	 {
		document.getElementById('iva').innerHTML = Math.round(parseInt(totaldominios.innerHTML) * 0.16) * 100 / 100;
	 }
	 getTotal();
}
function getTotal()
{
	 var totaldominios = document.getElementById('comdomain').innerHTML;
	 var plan = document.getElementById('contratoplan').innerHTML;
	 var iva = 	 document.getElementById('iva').innerHTML;
	 document.getElementById('total').innerHTML = (parseInt(totaldominios) + parseInt(plan)) + parseFloat(iva);
	 document.forms[0].total_pagar.value =  (parseInt(totaldominios) + parseInt(plan)) + parseFloat(iva);
	 document.forms[0].iva_.value = parseFloat(iva);
	 document.forms[0].total_dominios.value =  parseInt(totaldominios);
	
/*	 document.getElementById('total_pagar').value = (parseInt(totaldominios) + parseInt(plan)) + parseFloat(iva);
	 document.getElementById('iva_').value = parseFloat(iva);
	 document.getElememtById('total_dominios').value = parseInt(totaldominios);
*/}

function facturar(chck)
{
	var facturacion = document.getElementById('facturadatos');
	if(chck.checked)
	{
		facturacion.style.display = 'block';
	} 
	else
	{
		facturacion.style.display = 'none';
	}

}
function validExistentDomain()
{
	var domain = document.forms[0].dominioex.value;
	var len = domain.length;

	if(( domain.charAt(len - 4) != "."))
	{
		if( (domain.charAt(len - 3) != '.'))
		{
			alert("Ha introducido un Dominio invalido");
			document.forms[0].dominioex.focus();
			return false;
		}
	}
	
document.forms[0].appendChild(document.createElement("button")).click();
}

function verificar()
{
	var nombre = document.getElementById('ndominio').value;
	var tld = document.getElementById('tld').value;
	
	if(nombre != "")
	{
		document.getElementById('loading').style.display = 'block';
		document.getElementById('submit').disabled = true;
		xajax_testDomain(nombre,tld);
	} 
	else
	{
		alert("Introduzca un nombre para su dominio.");
		document.getElementById('dominio').focus();
		
	}
}

function verificarN()
{
	var nombre = document.getElementById('ndominio').value;
	var tld = document.getElementById('tld').value;
	//alert("hey");
	
	if(nombre != "")
	{
		document.getElementById('loading').style.display = 'block';
		document.getElementById('submit').disabled = true;
		xajax_testDomainN(nombre,tld);
	} 
	else
	{
		alert("Introduzca un nombre para su dominio.");
		document.getElementById('dominio').focus();
		
	}
}


