function menu_swch(block_id) 
{
	if (getElm('block'+block_id).style.display == 'block') 
	{
		getElm('block' + block_id).style.display = 'none';
		getElm('block' + block_id + '_swch').className = 'none';
  	} 
  	else 
  	{
		getElm('block' + block_id).style.display = 'block';
		getElm('block' + block_id + '_swch').className = 'active';
  	}
  	return false;
}

function RemindPassword(ErrMes)
{
	iLogin = document.forms['login-inner-form'].elements['login'];
	var clogin = iLogin.value;
	
	if(isNotEmpty(clogin))
	{
		window.location.href = '/go.php?type=remind&login='+clogin;
	}
	else
	{
		alert(ErrMes);
		iLogin.focus();
	}
	return false;
}


function AjaxWItemAddToCart(WItemID, WItemAmount, ErrMes)
{
	JsHttpRequest.query
	(
		'/backend.php?type=cart&action=addwitem',
		{
			'witemid': WItemID,
			'witemamount': WItemAmount
		},
		function (result, errors)
		{
			if(result.status == 0)
			{
				SetCartBlockNumbers(result.totalitems, result.totalprice);
				ShowInCartImage(WItemID);
			}
			else if(result.message)
			{
				alert(result.message);
			}
			else
			{
				alert(ErrMes);
			}
		},
		true
	);
	return false;
} 

function SetCartBlockNumbers(amount, price)
{
	if(Number(amount) > 0)
	{
		getElm('cartblockTotalWItems').innerHTML = amount;
		getElm('cartblockTotalSum').innerHTML = price;
		getElm('p_cartblockTotalWItems').style.display = 'block';
		getElm('p_cartblockTotalPrice').style.display = 'block';
		getElm('p_cartblockEmpty').style.display = 'none';
	}
	else
	{
		getElm('p_cartblockTotalWItems').style.display = 'none';
		getElm('p_cartblockTotalPrice').style.display = 'none';
		getElm('p_cartblockEmpty').style.display = 'block';
	}	
}

function ShowInCartImage(witemid)
{
	var acFlds = new Array('p', 'img', 'a', 'span');
	for (var i = 0; i < acFlds.length; i++)
	{
		if(getElm(acFlds[i] + '_addcart_' + witemid))
		{
			getElm(acFlds[i] + '_addcart_' + witemid).style.display = 'none';
		}
	}
	if( getElm('img_incart_'+witemid) )
	{
		getElm('img_incart_'+witemid).style.display = 'inline';
	}
}


// lib functions
function getElem(eid)
{
	if(document.getElementById(eid))
	{
		return document.getElementById(eid);
	}
	else
	{
		return null;
	}
}

function getElm(eid)
{
	return getElem(eid);
}

function showElem(elem)
{
	if(elem)
	{
		elem.style.visibility = 'visible';
	}
}

function hideElem(elem)
{
	if(elem)
	{
		elem.style.visibility = 'hidden';
	}
}


function radiobuttonValue(f, ename)
{
	var oRB, len, opt, i;
	oRB = f.elements[ename];
	len = oRB.length;
	for(i = 0; i < len; i++)
	{
		opt = oRB[i];
		if(opt.checked == true)
		{
			return opt.value;
		}
	} 
	return false;
}

function OpenWindow(url, w, h) 
{
	window.open(url, '', 'toolbar=0,menubar=0,location=0,status=0,scrollbars=0,resizable=0,height='+h+',width='+w+',left=50,top=50');
}

function flip(item)
{
	if (item.style.display == 'none')
	{
		item.style.display = 'inline';
	}
	else
	{
		item.style.display = 'none';
	}
}

function scrolled()
{
	parent.leftFrame.document.body.scrollTop=document.body.scrollTop;
	parent.rightFrame.document.body.scrollTop=document.body.scrollTop;
}

 
function isOpera()
{
	if(navigator.userAgent.toLowerCase().indexOf('opera')  > -1) {
		return true;
	} else {
		return false;
	}
}

function isIE()
{
	if(navigator.userAgent.toLowerCase().indexOf('msie')  > -1) {
		return true;
	} else {
		return false;
	}
} 

function oldIE()
{
	var ua = navigator.userAgent.toLowerCase();
	var i = ua.indexOf('msie');
	if(i<0) {
		return false;
	}
	var uatrimmed = ua.substr(i);
	var j = uatrimmed.indexOf(';');
	var vers = uatrimmed.substring(5,j);
	vers = parseFloat(vers);
	if(vers < 7)
	{
		return true;
	}
	else
	{
		return false;
	}
}

function getDocumentHeight() 
{
	var h1 = document.compatMode != 'CSS1Compat' ? document.body.scrollHeight : document.documentElement.scrollHeight;
	var h2 = getViewportHeight();
	return Math.max(h1, h2);
}

function getScrollTop()
{
	var scrTop = document.compatMode != 'CSS1Compat' ? document.body.scrollTop : document.documentElement.scrollTop;
	return scrTop;
}
 
function getViewportHeight() {
  return ((document.compatMode || isIE()) && !isOpera()) ? (document.compatMode == 'CSS1Compat') ? document.documentElement.clientHeight : document.body.clientHeight : (document.parentWindow || document.defaultView).innerHeight;
}

function isNotEmpty(str)
{
	var PatternEmpty = /^[\s]*$/i;
	if(PatternEmpty.test(str))
	{
		return false;
	}
	else
	{
		return true;
	}
}

function isEmpty(str)
{
	res = !(isNotEmpty(str));
	return res;
}

function isValidEmail(str)
{
	var PatternEmail = /^([a-zA-Z0-9_\.\-]+)@([a-zA-Z0-9\.\-]+)\.([a-zA-Z]{2,4})$/;
	if(!PatternEmail.test(str))
	{
		return false;
	}
	else
	{
		return true;
	}
}
