jQuery.noConflict();
function init(page)
{
	jQuery("a[href^='http']").not("a[href*='"+document.domain+"']").click(function(){
		_gaq.push(['_trackEvent', 'External Link', this.href, location.href]);
	});
	jQuery("a[href^='mailto:']").not("a.notrack").click(function(){
		recordIt('Email','','');
	});
	jQuery("a[href^='mailto:']").click(function(){
		_gaq.push(['_trackEvent', 'External Link', this.href, location.href]);
	});
	jQuery("a[href$='.pdf']").click(function(){
		var pdf = this.href.substr(this.href.indexOf("/doc/")+5);
		_gaq.push(['_trackEvent', 'PDF', pdf, location.href]);
	});
}
function ctf(theText) 
{
	if (theText.value == theText.defaultValue) 
	{
		theText.value = "";
	}
}
function rtf(theText) 
{
	if (theText.value == "") 
	{
		theText.value = theText.defaultValue;
	}
}

function validateForm(formElem, good_color, bad_color) 
{
	var inputElem = null;
	var success = true;
	
	inputElem = formElem.captcha;
	if( inputElem ) 
	{
		if(inputElem.value.length != 5)
		{
			inputElem.parentNode.style.borderColor = bad_color;
			inputElem.focus();
			success = false;
		}
		else 
		{
			inputElem.parentNode.style.borderColor = good_color;
		}
	}
	
	inputElem = formElem.asset_worth;
	if( inputElem ) 
	{
		if(inputElem.value == "") 
		{
			inputElem.parentNode.style.borderColor = bad_color;
			inputElem.focus();
			success = false;
		}
		else 
		{
			inputElem.parentNode.style.borderColor = good_color;
		}
	}
	
	inputElem = formElem.phone;
	if( inputElem ) 
	{
		if(inputElem.value == inputElem.defaultValue) 
		{
			inputElem.parentNode.style.borderColor = bad_color;
			inputElem.focus();
			success = false;
		}
		else 
		{
			inputElem.parentNode.style.borderColor = good_color;
		}
	}
	
	inputElem = formElem.email;
	if( inputElem ) 
	{
		if(!isValidEmail(inputElem.value)) 
		{
			inputElem.parentNode.style.borderColor = bad_color;
			inputElem.focus();
			success = false;
		}
		else 
		{
			inputElem.parentNode.style.borderColor = good_color;
		}
	}
	
	inputElem = formElem.name;
	if( inputElem ) 
	{
		if(inputElem.value == inputElem.defaultValue) 
		{
			inputElem.parentNode.style.borderColor = bad_color;
			inputElem.focus();
			success = false;
		}
		else 
		{
			inputElem.style.borderColor = good_color;
		}
	}
	
	if(!success)
	{
		alert("Please fill out all required fields with valid information.");
	}
	return success;
}

function isValidEmail(the_email) 
{
	var emailFilter=/^.+@.+\..{2,3}$/;
	var illegalChars= /[\(\)\<\'\>\,\;\:\\\/\"\[\]]/;
	if (!emailFilter.test(the_email) || the_email.match(illegalChars)) 
	{
		return false;
	}
	return true;
}

function fudlink(elem)
{
	if(getCookie('fud')=='1')
	{
		var pdf = elem.href.substr(elem.href.indexOf("doc=")+4)+".pdf";
		_gaq.push(['_trackEvent', 'PDF', pdf, location.href]);
		window.open(elem.href);
	}
	else
	{
		Modalbox.show(elem.href, {title: elem.title, width: 300});
	}
	return false;
}

function videopop(elem)
{
	_gaq.push(['_trackEvent', 'Video', elem.title, location.href]);
	Modalbox.show(elem.href, {title: elem.title, width: 618});
	return false;
}

function getCookie(c_name)
{
	if (document.cookie.length>0)
	{
		c_start=document.cookie.indexOf(c_name + "=");
		if (c_start!=-1)
		{
			c_start=c_start + c_name.length+1;
			c_end=document.cookie.indexOf(";",c_start);
			if (c_end==-1) c_end=document.cookie.length;
			return unescape(document.cookie.substring(c_start,c_end));
		}
	}
	return "";
}

function validatefud(formElem, good_color, bad_color) 
{
	var inputElem = null;
	var success = true;
	
	inputElem = formElem.email;
	if( inputElem ) 
	{
		if(!isValidEmail(inputElem.value)) 
		{
			inputElem.parentNode.style.borderColor = bad_color;
			inputElem.focus();
			success = false;
		}
		else 
		{
			inputElem.parentNode.style.borderColor = good_color;
		}
	}
	
	if(!success)
	{
		alert("Please fill out all required fields with valid information.");
		return false;
	}
	
	var pdf = formElem.action.substr(formElem.action.indexOf("doc=")+4)+".pdf";
	_gaq.push(['_trackEvent', 'PDF', pdf, location.href]);
	_gaq.push(['_trackEvent', 'Email Capture', pdf, location.href]);
	
	Modalbox.hide();
	
	return true;
}

function showvid(vid_id)
{
	var elem = document.getElementById('vid'+vid_id);
	var t = elem.getElementsByTagName('h6')[0].getElementsByTagName('a')[0].innerHTML;
	var d = elem.getElementsByTagName('p')[0].innerHTML;
	var v = elem.getElementsByTagName('input')[0].value;
	
	elem = document.getElementById('vidmain');
	document.getElementById('vidmain').getElementsByTagName('h5')[0].innerHTML = t;
	document.getElementById('vidmain').getElementsByTagName('p')[0].innerHTML = d;
	elem = elem.getElementsByTagName('object')[0];
	elem.getElementsByTagName('param')[0].value = v;
	elem.getElementsByTagName('embed')[0].src = v;
}

function getX(oElement) //necessary because of ie6
{
	var iReturnValue = 0;
	while( oElement != null ) 
	{
		iReturnValue += oElement.offsetLeft;
		oElement = oElement.offsetParent;
	}
	return iReturnValue;
}
function getY(oElement) //necessary because of ie6
{
	var iReturnValue = 0;
	while( oElement != null ) 
	{
		iReturnValue += oElement.offsetTop;
		oElement = oElement.offsetParent;
	}
	return iReturnValue;
}

var appeareffect = null;
function showLoc(area_elem) 
{
	if(!area_elem)
	{
		appeareffect.cancel();
		$('loc-map-hover').setStyle({visibility: 'hidden'});
		new Effect.Opacity('loc-map-hover', {from: 0.0, to: 0.0, duration: 0.0001});
		return;
	}
	
	var loc = area_elem.href.replace(".php","").split("/");
	loc = loc[loc.length-1];
	document.getElementById('loc-map-hover-txt').innerHTML = document.getElementById(loc).innerHTML;
	
	var map_elem = document.getElementById('loc-map');
	var hover_elem = document.getElementById('loc-map-hover');
	var pos = area_elem.coords.split(",");
	pos = new Array(
		getX(map_elem)+parseInt(pos[0])+(parseInt(pos[2])-parseInt(pos[0]))/2-(hover_elem.offsetWidth/2),
		getY(map_elem)+parseInt(pos[1])-hover_elem.offsetHeight-2);
	
	hover_elem.style.left = pos[0]+"px";
	hover_elem.style.top = pos[1]+"px";
	
	$('loc-map-hover').setStyle({visibility: 'visible'});
	appeareffect = new Effect.Opacity('loc-map-hover', { from: 0.0, to: 0.75, duration: 1.0 });
}
