// Campos Obligatorios
campos_contacto = new Array("First_Name","Last_Name","Telephone","Email");
rechazos_contacto = new Array("","","","");


campos_quote = new Array("First_Name","Last_Name","Telephone","Email","Country");
rechazos_quote = new Array("","","","","");

showProduct = function(cid,pid){
	$('light').style.display = 'block';
	$('fade').style.display = 'block';
	var url = 'data/product-get.php';
	var clasesNames = new Array("meat","spices","vegetables","fruits","beans");
	var opt = {
		// Use POST
		method: 'post',
		// Send this lovely data
		parameters: 'cid=' + cid + '&pid=' + pid,
		// Handle successful response
		onSuccess: function(t) {
			var datos = t.responseText.evalJSON();
			$('product-title').update(datos.categoria + ' | ' + datos.producto);
			$('product-title').className = 'title-5 ' + clasesNames[cid];
			$('product-image').update('<img src="img/products/'+datos.imagen+'" alt=" " />');
			$('product-description').update('<p>'+datos.descripcion+'</p>');
			$('product-description-title').className = 'title-4 ' + clasesNames[cid];
			$('product-packaging').update('<p>'+datos.packaging+'</p>');
			$('product-packaging-title').className = 'title-4 ' + clasesNames[cid];
			$('light').style.display = 'none';
			$('fade').style.display = 'none';
		}
	}
	new Ajax.Request(url, opt);
}

checkIn = function(id,txt){
	if($F(id) == txt){
		$(id).value = '';
	}
}
checkOut = function(id,txt){
	if($F(id) == ''){
		$(id).value = txt;
	}
}

// Generales
checkForm = function(campos,rechazos,form){
	var mForm = $(form);
	var n = 0;
	for(var i=0; i<campos.length; i++){
		var campo = mForm[campos[i]].value;
		var rechazo = rechazos[i];
		if(campo == rechazo){
			n++;
		}
	}
	if(n == 0){
		return true;
	}
	return false;
}

sendContact = function(){
	// ID del Form
	var myForm = $('contactForm');
	// Campos obligatorios
	var requiredFields = campos_contacto.join("|");
	// Archivo que envia el mail
	var url = 'data/send-mail.php';
	var opt = {
		// Use POST
		method: 'post',
		// Send this lovely data
		parameters: myForm.serialize() + '&camposObligatorios=' + requiredFields,
		// Handle successful response
		onSuccess: function(t) {
			var response = t.responseText.evalJSON();
			alert(response.mensaje);
			if(response.estado == 'ok'){
				myForm.reset();
			}
		}
	}
	new Ajax.Request(url, opt);
}

sendQuote = function(){
	// ID del Form
	var myForm = $('getaCuoteForm');
	// Campos obligatorios
	var requiredFields = campos_contacto.join("|");
	// Archivo que envia el mail
	var url = 'data/send-quote.php';
	var opt = {
		// Use POST
		method: 'post',
		// Send this lovely data
		parameters: myForm.serialize() + '&camposObligatorios=' + requiredFields,
		// Handle successful response
		onSuccess: function(t) {
			var response = t.responseText.evalJSON();
			alert(response.mensaje);
			if(response.estado == 'ok'){
				myForm.reset();
			}
		}
	}
	new Ajax.Request(url, opt);
}