I think the person who said: congrats, you now have to pee in a cup to see your kids is right on... and that sentence alone will hopefully wake you up about your drinking problem. Custody battles are usually pretty nasty, with one or both parties exaggerating in hopes to get what they want (and its a shame when parents hate their exes more than they love their kids - i see that phrase a lot around here and its very common and sad). You had a chance to defend yourself and you blew it by just handing it over to her. Maybe she wasn't exaggerating after all, and now, the judge won't forget that! Until he retires or for some reason he is replaced, you will be remembered by him as the dude who came to court drunk to respond to accusations of being a drunk....
In your case, i hope you do come to terms with your addiction and understand that now is the time to change your life around. You don't need to go to rehab or join a church or AA to get help, there are other non-religious, or cheaper options... google it.
When it comes down to it, its very basic. Do you want to see your kids and have a good relationship with them for the rest of their lives and see them get married and have kids and be a grandpa OR do you want to drink a flavored liquid that makes you feel woozy and giggly or dizzy and forgetful and can cause you legal problems and fatal car accidents and make you more and more miserable inside every day?
To me, the choice would be easy. And i don't have any experience with being an alcoholic, i don't even drink because i don't like the taste (and my fishing buddies harp on me about it, i just drink diet pepsi), so i can't necessarily relate, and for that my advice might be ignored by you. i have a close friend who is addicted to wine. i realize i can't help her. but sometimes people just need one huge wake up call that will inspire them to get help. i hope this is one for you.
But, dude... seriously? you DO have a problem because no one who is not an alcoholic would drink the day OF court, even if it was a sip. Don't you like soda? drink some soda, man. it tastes great. so what if you don't get buzzed. or drink near beer if you like the taste so much.
so, as you read this, a week before xmas, please come to terms with your problem. make something good come from this... not even for you, but for your kids, man!
PS most of my friends that don't drink, don't drink because their dad was a drunk. i think there is a good chance that your kids won't go down that road, and thats a good thing!
WAKE UP! PLEASE.
OK im done here.