function OfertasRegalos(){this.lstOfertas=null;this.OfertasRega=function a(f){var d=f.split("|");this.lstOfertas=new Array(d.length);for(var p=0;p<d.length;p++){var q=d[p];if(q.length>0){var g=q.split(",");var m=g[0];var b=g[1];var v=g[2];var t=g[3];var s=g[4];var o=g[5];var h=g[6];var e=g[7];var k=g[8];var j=g[9];var n=g[10];var w=g[11];var u=g[12];var r=g[13];var x=g[14];var c=g[15];var l=new Oferta(x,c,m);switch(m){case"DESCGRAL":l.dblDescuento=b;break;case"DESCPROD":l.dblDescuento=b;l.setLstCvesDesc(v);l.dblPrecio=s;l.dblPuntos=o;l.dblNegocio=h;l.dblCreditos=e;break;case"REGALO":l.setRegalo(v,t,s,o,h,e,n,w,u,r);break;case"SELREGALO":l.setRegalo(v,t,s,o,h,e,n,w,u,r);break;case"DESCCLAS":l.dblDescuento=b;l.intGrupo1=g[2];l.intGrupo2=g[3];l.intGrupo3=g[4];l.intGrupo4=g[5];l.intGrupo5=g[6];l.dblPrecio=g[9];l.dblPuntos=g[10];l.dblNegocio=g[11];l.dblCreditos=g[12];break;case"MSSG":l.strMsg=k;l.bolSoloAl=j;break;case"INCREMPROD":l.dblDescuento=b;if(v.length>0){l.setLstCvesDesc(v)}l.intApPto=g[10];l.intApVN=g[11];l.intApPrec=g[12];l.intApCred=g[13];break}this.lstOfertas[p]=l}}}}function Oferta(h,i,e){this.intId=h;this.strDescripcion=i;this.strTipo=e;this.dblDescuento=0;this.dblPrecio=0;this.dblPuntos=0;this.dblNegocio=0;this.dblCreditos=0;this.bolSoloAl=false;this.strMsg="";this.intGrupo1=0;this.intGrupo2=0;this.intGrupo3=0;this.intGrupo4=0;this.intGrupo5=0;this.lstRegalos=null;this.arrPartidasVenta=null;this.DivSelRegalos=null;this.intApPto=0;this.intApVN=0;this.intApCred=0;this.intApPrec=0;this.setRegalo=function j(D,q,r,B,n,v,s,G,F,E){var p=D.split("!");var o=s.split("!");var H=q.split("!");var y=r.split("!");var I=B.split("!");var t=n.split("!");var z=v.split("!");var x=G.split("!");var w=F.split("!");var u=E.split("!");this.lstRegalos=new Array(p.length);for(var A=0;A<p.length;A++){var C=new Regalo(p[A],o[A],H[A],y[A],I[A],t[A],z[A],parseInt(x[A]),parseInt(w[A]),parseInt(u[A]));this.lstRegalos[A]=C}};this.setLstCvesDesc=function g(o){var q=o.split(String.fromCharCode(10));this.lstRegalos=new Array(q.length);for(var p=0;p<q.length;p++){q[p]=q[p].replace(String.fromCharCode(10),"","g");q[p]=q[p].replace(String.fromCharCode(13),"","g");var n=new Regalo(q[p],0,0,0,0,0);this.lstRegalos[p]=n}};this.AplicaOferta=function b(){var n=false;if(this.strTipo=="DESCGRAL"){this.AplicaDescuentoGlobal(this.intId,this.dblDescuento,null)}if(this.strTipo=="DESCPROD"){if(parseFloat(this.dblDescuento)==0){this.AsignaPrecioProd(this.intId,this.lstRegalos,this.dblPrecio,this.dblPuntos,this.dblNegocio,this.dblCreditos)}else{this.AplicaDescuentoGlobal(this.intId,this.dblDescuento,this.lstRegalos)}}if(this.strTipo=="REGALO"){this.AnadirRegalo(this.intId,this.lstRegalos)}if(this.strTipo=="SELREGALO"){this.MostrarRegaloporSeleccion(this.intId,this.strDescripcion,this.lstRegalos)}if(this.strTipo=="DESCCLAS"){this.DescuentoporClas(this.intId,this.dblDescuento,this.dblPrecio,this.dblPuntos,this.dblNegocio,this.dblCreditos,this.intGrupo1,this.intGrupo2,this.intGrupo3,this.intGrupo4,this.intGrupo5)}if(this.strTipo=="MSSG"){alert(this.strMsg+" "+this.bolSoloAl);if(this.bolSoloAl=="true"){n=true}else{n=false}}if(this.strTipo=="INCREMPROD"){this.AsignaIncremProd(this.intId,this.dblDescuento,this.lstRegalos,this.intApPto,this.intApVN,this.intApPrec,this.intApCred)}return n};this.AplicaDescuentoGlobal=function f(r,u,n){if(this.arrPartidasVenta!=null){var o=this.arrPartidasVenta;for(var v=1;v<o.length;v++){var x=o[v];if(x.Eliminada==false&&x.objEsRegalo.strValor=="0"){try{var p=false;if(n==null){p=true}else{for(var t=0;t<n.length;t++){var w=n[t];if(w.strCve==x.objCve.strValor){p=true;break}}}if(p==true){if(x.objDescClie.strValor=="1"){x.objlstOfertas.setValor(x.objlstOfertas.strValor+","+r);x.AsignaDesc(u)}}}catch(q){var s="There was an error on this page."+q.description+"\n\n";alert(s)}}}}};this.AsignaPrecioProd=function m(s,o,z,y,x,q){var p=this.arrPartidasVenta;for(var v=1;v<p.length;v++){var A=p[v];if(A.Eliminada==false&&A.objEsRegalo.strValor=="0"){try{var n=false;for(var u=0;u<o.length;u++){var w=o[u];if(w.strCve==A.objCve.strValor){n=true;break}}if(n==true){A.objPrecioNeto.setValor(z);A.objPuntos.setValor(y);A.objNegocio.setValor(x);A.objCreditos.setValor(q);A.objlstOfertas.setValor(A.objlstOfertas.strValor+","+s);A.CalculaImporte()}}catch(r){var t="There was an error on this page."+r.description+"\n\n";alert(t);alert(t)}}}};this.AsignaIncremProd=function l(s,v,o,y,z,B,r){if(this.arrPartidasVenta!=null){var p=this.arrPartidasVenta;for(var w=1;w<p.length;w++){var A=p[w];if(A.Eliminada==false&&A.objEsRegalo.strValor=="0"){try{var n=false;if(o==null){n=true}else{if(o.length==0){n=true}else{for(var u=0;u<o.length;u++){var x=o[u];if(x.strCve==A.objCve.strValor){n=true;break}}}}if(n==true){A.objlstOfertas.setValor(A.objlstOfertas.strValor+","+s);A.AsignaInc(v,y,z,B,r)}}catch(q){var t="There was an error on this page.\n\n";t+="Error description: "+q.description+"\n\n";t+="Click OK to continue.\n\n";alert(t)}}}}};this.AnadirRegalo=function a(r,n){for(var s=0;s<n.length;s++){var t=n[s];var A=t.dblCant;var z=t.dblPrecio;var x=t.dblPuntos;var w=t.dblNegocio;var o=t.dblCreditos;var p=0;var q=t.strConc;var y=parseInt(t.intNotax1);var v=parseInt(t.intNotax2);var u=parseInt(t.intNotax3);if(t.strCve.length>0){Prod=adicionarFila(t.strCve,q,"",A,0,z,0,x,w,o,0,0,p,0,0,0,0,0,0,0,0,z,x,w,o,p,y,v,u,false,false,true,"darkblue",false,"");Prod.objlstOfertas.setValor(r)}}};this.DescuentoporClas=function c(y,t,z,x,w,o,u,s,r,q,p){var n=this.arrPartidasVenta;for(var v=1;v<n.length;v++){var A=n[v];if(A.Eliminada==false){if(A.objEsRegalo.strValor=="0"){if(A.EstaenlaClasificacion(u)==true&&A.EstaenlaClasificacion(s)==true&&A.EstaenlaClasificacion(r)==true&&A.EstaenlaClasificacion(q)==true&&A.EstaenlaClasificacion(p)==true){A.objlstOfertas.setValor(A.objlstOfertas.strValor+","+y);if(t>0){A.AsignaDesc(t)}else{A.objPrecioNeto.setValor(z);A.objPuntos.setValor(x);A.objNegocio.setValor(w);A.objCreditos.setValor(o);A.CalculaImporte()}break}}}}};this.MostrarRegaloporSeleccion=function k(y,p,v){if(this.DivSelRegalos==null){var z=document.getElementById("SeleccionaOfertas");var r=new ctrlTabla(z,0,1,2,"tablecolor");r.CreaTabla();this.DivSelRegalos=r;var t=r.AnadeFila("Fila ","headed2","left","");var D=t.AnadeCelda("","","","");D.AnadeCeldaContenido("<DIV ID=txtDiv STYLE='width:400; filter:glow(color=orange, strength=8, enabled=true)'><H1>Tiene productos por seleccionar!</H1></DIV>");var u=t.AnadeCelda("","","","")}else{if(this.DivSelRegalos.objTabla.rows.length==0){r=this.DivSelRegalos;var q=r.AnadeFila("Fila ","headed2","left","");var w=q.AnadeCelda("","","","");w.AnadeCeldaContenido("<DIV ID=txtDiv STYLE='width:400; filter:glow(color=orange, strength=8, enabled=true)'><H1>Tiene productos por seleccionar!</H1></DIV>");q.AnadeCelda("","","","")}}var n=this.DivSelRegalos;var F=n.AnadeFila("Fila "+y,"headed2","left","");var C=F.AnadeCelda("","","","");C.AnadeCeldaContenido("<b>"+p+"</b>");var B=F.AnadeCelda("","","","");var A=new Control("SelOferta"+y,"Select","0","","");var H=A.CreaSelect("Seleccione el producto que guste",false);A.Anadir("0","SELECCIONE");for(var s=0;s<v.length;s++){var o=v[s];var G=o.strConc;A.Anadir(o.strCve,o.strCve+" "+G)}B.AnadeCeldaControl(H);var E=document.createElement("INPUT");E.setAttribute("value","Agregar");E.setAttribute("name","Boton"+y);E.setAttribute("type","button");E.setAttribute("class","boton");E.setAttribute("className","boton");var x=this.arrPartidasVenta;var I=this;E.onclick=function(){I.AnadeSelRegalo(y,A,v,x);E.style.visibility="hidden";n.BorraFilas()};B.AnadeCeldaControl(E)};this.AnadeSelRegalo=function d(x,H,t,v){var r=H.RegresaValorLstActual();if(r!="0"){for(var s=0;s<t.length;s++){var n=t[s];var u=n.dblCant;var q=n.dblPrecio;var C=n.dblPuntos;var y=n.dblNegocio;var o=n.dblCreditos;var A=0;var G=n.strConc;var F=parseInt(n.intNotax1);var E=parseInt(n.intNotax2);var D=parseInt(n.intNotax3);if(n.strCve==r){var w=u;if(u>1){w=prompt("Introduce la cantidad(maximo "+u+")",""+u);try{if(w==""||w>u){alert("Cantidad erronea se tomaran en cuenta "+u+" piezas");w=u}}catch(p){alert(p);w=u}}z=adicionarFila(n.strCve,G,"",u,0,q,0,C,y,o,0,0,A,0,0,0,0,0,0,0,0,q,C,y,o,A,F,E,D,false,false,true,"darkGreen",true,"");z.objlstOfertas.setValor(x);break}}}else{for(var B=1;B<v.length;B++){var z=v[B];if(z.Eliminada==false){if(z.objEsRegalo.strValor=="1"){if(z.objlstOfertas.strValor==x){borrarFila(z.botonElimina,z,false);break}}}}}SumatoriaPartidas()}}function Regalo(d,c,a,j,g,f,b,i,h,e){this.strCve=d;this.strConc=c;this.dblCant=a;this.dblPrecio=j;this.dblPuntos=g;this.dblNegocio=f;this.dblCreditos=b;this.intNotax1=i;this.intNotax2=h;this.intNotax3=e};