1/** 2* Calculate shipping; called on submit. 3* This function decide which method to call to calculate the shipping charge. 4*/ 5$(function() { 6 var selectValues = { 7 "From Countries": { 8 "To Countries": "", 9 }, 10 "AU": { 11 "To Countries": "", 12 "Malaysia": "MY", 13 "Singapore": "SG", 14 "Thailand": "TH", 15 "South Korea": "KR", 16 "Hong Kong": "HK", 17 "Other Countries": "OCC", 18 }, 19 "FR": { 20 "To Countries": "", 21 "Australia": "AU", 22 "Malaysia": "MY", 23 "Singapore": "SG", 24 "Thailand": "TH", 25 "South Korea": "KR", 26 "Hong Kong": "HK", 27 "Other Countries": "OCC", 28 }, 29 "HK": { 30 "To Countries": "", 31 "Australia": "AU", 32 "Malaysia": "MY", 33 "Singapore": "SG", 34 "Thailand": "TH", 35 "South Korea": "KR", 36 "Other Countries": "OCC", 37 }, 38 "IT": { 39 "To Countries": "", 40 "Australia": "AU", 41 "Malaysia": "MY", 42 "Singapore": "SG", 43 "Thailand": "TH", 44 "South Korea": "KR", 45 "Hong Kong": "HK", 46 "Other Countries": "OCC", 47 }, 48 "JP": { 49 "To Countries": "", 50 "Australia": "AU", 51 "Malaysia": "MY", 52 "Singapore": "SG", 53 "Thailand": "TH", 54 "South Korea": "KR", 55 "Hong Kong": "HK", 56 "Other Countries": "OCC", 57 }, 58 "KR": { 59 "To Countries": "", 60 "Australia": "AU", 61 "Malaysia": "MY", 62 "Singapore": "SG", 63 "Thailand": "TH", 64 "Hong Kong": "HK", 65 "Other Countries": "OCC", 66 }, 67 "MY": { 68 "To Countries": "", 69 "Australia": "AU", 70 "Singapore": "SG", 71 "Thailand": "TH", 72 "South Korea": "KR", 73 "Hong Kong": "HK", 74 "Other Countries": "OCC", 75 }, 76 "SG": { 77 "To Countries": "", 78 "Australia": "AU", 79 "Malaysia": "MY", 80 "Thailand": "TH", 81 "South Korea": "KR", 82 "Hong Kong": "HK", 83 "Other Countries": "OCC", 84 }, 85 "TH": { 86 "To Countries": "", 87 "Australia": "AU", 88 "Singapore": "SG", 89 "Malaysia": "MY", 90 "South Korea": "KR", 91 "Hong Kong": "HK", 92 "Other Countries": "OCC", 93 }, 94 "GB": { 95 "To Countries": "", 96 "Australia": "AU", 97 "Malaysia": "MY", 98 "Singapore": "SG", 99 "Thailand": "TH", 100 "South Korea": "KR", 101 "Hong Kong": "HK", 102 "Other Countries": "OCC", 103 }, 104 "US": { 105 "To Countries": "", 106 "Afghanistan":"AF", 107 "à land Islands":"AX", 108 "Albania":"AL", 109 "Algeria":"DZ", 110 "American Samoa":"AS", 111 "Andorra":"AD", 112 "Angola":"AO", 113 "Anguilla":"AI", 114 "Antarctica":"AQ", 115 "Antigua and Barbuda":"AG", 116 "Argentina":"AR", 117 "Armenia":"AM", 118 "Aruba":"AW", 119 "Australia":"AU", 120 "Austria":"AT", 121 "Azerbaijan":"AZ", 122 "Bahamas":"BS", 123 "Bahrain":"BH", 124 "Bangladesh":"BD", 125 "Barbados":"BB", 126 "Belarus":"BY", 127 "Belgium":"BE", 128 "Belize":"BZ", 129 "Benin":"BJ", 130 "Bermuda":"BM", 131 "Bhutan":"BT", 132 "Bolivia":" BO", 133 "Bonaire":" BQ", 134 "Bosnia and Herzegovina":"BA", 135 "Botswana":"BW", 136 "Bouvet Island":"BV", 137 "Brazil":"BR", 138 "British Indian Ocean Territory":"IO", 139 "Brunei Darussalam":"BN", 140 "Bulgaria":"BG", 141 "Burkina Faso":"BF", 142 "Burundi":"BI", 143 "Cambodia":"KH", 144 "Cameroon":"CM", 145 "Canada":"CA", 146 "Cape Verde":"CV", 147 "Cayman Islands":"KY", 148 "Central African Republic":"CF", 149 "Chad":"TD", 150 "Chile":"CL", 151 "China":"CN", 152 "Christmas Island":"CX", 153 "Cocos (Keeling) Islands":"CC", 154 "Colombia":"CO", 155 "Comoros":"KM", 156 "Congo":"CG", 157 "Congo":" CD", 158 "Cook Islands":"CK", 159 "Costa Rica":"CR", 160 "Côte d'Ivoire":"CI", 161 "Croatia":"HR", 162 "Cuba":"CU", 163 "Curaçao":"CW", 164 "Cyprus":"CY", 165 "Czech Republic":"CZ", 166 "Denmark":"DK", 167 "Djibouti":"DJ", 168 "Dominica":"DM", 169 "Dominican Republic":"DO", 170 "Ecuador":"EC", 171 "Egypt":"EG", 172 "El Salvador":"SV", 173 "Equatorial Guinea":"GQ", 174 "Eritrea":"ER", 175 "Estonia":"EE", 176 "Ethiopia":"ET", 177 "Falkland Islands (Malvinas)":"FK", 178 "Faroe Islands":"FO", 179 "Fiji":"FJ", 180 "Finland":"FI", 181 "France":"FR", 182 "French Guiana":"GF", 183 "French Polynesia":"PF", 184 "French Southern Territories":"TF", 185 "Gabon":"GA", 186 "Gambia":"GM", 187 "Georgia":"GE", 188 "Germany":"DE", 189 "Ghana":"GH", 190 "Gibraltar":"GI", 191 "Greece":"GR", 192 "Greenland":"GL", 193 "Grenada":"GD", 194 "Guadeloupe":"GP", 195 "Guam":"GU", 196 "Guatemala":"GT", 197 "Guernsey":"GG", 198 "Guinea":"GN", 199 "Guinea-Bissau":"GW", 200 "Guyana":"GY", 201 "Haiti":"HT", 202 "Heard Island and McDonald Islands":"HM", 203 "Holy See (Vatican City State)":"VA", 204 "Honduras":"HN", 205 "Hong Kong":"HK", 206 "Hungary":"HU", 207 "Iceland":"IS", 208 "India":"IN", 209 "Indonesia":"ID", 210 "Iran":" IR", 211 "Iraq":"IQ", 212 "Ireland":"IE", 213 "Isle of Man":"IM", 214 "Israel":"IL", 215 "Italy":"IT", 216 "Jamaica":"JM",
217 "Japan":"JP", 218 "Jersey":"JE", 219 "Jordan":"JO", 220 "Kazakhstan":"KZ", 221 "Kenya":"KE", 222 "Kiribati":"KI", 223 "South Korea":"KR", 224 "Kuwait":"KW", 225 "Kyrgyzstan":"KG", 226 "Lao People's Democratic Republic":"LA", 227 "Latvia":"LV", 228 "Lebanon":"LB", 229 "Lesotho":"LS", 230 "Liberia":"LR", 231 "Libya":"LY", 232 "Liechtenstein":"LI", 233 "Lithuania":"LT", 234 "Luxembourg":"LU", 235 "Macao":"MO", 236 "Macedonia":" MK", 237 "Madagascar":"MG", 238 "Malawi":"MW", 239 "Malaysia":"MY", 240 "Maldives":"MV", 241 "Mali":"ML", 242 "Malta":"MT", 243 "Marshall Islands":"MH", 244 "Martinique":"MQ", 245 "Mauritania":"MR", 246 "Mauritius":"MU", 247 "Mayotte":"YT", 248 "Mexico":"MX", 249 "Micronesia":" FM", 250 "Moldova":" MD", 251 "Monaco":"MC", 252 "Mongolia":"MN", 253 "Montenegro":"ME", 254 "Montserrat":"MS", 255 "Morocco":"MA", 256 "Mozambique":"MZ", 257 "Myanmar":"MM", 258 "Namibia":"NA", 259 "Nauru":"NR", 260 "Nepal":"NP", 261 "Netherlands":"NL", 262 "New Caledonia":"NC", 263 "New Zealand":"NZ", 264 "Nicaragua":"NI", 265 "Niger":"NE", 266 "Nigeria":"NG", 267 "Niue":"NU", 268 "Norfolk Island":"NF", 269 "Northern Mariana Islands":"MP", 270 "Norway":"NO", 271 "Oman":"OM", 272 "Pakistan":"PK", 273 "Palau":"PW", 274 "Palestinian Territory":" PS", 275 "Panama":"PA", 276 "Papua New Guinea":"PG", 277 "Paraguay":"PY", 278 "Peru":"PE", 279 "Philippines":"PH", 280 "Pitcairn":"PN", 281 "Poland":"PL", 282 "Portugal":"PT", 283 "Puerto Rico":"PR", 284 "Qatar":"QA", 285 "Réunion":"RE", 286 "Romania":"RO", 287 "Russian Federation":"RU", 288 "Rwanda":"RW", 289 "Saint Barthélemy":"BL", 290 "Saint Helena":" SH", 291 "Saint Kitts and Nevis":"KN", 292 "Saint Lucia":"LC", 293 "Saint Pierre and Miquelon":"PM", 294 "Saint Vincent and the Grenadines":"VC", 295 "Samoa":"WS", 296 "San Marino":"SM", 297 "Sao Tome and Principe":"ST", 298 "Saudi Arabia":"SA", 299 "Senegal":"SN", 300 "Serbia":"RS", 301 "Seychelles":"SC", 302 "Sierra Leone":"SL", 303 "Singapore":"SG", 304 "Sint Maarten (Dutch part)":"XM", 305 "Slovakia":"SK", 306 "Slovenia":"SI", 307 "Solomon Islands":"SB", 308 "Somalia":"SO", 309 "South Africa":"ZA", 310 "South Georgia and the South Sandwich Islands":"GS", 311 "South Sudan":"SS", 312 "Spain":"ES", 313 "Sri Lanka":"LK", 314 "Sudan":"SD", 315 "Suriname":"SR", 316 "Svalbard and Jan Mayen":"SJ", 317 "Swaziland":"SZ", 318 "Sweden":"SE", 319 "Switzerland":"CH", 320 "Syrian Arab Republic":"SY", 321 "Taiwan":" TW", 322 "Tajikistan":"TJ", 323 "Tanzania":" TZ", 324 "Thailand":"TH", 325 "Timor-Leste":"TL", 326 "Togo":"TG", 327 "Tokelau":"TK", 328 "Tonga":"TO", 329 "Trinidad and Tobago":"TT", 330 "Tunisia":"TN", 331 "Turkey":"TR", 332 "Turkmenistan":"TM", 333 "Turks and Caicos Islands":"TC", 334 "Tuvalu":"TV", 335 "Uganda":"UG", 336 "Ukraine":"UA", 337 "United Arab Emirates":"AE", 338 "United Kingdom":"GB", 339 "United States":"US", 340 "United States Minor Outlying Islands":"UM", 341 "Uruguay":"UY", 342 "Uzbekistan":"UZ", 343 "Vanuatu":"VU", 344 "Venezuela":" VE", 345 "Viet Nam":"VN", 346 "Virgin Islands":" VG", 347 "Virgin Islands":" VI", 348 "Wallis and Futuna":"WF", 349 "Western Sahara":"EH", 350 "Yemen":"YE", 351 "Zambia":"ZM", 352 "Zimbabwe":"ZW", 353 354 }, 355 356 }; 357
358 var $vendor = $('#CountryFrom'); 359 var $model = $('#countryTo'); 360 $vendor.change(function() { 361 $model.empty().append(function() { 362 if ($('#CountryFrom').val()=='Other Countries'){ 363 alert('ShopandBox is currently working hard to secure discounted shipping rates for the rest of the world. Please communicate with your Boxer who will provide you with a shipping quote or ask us via the Contact Us page.'); 364 } 365 if ($('#countryTo').val()=='OCC'){ 366 alert('ShopandBox is currently working hard to secure discounted shipping rates for the rest of the world. Please communicate with your Boxer who will provide you with a shipping quote or ask us via the Contact Us page.'); 367 } 368 //HK Disabler or Enabler 369 var output = ''; 370 $.each(selectValues[$vendor.val()], function(key, value) { 371 output += '<option value="'+value+'">' + key + '</option>'; 372 }); 373 return output; 374 }); 375 }).change(); 376 377 // bonus: how to access the download link 378 $model.change(function() { 379 if ($('#countryTo').val()=='HK'){ 380 $('#zipcodeTo').prop('disabled',true) 381 $('#zipcodeTo').prop('hidden',true) 382 } 383 else{ 384 $('#zipcodeTo').prop('disabled',false) 385 $('#zipcodeTo').prop('hidden',false) 386 } 387 $('#download-link').attr('href', selectValues[$vendor.val()][$model.val()]).show(); 388 }); 389}); 390 391 392// this function is used to decide between place holder and the converiosn for KG 393function converttokg (){ 394 395 var weight = $('[name="weight"]').val(); 396 var length = $('[name="length"]').val(); 397 var width = $('[name="width"]').val(); 398 var height = $('[name="height"]').val(); 399 400 if (weight =="" || length =="" || width =="" || height =="" ) { 401 Placehtokg(); 402 } 403 else 404 { 405 convertToMetric(); 406 } 407} 408 409// this function is used to decide between place holder and the converiosn for Pounds 410function converttoPounds (){ 411 412 var weight = $('[name="weight"]').val(); 413 var length = $('[name="length"]').val(); 414 var width = $('[name="width"]').val(); 415 var height = $('[name="height"]').val(); 416 if (weight =="" || length =="" || width =="" || height =="" ) { 417 418 PlacehtoPounds(); 419 } 420 else 421 { 422 convertToImperial(); 423 } 424} 425 426// this function will make the diplay to metric unit 427function Placehtokg () { 428 var input = document.getElementById ("weight"); 429 input.placeholder = "Weight (Kg)"; 430 var input = document.getElementById ("length"); 431 input.placeholder = "Length (Cm)"; 432 var input = document.getElementById ("width"); 433 input.placeholder = "Width (Cm)"; 434 var input = document.getElementById ("height"); 435 input.placeholder = "Height (Cm)"; 436} 437 438// this function will make the diplay to Ipmerial unit 439function PlacehtoPounds () { 440 var input = document.getElementById ("weight"); 441 input.placeholder = "Weight (Pounds)"; 442 var input = document.getElementById ("length"); 443 input.placeholder = "Length (Inches)"; 444 var input = document.getElementById ("width"); 445 input.placeholder = "Width (Inches)"; 446 var input = document.getElementById ("height"); 447 input.placeholder = "Height (Inches)"; 448} 449 450// this function will convert the unit from imperial to metric 451function convertToMetric(){ 452 453 //Getting the values of the fields 454 var weight = $('[name="weight"]').val(); 455 var length = $('[name="length"]').val(); 456 var width = $('[name="width"]').val(); 457 var height = $('[name="height"]').val(); 458 459 //Conversions done here 460 var convertedWeight = Number(weight /2.2046).toFixed(1); 461 var convertedLength = Number(length / 0.39370).toFixed(1); 462 var convertedWidth = Number(width / 0.39370).toFixed(1); 463 var convertedHeight = Number(height / 0.39370).toFixed(1); 464 465 //Setting the values in the field to the converted name 466 $('[values="weight"]').val(convertedWeight); 467 $('[name="length"]').val(convertedLength); 468 $('[name="width"]').val(convertedWidth); 469 $('[name="height"]').val(convertedHeight); 470 471} 472 473// this function will convert the unit from metric to imperial 474function convertToImperial(){ 475 476 //Getting the values of the fields 477 var weight = $('[name="weight"]').val(); 478 var length = $('[name="length"]').val(); 479 var width = $('[name="width"]').val(); 480 var height = $('[name="height"]').val(); 481 482 //Conversions done here 483 var convertedWeight = Number(weight * 2.2046).toFixed(1); 484 var convertedLength = Number(length * 0.39370).toFixed(1); 485 var convertedWidth = Number(width * 0.39370).toFixed(1); 486 var convertedHeight = Number(height * 0.39370).toFixed(1); 487
488 //Setting the values in the field to the converted values 489 $('[name="weight"]').val(convertedWeight); 490 $('[name="length"]').val(convertedLength); 491 $('[name="width"]').val(convertedWidth); 492 $('[name="height"]').val(convertedHeight); 493} 494function calculateSubmitForm() { 495 496 var CountryFrom = $('#CountryFrom').val(); 497 hideDiscountedPriceExpressDivs(); 498 499 if(CountryFrom == 'United States'){ //Airmail; call the API; 500 calculateShow(); 501 return false; 502 } 503 else{ //Express; get values from csv file 504 if(checktoCountryForExpress() == true){ 505 506 var weight = $('#Weight').val(); 507 //var selWeight = $('#selWeight').val(); 508 var modeAll = $("input:radio[name=selMeasureMethod]:checked").val(); 509 var flagError = false; 510 511 if(isIntFloat(weight) == false){ //not int or float 512 showMsgPopup('Please enter a valid weight!'); 513 return false; 514 } 515 if(weight <= 0){ //less or equal to 0 516 showMsgPopup('Please enter a valid weight!'); 517 return false; 518 } 519 520 //validate weight ; if less then 20kg then process 521 switch(modeAll){ 522 case 'kg_cm': 523 if(weight > 30){ 524 var flagError = true; 525 var showWeight = 30; 526 } 527 break; 528 529 case 'pound_inch': 530 if(weight > 66){ 531 var flagError = true; 532 var showWeight = 66; 533 } 534 break; 535 } 536 537 if(flagError == true){ //more then 20 kg so stop and show the error msg. 538 var eMsg = ''; 539 eMsg += 'For weight over ' + showWeight + ' ' + selWeight + ''; 540 eMsg += ' please contact us via the Contact page for the quote.'; 541 542 showMsgPopup(eMsg); 543 return false; 544 } 545 else{ //less then 20 kg. so show the rate 546 calculateShowFromFile(); 547 return false; 548 } 549 550 } 551 else{ //if express is selected for non applicaple country. 552 var msg = ''; 553 msg += 'Please select appropriate to country.\n'; 554 msg += 'Currently Airmail Express available only to Australia, Malaysia & Singapore.\n'; 555 msg += 'ShopandBox is currently working hard to secure discounted shipping rates for the rest of the world.\n'; 556 msg += 'Please communicate with your Boxer who will provide you with a shipping quote or ask us'; 557 msg += ' via the Contact Us page.'; 558 showMsgPopup(msg); 559 return false; 560 } 561 562 } 563 564 return false; 565 566} 567 568/** 569* Check the from country if it is Express checkout supported or not. 570* Returns true if express checkout else false. 571*/ 572function checkFromCountryForExpress(){ 573 574 var countryFrom = $('#CountryFrom').val(); 575 var fromCountryArray = ['USA|Express', 'UK|Express', 'France|Express']; 576 if(fromCountryArray.indexOf(countryFrom) > -1 ){ //value found 577 return true; 578 } 579 else{ 580 return false 581 } 582 583} 584 585/** 586* Check the to country if it is Express checkout supported or not. 587* Returns true if express checkout else false. 588*/ 589function checktoCountryForExpress(){ 590 591 var CountryTo = $('#toCountryExpress').val(); 592 var toCountryArray = ['Australia', 'Malaysia', 'Singapore']; 593 if(toCountryArray.indexOf(CountryTo) > -1 ){ //value found 594 return true; 595 } 596 else{ 597 return false 598 } 599 600} 601 602/** 603* Ajax call to calculate shipping from csv file. 604*/ 605function calculateShowFromFile() { 606 607 var CountryFrom = $('#CountryFrom').val();
608 var CountryTo = $('#toCountryExpress').val(); 609 var Weight = $('#Weight').val(); 610 611 var Width = $('#Width').val(); 612 var Length = $('#Length').val(); 613 var Height = $('#Height').val(); 614 615 var modeAll = $("input:radio[name=selMeasureMethod]:checked").val(); 616 if(modeAll == 'kg_cm'){ 617 var selWeight = 'kg'; //$('#selWeight').val(); 618 var selWidth = 'cm';//$('#selWidth').val(); 619 var selLength = 'cm';//$('#selLength').val(); 620 var selHeight = 'cm';//$('#selHeight').val(); 621 } 622 else{ 623 var selWeight = 'pound'; 624 var selWidth = 'inch'; 625 var selLength = 'inch'; 626 var selHeight = 'inch'; 627 } 628 629 630 hideDiscountedPriceExpressDivs(); 631 $('#overlayAx').show(); 632 $('#loadingAx').show(); 633 634 $.ajax({ 635 url: "verAjaxFile.php", 636 type: "POST", 637 data: {Weight:Weight, selWeight:selWeight, 638 CountryFrom: CountryFrom, CountryTo:CountryTo, 639 Width:Width, Length:Length, Height:Height, 640 selWidth:selWidth, selLength:selLength, selHeight:selHeight 641 }, 642 dataType: "json", 643 cache: false, 644 beforeSend: function( xhr ) { 645 $('#calculateShowBtn').attr("onClick", ""); 646 showAjaxLoad(); 647 }, 648 success: function (data) { 649 hideAjaxLoad(); 650 console.log(data); 651 652 //show discounted price for malaysia 653 if(CountryTo == 'Malaysia' && checkFromCountryForExpress() == true){ 654 showDiscountedPriceExpressDivs(); 655 $('#discountedPriceExpress').val(data.expressPriceDiscounted); 656 $('#axPMETimeDiscounted').html('Delivery Time: 3 business days.'); 657 } 658 659 $('#airmailInputP').hide(); 660 $('#airmailInputDiv').hide(); 661 $('#PMEInt').val(data.expressPrice); 662 $('#PMInt').val(""); 663 $('#axPMTime').html(''); 664 $('#axPMETime').html('Delivery Time: 3 business days.'); 665 666 }, 667 error: function(data, errorThrown) { 668 hideAjaxLoad(); 669 } 670 }); 671} 672 673/** 674* Show discounted price divs 675*/ 676function showDiscountedPriceExpressDivs(){ 677 $('#discountedPriceMyP').show(); 678 $('#discountedPriceMyDiv').show(); 679} 680 681/** 682* Hide discounted price divs 683*/ 684function hideDiscountedPriceExpressDivs(){ 685 $('#discountedPriceMyP').hide(); 686 $('#discountedPriceMyDiv').hide(); 687} 688 689/** 690* Ajax call to calculate shipping by calling the API 691*/ 692function calculateShow() { 693 694 var Weight = $('#Weight').val();
695 var Country = $('#toCountry').val(); 696 var Width = $('#Width').val(); 697 var Length = $('#Length').val(); 698 var Height = $('#Height').val(); 699 700 /*convert the weight & dimention to pound Inch as the api takes only that method 701 * and make sure weight is in Integer not in decimal. 702 */ 703 var modeAll = $("input:radio[name=selMeasureMethod]:checked").val(); 704 if(modeAll == 'kg_cm'){ //then convert to pound - inch 705 var Weight = weightConvertion(Weight, 'pound'); 706 var Weight = rounditToInt(Weight); //convert the weight to a int for the API 707 var Length = lengthConvertion(Length, 'inch'); 708 var Width = lengthConvertion(Width, 'inch'); 709 var Height = lengthConvertion(Height, 'inch'); 710 } 711 else{ //means already in pound inch; so convetrv the weight to Int, no decimal for the API 712 var Weight = rounditToInt(Weight); 713 } 714 715 $('#overlayAx').show(); 716 $('#loadingAx').show(); 717 $('#airmailInputP').show(); 718 $('#airmailInputDiv').show(); 719 720 $.ajax({ 721 url: "verAjax.php", 722 type: "POST", 723 data: {Weight:Weight, Country:Country, Width:Width, 724 Length:Length, Height:Height 725 }, 726 dataType: "json", 727 cache: false, 728 beforeSend: function( xhr ) { 729 $('#calculateShowBtn').attr("onClick", ""); 730 showAjaxLoad(); 731 }, 732 success: function (data) { 733 if(isIntFloat(data.PMI_PRICE) == true && isIntFloat(data.PMEI_PRICE)){ 734 $('#PMInt').val(data.PMI_PRICE + " USD"); 735 $('#PMEInt').val(data.PMEI_PRICE + " USD"); 736 $('#axPMTime').html('Delivery Time: ' + data.PMI_TIME); 737 $('#axPMETime').html('Delivery Time: ' + data.PMEI_TIME); 738 $('#calculateShowBtn').attr("onClick", "calculateShow();"); 739 hideAjaxLoad(); 740 } 741 else{ 742 $('#calculateShowBtn').attr("onClick", "calculateShow();"); 743 hideAjaxLoad(); 744 showMsgPopup('Something went wrong, Please try again!'); 745 } 746 }, 747 error: function(data, errorThrown) { 748 $('#calculateShowBtn').attr("onClick", "calculateShow();"); 749 hideAjaxLoad(); 750 } 751 }); 752} 753 754/** 755* Show message in popup if country is in US 756*/ 757function checkCountry() { 758 759 var country = $('#CountryFrom').val(); 760 hideDiscountedPriceExpressDivs(); 761 762 if(country == 'United States'){ //Airmail; call the API; 763 $('#toCountryExpressDiv').hide(); 764 $('#toCountryAirmailDiv').show(); 765 addRequiredAttr(); //redo validation in some fields 766 $('#toCountryExpress').removeAttr( "required" ); 767 } 768 else if(country == 'Other Countries') { //no support 769 $('#toCountryExpressDiv').hide(); 770 $('#toCountryAirmailDiv').show(); 771 var msg = ''; 772 msg += 'ShopandBox is currently working hard to secure discounted shipping rates for the rest of the world.\n'; 773 msg += 'Please communicate with your Boxer who will provide you with a shipping quote or ask us'; 774 msg += ' via the Contact Us page.'; 775 showMsgPopup(msg); 776 $('#CountryFrom').val(''); 777 $('#toCountry').attr( "required", "required" ); 778 $('#toCountryExpress').removeAttr( "required" ); 779 } 780 else{ //DHL Express 781 $('#toCountryExpressDiv').show(); 782 $('#toCountryAirmailDiv').hide(); 783 /*if(country == 'Japan|Express'){ //if Japan remove Australia from TO country 784 $("#toCountryExpress option[value='Australia']").remove(); 785 } 786 else{ //if NOT Japan add Australia in TO country if there is not Australia 787 if($("#toCountryExpress option[value='Australia']").val() === undefined) { 788 $("#toCountryExpress option:first").after('<option value="Australia">Australia</option>'); 789 } 790 }*/ 791 removeRequiredAttr(); //remove validation in some fields 792 removeRequiredValue(); //remove values on those fields too 793 $('#toCountryExpress').attr( "required", "required" ); 794 } 795} 796 797/** 798* Remove required attribute to eliminate validation. 799*/ 800function removeRequiredAttr(){ 801 $('#Length').removeAttr( "required" ); 802 $('#Width').removeAttr( "required" ); 803 $('#Height').removeAttr( "required" ); 804 $('#toCountry').removeAttr( "required" ); 805} 806 807/** 808* Add required attribute. 809*/ 810function addRequiredAttr(){ 811 $('#Length').attr( "required", "required" ); 812 $('#Width').attr( "required", "required" ); 813 $('#Height').attr( "required", "required" ); 814 $('#toCountry').attr( "required", "required" ); 815} 816 817/** 818* Remove required attribute to eliminate validation. 819*/ 820function removeRequiredValue(){ 821 $('#Length').val( "" ); 822 $('#Width').val( "" ); 823 $('#Height').val( "" ); 824} 825 826/** 827* Convert Pound to Kg and Kg to Pound 828*/
829function convertWeight() { 830 831 var eleVal = $('#Weight').val(); 832 var m = $('#selWeight').val(); 833 var retVal = eleVal; 834 var hidWeight = $('#hidWeight').val(); 835 836 switch(m) { 837 case "pound": //from kg to pound 838 retVal = eleVal/0.453; 839 break; 840 case "kg": //from pound to kg 841 retVal = eleVal*0.453; 842 break; 843 } 844 $('#hidWeight').val(retVal); 845 $('#Weight').val(roundit(retVal)); 846 847} 848 849/** 850* Convert inch to cm and cm to inch 851*/ 852function convertLength(ele, mode) { 853 854 var m = $('#' + mode).val(); 855 var eleVal = $('#' + ele).val(); 856 var retVal = eleVal; 857 858 switch(m) { 859 case "inch": //from cm to inch 860 retVal = eleVal/2.54; 861 break; 862 case "cm": //from inch to cm 863 retVal = eleVal*2.54; 864 break; 865 } 866 867 $('#' + ele).val(roundit(retVal)); 868 869} 870 871/** 872* Round floating number to two decimal point 873*/ 874function roundit(which) { 875 876 return Math.round(which*100)/100 877 878} 879 880/** 881* Show the popup div with msg and overlay 882*/ 883function showMsgPopup(msg) { 884 $('.dim_bg').show(); 885 $('#msgPopup').html(msg); 886} 887 888/** 889* Hide the popup div with msg and overlay 890*/ 891function hideMsgPopUp(){ 892 $('.dim_bg').hide(); 893} 894 895/** 896* Show the Ajax load div with overlay 897*/ 898function showAjaxLoad(){ 899 $('.loading_image').show(); 900} 901 902/** 903* Hide the Ajax load div with overlay 904*/ 905function hideAjaxLoad(){ 906 $('.loading_image').hide(); 907} 908 909/** 910* check if a number is a float/decimal 911*/ 912function isIntFloat(value){ 913 var RE = /^\d*\.?\d*$/; 914 if(RE.test(value)){ 915 return true; 916 }else{ 917 return false; 918 } 919} 920 921/** 922* for the radio button kg/cm & pound/inch 923*/ 924function convertMeasurement(){ 925 926 var hidModeAll = $('#hidRadMeasureMethod').val(); 927 var modeAll = $("input:radio[name=selMeasureMethod]:checked").val(); 928 929 if(hidModeAll != modeAll){ 930 var modeArray = modeAll.split("_"); 931 var modeWeight = modeArray['0']; 932 var modeDistance = modeArray['1']; 933 934 //weight 935 var inWeight = $('#Weight').val(); 936 var retWeight = weightConvertion(inWeight, modeWeight); 937 if(retWeight > 0){ 938 $('#Weight').val(rounditTo(retWeight)); 939 } 940 941 //Dimension 942 var inLength = $('#Length').val(); 943 var inWidth = $('#Width').val(); 944 var inHeight = $('#Height').val(); 945 946 var retLength = lengthConvertion(inLength, modeDistance); 947 var retWidth = lengthConvertion(inWidth, modeDistance); 948 var retHeight = lengthConvertion(inHeight, modeDistance); 949 950 if(retLength > 0){ 951 $('#Length').val(rounditTo(retLength)); 952 } 953 if(retWidth > 0){ 954 $('#Width').val(rounditTo(retWidth)); 955 } 956 if(retHeight > 0){ 957 $('#Height').val(rounditTo(retHeight)); 958 } 959 960 $('#hidRadMeasureMethod').val(modeAll); 961 962 //change place holder 963 if(modeAll == 'kg_cm'){ 964 placeHolderKgCm(); 965 } 966 if(modeAll == 'pound_inch'){ 967 placeHolderPoundInch(); 968 } 969 970 } 971 972} 973 974/** 975* Change the place holder to Pound Inch 976*/ 977function placeHolderPoundInch(){ 978 $('#Weight').attr( "placeholder", "Weight (Pounds) " ); 979 $('#Length').attr( "placeholder", "Length (Inches)" ); 980 $('#Width').attr( "placeholder", "Width (Inches)" ); 981 $('#Height').attr( "placeholder", "Height (Inches)" ); 982} 983 984/** 985* Change the place holder to KG Cm 986*/ 987function placeHolderKgCm(){ 988 $('#Weight').attr( "placeholder", "Weight (Kg) " ); 989 $('#Length').attr( "placeholder", "Length (Cm)" ); 990 $('#Width').attr( "placeholder", "Width (Cm)" ); 991 $('#Height').attr( "placeholder", "Height (Cm)" ); 992} 993 994/** 995* Convert Pound to Kg and Kg to Pound 996*/ 997function weightConvertion(weight, toMode) { 998 999 var eleVal = weight; 1000 var m = toMode; 1001 var retVal = eleVal; 1002 //var hidWeight = $('#hidWeight').val(); 1003 1004 switch(m) { 1005 case "pound": //from kg to pound 1006 retVal = eleVal/0.453592; 1007 break; 1008 case "kg": //from pound to kg 1009 retVal = eleVal*0.453592; 1010 break; 1011 } 1012 return retVal; 1013 1014} 1015 1016/** 1017* Convert inch to cm and cm to inch 1018*/ 1019function lengthConvertion(l, toMode) { 1020 1021 var m = toMode; 1022 var eleVal = l; 1023 var retVal = eleVal; 1024 1025 switch(m) { 1026 case "inch": //from cm to inch 1027 retVal = eleVal/2.54; 1028 break; 1029 case "cm": //from inch to cm 1030 retVal = eleVal*2.54; 1031 break; 1032 } 1033 1034 return retVal; 1035 1036} 1037 1038/** 1039* round to 2 decimal point 1040*/ 1041function rounditTo(val){ 1042 var valRet = val.toFixed(2); 1043 1044 var modeAll = $("input:radio[name=selMeasureMethod]:checked").val(); 1045 1046 var valArray = valRet.split("."); 1047 var beforeDeci = valArray['0']; 1048 var afterDeci = valArray['1']; 1049 1050 if(afterDeci == 99){ 1051 valRet = parseInt(beforeDeci) + parseInt(1); 1052 } 1053 1054 if(afterDeci <= 02){ 1055 valRet = parseInt(beforeDeci); 1056 } 1057 1058 return valRet; 1059} 1060 1061/** 1062* Convert to integer;
1062 used for converting the weight to integer while calling the API 1063*/ 1064function rounditToInt(floatvalue){ 1065 //var intvalue = Math.floor( floatvalue ); 1066 var intvalue = Math.ceil( floatvalue ); 1067 //var intvalue = Math.round( floatvalue ); 1068 1069 return intvalue; 1070}
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.