// Return an Elements Position;

function find_pos(obj)
{
	var cur_left = cur_top = 0;

	if(obj.offsetParent)
	{
		cur_left = obj.offsetLeft;
		cur_top = obj.offsetTop;

		while (obj = obj.offsetParent)
		{
			cur_left += obj.offsetLeft;
			cur_top += obj.offsetTop;
		}
	}
	return [cur_left,cur_top];
}

// Get a CSS Value

function get_style(el,el_css)
{
	var css_value = el.style[el_css];

	if(!css_value) // If it's not an inline style
	{
		if(el.currentStyle) // IE
		{
			// Firefox wants "padding-top", and IE wants "paddingTop"
			// So we'll pass "padding-top" and convert it for IE
			var ix  = el_css.indexOf("-");

			if(ix > -1)
			{
				var new_css = el_css.split("-");
				for(var i=0; i<new_css.length; i++)
				{
					if(i>0)
					{
						new_css[i] = new_css[i].substring(0,1).toUpperCase() + new_css[i].substring(1,new_css[i].length);
					}
				}

				el_css = new_css.join("");
			}

			css_value = el.currentStyle[el_css];
		}
		else if(window.getComputedStyle)
		{
			css_value = document.defaultView.getComputedStyle(el,null).getPropertyValue(el_css);
		}
		else
		{
			css_value = null;
		}
	}

	return css_value;
}

// Window Dimensions

function get_window()
{
	// Window inner dimensions
	var window_x, window_y;

	if(self.innerHeight) // all except Explorer
	{
		//window_x = self.innerWidth;
		window_x = document.body.offsetWidth;
		window_y = self.innerHeight;
	}
	else if(document.documentElement && document.documentElement.clientHeight) // Explorer 6 Strict Mode
	{
		window_x = document.documentElement.clientWidth;
		window_y = document.documentElement.clientHeight;
	}
	else if (document.body) // other Explorers
	{
		window_x = document.body.clientWidth;
		window_y = document.body.clientHeight;
	}

	var window_dim = new Array(window_x, window_y);
	return window_dim;
}

// Article Height Check

function article_height()
{
	var left = document.getElementById("c-menu");

	if(!left) return;

	var left_bottom = left.offsetHeight + find_pos(left)[1];

	var article = document.getElementById("c-article");
	var article_bottom = article.offsetHeight + find_pos(article)[1];

	var non_content = left_bottom;

	if(article_bottom < non_content)
	{
		article.style.height = (article.offsetHeight + (non_content - article_bottom)) + (40) + "px";
	}
}

///// Form Functions

function trim(s)
{
	return s.replace(/^\s+|\s+$/g, '');
}

function valid_email(ea)
{
	var email_reg = "^[\\w-_\.]*[\\w-_\.]\@[\\w]\.+[\\w]+[\\w]$";
	var regex = new RegExp(email_reg);
	return regex.test(ea);
  }

function validate(f,el)
{
	var address = trim(document.getElementById(el).value);
	var valid = valid_email(address);

	if(!valid)
	{
		alert("\"" + address + "\" is not a valid email address. A valid email address is required to submit this form.");
		f.focus();
		f[el].select();
		return false;
	}
	else
	{
		return true
	}
}