var jqDialog = new function() {

    //________button / control labels
    this.strOk = 'Ok';
    this.strYes = 'Yes';
    this.strNo = 'No';
    this.strCancel = 'Cancel';
    this.strX = 'x close';


    //________
    this.closeTimer = null;
    this.width = 0; this.height = 0;
    
    this.divBoxName =    'jqDialog_box';    this.divBox = null;
    this.divContentName =    'jqDialog_content';    this.divContent = null;
    this.divOptionsName = 'jqDialog_options'; this.divOptions = null;
    this.btCloseName = 'jqDialog_close'; this.btClose = null;
    this.btYesName = 'jqDialog_yes'; this.btYes = null;
    this.btNoName = 'jqDialog_no'; this.btNo = null;
    this.btOkName = 'jqDialog_ok'; this.btOk = null;
    this.btCancel = 'jqDialog_ok'; this.btCancel = null;
    this.inputName = 'jqDialog_input'; this.input = null;


    //________create a confirm box
    this.confirm = function(message, callback_yes, callback_no) {        
        this.createDialog(message);
        this.btYes.show(); this.btNo.show();  this.btYes.focus();
        this.btOk.hide(); this.btCancel.hide(); 
        
        // just redo this everytime in case a new callback is presented
        this.btYes.unbind().click( function() {
            jqDialog.close();
            if(callback_yes) callback_yes();
        });

        this.btNo.unbind().click( function() {
            jqDialog.close();
            if(callback_no) callback_no();
        });

    };
    
    //________prompt dialog
    this.prompt = function(message, content, callback_ok, callback_cancel) {
        this.createDialog($("<p>").append(message).append( $("<p>").append( $(this.input).val(content) ) ));
        
        this.btYes.hide(); this.btNo.hide();
        this.btOk.show(); this.input.focus(); this.btCancel.show(); 
        
        // just redo this everytime in case a new callback is presented
        this.btOk.unbind().click( function() {
            jqDialog.close();
            if(callback_ok) callback_ok(jqDialog.input.val());
        });

        this.btCancel.unbind().click( function() {
            jqDialog.close();
            if(callback_cancel) callback_cancel();
        });

    };
    
    //________create an alert box
    this.alert = function(content, callback_ok) {
        this.createDialog(content);
        this.btCancel.hide(); this.btYes.hide(); this.btNo.hide(); this.btOk.show();
        this.btOk.focus();
        
        // just redo this everytime in case a new callback is presented
        this.btOk.unbind().click( function() {
            jqDialog.close();
            if(callback_ok)
                callback_ok();
        });
    };

    
    //________create a dialog with custom content
    this.content = function(content, close_seconds) {
        this.createDialog(content);
        this.divOptions.hide();
    };

    //________create an auto-hiding notification
    this.notify = function(content, close_seconds) {
        this.content(content);
        this.btClose.focus();
        if(close_seconds)
            this.closeTimer = setTimeout(function() { jqDialog.close(); }, close_seconds*1000 );
    };

    //________dialog control
    this.createDialog = function(content) {
        clearTimeout(this.closeTimer);
        this.divOptions.show();
        this.divContent.html(content);
        this.divBox.fadeIn('fast');
        this.maintainPosition();
    };
    
    this.close = function() {
        this.divBox.fadeOut('fast');
        this.clearPosition();
    };

    //________position control
    this.clearPosition = function() {
        $(window).scroll().remove();
    };
    this.makeCenter = function() {
        $(jqDialog.divBox).css (
            {
                top: ( (($(window).height() / 2) - ( ($(jqDialog.divBox).height()) / 2 ) )) + ($(document).scrollTop()) + 'px',
                left: ( (($(window).width() / 2) - ( ($(jqDialog.divBox).width()) / 2 ) )) + ($(document).scrollLeft()) + 'px',
            }
        );
    };
    this.maintainPosition = function() {
        $(window).scroll( function() {
            jqDialog.makeCenter();
        } );
        
    }

    //________
    this.init = function() {
        this.divBox = $("<div>").attr({ id: this.divBoxName });
        this.divContent = $("<div>").attr({ id: this.divContentName });
        this.divOptions = $("<div>").attr({ id: this.divOptionsName });
        this.btYes = $("<button>").attr({ id: this.btYesName }).append( document.createTextNode(this.strYes) );
        this.btNo = $("<button>").attr({ id: this.btNoName }).append( document.createTextNode(this.strNo) );
        this.btOk = $("<button>").attr({ id: this.btOkName }).append( document.createTextNode(this.strOk) );
        this.btCancel = $("<button>").attr({ id: this.btCancelName }).append( document.createTextNode(this.strCancel) );
        this.input = $("<input>").attr({ id: this.inputName });
        this.btClose = $("<button>").attr({ id: this.btCloseName }).append( document.createTextNode(this.strX) ).click(
                            function() {
                                jqDialog.close();
                            });

        this.divBox.append( this.btClose ).append( this.divContent ).append(
            this.divOptions.append(this.btYes).append(this.btNo).append(this.btOk).append(this.btCancel)
        );
        
        this.divBox.hide();
        $('body').append( this.divBox );
        this.makeCenter();
    };
    
};

$(document).ready(function(){

        jqDialog.init();

        /*var html = '<form method="post" action="signup.php">' +
            '<div>' +
            '<label>Email:</label> <input type="text" class="i" name="email" size="50" />' +
            '<input type="submit" value="Signup NOW" class="bt" />' +
            '</div></form>';
          */
        var html= "<form method=post action=\"https://app.icontact.com/icp/signup.php\" name=\"icpsignup\" id=\"icpsignup645\" accept-charset=\"UTF-8\" onsubmit=\"return verifyRequired645();\" >" +
                  "<input type=hidden name=redirect value=\"http://www.pennystockparlay.com/thanks.htm\" />" +
                  "<input type=hidden name=errorredirect value=\"http://www.icontact.com/www/signup/error.html\" />" +
                  '<div>' +
                  '<label>Email:</label> <input type="text" class="i" name="fields_email" size="50" />' +
                  '<input type="submit" value="Signup NOW" class="bt" />' +
                  '<input type=hidden name="listid" value="10561">' +
                  '<input type=hidden name="specialid:10561" value="RZA0">' +
                  '<input type=hidden name=clientid value="700247">' +
                  '<input type=hidden name=formid value="645">' +
                  '<input type=hidden name=reallistid value="1">' +
                  '<input type=hidden name=doubleopt value="0">' +
                  '</div></form>';
        
        window.setTimeout(function() {
            jqDialog.content(html);
        }, 900);

});
