 //######SEARCH TYPE BOX ON/OFF##########
function showdiv_searchType(pValue, pSelect)
{
    if(document.getElementById(pValue).style.display == 'none') {
        document.getElementById(pValue).style.display = 'block';
        document.getElementById(pSelect).className = 'select';
    } else {
        document.getElementById(pValue).style.display = 'none';
        document.getElementById(pSelect).className = '';
    }
}

//######SEARCH TYPE SELECTION##########
    function select_search_type(strType,strValue)
    {
        if(strType == 'SearchType7') {
            document.getElementById('normal_form').style.display = 'none';
            document.getElementById('custom_search_form').style.display = 'block';

    		document.getElementById('searchType').style.display = 'none';
    		document.getElementById('searchSelect').className  = '';

            document.getElementById('txtSearch').value = document.getElementById('q').value
            if(document.getElementById('txtSearch').value != "Search for Restaurants, Recipes, Blogs, ?, Brands, i.e. Sushi Restaurants or Chicken Recipes") {
                document.getElementById('txtSearch').className = 'text1';
            }
        } else {
            document.getElementById('custom_search_form').style.display = 'none';
            document.getElementById('normal_form').style.display = 'block';

            document.getElementById('q').value = document.getElementById('txtSearch').value
            if(document.getElementById('q').value != "Search for Restaurants, Recipes, Blogs, ?, Brands, i.e. Sushi Restaurants or Chicken Recipes") {
                document.getElementById('q').className = 'text1';
            }

            var strGenType = "SearchType";
            for(var i=1; i<=7; i++){
                var strSearchType = strGenType + i;
                document.getElementById(strSearchType).className = '';
            }

            document.getElementById(strType).className = 'current';
            document.getElementById('searchTypeShow').innerHTML = strValue;
            document.getElementById('searchType_custom').style.display = 'none';
            document.getElementById('searchSelect_custom').className = '';

            var cseId = new Array();
            cseId['SearchType1'] = '014242458819962724843:1meczakhb34';
            cseId['SearchType2'] = '014242458819962724843:broqee2jjeu';
            cseId['SearchType3'] = '014242458819962724843:jnmnsdfihuk';
            cseId['SearchType4'] = '014242458819962724843:r2nz8qs6l-i';
            cseId['SearchType5'] = '014242458819962724843:qpsnh0dtevo';
            cseId['SearchType6'] = '014242458819962724843:qh92a78bueg';

            document.getElementById('cx').value = cseId[strType];
        }

        document.getElementById('rstrType').value = strType;
        document.getElementById('rstrValue').value = strValue;
    }



function textbox_change(txtBox){
    document.getElementById(txtBox).value= '';
    document.getElementById(txtBox).className = 'text1';
}

//######SEARCH CLICK VALIDATION AND URL SPECIFICATION#########
function search_box_check()
{
    if((document.frmSearch.txtSearch.value == "") || (document.frmSearch.txtSearch.value == "Search for Restaurants, Recipes, Blogs, ?, Brands, i.e. Sushi Restaurants or Chicken Recipes")) {
        alert("please enter your searching criteria");
        document.frmSearch.txtSearch.focus();
        return false;
    } else {
        var v_txtSearch=removeSpaces(trim(ltrim(rtrim(document.frmSearch.txtSearch.value))));
        //var v_txtLocation=removeSpaces(trim(ltrim(rtrim(document.frmSearch.txtLocation.value))));
        var v_txtLocation=trim(ltrim(rtrim(document.frmSearch.txtLocation.value)));

        if(document.getElementById('searchTypeShow').innerHTML == 'Restaurants'){
            document.frmSearch.action='http://friendseat.com/search/'+v_txtSearch+'_restaurants_in_'+v_txtLocation;
            //document.frmSearch.action='search/'+v_txtSearch+'_restaurants_in_ny';
        } else if(document.getElementById('searchTypeShow').innerHTML == 'Recipes'){
            document.frmSearch.action='http://friendseat.com/recipe_search/'+v_txtSearch;
        } else if(document.getElementById('searchTypeShow').innerHTML == 'Blogs'){
            document.frmSearch.action="http://friendseat.com/blog/search/"+v_txtSearch;
        } else if(document.getElementById('searchTypeShow').innerHTML == 'People'){
            document.frmSearch.txtBrowseFor.value = v_txtSearch;
            document.frmSearch.btnSubmit.value = v_txtSearch;
            document.frmSearch.action="http://friendseat.com/search/reviewer";
        } /*else if(document.getElementById('searchTypeShow').innerHTML == 'Q &amp; A'){
            document.frmSearch.txtForumSearch_top.value = v_txtSearch;
            document.frmSearch.action="foodietalk_search.php";
        }*/ else if(document.getElementById('searchTypeShow').innerHTML == 'Local'){
            document.frmSearch.action='http://friendseat.com/l/'+v_txtSearch+'_'+v_txtLocation;
            //document.frmSearch.action='l/'+v_txtSearch+'_ny';
        }
    }

}

	//#####GENERAL FUNCTIONS#######
	function removeSpaces(str) {
		re = /\$|@|#|~|`|\%|\*|\^|\&|\(|\)|\+|\=|\[|\-|\]|\[|\}|\{|\;|\:|\'|\"|\<|\>|\?|\||\\|\!|\$|\./g;
		plus = /\$|,|@|#|~|`|\%|\*|\^|\&|\(|\)|\+|\=|\[|\-|\_|\]|\[|\}|\{|\;|\:|\'|\"|\<|\>|\?|\||\\|\!|\$|\./g;
			  // remove special characters like "$" and "," etc...
			  var actualValue= str.replace(re, "-");
			  var actualValue= actualValue.replace(plus, "+");
			  return actualValue=(actualValue.replace (/\s+/g, '-'))
	}

	function ltrim(stringToTrim) {
		return stringToTrim.replace(/^\s+/,"");
	}

	function rtrim(stringToTrim) {
		return stringToTrim.replace(/\s+$/,"");
	}

	function trim(s)
	{
	  while (s.substring(0,1) == ' ')
	  {
		s = s.substring(1,s.length);
	  }
	  while (s.substring(s.length-1,s.length) == ' ')
	  {
		s = s.substring(0,s.length-1);
	  }
		return s;
	 }
	function goto_signup()
	{
		document.location.href='signup';
	}
