

var WC = function() {
	return {
		validate_email: function(email) {
			return /\w{1,}[@][\w\-]{1,}([.]([\w\-]{1,})){1,3}$/.test(email);
		},

		initialize: function() {
			$$('table.data .clk a').each(function(link){
				Event.observe(link.up('tr'), 'click', function(e){if(Event.element(e).tagName.toUpperCase() !='A'){ window.location = link.href}});
			});
			var prop_thumbs = $('proposal_thumbs');
			if(prop_thumbs) {
				WC.thumbsSize();
			}
			var autof = $$('input.auto_focus');
			if(autof.length) {
				autof[0].focus();
			}
		},
		urls: {
			admin_proposal: '/admin/proposals/',
			jury_proposal: '/jury/proposal/',
			thumbs: '/admin/jury/',
			wait_img: '/stylesheets/art/loader.gif',
			choice_entry: '/proposals/'
		},
		
		thumbsSize: function() {
			var rows = $$('.entry_row');
			rows.each(function(row){
				var thumbs = row.select('.entry');
				var max = thumbs.max(function(thumb) {
				  return thumb.getHeight();
				})
				thumbs.each(function(thumb){
					thumb.setStyle({height: max+'px'});
					var url = thumb.down('a').href;
					Event.observe(thumb,'click',function(){window.location = url});
				});
				
			});
		},
		createCookie: function(name,value,days) {
			if (days) {
				var date = new Date();
				date.setTime(date.getTime()+(days*24*60*60*1000));
				var expires = "; expires="+date.toGMTString();
			}
			else var expires = "";
			document.cookie = name+"="+value+expires+"; path=/";
		},
		readCookie: function(name) {
			var nameEQ = name + "=";
			var ca = document.cookie.split(';');
			for(var i=0;i < ca.length;i++) {
				var c = ca[i];
				while (c.charAt(0)==' ') c = c.substring(1,c.length);
				if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
			}
			return null;
		},
		eraseCookie: function(name) {
			createCookie(name,"",-1);
		}
	}

}();

document.observe("dom:loaded", WC.initialize);
