Subversion Repositories SmartDukaan

Rev

Rev 11938 | Blame | Compare with Previous | Last modification | View Log | RSS feed

var pheight = Math.max(document.documentElement.clientHeight, window.innerHeight || 0);
if(document.getElementsByClassName('faq-hldr')[0] != undefined){
    document.getElementsByClassName('faq-hldr')[0].style.minHeight = pheight - 130 +'px';  
}

var lastId;
// function failedDetails(e){
  // 
  // var currentId = e.currentTarget;
  // currentId = currentId.getAttribute('data-key');
  // //document.getElementById(currentId).style.display = 'block';
  // if(lastId == undefined){
    // //document.getElementById(lastId).style.display = 'none';
    // lastId = currentId;
  // }else if(currentId != lastId){
    // document.getElementById(lastId).style.display = 'none';
    // lastId = currentId;
  // }else if(currentId == lastId){
    // document.getElementById(currentId).style.display = 'none';
    // lastId = undefined;
  // }
// }
  function myWallet(){
  window.location.href = base_url+'my-wallet';
  }
  function Order(){
  window.location.href = base_url+'my-orders';
  }
  function showForm(){
  if( document.getElementsByClassName('address-form')[0].style.display == 'block'){
     document.getElementsByClassName('address-form')[0].style.display = 'none';
  }else
    document.getElementById('cancellationForm').style.display = 'block';
    document.getElementById('request-btn').style.display = 'none';
    document.getElementsByClassName('update-address')[0].style.display = 'none';
  }
  
  function hideForm(){
  document.getElementById('cancellationForm').style.display = 'none';
  document.getElementById('request-btn').style.display = 'block';
  }
function submitForm(){
  
  var email = document.getElementById('email').value;
  var orderId = document.getElementById('orderId').value;
  var subject = document.getElementById('subject').value;
  var message = document.getElementById('message').value;
  var awb = document.getElementById('awb').value;
  var atpos = email.indexOf("@");
    var dotpos = email.lastIndexOf(".");
  if(awb == ''){
    awb = 'null';
  }
  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(!removeScript(email))
      {   
        document.getElementById('error').style.display = "block";
        document.getElementById('error').innerHTML ='Please remove script tags!';
        window.scrollTo(0,0); return false;}
  if(subject =='')
    {   
      document.getElementById('error').style.display = "block";
      document.getElementById('error').innerHTML ='Please fill reason field!';
      window.scrollTo(0,0); return false;}
  if(!removeScript(subject))
    {   
      document.getElementById('error').style.display = "block";
      document.getElementById('error').innerHTML ='Please remove script tags!';
      window.scrollTo(0,0); return false;}  
  if(message =='')
  {   
    document.getElementById('error').style.display = "block";
    document.getElementById('error').innerHTML ='Please fill message field!';
    window.scrollTo(0,0); return false;}
  if(!removeScript(message))
    {   
      document.getElementById('error').style.display = "block";
      document.getElementById('error').innerHTML ='Please remove script tags!';
      window.scrollTo(0,0); return false;}

  var url = base_url+'myaccount/contact/'+encodeURIComponent(email)+'/'+orderId+'/'+encodeURIComponent(subject)+'/'+encodeURIComponent(message)+'/'+encodeURIComponent(awb);
  microAjax(url, function (res) {
    
    if(res != ''){
      var data = JSON.parse(res);
      if(data['response'].status == 'SUCCESS'){
        //window.reload();
        document.getElementById('status').innerHTML = data['response'].message;
        document.getElementById('status').style.color = 'red';
        document.getElementById('cancellationForm').style.display = 'none';
      }
      else if(data['response'].status == 'FAILED'){
        document.getElementById('error').style.display = 'block';
        document.getElementById('error').innerHTML = data['response'].message;
        document.getElementById('cancellationForm').style.display = 'none';
        setTimeout(function(){
               document.getElementById('error').style.display = 'none';
           document.getElementById('error').innerHTML = '';
              },3000);
      }
    }
  });
}
var defaultAddress;
function showAddress(){
  
  var url = base_url+'myaccount/showAddress';
  microAjax(url, function (res) {
    
    if(res != ''){
      document.getElementById('appenddata').innerHTML = res;
      if(document.getElementById('cancellationForm').style.display == 'block'){
        document.getElementById('cancellationForm').style.display = 'none';
      }
      document.getElementsByClassName('address-form')[0].style.display = 'block';
      defaultAddress = document.getElementById('default').value;
      document.getElementById('request-btn').style.display = 'none';
    }
  }); 
}
var pinCode;
function changeAddress(addressId,type,pincode){
   
  pinCode = pincode;
  document.getElementById(defaultAddress).className = 'deliver-address';
  document.getElementById(addressId).className = 'deliver-address selected-add';
  document.getElementById('addressChange').style.display = 'block';
  defaultAddress = addressId;
}

var Days;
function submitAddress(){
  
  var url = base_url+'productinfo/getDeliveryDetails/'+itemId+'/'+pinCode;
   microAjax(url, function(res)
    {
      if(res!='')
      {
        data = JSON.parse(res);
        days = data.business_days;
        if(parseInt(days) < 0){
          document.getElementById('error').style.display = "block";
        document.getElementById('error').innerHTML ='Location is not serviceable!';
        window.scrollTo(0,0); return false;
        }else if(parseInt(days) > 0){
          Days = days;
            document.getElementsByClassName('delivery_info_cont')[0].style.display = 'block';
            document.getElementById('deliverinfo').innerHTML = 'Delivery to this address will take '+days+' business days. Delivery esitmate '+data.delivery_estimate;
            document.getElementById('deliverinfo').style.display = 'block';
            document.getElementById('deliverSubmit').style.display = 'block';
            document.getElementsByClassName('address-form')[0].style.display = 'none';
        } 
      }
    });
}
function deliveryAddress(){
  
  var url = base_url+'myaccount/modifyAddress/'+orderId+'/'+defaultAddress+'/'+Days;
   microAjax(url, function(res)
    {
      if(res!='')
      {
        var data = JSON.parse(res);
        if(data['response'].status == 'SUCCESS'){
      window.location.href = base_url+'order/'+orderId;
    }else if(data['response'].status == 'FAILURE'){
      alert(data['response'].message);
    }
      }
    });
}

function closeAddress(){
  document.getElementsByClassName('delivery_info_cont')[0].style.display = 'none';
  document.getElementById('request-btn').style.display = 'block';
  document.getElementsByClassName('address-form')[0].style.display = 'none';
}

function showAddressForm(){
  if(document.getElementsByClassName('update-address')[0].style.display == 'block'){
    document.getElementsByClassName('update-address')[0].style.display = 'none';
    document.getElementsByClassName('address-form')[0].style.display = 'block';
  }else{
    document.getElementsByClassName('update-address')[0].style.display = 'block';
    document.getElementsByClassName('address-form')[0].style.display = 'none';
  }
}
function saveAddress(){
  
  var fname = document.getElementById("name").value;
  var street1 = document.getElementById("line1").value;
  var street2 = document.getElementById("line2").value;
  var city = document.getElementById("city").value;
  var state = document.getElementById("state");
  state = state.options[state.selectedIndex].text;
  var zipcode = document.getElementById("pincode").value; 
  var phone = document.getElementById("phone").value;
if(fname =='')
      {   
        document.getElementById('error').style.display = "block";
        document.getElementById('error').innerHTML ='Please fill name field!';
        window.scrollTo(0,0); return false;}
  if(!removeScript(fname))
      {   
        document.getElementById('error').style.display = "block";
        document.getElementById('error').innerHTML ='Please remove script tags!';
        window.scrollTo(0,0); return false;}  
  if(fname.length> 50)
      {   
        document.getElementById('error').style.display = "block";
        document.getElementById('error').innerHTML ='Please Enter Less Than 50 Characters in name field!';
        window.scrollTo(0,0); return false;}
  if(fname !== fname.trim())
      {   
        document.getElementById('error').style.display = "block";
        document.getElementById('error').innerHTML ='Please remove excess whitespaces from name field!';
        window.scrollTo(0,0); return false;}
  if(fname !== fname.replace(/\s+/g, ' '))
      {   
        document.getElementById('error').style.display = "block";
        document.getElementById('error').innerHTML ='Please remove excess whitespaces from name field!';
        window.scrollTo(0,0); return false;}
  if(street1 =='')
      {   
        document.getElementById('error').style.display = "block";
        document.getElementById('error').innerHTML ='Please fill address field!';
        window.scrollTo(0,0); return false;}
  if(street1 != street1.trim())
      {   
        document.getElementById('error').style.display = "block";
        document.getElementById('error').innerHTML ='Please remove excess whitespaces from address field!';
        window.scrollTo(0,0); return false;}
  if(street1 != street1.replace(/\s+/g, ' '))
      {   
        document.getElementById('error').style.display = "block";
        document.getElementById('error').innerHTML ='Please remove excess whitespaces from address field!';
        window.scrollTo(0,0); return false;}
  if(!removeScript(street1))
      {   
        document.getElementById('error').style.display = "block";
        document.getElementById('error').innerHTML ='Please remove script tags!';
        window.scrollTo(0,0); return false;}
  if(street2 != street2.trim())
      {   
        document.getElementById('error').style.display = "block";
        document.getElementById('error').innerHTML ='Please remove excess whitespaces from address field!';
        window.scrollTo(0,0); return false;}
  if(street2 != street2.replace(/\s+/g, ' '))
      {   
        document.getElementById('error').style.display = "block";
        document.getElementById('error').innerHTML ='Please remove excess whitespaces from address field!';
        window.scrollTo(0,0); return false;}
  if(!removeScript(street2))
      {   
        document.getElementById('error').style.display = "block";
        document.getElementById('error').innerHTML ='Please remove script tags!';
        window.scrollTo(0,0); return false;}
  if(state =='Select State' || state == ' ')
      {   
        document.getElementById('error').style.display = "block";
        document.getElementById('error').innerHTML ='Please fill state field!';
        window.scrollTo(0,0); return false;}
  if(!removeScript(state))
      {   
        document.getElementById('error').style.display = "block";
        document.getElementById('error').innerHTML ='Please remove script tags!';
        window.scrollTo(0,0); return false;}
  if(city =='')
      {   
        document.getElementById('error').style.display = "block";
        document.getElementById('error').innerHTML ='Please fill City field!';
        window.scrollTo(0,0); return false;}
  if(!removeScript(city))
      {   
        document.getElementById('error').style.display = "block";
        document.getElementById('error').innerHTML ='Please remove script tags!';
        window.scrollTo(0,0); return false;}
  if(city != city.trim())
      {   
        document.getElementById('error').style.display = "block";
        document.getElementById('error').innerHTML ='Please remove excess whitespaces from city!';
        window.scrollTo(0,0); return false;}
  if(city != city.replace(/\s+/g, ' '))
      {   
        document.getElementById('error').style.display = "block";
        document.getElementById('error').innerHTML ='Please remove excess whitespaces from city!';
        window.scrollTo(0,0); return false;}
  if(zipcode =='')
      {   
        document.getElementById('error').style.display = "block";
        document.getElementById('error').innerHTML ='Please fill pincode field!';
        window.scrollTo(0,0); return false;}
  if(zipcode.length !=6)
      {   
        document.getElementById('error').style.display = "block";
        document.getElementById('error').innerHTML ='Pincode should be 6 digits long';
        window.scrollTo(0,0); return false;}
  if(!/^\d+$/.test(zipcode))
      {   
        document.getElementById('error').style.display = "block";
        document.getElementById('error').innerHTML ='Please Use numbers only for pincode!';
        window.scrollTo(0,0); return false;}
  if(zipcode != zipcode.trim())
      {   
        document.getElementById('error').style.display = "block";
        document.getElementById('error').innerHTML ='Please remove excess whitespaces from pincode!';
        window.scrollTo(0,0); return false;}
  if(zipcode != zipcode.replace(/\s+/g, ' '))
      {   
        document.getElementById('error').style.display = "block";
        document.getElementById('error').innerHTML ='Please remove excess whitespaces from pincode!';
        window.scrollTo(0,0); return false;}
  if(phone =='')
      {   
        document.getElementById('error').style.display = "block";
        document.getElementById('error').innerHTML ='Please fill phone number field!';
        window.scrollTo(0,0); return false;}
  if(!/^\d+$/.test(phone))
        {    document.getElementById('error').style.display = "block";
          document.getElementById('error').innerHTML ='Please Use numbers only for Mobile Number!';
          window.scrollTo(0,0); return false;}
  if(phone.length != 10)
        {    document.getElementById('error').style.display = "block";
          document.getElementById('error').innerHTML ='Mobile number should be of 10 digits!';
          window.scrollTo(0,0); return false;}
  if(phone != phone.trim())
      {   
        document.getElementById('error').style.display = "block";
        document.getElementById('error').innerHTML ='Please remove excess whitespaces from phone number!';
        window.scrollTo(0,0); return false;}
  if(phone != phone.replace(/\s+/g, ' '))
      {   
        document.getElementById('error').style.display = "block";
        document.getElementById('error').innerHTML ='Please remove excess whitespaces from phone number!';
        window.scrollTo(0,0); return false;}
    var url = base_url+'myaccount/saveAddress/'+encodeURIComponent(fname)+'/'+encodeURIComponent(street1)+'/'+encodeURIComponent(street2)+'/'+encodeURIComponent(city)+'/'+encodeURIComponent(state)+'/'+encodeURIComponent(zipcode)+'/'+encodeURIComponent(phone);
    microAjax(url, function (res) {
    
    if(res != ''){
      document.getElementById('appenddata').innerHTML = res;
      if(document.getElementById('cancellationForm').style.display == 'block'){
        document.getElementById('cancellationForm').style.display = 'none';
      }
      document.getElementsByClassName('address-form')[0].style.display = 'block';
      document.getElementsByClassName('update-address')[0].style.display = 'none';
      defaultAddress = document.getElementById('default').value;
    }
  }); 
}
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') {
        e.currentTarget.className = "sub-head";
        el.style.display = 'none';
        e.currentTarget.children[0].innerHTML = '+';
    } else {
        el.style.display = '';
        e.currentTarget.className += " selected";
        e.currentTarget.children[0].innerHTML = '-';
    }
    a = el;
    b = e.currentTarget.children[0];
}
var laste;
function toggleFaq(e){
    
    // if(e.target.className !== e.currentTarget.className ){
      // window.location = base_url+e.target.className;
    // }
    //else{
    if((laste != undefined) && (laste.nextElementSibling != e.currentTarget.nextElementSibling)){
      laste.nextElementSibling.style.display = 'none';
      laste.children[0].innerHTML = '+';
    }
    if(e.currentTarget.nextElementSibling.style.display != 'block'){
      e.currentTarget.nextElementSibling.style.display = 'block';
      e.currentTarget.children[0].innerHTML = '-';
    }else{
      e.currentTarget.nextElementSibling.style.display = 'none';
      e.currentTarget.children[0].innerHTML = '+';
    }
    laste = e.currentTarget;
  //}
}

function showMoreDeals(){
        window.location.href = base_url+"private-deals/1";
}

function quickAddToCart(id,catalogId){
        var email = document.getElementById("email").value;
        email = email.trim();
        var url = base_url+'cart/add/'+id+'/'+email+'/'+catalogId;
        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',id);
            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){
              window.location.href=base_url+document.getElementById(id+"-url").value;   
          }
        }
        });
}