// JavaScript Document
var currentCity = '#cities-1';
var currentButton = '#bt-hom';
function showCities(el) {
	hideCities(currentCity);
	$(el).fadeIn(300);
	//$('#content ul.cats li').css('z-index','0');
	currentCity = el;
}
function hideCities(el) {
	$(el).fadeOut(300);
}
function toggleButton(el) {
		$(currentButton).removeClass('current');
		currentButton = el;
		$(currentButton).addClass('current');
}
function checkDistance(el,allowed,actual) {
	if (allowed < actual) $(el).hide();
}
function changeSearch(searchType) {
	/*var action;
	var method = 'post';
	var target = '_self';
	var yellow = '<div id="search-labels"><div id="searchlabel-for">Search For: <span class="small-text">(e.g. broadband, food, car, etc.)</span></div><div id="searchlabel-where">Search Where: <span class="small-text">(e.g. state, city, zip, etc.)</span></div><div id="searchlabel-within">Within:</div></div><form method="get" action="/search" id="searchform"><div id="search-form"><input type="hidden" name="section" value="yellow" /><input name="for" id="for" class="search-textbox" type="text" value="" /><input name="location" id="location" class="search-textbox1" type="text" value="" /></div><div id="search-button-area"><input name="Btn" class="search-button" type="submit" value="Search" id="submit" /></div></form>';
	var white = '<div id="search-labels"><div id="searchlabel-fname">First Name: <span class="small-text">(Or business name)</span></div><div id="searchlabel-lname">Last Name: </div><div id="searchlabel-city">City: </div><div id="searchlabel-state">State: </div></div><form method="post" action="/search/white" id="searchform"><div id="search-form"><input name="fname" class="search-textbox2" type="text" value="" /><input name="lname" class="search-textbox2a" type="text" value="" /><input name="city" class="search-textbox3" type="text" value="" /><input name="tstate" class="search-textbox4" type="text" value="" /></div><div id="search-button-area"><input name="submit" class="search-button" type="submit" value="Search" id="submit" /></div></form>';
	var google = '<div id="search-labels"><div id="searchlabel-q">Enter Search Terms: </div></div><form method="get" action="http://www.google.com/search" id="searchform" target="_blank"><div id="search-form"><input name="q" class="search-textbox5" type="text" value="" /></div><div id="search-button-area"><input name="submit" class="search-button" type="submit" value="Search" id="submit" /></div></form>';*/
	switch (searchType) {
		case 'y': 
			toggleButton('#bt-yel');
			$('#search-white').hide();
			$('#search-google').hide();
			$('#search-yellow').show();
			//$("#search").html(yellow);
			//action = "/search"; 
			break;
		case 'w': 
			$('#search-google').hide();
			$('#search-yellow').hide();
			$('#search-white').show();
			toggleButton('#bt-whi');
			//$("#search").html(white);
			break;
		case 'g': 
			$('#search-yellow').hide();
			$('#search-white').hide();
			$('#search-google').show();
			toggleButton('#bt-goo');
			//$("#search").html(google);
			break;
		default: action = "/search/keywords/"; break;
	}
	
}
function showAds(adToShow) {
	$('#ads img').hide();
	$('#ads img#' + adToShow).show();
}
function doLinks(theLink) {
	$('#ads a').removeClass('current-ad');
	$('#ads a#' + theLink).addClass('current-ad');
}

function openMobile() {
	$('#theCats #getMobile').show();
}
function closeMobile() {
	$('#theCats #getMobile').hide();
}
function checkMobile() {
	var email = document.getElementById('email').value;
	var phone = document.getElementById('phone').value;
	var errors = '';
	
	if (email == '') {
		errors += ' * Please enter your Email address to confirm opting-in to receive a text message from us.\n';
	}
	if (phone == '') {
		errors += ' * Please enter your mobile phone number.\n';
	}
	if (email != '' && !checkMail(email)) {
		errors += ' * Please enter a valid Email address.\n';
	}
	if (phone != '' && !checkPhone(phone)) {
		errors += ' * Please enter your mobile number as 10 digits, no spaces or punctuation.\n';
	}
	
	if (errors != '') {
		alert('Please correct the following:\n' + errors);
		return false;
	}
	else return true;
}
function checkMail(email){
    var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	if (filter.test(email)) {
    	return true;
  	}
    return false;
}
function checkPhone(email){
    var filter = /^\d{10}$/;
	if (filter.test(email)) {
    	return true;
  	}
    return false;
}
