/* Reusable form sniffing stuff */
function qs( D ) { 	/* Return qsrc value on given document.form object (D) */
	var qsrc = (D.qsrc) ? D.qsrc.value : "";
	return qsrc;
}

function og( D ) { /* Return o parameter on given document.form object (D) */
	var o = (D.o) ? D.o.value : "";
	return o;
}
function qu( D ) { /* Return q parameter (user's value from input box) on given document.form object (D) */
	var q = (D.q) ? D.q.value : "";
	return q;
}

function appendQ(strDest, barID, el) {
	var D = document[barID]; 	/*form object*/
	var qsrc = qs(D); 	/* Find qsrc on form */
	var o = og(D);		/* Find o parameter on form*/
	var q = qu(D);		/* Find user's value from input box on form*/
	
	if(q) {
		q = escape(q);
		/* Piece together the query */
		var query = "q=" + q;
		var href = "";
		/* Pricegrabber is special as the url with no query is http://products.ask.com, but
		   if there is a query it's http://ask2.pricegrabber.com/....*/
		if(strDest == 3) {
			var productURL = "http://ask2.pricegrabber.com/search_gen_top.php?topcat_search=1&form_keyword="+q+"&qsrc="+qsrc+"&o="+o;
			el.href = el.href.replace(/http:\/\/Products.ask.com\//i, productURL); /* special url for pricegrabber */
		}
		else {
			var channel = "web?";
			if(strDest == 1) { channel = "pictures?"; }
			if(strDest == 2) { channel = "news?"; }
			if(strDest == 4) { channel = "local?"; }
			if (strDest == 5) //KIDS
			{
				query = "&ask=" + q;
				channel = "";
				o ="";//origin is already in base href
			}
			if (strDest == 6) //JEEVESIQ
			{
				query = "&" + query;
				channel = "";
				o ="";//origin is already in base href
			}

			href = channel + query ;
			if (o)	href += '&o=' + o;	//this may be elsewhere in URL, so don't append if not set here
			href += '&qsrc=' + qsrc;
			
			//NEWS handling
			if((strDest == 2)&&(q != ""))
			{
				href += '&news=true';
			}

			el.href += href;
		}
	} else {
		return true;
	}
}

function appendJPQ(barID, action) {
	var f = document[barID];
	f.action = action;
	f.submit();
}