function setCookie (name, value, expires, path, 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 set_archive_cookies () {
	//alert ("111");
	//var archive = getCookie( 'archive' );
	//alert (archive);
	var is_checkbox_checked;
	if (document.archive.is_archive_checkbox.checked){
		is_checkbox_checked = '1';
	} else {
		is_checkbox_checked = '0';
	}
	var dtExpires = new Date();
	dtExpires.setTime(dtExpires.getTime() + 60*60*24);
	dtExpires.toGMTString();
	setCookie ('archive',is_checkbox_checked,dtExpires,"/");
	document.archive.submit(); 
	return false;
}

function set_beznal_cookies () {
	//alert ("111");
	//var beznal = getCookie( 'beznal' );
	//alert (beznal);
	var is_checkbox_checked;
	if (document.beznal.is_beznal_checkbox.checked){
		is_checkbox_checked = '1';
	} else {
		is_checkbox_checked = '0';
	}
	var dtExpires = new Date();
	dtExpires.setTime(dtExpires.getTime() + 60*60*24);
	dtExpires.toGMTString();
	setCookie ('beznal',is_checkbox_checked,dtExpires,"/");
	document.beznal.submit(); 
	return false;
}

function set_show_month_orders_cookies () {
	//alert ("111");
	//var show_month_orders = getCookie( 'show_month_orders' );
	//alert (show_month_orders);
	var is_checkbox_checked;
	if (document.show_month_orders.is_show_month_orders_checkbox.checked){
		is_checkbox_checked = '1';
	} else {
		is_checkbox_checked = '0';
	}
	var dtExpires = new Date();
	dtExpires.setTime(dtExpires.getTime() + 60*60*24);
	dtExpires.toGMTString();
	setCookie ('show_month_orders',is_checkbox_checked,dtExpires,"/");
	document.show_month_orders.submit(); 
	return false;
}

function set_show_1c_orders_cookies () {
	var is_checkbox_checked;
	if (document.show_1c_orders.is_show_1c_orders_checkbox.checked){
		is_checkbox_checked = '1';
	} else {
		is_checkbox_checked = '0';
	}
	var dtExpires = new Date();
	dtExpires.setTime(dtExpires.getTime() + 60*60*24);
	dtExpires.toGMTString();
	setCookie ('show_1c_orders',is_checkbox_checked,dtExpires,"/");
	document.show_1c_orders.submit(); 
	return false;
}

function get_archive_cookies () {
	var archive = getCookie( 'archive' );
	alert (archive);
}

function getScrollXY() 
{
  var scrOfX = 0, scrOfY = 0;
  if( typeof( window.pageYOffset ) == 'number' ) {
    //Netscape compliant
    scrOfY = window.pageYOffset;
    scrOfX = window.pageXOffset;
  } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
    //DOM compliant
    scrOfY = document.body.scrollTop;
    scrOfX = document.body.scrollLeft;
  } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
    //IE6 standards compliant mode
    scrOfY = document.documentElement.scrollTop;
    scrOfX = document.documentElement.scrollLeft;
  }
  return [ scrOfX, scrOfY ];
}

function getCookiePos( name ) 
{
	var start = document.cookie.indexOf( name + "=" );
	var len = start + name.length + 1;
	if ( ( !start ) && ( name != document.cookie.substring( 0, name.length ) ) ) {
		return null;
	}
	if ( start == -1 ) return null;
	var end = document.cookie.indexOf( ';', len );
	if ( end == -1 ) end = document.cookie.length;
	return unescape( document.cookie.substring( len, end ) );
}

function setCookiePos( name, value, expires, path, domain, secure ) 
{
	var today = new Date();
	today.setTime( today.getTime() );
	if ( expires ) {
		expires = expires * 1000 * 60 * 60 * 24;
	}
	var expires_date = new Date( today.getTime() + (expires) );
	document.cookie = name+'='+escape( value ) +
		( ( expires ) ? ';expires='+expires_date.toGMTString() : '' ) + //expires.toGMTString()
		( ( path ) ? ';path=' + path : '' ) +
		( ( domain ) ? ';domain=' + domain : '' ) +
		( ( secure ) ? ';secure' : '' );
}

function deleteCookiePos( name, path, domain ) 
{
	if ( getCookiePos( name ) ) document.cookie = name + '=' +
			( ( path ) ? ';path=' + path : '') +
			( ( domain ) ? ';domain=' + domain : '' ) +
			';expires=Thu, 01-Jan-1970 00:00:01 GMT';
}

function update_scroll_data ()
{
	var curScroll = getScrollXY();
	setCookiePos( 'scroll_pos', curScroll[0] + ',' + curScroll[1], 
		7200, '/', document.location.host);
}

function set_scroll_position (uid,position)
{
	//alert (uid);
	var scroll_pos = getCookiePos ('scroll_pos');
	if (scroll_pos)
	{
		scroll_pos = scroll_pos.split (',');
		//alert (scroll_pos[1]);
		if (uid == 0) {
			if (position == 1) {
				if (scroll_pos[1] > 114) { //114
					scroll_pos[1] = 114;
				}
			} 
			if (position == 2) {
				if (scroll_pos[1] > 201) { //201
					scroll_pos[1] = 201;
				}
			}
		} else {
			if (position == 1) {
				if (scroll_pos[1] > 168) { //223
					scroll_pos[1] = 168;
				}
			} 
			if (position == 2) {
				if (scroll_pos[1] > 254) { //318
					scroll_pos[1] = 254;
				}
			}
		}
		if (position == 3) {
			scroll_pos[1] = 0;
		} 
    window.scrollTo(scroll_pos[0], scroll_pos[1]);
	}
}

function entsub(event) {
	if (event && event.keyCode == 13) {
		document.quantityform.submit();
	} else {
		return true;
	}	
}


function init(){
	var browser = navigator.appName;
	if (browser == "Netscape") {
		layerStyleRef="layer.";
		layerRef="document.layers";
		styleSwitch="";
	}else{
		layerStyleRef="layer.style.";
		layerRef="document.all";
		styleSwitch=".style";
	}
}
function showLayer(layerName){
	eval(layerRef+'["'+layerName+'"]'+styleSwitch+'.visibility="visible"');
}
function hideLayer(layerName){
	eval(layerRef+'["'+layerName+'"]'+styleSwitch+'.visibility="hidden"');
}

function set_catalog_cookies(page) {
	var dtExpires = new Date();
	dtExpires.setTime(dtExpires.getTime() + 60*60);
	dtExpires.toGMTString();
	setCookie ('catalog_page',page,dtExpires,"/");
	return false;
}

function showPhoto(pname, pwidth, pheight) {
	w=window.open(pname, 'viewPhoto',  'toolbar=0,scrollbars=0,location=0,directories=0,status=0,menubar=0,resizable=0,width='+pwidth+',height='+pheight+',border=thin,top=50,left=50,help=0');
	w.focus();
} 
