//variable "SEARCH_HINT" will be define inline in the <head> tag
function checkHomeValueFocus(id){
	if(id.value==SEARCH_HINT){
		id.className='search_input search_home focus';
		id.value='';
	}
}

//variable "SEARCH_HINT" will be define inline in the <head> tag
function checkValueFocus(id){
	if(id.value==SEARCH_HINT){
		id.className='search_input focus';
		id.value='';
	}
}

//variable "SEARCH_HINT" will be define inline in the <head> tag
function checkHomeValueBlur(id){
	if(id.value==''){
		id.value=SEARCH_HINT;
		id.className='search_input search_home blur';
	}
	if(id.value==SEARCH_HINT){
		id.className='search_input search_home blur';
	}
}

//variable "SEARCH_HINT" will be define inline in the <head> tag
function checkValueBlur(id){
	if(id.value==''){
		id.value=SEARCH_HINT;
		id.className='search_input blur';
	}
	if(id.value==SEARCH_HINT){
		id.className='search_input blur';
	}
}

function smutEngine(value) {

	var cmp = String.fromCharCode(115,101,120,32,98,97,98,101,115,32,115,104,105,116,32,102,117,99,107,32,
			100,97,109,110,32,112,111,114,110,111,32,99,117,110,116,32,97,115,115,104,111,108,101,32,112,101,100,111,112,104,
			105,108,101,32,109,97,110,45,98,111,121,32,109,97,110,47,98,111,121,32,116,
			119,97,116,32,23628,32,25805,20320,32,36068,20154,32,19981,35201,33225,32,24178,27515,20320,32,
			26085,27515,20320,32,24178,20320,32,26085,20320,32,23014,32,38512,33686,32,38512,36947,32,38525,
			20855,32,25105,25805,32,20182,23229,30340,32,29399,26085,32,25105,26085,32,39135,23630,32,39154,
			23615,32,20320,23229,32,20320,22823,29242,32,20166,34903,32,23628,32,25805,20320,32,36145,20154,32,
			19981,35201,33080,32,24178,27515,20320,32,26085,27515,20320,32,24178,20320,32,26085,20320,32,22904,
			32,38452,33550,32,38452,36947,32,38451,20855,32,25105,25805,32,20182,22920,30340,32,29399,26085,32,
			25105,26085,32,39135,23630,32,39278,23615,32,20320,22920,32,20320,22823,29239,32,20166,34903);

	//specail character string including space
	re = /\$|,|@|#|~|`|\s|\t|\%|\*|\^|\&|\(|\)|\+|\=|\[|\-|\_|\]|\[|\}|\{|\;|\:|\'|\"|\<|\>|\?|\||\\|\!|\$|\./g;
	
	txt=value;
	lowercase_txt = txt.toLowerCase();
	pure_txt = lowercase_txt.replace(re, "");
	tstx="";
	
	var arr = cmp.split(" ");
	
	for (var i=0; i<arr.length; i++){
		if (pure_txt.indexOf(arr[i])>-1){
			return true;
	   }
	}

	return false;
}

function encodeSpecialChar(input){
	//retainChar is the special charater that needs to be search
	//filterChar is characters need to ignore
	retainChar = /(\'|\&)/g;
	filterChar = /\%|\||\\|\/|\)|\(|\*|\^|\$|\#|\@|\!|\~|\=|\[|\]|\{|\}|\"|\:|\;|\?|\>|\<|\.|\+|\-|\_|\,/g;
	
	input1 = input.replace(filterChar, ' ');
	
	//filter keywords
	var keyWords = ["or", "and", "of", "ltd", "in", "not", "is", "a", "an", "the", "that"];
	input1 = filterkeyWords(input1, keyWords);
	
	input1 = input1.replace(/\s+/g, ' ');
	
	input2 = encodeURI(input1);
	
	//inline function for doing escape special character to the matching terms
	//encode the ignored character to the encodeURI function
	function encodeChar(match){
		return escape(match);
	}
	input3 = input2.replace(retainChar, encodeChar);
	
	input3 = encodeURI(input3);
	
	return input3;
}

function filterkeyWords(str, keyWords) {
	for (var i=0; i<keyWords.length; i++) {
		var keyWord = keyWords[i];
		str = str.replace(eval('/(.*?) ' + keyWord + ' (.*?)/gi'), '$1 $2');
		str = str.replace(eval('/^' + keyWord + ' (.*?)/i'), '$1 ');
		str = str.replace(eval('/(.*?) ' + keyWord + '$/i'), '$1 ');
		str = str.replace(eval('/^' + keyWord + '$/i'), ' ');
	}
	
	return str;
}

function checkKeywords(form){
	var input = form.keywords.value;
	var url;
	if(input != null && input != '' && input != SEARCH_HINT){
		if(!smutEngine(input)){
			url = form.action.split('search')[0] + "search/keywords:" + encodeSpecialChar(input);
			window.location.replace(url);
		}else
			alert(SMUT_KEYWORD);
	}else
		alert(NULL_KEYWORD);
	return false;
}

function mobileCheckKeywords(form){
	var input = form.keywords.value;
	if(input != null && input != ''){
		if(!smutEngine(input))
			return true;
		else
			alert(SMUT_KEYWORD);
	}else
		alert(NULL_KEYWORD);
	return false;
}