
String.prototype.contains = function(t) { return this.indexOf(t) >= 0 ? true : false }
var $E = YAHOO.util.Event;
var $D = YAHOO.util.Dom;
var $A = YAHOO.util.Anim;

//function for submitting a field on hitting enter
//also used for triggering a input field update on event firing
function submitenter(forminputfield, e, fontsRenderSize, searchTerm)
{
	//http://www.htmlcodetutorial.com/forms/index_famsupp_157.html
	var keycode;
	if (window.event) keycode = window.event.keyCode;
		else if (e) keycode = e.which;
		else return true;

	if (keycode == 13){ // 13 = Enter
	   if (fontsRenderSize) {
	   		refreshAllImagesOnList(fontsRenderSize, 'true');
	   }
	   if (searchTerm!="") {
	   		forminputfield.form.submit();
	   }
	   return false;
	   }
	else
	   return true;
}

//function to update a input field and resetting the class
function fillInSearchTerm(inputId, searchTerm) {
	var ourInput = document.getElementById(inputId);
	if (ourInput!=null) {
		(searchTerm);
		ourInput.value = searchTerm;
		ourInput.setAttribute("class", "");
	}
	if (inputId == "font.qsearch.keyword") {
		//also update hidden input for search input field
		var ourSearchTermInput = document.getElementById("searchTerm");
		if (searchTerm == null || searchTerm == "") {
			searchTerm = "#fsm('font.qsearch.first.value')";
		}
		ourSearchTermInput.value = searchTerm;
	}
}
//function for calculating the window width
function getWindowWidth() {
		var pageWidth;
		if (self.innerHeight) {	// Awesome Browsers
			pageWidth = self.innerWidth;
		} else if (document.documentElement && document.documentElement.clientHeight) { 
			// Exploder 6 Strict Mode
			pageWidth = document.documentElement.clientWidth;
		} else if (document.body) { // Other Exploders Versions
			pageWidth = document.body.clientWidth;
		}
		return pageWidth;	
}
//function for calculating the window height
function getWindowHeight() {
	var pageHeight;
	if (self.innerHeight) {	// Awesome Browsers
		pageHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { 
		// Exploder 6 Strict Mode
		pageHeight = document.documentElement.clientHeight;
	} else if (document.body) { // Other Exploders Versions
		pageHeight = document.body.clientHeight;
	}
	return pageHeight;
}

function checkInput(el){
	var val = el.value.replace(/[^\.^,\d]/g, '');
	el.value = val;
	if(val == 0 && val != ""){
		el.value = 1;
	}	
}
/**
 * Runs javascript escape() function but replaces plus signs as well
 * 
 */
function escapePlus(txt){
	if(txt === "" || txt == null) return txt;
	var retVal = "";
	var parts = txt.split("+");
	if(parts.length <= 1) {
		return escape(txt);
	}
	for(var i = 0; i <parts.length; i++ ){
		parts[i] = escape(parts[i]);
	}
	return parts.join("%2B");
}

function updateNewSearchLink(kind) {
	//alert("test");
	var newSearchLink = document.getElementById("linkToSearch");
	if (null != newSearchLink) {
		if (kind == 1) {
			newSearchLink.setAttribute("onclick", "retrieveCheckKeywordsAndSubmit('compact');");	
		} else {
			newSearchLink.setAttribute("onclick", "retrieveCheckKeywordsAndSubmit('extended');");
		}
	}
}

function check4ReturnedError(divId) {
	var ourDiv = document.getElementById(divId);
	if (null != ourDiv) {
		if (ourDiv.getAttribute("class").contains("error")) {
			return true;
		}
	}
	return false;
}

