/*** UTILS ***/
function Utils() {}

Utils.isSubmitForm = function(e, form) {
	var keyNum;
	
	if(window.event) // IE
		{
			keyNum = e.keyCode;
		}
	else if(e.which) // Netscape/Firefox/Opera
		{
			keyNum = e.which;
		}
	if(keyNum==13) form.submit();
}

Utils.displayRows = function(obj, rowNameValue) {
	var elems=document.getElementsByTagName('tr'),rows=[];
	for(var i=0;i<elems.length;i++){// IE solution
		att = elems[i].getAttribute('name');
		if(att == 'captionRow'+rowNameValue) {
			rows.push(elems[i]);
		}
	}

	for(var i=0; i<rows.length; i++) {
		if (rows[i].style.display == 'none') {
			rows[i].style.display = '';
			obj.innerHTML = 'zwiń';
		}
		else  {
			rows[i].style.display = 'none';
			obj.innerHTML = 'więcej';
		}
	}

}

Utils.hideShowDiv = function(id) {
	var divElem = document.getElementById(id);

	if (divElem.style.display == 'none') {
		divElem.style.display = '';
	}
	else  {
		divElem.style.display = 'none';
	}
}

Utils.changeTrBColor =	function(id) {
	var el = document.getElementById(id);
	if(el.className == 'tr-off') {
		el.className = 'tr-on';
	} else {
		el.className = 'tr-off';
	}	       
}

Utils.changeDisabledAttr = function(id) {
	var el = document.getElementById(id);
	if(el.disabled) {
		el.disabled = false;
	} else {
		el.disabled = true;
	}	       
}

function addToBookmark(address, title) {
    //FireFox
    if (window.sidebar) { 
        window.sidebar.addPanel(title, address, ""); 
    //IE
    } else if (window.external) {
        window.external.AddFavorite(address, title); 
    //Opera
    } else if (window.opera && window.print) {
        var a = document.createElement('a');
        a.setAttribute('href', address);
        a.setAttribute('title', title);
        a.setAttribute('rel','sidebar');
        a.click();
    }
}


function getNaviWidth() {
	if (document.body) {
		return document.body.clientWidth;
	} else {
		return window.innerWidth;
	}
}

function getNaviHeight() {
	if (document.body) {
		return document.body.clientHeight;
	} else {
		return window.innerHeight;
	}
}

function getScrollX() {
	if (typeof(window.pageXOffset) == 'number' ) {
		// Netscape
		return window.pageXOffset;
	} else if (document.body && document.body.scrollLeft) {
		// DOM
		return document.body.scrollLeft;
	} else if (document.documentElement && document.documentElement.scrollLeft) {
		// IE6
		return document.documentElement.scrollLeft;
	} else {
		return 0;
	}
}

function getScrollY() {
	if (typeof(window.pageYOffset) == 'number' ) {
		// Netscape
		return window.pageYOffset;
	} else if (document.body && document.body.scrollTop) {
		// DOM
		return document.body.scrollTop;
	} else if (document.documentElement && document.documentElement.scrollTop) {
		// IE6
		return document.documentElement.scrollTop;
	} else {
		return 0;
	}
}

function showInfo(text, width) {
	var el = document.getElementById('cloud');
	el.innerHTML = text;
	if(width != undefined) {
		el.style.width = width + 'px';
	}
	el.style.top = 0;
	el.style.left = 0;
	el.style.display = 'block';
}

function hideInfo() {
	var el = document.getElementById('cloud');
	el.style.display = 'none';
}

function getMouseCoordinates(evt) {
	if (!document.getElementById('cloud')) {
		return 0;
	}
	var disp = document.getElementById('cloud').style.display;
	if (disp == 'none') {
		return 0;
	}
	var style = document.getElementById('cloud').style;
	var width = getNaviWidth();
	var height = getNaviHeight();
	var cloud_width = document.getElementById('cloud').offsetWidth;
	var cloud_height = document.getElementById('cloud').offsetHeight;
	var x = 0;
	var y = 0;
	var plusX;
	var plusY;
	if (document.layers) {
		x = evt.x;
		y = evt.y;
	} else if (document.all) {
		x = event.clientX;
		y = event.clientY;
	} else if (document.getElementById) {
		x = evt.clientX;
		y = evt.clientY;
	}
	plusX = getScrollX();
	plusY = getScrollY();
	if ((x + 20 + cloud_width) > width ) {
		trop = (x + 20 + cloud_width) - width;
		style.left = (x - trop + plusX) + 'px';
	} else {
		style.left = (x + plusX) + 'px';
	}
	if ((y - cloud_height - 20) < 0 ) {
		style.top = (y + 20 + plusY) + 'px';
	} else {
		style.top = (y - cloud_height - 20 + plusY) + 'px';
	}
}

if (document.layers) {
	document.captureEvents(Event.MOUSEMOVE);
}

if (document.layers || document.all) {
	document.onmousemove = getMouseCoordinates;
}

if (document.addEventListener) {
	document.addEventListener('mousemove', getMouseCoordinates, true);
}

/*** VALIDATORS ***/
function Validators() {}

Validators.validateLogin = function(id) {
	var element = document.getElementById(id);
	var regex = /^[a-zA-Z0-9\_]+$/
	if(regex.test(element.value)) {
		element.style.borderColor = '';
		element.style.backgroundColor = '';
		document.getElementById('loginError').innerHTML = '';
		return true;
	} else {
		element.style.borderColor = 'red';
		element.style.backgroundColor = 'pink';
		document.getElementById('loginError').innerHTML = 'Niepoprawny login, dopuszczalne znaki: a-Z 0-9 _';
		return false;
	}
}

Validators.validateEmail = function(id) {
	var element = document.getElementById(id);
	if(element.value == '') {
		element.style.borderColor = 'red';
		element.style.backgroundColor = 'pink';
		document.getElementById('emailError').innerHTML = 'Podaj e-mail!';
		return false;		
	}
	
	var regex = /^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,4})$/
	if(regex.test(element.value)) {
		element.style.borderColor = '';
		element.style.backgroundColor = '';
		document.getElementById('emailError').innerHTML = '';
		return true;
	} else {
		element.style.borderColor = 'red';
		element.style.backgroundColor = 'pink';
		document.getElementById('emailError').innerHTML = 'Adres e-mail jest niepoprawny!';
		return false;
	}
}

Validators.validateInputText = function(id, message, messageFieldId) {
	var element = document.getElementById(id);
	var regex = /^[a-zA-Z0-9\.\-\_ąćęłńóśźżĄĆĘŁŃÓŚŹŻ]+[a-zA-Z0-9\.\-\_\ ąćęłńóśźżĄĆĘŁŃÓŚŹŻ]*$/
	if(regex.test(element.value)) {
		element.style.borderColor = '';
		element.style.backgroundColor = '';
		document.getElementById(messageFieldId).innerHTML = '';
		return true;
	} else {
		element.style.borderColor = 'red';
		element.style.backgroundColor = 'pink';
		if(message != undefined) {
			document.getElementById(messageFieldId).innerHTML = message;
		}
		return false;
	}
}

Validators.isEmptyValue = function(id, message, messageFieldId) {
	var element = document.getElementById(id);
	var strTemp = element.value;
	strTemp = Validators.trimAll(strTemp);
	if(strTemp.length > 0) {
		element.style.borderColor = '';
		element.style.backgroundColor = '';
		document.getElementById(messageFieldId).innerHTML = '';
		return true;
	} else {
		element.style.borderColor = 'red';
		element.style.backgroundColor = 'pink';
		if(message != undefined) {
			document.getElementById(messageFieldId).innerHTML = message;
		}
		return false;
	}
}

Validators.isNumericValue = function(id, messageFieldId) {
	var element = document.getElementById(id);
	var regex = /^[0-9]*$/
	if(regex.test(element.value)) {
		element.style.borderColor = '';
		element.style.backgroundColor = '';
		document.getElementById(messageFieldId).innerHTML = '';
		return true;
	} else {
		element.style.borderColor = 'red';
		element.style.backgroundColor = 'pink';
		document.getElementById(messageFieldId).innerHTML = "Podaj wartość liczbową!";
		return false;
	}
}

Validators.isTextValue = function(id, messageFieldId) {
	var element = document.getElementById(id);
	var regex = /^[a-zA-Z\-\ ąćęłńóśźżĄĆĘŁŃÓŚŹŻ]*$/
	if(regex.test(element.value)) {
		element.style.borderColor = '';
		element.style.backgroundColor = '';
		document.getElementById(messageFieldId).innerHTML = '';
		return true;
	} else {
		element.style.borderColor = 'red';
		element.style.backgroundColor = 'pink';
		document.getElementById(messageFieldId).innerHTML = "Niepoprawna wartość, dopuszczalne znaki: a-z!";
		return false;
	}
}

Validators.textareaCounter = function(field, maxLimit, counterFieldId) {
	if (field.value.length > maxLimit) {
		field.value = field.value.substring(0, maxLimit);
	}
	else {
		document.getElementById(counterFieldId).innerHTML = maxLimit - field.value.length;
	}
}

Validators.trimAll = function(strValue) {
	var regex = /^(\s*)$/;

	if(regex.test(strValue)) {
		strValue = strValue.replace(regex, '');
		if( strValue.length == 0)
			return strValue;
	}

	regex = /^(\s*)([\W\w]*)(\b\s*$)/;
	if(regex.test(strValue)) {
		strValue = strValue.replace(regex, '$2');
	}
	return strValue;
}

/*** FAVCOOKS PAGE ***/
function FavCooksPage() {}

FavCooksPage.sortDirection = function(direction) {
	document.FavoriteCooksForm.sortSequence.value = 'sortDirection';
	document.FavoriteCooksForm.sortDirection.value = direction;
	document.FavoriteCooksForm.submit();
}

FavCooksPage.sortDate = function(date) {
	document.FavoriteCooksForm.sortSequence.value = 'sortDate';
	document.FavoriteCooksForm.sortDate.value = date;
	document.FavoriteCooksForm.submit();
}

FavCooksPage.deleteCookFromFavorite = function(deleteFavCook) {
	if (window.confirm("Czy na pewno chcesz usunąć z ulubionych?")) {
		document.FavoriteCooksForm.deleteFavCook.value = deleteFavCook;
		document.FavoriteCooksForm.submit();
	}
}

/*** FAVRECIPES PAGE ***/
function FavRecipesPage() {}

FavRecipesPage.sortRecipesSearchResult = function(interval) {
	document.FavoriteRecipesForm.interval.value = interval;
	document.FavoriteRecipesForm.submit();
}

FavRecipesPage.pagingRecipesSearchResult = function(interval) {
	document.FavoriteRecipesForm.interval.value = interval;
	document.FavoriteRecipesForm.submit();
}

FavRecipesPage.sortByCategoryOn = function(categoryId, categoryType) {
	document.getElementById(categoryType).value = categoryId;
	document.FavoriteRecipesForm.submit();
}

FavRecipesPage.sortByCategoryOff = function(categoryType) {
	document.getElementById(categoryType).value = '';
	document.FavoriteRecipesForm.submit();
}

FavRecipesPage.deleteRecipeFromCookbook = function(recipeId,profileId) {
	if (window.confirm("Czy na pewno chcesz usunąć z ulubionych?")) {
		document.FavoriteRecipesForm.profileOfDeleteRecipe.value = profileId;
		document.FavoriteRecipesForm.deleteRecipe.value = recipeId;
		document.FavoriteRecipesForm.submit();
	}
}

/*** MESSAGE PAGE ***/
function MessagePage() {}

MessagePage.pagingReceivedMessages = function(interval) {
	document.InboxForm.interval.value = interval;
	document.InboxForm.submit();
}

MessagePage.redirectTo = function(url) {
	location.href = url; 
}

MessagePage.deleteMessage = function(msgId) {
	document.InboxForm.deleteMessage.value = msgId;
	document.InboxForm.submit();
}

MessagePage.deleteMessages = function() {
	document.InboxForm.submit();
}

MessagePage.deleteShowedMessage = function(msgId) {
	document.MessageContentForm.deleteMessage.value = msgId;
	document.MessageContentForm.action = 'otrzymane_wiadomosci';
	document.MessageContentForm.submit();
}

MessagePage.showMessage = function(msgId) {
	document.InboxForm.showMsgId.value = msgId;
	document.InboxForm.action = 'twoja_wiadomosc';
	document.InboxForm.submit();
}

MessagePage.checkAll = function() {
	var elems=document.getElementsByTagName('input'),rows=[];
	for(var i=0;i<elems.length;i++){// IE solution
		att1 = elems[i].getAttribute('name');
		att2 = elems[i].getAttribute('type');
		if(att1.substr(0, 11) == 'receivedMsg' && att2 == 'checkbox') {
			rows.push(elems[i]);
		}
	}
	for (i = 0; i < rows.length; i++) {
		rows[i].checked = true ;
		
		var el = document.getElementById('msg'+rows[i].value);
		el.className = 'tr-on';
	}
}

MessagePage.uncheckAll = function() {
	var elems=document.getElementsByTagName('input'),rows=[];
	for(var i=0;i<elems.length;i++){// IE solution
		att1 = elems[i].getAttribute('name');
		att2 = elems[i].getAttribute('type');
		if(att1.substr(0, 11) == 'receivedMsg' && att2 == 'checkbox') {
			rows.push(elems[i]);
		}
	}
	for (i = 0; i < rows.length; i++) {
		rows[i].checked = false ;
		
		var el = document.getElementById('msg'+rows[i].value);
		el.className = 'tr-off';
	}
}

/*** PROFILE PAGE ***/
function ProfilePage() {}

ProfilePage.sortRecipesSearchResult = function(interval) {
	document.ProfileInfoForm.interval.value = interval;
	document.ProfileInfoForm.submit();
}

ProfilePage.pagingRecipesSearchResult = function(interval) {
	document.ProfileInfoForm.interval.value = interval;
	document.ProfileInfoForm.submit();
}

ProfilePage.addCommentToProfile = function() {
	var profileComment = document.getElementById('inputProfileComment').value;
	if(Validators.trimAll(profileComment).length == 0) {
		alert('Komentarz jest pusty!');
	} else {
		document.ProfileInfoForm.profileComment.value = profileComment;
		document.getElementById('addCommentButton').onclick='';
		document.ProfileInfoForm.submit();
	}
}

ProfilePage.addProfileToFavorite = function(profileId) {
	document.getElementById('xajaxIDaddtofavorite').innerHTML = '<img src="./gfx/ajax-loader.gif">';
	xajax_addProfileToFavorite(profileId);
}

ProfilePage.deleteProfileFromFavorite = function(profileId) {
	if (window.confirm("Czy na pewno chcesz usunąć z ulubionych?")) {
		document.getElementById('xajaxIDaddtofavorite').innerHTML = '<img src="./gfx/ajax-loader.gif">';
		xajax_deleteProfileFromFavorite(profileId);
	}
}

ProfilePage.deleteRecipeFromCookbook = function(recipeId, profileId) {
	if (window.confirm("Czy na pewno chcesz usunąć z ulubionych?")) {
		document.ProfileInfoForm.profileOfDeleteRecipe.value = profileId;
		document.ProfileInfoForm.deleteRecipe.value = recipeId;
		document.ProfileInfoForm.submit();
	}
}

ProfilePage.deleteRecipeFoto = function(fotoId, recipeId) {
	if (window.confirm("Czy na pewno chcesz usunąć zdjęcie?")) {
		document.ProfileInfoForm.deleteFoto.value = fotoId;
		document.ProfileInfoForm.recipeOfDeletedFoto.value = recipeId;
		document.ProfileInfoForm.submit();
	}
}

ProfilePage.deleteCookFromFavorite = function(deleteFavCook) {
	if (window.confirm("Czy na pewno chcesz usunąć z ulubionych?")) {
		document.ProfileInfoForm.deleteFavCook.value = deleteFavCook;
		document.ProfileInfoForm.submit();
	}
}

ProfilePage.showAllComments = function() {
	document.ProfileInfoForm.showAllComments.value = 'all';
	document.ProfileInfoForm.submit();
}

/*** ADDRECIPE PAGE ***/
function AddRecipePage() {}

AddRecipePage.EditRow = undefined;
AddRecipePage.BlockDeleteRow = undefined;

AddRecipePage.addIngredient = function() {
	document.getElementById('isModifiedIngredients').value = 'true';
	
	if(document.getElementById('btnAddIngredient').innerHTML == 'Zapisz') {
		AddRecipePage.changeIngredient(AddRecipePage.EditRow);
		AddRecipePage.BlockDeleteRow = false;
		return;
	}
	
	var inName = document.getElementById('inIngrName').value;
	var inDescription = document.getElementById('inIngrDescription').value;
	var inAmount = document.getElementById('inIngrAmount').value;
	
	if(inName == '') {
		alert('Podaj nazwę składnika!');
		return;
	}
	document.getElementById('inIngrName').value = '';
	document.getElementById('inIngrDescription').value = '';
	document.getElementById('inIngrAmount').value = '';
	
	var tbl = document.getElementById('ingrTable');
	var lastRow = tbl.rows.length;
	var iteration = lastRow;
	var row = tbl.insertRow(lastRow);
  
	var cell0 = row.insertCell(0);
	var textNode = document.createTextNode(inName);
	cell0.className = 'addRecipeMainBox2BodyTdName';
	cell0.appendChild(textNode);
  
    var cell1 = row.insertCell(1);
	var textNode = document.createTextNode(inDescription);
	cell1.appendChild(textNode);

    var cell2 = row.insertCell(2);
	var textNode = document.createTextNode(inAmount);
	cell2.appendChild(textNode);

	var cell3 = row.insertCell(3);
    var el = document.createElement('div');
	el.innerHTML = "<input type='hidden' id='ingredient"+lastRow+"' name='ingredient"+lastRow+"' value='"+inName+'#'+inDescription+'#'+inAmount+"' />";
	cell3.appendChild(el);
	
    var cell4 = row.insertCell(4);
	cell4.className = 'addRecipeMainBox2BodyTdOp';
	var el = document.createElement('div');
	el.innerHTML = "<a style='color:red; cursor:pointer;' title='edytuj składnik' onclick='AddRecipePage.editIngredient("+iteration+");'><img src='gfx/reci_ingr_edit.gif'></a><a style='color:red; cursor:pointer;' title='usuń składnik' onclick='AddRecipePage.removeIngredient("+iteration+");'><img src='gfx/bin.gif'></a></a>"
	cell4.appendChild(el);
}

AddRecipePage.removeIngredient = function(nr) {
	document.getElementById('isModifiedIngredients').value = 'true';
	
	if(AddRecipePage.BlockDeleteRow) {
		alert('Zapisz zmiany');
		return;
	}
	var tbl = document.getElementById('ingrTable');
	tbl.deleteRow(nr);
	AddRecipePage.reorderIngredients(tbl, nr);
}

AddRecipePage.reorderIngredients = function(tbl, baseRow) {
	for (var i = baseRow; i < tbl.rows.length; i++) {
		var hInput = document.getElementById('ingredient'+(i+1));
		tbl.rows[i].deleteCell(3);
		var cell3 = tbl.rows[i].insertCell(3);
	    var el = document.createElement('div');
		el.innerHTML = "<input type='hidden' id='ingredient"+i+"' name='ingredient"+i+"' value='"+hInput.value+"' />";
		cell3.appendChild(el);

		tbl.rows[i].deleteCell(4);
		var cell4 = tbl.rows[i].insertCell(4);
		cell4.className = 'addRecipeMainBox2BodyTdOp';
		var el = document.createElement('div');
		el.innerHTML = "<a style='color:red; cursor:pointer;' title='edytuj składnik' onclick='AddRecipePage.editIngredient("+i+");'><img src='gfx/reci_ingr_edit.gif'></a><a style='color:red; cursor:pointer;' title='usuń składnik' onclick='AddRecipePage.removeIngredient("+i+");'><img src='gfx/bin.gif'></a></a>"
		cell4.appendChild(el);
	}
}

AddRecipePage.editIngredient = function(nr) {
	document.getElementById('isModifiedIngredients').value = 'true';

	if(AddRecipePage.BlockDeleteRow) {
		alert('Zapisz zmiany');
		return;
	}
	
	AddRecipePage.BlockDeleteRow = true;
	
	var tbl = document.getElementById('ingrTable');
	tbl.rows[nr].style.backgroundColor = '#F35B00';

	document.getElementById('btnAddIngredient').innerHTML = 'Zapisz';
	AddRecipePage.EditRow = nr;
	
	document.getElementById('inIngrName').value = tbl.rows[nr].cells[0].innerHTML;
	document.getElementById('inIngrDescription').value = tbl.rows[nr].cells[1].innerHTML;
	document.getElementById('inIngrAmount').value = tbl.rows[nr].cells[2].innerHTML;
}

AddRecipePage.changeIngredient = function(nr) {
	var tbl = document.getElementById('ingrTable');
	var inName = document.getElementById('inIngrName').value;
	var inDescription = document.getElementById('inIngrDescription').value;
	var inAmount = document.getElementById('inIngrAmount').value;
	
	if(inName == '') {
		alert('Podaj nazwę składnika!');
		return;
	}
	
	tbl.rows[nr].cells[0].innerHTML = inName;
	tbl.rows[nr].cells[1].innerHTML = inDescription;
	tbl.rows[nr].cells[2].innerHTML = inAmount;
	
	document.getElementById('ingredient'+nr).value = inName+'#'+inDescription+'#'+inAmount;
	
	document.getElementById('btnAddIngredient').innerHTML = 'Dodaj składnik';
	document.getElementById('inIngrName').value = '';
	document.getElementById('inIngrDescription').value = '';
	document.getElementById('inIngrAmount').value = '';
	
	tbl.rows[nr].style.backgroundColor = '';
}

AddRecipePage.submitForm = function() {
	var valitadion = true;
	if(!Validators.validateInputText('recipeName', 'Podaj nazwę przepisu, dopuszczalne znaki: a-Z 0-9 . _ -', 'recipeNameError')) {
		valitadion = false;
	}
	if(!Validators.isEmptyValue('recipeDescription', 'Podaj sposób przygotowania', 'recipeDescriptionError')) {
		valitadion = false;
	}
	if(!valitadion) {
		alert('Dane są niekompletne');
		return;
	}

	document.getElementById('submitId').onclick='';
	document.AddRecipeForm.submit();
}

/*** RECIPE PAGE ***/
function RecipePage() {}

RecipePage.addCommentToRecipe = function() {
	if(document.AddCommentToRecipe.recipeComment.value == '') {
		alert('Komentarz jest pusty!');
	} else {
		document.AddCommentToRecipe.submit();
	}
}

RecipePage.addFotoToRecipe = function() {
	if(document.RecipeFotoForm.file.value == '') {
		alert('Nie podano pliku!');
	} else {
		document.getElementById('submitId').onclick='';
		document.RecipeFotoForm.submit();
	}
}

RecipePage.addRecipeToFavorite = function(recipeId) {
	document.getElementById('addtofavorite').innerHTML = '<center><br/><img src="./gfx/ajax-loader.gif"></center>';
	xajax_addRecipeToFavorite(recipeId);
}

RecipePage.voteToRecipe = function(vote, recipeId) {
	document.getElementById('op_doyoulike').innerHTML = '<img src="./gfx/ajax-loader.gif">';
	xajax_voteToRecipe(vote, recipeId);
}

RecipePage.printRecipePage = function(recipeId) {
	var vLeft = (screen.width - 800)/2;
	var vTop = (screen.height - 600)/2;
	window.open('drukuj?przepis='+recipeId,'Przepis','left='+vLeft+',top='+vTop+',width=800,height=600,scrollbars=yes');
}

/*** RECIPES PAGE ***/
function RecipesPage() {}

RecipesPage.sortRecipesSearchResult = function(interval) {
	document.RecipesSearchForm.interval.value = interval;
	document.RecipesSearchForm.submit();
}

RecipesPage.pagingRecipesSearchResult = function(interval) {
	document.RecipesSearchForm.interval.value = interval;
	document.RecipesSearchForm.submit();
}

RecipesPage.sortByCategoryOn = function(categoryId, categoryType) {
	document.getElementById(categoryType).value = categoryId;
	document.RecipesSearchForm.submit();
}

RecipesPage.sortByCategoryOff = function(categoryType) {
	document.getElementById(categoryType).value = '';
	document.RecipesSearchForm.submit();
}

RecipesPage.deleteRecipeFromCookbook = function(recipeId, profileId) {
	if (window.confirm("Czy na pewno chcesz usunąć z ulubionych?")) {
		document.RecipesSearchForm.profileOfDeleteRecipe.value = profileId;
		document.RecipesSearchForm.deleteRecipe.value = recipeId;
		document.RecipesSearchForm.submit();
	}
}

/*** SEARCH PAGE ***/
function SearchPage() {}

SearchPage.sortFridgeSearchResult = function(interval) {
	document.FridgeSearchResultForm.interval.value = interval;
	document.FridgeSearchResultForm.submit();
}

SearchPage.pagingFridgeSearchResult = function(interval) {
	document.FridgeSearchResultForm.interval.value = interval;
	document.FridgeSearchResultForm.submit();
}

SearchPage.sortByCategoryOn = function(categoryId, categoryType) {
	document.getElementById(categoryType).value = categoryId;
	document.FridgeSearchResultForm.submit();
}

SearchPage.sortByCategoryOff = function(categoryType) {
	document.getElementById(categoryType).value = '';
	document.FridgeSearchResultForm.submit();
}

SearchPage.callbackSuggestedIngredients = function() {
 	alert('DZIALA');
}

/*** START PAGE ***/
function StartPage() {}

StartPage.submitForm = function() {
	document.IngredientsGroupsForm.submit();
}


