function confirmCancel(id) {
	if (confirm("Do you want to cancel this membership?")) {
		document.location = 'customer-bill.php?action=cancel&id=' + id;
	}
}

function issueRefund(id,invoice) {
	if (confirm("Do you want to issue refund?")) {
		document.location = 'customer-bill.php?action=refund&id='+id+'&invoice=' + invoice;
	}
}

function toggleBox(szDivID, iState) // 1 visible, 0 hidden
{
   var obj = document.layers ? document.layers[szDivID] :
   document.getElementById ?  document.getElementById(szDivID).style :
   document.all[szDivID].style;
   obj.display = document.layers ? (iState ? "show" : "hide") :
   (iState ? "block" : "none");
}


function HideMsg() {
	setTimeout("HideOpenMsg()",4000);
}

function HideOpenMsg() {
	if (document.getElementById){
		document.getElementById('msg').style.visibility='hidden';
	} else {
		if (document.layers){ //NS4
			document.msg.visibility = 'hidden';
		} else { //IE4
			document.all.msg.style.visibility = 'hidden';
		}
	}
}

function waitPreloadPage() { //DOM
	if (document.getElementById){
		document.getElementById('prepage').style.visibility='hidden';
	} else {
		if (document.layers){ //NS4
			document.prepage.visibility = 'hidden';
		} else { //IE4
			document.all.prepage.style.visibility = 'hidden';
		}
	}
}


function submitform() {
	if(document.process.onsubmit()) {
		document.process.submit();
		document.process.go.style.color = '#FFFFFF';
		document.process.go.style.background = 'url()';
		document.process.go.value = 'Please Wait!';				// rename submit button
		document.process.go.disabled = true;					// Disable submit button
	}
}

function submitOpt() {
		document.process.submit();
		document.process.go.value = 'Please Wait!';				// rename submit button
		document.process.go.disabled = true;					// Disable submit button
}

function setPointer(theRow, thePointerColor)
{
  if (typeof(theRow.style) == 'undefined' || typeof(theRow.cells) == 'undefined') {
    return false;
  }
  var row_cells_cnt = theRow.cells.length;
  for (var c=0; c < row_cells_cnt; c++) {
    theRow.cells[c].bgColor = thePointerColor;
  }
  return true;
}

function handleEnter (field, event) {
	var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
	if (keyCode == 13) {
		var i;
		for (i = 0; i < field.form.elements.length; i++)
			if (field == field.form.elements[i])
				break;
		i = (i + 1) % field.form.elements.length;
		field.form.elements[i].select();
		return false;
	} 
	else
	return true;
}



function formatPhone(PhoneNumberInitialString)
  {
    var FmtStr="";
    var index = 0;
    var LimitCheck;

    LimitCheck = PhoneNumberInitialString.length;
    while (index != LimitCheck)
      {
        if (isNaN(parseInt(PhoneNumberInitialString.charAt(index))))
          { }
        else
          { FmtStr = FmtStr + PhoneNumberInitialString.charAt(index); }
        index = index + 1;
      }
    if (FmtStr.length >= 10)
      {
        FmtStr = "" + FmtStr.substring(0,3) + "-" + FmtStr.substring(3,6) + "-" + FmtStr.substring(6,10);
      }
    return FmtStr;
  }


function viewGuide() {
	var baseurl = 'guidelines.php?state=';
	state = this.applicant.state.value;
	if (state.lenght != 0) {
		frames['guidelines'].location.href = baseurl + state;
	}
}



function formatCard(InitialString) {
    var FmtStr="";
    var index = 0;
    var LimitCheck;

    LimitCheck = InitialString.length;
    while (index != LimitCheck)
      {
        if (isNaN(parseInt(InitialString.charAt(index))))
          { }
        else
          { FmtStr = FmtStr + InitialString.charAt(index); }
        index = index + 1;
      }
    if (FmtStr.length >= 4)
      {
        FmtStr = "" + FmtStr.substring(0,4) + "-" + FmtStr.substring(4,8) + "-" + FmtStr.substring(8,12) + "-" + FmtStr.substring(12,16);
      }
    return FmtStr;
}

function formatSSN(InitialString) {
    var FmtStr="";
    var index = 0;
    var LimitCheck;

    LimitCheck = InitialString.length;
    while (index != LimitCheck)
      {
        if (isNaN(parseInt(InitialString.charAt(index))))
          { }
        else
          { FmtStr = FmtStr + InitialString.charAt(index); }
        index = index + 1;
      }
    if (FmtStr.length >= 4)
      {
        FmtStr = "" + FmtStr.substring(0,3) + "-" + FmtStr.substring(3,5) + "-" + FmtStr.substring(5,9);
      }
    return FmtStr;
}


function formatDate(InitialString) {
    var FmtStr="";
    var index = 0;
    var LimitCheck;

    LimitCheck = InitialString.length;
    while (index != LimitCheck)
      {
        if (isNaN(parseInt(InitialString.charAt(index))))
          { }
        else
          { FmtStr = FmtStr + InitialString.charAt(index); }
        index = index + 1;
      }



    if (FmtStr.length == 4)
      {
	var findyear = FmtStr.substring(2,4);
	if (findyear < 20) findyear = "20";
	else findyear = "19";
        FmtStr = "0" + FmtStr.substring(0,1) + "/0" + FmtStr.substring(1,2) + "/" + findyear + FmtStr.substring(2,4);

      }
    if (FmtStr.length == 5)
      {
	var findyear = FmtStr.substring(3,5);
	if (findyear < 20) findyear = "20";
	else findyear = "19";

	var findmonth = FmtStr.substring(0,2);
	if (findmonth > 12) { findmonth = "0" + FmtStr.substring(0,1); findday = FmtStr.substring(1,3); }
	else { findmonth = FmtStr.substring(0,2); findday = "0" + FmtStr.substring(2,3); }	


        FmtStr = "" + findmonth + "/" + findday + "/" + findyear + FmtStr.substring(3,5);

      }

    if (FmtStr.length == 6)
      {
	var findyear = FmtStr.substring(4,6);
	if (findyear < 20) findyear = "20";
	else findyear = "19";
        FmtStr = "" + FmtStr.substring(0,2) + "/" + FmtStr.substring(2,4) + "/" + findyear + FmtStr.substring(4,6);

      }
    if (FmtStr.length == 8)
      {
        FmtStr = "" + FmtStr.substring(0,2) + "/" + FmtStr.substring(2,4) + "/" + FmtStr.substring(4,8);
      }

    return FmtStr;
}

function popUp(URL) {
	day = new Date();
	id = day.getTime();
	eval("page" + id + " = window.open('/pop.php?id=' + URL, '" + id + "', 'addressbar=0,toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=0,width=600,height=380');");
}

function popPage(URL) {
	day = new Date();
	id = day.getTime();
	eval("page" + id + " = window.open('/' + URL + '.html', '" + id + "', 'addressbar=0,toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=0,width=600,height=500');");
}

function drillDown(sourceID, startdate, enddate, status) {
	day = new Date();
	id = day.getTime();
	eval("page" + id + " = window.open('report-membership-drill.php?sourceID=' + sourceID + '&startDate=' + startdate + '&endDate=' + enddate + '&status=' + status, '" + id + "', 'addressbar=0,toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=0,width=860,height=560');");
}

var exit=true;
function exitwindow() {
	var url = '/exit.php';
	var win = 'toolbar=0,directories=0,menubar=0,scrollbars=0,resizable=0,width=450,height=549';
	if (exit) {
		day = new Date();
		id = day.getTime();
		eval("page" + id + " = window.open(url, '" + id + "', 'addressbar=0,toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=450,height=549');");

	}
}
