Subversion Repositories SmartDukaan

Rev

Rev 12524 | 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(){
  
  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;
  pincode = pincode.trim();
  if(/^\d+$/.test(pincode) && pincode.length == 6){
    var url = base_url+'productinfo/getDeliveryDetails/'+itemId+'/'+pincode;
  microAjax(url, function(res)
    {
      
        //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('error1'))
          document.getElementById('error1').style.display = 'none';
          if(document.getElementById('delivery')){
            for(i=0;i<items.length;i++){
              if(items[i].id == itemId){
                if(items[i].comingSoon != undefined && items[i].comingSoon == true){
                  document.getElementById('delivery').innerHTML = data.delivery_estimate+' after arrival';
                }else{
                  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('error1').style.display = 'block';
          //document.getElementById('error').innerHTML = 'Location is not serviceable';
        } 
      }
    });
  }else{
      if(checkPincode != true){
        document.getElementById('error').style.display = 'block';
        document.getElementById('error').innerHTML = 'Invalid pincode!'
      }
  }
}
function hideDealInfo(){
        document.getElementById('dealpricediv').style.display = 'none';
        if(document.getElementById('offertext')!=undefined){
                document.getElementById('offertext').style.display = 'none';
        }
        //document.getElementById('couponcodediv').style.display = 'none';
        document.getElementById('discount').style.display = 'inline-block';
        document.getElementById('sellingPrice').className = "";
}
function showDealInfo(){
        document.getElementById('dealpricediv').style.display = 'block';
        if(document.getElementById('offertext')!=undefined){
                document.getElementById('offertext').style.display = 'block';
        }
        //document.getElementById('couponcodediv').style.display = 'block';
        document.getElementById('sellingPrice').className = "strike";
        document.getElementById('discount').style.display = 'none';
}
var checkPincode;
function updateColor(value){
    
    checkPincode = true;
    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){
              if(!items[i].dealPojo){
                hideDealInfo();
              }else{
                if(privatedealuser){
                        document.getElementById('dealprice').innerHTML = items[i].dealPrice;    
                        if(document.getElementById('offertext')){
                                document.getElementById('offertext').innerHTML = items[i].dealText;     
                        }       
                        document.getElementById('dealdiscount').innerHTML = items[i].discount;  
                        showDealInfo();
                }
              }
              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);
              var noMrp;
              if(mrp > 0){
                document.getElementById('mrp').innerHTML = items[i].mrp;
              }else{
                noMrp = 1;
                document.getElementById('mrp').innerHTML = '';
              }
              if(items[i].discount != undefined && parseInt(items[i].discount) >0){
                 document.getElementById('discount').innerHTML = '('+items[i].discount+'% off)'; 
              }
              if(parseInt(items[i].sellingPrice) > 0){
                document.getElementById('rs').innerHTML = 'Rs';
                document.getElementById('sellingPrice').innerHTML = items[i].sellingPrice;
              }else{
                document.getElementById('sellingPrice').innerHTML = '';
                if(noMrp == 1){
                  document.getElementById('rs').innerHTML = '';
                }else{
                  document.getElementById('rs').innerHTML = 'Rs';
                }
              }
              if(items[i].minEmi != undefined && parseInt(items[i].minEmi) >0){
                document.getElementById('emi').innerHTML = ' EMI from Rs. '+items[i].minEmi+' per month';
              }
              if(items[i].comingSoon != undefined && items[i].comingSoon == true){
               document.getElementById('comingSoon').style.display = 'block'; 
              }else{
                document.getElementById('comingSoon').style.display = 'none';
              }
              checkShipping();
              checkPincode = false;
              return false; 
          }
        }
      }
function addToCart(){
  
  var itemId ;
  var color = document.getElementById('color');
  if(color != null){
   itemId = (color.options[color.selectedIndex].value); 
  }else{
    itemId = items[0].id;
  }
  var url = document.URL;
  url = url.split('-');
  itemName = url.pop();
  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+'/'+itemName;
  }
  else{
    var url = base_url+'cart/add/'+itemId+'/null'+'/'+itemName;
  }
    //window.location.href = url;
    microAjax(url, function(res)
      {
      
        if(res!='')
        {
          
          data = JSON.parse(res);
          if(data['addcart'][0].redirectUrl != undefined && data['addcart'][0].redirectUrl != ''){
            //window.history.replaceState("",document.title, base_url+'cart');
            /*if(typeof _gaq != "undefined" && _gaq != null)  {
              _gaq.push(['_trackEvent', 'Order', 'Add To Cart',itemId]);
            }*/
        ga('send', 'event', 'Order', 'Add To Cart',itemId);
            var ua = navigator.userAgent.toLowerCase();
            var redirectUrl = data['addcart'][0].redirectUrl;
            var isIE = ua.indexOf('msie') !== -1;
            if (isIE){
              window.location.replace(base_url+redirectUrl);
            }else{
              window.location.href = base_url+redirectUrl;
            }
          }else if(data['addcart'][0].message != undefined){
            message = data['addcart'][0].message;
            document.getElementById('buy').innerHTML = "NOTIFY ME";
            document.getElementById('error').style.display = "block";
            document.getElementById('email').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){

/*if(typeof _gaq != "undefined" && _gaq != null)  {
    _gaq.push(['_trackEvent', 'Widget', 'Accessory Click', title]);
  }*/
        ga('send', 'event', 'Widget', 'Accessory Click',title);
}