function fnEnterKey(buttonToClick, e) 

{ 
           var code;
            if (!e) var e = window.event;
            if (e.keyCode) code = e.keyCode;
            else if (e.which) code = e.which;
            if (code == 13) 
            { 
            e.cancelBubble = true; 
            e.returnValue = false; 
            //(document.getElementById(buttonToClick)).click(); 
	    submitSearch();
	    return false;
            } 
}

function submitSearch() {

	var dd = document.getElementById('ddsearch');
	var seltext = dd[dd.selectedIndex].text;
	var selval = dd[dd.selectedIndex].value;

	if ( selval =='#' || selval == '' ) {
		alert("Please choose a search topic.");
		return;
	}
	var frm = document.getElementById('frm_search');

	document.getElementById('keywords').value = document.getElementById('searchtext').value;
	document.getElementById('q').value = document.getElementById('searchtext').value;
	document.getElementById('se.category.kq').value = document.getElementById('searchtext').value;
        document.getElementById('qKeywords').value = document.getElementById('searchtext').value;

	var pos=-1, parg="";

//	if (seltext != 'All')
//	{
		pos = selval.lastIndexOf("p=");
		if ( pos > 0 ) {
			pstr = selval.substring( pos );
			pos = pstr.indexOf("&")
			if  ( pos < 0 )
				parg = pstr.substring(2)
			else
				parg = pstr.substring( 2, pos )
		}
		document.getElementById('p').value = parg;
		parg = "";
		pos = selval.lastIndexOf("search=");
		if ( pos > 0 ) {
			pstr = selval.substring( pos );
			pos = pstr.indexOf("&")
			if  ( pos < 0 )
				parg = pstr.substring(7)
			else
				parg = pstr.substring( 7, pos )
		}
		document.getElementById('search').value = parg;
//	}

	frm.action = selval;

	if ( dd[dd.selectedIndex].text == 'Homes' )
		frm.method='post';
		
	if ( dd[dd.selectedIndex].text == 'Jobs' )
		frm.method='post';
		
	if ( dd[dd.selectedIndex].text == 'Jobs' )	
		frm.action='http://hotjobs.yahoo.com/jobseeker/jobsearch/search_results.html?partner=wickedlocaljobs&keywords_all=' + document.getElementById('searchtext').value + '&ulm_input1=Boston%2C+MA&metro_area=1&industry1=&updated_since=sixtydays&basicsearch=1&country1=USA&search=Search&basicsearch.x=1&kw=' + document.getElementById('searchtext').value;

	frm.submit();

}

document.write('<form name="frm_search" id="frm_search" action="search.aspx" method="get">');
document.write('<input type="hidden" name="keywords" id="keywords" value="" />');
document.write('<input type="hidden" name="q" id="q" value="" />');
document.write('<input type="hidden" name="qKeywords" id="qKeywords" value="" />');
document.write('<input type="hidden" name="se.category.kq" id="se.category.kq" value="" />');
document.write('<input type="hidden" name="search" id="search" value="" />');
document.write('<input type="hidden" name="p" id="p" value="" />');
document.write('</form>');
document.write('<table cellpadding="0" cellspacing="0" border="0">');
document.write('<tr>');
document.write('<td width="4" rowspan="2"><img src="http://www.wickedlocal.com/images/realestate/clear.gif" width="1" height="1" border="0"></td>');
document.write('<td colspan="5" align="left" valign="middle"><img src="http://www.southofboston.net/searchbox/sbox_search.gif" border="0"></td>');
document.write('<td width="4" rowspan="2"><img src="http://www.wickedlocal.com/images/realestate/clear.gif" width="1" height="1" border="0"></td>');
document.write('</tr>');
document.write('<tr>');
document.write('<td><input name="searchtext" type="text" id="searchtext" size="15" onkeypress="return fnEnterKey(' + "'" + 'btn_searchgo' + "'" + ', event);" style="width:127px;/></td>');
document.write('<td><img src="http://www.wickedlocal.com/images/realestate/clear.gif" border="0" width="5"><img src="http://www.wickedlocal.com/images/realestate/clear.gif" width="4" height="1" border="0"><select name="ddsearch" id="ddsearch" style="width:111px;">');
document.write('<option value="#">Select One:</option>');
document.write('<option value="http://search.wickedlocal.com/sp?p=sb_news_search">News</option>');
document.write('<option value="http://hotjobs.yahoo.com/jobseeker/jobsearch/search_results.html?partner=wickedlocaljobs&keywords_all=sales&ulm_input1=Boston%2C+MA&metro_area=1&industry1=&updated_since=sixtydays&basicsearch=1&country1=USA&search=Search&basicsearch.x=1&kw=">Jobs</option>');
document.write('<option value="http://realestate.wickedlocal.com/properties/search/results.php?qAction=search&amp;page=1&amp;pagesize=25&amp;view=1&amp;qTerms=sell&amp;qCity=&amp;qState=&amp;qZip=&amp;qRadius=&amp;propertyType%5B0%5D=Houses+For+Sale&amp;propertyType%5B1%5D=Condos&amp;propertyType%5B2%5D=Cape+Cod+Real+Estate&amp;propertyType%5B3%5D=Commercial&amp;propertyType%5B4%5D=Investment&amp;propertyType%5B5%5D=Out+of+State+Property&amp;propertyType%5B6%5D=Vacation+Property&amp;propertyType%5B7%5D=Land&amp;propertyType%5B8%5D=Active+Adult+Communities&amp;propertyType%5B9%5D=Mobile+Homes&amp;propertyType%5B10%5D=Real+Estate+Services&amp;qMinPrice=&amp;qMaxPrice=&amp;qBedrooms=&amp;qBathrooms=&amp;qSqft=&amp;qMinLotSize=&amp;qLotSizeUnits=&amp;qSortBy=Price">Homes</option>');
document.write('<option value="http://ledger.admin.planetdiscover.com/sp?p=sb_cars_search">Wheels</option>');
document.write('<option value="http://search.wickedlocal.com/sp?p=sb_merchandise_search&amp;search=classifieds">Shopping</option>');
document.write('<option value="http://ledger.admin.planetdiscover.com/sp?p=sb_business_search">Businesses</option>');
document.write('</select>');
document.write('</td>');
document.write('<td><a href="javascript:submitSearch();"><img src="http://www.southofboston.net/searchbox/sbox_go.gif" border="0" style="margin-left:5px;"></a></td>');
document.write('</tr>');
document.write('<tr>');
document.write('<td height="4" colspan="3"><img src="http://www.wickedlocal.com/images/realestate/clear.gif" width="1" height="1" border="0"></td>');
document.write('');
document.write('</tr>');
document.write('</table>');
