Subversion Repositories SmartDukaan

Rev

Rev 10746 | Rev 10781 | 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;
10746 lgm 62
  if(/^\d+$/.test(pincode) && pincode.length == 6){
10700 lgm 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{
10777 lgm 106
      if(checkPincode != true){
107
        document.getElementById('error').style.display = 'block';
108
        document.getElementById('error').innerHTML = 'Invalid pincode!'
109
      }
10700 lgm 110
  }
10582 lgm 111
}
10777 lgm 112
var checkPincode;
10582 lgm 113
function updateColor(value){
114
    debugger;
10777 lgm 115
    checkPincode = true;
10582 lgm 116
    if(document.getElementById('error').style.display == "block"){
117
      document.getElementById('error').style.display = "none";
118
    }
119
        for(i=0;i<items.length;i++){
120
          if(value.currentTarget.value == items[i].id){
121
              document.getElementById('buy').innerHTML = items[i].buttonText;
122
              var buttonText = items[i].buttonText;
123
              if(buttonText.toUpperCase() == 'NOTIFY ME'){
124
                document.getElementById('email').style.display = 'block';
125
              }
126
              else{
127
                document.getElementById('email').style.display = 'none';  
128
              }
129
              var mrp = parseInt(items[i].mrp);
10727 lgm 130
              var noMrp;
10582 lgm 131
              if(mrp > 0){
132
                document.getElementById('mrp').innerHTML = items[i].mrp;
10727 lgm 133
              }else{
134
                noMrp = 1;
135
                document.getElementById('mrp').innerHTML = '';
10582 lgm 136
              }
137
              if(items[i].discount != undefined && parseInt(items[i].discount) >0){
138
                 document.getElementById('discount').innerHTML = '('+items[i].discount+'% off)'; 
139
              }
10727 lgm 140
              if(parseInt(items[i].sellingPrice) > 0){
141
                document.getElementById('rs').innerHTML = 'Rs';
142
                document.getElementById('sellingPrice').innerHTML = items[i].sellingPrice;
143
              }else{
144
                document.getElementById('sellingPrice').innerHTML = '';
145
                if(noMrp == 1){
146
                  document.getElementById('rs').innerHTML = '';
147
                }else{
148
                  document.getElementById('rs').innerHTML = 'Rs';
149
                }
150
              }
151
              if(items[i].minEmi != undefined && parseInt(items[i].minEmi) >0){
152
                document.getElementById('emi').innerHTML = ' EMI from Rs. '+items[i].minEmi+' per month';
153
              }
154
              if(items[i].comingSoon != undefined && items[i].comingSoon == true){
155
               document.getElementById('comingSoon').style.display = 'block'; 
156
              }else{
157
                document.getElementById('comingSoon').style.display = 'none';
158
              }
10582 lgm 159
              checkShipping();
10777 lgm 160
              checkPincode = false;
10582 lgm 161
              return false; 
162
          }
163
        }
164
      }
165
function addToCart(){
166
  debugger;
167
  var itemId ;
168
  var color = document.getElementById('color');
10727 lgm 169
  if(color != null){
10582 lgm 170
   itemId = (color.options[color.selectedIndex].value); 
171
  }else{
172
    itemId = items[0].id;
173
  }
174
  if(document.getElementById('email').style.display == 'block'){
175
    var email = document.getElementById('email').value;
176
    email = email.trim();
177
      var atpos = email.indexOf("@");
178
      var dotpos = email.lastIndexOf(".");
179
      if(email ==''){     
180
          document.getElementById('error').style.display = "block";
181
          document.getElementById('error').innerHTML ='Please fill email field!';
182
          window.scrollTo(0,0); return false;
183
        }
184
      if((atpos<1) || (dotpos < atpos+2) || (dotpos+2 >= email.length)){
185
          document.getElementById('error').style.display = "block";
186
          document.getElementById('error').innerHTML ='Please fill email in correct format!';
187
          window.scrollTo(0,0); return false;
188
      }    
189
      if(email.length> 50){  
190
          document.getElementById('error').style.display = "block";
191
          document.getElementById('error').innerHTML ='Please enter less than 50 characters in email field!';
192
          window.scrollTo(0,0); return false;
193
      }
194
      if(email.indexOf(' ') != -1){  
195
          document.getElementById('error').style.display = "block";
196
          document.getElementById('error').innerHTML ='Please remove space from email field!';
197
          window.scrollTo(0,0); return false;
198
      }
199
      var url = base_url+'cart/add/'+itemId+'/'+email;
200
  }
201
  else{
202
    var url = base_url+'cart/add/'+itemId+'/null';
203
  }
204
    //window.location.href = url;
205
    microAjax(url, function(res)
206
      {
207
      debugger;
208
        if(res!='')
209
        {
210
          debugger;
211
          data = JSON.parse(res);
10727 lgm 212
          if(data['addcart'][0].redirectUrl != undefined && data['addcart'][0].redirectUrl != ''){
10582 lgm 213
            //window.history.replaceState("",document.title, base_url+'cart');
214
            ga('send', 'event', 'Order', 'Add To Cart',itemId);
215
            var ua = navigator.userAgent.toLowerCase();
10727 lgm 216
            var redirectUrl = data['addcart'][0].redirectUrl;
10582 lgm 217
            var isIE = ua.indexOf('msie') !== -1;
218
            if (isIE){
10727 lgm 219
              window.location.replace(base_url+redirectUrl);
10582 lgm 220
            }else{
10727 lgm 221
              window.location.href = base_url+redirectUrl;
10582 lgm 222
            }
223
          }else if(data['addcart'][0].message != undefined){
224
            message = data['addcart'][0].message;
225
            document.getElementById('error').style.display = "block";
226
            document.getElementById('error').innerHTML = message;
227
            window.scrollTo(0,0);
228
          }
229
        }
230
      });
231
}
232
function clearError(){
233
  if(document.getElementById('error').style.display == "block"){
234
    document.getElementById('error').style.display = "none";
235
  }
236
}
237
function trackAccessories(title){
238
debugger;
239
ga('send', 'event', 'Widget', 'Accessory Click', title);
240
}