var CaptchaGenNo = 0;
var CoverFrame;

function ReGenCaptcha(CaptchaObj) {
  CaptchaObj.src = "/Scripts/ASP/Captcha.asp?Regen=" + CaptchaGenNo;
  CaptchaGenNo++;
}

function breakout() {
  if (window.top!=window.self) {
    window.top.location = window.location;
  }
}

function InfoPrompt() {
  var WindowURL = "/Scripts/ASP/InfoPrompt.asp";
  window.open(WindowURL,"_blank","directories=no,fullscreen=no,height=600,width=500,location=no,menubar=no,resizable=no,scrollbars=no,status=no,toolbar=no");
}

function ShowFLV() {
  var WindowURL = "/Scripts/ASP/ShowFLV.asp";
  window.open(WindowURL,"_blank","directories=no,fullscreen=no,height=460,width=580,location=no,menubar=no,resizable=no,scrollbars=no,status=no,toolbar=no");
}

function LaunchClientAdmin(GoToTab) {
  var WindowURL = "/Accounts/default.asp?Tab=" + GoToTab;
  window.open(WindowURL,"ClientAdmin","directories=no,fullscreen=no,height=1000,width=850,location=no,menubar=no,resizable=no,scrollbars=yes,status=no,toolbar=no");
}

function OpenPrivacy() {
  var WindowURL = "/Scripts/ASP/Privacy.asp";
  window.open(WindowURL,"PrivacyWindow","directories=no,fullscreen=no,height=600,width=550,location=no,menubar=no,resizable=no,scrollbars=yes,status=no,toolbar=no");
}

function OpenTerms() {
  var WindowURL = "/Scripts/ASP/TermsOfUse.asp";
  window.open(WindowURL,"TermsWindow","directories=no,fullscreen=no,height=600,width=550,location=no,menubar=no,resizable=no,scrollbars=yes,status=no,toolbar=no");
}

function LogOut() {
  if (confirm("Are you sure you wish to log out?")) {
    window.location = "/Accounts/Logout.asp";
  }
}

function GetMultiVals(SelectObj) {
  var selectedArray = "";
  var i = 0;

  for (i=0; i < SelectObj.options.length; i++) {
    if (SelectObj.options[i].selected) {
      selectedArray = selectedArray + SelectObj.options[i].value + ",";
    }
  }
  if (selectedArray != "") { selectedArray = selectedArray.substr(0, selectedArray.length - 1); }
  return selectedArray;
}

function PhoneEntry(PhoneObj) {
  var RetVal = "";
  var TempVal = "";
  var PhoneLoop = 0;

  if (PhoneObj.value.length > 0) {
    for (PhoneLoop = 0; PhoneLoop <= PhoneObj.value.length; PhoneLoop++) {
      if (IsNumeric(PhoneObj.value.substr(PhoneLoop, 1)) == true) {
        TempVal = TempVal + PhoneObj.value.substr(PhoneLoop, 1);
      }
    }
    if ((TempVal.length > 0) && (TempVal.length <= 10)) {
      if ((TempVal.length > 3) && (TempVal.length <= 7)) {
        RetVal = TempVal.substr(0, 3) + "-" + TempVal.substr(3, TempVal.length - 3);
      }
      else if ((TempVal.length > 7) && (TempVal.length <= 10)) {
        RetVal = "(" + TempVal.substr(0, 3) + ") " + TempVal.substr(3, 3) + "-" + TempVal.substr(6, TempVal.length - 6);
      }
      else {
        RetVal = TempVal;
      }
      PhoneObj.value = RetVal;
    }
  }
}

function PhoneNoOnly(PhoneObj) {
  var RetVal = "";
  var TempVal = "";
  var PhoneLoop = 0;

  if (PhoneObj.value.length > 0) {
    for (PhoneLoop = 0; PhoneLoop <= PhoneObj.value.length; PhoneLoop++) {
      if (IsNumeric(PhoneObj.value.substr(PhoneLoop, 1)) == true) {
        TempVal = TempVal + PhoneObj.value.substr(PhoneLoop, 1);
      }
    }
    RetVal = TempVal.substr(0, 10);
  }
  return RetVal;
}

function IsNumeric(sText) {
  var ValidChars = "0123456789.";
  var IsNumber=true;
  var Char;
 
  for (i = 0; i < sText.length && IsNumber == true; i++) { 
    Char = sText.charAt(i);
    if (ValidChars.indexOf(Char) == -1) {
      IsNumber = false;
    }
  }
  return IsNumber;
}

function findPos(obj) {
  var curleft = 0;
  var curtop = 0;

  if (obj.offsetParent) {
    do {
      curleft += obj.offsetLeft;
      curtop += obj.offsetTop;
    } while (obj = obj.offsetParent);
  }
  return [curleft,curtop];
}

function CoverIframe(divPopup) {

  CoverFrame = document.createElement("IFRAME");

  CoverFrame.setAttribute("src", "/Scripts/ASP/Blank.asp");
  CoverFrame.style.position = "absolute";
  CoverFrame.style.left = divPopup.offsetLeft + "px";
  CoverFrame.style.top = divPopup.offsetTop + "px";
  CoverFrame.style.width = divPopup.offsetWidth + "px";
  CoverFrame.style.height = divPopup.offsetHeight + "px";
  CoverFrame.style.zIndex = "1";

  document.body.appendChild(CoverFrame);
}

function unCoverIframe() {
  document.body.removeChild(CoverFrame);
  CoverFrame = null;
}

function TruePageSize(XorY) {
  if (window.innerHeight && window.scrollMaxY) {// Firefox
    yWithScroll = window.innerHeight + window.scrollMaxY + 1;
    xWithScroll = window.innerWidth + window.scrollMaxX  - 18;
  }
  else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
    yWithScroll = document.body.scrollHeight;
    xWithScroll = document.body.scrollWidth;
  }
  else { // works in Explorer 6 Strict, Mozilla (not FF) and Safari
    yWithScroll = document.body.offsetHeight;
    xWithScroll = document.body.offsetWidth;
  }
  //alert( 'The height is ' + yWithScroll + ' and the width is ' + xWithScroll );
  if (XorY=="Width") return xWithScroll;
  if (XorY=="Height") return yWithScroll + 10;
}

function thisTagIndex(OrigObj) { 
  var ParentObj = OrigObj.parentNode;
  var count = 0;
  for (i=0; i<=ParentObj.childNodes.length - 1; i++) {
    if (ParentObj.childNodes[i].nodeType == 1) {
      if (ParentObj.childNodes[i].tagName == OrigObj.tagName) {
        if (ParentObj.childNodes[i] == OrigObj) {
          return count;
        }
        else {
          count++
        }
      }
    }
  }
}