var Comments = {

	flash: {
		clear: function() { if ($('flash')) $('flash').update(); },
		show: function(msg) {
			var text = msg.error || msg.ok || '';
			$('flash').update('<p>' + text + '</p>');
			$('flash').addClassName(msg.error ? 'error' : 'notice');
		}
	},

	newComment: function() {
		$('add_comment_form').reset();
		$('add_comment_form').show();
		Comments.flash.clear();
	},
	
	cancel: function() {
		$('add_comment_form').hide();
		$('add_comment_form').reset();
		Comments.flash.clear();
	},
	
	save: function(cantConnectMsg, blankMsg) {
		if ($("comment_body").getValue().strip().blank()) {
			alert(blankMsg);
			return false;
		}
		new Ajax.Request('index.php?do=saveObjectComment', {
			method: 'post',
			parameters: $('add_comment_form').serialize(),
			onComplete: function(transport) {
				var response = transport.responseText.sub('<html><body>', '');
				response = response.sub('</body></html>', '').evalJSON(true);
				//Comments.flash.show(response.status);
				$('add_comment_form').hide();
				$('add_comment_form').reset();
				if (!$('comments_list')) {
					$('nocomments').remove();
					Element.insert('comments_area', { bottom: new Element('ol', { id: 'comments_list' }) });
				}
				Element.insert('comments_list', { top: response.comment });
				new Effect.Highlight($('comments_list').childElements().first(), { startcolor: '#ffff99', endcolor: '#ffffff' });
				
			},
			onFailure: function() { Comments.flash.show({ error: cantConnectMsg }); }
		});
	}
};


var wci = {
		
	reportProblem: function(blank_msg) {
		var valid = true;
		[$('problem-title'), $('problem-category'), $('problem-description')].each(function(field) {
			if (field.getValue().blank()) {
				alert(blank_msg);
				valid = false;
				throw $break;
			}
		});
		return valid;
	}
};


function sendForm(nameForm){

  document.forms[nameForm].submit();

}

function disableForm(name) {
	
		var theform = $(name)
	
		if (document.all || document.getElementById) {
			for (i = 0; i < theform.length; i++) {
			var formElement = theform.elements[i];
				if (true) {
					if (formElement.disabled == false){
					formElement.disabled = true;
					
					}else{
					formElement.disabled = false;
					}
				}
			}
		}
	}
	
function registerNewsletter(){
	var email = document.getElementById('nl_email').value;
	document.location='./?do=registerNewsletter&email='+email;
}

function unregisterNewsletter(){
	var email = document.getElementById('nl_email').value;
	document.location='./?do=unregisterNewsletter&email='+email;
}

var Tiny = {
		
		settings: {
			language: "en",
			mode : "textareas",
			theme : "advanced",
			plugins : "style,table,advhr,advimage,advlink,insertdatetime,preview,searchreplace,contextmenu,paste,media,directionality,fullscreen,noneditable",
			theme_advanced_toolbar_location : "top",
			theme_advanced_toolbar_align : "left",
			theme_advanced_path_location : "bottom",
			content_css : "./style/site/content.css",
			plugin_insertdate_dateFormat : "%Y-%m-%d",
			plugin_insertdate_timeFormat : "%H:%M:%S",
			external_image_list_url : "./tinyMc.php",
			external_link_list_url : "./tinyMcFile.php",
			flash_external_list_url : "./example_flash_list.js",
			media_external_list_url : "./tinyMcFlash.php",
			extended_valid_elements : "hr[class|width|size|noshade],font[face|size|color|style],span[class|align|style]",
			theme_advanced_resize_horizontal : false,
			theme_advanced_resizing : true,
			nonbreaking_force_tab : true,
			apply_source_formatting : true
		},
		
		init: function() {
			tinyMCE.init(this.settings);
		}
};