

//
//  BROWSER DETECTION
//

var dom = (document.getElementById)? true : false;
var nn4 = (document.layers)? true : false;
var ie4 = (!dom && document.all)? true : false;
var opr = (navigator.userAgent.indexOf('Opera') >= 0)? true : false;


//
// IMAGES
//

function objImage(imgName,imgOff,imgOn) 
{
	this.name = imgName;
	this.offImgObject = loadImage(imgOff);
	this.onImgObject  = loadImage(imgOn);
	this.on  = imageOn;
	this.off = imageOff;
	this.statuson  =  false;
}

function imageOn()
{
	document[this.name].src = this.onImgObject.src;
	this.statuson = true;
}

function imageOff()
{
	document[this.name].src = this.offImgObject.src;
	this.statuson = false;
}

function loadImage(imgSrcName)
{
	imgObject = new Image()
	imgObject.src = imgSrcName;
	return imgObject;
}


//
// WINDOWS
//

function openWindow(winName,winURL,winFullScreen,winChannelMode,winToolBar,winLocation,winDirectories,winStatus,winMenubar,winScrollbars,winResizable,winWidth,winHeight,winTop,winLeft)
{
	var winFeatures  = "fullscreen=" + winFullScreen + "," + "channelmode=" + winChannelMode + "," + "toolbar=" + winToolBar + "," + "location=" + winLocation + "," + "directories=" + winDirectories + "," + "status=" + winStatus + "," + "menubar=" + winMenubar + "," + "scrollbars=" + winScrollbars + "," + "resizable=" + winResizable + "," + "width=" + winWidth + "," + "height=" + winHeight + "," + "top=" + winTop + "," + "left=" + winLeft + ",";
	var winName = window.open(winURL,winName,winFeatures);
}


//
// LAYERS
//

function loadSpan(name,info) 
{ 
	if (dom) eval('document.getElementById("' + name + '").innerHTML = info;');
	else if (ie4 || opr) eval('document.all["' + name + '"].innerHTML = info;');
}

//
// COOKIES
//

var today = new Date();
var expiryyear = new Date(today.getTime() + 365 * 24 * 60 * 60 * 1000);
var expirymonth = new Date(today.getTime() + 30 * 24 * 60 * 60 * 1000);
var expiryday = new Date(today.getTime() + 24 * 60 * 60 * 1000);

function getCookieVal(offset) 
{
	var endstr = document.cookie.indexOf(";", offset);
	if(endstr == -1) { endstr = document.cookie.length; }
	return unescape(document.cookie.substring(offset, endstr));
}

function getCookie(name) 
{
	var arg = name + "=";
	var alen = arg.length;
	var clen = document.cookie.length;
	var i = 0;
	while(i < clen) 
	{
		var j = i + alen;
		if (document.cookie.substring(i, j) == arg) 
		{
			return getCookieVal (j);
		}
		i = document.cookie.indexOf(" ", i) + 1;
		if (i == 0) break; 
	}
	return null;
}

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 setCookie(name,value,expires,path,domain,secure) 
{
  document.cookie = name + "=" + escape (value) +
    ((expires) ? "; expires=" + expires.toGMTString() : "") +
    ((path) ? "; path=" + path : "") +
    ((domain) ? "; domain=" + domain : "") +
    ((secure) ? "; secure" : "");
}

//
// PRODUCT PAGE SUPPORT
//

function loadCategory(id) {
	document.mainForm.action = "catalog.php";
	document.mainForm.Id.value = parseInt(id);
	document.mainForm.submit();
}

function loadProduct(id) { 
	openWindow("product" + id,"product.php?Id=" + id,0,0,0,0,0,0,0,1,1,950,700,20,20); 
}

function toBasket(id) {
//	if (getCookie("basket12md") == null) {
//		setCookie("basket12md", "0");
//	} else {
//		setCookie("basket12md", getCookie("basket12md") + "," + id);
//	}	
}

//
// CATALOG PAGE SUPPORT
//

function viewCategory(id) {
	document.mainForm.action = "catalog.php";
	document.mainForm.Id.value = parseInt(id);
	document.mainForm.submit();
}

function openGroup(id) {
	if (dom) {
		if (document.getElementById('group' + id).style.display == 'none') {
			eval('icon' + id + '.on();');
			document.getElementById('group' + id).style.display = 'block';
		} else {
			eval('icon' + id + '.off();');
			document.getElementById('group' + id).style.display = 'none';
		}
	} else if (ie4 || opr) {
		document.all['group' + id].style.display = (document.all['group' + id].style.display == 'none') ? 'block' : 'none';
	}
	
	if (document.ProductForm) {
		for (var i = 0; i < document.ProductForm.Category.length; i++) {
			if (document.ProductForm.Category[i].value == id) document.ProductForm.Category.selectedIndex = i;
		}
	}
}

//
// NEWS
//

function loadNews(id) {
	document.mainForm.action = "more.php";
	document.mainForm.Id.value = parseInt(id);
	document.mainForm.submit();
}

//
// ARTICLES
//

function loadArticle(id) {
	document.mainForm.action = "article.php";
	document.mainForm.Id.value = parseInt(id);
	document.mainForm.submit();
}

function openSpan(name) {
	if (dom) {
		document.getElementById(name).style.display = 'block';
	} else if (ie4 || opr) {
		document.all[name].style.display = 'block';
	}
}

function closeSpan(name) {
	if (dom) {
		document.getElementById(name).style.display = 'none';
	} else if (ie4 || opr) {
		document.all[name].style.display = 'none';
	}
}

