// Place your application-specific JavaScript functions and classes here
// This file is automatically included by javascript_include_tag :defaults
var addEvent = (function(){
    if(document.addEventListener) {
        return function(obj,name,func){
            obj.addEventListener(name, func, false);
        }
    } else if (document.attachEvent) {
        return function(obj,name,func){
            obj.attachEvent('on'+name, func);
        }
    } else return function(){
        throw 'Error'
    }
})();

function showMessage(text) {
    var message_container = document.getElementById("message-container");
    var div = document.createElement("div");
    div.className = 'message-content';
    message_container.appendChild(div);
    div.innerHTML = text;
    
    addEvent(message_container,"click", function(){
        $(message_container).fade({
            duration: 1.0
        });
        $(div).remove();
    });
    
    message_container.show();
    
	
//    setTimeout(function(){
//        $(message_container).fade({
//            duration: 1.0
//        });
//    }, 7000);
}

function showAlert(text) {
    var message_container = document.getElementById("alert-container");
    var div = document.createElement("div");
    div.className = 'message-content';
    message_container.appendChild(div);
    div.innerHTML = text;
    
    addEvent(message_container,"click", function(){
        $(message_container).fade({
            duration: 1.0
        });
        $(div).remove();
    });

    $(message_container).show();
    
//    setTimeout(function(){
//        $(message_container).fade({
//            duration: 1.0
//        });
//    }, 7000);
}

function forumCitation(text) {
    var editor = nicEditors.findEditor('area1')
    var prev_text = editor.getContent();
    editor.setContent(prev_text + text + '<br />');
}

var ViisPayments = {
    _init: function(){
        var self = this;
    },
    _toggle_payment_methods: function(i, msg) {
        if (i == 0) {
            $('init_paypal_checkout').checked = false;
        } else if (i == 1) {
            if($('currency').selectedIndex == 0) {
                showAlert(msg);
                $('init_paypal_checkout').checked = false;
            } else {
                $('init_paid').checked = false;
            }
        }
    }
}

Event.observe(window, 'load', function() {
  ViisPayments._init();
});
