$(document).ready(function() {

	$("#nowSearchBtn").click(function() {
		
		$("#searchform").attr("action","http://www.newsoftheworld.co.uk/sitesearch.do");
		$("#masthead_query").css({'background-image':""});

		setFormValue("view", "internal");

	});

	$("#gglSearchBtn").click(function() {

		$("#searchform").attr("action","http://www.newsoftheworld.co.uk/googleSearch.do");
		$("#masthead_query").css({'background-image':"url('images/poweredByGoogle.jpg')"});

		setFormValue("pageNum", "1");
		setFormValue("resultsPerPage", "10");
		setFormValue("searchmode", "adsandresults");
		setFormValue("similarlink", "false");
		setFormValue("pubName", "notw");
		setFormValue("internationalSearch", "false");
	});

});

function setFormValue(name, value) {

	var form = document.getElementById("searchform");
	var input = document.createElement("input");
	input.setAttribute("type", "hidden");
	input.setAttribute("name", name);
	input.setAttribute("value", value);
	form.appendChild(input);
}

function clearImg() {
	
	$("#masthead_query").css({'background-image':""});
}

// removed from search-header.jsp

function trimString (str) {
  str = this != window? this : str;
  return str.replace(/^\s+/g, '').replace(/\s+$/g, '');
}

function showValMain(qry){
	var sLength = qry; //this would be ur text box value
	sLength = trimString(sLength);
	
	if(sLength.length < 1 ){
		alert('Please enter a term to search for')
		return false;
	}

	sLength = checkString(sLength);
	if(sLength != 0) {
		alert('Please enter a valid search term');
		return false;
	}
	//else{
	//	webSearchSubmit(sSelectedAdvSearchTab);
	//	return false;
	//	}
}

function checkString(searchFname){
	var myChar = new Array();
	var totArrLength = 0;
	var isValid
	var isThereValue = 1;
	
	for(i=0;i<26;i++){
		myChar[totArrLength] = String.fromCharCode(65+i);
		totArrLength = totArrLength+1;
		}
	for(i=0;i<26;i++){
		myChar[totArrLength] = String.fromCharCode(97+i);
		totArrLength = totArrLength+1;
		}
	for(i=0;i<10;i++){
		myChar[totArrLength] = String.fromCharCode(48+i);
		totArrLength = totArrLength+1;
		}
	for(i=0;i<myChar.length;i++){
			isValid = searchFname.indexOf(myChar[i]);
			if(isValid != -1){
				isThereValue = 0;
			}
	}
	
	return isThereValue;
}