Array
(
    [i] => 1999999999318
    [category] => iphones
    [c] => iphones
)
{"Apple iPhone 17 Pro Max":{"url":"\/sell\/iPhone-17-Pro-Max","text":"iPhone 17 Pro Max","image":"\/i\/products\/pp_iphone17promax.png","pid":"0000000431555","metatitle":"Apple iPhone 17 Pro Max","productseries":"134","maxprice":"1360.00"},"Apple iPhone 17 Pro":{"url":"\/sell\/iPhone-17-Pro","text":"iPhone 17 Pro","image":"\/i\/products\/pp_iphone17pro.png","pid":"0000000431531","metatitle":"Apple iPhone 17 Pro","productseries":"134","maxprice":"1081.00"},"Apple iPhone 17 Air":{"url":"\/sell\/iPhone-17-Air","text":"iPhone 17 Air","image":"\/i\/products\/pp_iphone17air.png","pid":"0000000431516","metatitle":"Apple iPhone 17 Air","productseries":"134","maxprice":"812.00"},"Apple iPhone 17e":{"url":"\/sell\/iPhone-17e","text":"iPhone 17e","image":"\/i\/products\/iphone17e.png","pid":"0000000432181","metatitle":"Apple iPhone 17e","productseries":"134","maxprice":"463.00"},"Apple iPhone 17":{"url":"\/sell\/iPhone-17","text":"iPhone 17","image":"\/i\/products\/pp_iphone17.png","pid":"0000000431500","metatitle":"Apple iPhone 17","productseries":"134","maxprice":"742.00"},"Apple iPhone 16e":{"url":"\/sell\/iPhone-16e","text":"iPhone 16e","image":"\/i\/products\/pp_iphone16e.png","pid":"0000000430898","metatitle":"Apple iPhone 16e","productseries":"133","maxprice":"441.00"},"Apple iPhone 16 Pro Max":{"url":"\/sell\/iPhone-16-Pro-Max","text":"iPhone 16 Pro Max","image":"\/i\/products\/pp_iphone16promax.png","pid":"1999999999320","metatitle":"Apple iPhone 16 Pro Max","productseries":"133","maxprice":"1025.00"},"Apple iPhone 16 Pro":{"url":"\/sell\/iPhone-16-Pro","text":"iPhone 16 Pro","image":"\/i\/products\/pp_iphone16pro.png","pid":"1999999999324","metatitle":"Apple iPhone 16 Pro","productseries":"133","maxprice":"865.00"},"Apple iPhone 16 Plus":{"url":"\/sell\/iPhone-16-Plus","text":"iPhone 16 Plus","image":"\/i\/products\/pp_iphone16plus.png","pid":"1999999999327","metatitle":"Apple iPhone 16 Plus","productseries":"133","maxprice":"570.00"},"Apple iPhone 16":{"url":"\/sell\/iPhone-16","text":"iPhone 16","image":"\/i\/products\/pp_iphone16.png","pid":"1999999999330","metatitle":"Apple iPhone 16","productseries":"133","maxprice":"553.00"},"Apple iPhone 15 Pro Max":{"url":"\/sell\/iPhone-15-Pro-Max","text":"iPhone 15 Pro Max","image":"\/i\/products\/pp_iphone15promax.png","pid":"1999999999559","metatitle":"Apple iPhone 15 Pro Max","productseries":"132","maxprice":"710.00"},"Apple iPhone 15 Pro":{"url":"\/sell\/iPhone-15-Pro","text":"iPhone 15 Pro","image":"\/i\/products\/pp_iphone15pro.png","pid":"1999999999567","metatitle":"Apple iPhone 15 Pro","productseries":"132","maxprice":"640.00"},"Apple iPhone 15 Plus":{"url":"\/sell\/iPhone-15-Plus","text":"iPhone 15 Plus","image":"\/i\/products\/pp_iphone15plus.png","pid":"1999999999575","metatitle":"Apple iPhone 15 Plus","productseries":"132","maxprice":"443.00"},"Apple iPhone 15":{"url":"\/sell\/iPhone-15","text":"iPhone 15","image":"\/i\/products\/pp_iphone15.png","pid":"1999999999577","metatitle":"Apple iPhone 15","productseries":"132","maxprice":"434.00"},"Apple iPhone 14 Pro Max":{"url":"\/sell\/iPhone-14-Pro-Max","text":"iPhone 14 Pro Max","image":"\/i\/products\/pp_iphone14promax.png","pid":"0194253378778","metatitle":"Apple iPhone 14 Pro Max","productseries":"131","maxprice":"550.00"},"Apple iPhone 14 Pro":{"url":"\/sell\/iPhone-14-Pro","text":"iPhone 14 Pro","image":"\/i\/products\/pp_iphone14pro.png","pid":"0194253400905","metatitle":"Apple iPhone 14 Pro","productseries":"131","maxprice":"431.00"},"Apple iPhone 14 Plus":{"url":"\/sell\/iPhone-14-Plus","text":"iPhone 14 Plus","image":"\/i\/products\/pp_iphone14plus.png","pid":"0194253372400","metatitle":"Apple iPhone 14 Plus","productseries":"131","maxprice":"335.00"},"Apple iPhone 14":{"url":"\/sell\/iPhone-14","text":"iPhone 14","image":"\/i\/products\/pp_iphone14.png","pid":"0194253409304","metatitle":"Apple iPhone 14","productseries":"131","maxprice":"350.00"},"Apple iPhone SE 3":{"url":"\/sell\/iPhone-SE-3","text":"iPhone SE 3","image":"\/i\/products\/pp_iphonese2022.png","pid":"0194253134992","metatitle":"Apple iPhone SE 3","productseries":"144","maxprice":"141.00"},"Apple iPhone 13 Pro Max":{"url":"\/sell\/iPhone-13-Pro-Max","text":"iPhone 13 Pro Max","image":"\/i\/products\/pp_iphone13promax.png","pid":"0400064434498","metatitle":"Apple iPhone 13 Pro Max","productseries":"130","maxprice":"407.00"},"Apple iPhone 13 Pro":{"url":"\/sell\/iPhone-13-Pro","text":"iPhone 13 Pro","image":"\/i\/products\/pp_iphone13pro.png","pid":"0400064434313","metatitle":"Apple iPhone 13 Pro","productseries":"130","maxprice":"372.00"},"Apple iPhone 13":{"url":"\/sell\/iPhone-13","text":"iPhone 13","image":"\/i\/products\/pp_iphone13.png","pid":"0194252704653","metatitle":"Apple iPhone 13","productseries":"130","maxprice":"250.00"},"Apple iPhone 13 Mini":{"url":"\/sell\/iPhone-13-Mini","text":"iPhone 13 Mini","image":"\/i\/products\/pp_iphone13mini.png","pid":"0194252686485","metatitle":"Apple iPhone 13 Mini","productseries":"130","maxprice":"237.60"},"Apple iPhone 12 Pro Max":{"url":"\/sell\/iPhone-12-Pro-Max","text":"iPhone 12 Pro Max","image":"\/i\/products\/pp_iphone12promax.png","pid":"0400060097383","metatitle":"Apple iPhone 12 Pro Max","productseries":"129","maxprice":"272.00"},"Apple iPhone 12 Pro":{"url":"\/sell\/iPhone-12-Pro","text":"iPhone 12 Pro","image":"\/i\/products\/pp_iphone12pro.png","pid":"0400060097048","metatitle":"Apple iPhone 12 Pro","productseries":"129","maxprice":"260.00"},"Apple iPhone 12 Mini":{"url":"\/sell\/iPhone-12-Mini","text":"iPhone 12 Mini","image":"\/i\/products\/pp_iphone12mini.png","pid":"0400060097307","metatitle":"Apple iPhone 12 Mini","productseries":"129","maxprice":"135.00"},"Apple iPhone 12":{"url":"\/sell\/iPhone-12","text":"iPhone 12","image":"\/i\/products\/pp_iphone12.png","pid":"0400060096799","metatitle":"Apple iPhone 12","productseries":"129","maxprice":"183.00"},"Apple iPhone SE 2":{"url":"\/sell\/iPhone-SE-2","text":"iPhone SE 2","image":"\/i\/products\/pp_iphonese2020.png","pid":"0400063412862","metatitle":"Apple iPhone SE 2","productseries":"144","maxprice":"94.00"},"Apple iPhone 11 Pro Max":{"url":"\/sell\/iPhone-11-Pro-Max","text":"iPhone 11 Pro Max","image":"\/i\/products\/pp_iphone11promaxgold.png","pid":"0400063413210","metatitle":"Apple iPhone 11 Pro Max","productseries":"128","maxprice":"248.00"},"Apple iPhone 11 Pro":{"url":"\/sell\/iPhone-11-Pro","text":"iPhone 11 Pro","image":"\/i\/products\/pp_iphone11progold.png","pid":"0400063413081","metatitle":"Apple iPhone 11 Pro","productseries":"128","maxprice":"195.00"},"Apple iPhone 11":{"url":"\/sell\/iPhone-11","text":"iPhone 11","image":"\/i\/products\/pp_iphone11white.png","pid":"1999999996626","metatitle":"Apple iPhone 11","productseries":"128","maxprice":"161.00"},"Apple iPhone Xs Max":{"url":"\/sell\/iPhone-Xs-Max","text":"iPhone Xs Max","image":"\/i\/products\/pp_iphonexsmaxsilver.png","pid":"0190198786043","metatitle":"Apple iPhone Xs Max","productseries":"147","maxprice":"186.00"},"Apple iPhone XR":{"url":"\/sell\/iPhone-XR","text":"iPhone XR","image":"\/i\/products\/pp_iphonexrwhite.png","pid":"1999999996073","metatitle":"Apple iPhone XR","productseries":"146","maxprice":"136.00"},"Apple iPhone Xs":{"url":"\/sell\/iPhone-Xs","text":"iPhone Xs","image":"\/i\/products\/pp_iphonexssilver.png","pid":"0400060096423","metatitle":"Apple iPhone Xs","productseries":"147","maxprice":"135.00"},"Apple iPhone X":{"url":"\/sell\/iPhone-X","text":"iPhone X","image":"\/i\/products\/pp_iphonexsilver.png","pid":"4893025144714","metatitle":"Apple iPhone X","productseries":"145","maxprice":"100.00"},"Apple iPhone 8 Plus":{"url":"\/sell\/iPhone-8-Plus","text":"iPhone 8 Plus","image":"\/i\/products\/pp_iphone8plusgold.png","pid":"0400060096591","metatitle":"Apple iPhone 8 Plus","productseries":"143","maxprice":"80.00"},"Apple iPhone 8":{"url":"\/sell\/iPhone-8","text":"iPhone 8","image":"\/i\/products\/pp_iphone8gold.png","pid":"1999999996666","metatitle":"Apple iPhone 8","productseries":"143","maxprice":"70.00"},"Apple iPhone 7 Plus":{"url":"\/sell\/iPhone-7-Plus","text":"iPhone 7 Plus","image":"\/i\/products\/pp_iphone7plussilver.png","pid":"1999999998437","metatitle":"Apple iPhone 7 Plus","productseries":"142","maxprice":"27.00"},"Apple iPhone 7":{"url":"\/sell\/iPhone-7","text":"iPhone 7","image":"\/i\/products\/pp_iphone7silver.png","pid":"1999999998490","metatitle":"Apple iPhone 7","productseries":"142","maxprice":"25.00"}}<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Options for selling your device near you | Flipsy</title>
<meta name=description content="Find Your Next Device with Flipsy! Tell us what you're looking for, and we'll help you find the best options.">
<meta name=keywords content="local, phone, device, buy, buying, near">
<link rel="canonical" href="https://flipsy.com/buy-local">
<link href="/_assets/css/style.css" rel="stylesheet">
<link rel="preconnect" href="https://fonts.gstatic.com/" crossorigin>    
<link href="https://fonts.googleapis.com/css2?family=Montserrat:wght@400;500;600&display=swap" rel="stylesheet">
<style type="text/css">
@-webkit-keyframes animatetop{from{top:-50%;opacity:0}to{top:0;opacity:1}}@keyframes animatetop{from{top:-50%;opacity:0}to{top:0;opacity:1}}body,html{min-height:100vh;height:100%;max-height:100%}.modal{display:flex;position:fixed;z-index:1;left:0;top:0;width:100%;height:100%;overflow:auto;background-color:#fff;background-color:rgba(255,255,255,.6)}.modal-content{font-family:Montserrat,sans-serif;position:relative;background-color:#fefefe;margin:auto;padding:0;width:671px;max-width:95%;min-height:534px;text-align:center;border-radius:25px;overflow:hidden;border:1px solid #ececec;box-shadow:6px 6px 14px #0000000d}.modal-body .col-container{display:flex;flex-direction:row;flex-wrap:wrap;width:100%;min-height:534px}.modal-body .col-container-row{display:flex;flex-direction:row;width:100%}.modal-body .col-container .col{display:flex;flex:1;justify-content:center;align-items:center}.redirectpageBG{position:relative}.redirectpageBG:before{z-index:-1;content:"";position:absolute;background:url(/_assets/images/page_bg_top.svg) no-repeat left top;top:0;left:0;width:100%;height:100%}.redirectpageBG:after{z-index:-1;content:"";position:absolute;background:url(/_assets/images/page_bg_bottom.svg) no-repeat right bottom;bottom:0;right:0;width:100%;height:100%}.thankspage{position:relative;height:100%;width:100%;overflow:auto;padding:50px 0}.thankspage .container{position:relative;z-index:100;text-align:center;min-height:100%;display:flex;flex-direction:column;justify-content:center;align-items:center}.thankspage .loader{text-align:center}.thankspage h3{font-size:26px;color:#141414}.thankspage h4{font-size:26px;color:#141414;font-weight:400;margin:10px 0;line-height:30px}.thankspage h4 span{color:#141414}.thankspage h5{font-size:18px;font-weight:400}.thankspage p{color:#838383;font-size:14px}.redirectpage{position:relative;height:100%;width:100%;overflow:auto;padding:50px 0}.redirectpage .container{position:relative;z-index:100;text-align:center;min-height:100%;display:flex;flex-direction:column;justify-content:center;align-items:center}.redirectpage .loader{text-align:center}.redirectpage h1{font-size:25px;color:#141414;line-height:40px;margin:35px 0 8px 0;position:relative}.redirectpage h2{font-size:25px;color:#141414;line-height:40px;margin:35px 0 8px 0;position:relative}.redirectpage h2 img.logo{position:absolute;right:-5px;bottom:-15px;right:15px;top:-50px}.redirectpage h2 span{font-size:45px}.redirectpage h3{font-size:22px;color:#141414;margin:15px 0}.redirectpage h4{font-size:18px;color:#141414;font-weight:600;margin:0;line-height:24px}.redirectpage h4.para{font-weight:400}.redirectpage h4 span{color:#141414}.redirectpage h5{font-size:18px;font-weight:400}.redirectpage p{color:#838383;font-size:14px;padding:0;margin:0}.input-containers{width:415px;height:57px;margin:15px 0}.input-container .input-field{width:100%;padding:0 0 0 50px;border-radius:10px;height:57px;background:url(/_assets/images/email_icon.svg) #fafafa no-repeat 18px center!important}.input-container .input-field:active,.input-container .input-field:focus,.input-container .input-field:hover{background:url(/_assets/images/email_icon.svg) #fff no-repeat 18px center!important}.redirecturl a{font-size:18px;margin-top:20px;color:#0a3ab0;border-bottom:1px solid #0a3ab0;font-weight:500}.modal-body .close{font-size:18px;margin-top:20px}.modal-body .close a{color:#0a3ab0}.modal-body .copycouponcontents{color:#6f6f6f;font-size:16px;text-align:center;margin:15px auto;width:260px;line-height:25px}.modal-body .firstCol{background:#f2f3f6}.left-col{padding:0 20px;position:relative}.left-col:before{position:absolute;background:#f48120;height:2px;width:45%;content:" ";left:20px;top:0}.left-col:after{position:absolute;background:#f48120;height:2px;width:45%;content:" ";right:20px;bottom:-15px}.modal-body .left-col h2{color:#141414;font-size:25px}.modal-body .left-col h2 span{font-size:45px}.modal-body .left-col p{color:#141414;font-size:23px;font-weight:400;padding:0;margin:0}.primary-button-arrow-fill:after{width:25px;height:25px}.primary-button-arrow-fill,.visitBtn button{padding:10px 5px;font-size:18px;width:280px;text-align:center}.copyCode{width:260px;margin:20px auto;text-transform:uppercase}.afterCopy,.beforeCopy{cursor:pointer}.afterCopy{color:#358403;display:none}.afterCopy .a{fill:#358403;stroke:#358403}.flipsyTop{color:#b20a2c;border:1px dashed #b20a2c;border-top-left-radius:10px;border-top-right-radius:10px;font-size:23px;font-weight:700;padding-top:15px;padding-bottom:15px}.flipsyBot{color:#b20a2c;font-size:23px;background:#fff2f3;border-left:1px solid #b20a2c;border-right:1px solid #b20a2c;border-bottom:1px solid #b20a2c;border-bottom-left-radius:10px;border-bottom-right-radius:10px;padding:5px 0}.mobileView{display:none}.desktopView{display:block;margin-top:20px}.thanksView img{max-width:200px;width:80%;height:auto}.mobileView img{max-width:140px;width:80%;height:auto}@media only screen and (max-width:1380px){.redirectpageBG:after,.redirectpageBG:before{background-size:50% auto}}@media only screen and (max-width:1220px){.redirectpageBG:after,.redirectpageBG:before{background-size:40% auto}}@media only screen and (max-width:1025px){.redirectpageBG:after,.redirectpageBG:before{background-size:40% auto}}@media only screen and (max-width:768px){.thankspage .container{padding-left:25px;padding-right:25px}.redirectpage .container{padding-left:25px;padding-right:25px}}@media only screen and (max-width:670px){.modal-body .col-container,.modal-content{min-height:100%;overflow:auto}.modal-body{overflow:auto}.modal-body .left-col p{padding-bottom:0}.modal-body .col-container-row{display:block}.left-col:after,.left-col:before{display:none}.left-col{padding:15px 25px}.mobileView{display:block;margin-bottom:10px}.modal{padding:0}.desktopView{display:none}.visitBtn{margin-top:10px}.modal-content{margin:0;top:0;padding:0;width:100%;max-width:100%;top:0;border-radius:0;height:100%}.modal-body .close{margin-bottom:20px}.redirectpage h2{margin:15px 0 30px 0;padding-right:50px;padding-left:50px;display:inline-block}.redirectpage h2 img.logo{position:absolute;right:125px;right:-5px;bottom:-15px;top:inherit}.redirectpage h2:before{display:none}}@media only screen and (max-width:420px){.input-container{width:320px;max-width:98%}}
@keyframes ldio-gv3u0x07czk{0%{transform:translate(9.99px,47.730000000000004px) scale(0)}25%{transform:translate(9.99px,47.730000000000004px) scale(0)}50%{transform:translate(9.99px,47.730000000000004px) scale(1)}75%{transform:translate(47.730000000000004px,47.730000000000004px) scale(1)}100%{transform:translate(85.47000000000001px,47.730000000000004px) scale(1)}}@keyframes ldio-gv3u0x07czk-r{0%{transform:translate(85.47000000000001px,47.730000000000004px) scale(1) :}100%{transform:translate(85.47000000000001px,47.730000000000004px) scale(0)}}@keyframes ldio-gv3u0x07czk-c{0%{background:#b11e23}25%{background:#f48120}50%{background:#b11e23}75%{background:#f48120}100%{background:#b11e23}}.ldio-gv3u0x07czk div{position:absolute;width:15.540000000000001px;height:15.540000000000001px;border-radius:50%;transform:translate(47.730000000000004px,47.730000000000004px) scale(1);background:#b11e23;animation:ldio-gv3u0x07czk 2.8571428571428568s infinite cubic-bezier(0,.5,.5,1)}.ldio-gv3u0x07czk div:nth-child(1){background:#f48120;transform:translate(85.47000000000001px,47.730000000000004px) scale(1);animation:ldio-gv3u0x07czk-r .7142857142857142s infinite cubic-bezier(0,.5,.5,1),ldio-gv3u0x07czk-c 2.8571428571428568s infinite step-start}.ldio-gv3u0x07czk div:nth-child(2){animation-delay:-.7142857142857142s;background:#b11e23}.ldio-gv3u0x07czk div:nth-child(3){animation-delay:-1.4285714285714284s;background:#f48120}.ldio-gv3u0x07czk div:nth-child(4){animation-delay:-2.142857142857143s;background:#b11e23}.ldio-gv3u0x07czk div:nth-child(5){animation-delay:-2.8571428571428568s;background:#f48120}.loadingio-spinner-ellipsis-t2ypu0vws59{width:111px;height:111px;display:inline-block;overflow:hidden;background:#fff}.ldio-gv3u0x07czk{width:100%;height:100%;position:relative;transform:translateZ(0) scale(1);backface-visibility:hidden;transform-origin:0 0}.ldio-gv3u0x07czk div{box-sizing:content-box}.tleft{text-align:left}
    .form-container {
      max-width: 800px;
    }

    .form-group {
      margin-bottom: 24px;
    }
    label {
      display: block;
      margin-bottom: 8px;
      font-weight: 600;
      color: #444;
    }
    input, select, textarea {
      width: 100%;
      padding: 12px;
      border: 1px solid #ddd;
      border-radius: 6px;
      font-size: 16px;
      transition: border-color 0.3s, box-shadow 0.3s;
    }
    input:focus, select:focus, textarea:focus {
      border-color: #2c6ecb;
      box-shadow: 0 0 0 3px rgba(44, 110, 203, 0.15);
      outline: none;
    }
    select {
      appearance: none;
      background-image: url("data:image/svg+xml;charset=US-ASCII,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20width%3D%22292.4%22%20height%3D%22292.4%22%3E%3Cpath%20fill%3D%22%23333%22%20d%3D%22M287%2069.4a17.6%2017.6%200%200%200-13-5.4H18.4c-5%200-9.3%201.8-12.9%205.4A17.6%2017.6%200%200%200%200%2082.2c0%205%201.8%209.3%205.4%2012.9l128%20127.9c3.6%203.6%207.8%205.4%2012.8%205.4s9.2-1.8%2012.8-5.4L287%2095c3.5-3.5%205.4-7.8%205.4-12.8%200-5-1.9-9.2-5.5-12.8z%22%2F%3E%3C%2Fsvg%3E");
      background-repeat: no-repeat;
      background-position: right 12px center;
      background-size: 12px;
      padding-right: 40px;
    }
    .select-with-icon {
      position: relative;
    }
    .select-icon {
      position: absolute;
      top: 12px;
      left: 12px;
      color: #6c757d;
      pointer-events: none;
    }
    select.with-icon {
      padding-left: 40px;
    }
    option {
      padding: 10px;
    }
    .icon-option {
      display: flex;
      align-items: center;
    }
    textarea {
      height: 120px;
      resize: vertical;
    }
    .checkbox-group {
      margin-top: 12px;
    }
    .checkbox-label {
      display: flex;
      align-items: center;
      font-weight: normal;
      margin-bottom: 10px;
      cursor: pointer;
      padding: 5px;
      border-radius: 4px;
      transition: background-color 0.2s;
    }
    .checkbox-label:hover {
      background-color: #f0f4f8;
    }
    .checkbox-input {
      width: auto;
      margin-right: 12px;
      height: 18px;
      width: 18px;
    }
    .price-range {
      display: flex;
      gap: 15px;
      align-items: center;
    }
    .price-range input {
      flex: 1;
    }
    .price-range span {
      color: #6c757d;
      font-weight: 500;
    }

    .btn {
      background-color: #2c6ecb;
      color: white;
      border: none;
      padding: 14px 28px;
      border-radius: 6px;
      font-size: 16px;
      cursor: pointer;
      display: inline-block;
      font-weight: 600;
      text-align: center;
      transition: background-color 0.2s, transform 0.1s;
      width: 100%;
    }
    .btn:hover {
      background-color: #245aa8;
    }
    .btn:active {
      transform: translateY(1px);
    }
    .required {
      color: #e53935;
      margin-left: 3px;
    }
    .form-note {
      font-size: 14px;
      color: #6c757d;
      margin-top: 6px;
    }
    .form-section {
      border-bottom: 1px solid #eaebef;
      margin-bottom: 30px;
    }
    .form-section-title {
      font-size: 18px;
      color: #444;
      margin-bottom: 20px;
    }
    .form-row {
      display: flex;
      gap: 20px;
      margin-bottom: 14px;
    }
    .form-col {
      flex: 1;
    }
    .smlnote {font-size:12px;font-weight:400}
		.error, .validation-success {
		    display: none;
		}
		.error {
		    color: red;
		    font-size: 12px;
		    margin-top: 5px;
		}
		input.invalid, select.invalid {
		    border: 1px solid red;
		}
		.validation-success {
		    color: green;
		    font-weight: 700;
		    margin-top: 15px;
		}    
    @media (max-width: 600px) {
      .form-row {
        flex-direction: column;
        gap: 0;
      }
    }
    #deviceTypeOptions {
      max-height: 0;
      overflow: hidden;
      transition: max-height 0.3s ease-out;
      background-color: white;
      border-radius: 6px;
      border: 1px solid #ddd;
      position: absolute;
      width: 100%;
      z-index: 10;
      margin-top: 5px;
      box-shadow: 0 4px 12px rgba(0,0,0,0.1);
    }
    .device-option {
      padding: 12px 15px;
      cursor: pointer;
      display: flex;
      align-items: center;
      transition: background-color 0.2s;
    }
    .device-option:hover {
      background-color: #f0f4f8;
    }
    .device-option i {
      margin-right: 12px;
      width: 20px;
      text-align: center;
      color: #555;
    }
    .custom-select-header {
      display: flex;
      align-items: center;
      justify-content: space-between;
      padding: 12px;
      border: 1px solid #ddd;
      border-radius: 6px;
      background-color: white;
      cursor: pointer;
      user-select: none;
    }
    .custom-select-header:hover {
      border-color: #bbbbbb;
    }
    .custom-select-header.active {
      border-color: #2c6ecb;
      box-shadow: 0 0 0 3px rgba(44, 110, 203, 0.15);
    }
    .custom-select-header i.fa-chevron-down {
      transition: transform 0.3s;
    }
    .custom-select-header.active i.fa-chevron-down {
      transform: rotate(180deg);
    }
    .custom-select-selected {
      display: flex;
      align-items: center;
    }
    .custom-select-selected i {
      margin-right: 10px;
      width: 20px;
      text-align: center;
    }
    .loading-indicator {
		  min-width: 80px;
		  display: inline-block;
		  visibility: hidden;
		  color: #888;
		  font-style: italic;
		  margin-left: 8px;
		}</style>
<!-- Google Tag Manager -->
<script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
})(window,document,'script','dataLayer','GTM-WD7RSXZ');</script>
		<!-- End Google Tag Manager -->
	     
<!-- Global site tag (gtag.js) - Google Ads: 1062237289 -->
<script async src="https://www.googletagmanager.com/gtag/js?id=AW-1062237289"></script>
<script>
  window.dataLayer = window.dataLayer || [];
  function gtag(){dataLayer.push(arguments);}
  gtag('js', new Date());

  gtag('config', 'AW-1062237289');
</script>
			
<script>
function gtag_report_conversion(url) {
  var callback = function () {
    if (typeof(url) != 'undefined') {
      window.location = url;
    }
  };
  gtag('event', 'conversion', {
      'send_to': 'AW-1062237289/jskqCJyE07IaEOnowfoD',
      'event_callback': callback
  });
  return false;
}
</script>			
</head>
<body class="redirectpageBG">

<div class="redirectpage">
	<div class="container">
		<div class="thanksView">
			<img src="/_assets/images/flipsylogo.svg" alt="Flipsy.com logo" width="140px" height="55px">
		</div>
		
		<h1>Find Your Next Device with Flipsy!</h1>
		
		<div id="content">
		
			<h4 class="para" style="text-align: center;">Tell us what you're looking for, and we'll help you find the best options.</h4>
			
			<div class="form-container">		
			<form id="bulcl" name="bulcl" action="/buy-local" method="post" >

	      <div class="form-section">
	        <h3 class="form-section-title">Device Information</h2>

	        <div class="form-row">	        
	          <div class="form-col">
			        <div class="form-group">
								<label for="deviceType">Device Type</label>
								<select id="deviceType" name="deviceType" required>
								  <option value="" selected>Select a device type</option>
								  <option value="smartphone" selected>Smartphone</option>

								</select>
								<div id="deviceTypeError" class="error">Please select a device type</div>
			        </div>
	          </div>	        
	        
	          <div class="form-col">
	            <div class="form-group">
	              <label for="brand">Brand</label>
	              <select id="brand" name="brand" required>
	                <option value="">Select brand</option>
	                <option value='/sell/iPhone' selected>iPhone</option><option value='/sell/Samsung-Phone'>Samsung</option><option value='/motorola/browse'>Motorola</option><option value='/htc/browse'>HTC</option><option value='/lg/browse'>LG</option><option value='/nokia/browse'>Nokia</option><option value='/google/browse'>Google Pixel</option><option value='/asus/browse'>Asus</option><option value='/sony/browse'>Sony</option><option value='/oneplus/browse'>OnePlus</option><option value='/microsoft/browse'>Microsoft</option><option value='/nothing/browse'>Nothing</option><option value='/cat/browse'>CAT</option>	              </select>
	              <div id="brandError" class="error">Please select a brand</div>
	            </div>
	          </div>	       
	        </div>
	        
	        <div class="form-row">	          
	          <div class="form-col">
	            <div class="form-group">
	              <label for="device">Device</label>
	              <select id="device" name="device" required>
	                <option value="">Select device</option>
	                <option value='/sell/iPhone-17-Pro-Max' data-mt='Apple iPhone 17 Pro Max'>iPhone 17 Pro Max</option><option value='/sell/iPhone-17-Pro' data-mt='Apple iPhone 17 Pro'>iPhone 17 Pro</option><option value='/sell/iPhone-17-Air' data-mt='Apple iPhone 17 Air'>iPhone 17 Air</option><option value='/sell/iPhone-17e' data-mt='Apple iPhone 17e'>iPhone 17e</option><option value='/sell/iPhone-17' data-mt='Apple iPhone 17'>iPhone 17</option><option value='/sell/iPhone-16e' data-mt='Apple iPhone 16e'>iPhone 16e</option><option value='/sell/iPhone-16-Pro-Max' selected data-mt='Apple iPhone 16 Pro Max'>iPhone 16 Pro Max</option><option value='/sell/iPhone-16-Pro' data-mt='Apple iPhone 16 Pro'>iPhone 16 Pro</option><option value='/sell/iPhone-16-Plus' data-mt='Apple iPhone 16 Plus'>iPhone 16 Plus</option><option value='/sell/iPhone-16' data-mt='Apple iPhone 16'>iPhone 16</option><option value='/sell/iPhone-15-Pro-Max' data-mt='Apple iPhone 15 Pro Max'>iPhone 15 Pro Max</option><option value='/sell/iPhone-15-Pro' data-mt='Apple iPhone 15 Pro'>iPhone 15 Pro</option><option value='/sell/iPhone-15-Plus' data-mt='Apple iPhone 15 Plus'>iPhone 15 Plus</option><option value='/sell/iPhone-15' data-mt='Apple iPhone 15'>iPhone 15</option><option value='/sell/iPhone-14-Pro-Max' data-mt='Apple iPhone 14 Pro Max'>iPhone 14 Pro Max</option><option value='/sell/iPhone-14-Pro' data-mt='Apple iPhone 14 Pro'>iPhone 14 Pro</option><option value='/sell/iPhone-14-Plus' data-mt='Apple iPhone 14 Plus'>iPhone 14 Plus</option><option value='/sell/iPhone-14' data-mt='Apple iPhone 14'>iPhone 14</option><option value='/sell/iPhone-SE-3' data-mt='Apple iPhone SE 3'>iPhone SE 3</option><option value='/sell/iPhone-13-Pro-Max' data-mt='Apple iPhone 13 Pro Max'>iPhone 13 Pro Max</option><option value='/sell/iPhone-13-Pro' data-mt='Apple iPhone 13 Pro'>iPhone 13 Pro</option><option value='/sell/iPhone-13' data-mt='Apple iPhone 13'>iPhone 13</option><option value='/sell/iPhone-13-Mini' data-mt='Apple iPhone 13 Mini'>iPhone 13 Mini</option><option value='/sell/iPhone-12-Pro-Max' data-mt='Apple iPhone 12 Pro Max'>iPhone 12 Pro Max</option><option value='/sell/iPhone-12-Pro' data-mt='Apple iPhone 12 Pro'>iPhone 12 Pro</option><option value='/sell/iPhone-12-Mini' data-mt='Apple iPhone 12 Mini'>iPhone 12 Mini</option><option value='/sell/iPhone-12' data-mt='Apple iPhone 12'>iPhone 12</option><option value='/sell/iPhone-SE-2' data-mt='Apple iPhone SE 2'>iPhone SE 2</option><option value='/sell/iPhone-11-Pro-Max' data-mt='Apple iPhone 11 Pro Max'>iPhone 11 Pro Max</option><option value='/sell/iPhone-11-Pro' data-mt='Apple iPhone 11 Pro'>iPhone 11 Pro</option><option value='/sell/iPhone-11' data-mt='Apple iPhone 11'>iPhone 11</option><option value='/sell/iPhone-Xs-Max' data-mt='Apple iPhone Xs Max'>iPhone Xs Max</option><option value='/sell/iPhone-XR' data-mt='Apple iPhone XR'>iPhone XR</option><option value='/sell/iPhone-Xs' data-mt='Apple iPhone Xs'>iPhone Xs</option><option value='/sell/iPhone-X' data-mt='Apple iPhone X'>iPhone X</option><option value='/sell/iPhone-8-Plus' data-mt='Apple iPhone 8 Plus'>iPhone 8 Plus</option><option value='/sell/iPhone-8' data-mt='Apple iPhone 8'>iPhone 8</option><option value='/sell/iPhone-7-Plus' data-mt='Apple iPhone 7 Plus'>iPhone 7 Plus</option><option value='/sell/iPhone-7' data-mt='Apple iPhone 7'>iPhone 7</option>	              </select>
	              <div id="modelError" class="error">Please select your desired model</div>
	            </div>
	          </div>
          
	          <div class="form-col">
	            <div class="form-group">
	              <label for="specificModel">Model</label>
	              <select id="model" name="model" required>
	                <option value="">Select model</option>
	                <option value='0195949805141'>1TB (AT&T)</option><option value='0000000427197'>1TB (Other)</option><option value='0000000429688'>1TB (Spectrum)</option><option value='0000000432101'>1TB (Sprint)</option><option value='0195949805141'>1TB (T-Mobile)</option><option value='0000000428513'>1TB (U.S. Cellular)</option><option value='1999999999318' selected>1TB (Unlocked)</option><option value='0400064433811'>1TB (Verizon Wireless)</option><option value='0000000429763'>1TB (Xfinity Mobile)</option><option value='0195949805066'>256GB (AT&T)</option><option value='0000000427198'>256GB (Other)</option><option value='0000000429689'>256GB (Spectrum)</option><option value='0000000432102'>256GB (Sprint)</option><option value='0195949805066'>256GB (T-Mobile)</option><option value='0000000428514'>256GB (U.S. Cellular)</option><option value='1999999999320'>256GB (Unlocked)</option><option value='0400064433743'>256GB (Verizon Wireless)</option><option value='0000000429764'>256GB (Xfinity Mobile)</option><option value='0195949805103'>512GB (AT&T)</option><option value='0000000427199'>512GB (Other)</option><option value='0000000429690'>512GB (Spectrum)</option><option value='0000000432103'>512GB (Sprint)</option><option value='0195949805103'>512GB (T-Mobile)</option><option value='0000000428515'>512GB (U.S. Cellular)</option><option value='1999999999319'>512GB (Unlocked)</option><option value='0400064433798'>512GB (Verizon Wireless)</option><option value='0000000429765'>512GB (Xfinity Mobile)</option>	              </select>
	              <div id="modelError" class="error">Please select your desired model</div>
	            </div>
	          </div>	          
	        </div>
	       
	        
	      </div>
	
	      <div class="form-section">
	        <h3 class="form-section-title">Purchase Details</h2>
	
	        <div class="form-row">	        
	          <div class="form-col">
			        <div class="form-group">
				        <label>Purchase Preference</label>
			          <div class="checkbox-group">
			            <label class="checkbox-label">
			              <input type="checkbox" class="checkbox-input" id="preferOnline" name="preferOnline">
			              <i class="fas fa-shopping-cart"></i> Online retailers
			            </label>
			            <label class="checkbox-label">
			              <input type="checkbox" class="checkbox-input" id="preferLocal" name="preferLocal">
			              <i class="fas fa-store"></i> Local stores
			            </label>
									<input type="hidden" class="checkbox-input" id="preferPrivate" name="preferPrivate" value=''>
			            <div id="channelError" class="error">Please select at least one purchase preference</div>
			          </div>
			        </div>
	          </div>
	          
	          <div class="form-col">
	            <div class="form-group">
	              <label for="location">US Zip</span></label>
	              <div class="select-with-icon">
	                <i class="fas fa-map-marker-alt select-icon"></i>
	                <input type="text"  id="zipCode" name="zipCode" pattern="[0-9]{5}" maxlength="5" placeholder="ZIP Code">
	                <div id="zipCodeError" class="error">Enter a valid 5-digit US zip code (e.g., 90210)</div>
	              </div>
	              <p class="form-note">For local store options and shipping calculations</p>
	            </div>       
	          </div>
	        </div>
	      </div>
	
	      <div class="form-section">
	        <h3 class="form-section-title">Contact Information</h2>
	        
	        <div class="form-row">
	          <div class="form-col">
	            <div class="form-group">
	              <label for="email">Email Address</label>
	              <div class="select-with-icon">
	                <i class="fas fa-envelope select-icon"></i>
	                <input type="email" id="email" name="email" required>
	                <div id="emailError" class="error">Please enter a valid email address (e.g., example@domain.com)</div>
	                <p>We are committed to keeping your email address confidential</p>
	              </div>
	            </div>
	          </div>
	          <div class="form-col">
	            <div class="form-group">
	              <label for="phone">Phone Number <span class="smlnote">(optional)</span></label>
	              <div class="select-with-icon">
	                <i class="fas fa-phone select-icon"></i>
	                <input type="tel" id="phone" name="phone" placeholder="(123) 456-7890">
	                <div id="phoneError" class="error">Please enter a valid US phone number</div>
	              </div>
	            </div>
	          </div>
	        </div>
	
	        <div class="form-group">
					  <label class="checkbox-label">
					    <input type="checkbox" class="checkbox-input" id="consentContact" required>
					    <span>Yes, I consent to Flipsy contacting me with purchase options for my requested device</span>
					  </label>
					  <div id="consentContactError" class="error">You must consent to be contacted</div>
					</div>
	      </div>
			
		
			

			<div class="visitBtn"><button type="submit" class="primary-button-arrow-fill">Find My Device</button></div>
			<input id="pid" type="hidden" name="i" value="1999999999318">
			</form>
			</div>
		</div>
	</div>
</div>

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>

<script type="text/javascript">

        const email = document.getElementById('email');
        const zipCode = document.getElementById('zipCode');
        
        const emailError = document.getElementById('emailError');
        const zipCodeError = document.getElementById('zipCodeError');

        
        function validateEmail(email) {
            const re = /^(([^<>()\[\]\.,;:\s@"]+(\.[^<>()\[\]\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
            return re.test(String(email).toLowerCase());
        }
        
        function validateZipCode(zip) {
            const re = /^[0-9]{5}$/;
            return re.test(zip);
        }
        
        email.addEventListener('input', function() {
            if (validateEmail(email.value)) {
                email.classList.remove('invalid');
                emailError.style.display = 'none';
            } else {
                email.classList.add('invalid');
                emailError.style.display = 'block';
            }
        });
        
        zipCode.addEventListener('input', function() {
            if (validateZipCode(zipCode.value)) {
                zipCode.classList.remove('invalid');
                zipCodeError.style.display = 'none';
            } else {
                zipCode.classList.add('invalid');
                zipCodeError.style.display = 'block';
            }
        });
        



    
$("#bulcl").submit(function(event) {
  event.preventDefault();
 

  let isValid = true;

  // Device Type
  const deviceType = document.getElementById('deviceType');
  const deviceTypeError = document.getElementById('deviceTypeError');
  if (!deviceType.value) {
    deviceType.classList.add('invalid');
    deviceTypeError.style.display = 'block';
    isValid = false;
  } else {
    deviceType.classList.remove('invalid');
    deviceTypeError.style.display = 'none';
  }

  // Brand
  const brand = document.getElementById('brand');
  const brandError = document.getElementById('brandError');
  if (!brand.value) {
    brand.classList.add('invalid');
    brandError.style.display = 'block';
    isValid = false;
  } else {
    brand.classList.remove('invalid');
    brandError.style.display = 'none';
  }

  // Model
  const model = document.getElementById('model');
  const modelError = document.getElementById('modelError');
  if (!model.value) {
    model.classList.add('invalid');
    modelError.style.display = 'block';
    isValid = false;
  } else {
    model.classList.remove('invalid');
    modelError.style.display = 'none';
  }


  // Purchase Preference (at least one checked)
  const preferOnline = document.getElementById('preferOnline');
  const preferLocal = document.getElementById('preferLocal');
  const preferPrivate = document.getElementById('preferPrivate');
  const channelError = document.getElementById('channelError');
  if (!preferOnline.checked && !preferLocal.checked && !preferPrivate.checked) {
    channelError.style.display = 'block';
    isValid = false;
  } else {
    channelError.style.display = 'none';
  }

  // Zip Code (required only if preferLocal is checked)
  if (preferLocal.checked) {
    if (!validateZipCode(zipCode.value)) {
      zipCode.classList.add('invalid');
      zipCodeError.style.display = 'block';
      isValid = false;
    } else {
      zipCode.classList.remove('invalid');
      zipCodeError.style.display = 'none';
    }
  } else {
    zipCode.classList.remove('invalid');
    zipCodeError.style.display = 'none';
  }

  // Email (already present)
  if (!validateEmail(email.value)) {
    email.classList.add('invalid');
    emailError.style.display = 'block';
    isValid = false;
  } else {
    email.classList.remove('invalid');
    emailError.style.display = 'none';
  }

  // Phone (optional, but must be valid if filled)
  const phone = document.getElementById('phone');
  const phoneError = document.getElementById('phoneError');
  function validatePhone(phoneVal) {
    // Accepts (123) 456-7890, 123-456-7890, 1234567890, 123.456.7890, 123 456 7890
    return /^\s*(?:\+?1[-.\s]?)?(?:\([2-9][0-9]{2}\)|[2-9][0-9]{2})[-.\s]?[0-9]{3}[-.\s]?[0-9]{4}\s*$/.test(phoneVal);
  }
  if (phone.value.trim() !== "" && !validatePhone(phone.value.trim())) {
    phone.classList.add('invalid');
    phoneError.style.display = 'block';
    isValid = false;
  } else {
    phone.classList.remove('invalid');
    phoneError.style.display = 'none';
  }

// Consent to contact
  const consentContact = document.getElementById('consentContact');
  const consentContactError = document.getElementById('consentContactError');
  if (!consentContact.checked) {
    consentContactError.style.display = 'block';
    isValid = false;
  } else {
    consentContactError.style.display = 'none';
  }

  if (isValid) {
    document.querySelectorAll('.invalid').forEach(function(element) {
      element.classList.remove('invalid');
    });
    document.querySelectorAll('.error').forEach(function(element) {
      element.style.display = 'none';
    });
    var dta = $(this).serialize();
    $.post("/buy-local", {aj_x:'a', data:dta}, function(data) {
      if (data != '') {
        $('#content').html(data);
      } else {
        data = 'Oh no! There has been an error :(  Please contact us at <a href="mailto:service@flipsy.com">service@flipsy.com</a>';
        $('#content').html(data);
      }
    });
  }
});
// Enable/disable category select based on deviceType selection
const deviceType = document.getElementById('deviceType');
const brand = document.getElementById('brand');
deviceType.addEventListener('change', function() {
  let brandLoading = document.getElementById('brandLoading');
  if (!brandLoading) {
    brandLoading = document.createElement('span');
    brandLoading.id = 'brandLoading';
    brandLoading.className = 'loading-indicator';
    brandLoading.textContent = 'Loading...';
    brand.parentNode.appendChild(brandLoading);
  }
  if (deviceType.value) {
    brandLoading.style.visibility = 'visible';
    // AJAX to fetch brands for selected deviceType
    $.post('/buy-local', {aj_b: 1, deviceType: deviceType.value}, function(response) {
      let data = response;

      // If response is a string, try to parse as JSON
      if (typeof data === 'string') {
        try {
          data = JSON.parse(data);
        } catch (e) {
          data = {results: [], errors: []};
        }
      }
      // Clear previous options except placeholder
      brand.innerHTML = '<option value="">Select brand</option>';
      if (data.results && data.results.length > 0) {
        data.results.forEach(function(item) {
          const opt = document.createElement('option');
          opt.value = item.value;
          opt.textContent = item.text;
          brand.appendChild(opt);
          hasResults = true;
        });
        brand.disabled = false;
        brand.focus();
      } else {
        brand.disabled = true;
      }
      brandLoading.style.visibility = 'hidden';
      // Error handling
      let errorDiv = document.getElementById('brandFetchError');
      if (!errorDiv) {
        errorDiv = document.createElement('div');
        errorDiv.id = 'brandFetchError';
        errorDiv.className = 'error';
        brand.parentNode.appendChild(errorDiv);
      }
      if (Array.isArray(data.errors) && data.errors.length > 0) {
        errorDiv.textContent = data.errors.join(', ');
        errorDiv.style.display = 'block';
      } else if (!data.results || data.results.length === 0) {
        errorDiv.textContent = 'Invalid server response';
        errorDiv.style.display = 'block';
      } else {
        errorDiv.textContent = '';
        errorDiv.style.display = 'none';
      }
      brandLoading.style.visibility = 'hidden';
    }).fail(function() {
      brandLoading.style.visibility = 'hidden';
    });
  } else {
    brand.value = '';
    brand.disabled = true;
    // Also clear options except placeholder
    brand.innerHTML = '<option value="">Select brand</option>';
    let brandLoading = document.getElementById('brandLoading');
    if (brandLoading) brandLoading.style.visibility = 'hidden';
  }
});
// Enable/disable device select based on brand selection
const device = document.getElementById('device');
brand.addEventListener('change', function() {
  
  // Error div for model
  let deviceErrorDiv = document.getElementById('deviceFetchError');
  if (!deviceErrorDiv) {
    deviceErrorDiv = document.createElement('div');
    deviceErrorDiv.id = 'deviceFetchError';
    deviceErrorDiv.className = 'error';
    device.parentNode.appendChild(deviceErrorDiv);
  }
  if (brand.value) {
    // device loading indicator
    let deviceLoading = document.getElementById('deviceLoading');
    if (!deviceLoading) {
      deviceLoading = document.createElement('span');
      deviceLoading.id = 'deviceLoading';
      deviceLoading.className = 'loading-indicator';
      deviceLoading.textContent = 'Loading...';
      device.parentNode.appendChild(deviceLoading);
    }
    deviceLoading.style.visibility = 'visible';
    // AJAX to fetch devices for selected brand
    $.post(brand.value, {aj_m: 1}, function(response) {
      let data = response;
      if (typeof data === 'string') {
        try {
          data = JSON.parse(data);
        } catch (e) {
          data = null;
        }
      }
      device.innerHTML = '<option value="">Select device</option>';
      let hasResults = false;
      if (data && typeof data === 'object' && !Array.isArray(data)) {
        for (const key in data) {
          if (data.hasOwnProperty(key) && data[key].text && data[key].url) {
            const item = data[key];
            const opt = document.createElement('option');
            opt.value = item.url;
            opt.textContent = item.text;
            if (item.metatitle) opt.setAttribute('data-mt', item.metatitle);
            device.appendChild(opt);
            hasResults = true;
          }
        }
      }
      if (hasResults) {
        device.disabled = false;
        device.focus();
        deviceErrorDiv.textContent = '';
        deviceErrorDiv.style.display = 'none';
      } else {
        device.disabled = true;
        deviceErrorDiv.textContent = 'No devices found or invalid server response.';
        deviceErrorDiv.style.display = 'block';
      }
      deviceLoading.style.visibility = 'hidden';
    }).fail(function() {
      device.disabled = true;
      deviceErrorDiv.textContent = 'Failed to fetch devices.';
      deviceErrorDiv.style.display = 'block';
      deviceLoading.style.visibility = 'hidden';
    });
  } else {
    device.value = '';
    device.disabled = true;
    device.innerHTML = '<option value="">Select device</option>';
    deviceErrorDiv.textContent = '';
    deviceErrorDiv.style.display = 'none';
    let deviceLoading = document.getElementById('deviceLoading');
    if (deviceLoading) deviceLoading.style.visibility = 'hidden';
  }
});

// Enable/disable model select based on device selection
const model = document.getElementById('model');
device.addEventListener('change', function() {
  
  // Error div for model
  let modelErrorDiv = document.getElementById('modelFetchError');
  if (!modelErrorDiv) {
    modelErrorDiv = document.createElement('div');
    modelErrorDiv.id = 'modelFetchError';
    modelErrorDiv.className = 'error';
    model.parentNode.appendChild(modelErrorDiv);
  }
  if (device.value) {
    // Model loading indicator
    let modelLoading = document.getElementById('modelLoading');
    if (!modelLoading) {
      modelLoading = document.createElement('span');
      modelLoading.id = 'modelLoading';
      modelLoading.className = 'loading-indicator';
      modelLoading.textContent = 'Loading...';
      model.parentNode.appendChild(modelLoading);
    }
    modelLoading.style.visibility = 'visible';
    var selectedDeviceOption = device.options[device.selectedIndex];
    var deviceMT = selectedDeviceOption ? selectedDeviceOption.getAttribute('data-mt') : '';
    // AJAX to fetch models for selected brand
    $.post('/buy-local', {aj_mdl: 1, deviceMT: deviceMT}, function(response) {   		
      let data = response; console.log(data);
      if (typeof data === 'string') {
        try {
          data = JSON.parse(data);
        } catch (e) {
          data = {results: [], errors: []};
        }
      }
      model.innerHTML = '<option value="">Select model</option>';
      let hasResults = false;
      if (data.results && data.results.length > 0) {
        data.results.forEach(function(item) {
          const opt = document.createElement('option');
          opt.value = item.value;
          opt.textContent = item.text;
          model.appendChild(opt);
          hasResults = true;
        });
      }
      if (hasResults) {
        model.disabled = false;
        model.focus();
        modelErrorDiv.textContent = '';
        modelErrorDiv.style.display = 'none';
      } else {
        model.disabled = true;
        modelErrorDiv.textContent = 'No models found or invalid server response.';
        modelErrorDiv.style.display = 'block';
      }
      modelLoading.style.visibility = 'hidden';
    }).fail(function() {
      model.disabled = true;
      modelErrorDiv.textContent = 'Failed to fetch models.';
      modelErrorDiv.style.display = 'block';
      modelLoading.style.visibility = 'hidden';
    });
  } else {
    model.value = '';
    model.disabled = true;
    model.innerHTML = '<option value="">Select model</option>';
    modelErrorDiv.textContent = '';
    modelErrorDiv.style.display = 'none';
    let modelLoading = document.getElementById('modelLoading');
    if (modelLoading) modelLoading.style.visibility = 'hidden';
  }
});
// Set hidden pid field when model is selected
model.addEventListener('change', function() {
  var pidField = document.getElementById('pid');
  var selectedOption = model.options[model.selectedIndex];
  if (pidField && selectedOption && selectedOption.getAttribute('data-id')) {
    pidField.value = selectedOption.getAttribute('data-id');
  }
});
</script> 
</body>
</html>
