
YAHOO.namespace("cotizaciones");
function initDialogCotizacion() {
	var handleSuccess = function(o){alert("Hemos recibido su solicitud de cotización, muchas gracias!");};
	var handleFailure = function(o) {alert("No se pudo enviar su solicitud!: " + o.status);};
	YAHOO.cotizaciones.dialog = new YAHOO.widget.Dialog("ldblFrmCtzcns_",{ width : "500px", modal:true, fixedcenter : true, visible : false, constraintoviewport : true, buttons : [ { text:"Enviar", handler:function(){ this.submit();}, isDefault:true },{ text:"Cancelar", handler:function(){this.cancel();}}]});
	YAHOO.cotizaciones.dialog.validate = function() {
		var data = this.getData();
		if(data.email=="" || !(checkmail(data.email))){
			alert("Ingrese su direccion de correo electronico");return false;
		}
		if (data.nombre == "" || data.telefono== "") {
			alert("Ingrese su nombre y telefono para que podamos contactarnos con usted");return false;
		}
		if (data.entrega_provincia== "0") {
			alert("Seleccione la provincia de entrega");return false;
		}
		return true;
	};
	YAHOO.cotizaciones.dialog.callback = { success: handleSuccess, failure: handleFailure };
	YAHOO.cotizaciones.dialog.render();
	YAHOO.cotizaciones.dialog.show();
}

function initCotizaciones(){
	if(!YAHOO.cotizaciones.dialog){
		var content = document.getElementById("ldblFrmCtzcns");
		content.innerHTML = "";
		var callback={success : function(o){ content.innerHTML = o.responseText; initDialogCotizacion(); YAHOO.formnegocios.wait.hide();},failure : function(o) {content.style.visibility = "visible";content.innerHTML = "no se pudo conectar al servicio!";YAHOO.formnegocios.wait.hide();}};
		initWait({header:"Cargando el formulario...", body:"<img src=\"http://us.i1.yimg.com/us.yimg.com/i/us/per/gr/gp/rel_interstitial_loading.gif\"/>"});
		var conn = YAHOO.util.Connect.asyncRequest("GET", "/insumos/cotizaciones/cotizador.asp", callback);
	}else{
	YAHOO.cotizaciones.dialog.show();
	}
}

function initComoOperar() {
	if(!YAHOO.cotizaciones.panel){
		var handleCerrar= function(){this.hide();}
		YAHOO.cotizaciones.panel= new YAHOO.widget.SimpleDialog("comooperar",{ modal:true, width: "570px",fixedcenter: true, visible: false,draggable: false, close: true,text: "<img src=\"http://www.agrositio.com/insumos/images/operar_explicacion.jpg\" border=\"0\" />",constraintoviewport: true,buttons: [{text:"Cerrar", handler:handleCerrar, isDefault:true }]});
		YAHOO.cotizaciones.panel.setHeader("¿Como operar en Insumos?");
		YAHOO.cotizaciones.panel.render(document.body);
	}
	YAHOO.cotizaciones.panel.show();
}