// common javascrit


// On Load
$(document).ready(function(){


	$("#ListingAjax").autocomplete(
		"listing_ajax.php",
		{
			delay:10,
			minChars:3,
			matchSubset:1,
			/*matchContains:1,
			cacheLength:10,
			autoFill:true,*/
			onItemSelect:selectItem,
			//onFindValue:findValue,
			formatItem:formatItem			
		}
	);
	
	
	$("#CategoryAjax").autocomplete(
		"category_ajax.php",
		{
			delay:10,
			minChars:3,
			matchSubset:1,
			/*matchContains:1,
			cacheLength:10,
			autoFill:true,*/
			onItemSelect:selectItem,
			//onFindValue:findValue,
			formatItem:formatItem			
		}
	);
	
	$("#PlaceAjax").autocomplete(
		"place_ajax.php",
		{
			delay:10,
			minChars:3,
			matchSubset:10,
			onItemSelect:selectItem,
			formatItem:formatItem			
		}
	);
	
});


function findValue(li) {
	//if( li == null ) return alert("No match!");

	// if coming from an AJAX call, let's use the CityId as the value
	//if( !!li.extra ) var sValue = li.extra[0];

	// otherwise, let's just display the value in the text box
	//else var sValue = li.selectValue;
	
	var sValue = li.selectValue;

	//alert("The value you selected was: " + sValue);
}

function selectItem(li) 
{
	findValue(li);
}

function formatItem(row) 
{
	return row[0];
}

function lookupAjax(id)
{
	var oSuggest = $("#"+id)[0].autocompleter;
	oSuggest.findValue();
	return false;
}

function call_js(){
	
	if(document.getElementById('location').value!='') { 
	 document.locationsearc.submit(); return true; 
	
	}
}

function CheckEmail(email)
{
	if(email.search(/^[a-zA-Z0-9_\.]+\@{1}[a-zA-Z0-9\-]+\.{1}[a-zA-Z\.]+$/) ==-1)
	{
		return false;
	}
	else
	{
		return true;
	}
}

function showLoginAlert()
{
	
	$("#loginalert").show();
}

function hideLoginAlert()
{
	$("#loginalert").hide();
}


function showVotedAlert()
{
	$("#votedAlert").show();
}

function hideVotedAlert()
{
	$("#votedAlert").hide();
}

function setCookie(szName, szValue, szExpires, szPath, szDomain, bSecure)
{
 	var szCookieText = 	   escape(szName) + '=' + escape(szValue);
	if(typeof(szExpires) == 'undefined')
	{
		 var today = new Date();
  		 szExpires = new Date(today.getYear(), today.getMonth(), today.getDate()+1);		
	}
	szCookieText +=	 	   (szExpires ? '; EXPIRES=' + szExpires.toGMTString() : '');
	
	if(typeof(szPath) != 'undefined')
	{
		szCookieText += 	   (szPath ? '; PATH=' + szPath : '');
	}
	if(typeof(szDomain) != 'undefined')
	{
		szCookieText += 	 (szDomain ? '; DOMAIN=' + szDomain : '');
	}
	if(typeof(bSecure) != 'undefined')
	{
		szCookieText += 	  (bSecure ? '; SECURE' : '');
	}
	
	document.cookie = szCookieText;
}

function getCookie(szName)
{
 	var szValue =	  null;
	if(document.cookie)	   //only if exists
	{
       	var arr = 		  document.cookie.split((escape(szName) + '=')); 
       	if(2 <= arr.length)
       	{
           	var arr2 = 	   arr[1].split(';');
       		szValue  = 	   unescape(arr2[0]);
       	}
	}
	return szValue;
}

function deleteCookie(szName)
{
 	var tmp = 	  			 	 getCookie(szName);
	if(tmp) 
	{ setCookie(szName,tmp,(new Date(1))); }
}






