Subversion Repositories SmartDukaan

Rev

Rev 10625 | Rev 10727 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

function saveurl()
{
    localStorage.path = document.URL;
}

function spliturl(url)
{
 fullpath = url.substring(0, (url.indexOf("?") == -1) ? url.length : url.indexOf("?"));
 params =fullpath.split('<?=base_url()?>');
 //console.log(params[1]);
 getparams = url.split('?');
 //console.log(getparams[1]);
 var output = new Array();
 output[0] = params[1]; //data controller to parameters
 output[1] = getparams[1];//get input
 output[2]=fullpath; //full url expcept get input
 //console.log(output);
 return output;
}


function productSorting(category,sorttype)
  {
    //var cpage = document.getElementById('page').innerHTML;
    //if(cpage != 1){cpage=1;} else {cpage = parseInt(cpage) +1;}
    document.getElementById('page').innerHTML = 1;
    var url = base_url+'products?category='+category+'&filter='+sorttype;
    window.location.href = url;
    

  }
var a;
var b;
function togglelist(e, id) {

    var el = document.getElementById(id);
    if ((a != undefined) && (b != null) && (a != el)) {
        a.style.display = 'none';
        b.innerHTML = '+';
    }
    if (el.style.display != 'none') {
        el.style.display = 'none';
        e.currentTarget.children[1].innerHTML = '+';
    } else {
        el.style.display = '';
        e.currentTarget.children[1].innerHTML = '-';
    }
    a = el;
    b = e.currentTarget.children[1];
}

function checkShipping(){
  debugger;
  var itemId ;
  var color = document.getElementById('color');
  if(color = null){
   itemId = (color.options[color.selectedIndex].value); 
  }else{
    itemId = items[0].id;
  }
  var pincode = document.getElementById('pincode').value;
  if(pincode.match(/^\d+/) && pincode.length == 6){
    var url = base_url+'productinfo/getDeliveryDetails/'+itemId+'/'+pincode;
  microAjax(url, function(res)
    {
      debugger;
        //console.log(res);
      if(res!='')
      {
        data = JSON.parse(res);
        days = data.business_days;
        if(days >= 0){
          document.getElementById('service').style.display = 'block';
          document.getElementById('error').style.display = 'none';
          if(document.getElementById('delivery'))
            document.getElementById('delivery').innerHTML = data.delivery_estimate;
          if(document.getElementById('cod')){
            if(data.is_cod_available_for_location == true){
              document.getElementById('cod').innerHTML = 'Cash On Delivery';
            }
          }
          if(data.on_time_guarantee == true){
            if(document.getElementById('guarantee').style.display == 'none'){
              document.getElementById('guarantee').style.display == 'block';
            }
            //document.getElementById('guarantee').innerHTML = 'Yes';
          }
            
        }else{
          document.getElementById('service').style.display = 'none';
          document.getElementById('error').style.display = 'block';
          document.getElementById('error').innerHTML = 'Location is not serviceable'
        } 
      }
    });
  }else{
      document.getElementById('error').style.display = 'block';
      document.getElementById('error').innerHTML = 'Invalid pincode!'
  }
}
function updateColor(value){
    debugger;
    if(document.getElementById('error').style.display == "block"){
      document.getElementById('error').style.display = "none";
    }
        for(i=0;i<items.length;i++){
          if(value.currentTarget.value == items[i].id){
              document.getElementById('buy').innerHTML = items[i].buttonText;
              var buttonText = items[i].buttonText;
              if(buttonText.toUpperCase() == 'NOTIFY ME'){
                document.getElementById('email').style.display = 'block';
              }
              else{
                document.getElementById('email').style.display = 'none';  
              }
              var mrp = parseInt(items[i].mrp);
              if(mrp > 0){
                document.getElementById('mrp').innerHTML = items[i].mrp;
              }
              if(items[i].discount != undefined && parseInt(items[i].discount) >0){
                 document.getElementById('discount').innerHTML = '('+items[i].discount+'% off)'; 
              }
              document.getElementById('sellingPrice').innerHTML = items[i].sellingPrice;
              document.getElementById('emi').innerHTML = ' EMI from Rs. '+items[i].minEmi+' per month';
              checkShipping();
              return false; 
          }
        }
      }
function addToCart(){
  debugger;
  var itemId ;
  var color = document.getElementById('color');
  if(color = null){
   itemId = (color.options[color.selectedIndex].value); 
  }else{
    itemId = items[0].id;
  }
  if(document.getElementById('email').style.display == 'block'){
    var email = document.getElementById('email').value;
    email = email.trim();
      var atpos = email.indexOf("@");
      var dotpos = email.lastIndexOf(".");
      if(email ==''){     
          document.getElementById('error').style.display = "block";
          document.getElementById('error').innerHTML ='Please fill email field!';
          window.scrollTo(0,0); return false;
        }
      if((atpos<1) || (dotpos < atpos+2) || (dotpos+2 >= email.length)){
          document.getElementById('error').style.display = "block";
          document.getElementById('error').innerHTML ='Please fill email in correct format!';
          window.scrollTo(0,0); return false;
      }    
      if(email.length> 50){  
          document.getElementById('error').style.display = "block";
          document.getElementById('error').innerHTML ='Please enter less than 50 characters in email field!';
          window.scrollTo(0,0); return false;
      }
      if(email.indexOf(' ') != -1){  
          document.getElementById('error').style.display = "block";
          document.getElementById('error').innerHTML ='Please remove space from email field!';
          window.scrollTo(0,0); return false;
      }
      var url = base_url+'cart/add/'+itemId+'/'+email;
  }
  else{
    var url = base_url+'cart/add/'+itemId+'/null';
  }
    //window.location.href = url;
    microAjax(url, function(res)
      {
      debugger;
        if(res!='')
        {
          debugger;
          data = JSON.parse(res);
          if(data['addcart'][0].lines != undefined){
            //window.history.replaceState("",document.title, base_url+'cart');
            ga('send', 'event', 'Order', 'Add To Cart',itemId);
            var ua = navigator.userAgent.toLowerCase();
            var isIE = ua.indexOf('msie') !== -1;
            if (isIE){
              window.location.replace(base_url+'cart');
            }else{
              window.location.href = base_url+'cart';
            }
          }else if(data['addcart'][0].message != undefined){
            message = data['addcart'][0].message;
            document.getElementById('error').style.display = "block";
            document.getElementById('error').innerHTML = message;
            window.scrollTo(0,0);
          }
        }
      });
}
function clearError(){
  if(document.getElementById('error').style.display == "block"){
    document.getElementById('error').style.display = "none";
  }
}
function trackAccessories(title){
debugger;
ga('send', 'event', 'Widget', 'Accessory Click', title);
}