// JavaScript Document

function toggleMyLocation() {
	mypdx = document.getElementById('myLocPop');
	if(mypdx.style.display == 'block')
		mypdx.style.display = 'none';
	else
		mypdx.style.display = 'block';
	//mypdx.style.zIndex = 10;

}

function hideMyLocation() {
	mypdx = document.getElementById('myLocPop');
	mypdx.style.display = 'none';
	//mypdx.style.zIndex = -1;
}

function focusMiniSearch() {
	theinput = document.getElementById('cityOrZip');
	if(theinput.value == 'City & ST, or ZIP')
		theinput.value = '';
		
	theinput.className = 'cityOrZipAfterFocus';
}

function formatPhone(phoneNum) {
	phoneNum += '';
    if(phoneNum.length != 10) return(phoneNum);//give it back just like it came
    sArea = phoneNum.substr(0,3);
   	sPrefix = phoneNum.substr(3,3);
    sNumber = phoneNum.substr(6,4);
   	phoneNum = "("+sArea+") "+sPrefix +"-"+sNumber; 
	return phoneNum;
}



function checkLocation(theBrand) {
   // Set the optional parameter if needed
   if ( theBrand === undefined ) { theBrand = 'all'; }
	
	//alert(theBrand);
	
	theCity = document.getElementById('city').value;
	theState = document.getElementById('state').value;
	theZip = document.getElementById('zipcode').value;
	
	if(theZip != '') {
		$.post("../finder/checkLoc.php", { zipcode: theZip, findBrand: theBrand }, function(data){ processLocResult(data); }, "text");
	} else if(theCity != '') {
		$.post("../finder/checkLoc.php", { city: theCity, state: theState, findBrand: theBrand }, function(data){ processLocResult(data); }, "text");
	} else {
		locPop('Error', 'Please provide a location.');
		return;
	}
}

function checkLocationFind(findvalue, theBrand) {
   // Set the optional parameter if needed
   if ( theBrand === undefined ) { theBrand = 'all'; }
   
	//alert(theBrand);
	
	theCity = document.getElementById('city').value;
	theState = document.getElementById('state').value;
	theZip = document.getElementById('zipcode').value;
	
	if(theZip != '') {
		$.post("../finder/checkLoc.php", { zipcode: theZip }, function(data){ processLocResult(data); }, "text");
	} else if(theCity != '') {
		$.post("../finder/checkLoc.php", { city: theCity, state: theState, lookfor: findvalue, findBrand: theBrand }, function(data){ processLocResult(data); }, "text");
	} else {
		locPop('', 'We did not receive any information in the form. Please check your entry and try again.<br><br><strong>Enter your city, state or ZIP to find a location near you!</strong>');
		return;
	}
}

/*
function checkLocationJobs() {
	theCity = document.getElementById('city').value;
	theState = document.getElementById('state').value;
	theZip = document.getElementById('zipcode').value;
	
	if(theZip != '') {
		$.post("../finder/checkLoc.php", { zipcode: theZip, jobs: 'true' }, function(data){ processLocResult(data); }, "text");
	} else if(theCity != '' && theState != '') {
		$.post("../finder/checkLoc.php", { city: theCity, state: theState, jobs: 'true' }, function(data){ processLocResult(data); }, "text");
	} else {
		locPop('Error', 'Please provide a location.');
		return;
	}
}
*/

function checkLocationMini() {
	theCityOrZip = document.getElementById('cityOrZip').value;
	
	if(theCityOrZip != '' && theCityOrZip != 'City & ST, or ZIP') {
		$.post("../finder/checkLoc.php", { cityOrZip: theCityOrZip, findBrand: 'all' }, function(data){ processLocResult(data); }, "text");
	} else {
		locPop('', 'We did not receive any information in the form. Please check your entry and try again.<br><br><strong>Enter your city, state or ZIP to find a location near you!</strong>');
		return;
	}
}


function processLocResult(theLocCount) {
	//alert(theLocCount);
	if(theLocCount == 0 || theLocCount == '') {
		locPop('Sorry!', 'We\'re sorry. There are no Pappas brand restaurants in the provided area.');
		return;
	} else if(theLocCount >= 1) {
		//locations were found, we need to redirect...
		window.location="../locations/";
	} else {
		//checkLoc.php returned something other than a number or empty, through unknown error message	
		locPop('Error', 'There was an unknown problem with your submission. Please check your location and try again.');
		return;
	}
}

/**********************************************************
      POP MESSAGE FUNCTIONS
*/

function locPop(msgHdr, theMsg) {
	document.getElementById('locMsgHdr').innerHTML = msgHdr;
	if(msgHdr == '')
		document.getElementById('locMsgHdr').style.display = 'none';
	else
		document.getElementById('locMsgHdr').style.display = 'block';
	document.getElementById('theLocMsg').innerHTML = theMsg;
	
	$('#locPop').jqmShow();
}

function closeLocMsg() {
	$('#locPop').jqmHide();
}

function closeFlashMsg() {
	$('#flashPop').jqmHide();
}
