﻿//show apply selection to all link
function showApplySelectAllLink(){    
    var foIDDuplicate="";
    var participantidList="";
    $("span[participantid]").each(function() { 
        var participantItemId = $(this).attr("participantid");        
        if(participantidList.indexOf(participantItemId) < 0){
            foIDDuplicate = "";
        }
        if( $(this).children().attr("type") == 'checkbox'){
            var checkboxid = $(this).children().attr("id").toString();
            var fostartpos = checkboxid.indexOf("_foOption_");
            if( fostartpos > 0){
                var foendpos = $(this).children().attr("id").lastIndexOf("_");
                var foID = $(this).children().attr("id").substring(fostartpos+10,foendpos); 
                if (foIDDuplicate.indexOf(foID) < 0 ){
                    if($("span[participantid='"+participantItemId+"']>input[id*='"+foID+"'][type='checkbox']").size() > 1 ){
                        var suffixstartpos= foendpos;
                        var suffix= $(this).children().attr("id").substring(suffixstartpos);
                        var tdid = "#tdApplySelectionToAll_"+foID+suffix;
                        var ahtmlcontent = "<a href=\"javascript:selectallsameFO(\'"+$(this).children().attr("id").substring(fostartpos,foendpos)+"\',\'"+$(this).attr("participantid")+"\');\">"+$(this).attr("linkname")+"</a>"
                        $(tdid).html(ahtmlcontent);                
                        foIDDuplicate = foIDDuplicate + "," + foID; 
                        if (participantidList.indexOf(participantItemId) < 0 ){
                                participantidList = participantidList + "," + participantItemId; 
                            }
                        }
                }
             }
         }            
    });
}

//select duplicate FO per participant
function selectallsameFO(foid,participantid){  
    if($("span[participantid='"+participantid+"']>input[id*='"+foid+"'][type='checkbox']").attr('checked')){  
        $("span[participantid='"+participantid+"']>input[id*='"+foid+"'][type='checkbox']").attr('checked',true);
    }else{
        $("span[participantid='"+participantid+"']>input[id*='"+foid+"'][type='checkbox']").attr('checked',false);
    }
}

//for get inline style
function getStylevalue(objid, recorderid,styletext) {                            
            document.getElementById(recorderid).value = document.getElementById(objid).style.cssText +";"+ styletext;
        }
//for set inline style
function setStylevalue(objid, recorderid,styletext) {  
            if(document.getElementById(recorderid).value.length > 0){
                document.getElementById(objid).style.cssText = document.getElementById(recorderid).value +";"+ styletext +";display:block;overflow-x:hidden;overflow-y:hidden";
            }else{
                document.getElementById(objid).style.cssText = styletext +";display:block;overflow-x:hidden;overflow-y:hidden";
            }
        }
 
//for get textarea which don't need grow up.If text area don't need scroll bar, return true.
function setTextAreaNOGrowup(objid) {    
        var objArray=new Array("txtWaiver","txtPersonalMessage");
        //new Array("Saab","Volvo","BMW");
        var returnValue=false;
        for (i=0; i< objArray.length; i++ )
        {
            if(objid.indexOf(objArray[i]) < 0)
            {
                returnValue=true;
                break;
            }
        }
        return returnValue;
    }     
    
        
//for set all multiline inline style in one page
function setAllStylevalue() {              
            $("textarea").each(function() { 
            if ($(this).attr('name') != '' && setTextAreaNOGrowup($(this).attr('id'))){
                document.getElementById($(this).attr("id")).style.cssText =document.getElementById($(this).attr("id").replace("txtInput","stylerecorder")).value +";display:block;overflow-x:hidden;overflow-y:hidden";                              
            }}); 
        }

//when click next button,verify all required fields in buddy request page
function verifyBuddyRequestFields(){   
    var bInput =false;     
        $("input[id*=txtBuddyRequest]").each(function() { 
        if ($(this).val().length>0){
            bInput=true;
            }}); 
        if(bInput)
        {
            return confirm("You have filled out information but have not accepted/requested. Are you sure you want to continue to the next page?");
        }else
        {return true;}
        
}        

//for limit user input characters
function limitChars(id, maxcount) {
            var obj = document.getElementById(id);
            var objlength = obj.value.length + obj.value.split("\n").length-1;
            if ( objlength > maxcount) {
                obj.value = obj.value.substring(0, (maxcount-obj.value.split("\n").length+1));                
            }
        }
        
//for Show user input characters num
function ShowTxtCount(id, showTxtCountid,maxvalue) {
            var obj = document.getElementById(id);
            var showTxtCountObj = document.getElementById(showTxtCountid);
            var objlength = obj.value.length + obj.value.split("\n").length-1;
            var JQueryshowTxtCountObj = $(showTxtCountObj);
            JQueryshowTxtCountObj.html(objlength + "/" + maxvalue);
            
        }
        
function MultilinetextIsWithinMinMax(input,min,max,cssClass, styles, errClass, errStyles, required,showTxtCountid,recorderid) {
    var inputObj = document.getElementById(input);
    var isValid = true;
    
    
    if (inputObj.value.length + inputObj.value.split("\n").length-1 < min) {
            isValid = false;
    }    
    if ((inputObj.value.length + inputObj.value.split("\n").length-1 > max) && (max > 0)) {
        isValid = false;
    }
    
    if ((required) && (inputObj.value.length == 0)) {
    isValid = true;
    } 
        
    //if isValid is false at this point, then the control failed validation again
    //the regular expression which means we need to highlight the field to draw
    //the user's attention to the error.
    document.getElementById(showTxtCountid).style.cssText = "color:#333333;";
    if(isValid == false) {
        inputObj.className = errClass;
        inputObj.style.cssText = errStyles;
                
        document.getElementById(showTxtCountid).style.cssText = "color:#FF0000;";
        
        resetNavigationButtons();
	}           
    else if (!required)
    {
        inputObj.className = cssClass;
        inputObj.style.cssText = styles;	        
    }     
   
    return isValid;
}

//let firefox support innerText property
function getInnerText(elemnetid)
{
    var hasInnerText = (document.getElementsByTagName("body")[0].innerText != undefined) ? true : false;
    var elem = document.getElementById(elemnetid);   
    if(!hasInnerText){
       return elem.textContent ;        
    } else{
       return elem.innerText ;        
    }    
}

//let firefox support innerText property
function setInnerText(elemnetid,value)
{
    var hasInnerText = (document.getElementsByTagName("body")[0].innerText != undefined) ? true : false;
    var elem = document.getElementById(elemnetid);   
    if(!hasInnerText){
       elem.textContent = value ;        
    } else{
       elem.innerText  = value ;        
    }    
}


//This is for the Absolute position for a control on the page
function getAbsolutePos(ATarget)
{
    var target = ATarget;
    var pos = {x:target.offsetLeft, y:target.offsetTop};
    
    var target = target.offsetParent;
    while (target)
    {
        pos.x += target.offsetLeft;
        pos.y += target.offsetTop;
        
        target = target.offsetParent
    }
    
    return pos;
}

//we want to find the first control that may accept user input, except button
//then we set focus on that control for easy user input without mouse
function setFocusOnFirstNonButton()
{
    //get all input and select control
    var inputArray = document.getElementsByTagName("input");
    var selectArray = document.getElementsByTagName("select");

    //find the top one of each group
    var firstInput = null;
    if (inputArray != null) {
        for (i=0; i< inputArray.length; i++ )
        {
            if(inputArray[i].type != "button" 
                && inputArray[i].type != "hidden"
                && inputArray[i].type != "image"
                && inputArray[i].disabled == false)
            {
                firstInput = inputArray[i];
                break;
            }
        }
    }
    
    var firstSelect = null;    
    if (selectArray != null) {
        for (i=0; i< selectArray.length; i++ )
        {
            if(selectArray[i].disabled == false)
            {
                firstSelect = selectArray[i];
                break;
            }
        }
    }
    
    //get the top one on the page
    var topOne = null
    if (firstInput != null && firstSelect != null)
    {
        var inputOffset = getAbsolutePos(firstInput);
        var selectOffset = getAbsolutePos(firstSelect);
        
        if (inputOffset.y < selectOffset.y)
        {
            topOne = firstInput;
        }
        else if (inputOffset.y > selectOffset.y)
        {
            topOne = firstSelect;
        }
        else
        {
            //here means they are on the same horizontal, get the left one
            topOne = inputOffset.x <= selectOffset.x ? firstInput : firstSelect
        }
    }
    else if (firstInput != null)
    {
        topOne = firstInput;
    }
    else if (firstSelect != null)
    {
        topOne = firstSelect;
    }
    
    if (topOne != null)
    {
        topOne.focus();
    }
}

//Those three functions is used for "When enter is pressed assume the continue button"
//and we call registerEnterKeyHandler at first, so that once user hit enter, we just call onclick of next button
function registerEnterKeyHandler(){
    if(document.addEventListener){
    document.addEventListener("keypress",fireFoxEnterKeyHandler, true);
    }else{
    document.attachEvent("onkeypress",ieEnterKeyHandler);
    }
}
function fireFoxEnterKeyHandler(evt){
    //alert("firefox");
    
    if(evt.keyCode == 13 
        && document.getElementById("btnNextCustom_1") != null
        && evt.target.tagName != "A"
        && evt.target.type != "button"
        && evt.target.type != "submit"
        && (evt.target.type != "textarea" || evt.target.name.indexOf("txtWaiver") > 0))
        {
        document.getElementById("btnNextCustom_1").click();
    }
}
function ieEnterKeyHandler(evt){
    if(evt.keyCode == 13
        && document.getElementById("btnNextCustom_1") != null
        && evt.srcElement.tagName != "A"
        && evt.srcElement.type != "button"
        && evt.srcElement.type != "submit"
        && (evt.srcElement.type != "textarea" || evt.srcElement.name.indexOf("txtWaiver") > 0))
        {
        document.getElementById("btnNextCustom_1").click();
    }
}

//here we'd like to disable all the controls which may cause post back action when user change their selection,
//so that user can't send request to the server frequently, they have to wait to the end of response on server side
//this is used for avoid 'Invalid postback or callback argument.' exception which throw by dotNet platform
// HERE we assume only all the INPUT type and select type would cause POSTBACK, so that we don't need to go through
//everything on the page, as Internet Explorer running very slow with javascript
function disablePostBackControls() {

    var contronlArray = document.getElementsByTagName("input");
    
    if (contronlArray != null){
        for (i=0; i< contronlArray.length; i++ )
        {
            if(contronlArray[i].type != "text"
                && (contronlArray[i].onchange != null || contronlArray[i].onclick != null)){
                contronlArray[i].disabled = true;
            }
        }
    }
    
    contronlArray = document.getElementsByTagName("select");
    
    if (contronlArray != null){
        for (i=0; i< contronlArray.length; i++ )
        {
            if(contronlArray[i].onchange != null || contronlArray[i].onclick != null){
                contronlArray[i].disabled = true;
            }
        }
    }
}


//This function is for register multi function to handle window.onload event
function addLoadEvent(func) {   
    var oldonload = window.onload;   
    if (typeof window.onload != 'function') {   
        window.onload = func;   
    } else {   
        window.onload = function() {   
            if (oldonload) {   
                oldonload();   
            }   
            func();   
        }   
    }   
} 

//Gets or Sets the __EVENTARGUMENT hidden input control on a given page
function EVENTARGUMENT(formName, input) {
    var theform;
    //The code that is commented out is supposed to accomodate IE Browser, but causes error on IE 7
    //It may still be necessary for older versions of IE, needs to be tested.
    //if (window.navigator.appName.toLowerCase().indexOf("microsoft") > -1) {
    //    theform = document.formName; 
    //}
    //else {
        theform = document.forms[formName]; 
    //}
    if (input != '') {
        //SET
        theform.__EVENTARGUMENT.value = input;
    }
    else {
        return theform.__EVENTARGUMENT.value;
    }
}

function tabNext(e, currentField, nextField) {
    var fld = document.getElementById(currentField);
    var nxtfld = document.getElementById(nextField);
    var key;

    if(window.event) { //IE
        key = e.keyCode;
    }
    else if(e.which) { // Netscape/Firefox/Opera
        key = e.which;
    }
    
    //if((key >= 48 && key <= 57) && fld.value.length == fld.maxLength) {
    //add support for Number Pad
    if((key >= 48 && key <= 57 || key >= 96 && key <= 105) && fld.value.length == fld.maxLength) {
        nxtfld.focus();
        if(nxtfld == '[object HTMLInputElement]' || nxtfld == '[object]') {
            nxtfld.select();
        }
    }
}

function tabBack(e, currentField, previousField) {
    var fld = document.getElementById(currentField);
    var prevfld = document.getElementById(previousField);
    var key;

    if(window.event) { //IE
        key = e.keyCode;
    }
    else if(e.which) { // Netscape/Firefox/Opera
        key = e.which;
    }
    if(key == 8 && fld.value.length == 0) {
    //they hit the backspace key and the field they are in is empty
    //so we need to give focus to the previous field.
            prevfld.focus();
            prevfld.select();
            return false;
    }
    else {
        return true;
    }
}

function restoreDefaultText(field, defaultText) {
    var fld = document.getElementById(field);
        
    if(fld.value == '') {
        fld.value = defaultText;
    }
}

function inputMask(e, type) {
    var key;

    if(window.event) { //IE
        key = e.keyCode;
    }
    else if(e.which) { // Netscape/Firefox/Opera
        key = e.which;
    }
    
    switch(type) {
        case 'numbers only':
            // modified to  allow the number pad
            if((key >= 58 && key <= 95) || (key >=106 && key <= 126) || (key <= 47 && key >= 32)) {
                return false;
            }
            else {
                return true;
            }
            break;
        case 'money':
        //allows a dollar sign and decimal point
            if((key >= 58 && key <= 126) || (key == 47) || (key <= 45 && key >= 32)) {
                return false;
            }
            else {
                return true;
            }
        case 'account number':
        //allows spaces and dashes
            if((key >= 58 && key<= 126) || (key <= 47 && key >= 46) || (key <= 44 && key >= 33)) {
                return false;
            }
            else {
                return true;
            }
        default:
            return true;
            break;
    }
}
function FormatCurrency(num) { 
	var sign, cents; 
	num = num.toString().replace(/\$|\,/g,''); 
	if(isNaN(num)) 
	num = "0"; 
	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 (((sign)?'':'-') + '$' + num + '.' + cents); 
}

function getCurrencyValue(num)
{
    var noJunk = ""
    var withDollar = ""
    var foundDecimal = 0
    var foundAlphaChar = 0
    num += "";

    if (num == "") { return NaN; }
    for (i=0; i <= num.length; i++)
    {
        var thisChar = num.substring(i, i+1);
        if (thisChar == ".")
        {
          foundDecimal = 1;
          noJunk = noJunk + thisChar;
        }
        if ((thisChar < "0") || (thisChar > "9"))
        {
          if ((thisChar != "$") && (thisChar !=".") && (thisChar != ",") && (thisChar != " ") && (thisChar !="")) foundAlphaChar = 1;
        }
        else
		 {
		    withDollar = withDollar + thisChar
		    noJunk = noJunk + thisChar
		 }

		 if ((thisChar == "$") || (thisChar == ".") || (thisChar == ","))
		 {
		   withDollar = withDollar + thisChar
		 }
  	}
     if (foundDecimal) { return parseFloat(noJunk); }
     else if (noJunk.length > 0) { return parseFloat(noJunk); }
     else return NaN;
}

function fixInput(field, fixType, ampmField) {
    var fld = document.getElementById(field);
    if(ampmField != '') {
	    var ampm = document.getElementById(ampmField);
	}
    var str = fld.value;
    
    switch(fixType) {
        case 'hour':
            if(str == 0) {
                str = 12;
                fld.value = str;
            }
            else if(str.length == 1) {
                str = '0' + str;
                fld.value = str;
            }
            else if(str > 12) {
                str = str % 12;
                if(str == 0) {
                    str = 12;
                    fld.value = str;
                }
                else if(str > 0 && str < 10) {
                    str = '0' + str;
                    fld.value = str;
                }
                else {
                    fld.value = str;
                }
                ampm.options[1].selected = true;
            }
            break;
        case 'minute':
            if(str.length == 1) {
                str = '0' + str;
                fld.value = str;
            }
            if(str > 59) {
                str = '59';
                fld.value = str;
            } 
            break;
        case 'month':
            if(str == 0) {
                str = '01';
                fld.value = str;
            }
            else if(str.length == 1) {
                str = '0' + str;
                fld.value = str;
            }
            if(str > 12) {
                str = '12';
                fld.value = str;
            }
            break;
        case 'day':
            if(str == 0) {
                str = '01';
                fld.value = str;
            }
            else if(str.length == 1) {
                str = '0'+ str;
                fld.value = str;
            }
            if(str > 31) {
                str = '31';
                fld.value = str;
            } 
            break;
        case 'year':
            if(str < 26) {
                switch(str.length) {
                    case 1:
                        str = '200' + str;
                        fld.value = str;
                        break;
                    case 2:
                        str = '20' + str;
                        fld.value = str;
                        break;
                    case 3:
                        str = '2' + str;
                        fld.value = str;
                        break;
                }
            }
            else {
                switch(str.length) {
                    case 2:
                        str = '19' + str;
                        fld.value = str;
                        break;
                    case 3:
                        str = '2' + str;
                        fld.value = str;
                        break;
                }
            }
            break;
    }
}

function compareDates(year, month, day, prefix, comparison, calcDate) {
    var yearObj = document.getElementById(year);
    var monthObj = document.getElementById(month);
    var dayObj = document.getElementById(day);
    var comparisonObj = document.getElementById(comparison);
    var today = new Date();
    var calcDay;
    var calcMonth;
    var calcYear;
    var daysDiff;
    var monthsDiff;
    var yearsDiff;
    
    if(calcDate == '') {
        calcDay = today.getDate();
        calcMonth = today.getMonth();
        calcYear = today.getFullYear();
        
        monthsDiff = calcMonth + 1 - monthObj.value;
    }
    else {
        calcDay = calcDate.substring(3, 5);
        calcMonth = calcDate.substring(0, 2);
        calcYear = calcDate.substring(6);
        
        monthsDiff = calcMonth - monthObj.value;
    }
    
    daysDiff = calcDay - dayObj.value;
    yearsDiff = calcYear - yearObj.value;
    

    if(yearsDiff >= 2) {
        if(monthsDiff > 0) {
            comparisonObj.innerHTML = prefix + ' ' + yearsDiff + ' yrs';
        }
        else if(monthsDiff == 0) {
            if(daysDiff >= 0) {
                comparisonObj.innerHTML = prefix + ' ' + yearsDiff + ' yrs';
            }
            else if(daysDiff < 0) {
                comparisonObj.innerHTML = prefix + ' ' + (yearsDiff - 1) + ' yrs';
            }
            else {
                comparisonObj.innerHTML = prefix + '';
            }
        }
        else if(monthsDiff < 0) {
            comparisonObj.innerHTML = prefix + ' ' + (yearsDiff - 1) + ' yrs';
        }
        else {
            comparisonObj.innerHTML = prefix + '';
        }
    }
    else if(yearsDiff == 1) {
        if(monthsDiff > 0) {
            comparisonObj.innerHTML = prefix + ' ' + yearsDiff + ' yr';
        }
        else if(monthsDiff == 0) {
            if(daysDiff >= 0) {
                comparisonObj.innerHTML = prefix + ' ' + yearsDiff + ' yr';
            }
            else if(daysDiff < 0) {
                comparisonObj.innerHTML = prefix + '< 1 yr';
            }
            else {
                comparisonObj.innerHTML = prefix + '';
            }
        }
        else if(monthsDiff < 0) {
            comparisonObj.innerHTML = prefix + '< 1 yr';
        }
        else {
            comparisonObj.innerHTML = prefix + '';
        }
    }
    else if(yearsDiff == 0) {
        if(monthsDiff > 0) {
            comparisonObj.innerHTML = prefix + '< 1 yr';
        }
        else if(monthsDiff == 0) {
            if(daysDiff >= 0) {
                comparisonObj.innerHTML = prefix + '< 1 yr';
            }
            else {
                comparisonObj.innerHTML = prefix + '';
            }
        }
        else {
            comparisonObj.innerHTML = prefix + '';
        }
    }
    else {
        comparisonObj.innerHTML = prefix + '';
    }
}

//for radio buttons or checkboxes
function uncheckField(field) {
    if (document.getElementById(field) != null) { document.getElementById(field).checked = false; }
}

//for radio buttons or checkboxes
function checkField(field) {
    if (document.getElementById(field) != null) { document.getElementById(field).checked = true; }
}

//for select all checkboxes
function selectAllToggle(selectAll, field) {
    if (document.getElementById(field) != null) {
        document.getElementById(field).checked = document.getElementById(selectAll).checked
    }
}

function clearText(field) {
    if (document.getElementById(field) != null) {
        document.getElementById(field).value = '';
    }
}

function clearDefaultText(field, defaultText) {
    var fld = document.getElementById(field);
        
    if(fld.value == defaultText) {
        clearText(field);
    }
}

function clearSelection(field) {
   if (document.getElementById(field) != null) { document.getElementById(field).options[0].selected = true; }
}

function enableElement(element) {
    if (document.getElementById(element) != null) { document.getElementById(element).disabled=false; }
}

function disableElement(element) {
   if (document.getElementById(element) != null) { document.getElementById(element).disabled=true; }
}

function hideElement(element) {
    if (document.getElementById(element) != null) { document.getElementById(element).style.display = 'none'; }
}

function showElement(element) {
    if (document.getElementById(element) != null) { document.getElementById(element).style.display = ''; }
}

function phoneIsFilled(areaCode, prefix, number, extension, areaCodeCss, prefixCss, numberCss, extCss, areaCodeStyles, prefixStyles, numberStyles, extStyles, areaCodeErrCss, prefixErrCss, numberErrCss, extErrCss, areaCodeErrStyles, prefixErrStyles, numberErrStyles, extErrStyles) {
    var isValid = false;
    var areaCodeObj = document.getElementById(areaCode);
    var prefixObj = document.getElementById(prefix);
    var numberObj = document.getElementById(number);
	if(extension != '') {
	    var extensionObj = document.getElementById(extension);
	}
	
	if(areaCodeObj.value != '') {
		isValid = true;
	} 	
    if(prefixObj.value != '') {
        isValid = true;
    }
    if(numberObj.value != '') {
        isValid = true;
    }
    if(extension != '') {        
        if(extensionObj.value != '') {
            isValid = true;
        }
    }
    //if isValid is false at this point, then it means that no portions
    //of the control have been filled which means we need to highlight
    //the field to draw the user's attention to the error.
    if(isValid == false) {
        areaCodeObj.className = areaCodeErrCss;
        areaCodeObj.style.cssText = areaCodeErrStyles;
        
        prefixObj.className = prefixErrCss;
        prefixObj.style.cssText = prefixErrStyles;
        
        numberObj.className = numberErrCss;
        numberObj.style.cssText = numberErrStyles;
        
        if(extension != '') {
            extensionObj.className = extErrCss;
            extensionObj.style.cssText = extErrStyles;
        }
        
        resetNavigationButtons();
	}
	else {
	    areaCodeObj.className = areaCodeCss;
	    areaCodeObj.style.cssText = areaCodeStyles;
	    
        prefixObj.className = prefixCss;
        prefixObj.style.cssText = prefixStyles;
        
        numberObj.className = numberCss;
        numberObj.style.cssText = numberStyles;
        
        if(extension != '') {
            extensionObj.className = extCss;
            extensionObj.style.cssText = extStyles;
        }
	}
	return isValid;
}

function phoneIsValid(areaCode, prefix, number, extension,checkExt, areaCodeCss, prefixCss, numberCss, extCss, areaCodeStyles, prefixStyles, numberStyles, extStyles, areaCodeErrCss, prefixErrCss, numberErrCss, extErrCss, areaCodeErrStyles, prefixErrStyles, numberErrStyles, extErrStyles, required) {
    var isValid = true;
    var areaCodeObj = document.getElementById(areaCode);
    var prefixObj = document.getElementById(prefix);
    var numberObj = document.getElementById(number);
    if(checkExt == 'true') {
        var extensionObj = document.getElementById(extension);
    }
    
    if(!(/[2-9]\d{2}|^$/.test(areaCodeObj.value))) {
        isValid = false;
    }
    else if(!(/\d{3}|^$/.test(prefixObj.value))) {
        isValid = false;
    }
    else if(!(/\d{4}|^$/.test(numberObj.value))) {
        isValid = false;
    }
    else if(checkExt == 'true')  {
        if(!(/\d{1,10}|^$/.test(extensionObj.value))) {
            isValid = false;
        }
    }
    var isAreaCodeEmpty = (areaCodeObj.value == '');
    var isprefixEmpty = (prefixObj.value == '');
    var isnumberEmpty = (numberObj.value == '');
    var isExtensionEmpty = ''
    if(checkExt == 'true') {
       isExtensionEmpty  = (extensionObj.value == '');
    }
    
    if(isAreaCodeEmpty != isprefixEmpty || isAreaCodeEmpty != isnumberEmpty) {
        isValid = false;
    }
    if(checkExt == 'true') {
        if(!isExtensionEmpty && isAreaCodeEmpty != isExtensionEmpty) {
            isValid = false;
        }
    }
    //if isValid is false at this point, then at least one portion
    //of the control failed validation which means we need to highlight
    //the field to draw the user's attention to the error.
    if(isValid == false) {
        areaCodeObj.className = areaCodeErrCss;
        areaCodeObj.style.cssText = areaCodeErrStyles;
        
        prefixObj.className = prefixErrCss;
        prefixObj.style.cssText = prefixErrStyles;
        
        numberObj.className = numberErrCss;
        numberObj.style.cssText = numberErrStyles;
        
        if(checkExt == 'true') {
            extensionObj.className = extErrCss;
            extensionObj.style.cssText = extErrStyles;
        }
        
        resetNavigationButtons();
    }
    //we only want to reset the class back to normal if the field is not required.
    //otherwise resetting the class is taken care of by required validation.
    else if(!required) {
        areaCodeObj.className = areaCodeCss;
	    areaCodeObj.style.cssText = areaCodeStyles;
	    
        prefixObj.className = prefixCss;
        prefixObj.style.cssText = prefixStyles;
        
        numberObj.className = numberCss;
        numberObj.style.cssText = numberStyles;
        
        if(checkExt == 'true') {
            extensionObj.className = extCss;
            extensionObj.style.cssText = extStyles;
        }
    }
    return isValid;
}

function dateIsWithinMinMaxRange(minDay, minMonth, minYear, maxDay, maxMonth, maxYear, day, month, year, dayDefault, monthDefault, yearDefault, cssClassDay, cssClassMonth, cssClassYear, dayStyles, monthStyles, yearStyles, errClassDay, errClassMonth, errClassYear, errDayStyles, errMonthStyles, errYearStyles, required) {
    var isValid = false;
    var dayObj = document.getElementById(day);
    var monthObj = document.getElementById(month);
    var yearObj = document.getElementById(year);
    
    if(dayObj.value != '' && dayObj.value != dayDefault) {
        isValid = true;
    }             
    else if(monthObj.value != '' && monthObj.value != monthDefault) {
        isValid = true;
    }
    else if(yearObj.value != '' && yearObj.value != yearDefault) {
        isValid = true;
    }
    
    //is it filled?
    if (isValid) {
        //is it valid?
        if (dateIsValid(day, month, year, dayDefault, monthDefault, yearDefault, cssClassDay, cssClassMonth, cssClassYear, dayStyles, monthStyles, yearStyles, errClassDay, errClassMonth, errClassYear, errDayStyles, errMonthStyles, errYearStyles, true)) {
            //now we can test for min/max because we know it is filled and valid
            if (parseInt(minYear) == 1) {
                //no minimum was set
                isValid = true;
            }
            else if (minMaxDateCompare(minDay, minMonth, minYear, dayObj.value, monthObj.value, yearObj.value) < 0) {
                isValid = false;
            }
            
            if (parseInt(maxYear) == 1) {
                //no maximum was set
                isValid = true;
            }
            else if (minMaxDateCompare(maxDay, maxMonth, maxYear, dayObj.value, monthObj.value, yearObj.value) > 0) {
                isValid = false;
            }
        }
        else {
            //it's not even valid, so don't give min/max errors
            isValid = true;
            return isValid;
        } 
    }
    else {
        //it's not even filled, so don't give min/max errors
        isValid = true;
    }
    
    
    if(isValid == false) {
        dayObj.className = errClassDay;
        dayObj.style.cssText = errDayStyles;
        monthObj.className = errClassMonth;
        monthObj.style.cssText = errMonthStyles;
        yearObj.className = errClassYear;
        yearObj.style.cssText = errYearStyles;
        
        resetNavigationButtons();
	}
	//we only want to reset the class back to normal if the field is not required.
    //otherwise resetting the class is taken care of by required validation.
    
	else if(!required) {
        dayObj.className = cssClassDay;
        dayObj.style.cssText = dayStyles;
	    monthObj.className = cssClassMonth;
	    monthObj.style.cssText = monthStyles;
        yearObj.className = cssClassYear;
        yearObj.style.cssText = yearStyles;
	}
    
    
    return isValid;
}

//must be given valid dates
//returns 1 if the d1 is before d2
//returns 0 if they are the same date
//returns -1 if the d1 is after the d2
function minMaxDateCompare(d1Day,d1Month,d1Year,d2Day,d2Month,d2Year)
{
if (d1Day.charAt(0)=="0"){
    d1Day = d1Day.substr(1)
}
if (d1Month.charAt(0)=="0"){
    d1Month = d1Month.substr(1)
}

d1Day = parseInt(d1Day);
d1Month = parseInt(d1Month);
d1Year = parseInt(d1Year);
if (d2Day.charAt(0)=="0"){
    d2Day = d2Day.substr(1)
}
if (d2Month.charAt(0)=="0"){
    d2Month = d2Month.substr(1)
}

d2Day = parseInt(d2Day);
d2Month = parseInt(d2Month);
d2Year = parseInt(d2Year);

    if (d2Year > d1Year) {
        return 1;
    }
    else if (d2Year < d1Year) {
        return -1;
    }
    else {
        //same year
        if (d2Month > d1Month) {
            return 1;
        }
        else if (d2Month < d1Month) {
            return -1;
        }
        else {
            //same month
            if (d2Day > d1Day) {
                return 1;
            }
            else if (d2Day < d1Day) {
                return -1;
            }
            else {
                return 0;   
            } 
        }    
    }

}

function dateIsFilled(day, month, year, dayDefault, monthDefault, yearDefault, cssClassDay, cssClassMonth, cssClassYear, dayStyles, monthStyles, yearStyles, errClassDay, errClassMonth, errClassYear, errDayStyles, errMonthStyles, errYearStyles) {
    var isValid = false;
    var dayObj = document.getElementById(day);
    var monthObj = document.getElementById(month);
    var yearObj = document.getElementById(year);
    
    if(dayObj.value != '' && dayObj.value != dayDefault) {
        isValid = true;
    }             
    else if(monthObj.value != '' && monthObj.value != monthDefault) {
        isValid = true;
    }
    else if(yearObj.value != '' && yearObj.value != yearDefault) {
        isValid = true;
    }
    //if isValid is false at this point, then it means that no portions
    //of the control have been filled which means we need to highlight
    //the field to draw the user's attention to the error.
    if(isValid == false) {
        dayObj.className = errClassDay;
        dayObj.style.cssText = errDayStyles;
        monthObj.className = errClassMonth;
        monthObj.style.cssText = errMonthStyles;
        yearObj.className = errClassYear;
        yearObj.style.cssText = errYearStyles;
        
        resetNavigationButtons();
	}
	else {
        dayObj.className = cssClassDay;
        dayObj.style.cssText = dayStyles;
	    monthObj.className = cssClassMonth;
	    monthObj.style.cssText = monthStyles;
        yearObj.className = cssClassYear;
        yearObj.style.cssText = yearStyles;
	}
	return isValid;
}

function dateIsValid(day, month, year, dayDefault, monthDefault, yearDefault, cssClassDay, cssClassMonth, cssClassYear, dayStyles, monthStyles, yearStyles, errClassDay, errClassMonth, errClassYear, errDayStyles, errMonthStyles, errYearStyles, required) {
    var isValid = true;
    var dayObj = document.getElementById(day);
    var monthObj = document.getElementById(month);
    var yearObj = document.getElementById(year);
            
    if(!(/0[1-9]|1[0-2]|^$/.test(monthObj.value)) && monthObj.value != monthDefault) {
        isValid = false;
    }
    switch(monthObj.value) {
        case monthDefault:case '01':case '03':case '05':case '07':case '08':case '10':case '12':
            if(!(/[0-2][0-9]|3[0-1]|^$/.test(dayObj.value)) && dayObj.value != dayDefault) {
                isValid = false;
            }
        break;
        case '04':case '06':case '09':case '11':
            if(!(/[0-2][0-9]|30|^$/.test(dayObj.value)) && dayObj.value != dayDefault) {
                isValid = false;
            }
        break;
        case '02':
            if(!(/[0-2][0-9]|^$/.test(dayObj.value)) && dayObj.value != dayDefault) {
                isValid = false;
            }
        break;
        default:
            isValid = false;
        break;
    }
    switch(dayObj.value) {
        case '29':
            // only februrary matters for leap year calculation -Jay
            if(monthObj.value == 2)
            {
                if(!(/\d{4}|^$/.test(yearObj.value)) && yearObj.value != yearDefault) {
                    isValid = false;
                }
                if(yearObj.value % 4 == 0) {
                    if(yearObj.value % 100 == 0) {
                        if(yearObj.value % 400 == 0) {
                            //do nothing
                        }
                        else {
                            isValid = false;
                        }
                    }
                }
                else {
                    isValid = false;
                }
            }
        break;
        default:
            if(!(/\d{4}|^$/.test(yearObj.value)) && yearObj.value != yearDefault) {
                isValid = false;
            }
        break;
    }
    var isDayEmpty = (dayObj.value == '' || dayObj.value == dayDefault);
    var isMonthEmpty = (monthObj.value == '' || monthObj.value == monthDefault);
    var isYearEmpty = (yearObj.value == '' || yearObj.value == yearDefault);
    if(isMonthEmpty != isDayEmpty || isMonthEmpty != isYearEmpty) {
        isValid = false;
    }
    
    //if isValid is false at this point, then at least one portion
    //of the control failed validation which means we need to highlight
    //the field to draw the user's attention to the error.
    if(isValid == false) {
        dayObj.className = errClassDay;
        dayObj.style.cssText = errDayStyles;
        monthObj.className = errClassMonth;
        monthObj.style.cssText = errMonthStyles;
        yearObj.className = errClassYear;
        yearObj.style.cssText = errYearStyles;
        
        resetNavigationButtons();
	}
	//we only want to reset the class back to normal if the field is not required.
    //otherwise resetting the class is taken care of by required validation.
	else if(!required) {
        dayObj.className = cssClassDay;
        dayObj.style.cssText = dayStyles;
	    monthObj.className = cssClassMonth;
	    monthObj.style.cssText = monthStyles;
        yearObj.className = cssClassYear;
        yearObj.style.cssText = yearStyles;
	}
	return isValid;
}

function ssnIsFilled(input1, input2, input3, input1Css, input2Css, input3Css, input1Styles, input2Styles, input3Styles, input1ErrCss, input2ErrCss, input3ErrCss, input1ErrStyles, input2ErrStyles, input3ErrStyles) {
    var isValid = false;
    var input1Obj = document.getElementById(input1);
    var input2Obj = document.getElementById(input2);
    var input3Obj = document.getElementById(input3);
		
	if(input1Obj.value != '') {
		isValid = true;
	} 	
    else if(input2Obj.value != '') {
        isValid = true;
    }
    else if(input3Obj.value != '') {
        isValid = true;
    }
    //if isValid is false at this point, then it means that no portions
    //of the control have been filled which means we need to highlight
    //the field to draw the user's attention to the error.
    if(isValid == false) {
        input1Obj.className = input1ErrCss;
        input1Obj.style.cssText = input1ErrStyles
        
        input2Obj.className = input2ErrCss;
        input2Obj.style.cssText = input2ErrStyles
        
        input3Obj.className = input3ErrCss;
        input3Obj.style.cssText = input3ErrStyles
        
        resetNavigationButtons();
	}
	else {
	    input1Obj.className = input1Css;
        input1Obj.style.cssText = input1Styles
        
        input2Obj.className = input2Css;
        input2Obj.style.cssText = input2Styles
        
        input3Obj.className = input3Css;
        input3Obj.style.cssText = input3Styles
	}
	return isValid;
}

function ssnIsValid(input1, input2, input3, input1Css, input2Css, input3Css, input1Styles, input2Styles, input3Styles, input1ErrCss, input2ErrCss, input3ErrCss, input1ErrStyles, input2ErrStyles, input3ErrStyles, required) {
    var isValid = true;
    var input1Obj = document.getElementById(input1);
    var input2Obj = document.getElementById(input2);
    var input3Obj = document.getElementById(input3);
        
    if(!(/(?!666)(00[1-9]|0[1-9]0|0[1-9][1-9]|[1-6]\d{2}|7[0-6]\d|77[0-2])|^$/.test(input1Obj.value))) {
        isValid = false;
    }
    if(!(/(?!00)\d{2}|^$/.test(input2Obj.value))) {
        isValid = false;
    }
    if(!(/(?!0000)\d{4}|^$/.test(input3Obj.value))) {
        isValid = false;
    }
    
    var isinput1Empty = /^$/.test(input1Obj.value);
    var isinput2Empty = /^$/.test(input2Obj.value);
    var isinput3Empty = /^$/.test(input3Obj.value);
    
    if(isinput1Empty != isinput2Empty || isinput1Empty != isinput3Empty) {
        isValid = false;
    }
    //if isValid is false at this point, then at least one portion
    //of the control failed validation which means we need to highlight
    //the field to draw the user's attention to the error.
    if(isValid == false) {
        input1Obj.className = input1ErrCss;
        input1Obj.style.cssText = input1ErrStyles
        
        input2Obj.className = input2ErrCss;
        input2Obj.style.cssText = input2ErrStyles
        
        input3Obj.className = input3ErrCss;
        input3Obj.style.cssText = input3ErrStyles
        
        resetNavigationButtons();
    }
    //we only want to reset the class back to normal if the field is not required.
    //otherwise resetting the class is taken care of by required validation.
    else if(!required) {
        input1Obj.className = input1Css;
        input1Obj.style.cssText = input1Styles
        
        input2Obj.className = input2Css;
        input2Obj.style.cssText = input2Styles
        
        input3Obj.className = input3Css;
        input3Obj.style.cssText = input3Styles
    }
    return isValid;
}

function timeIsFilled(hour, minute, hourDefault, minuteDefault, hourCss, minuteCss, hourStyles, minuteStyles, hourErrCss, minuteErrCss, hourErrStyles, minuteErrStyles) {
    var isValid = false;
    var hourObj = document.getElementById(hour);
    var minuteObj = document.getElementById(minute);
        
    if(hourObj.value != '' && hourObj.value != hourDefault) {
        isValid = true;
    }
    else if(minuteObj.value != '' && minuteObj.value != minuteDefault) {
        isValid = true;
    }
    //if isValid is false at this point, then it means that no portions
    //of the control have been filled which means we need to highlight
    //the field to draw the user's attention to the error.
    if(isValid == false) {
        hourObj.className = hourErrCss;
        hourObj.style.cssText = hourErrStyles;
        
        minuteObj.className = minuteErrCss;
        minuteObj.style.cssText = minuteErrStyles;
        
        resetNavigationButtons();
	}
	else {
	    hourObj.className = hourCss;
        hourObj.style.cssText = hourStyles;
        
        minuteObj.className = minuteCss;
        minuteObj.style.cssText = minuteStyles;
	}
	return isValid;
}

function timeIsValid(hour, minute, hourDefault, minuteDefault, hourCss, minuteCss, hourStyles, minuteStyles, hourErrCss, minuteErrCss, hourErrStyles, minuteErrStyles, required) {
    var isValid = true;
    var hourObj = document.getElementById(hour);
    var minuteObj = document.getElementById(minute);
        
    if(!(/0[1-9]|1[0-2]|^$/.test(hourObj.value)) && hourObj.value != hourDefault) {
        isValid = false;
    }
    if(!(/[0-5][0-9]|^$/.test(minuteObj.value)) && minuteObj.value != minuteDefault) {
        isValid = false;
    }
    
    var isHourEmpty = (hourObj.value == '' || hourObj.value == hourDefault)
    var isMinuteEmpty = (minuteObj.value == '' || minuteObj.value == minuteDefault)
    
    if(isHourEmpty != isMinuteEmpty) {
        isValid = false;
    }
    //if isValid is false at this point, then at least one portion
    //of the control failed validation which means we need to highlight
    //the field to draw the user's attention to the error.
    if(isValid == false) {
        hourObj.className = hourErrCss;
        hourObj.style.cssText = hourErrStyles;
        
        minuteObj.className = minuteErrCss;
        minuteObj.style.cssText = minuteErrStyles;
        
        resetNavigationButtons();
	}
	//we only want to reset the class back to normal if the field is not required.
    //otherwise resetting the class is taken care of by required validation.
	else if(!required) {
	    hourObj.className = hourCss;
        hourObj.style.cssText = hourStyles;
        
        minuteObj.className = minuteCss;
        minuteObj.style.cssText = minuteStyles;
	}
	return isValid;
}

function textIsFilled(input, cssClass, styles, errClass, errStyles, skipStyle) {
    var inputObj = document.getElementById(input);
    var isValid = false;
    if (inputObj != null) {
        isValid = (inputObj.value != '');
    }else{
        isValid = true;
        return isValid;
    }
    
    //if isValid is false at this point, then it means that no data
    //has been entered in the control which means we need to highlight
    //the field to draw the user's attention to the error.
    if(isValid == false) {
        if(skipStyle == 'undefined' || !skipStyle)
       {  
            inputObj.className = errClass;
            inputObj.style.cssText = errStyles;
       } 
        
        resetNavigationButtons();
    }
	else {
	    if(skipStyle == 'undefined' || !skipStyle)
	   { 
	        inputObj.className = cssClass;
	        inputObj.style.cssText = styles;
	   } 
	}
	return isValid;
}

function textIsWithinMinMax(input,min,max,cssClass, styles, errClass, errStyles, required) {
    var inputObj = document.getElementById(input);
    var isValid = true;
    
    
    if (inputObj.value.length < min) {
            isValid = false;
    }    
    if ((inputObj.value.length > max) && (max > 0)) {
        isValid = false;
    }
    
    if ((required) && (inputObj.value.length == 0)) {
    isValid = true;
    } 
        
    //if isValid is false at this point, then the control failed validation again
    //the regular expression which means we need to highlight the field to draw
    //the user's attention to the error.
    if(isValid == false) {
        inputObj.className = errClass;
        inputObj.style.cssText = errStyles;
        
        resetNavigationButtons();
	}           
    else if (!required)
    {
        inputObj.className = cssClass;
        inputObj.style.cssText = styles;	
    }
    
    return isValid;
}

function textIsValidforZip(input, cssClass, styles, errClass, errStyles, regex, required){
    var inputObj = document.getElementById(input);
    var isValid = false;
     if (inputObj != null){
        isValid = (inputObj.value == '' || inputObj.value != '00000');
    }
    if (isValid){
        isValid =  textIsValid(input, cssClass, styles, errClass, errStyles, regex, required);
    }else{
        inputObj.className = errClass;
        inputObj.style.cssText = errStyles;
        
        resetNavigationButtons();
    }
    return isValid;
}

function textIsValid(input, cssClass, styles, errClass, errStyles, regex, required) {
    var inputObj = document.getElementById(input);
    var re = new RegExp(regex);
    var isValid = false;
    if (inputObj != null){
        isValid = (re.test(inputObj.value) || inputObj.value == '');
    }else{
        isValid = true;
        return isValid;
    }

    //if isValid is false at this point, then the control failed validation again
    //the regular expression which means we need to highlight the field to draw
    //the user's attention to the error.
    if(isValid == false) {
        inputObj.className = errClass;
        inputObj.style.cssText = errStyles;
        
        resetNavigationButtons();
	}
	//we only want to reset the class back to normal if the field is not required.
    //otherwise resetting the class is taken care of by required validation.
	else if(!required) {
	    inputObj.className = cssClass;
	    inputObj.style.cssText = styles;
	}
	return isValid;
}

function textIsSame(input, inputCss, inputStyles, inputErrCss, inputErrStyles, confirm, confirmCss, confirmStyles, confirmErrCss, confirmErrStyles, required) {
    var inputObj = document.getElementById(input);
    var confirmObj = document.getElementById(confirm);
    
    if(required) {
        var isValid = (inputObj.value == confirmObj.value);
    }
    else {
        var isValid = (inputObj.value == confirmObj.value || confirmObj.value == '');
    }
    //if isValid is false at this point, then the two inputs do not match which means
    //we need to highlight the fields to draw the user's attention to the error.
    if (isValid == false) {
        inputObj.className = inputErrCss;
        inputObj.style.cssText = inputErrStyles;
        
        confirmObj.className = confirmErrCss;
        confirmObj.style.cssText = confirmErrStyles;
        resetNavigationButtons();
    }
    else {
        inputObj.className = inputCss;
        inputObj.style.cssText = inputStyles;
        
        confirmObj.className = confirmCss;
        confirmObj.style.cssText = confirmStyles;
    }
    return isValid;
}

function chkBoxIsFilled(input, container, cssClass, styles, errClass, errStyles) {
    var inputObj = document.getElementById(input);
    var containerObj = document.getElementById(container);
    var isValid = false;
    
    var option = document.getElementById(input + '_0');
    var i = 1
    while(option != null) {
        if (option.checked) {
            isValid = true;
        }
        option = document.getElementById(input + '_' + i);
        i++;
    }
    //if isValid is false at this point, then it means that no data
    //has been entered in the control which means we need to highlight
    //the field to draw the user's attention to the error.
    if(isValid == false) {
        containerObj.className = errClass;
        containerObj.style.cssText = errStyles;
        
        resetNavigationButtons();
    }
	else {
	    containerObj.className = cssClass;
	    containerObj.style.cssText = styles;
	}
	return isValid;
}

function lsBoxIsFilled(input, container, cssClass, styles, errClass, errStyles) {
    var inputObj = document.getElementById(input);
    var containerObj = document.getElementById(container);
    var isValid;
    if (inputObj == null){
        isValid = false;
    }
    else {
        isValid = inputObj.selectedIndex > -1;
    }
    
    //if isValid is false at this point, then it means that no data
    //has been entered in the control which means we need to highlight
    //the field to draw the user's attention to the error.
    if(isValid == false) {
        containerObj.className = errClass;
        containerObj.style.cssText = errStyles;
        
        resetNavigationButtons();
    }
	else {
	    containerObj.className = cssClass;
	    containerObj.style.cssText = styles;
	}
	return isValid;
}

function radioIsFilled(input, container, cssClass, styles, errClass, errStyles) {
    var inputObj = document.getElementById(input);
    var containerObj = document.getElementById(container);
    var groupName = document.getElementById(input + '_0').name;
    var isValid = false;
    
    var options = document.getElementsByName(groupName);
    for(i=0; i<options.length; i++) {
        if (options[i].checked) {
            isValid = true;
        }
    }
    //if isValid is false at this point, then it means that no data
    //has been entered in the control which means we need to highlight
    //the field to draw the user's attention to the error.
    if(isValid == false) {
        containerObj.className = errClass;
        containerObj.style.cssText = errStyles;
        
        resetNavigationButtons();
    }
	else {
	    containerObj.className = cssClass;
	    containerObj.style.cssText = styles;
	}
	return isValid;
}

function dropDownIsFilled(input, container, cssClass, styles, errClass, errStyles) {
    var inputObj = document.getElementById(input);
    var containerObj = document.getElementById(container);
    //var isValid = (inputObj.options[inputObj.selectedIndex].value > 0);
    var isValid = (inputObj.options[inputObj.selectedIndex].value != '0');
    
    //if isValid is false at this point, then it means that no data
    //has been entered in the control which means we need to highlight
    //the field to draw the user's attention to the error.
    if(isValid == false) {
        containerObj.className = errClass;
        containerObj.style.cssText = errStyles;
        
        resetNavigationButtons();
    }
	else {
	    containerObj.className = cssClass;
	    containerObj.style.cssText = styles;
	}
	return isValid;
}

function waiverIsFilled(waiver, input, cssClass, cssClassAcceptReject, errClass, errClassAcceptReject) {
    var waiverObj = document.getElementById(waiver);
    var inputObj = document.getElementById(input);
    var groupName = document.getElementById(input + '_0').name;
    var isValid = false;
    
    var options = document.getElementsByName(groupName);
    for(i=0; i<options.length; i++) {
        if (options[i].checked) {
            isValid = true;
        }
    }
    //if isValid is false at this point, then it means that no data
    //has been entered in the control which means we need to highlight
    //the field to draw the user's attention to the error.
    if(isValid == false) {
        waiverObj.className = errClass;
        inputObj.className = errClassAcceptReject;
        
        resetNavigationButtons();
    }
	else {
	    waiverObj.className = cssClass;
	    inputObj.className = cssClassAcceptReject;
	}
	return isValid;
}

function optionIsFilled(groupName, container, cssClass, styles, errClass, errStyles) {
    var isValid = false;
    var options = document.getElementsByName(groupName);
    var containerObj = document.getElementById(container);
    
    for(i=0; i<options.length; i++) {
        if (options[i].checked) {
            isValid = true;
        }
    }
    
     //if isValid is false at this point, then it means that no data
    //has been entered in the control which means we need to highlight
    //the field to draw the user's attention to the error.
    if(isValid == false) {
        containerObj.className = errClass;
        containerObj.style.cssText = errStyles;
        
        resetNavigationButtons();
    }
	else {
	    containerObj.className = cssClass;
	    containerObj.style.cssText = styles;
	}
	return isValid;
}

//used only for Payment Option Standard Control
function specialOptionIsFilled(groupName, addedCheckbox, container, cssClass, styles, errClass, errStyles) {
    var isValid = false;
    var checkbox = document.getElementById(addedCheckbox);
    var options = document.getElementsByName(groupName);
    var containerObj = document.getElementById(container);
    
    for(i=0; i<options.length; i++) {
        if (options[i].checked) {
            isValid = true;
        }
    }

    if (checkbox.checked) {
         isValid = true;
    }
    
     //if isValid is false at this point, then it means that no data
    //has been entered in the control which means we need to highlight
    //the field to draw the user's attention to the error.
    if(isValid == false) {
        containerObj.className = errClass;
        containerObj.style.cssText = errStyles;
        
        resetNavigationButtons();
    }
	else {
	    containerObj.className = cssClass;
	    containerObj.style.cssText = styles;
	}
	return isValid;
}

function optionInputIsValid(option, input, regex, errClass, errStyles, skipStyle) {
    var isValid = true;
    var optionObj = document.getElementById(option);
    var inputObj = document.getElementById(input);
    var re = new RegExp(regex);
    
    if (optionObj != null) {
        if(optionObj.checked) {
            isValid = (re.test(inputObj.value));
        }
    }
    
    if(isValid == false) {
        if(skipStyle == 'undefined' || !skipStyle)
       {  
            inputObj.className = errClass;
            inputObj.style.cssText = errStyles;
       } 
        
        resetNavigationButtons();
    }
	return isValid;
}

function cardTypeIsFilled(option, input, container, cssClass, styles, errClass, errStyles) {
    var isValid = true;
    var optionObj = document.getElementById(option);
    
    if(optionObj.checked) {
        isValid = dropDownIsFilled(input, container, cssClass, styles, errClass, errStyles);
    }
    else {
        var containerObj = document.getElementById(container);
        containerObj.className = cssClass;
        containerObj.style.cssText = styles;
    }
    return isValid;
}

function cardNumberIsValid(option, cardType, input, cssClass, styles, errClass, errStyles, isTypeIgnore) {
    var isValid = true;

    var optionObj = document.getElementById(option);
    var inputObj = document.getElementById(input);
    
	if	(isTypeIgnore == true){
		var cardNumber = inputObj.value;
		if (cardNumber.length!=0){
			isValid = /^$|^((4\d{3}(-\d{4}){2}-(\d{4}|\d{1}))|(4\d{3}( \d{4}){2} (\d{4}|\d{1}))|(4(\d{15}|\d{12})))$/.test(cardNumber);
			if (isValid == false) {
				isValid = /^$|^((5[1-5]\d{2}(-\d{4}){3})|(5[1-5]\d{2}( \d{4}){3})|(5[1-5]\d{14}))$/.test(cardNumber);
			}
			if (isValid == false) {
				isValid = /^$|^(((6011|650\d{1})(-\d{4}){3})|((6011|650\d{1})( \d{4}){3})|(6011\d{12}|650\d{13}))$/.test(cardNumber);
			}
			if (isValid == false) {
				isValid = /^$|^((3[4,7]\d{2}(-\d{4}){2})-\d{3}|(3[4,7]\d{2}( \d{4}){2}) \d{3}|(3[4,7]\d{13}))$/.test(cardNumber);
			}		
		}
		else 
		{
			isValid = false;
		}
	}else if(optionObj.checked) {
        var cardTypeObj = document.getElementById(cardType);
        var cardType = cardTypeObj.options[cardTypeObj.selectedIndex].value;
        var cardNumber = inputObj.value;
    
        if(cardType == 1 || cardType == 2) {
            isValid = /^$|^((4\d{3}(-\d{4}){2}-(\d{4}|\d{1}))|(4\d{3}( \d{4}){2} (\d{4}|\d{1}))|(4(\d{15}|\d{12})))$/.test(cardNumber);
        }
        else if(cardType == 3 || cardType == 4) {
            isValid = /^$|^((5[1-5]\d{2}(-\d{4}){3})|(5[1-5]\d{2}( \d{4}){3})|(5[1-5]\d{14}))$/.test(cardNumber);
        }
        else if(cardType == 5) {
            isValid = /^$|^(((6011|650\d{1})(-\d{4}){3})|((6011|650\d{1})( \d{4}){3})|(6011\d{12}|650\d{13}))$/.test(cardNumber);
        }
        else if(cardType == 6) {
            isValid = /^$|^((3[4,7]\d{2}(-\d{4}){2})-\d{3}|(3[4,7]\d{2}( \d{4}){2}) \d{3}|(3[4,7]\d{13}))$/.test(cardNumber);
        }
        else {
            isValid = /^$|^[0-9]+$/.test(cardNumber);
        }
    }

    if(isValid == false) {
        inputObj.className = errClass;
        inputObj.style.cssText = errStyles;
        
        resetNavigationButtons();
    }
	return isValid;
}

function expireDateIsFilled(option, month, year, monthContainer, yearContainer, cssClass, styles, errClass, errStyles) {
    var isValid = true;
    var optionObj = document.getElementById(option);
    var monthContainerObj = document.getElementById(monthContainer);
    var yearContainerObj = document.getElementById(yearContainer);
    
    if(optionObj.checked) {
        var monthFilled = dropDownIsFilled(month, monthContainer, cssClass, styles, errClass, errStyles);
        var yearFilled = dropDownIsFilled(year, yearContainer, cssClass, styles, errClass, errStyles);
        isValid = monthFilled && yearFilled;
    }
    
    if(isValid == false) {
        monthContainerObj.className = errClass;
        monthContainerObj.style.cssText = errStyles;
        
        yearContainerObj.className = errClass;
        yearContainerObj.style.cssText = errStyles;
        
        resetNavigationButtons();
    }
	else {
	    monthContainerObj.className = cssClass;
        monthContainerObj.style.cssText = styles;
        
        yearContainerObj.className = cssClass;
        yearContainerObj.style.cssText = styles;
	}
	return isValid;
}

function expireDateIsValid(option, month, year, monthContainer, yearContainer, cssClass, styles, errClass, errStyles) {
    var isValid = true;
    var optionObj = document.getElementById(option);
    var monthObj = document.getElementById(month);
    var yearObj = document.getElementById(year);
    var monthContainerObj = document.getElementById(monthContainer);
    var yearContainerObj = document.getElementById(yearContainer);
    
    if(optionObj.checked) {
        isValid = false;
        var today = new Date();
        var month = today.getMonth() + 1;
        //NOTE: getMonth returns a zero-based index for the current month (Jan is 0, Feb is 1, etc.)
        //which means we have to add 1 to the value returned in order to get an accurate comparison.
        var year = today.getFullYear();
        var monthValue = 0;
        var yearValue = 0;
        
        if(monthObj.value != '') {
            monthValue = monthObj.value;
        }
        if(yearObj.value != '') {
            yearValue = yearObj.value;
        }
        
        if(yearValue > year) {
            isValid = true;
        }
        else if(monthValue >= month && yearValue == year) {
            isValid = true;
        }
        else if(monthValue == 0 || yearValue == 0) {
            isValid = true;
        }
    }
    if(isValid == false) {
        monthContainerObj.className = errClass;
        monthContainerObj.style.cssText = errStyles;
        
        yearContainerObj.className = errClass;
        yearContainerObj.style.cssText = errStyles;
        
        resetNavigationButtons();
    }
	return isValid;
}

function autoBillingIsFilled(payDeposit, payUserDefined, payZero, eCheck, creditCard, autoBill, autoBillContainer ,cssClass, styles, errClass, errStyles) {
    var isValid = true;
    var payDepositObj = document.getElementById(payDeposit);
    var payUserDefinedObj = document.getElementById(payUserDefined);
    var payZeroObj = document.getElementById(payZero);
    var eCheckObj = document.getElementById(eCheck);
    var creditCardObj = document.getElementById(creditCard);
    var autoBillObj = document.getElementById(autoBill);
    var autoBillContainerObj = document.getElementById(autoBillContainer);
    
    //since it is possible that some or all of these elements do not exist on the page,
    //we must first check to see if they exist, and if not, initialize them as new
    //controls to avoid the javascript equivalent of a null reference exception.
    if(eCheckObj == null) {
        eCheckObj = document.createElement('input');
        eCheckObj.type = 'radio';
    }
    if(creditCardObj == null) {
        creditCardObj = document.createElement('input');
        creditCardObj.type = 'radio';
    }
    if(payDepositObj == null) {
        payDepositObj = document.createElement('input');
        payDepositObj.type = 'radio';
    }
    if(payUserDefinedObj == null) {
        payUserDefinedObj = document.createElement('input');
        payUserDefinedObj.type = 'radio';
    }
    if(payZeroObj == null) {
        payZeroObj = document.createElement('input');
        payZeroObj.type = 'radio';
    }
    
    if(payDepositObj.checked || payUserDefinedObj.checked) {
        if(eCheckObj.checked || creditCardObj.checked) {
            isValid = autoBillObj.checked;
        }
    }
    else if(payZeroObj.checked) {
        if(creditCardObj.checked) {
            isValid = autoBillObj.checked;
        }
    }
    
    if(isValid == false) {
        autoBillContainerObj.className = errClass;
        autoBillContainerObj.style.cssText = errStyles;
        
        resetNavigationButtons();
    }
	else {
        autoBillContainerObj.className = cssClass;
        autoBillContainerObj.style.cssText = styles;
	}
	return isValid;
}

function paymentSelectionIsValid(payZero, payFull, payDeposit, payUserDefined, payCustom, eCheck, offline, container, cssClassContainer, styles, errClassContainer, errStyles) {
    var isValid = true;
    var payZeroObj = document.getElementById(payZero);
    var payFullObj = document.getElementById(payFull);
    var payDepositObj = document.getElementById(payDeposit);
    var payUserDefinedObj = document.getElementById(payUserDefined);
    var eCheckObj = document.getElementById(eCheck);
    var payCustomObj = document.getElementById(payCustom);
    //var creditBalanceObj = document.getElementById(creditBalance);
    var offlineObj = document.getElementById(offline);
    var containerObj = document.getElementById(container);
    
    //since it is possible that some or all of these elements do not exist on the page,
    //we must first check to see if they exist, and if not, initialize them as new
    //controls to avoid the javascript equivalent of a null reference exception.
    if(payZeroObj == null) {
        payZeroObj = document.createElement('input');
        payZeroObj.type = 'radio';
    }
    if(payFullObj == null) {
        payFullObj = document.createElement('input');
        payFullObj.type = 'radio';
    }
    if(payDepositObj == null) {
        payDepositObj = document.createElement('input');
        payDepositObj.type = 'radio';
    }
    if(payUserDefinedObj == null) {
        payUserDefinedObj = document.createElement('input');
        payUserDefinedObj.type = 'radio';
    }
    if(eCheckObj == null) {
        eCheckObj = document.createElement('input');
        eCheckObj.type = 'radio';
    }
    if(payCustomObj == null) {
        payCustomObj = document.createElement('input');
        payCustomObj.type = 'checkbox';
    }
//    if(creditBalanceObj == null) {
//        creditBalanceObj = document.createElement('input');
//        creditBalanceObj.type = 'checkbox';
//    }
    if(offlineObj == null) {
        offlineObj = document.createElement('input');
        offlineObj.type = 'radio';
    }
    
    if(payZeroObj.checked) {
        if(eCheckObj.checked) {
            isValid = false;
        }
    }
    else if(payFullObj.checked || payDepositObj.checked || payUserDefinedObj.checked || payCustomObj.checked) {
        if(offlineObj.checked) {
            isValid = false;
        }
    }
    
    if(isValid == false) {
        containerObj.className = errClassContainer;
        containerObj.style.cssText = errStyles;
        
        resetNavigationButtons();
    }
	else {
        containerObj.className = cssClassContainer;
        containerObj.style.cssText = styles;
	}
	return isValid;
}

function customPaymentIsValid(CustomPayment, CustomPaymentAmount, cssClass, styles, errClass, errStyles) {
	var CustomPaymentObj = document.getElementById(CustomPayment);
	var CustomPaymentAmountObj = document.getElementById(CustomPaymentAmount)
	
	if (CustomPaymentObj == null){
		 return true; }
	else {
		if (CustomPaymentObj.checked) {			
			if (isNaN(getCurrencyValue(CustomPaymentAmountObj.value)) == false) {
				CustomPaymentAmountObj.className = cssClass;
	    		CustomPaymentAmountObj.style.cssText = styles;
				return true; } 
			else {
				CustomPaymentAmountObj.className = errClass;
	    		CustomPaymentAmountObj.style.cssText = errStyles;
				resetNavigationButtons();
				return false;}
			}
		else {
		 	return true;
		}
	} 
 }
 
//"printText" must be HTML formatted (e.g. <br> instead of vbCrLf) strings for printing
//  remember to also use escape characters inside of "printtext", especially for apstrophes (&apos;)
function printerFriendlyText(printText) {
    var WinPrint = window.open('','','left=75,top=75,width=600,scrollbars=1,menubar=1,resizable=yes');
    WinPrint.document.open();
    WinPrint.document.write(printText);
    WinPrint.document.close();
    WinPrint.focus();
    WinPrint.print();
    //WinPrint.close(); //closes the printer-friendly browser window when print dialog is closed (either print or cancel)
}

function buttonProcessing(buttonType,buttonID,processingValue,desiredState) {
    if (buttonType=='imagebutton') {
        if (desiredState=='disabled') {            
            showElement(processingValue);
            hideElement(buttonID);  
        }else {
            hideElement(processingValue); 
            showElement(buttonID);           
        }//for imagebutton change by tony on 2009-4-10
    }else {
        if (desiredState=='disabled') {
            disableElement(buttonID);
        }else {
            enableElement(buttonID);
        }
        document.getElementById(buttonID).value=processingValue;
    }
}

function timeDurationIsFilled(hour, minute, second, millisecond, hourDefault, minuteDefault, secondDefault, millisecondDefault, hourCss, minuteCss, secondCss, millisecondCss, hourStyles, minuteStyles, secondStyles, millisecondStyles, hourErrCss, minuteErrCss, secondErrCss, millisecondErrCss, hourErrStyles, minuteErrStyles, secondErrStyles, millisecondErrStyles) {
    var isValid = false;
    var hourObj = document.getElementById(hour);
    var minuteObj = document.getElementById(minute);
    var secondObj = document.getElementById(second);
    var millisecondObj = document.getElementById(millisecond);
        
    if(hourObj.value != '' && hourObj.value != hourDefault) {
        isValid = true;
    }
    else if(minuteObj.value != '' && minuteObj.value != minuteDefault) {
        isValid = true;
    }
    else if(secondObj.value != '' && secondObj.value != secondDefault) {
        isValid = true;
    }
    else if(millisecondObj.value != '' && millisecondObj.value != millisecondDefault) {
        isValid = true;
    }
    //if isValid is false at this point, then it means that no portions
    //of the control have been filled which means we need to highlight
    //the field to draw the user's attention to the error.
    if(isValid == false) {
        hourObj.className = hourErrCss;
        hourObj.style.cssText = hourErrStyles;
        
        minuteObj.className = minuteErrCss;
        minuteObj.style.cssText = minuteErrStyles;
        
        secondObj.className = secondErrCss;
        secondObj.style.cssText = secondErrStyles;
        
        millisecondObj.className = millisecondErrCss;
        millisecondObj.style.cssText = millisecondErrStyles;
        
        resetNavigationButtons();
	}
	else {
	    hourObj.className = hourCss;
        hourObj.style.cssText = hourStyles;
        
        minuteObj.className = minuteCss;
        minuteObj.style.cssText = minuteStyles;
        
        secondObj.className = secondCss;
        secondObj.style.cssText = secondStyles;
        
        millisecondObj.className = millisecondCss;
        millisecondObj.style.cssText = millisecondStyles;
	}
	return isValid;
}

function timeDurationIsValid(hour, minute, second, millisecond, hourDefault, minuteDefault, secondDefault, millisecondDefault, hourCss, minuteCss, secondCss, millisecondCss, hourStyles, minuteStyles, secondStyles, millisecondStyles, hourErrCss, minuteErrCss, secondErrCss, millisecondErrCss, hourErrStyles, minuteErrStyles, secondErrStyles, millisecondErrStyles, required) {
    var isValid = true;
    var hourObj = document.getElementById(hour);
    var minuteObj = document.getElementById(minute);
    var secondObj = document.getElementById(second);
    var millisecondObj = document.getElementById(millisecond);
        
    if(!(/[0-9][0-9]|^$/.test(hourObj.value)) && hourObj.value != hourDefault) {
        isValid = false;
    }
    if(!(/[0-5][0-9]|^$/.test(minuteObj.value)) && minuteObj.value != minuteDefault) {
        isValid = false;
    }
    if(!(/[0-5][0-9]|^$/.test(secondObj.value)) && secondObj.value != secondDefault) {
        isValid = false;
    }
    if(!(/[0-9][0-9][0-9]|^$/.test(millisecondObj.value)) && millisecondObj.value != millisecondDefault) {
        isValid = false;
    }
    
    var isHourEmpty = (hourObj.value == '' || hourObj.value == hourDefault)
    var isMinuteEmpty = (minuteObj.value == '' || minuteObj.value == minuteDefault)
    var isSecondEmpty = (secondObj.value == '' || secondObj.value == secondDefault)
    var isMillisecondEmpty = (millisecondObj.value == '' || millisecondObj.value == millisecondDefault)
    
    if(isHourEmpty != (isMinuteEmpty && isSecondEmpty && isMillisecondEmpty)) {
        isValid = false;
    }
    //if isValid is false at this point, then at least one portion
    //of the control failed validation which means we need to highlight
    //the field to draw the user's attention to the error.
    if(isValid == false) {
        hourObj.className = hourErrCss;
        hourObj.style.cssText = hourErrStyles;
        
        minuteObj.className = minuteErrCss;
        minuteObj.style.cssText = minuteErrStyles;
        
        secondObj.className = secondErrCss;
        secondObj.style.cssText = secondErrStyles;
        
        millisecondObj.className = millisecondErrCss;
        millisecondObj.style.cssText = millisecondErrStyles;
        
        resetNavigationButtons();
	}
	//we only want to reset the class back to normal if the field is not required.
    //otherwise resetting the class is taken care of by required validation.
	else if(!required) {
	    hourObj.className = hourCss;
        hourObj.style.cssText = hourStyles;
        
        minuteObj.className = minuteCss;
        minuteObj.style.cssText = minuteStyles;
        
        secondObj.className = secondCss;
        secondObj.style.cssText = secondStyles;
        
        millisecondObj.className = millisecondCss;
        millisecondObj.style.cssText = millisecondStyles;
	}
	return isValid;
}
