Subversion Repositories SmartDukaan

Rev

Rev 10700 | Rev 10746 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
10582 lgm 1
function saveurl()
2
{
3
    localStorage.path = document.URL;
4
}
5
 
6
function spliturl(url)
7
{
8
 fullpath = url.substring(0, (url.indexOf("?") == -1) ? url.length : url.indexOf("?"));
9
 params =fullpath.split('<?=base_url()?>');
10
 //console.log(params[1]);
11
 getparams = url.split('?');
12
 //console.log(getparams[1]);
13
 var output = new Array();
14
 output[0] = params[1]; //data controller to parameters
15
 output[1] = getparams[1];//get input
16
 output[2]=fullpath; //full url expcept get input
17
 //console.log(output);
18
 return output;
19
}
20
 
21
 
22
function productSorting(category,sorttype)
23
  {
24
    //var cpage = document.getElementById('page').innerHTML;
25
    //if(cpage != 1){cpage=1;} else {cpage = parseInt(cpage) +1;}
26
    document.getElementById('page').innerHTML = 1;
27
    var url = base_url+'products?category='+category+'&filter='+sorttype;
28
    window.location.href = url;
29
 
30
 
31
  }
32
var a;
33
var b;
34
function togglelist(e, id) {
35
 
36
    var el = document.getElementById(id);
37
    if ((a != undefined) && (b != null) && (a != el)) {
38
        a.style.display = 'none';
39
        b.innerHTML = '+';
40
    }
41
    if (el.style.display != 'none') {
42
        el.style.display = 'none';
43
        e.currentTarget.children[1].innerHTML = '+';
44
    } else {
45
        el.style.display = '';
46
        e.currentTarget.children[1].innerHTML = '-';
47
    }
48
    a = el;
49
    b = e.currentTarget.children[1];
50
}
51
 
52
function checkShipping(){
53
  debugger;
10625 lgm 54
  var itemId ;
10582 lgm 55
  var color = document.getElementById('color');
10727 lgm 56
  if(color != null){
10625 lgm 57
   itemId = (color.options[color.selectedIndex].value); 
58
  }else{
59
    itemId = items[0].id;
60
  }
10582 lgm 61
  var pincode = document.getElementById('pincode').value;
10700 lgm 62
  if(pincode.match(/^\d+/) && pincode.length == 6){
63
    var url = base_url+'productinfo/getDeliveryDetails/'+itemId+'/'+pincode;
10582 lgm 64
  microAjax(url, function(res)
65
    {
66
      debugger;
67
        //console.log(res);
68
      if(res!='')
69
      {
70
        data = JSON.parse(res);
71
        days = data.business_days;
72
        if(days >= 0){
10700 lgm 73
          document.getElementById('service').style.display = 'block';
74
          document.getElementById('error').style.display = 'none';
10727 lgm 75
          if(document.getElementById('delivery')){
76
            for(i=0;i<items.length;i++){
77
              if(items[i].id == itemId){
78
                if(items[i].comingSoon != undefined && items[i].comingSoon == true){
79
                  document.getElementById('delivery').innerHTML = data.delivery_estimate+' after arrival';
80
                }else{
81
                  document.getElementById('delivery').innerHTML = data.delivery_estimate;
82
                }
83
              }  
84
            }
85
          }
10582 lgm 86
          if(document.getElementById('cod')){
87
            if(data.is_cod_available_for_location == true){
88
              document.getElementById('cod').innerHTML = 'Cash On Delivery';
89
            }
90
          }
91
          if(data.on_time_guarantee == true){
92
            if(document.getElementById('guarantee').style.display == 'none'){
93
              document.getElementById('guarantee').style.display == 'block';
94
            }
95
            //document.getElementById('guarantee').innerHTML = 'Yes';
96
          }
97
 
98
        }else{
99
          document.getElementById('service').style.display = 'none';
100
          document.getElementById('error').style.display = 'block';
10598 lgm 101
          document.getElementById('error').innerHTML = 'Location is not serviceable'
10582 lgm 102
        } 
103
      }
104
    });
10700 lgm 105
  }else{
106
      document.getElementById('error').style.display = 'block';
107
      document.getElementById('error').innerHTML = 'Invalid pincode!'
108
  }
10582 lgm 109
}
110
function updateColor(value){
111
    debugger;
112
    if(document.getElementById('error').style.display == "block"){
113
      document.getElementById('error').style.display = "none";
114
    }
115
        for(i=0;i<items.length;i++){
116
          if(value.currentTarget.value == items[i].id){
117
              document.getElementById('buy').innerHTML = items[i].buttonText;
118
              var buttonText = items[i].buttonText;
119
              if(buttonText.toUpperCase() == 'NOTIFY ME'){
120
                document.getElementById('email').style.display = 'block';
121
              }
122
              else{
123
                document.getElementById('email').style.display = 'none';  
124
              }
125
              var mrp = parseInt(items[i].mrp);
10727 lgm 126
              var noMrp;
10582 lgm 127
              if(mrp > 0){
128
                document.getElementById('mrp').innerHTML = items[i].mrp;
10727 lgm 129
              }else{
130
                noMrp = 1;
131
                document.getElementById('mrp').innerHTML = '';
10582 lgm 132
              }
133
              if(items[i].discount != undefined && parseInt(items[i].discount) >0){
134
                 document.getElementById('discount').innerHTML = '('+items[i].discount+'% off)'; 
135
              }
10727 lgm 136
              if(parseInt(items[i].sellingPrice) > 0){
137
                document.getElementById('rs').innerHTML = 'Rs';
138
                document.getElementById('sellingPrice').innerHTML = items[i].sellingPrice;
139
              }else{
140
                document.getElementById('sellingPrice').innerHTML = '';
141
                if(noMrp == 1){
142
                  document.getElementById('rs').innerHTML = '';
143
                }else{
144
                  document.getElementById('rs').innerHTML = 'Rs';
145
                }
146
              }
147
              if(items[i].minEmi != undefined && parseInt(items[i].minEmi) >0){
148
                document.getElementById('emi').innerHTML = ' EMI from Rs. '+items[i].minEmi+' per month';
149
              }
150
              if(items[i].comingSoon != undefined && items[i].comingSoon == true){
151
               document.getElementById('comingSoon').style.display = 'block'; 
152
              }else{
153
                document.getElementById('comingSoon').style.display = 'none';
154
              }
10582 lgm 155
              checkShipping();
156
              return false; 
157
          }
158
        }
159
      }
160
function addToCart(){
161
  debugger;
162
  var itemId ;
163
  var color = document.getElementById('color');
10727 lgm 164
  if(color != null){
10582 lgm 165
   itemId = (color.options[color.selectedIndex].value); 
166
  }else{
167
    itemId = items[0].id;
168
  }
169
  if(document.getElementById('email').style.display == 'block'){
170
    var email = document.getElementById('email').value;
171
    email = email.trim();
172
      var atpos = email.indexOf("@");
173
      var dotpos = email.lastIndexOf(".");
174
      if(email ==''){     
175
          document.getElementById('error').style.display = "block";
176
          document.getElementById('error').innerHTML ='Please fill email field!';
177
          window.scrollTo(0,0); return false;
178
        }
179
      if((atpos<1) || (dotpos < atpos+2) || (dotpos+2 >= email.length)){
180
          document.getElementById('error').style.display = "block";
181
          document.getElementById('error').innerHTML ='Please fill email in correct format!';
182
          window.scrollTo(0,0); return false;
183
      }    
184
      if(email.length> 50){  
185
          document.getElementById('error').style.display = "block";
186
          document.getElementById('error').innerHTML ='Please enter less than 50 characters in email field!';
187
          window.scrollTo(0,0); return false;
188
      }
189
      if(email.indexOf(' ') != -1){  
190
          document.getElementById('error').style.display = "block";
191
          document.getElementById('error').innerHTML ='Please remove space from email field!';
192
          window.scrollTo(0,0); return false;
193
      }
194
      var url = base_url+'cart/add/'+itemId+'/'+email;
195
  }
196
  else{
197
    var url = base_url+'cart/add/'+itemId+'/null';
198
  }
199
    //window.location.href = url;
200
    microAjax(url, function(res)
201
      {
202
      debugger;
203
        if(res!='')
204
        {
205
          debugger;
206
          data = JSON.parse(res);
10727 lgm 207
          if(data['addcart'][0].redirectUrl != undefined && data['addcart'][0].redirectUrl != ''){
10582 lgm 208
            //window.history.replaceState("",document.title, base_url+'cart');
209
            ga('send', 'event', 'Order', 'Add To Cart',itemId);
210
            var ua = navigator.userAgent.toLowerCase();
10727 lgm 211
            var redirectUrl = data['addcart'][0].redirectUrl;
10582 lgm 212
            var isIE = ua.indexOf('msie') !== -1;
213
            if (isIE){
10727 lgm 214
              window.location.replace(base_url+redirectUrl);
10582 lgm 215
            }else{
10727 lgm 216
              window.location.href = base_url+redirectUrl;
10582 lgm 217
            }
218
          }else if(data['addcart'][0].message != undefined){
219
            message = data['addcart'][0].message;
220
            document.getElementById('error').style.display = "block";
221
            document.getElementById('error').innerHTML = message;
222
            window.scrollTo(0,0);
223
          }
224
        }
225
      });
226
}
227
function clearError(){
228
  if(document.getElementById('error').style.display == "block"){
229
    document.getElementById('error').style.display = "none";
230
  }
231
}
232
function trackAccessories(title){
233
debugger;
234
ga('send', 'event', 'Widget', 'Accessory Click', title);
235
}