var carousel = null;

String.prototype.normalize = function(){
	return this.replace(/\s+/g, " ");
};

String.prototype.trim=function(){
	return this.replace(/^\s*|\s*$/g,'');
}

function check_email_fill(field, mode)
{
	if (mode == 'on' && field.value.trim() == 'enter email address')
		field.value = '';

	else if (mode == 'off' && field.value.trim() == '')
		field.value = 'enter email address';
}

function swap_sub_nav(link)
{
	var i = 1;

	while (document.getElementById('sub_nav_links_' + i))
	{
		var temp_div = document.getElementById('sub_nav_links_' + i);

		if (link == i)
			temp_div.style.display = '';

		else
			temp_div.style.display = 'none';

		i++;
	}
}

function swap_state(state)
{
	swap_rep_region(0);

	var us = document.getElementById('rep_country_0');

	if (us)
	{
		var found = false;

		for (var i = 0; i < us.childNodes.length; i++)
		{
			if (us.childNodes[i].nodeName == 'DIV')
			{
				if (us.childNodes[i].id == 'state_' + state)
				{
					us.childNodes[i].style.display = '';
					found = true;
				}

				else
					us.childNodes[i].style.display = 'none';
			}
		}

		if (!found)
			document.getElementById('no_reps').style.display = '';
	}

	return false;
}

function swap_side_subnav(nav)
{
	var i = 1;

	while (document.getElementById('side_subnav_' + i))
	{
		var temp_div = document.getElementById('side_subnav_' + i);

		if (nav == i)
			temp_div.style.display = '';

		else
			temp_div.style.display = 'none';

		i++;
	}

	return false;
}

function swap_rep_region(region)
{
	var i = 0;

	document.getElementById('no_reps').style.display = 'none';

	while (document.getElementById('rep_country_' + i))
	{
		if (region == i)
			document.getElementById('rep_country_' + i).style.display = '';

		else
			document.getElementById('rep_country_' + i).style.display = 'none';

		i++;
	}

	return false;
}

function validEmail(email) {

	invalidChars = " /:,;"

	if (email == "") {
		return false
	}
	for (i=0; i<invalidChars.length; i++) {
		badChar = invalidChars.charAt(i)
		if (email.indexOf(badChar,0) > -1) {
			return false
		}
	}
	atPos = email.indexOf("@",1)
	if (atPos == -1) {
		return false
	}
	if (email.indexOf("@",atPos+1) > -1) {
		return false
	}
	periodPos = email.indexOf(".",atPos)
	if (periodPos == -1) {
		return false
	}
	if (periodPos+3 > email.length)    {
		return false
	}
	return true
}

function submitIt(subsForm) {
	if (!validEmail(document.subsForm.email.value))
		{
			alert("Invalid email address")
			document.subsForm.email.focus()
			document.subsForm.email.select()
			return false
		}


	var pref = "";
	var reqfields = new Array('email');

		for(i=0; i < reqfields.length;i++)
			{
				tempfield = "document.subsForm."+pref+reqfields[i]+".value";
				tempid = "document.subsForm."+pref+reqfields[i]+".id";
				tempval = eval(tempfield);
				tempid = eval(tempid);

				if(tempval=="")
					{
						alert("Please provide a "+tempid+".");
						return false;
					}
		}

	return true
}


document.observe("dom:loaded", function() {

	if ($$('#carousel_home li').length > 1)
	{
		carousel = new Pluit.Carousel('#carousel_home', {
			effect			:	'fade',
			autoPlay		:	true,
			circular		:	true,
			hidePrevNext	:	true,
			slideDuration	:	6,
			animDuration	:	0.7
		});
	}
});

