Array.extend(
{
	remove: function(items)
	{
		if(!items.push)
			items = [items];
	
		var tmp = [];
		for(var i = 0; i < this.length; i++)
			if(!items.contains(this[i]))
					tmp.push(this[i]);
		return tmp;
	}
});

El.extend(
{
	_getValue: function()
	{
		switch(this.tagName.toLowerCase())
		{
			case 'select':
				return (window.ie) ? this.options[this.selectedIndex].text : this.options[this.selectedIndex].value;
			case 'input':
				var t = this.type.toLowerCase();
				if
				(
					!(
						(this.checked && ['checkbox', 'radio'].contains(t))
						||
						['text', 'file', 'password'].contains(t)
					)
					||
					(this.style.display == 'none' || this.parentNode.style.display == 'none')
				)
					break;
			case 'textarea':
				return this.value;
		};
		return false;
	},

	getByTag: function()
	{
		var tmp = [];
		for(var i = 0; i < arguments.length; i++)
			tmp = tmp.concat($A(this.getElementsByTagName(arguments[i])));
		return tmp;
	}
});

var ISDAlumni =
{
	deleteUser: function(id)
	{
		if(confirm('Delete this user?'))
		{
			window.location = '/users/delete/'+ id +'/';
		}
		return false;
	},
	
	editUser: function(id)
	{
		window.location = '/users/admin/'+ id +'/';
		return false;
	},
	
	fixRedBar: function()
	{
		$('isd-red-bar').getByTag('div')[0].innerHTML = redBarLinks;
	},
	
	checkForm: function(form, fields)
	{
		var ips = $(form).getByTag('input', 'textarea', 'select');
		ips = ips.remove([$('form-city'), $('re_password')]);
		
		if(fields == 'required')
		{
			var tmp = [];
			ips.each(function(el)
			{
				if(!$(el).hasClass('optional'))
					tmp.push(el);
			});
			ips = tmp;
		}
		var flags = 0, pass = 0; email = 0;
		for(var i = 0; i < ips.length; i++)
		{
			var v = $(ips[i])._getValue();
			if(!['submit', 'reset'].contains(ips[i].type.toLowerCase()))
			{
				if(['UserPassword'].contains(ips[i].id) && ($('re_password') && $('re_password')._getValue() != v))
				{
					$(ips[i].parentNode).addClass('warning');
					pass++; flags++;
				}
				if(['UserEmail'].contains(ips[i].id))
				{
					var validEmail = (/^[^@]+\@[^\.]+\.[a-z]{3,4}$/).test(v);
					if(!validEmail)
					{
						$(ips[i].parentNode).addClass('warning');
						email++; flags++;
					}
					else
						$(ips[i].parentNode).removeClass('warning');
				}
				if(v === '')
				{
					$(ips[i].parentNode).addClass('warning');
					flags++;
				}
				else
					$(ips[i].parentNode).removeClass('warning');
			}
		}
		var msg = 'Please fill out all required fields.';
		if($('form-city')._getValue() != '')
			flags = 9000;
		if(pass > 0 && flags != 9000)
			msg += "\nPasswords do not match.";
		if(email > 0 && flags != 9000)
			msg += "\nPlease enter a valid email address.";
		if(flags > 0 && flags != 9000)
			alert(msg);
		return (flags == 0 && pass == 0);
	},
	
	checkCustomCategory: function(el)
	{
		$($('JobCustomCategory').parentNode)[($(el)._getValue() === '0') ? 'show' : 'hide']({'height': false});
	},
	
	search: function(url, el)
	{
		var v = $(el).getByTag('input')[0].value;
		if(v != '')
		{
			window.location = '/'+ url +'/search/'+ v;
		}
		return false;
	},
	
	toggleRecipients: function(el)
	{
		el = $(el);
		if(el)
		{
			$('content').style.height = '';
			with(el)
			{
				if(style.display == 'none')
					show();
				else
					hide();
			}
		}
	}
};
