var cuenta=0;
var valor=0;
var precios = new Array(0,2050.00,2050.00,2340.00,2340.00,2790.00,2790.00,3310.00,3310.00,4400.00,550.00,340.00,654.00,136.00,140.00,1695.00,1695.00);

function dev_Precio(objeto) {
	var num_ind = objeto.selectedIndex;
	return precios[num_ind];
}

function enviado(form) {                       
	if (cuenta == 0)
	{
 		cuenta++;
		form.submit();					
		return true;
	}
	else {
		alert("This form already has been sent, thank you very much.");
		return false;
	}
}

function Redondeo (imp){
	importe = '' + imp;
	if (importe.indexOf(".") != -1){
	entero = importe.substr(0,importe.indexOf("."));
	decimal = Math.round((imp - entero) * 100);
	if (decimal < 10) decimal = '0' + decimal;
	else decimal = '' + decimal;
	return (entero + "," + decimal);
	}
	else return imp + ',00';
}
function Calcular(form){
var precio_1 = dev_Precio(form.producto1);
var precio_2 = dev_Precio(form.producto2);
var precio_3 = dev_Precio(form.producto3);
var precio_4 = dev_Precio(form.producto4);
form.precio1.value = Redondeo(precio_1) + ' €';
form.importe1.value = Redondeo((precio_1 * form.unidades1.value)) + ' €';
form.precio2.value = Redondeo(precio_2) + ' €';
form.importe2.value = Redondeo((precio_2 * form.unidades2.value)) + ' €';
form.precio3.value = Redondeo(precio_3) + ' €';
form.importe3.value = Redondeo((precio_3 * form.unidades3.value)) + ' €';
form.precio4.value = Redondeo(precio_4) + ' €';
form.importe4.value = Redondeo((precio_4 * form.unidades4.value)) + ' €';
valor = ((precio_1 * form.unidades1.value)+(precio_2 * form.unidades2.value)+(precio_3 * form.unidades3.value)+(precio_4 * form.unidades4.value));
form.suma.value = Redondeo(valor) + ' €';
}

function Validar(form){
if (form.producto1.value == 0 && form.producto2.value == 0 && form.producto3.value == 0 && form.producto4.value == 0)
 {alert("Please, it chooses a product or service .");form.producto1.focus();return;}
if (form.nombre.value == "") { alert("Please, its Name writes"); form.nombre.focus(); return; }
if (form.domicilio.value == "") { alert("Please, its Address writes"); form.domicilio.focus(); return; }
if (form.ciudad.value == "") { alert("Please, its City writes"); form.ciudad.focus(); return; }
if (form.cp.value == "") { alert("Please, its Zip/Postal Code writes"); form.cp.focus(); return; }
if (form.estado_provincia.value == "") { alert("Please, its State/Province writes"); form.estado_provincia.focus(); return; }
if (form.pais.value == "") { alert("Please, its Country writes"); form.pais.focus(); return; }
if (form.telefono.value == "") { alert("Please, its Telephone number writes"); form.telefono.focus(); return; }
if (form.email.value == "") { alert("Please, its e-mail writes"); form.email.focus(); return; }
if (form.email.value.indexOf('@', 0) == -1 || form.email.value.indexOf('.', 0) == -1)
{ alert("Incorrect email"); form.email.focus(); return; }
enviado(form);
}

function RecogerPedido(form) {
	if (parent.parent.product != '') {
		if (form.producto1.value ='0') {
			form.producto1.value = parent.parent.product; form.producto1.focus();
		}
		else {
			if (form.producto2.value ='0') {
				form.producto2.value = parent.parent.product; form.producto2.focus();
			}
			else {
				if (form.producto3.value ='0') {
					form.producto3.value = parent.parent.product; form.producto3.focus();
				}
				else {
					form.producto4.value = parent.parent.product; form.producto4.focus();
				}
			}
		}
		Calcular (form);
		parent.parent.product = '';
	}
}

