
function verifyIsLogined(user, contextPath, pageName, params) {
	if (!user) {
		redirectToUrl(contextPath + '/sign-in.html?redirectPage=' + pageName + '&params=' + params);
	} else {
		return true;
	}
}

function submitForm(formId) {
	$(formId).submit();
}

function submitFormAndChangeAct(formId, actInputId, newValue) {
	$(actInputId).value = newValue;
	submitForm(formId);
}

Event.observe(window, 'load', function(event) {
	var countrySelector = $('countrySelector');
	if (countrySelector && countrySelector.value == 'United States of America') {
		 $('stateId').show();
	}
	
	for (var i = 1; i <= 12; i++) {
		if (getCookie('menu-list' + i)) {
			var list = $('list' + i);
			if (list) {
				showmnu(i);
			}
		}
	}
});

function showSubCategories(obj, isActive) {	
	if ($('list'+obj).style.display=='block') {
		hidemnu(obj, isActive);						
	}
	else {
		showmnu(obj);
	}
}

function showmnu(num) {
	$('list'+num).style.display='block';
	$('cat'+num).className = 'showmnu-cat';
	$('li-cat'+num).style.color='#808c7e';
	$('li-cat'+num).className = 'showmnu-li-cat';
	setCookie('menu-list' + num, 'shown', '/');
}

function hidemnu(num, isActive) {
	$('list'+num).style.display='none';
	$('cat'+num).className = 'hidemnu-cat';	
	$('li-cat'+num).className = 'hidemnu-li-cat';
	if (isActive) {
		$('li-cat'+num).style.color='#2f3930';
	}
	deleteCookie('menu-list' + num, '/');
}

function changeBLockVisibility(blockId) {
	if ($(blockId).style.display=='block') {
		$(blockId).style.display='none';		
	}
	else {
		$(blockId).style.display='block';
	}
	return false;
}

function changeBlockDisplay(blockId) {
	if ($(blockId).style.display == 'none') {
		$(blockId).show();
	} else {
		$(blockId).hide();
	}
	return false;
}

function redirectToUrl(url) {
	window.location.href = url;
	return false;
}

function showStates(select, id) {
	var country = select.value;
	if (country == 'United States of America') {
		$(id).show();
	} else {
		$(id).hide();
	}
	return false;
}

function setCookie(name, value, path, expires, domain, secure) {
    document.cookie = name + "=" + escape(value) +
      ((expires) ? "; expires=" + expires : "") +
      ((path) ? "; path=" + path : "") +
      ((domain) ? "; domain=" + domain : "") +
      ((secure) ? "; secure" : "");
}

function getCookie(name) {
	var cookie = " " + document.cookie;
	var search = " " + name + "=";
	var setStr = null;
	var offset = 0;
	var end = 0;
	if (cookie.length > 0) {
		offset = cookie.indexOf(search);
		if (offset != -1) {
			offset += search.length;
			end = cookie.indexOf(";", offset)
			if (end == -1) {
				end = cookie.length;
			}
			setStr = unescape(cookie.substring(offset, end));
		}
	}
	return(setStr);
}

function deleteCookie(name, path, domain) {
    if (getCookie(name)) {
            document.cookie = name + "=" + 
            ((path) ? "; path=" + path : "") +
            ((domain) ? "; domain=" + domain : "") +
            "; expires=Thu, 01-Jan-70 00:00:01 GMT"
    }
}

function charLimitations(inputId, maxCharsCount) {
	var countrySelector = $(inputId);
	if (countrySelector) {
		var value = countrySelector.value;
		if (value.length >= maxCharsCount) {
			countrySelector.value = value.substring(0, maxCharsCount - 1);
		}
	}
	return false;
} 