function searchState(state) {
	var approved = new Array("VA","ND","NJ","NY","FL","CA");
	var flag = null;
	for (i=0; i<approved.length; i++)
		if(approved[i] == state)
			flag = state;
	if(flag != null) {
		document.getElementById('approved').style.display = 'block';
		document.getElementById('not_approved').style.display = 'none';
		document.getElementById('state_link').href = 'info.php?st=' + state;
		//xmlParser(state); too messy to show data in the banner div
	} else {
		document.getElementById('not_approved').style.display = 'block';
		document.getElementById('approved').style.display = 'none';
	}
};

var activetab = 1;
function slide(clicked) {
	var next = parseInt(clicked);
	$('#carousel_lower .carousel .carousel_wrap').animate({left:-900*(parseInt(clicked)-1)});
		if(activetab != next){
			$('#carousel_nav li.s'+next+' a').addClass('active');
			$('#carousel_nav li.s'+activetab+' a').removeClass('active');
			activetab = next;
		}
};

function ascend(clicked) {
	var next = parseInt(clicked);
	$('#carousel_upper .carousel .carousel_wrap').animate({top:-220*(parseInt(clicked)-1)});
};

function init(){
	var inp = document.getElementsByTagName('input');
	for(var i = 0; i < inp.length; i++) {
		if(inp[i].type == 'text') {
			inp[i].setAttribute('rel',inp[i].defaultValue)
			inp[i].setAttribute('color',inp[i].style.color)
			inp[i].onfocus = function() {
				if(this.value == this.getAttribute('rel')) {
					this.value = '';
					this.style.color = '#000000';
				} else {
					return false;
				}
			}
			inp[i].onblur = function() {
				if(this.value == '') {
					this.value = this.getAttribute('rel');
					this.style.color = this.getAttribute('color');
				} else {
					return false;
				}
			}
			inp[i].ondblclick = function() {
				this.value = this.getAttribute('rel')
			}
		}
	}
}
if(document.childNodes) {
	window.onload = init
};

var ajax = new Array();
var values = new Array();
function newsletter(instance) //live validation function
{	
	var ins = instance;
	var loader = document.getElementById('email_submit' + ins);
	loader.src = "images/ajax-loader.gif";
	var form = document.getElementById('email' + ins);
	var form_val = form.value;
	var ajax = new sack();
	ajax.element = 'result' + ins;
	ajax.requestFile = 'includes/sql.php?type=newsletter&val=' + form_val + '&ins=' + ins;
	ajax.onCompletion = loader.src = "images/send_button.gif";
	ajax.runAJAX();
	return false;
};

function unsubscribe(email,instance) //live validation function
{
	var email = email;
	var ins = instance;
	var ajax = new sack();
	ajax.element = 'result' + ins;
	ajax.requestFile = 'includes/sql.php?type=unsubscribe&val='+email;
	ajax.runAJAX();
	return false;
};

document.observe('dom:loaded', function(event){
  $$('a[href*="#"]').each(function(anchor){
	anchor.observe('click', function(event) {
	  var pageAnchor   = $$('a[name~="#{href}"]'.interpolate({href: this.href.split('#')[1]})).first();
	  var delta        = pageAnchor.offsetTop - document.viewport.getScrollOffsets().top;
	  var updateUrl    = function(){ location.href = this.href }.bind(this);

	  new Effect.Scroll(window, { y: delta, afterFinish: updateUrl, duration: 0.4 });
	  Event.stop(event);
	});
  });
});

