// clear form fields
function clearDefault(el) {
	var defaultValue = "";
	if (defaultValue == el.value) {
		el.value = "";
	}
}

function checkEnter(e, caller) //e is event object passed from function invocation
{

	var characterCode //literal character code will be stored in this variable

	if (e && e.which || e.which == 0) { //if which property of event object is supported (NN4)

		e = e
		characterCode = e.which //character code is contained in NN4's which property
	}
	else {
		e = event
		characterCode = e.keyCode //character code is contained in IE's keyCode property
	}

	if (characterCode == 13)//if generated character code is equal to ascii 13 (if enter key)
	{
		if (document.all) {
			e.returnValue = false;
			e.cancel = true;
		}
		else {
			e.preventDefault();
		}
		var obj = document.getElementById(caller);
		if (obj) {

			if (obj.click) {
				obj.click();
			}
		}
		return false
	}
	else {
		return true
	}

}

// the institutions have their domains... is not more necessary for others builds of the url
function quickSearch(query) {

	var query = encodeURIComponent(query);

	if (query != '') {
		location.href = '/Search.aspx?q=' + query;
	}
}

function validateSpecialCharsProducts(strToSearch) {
	var illegalChars = '0123456789';
	for (var i = 0; i < strToSearch.length; i++) {
		if (illegalChars.indexOf(strToSearch.charAt(i)) == -1) {
			return false;
		}
	}
	return true;
}

function doSearch() {

	var q = '?q=';
	var qBox = document.getElementById('searchText1');
	var newlocation = '';

	curQuery = ClearString(qBox.value);

	if (curQuery.length == 9 && validateSpecialCharsProducts(curQuery)) {
		newlocation = curQuery;
	}
	else {
		newlocation = qBox.value;
	}

	if (qBox != null) {
		q += encodeURI(newlocation);
	}

	location.href = '/Search.aspx' + q;

	return;
}

function checkAll(field) {
	for (i = 0; i < field.length; i++)
		if (field[i].checked == true) {
	}
}

function getNumForPage(newnum) {
	var url = location.href;
	var num_value = "";
	var start_value = "";

	var querystring = url.split("?")[1];

	qss = querystring.split("&");
	for (i = 0; i < qss.length; i++) {
		qs = qss[i].split("=");
		if (qs[0] == "num") {
			num_value = qs[1];
		}
		if (qs[0] == "start") {
			start_value = qs[1];
		}
	}

	if (num_value == "") {
		url = url + "&num=" + newnum;
	}
	else {
		url = url.replace("num=" + num_value, "num=" + newnum);
	}

	if (start_value == "") {
		url = url + "&start=" + 0;
	}
	else {
		url = url.replace("start=" + start_value, "start=0");
	}

	location.href = url;
}

function SubmitBasket(txtIDs) {
	var elHiddenBasket = document.getElementById("hidBasket");

	var txtid;
	var valueProducts = "";

	var ids = txtIDs.substring(1).split("|");
	for (i = 0; i < ids.length; i++) {
		txtid = document.getElementById(ids[i]);
		if (document.getElementById(ids[i]).value != "") {
			valueProducts += "|" + ids[i] + "=" + document.getElementById(ids[i]).value;
		}
	}
	elHiddenBasket.setAttribute("value", valueProducts.substring(1));
}

