function auto_tab(currentField, nextField, valueLen)
{
	if ($(currentField).value.length == valueLen)
	{
		$(nextField).focus();
	}
}

function validate_email(email)
{
   var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
   
   return reg.test(email);
}

function hideShow(el, opt, display)
{
	if (parseInt(opt) == 1)
	{
		$(el).style.display = display;
	}
	else
	{
		$(el).style.display = 'none';
	}
}

function show_hide(el, display)
{
	if ($(el).style.display == 'none')
	{
		$(el).style.display = display;
	}
	else
	{
		$(el).style.display = 'none';
	}
}

function validate_radio(form, el)
{
	var radio = form.el;
	var option = -1;
	
	for (i = radio.length-1; i > -1; i--)
	{
		if (radio[i].checked)
		{
			option = i; i = -1;
		}
	}
	if (option == -1) 
	{
		return false;
	}
	else
	{
		return true;
	}
}

function disable_all_form(formName)
{
	var theForm = document.formName;
	
   	for(i = 0; i < theForm.elements.length; i++)
	{
   		//theForm.elements[i].disabled = true;
		if(theForm.elements[i].type == "text" || theForm.elements[i].type == "textarea" || theForm.elements[i].type == "button")
		{
      		alertText += "Element Value: " + theForm.elements[i].value + "\n"
      	}
      	else if(theForm.elements[i].type == "checkbox")
		{
      		alertText += "Element Checked? " + theForm.elements[i].checked + "\n"
      	}
      	else if(theForm.elements[i].type == "select-one")
		{
      		alertText += "Selected Option's Text: " + theForm.elements[i].options[theForm.elements[i].selectedIndex].text + "\n"
      	}
		
		alert(alertText);
   	}
}

function zip_auto_fill(zipField, cityField, stateField, countyField)
{
	new Ajax.Request('includes/ajax/general.ajax.php',
					 {
					  	method:'get',
						parameters: {action: 'auto_fill', zip: $(zipField).value}, 
					  	onSuccess: function(transport){
							var response = transport.responseText.split('|');
							
							$(cityField).value = response[0];
							$(stateField).value = response[1];
					  	},
					  	onFailure: function(){  }
					 });
	
	if (countyField != '')
	{
		getCountyByZip($(zipField).value, countyField);
	}
}

function getCountyByZip(zip, countyField)
{
	$j.ajax({
		url: "includes/ajax/geodata.ajax.php", 
		data: {action: 'get_county', zip: zip},
		success: function(data){
			if (data != '')
			{
				$j('#'+countyField).val(data);
			}
		}
	});
}

function is_weekend(dt)
{
	var date_obj = new Date(dt);
			
	var day = date_obj.getDay();
	
	if (day == 0 || day == 6)
	{
		return true;
	}
	
	return false;
}

function isArray(obj) 
{
   if (obj.constructor.toString().indexOf("Array") == -1)
      return false;
   else
      return true;
}

function form_helpers(elArray)
{
	if(isArray(elArray))
	{
		var arLen=elArray.length;
		for ( var i=0, len=arLen; i<len; ++i )
		{	
			$j('#'+elArray[i]['id']).qtip({							   
				content: elArray[i]['text'],
				show: 'focus',
				hide: 'blur',
				position: {
					corner: {
						target: 'rightMiddle',
						tooltip: 'leftMiddle'
					}, 
					target: (elArray[i]['target'] ? (elArray[i]['target'] == '' ? false : $j('#'+elArray[i]['target'])) : false)
				},
				style: {
					border: {
						width: 5,
						radius: 10
					},
					padding: 10,
					textAlign: 'center',
					tip: true, 
					name: 'blue' 
				}
			});	
		}
	}
}
