﻿var last_element;
var no_email = false;
var move_in = 0;

function checkNoEmail() {
  var ea = document.getElementById('ctl00_cphMain_rStep3_ctl00_email_address');
  if (no_email == false && ea.value.length == 0) {
    var modalPopupBehavior = $find('mpeNoEmailcheckModalPopupBehavior');
    modalPopupBehavior.show();
    return false;
  } else {
    return true;
  }
}

function focusEmail() {
  var ea = document.getElementById('ctl00_cphMain_rStep3_ctl00_email_address');
  if (ea) {
      ea.focus();
  }
}

function setNoEmail() {
    no_email = true;
}

function showOrderTypeDisclaimer(i) {
  if (i) {
    move_in = move_in + 1;
  }
  var ot1 = document.getElementById('ctl00_cphMain_rStep3_ctl00_service_type_1');
  if (move_in > 2) {
    document.location.href = '/TexasSmartLock/Default.aspx?must_call=True';
  }
  if (ot1.checked) {
    var modalPopupBehavior = $find('mpeOrderTypeCheckModalPopupBehavior');
    modalPopupBehavior.show();
    return false;
  } else {
    return true;
  }
}

function setOrderType() {
  var ot0 = document.getElementById('ctl00_cphMain_rStep3_ctl00_service_type_0');
  var ot1 = document.getElementById('ctl00_cphMain_rStep3_ctl00_service_type_1');
  ot0.checked = false;
  ot1.checked = false;
}
function Trim(textbox) {
  textbox.value = textbox.value.replace(/^\s+|\s+$/g, '');
}
function returnFocus() {
  var el = last_element;
  if (el != null) {
    el.focus();
    return true;
  }
}
function setMsg() {
  var msg = document.getElementById(arguments[0]);
  if (msg != null) {
    msg.innerHTML = arguments[1];
    return true;
  }
}
function toggleDisplay() {
  var el = document.getElementById(arguments[0]);
  if (el == null) {
    return true;
  }
  if (el.style.display == 'none') {
    el.style.display = 'block';
  } else {
    el.style.display = 'none';
  }
  return true;
}
function disableAllAfterValidate() {
  var v = Page_ClientValidate(arguments[0]);
  if (v == true) {
    window.setTimeout("disableAllInPanel('" + arguments[1] + "');", 0);
  }
}
function disableAllAfter() {
  window.setTimeout("disableAllInPanel('" + arguments[0] + "');", 0);
}
function disableAllInPanel() {
  var pnl = document.getElementById(arguments[0]);
  if (pnl) {
    var tb = pnl.getElementsByTagName('input');
    for (i = 0; i < tb.length; i++) {
      if (tb[i].type + '' != 'undefined' && tb[i].type + '' != 'hidden') {
        try { tb[i].disabled = true; } catch (err) { }
      }
    }
    var links = pnl.getElementsByTagName('a');
    for (i = 0; i < links.length; i++) {
      try { links[i].disabled = true; } catch (err) { }
      try { links[i].href = 'javascript:void(0);'; } catch (err) { }
    }
    var sels = pnl.getElementsByTagName('select');
    for (i = 0; i < sels.length; i++) {
      try { sels[i].disabled = true; } catch (err) { }
    }
  }
}
function hidePanel(el) {
  var errPanel = document.getElementById(el);
  if (errPanel != null) {
    var errStyle = errPanel.style.display;
    if (errStyle != null) {
      if (errStyle != 'none') {
        errPanel.style.display = 'none';
      }
    }
  }
}

function isChecked(chkd, t, val, vg) {
  var t = document.getElementById(t);
  if (chkd) {
    t.value = 'yes';
    } else {
    t.value = '';
  }
  var v = document.getElementById(val);
  ValidatorValidate(v, vg);
}

function finalCheck() {
  if (!Page_ClientValidate(arguments[0])) {
    return false;
  }
  if (checkNoEmail() && showOrderTypeDisclaimer(false)) {    
    disableListAfterValidate(arguments[0], arguments[1], arguments[2]);
    return true;
  } else {
  return false;
}
}

