// JavaScript Document
custom = jQuery.noConflict(); 
custom(document).ready(function() {
    custom.fn.delay = function(time, callback){
        return this.animate({ opacity: '+=0' }, time, callback);
    }
    custom("#CTName").click(function() {
        custom("#CTClaimNumber").next('input').attr("disabled", true).val("Claim Number");
        custom("#CTDrugCardNumber").next('input').unmask().attr("disabled", true).val("Drug Card Number");
        custom(this).next('input').removeAttr("disabled").val("").focus();
    });
    custom("#CTClaimNumber").click(function() {
        custom("#CTName").next('input').attr("disabled", true).val("Claimant Name");
        custom("#CTDrugCardNumber").next('input').unmask().attr("disabled", true).val("Drug Card Number");
        custom(this).next('input').removeAttr("disabled").val("").focus();
    });
	// this is edited by Joel //
    custom("#CTDrugCardNumber").click(function() {
        custom("#CTName").next('input').attr("disabled", true).val("Claimant Name");
        custom("#CTClaimNumber").next('input').attr("disabled", true).val("Claim Number");
	// ID added to field name and unmask is added too //		
		custom("#DrugCardNum").unmask();
		custom("#DrugCardNum").mask("999-99999-99999").removeAttr("disabled").val("").focus();
    });
    custom("#nextTable input").attr("disabled", true);
    custom("#EMTypeR1").click(function() {
        custom("#nextTable input").each(function(){custom(this).attr("disabled", true)});
        custom("#EMEmployer").removeAttr("disabled");
    });
    custom("#EMTypeR2").click(function() {
        custom("#nextTable input").each(function(){
            custom(this).removeAttr("disabled");
            custom("#EMEmployer").attr("disabled", true);
        });
    });
    custom("#EMTypeR3").click(function() {
        custom("#nextTable input").each(function(){
            custom(this).removeAttr("disabled");
            custom("#EMEmployer").attr("disabled", true);
        });
    });
    custom("#CTName").next('input').blur(function() {
        if(custom(this).val() == '') custom(this).attr("disabled", true).val("Claimant Name");
    });
 //   custom("#CTClaimNumber").next('input').blur(function() {
  //      if(custom(this).val() == '') custom(this).attr("disabled", true).val("Claim Number");
   // });
 //   custom("#CTDrugCardNumber").next('input').blur(function() {
 //       if(custom(this).val() == '') custom(this).unmask().attr("disabled", true).val("Prescription Drug Card Number");
 //   });
    custom("input[name='receivedbyEmail']").click(function() {
        if(custom(this).val() == '')custom(this).next('input').removeAttr("disabled").val("").focus();
    });
    custom("#access-block1 .access-uname").focus(function () {
        if(custom(this).val() == 'Username') custom(this).val('');
        custom(this).blur(function(){
            if(custom(this).val() == '') custom(this).val('Username');
        });
    });
    custom("#access-block1 .access-pword").focus(function () {
        if(custom(this).val() == 'Password') custom(this).val('');
        custom(this).blur(function(){
            if(custom(this).val() == '') custom(this).val('Password');
        });
    });
    custom("input[name='drug-lookup']").focus(function () {
        if(custom(this).val() == 'Drug Name or NDC#') custom(this).val('');
        custom(this).blur(function(){
            if(custom(this).val() == '') custom(this).val('Drug Name or NDC#');
        });
    });
    custom("input#pharm-block-name").focus(function () {
        if(custom(this).val() == 'Pharmacy Name') custom(this).val('');
        custom(this).blur(function(){
            if(custom(this).val() == '') custom(this).val('Pharmacy Name');
        });
    });
    custom("input#pharm-block-city").focus(function () {
        if(custom(this).val() == 'City') custom(this).val('');
        custom(this).blur(function(){
            if(custom(this).val() == '') custom(this).val('City');
        });
    });
    custom("input#pharm-block-zip").focus(function () {
        if(custom(this).val() == 'Zip Code') custom(this).mask("99999",{placeholder:"0"}).focus();
        custom(this).blur(function(){
            var zipregx = /[0-9]{5}/;
            if((zipregx.test(custom(this).val()) == false) || custom(this).val() == "00000") {
                custom(this).unmask().val("Invalid Zip").delay(1000, function(){custom(this).val("Zip Code");});
                return false;
            }
        });
    });
    custom.mask.definitions['1']='[01]';
    custom.mask.definitions['2']='[12]';
    custom.mask.definitions['3']='[0123]';
    custom("input[name='CTDOB']").mask("19/39/2999");
    custom("input[name='CTDOI']").mask("19/39/2999");
    custom("input[name='CTState']").mask("aa",{placeholder:"X"});
    custom("input[name^='EMState']").mask("aa",{placeholder:"X"});
    custom("input[name='pharm-block-state']").mask("aa",{placeholder:"X"});
    custom("input[name='ReceivedState']").mask("aa",{placeholder:"X"});
    custom("input[name='CTPostal']").mask("99999?-9999",{placeholder:"0"});
    custom("input[name='EMPostal']").mask("99999?-9999",{placeholder:"0"});
    custom("input[name='Receivedzip']").mask("99999?-9999",{placeholder:"0"});
    custom("input[name^='ExpiredDate']").mask("19/39/2999");
    custom("input[name^='CTPhone']").mask("(999)999-9999? x99999");
    custom("input[name='EMPhone']").mask("(999)999-9999? x99999");
    custom("input[name='phone']").mask("(999)999-9999? x99999");
    custom("input[name='EMFax']").mask("(999)999-9999");
    custom("input[name='EMEmail']").val('____@____.___');
    custom("input[name='EMEmail']").focus(function () {
        if(custom(this).val() == '____@____.___') custom(this).val('');
            custom(this).blur(function(){
            var emailregx = /[a-zA-Z0-9-_]+@[a-zA-Z-]+?\.[a-zA-Z]{2,6}/;
            if((emailregx.test(custom(this).val()) == false) || custom(this).val() == "") {
                custom(this).val("Invalid Email").delay(1000, function(){custom(this).val("____@____.___");});
            }
        });
    });
    custom("input[type=radio]").addClass("radio");
    custom("input[type=checkbox]").addClass("checkbox");
    custom(".collapser").click(function () {
      custom(this).next('div').slideToggle("fast");
      custom(this).toggleClass("minus_icon"); return false;
    });
    custom(".full-collapser").click(function () {
      custom(this).next('div').slideToggle("slow");
      custom(this).text(custom(this).text() == 'Collapse All Content' ? 'Show All Content' : 'Collapse All Content');
      custom(this).toggleClass("minus_icon"); return false;
    });
    custom(".collapsable.open").slideDown(function () {
        custom(this).height("auto"); return false;
    });
    custom(".collapsable.close").slideUp(function () {
        custom(this).height("auto");
        custom(this).prev('span').toggleClass("minus_icon"); return false;
    });
});
