function doLogin( ) {
    if ( document.logon.userName.value == '' ) {
        alert('User ID cannot be blank.');
        document.logon.userName.focus();
        return false;
    }
    if ( document.logon.userPswd.value == '' ) {
        alert('Password cannot be blank.');
        document.logon.userPswd.focus();
        return false;
    }
    document.logon.submit();
    return false;
}
function chkCng ( obj ) {
    document.frmS.curr_page.value = obj.value;
    document.frmS.event.value = "GotoPage";
    document.frmS.submit();
    return false;
}
function chkRsPerPage( obj ) {
    document.frmS.rs_per.value = obj.value;
    document.frmS.event.value = "PageScale";
    document.frmS.submit();
}
function doNewSearch( ) {
    document.frmS.action = "RegOnline.jsp";
    document.frmS.cpr.value    = "CDC";
    document.frmS.event.value  = "";
    document.frmS.submit();
    return false;
}
function redoSearch( ) {
    document.frmS.action = "RegOnline.jsp";
    document.frmS.cpr.value    = "";
    document.frmS.event.value = "";
    document.frmS.submit();
    return false;
}
function setDayOfWeek( d ) {
    if (d!='') {
        document.fSearch.day_of_week.value=d;
    }
}
function setTimeOfDay ( t ) {
    if(t!='') {
        document.fSearch.time_of_day.value=t;
    }
}
function setGender(g){
    if (g!=''){
        document.fSearch.gender_req.value=g;
    }
}
function setAge(a1,a2){
    if(a1!=''){
        document.fSearch.age1.value=a1;
    }
    if (a2!=''){
        document.fSearch.age2.value=a2;
    }
}
function chkAge( ) {
    var a1 = document.fSearch.age1.value;
    var a2 = document.fSearch.age2.value;
    if ( a1 == "L" || a1 == "O" || a1 == "%" ) {
        document.fSearch.age2.value = "";
        return false;
    }
    if ( a2 != '' ) {
        if ( parseFloat(a1) > parseFloat(a2) ) {
            document.fSearch.age2.value = a1;
        }
    }
}
function showDetailView(clsid, rid) {
    document.frmS.clsid.value = clsid;
    document.frmS.rid.value   = rid;
    document.frmS.action      = "PDetailView.jsp";
    document.frmS.submit();
    return false;
}
function showAddOns(clsid, rid) {
    document.frmS.clsid.value = clsid;
    document.frmS.prnt.value  = clsid;
    document.frmS.rid.value   = rid;
    document.frmS.link.value  = "A";
    document.frmS.action      = "PDetailView.jsp";
    document.frmS.submit();
    return false;
}
function doSearchList( ) {
    document.frmS.action      = "RegSearchList.jsp";
    document.frmS.event.value = "PageScale";
    document.frmS.submit();
    return false;
}
function doNextRec( ) {
    document.frmS.event.value = "NextRecord";
    document.frmS.submit();
    return false;
}
function doPrevRec( ) {
    document.frmS.event.value = "PrevRecord";
    document.frmS.submit();
    return false;
}
function addtocart(s,r) {
    document.frmS.clsid.value = s;
    document.frmS.rid.value   = r;
    document.frmS.event.value = "add";
    document.frmS.submit();
    return false;
}
function doSignin( ) {
    document.frmS.action = "login.jsp";
    document.frmS.event.value = "PDet";
    document.frmS.submit();
    return false;
}
function chngBuyFor( obj ) {
    document.frmS.event.value = "ChngBuyFor";
    document.frmS.buyForIdx.value = obj.value;
    document.frmS.submit();
    return false;
}
function doViewCart ( typ ) {
    if ( typ == "d" ) {
        document.frmS.event.value = "Det"
    } else if ( typ == "s" ) {
        document.frmS.event.value = "Lst"
    }
    document.frmS.action = "https://154.1.0.128/RegOnline/ViewCart.jsp";
    document.frmS.submit();
    return false;
}
function round_decimals(original_number, decimals) {
    var result1 = original_number * Math.pow(10, decimals)
    var result2 = Math.round(result1)
    var result3 = result2 / Math.pow(10, decimals)
    return pad_with_zeros(result3, decimals)
}
function pad_with_zeros(rounded_value, decimal_places) {
    // Convert the number to a string
    var value_string = rounded_value.toString()
    // Locate the decimal point
    var decimal_location = value_string.indexOf(".")
    // Is there a decimal point?
    if (decimal_location == -1) {
        // If no, then all decimal places will be padded with 0s
        decimal_part_length = 0
        // If decimal_places is greater than zero, tack on a decimal point
        value_string += decimal_places > 0 ? "." : ""
    }
    else {
        // If yes, then only the extra decimal places will be padded with 0s
        decimal_part_length = value_string.length - decimal_location - 1
    }
    // Calculate the number of decimal places that need to be padded with 0s
    var pad_total = decimal_places - decimal_part_length
    if (pad_total > 0) {
        // Pad the string with 0s
        for (var counter = 1; counter <= pad_total; counter++) 
            value_string += "0"
        }
    return value_string
}
function objformatCurrency(obj) {
    obj.value = currencyNumberOnly(obj.value);
    if ( isNaN(obj.value) ) {
        obj.value = '0.00';
    }
    obj.value = '$'+formatCurrency(obj.value);
}
function formatCurrency(num) {
   num = num.toString().replace(/\$|\,/g,'');
   if(isNaN(num)) {
      alert("Not a valid Currency");
      document.forms[form][obj.name].value = 0;
      return false;
   }
   sign = (num == (num = Math.abs(num)));
   num = Math.floor(num*100+0.50000000001);
   cents = num%100;
   num = Math.floor(num/100).toString();
   if(cents<10) { cents = "0" + cents; }
   for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
   num = num.substring(0,num.length-(4*i+3))+','+
   num.substring(num.length-(4*i+3));
   return num+"."+cents;
}
function currencyNumberOnly (n) {
	var inx = 0; var num = ''; var isNegative = 'N';
    if ( n.indexOf('(') > -1 || n.indexOf(')') > -1 ) { isNegative = 'Y'; }
	while ( inx <= n.length ) {
		if ( n.charAt(inx) >= 0 && n.charAt(inx) <= 9 || n.charAt(inx) == '.' || n.charAt(inx) == '-' ) {
			num = num + n.charAt(inx);
		}
		inx ++;
	}
    if ( isNegative == 'Y' ) {
        if ( parseFloat(num) > 0 ) {
             num = (parseFloat(num) * -1);
        }
    }
	return num;
}
function validatePhone(obj){
    var p = obj.value;
    if ( p != '' ) {
        p = phoneNumberOnly( p );
    }
    if ( p.length > 3 && p.length < 8 ) {
        x = p.indexOf('-');
        if ( x == -1 ) {
            p = p.substring(0,3) + "-" + p.substring(3,130);
        }
    } else if ( p.length >= 8 && p.length <= 10 ) {
        if ( event.keyCode != 8 || event.keyCode != 46 ) {
            x1 = p.indexOf('(');
            if ( x1 == -1 ) {
                p = "(" + p;
            }
            x2 = p.indexOf(')');
            if ( x2 == -1 ) {
                p = p.substring(0,4) + ")" + p.substring(4,130);
            }
            x3 = p.indexOf('-');
            if ( x3 == -1 ) {
                p = p.substring(0,8) + "-" + p.substring(8,130);
            } else {
                p = p.substring(0,x3) + p.substring(x3+1,130);
                p = p.substring(0,8) + "-" + p.substring(8,130);
            }
        }
    }
    obj.value = p;
}
function phoneNumberOnly (p) {
    var inx = 0;
    var phone = '';
    while ( inx <= p.length ) {
        if ( p.charCodeAt(inx) >= 48 && p.charCodeAt(inx) <= 57 ) {
            phone = phone + p.charAt(inx);
        }
        inx ++;
    }
    return phone;
}
function logOut (link) {
    window.location.href = link;
}
function goHome (link) {
    window.location.href = link;
}
function showCCDisc (width,height,id) {
    if ( width  == '' ) { width  = '500'; }
    if ( height == '' ) { height = '500'; }
    var ix1 = width.indexOf('px');
    var ix2 = height.indexOf('px');
    if ( ix1 > -1 ) { width  = width.substring(0,ix1);  }
    if ( ix2 > -1 ) { height = height.substring(0,ix2); }
    var win = window.open('CCDisclaimer.jsp?sid='+id+'&typ=Privacy','mblccdisclaimer','menubar=1,resizable=yes,scrollbars=yes,width='+width+',height='+height);
    win.focus();
    return false;
}
function showContact (width,height,id) {
    if ( width  == '' ) { width  = '500'; }
    if ( height == '' ) { height = '500'; }
    var ix1 = width.indexOf('px');
    var ix2 = height.indexOf('px');
    if ( ix1 > -1 ) { width  = width.substring(0,ix1);  }
    if ( ix2 > -1 ) { height = height.substring(0,ix2); }
    var win = window.open('CCDisclaimer.jsp?sid='+id+'&typ=Contact','contactus','menubar=1,resizable=yes,scrollbars=yes,width='+width+',height='+height);
    win.focus();
    return false;
}