        //Abre el pupu para mostrar la imagen grande
        function popupimgproducto(idprod,idimag,ancho,alto)
        {
                idimag=document.getElementById('idimagenv').value;
               // alert(idimag);
                imagancho=ancho; //document.getElementById('imagenvancho').value;
                imagalto=alto; //document.getElementById('imagenvalto').value;

                ruta= "index.php?idmod=ecommerce&act=mimag&idprod=" + idprod + "&idimag=" + idimag;
                formato="left=20,top=20,width="+imagancho+",height="+imagalto+",toolbar=no,resizable=0,scrollbars=no, menubar=no, location=no";
                //alert(ruta);
                window.open(ruta,"imagenprod",formato)
        }


      //Ajax para cambiar las imagenes
      function CambiaImagenes(vProd,vImag) {
        var url = "index.php?idmod=ecommerce&act="; // The server-side script

        if (!isWorking && http) {

          var vAccion="cimagenes";

          http.open("GET", url + escape(vAccion)+"&idprod="+escape(vProd)+"&idimag="+escape(vImag), true);

          http.onreadystatechange = handleHttpResponse;
          isWorking = true;

          http.send(null);
        }
      }



      function handleHttpResponse() {

        if (http.readyState == 4) {

           if (http.responseText.indexOf('invalid') == -1) {
            // Split the comma delimited response into an array

            if(http.responseText=="vacio"){

             }else{


               results = http.responseText.split("|");
               document.getElementById('catalogoimagengrande').src = results[2];
               document.getElementById('catimagendetalle').src = results[5];

               document.getElementById('idimagenv').value = results[0];
               document.getElementById('imagenvancho').value = results[6];
               document.getElementById('imagenvalto').value = results[7];


            }
            //var indice =document.getElementById('listaidiomas').selectedIndex
            //document.getElementById('ididioma').value = document.getElementById('listaidiomas').options[indice].value;
            //document.getElementById('textoidioma').innerHTML=document.getElementById('listaidiomas').options[indice].text;

            isWorking = false;
            //YaCargo();
            //document.getElementById("imgsubmit").disabled=false;
          }
        }
      }




      function getHTTPObject() {
              var xmlhttp=false;
              try
              {

                      // Creacion del objeto AJAX para navegadores no IE
                      xmlhttp=new ActiveXObject("Msxml2.XMLHTTP");
              }
              catch(e)
              {
                      try
                      {
                              // Creacion del objet AJAX para IE
                              xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
                      }
                      catch(E) { xmlhttp=false; }
              }
              if (!xmlhttp && typeof XMLHttpRequest!='undefined') { xmlhttp=new XMLHttpRequest(); }

              return xmlhttp;
      }
      var isWorking = false;
      var http = getHTTPObject(); // We create the HTTP Object


      function CambiaOpcion(vProd,vidopcion,vidvalor){
        var url = "index.php?idmod=ecommerce&act="; // The server-side script

        if (!isWorking && http) {

          var vAccion="cambiaopcion";

          var codigoprod= document.getElementById('codigoprod').value ;

           //alert( url + escape(vAccion)+"&idprod="+escape(vProd)+"&idopcion="+escape(vidopcion)+"&idvalor="+escape(vidvalor));
          http.open("GET", url + escape(vAccion)+"&idprod="+escape(vProd)+"&idopcion="+escape(vidopcion)+"&idvalor="+escape(vidvalor)+"&codigoprod="+escape(codigoprod), true);

          http.onreadystatechange = handleHttpResponse2;
          isWorking = true;

          http.send(null);
        }

      }

      function handleHttpResponse2() {

        if (http.readyState == 4) {

           if (http.responseText.indexOf('invalid') == -1) {
            // Split the comma delimited response into an array

            if(http.responseText=="vacio"){

             }else{
              //  alert(http.responseText);

               results = http.responseText.split("|");
                var divopcion="tvaloropcion"+results[1];
               document.getElementById(divopcion).innerHTML = results[2];
               var valopcion="ocidopcion-"+results[1];
                  document.getElementById(valopcion).value = results[5];
               document.getElementById('codprodcomp').innerHTML = results[6];

               document.getElementById('codigoprodopcion').value =  results[6];

               if(results[8]!=""){
               document.getElementById('catalogoimagengrande').src = results[8];
               document.getElementById('catimagendetalle').src = results[11];



              // alert(divopcion);


               document.getElementById('idimagenv').value = results[0];
               document.getElementById('imagenvancho').value = results[12];
                document.getElementById('imagenvalto').value = results[13];

                 }




               //alert(results[6]);
             // alert( document.getElementById('idimagenv').value);
               //alert(document.getElementById('idimagenv').value);

            }

            isWorking = false;
          }
        }
      }


      function SacaOpciones(){

       var submission_string="";

        document.forms['form_agregaitem'].elements['opciones'].value="";
         for (var elems=0; elems<document.forms['form_agregaitem'].length;elems++){
                nombreel=document.forms['form_agregaitem'].elements[elems].name;
                nombreel.substring(0,11)
                if (nombreel.substring(0,11) == "ocidopcion-"){
                   idopcionj=nombreel.substring(11)
                   idvalopcionj=document.forms['form_agregaitem'].elements[elems].value;
                   document.forms['form_agregaitem'].elements['opciones'].value=document.forms['form_agregaitem'].elements['opciones'].value+idopcionj+":::"+idvalopcionj+"|";
                   //alert(document.forms['form_agregaitem'].elements['opciones'].value);
                }
         }
     }

        function Valida(){
                        SacaOpciones();
                        frm=document.form_agregaitem;

                        cantidad=frm.cantidad.value;

                        if(cantidad.length == 0){
                                alert("Ingrese la cantidad");
                                return false;
                        }
                        if(cantidad <= 0){
                                alert("La Cantidad debe ser Mayor a 0");
                                return false;
                        }

        }


        function BorradeCarr(VidCarr,idioma){

               if(idioma==1){
                    var entrar = confirm("¿Desea eliminar el Articulo?")
               }else{
                    var entrar = confirm("Do you want to delete this item?")
               }

               if (entrar==true ){
                    location.href='index.php?idmod=ecommerce&act=borradcar&idcarr='+VidCarr;
               }else{
                    return;
               }
        }

        function CambiaEnvio(vIdZona){

             var url = "index.php?idmod=ecommerce&act="; // The server-side script

             if (!isWorking && http) {

               var vAccion="czonaenvio";

               http.open("GET", url + escape(vAccion)+"&idzona="+escape(vIdZona)+"&esajax=1", true);

               http.onreadystatechange = handleHttpResponse3;
               isWorking = true;

               http.send(null);
             }

        }

      function handleHttpResponse3() {

        if (http.readyState == 4) {

           if (http.responseText.indexOf('invalid') == -1) {
               if(http.responseText=="vacio"){

               }else{
                    results = http.responseText.split(":::");

                    var oSelect = document.getElementById('paisenvio');
                    opciones= results[0].split("##");
                    document.getElementById('paisenvio').innerHTML = "";

                    newOpt = document.createElement( 'option' );
                    newOpt.text = "Seleccione un Pais";
                    newOpt.value = 0;
                    oSelect.appendChild(newOpt);

                    for(var k=0; k<opciones.length-1; k++){
                           teval= opciones[k].split("|");
                           texopcion=teval[1];
                           valopcion= parseInt(teval[0]);


                              newOpt = document.createElement( 'option' );
                              newOpt.text = texopcion;
                              newOpt.value = valopcion;
                              oSelect.appendChild(newOpt);

                             // alert("KK");

                    }

                    document.getElementById('cat_ttotalenvio').innerHTML = results[1];

                    document.getElementById('precioenvio').value = results[1];


                    document.getElementById('pesototal').value = results[1];



                    document.getElementById('totaltotal').value = parseFloat(document.getElementById('preciototal').value) + parseFloat(results[1]);



                    document.getElementById('cat_ttotal').innerHTML = document.getElementById('totaltotal').value;



               }
               isWorking = false;
           }
        }
      }
