Subversion Repositories SmartDukaan

Rev

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


var lastId;
function failedDetails(e){
        debugger;
        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';
        }
        document.getElementById('cancellationForm').style.display = 'block';
        document.getElementsByClassName('update-address')[0].style.display = 'none';
  }
  function hideForm(){
  document.getElementById('cancellationForm').style.display = 'none';
  }
function submitForm(){
        debugger;
        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;
        if(awb == ''){
                awb = 'null';
        }
        var url = base_url+'myaccount/contact/'+encodeURIComponent(email)+'/'+orderId+'/'+encodeURIComponent(subject)+'/'+encodeURIComponent(message)+'/'+encodeURIComponent(awb);
        microAjax(url, function (res) {
                debugger;
                if(res != ''){
                        var data = JSON.parse(res);
                        if(data['response'].status == 'SUCCESS'){
                                document.getElementById('status').innerHTML = data['response'].message;
                        }
                        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(){
        debugger;
        var url = base_url+'myaccount/showAddress';
        microAjax(url, function (res) {
                debugger;
                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;
                }
        }); 
}
var pinCode;
function changeAddress(addressId,type,pincode){
   debugger;
  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(){
        debugger;
        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(parseInt(days) < 0){
                alert('This location is not servicable')
        }else if(parseInt(days) > 0){
                Days = days;
            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';
        } 
      }
    });
}
function deliveryAddress(){
        debugger;
        var url = base_url+'myaccount/modifyAddress/'+orderId+'/'+defaultAddress+'/'+Days;
         microAjax(url, function(res)
    {
      debugger;
        //console.log(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 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(){
        debugger;
  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('error1').style.display = "block";
        document.getElementById('error1').innerHTML ='Please fill name field!';
        window.scrollTo(0,0); return false;}
  // if(!fname.match(/^[a-zA-Z]+$/))
  //     {   
  //       document.getElementById('error').style.display = "block";
  //       document.getElementById('errorcode').innerHTML ='Please fill Alphabets Only In First Name!';
  //       window.scrollTo(0,0); return false;}  
  if(fname.length> 50)
      {   
        document.getElementById('error1').style.display = "block";
        document.getElementById('error1').innerHTML ='Please Enter Less Than 50 Characters in name field!';
        window.scrollTo(0,0); return false;}
  if(street1 =='')
      {   
        document.getElementById('error1').style.display = "block";
        document.getElementById('error1').innerHTML ='Please fill address field!';
        window.scrollTo(0,0); return false;}
  if(city =='')
      {   
        document.getElementById('error1').style.display = "block";
        document.getElementById('error1').innerHTML ='Please fill City field!';
        window.scrollTo(0,0); return false;}
  if(state =='')
      {   
        document.getElementById('error1').style.display = "block";
        document.getElementById('error1').innerHTML ='Please fill state field!';
        window.scrollTo(0,0); return false;}
  if(zipcode =='')
      {   
        document.getElementById('error1').style.display = "block";
        document.getElementById('error1').innerHTML ='Please fill pincode field!';
        window.scrollTo(0,0); return false;}
  if(zipcode.length !=6)
      {   
        document.getElementById('error1').style.display = "block";
        document.getElementById('error1').innerHTML ='Pincode should be 6 digits long';
        window.scrollTo(0,0); return false;}
  if(!zipcode.match(/^\d+/))
      {   
        document.getElementById('error1').style.display = "block";
        document.getElementById('error1').innerHTML ='Please Use numbers only for pincode!';
        window.scrollTo(0,0); return false;}
  if(phone =='')
      {   
        document.getElementById('error1').style.display = "block";
        document.getElementById('error1').innerHTML ='Please fill phone number field!';
        window.scrollTo(0,0); return false;}
  if(!phone.match(/^\d+/))
        {    document.getElementById('error1').style.display = "block";
          document.getElementById('error1').innerHTML ='Please Use numbers only for Mobile Number!';
          window.scrollTo(0,0); return false;}
  if(phone.length != 10)
        {    document.getElementById('error1').style.display = "block";
          document.getElementById('error1').innerHTML ='Mobile number should be of 10 digits!';
          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) {
                debugger;
                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;
                }
        }); 
}