﻿

$(document).ready(function(){
    
    /* rsv-protection page */
     $('#txtCellAreaCode').autotab({ target: 'txtCellExchange', format: 'numeric' });
     $('#txtCellExchange').autotab({ target: 'txtCellExt', format: 'numeric', previous: 'txtCellAreaCode' });
     $('#txtCellExt').autotab({ previous: 'txtCellExchange', format: 'numeric' });
     $('#txtPhoneAreaCode').autotab({ target: 'txtPhoneExchange', format: 'numeric' });
     $('#txtPhoneExchange').autotab({ target: 'txtPhoneExt', format: 'numeric', previous: 'txtPhoneAreaCode' });
     $('#txtPhoneExt').autotab({ previous: 'txtPhoneExchange', format: 'numeric' });

      
      /* tell a friend */
      
      $(".ecard").click( function() {
            //console.log("swap") ;
            swapImg($(this).attr('id')) ;
      }) ;
      
      /* panel control listeners */
      $(".panel_control").click( function() {
            togglePanel($(this)) ;
       }) ;
      
      // call these to open the email and cell reminder panels if they are checked on page load
      $(".panel_control").each( function () {
            togglePanel($(this)) ;
       }) ;
      
    
});

    /*function togglePhone() {
        thrive = document.getElementById("cbThriveNetwork");
        var phone = document.getElementById("phone")
        if (thrive.checked) {
            phone.style.display = "block";
        }
        else
            phone.style.display = "none";
    }
    function toggleCell() {
        cellUpdates = document.getElementById("cbTxtReminder");
        var cell = document.getElementById("cell")
        if (cellUpdates.checked) {
            cell.style.display = "block";
        }
        else
            cell.style.display = "none";
    }
    function toggleReminders() {
        reminders = document.getElementById("cbReminders");
        var reminderoptions = document.getElementById("reminderoptions")
        if (reminders.checked) {
            reminderoptions.style.display = "block";
        }
        else
            reminderoptions.style.display = "none";
    }*/
    
    function togglePanel(checkbox) {
       
        if (checkbox.attr("id").match("cbReminders")) {
            
            if (checkbox.attr("checked")) {
                $("#reminderoptions").css("display", "block") ;
            } else {
                $("#reminderoptions").css("display", "none")  ;
            }
       } else if (checkbox.attr("id").match("cbTxtReminder")) {
            
            if (checkbox.attr("checked")) {
                 $("#txtreminderoptions").css("display", "block") ;
            } else {
                $("#txtreminderoptions").css("display", "none") ;
            }
            
        }
    }
    

    function limitText(limitField, limitNum) {
	    if (limitField.value.length > limitNum) {
		    limitField.value = limitField.value.substring(0, limitNum);
	    } 
    }

			
				    
function swapImg(id) {
    
    
    var id_number = id.substring(id.length-1, id.length) ;
    //console.log("swapping to " + id + " " + id_number) ;
    $('#displayEcard').attr("src", "/ui/images/ecard" + id_number + "-img.jpg") ;
}

var alreadycleared = false;
function hideDefault(field) {

if(alreadycleared != true) {
alreadycleared = true;
$(field).val("");
$(field).css("color", "#000") ;
}

}   

