

//
//  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;


// MPLAYER VIDEO

function addVideo(src, width, height, autostart) {
    document.write('<OBJECT ID="mPlayer" width="' + width + 'px" height="' + height +'px" CLASSID="CLSID:22d6f312-b0f6-11d0-94ab-0080c74c7e95" CODEBASE="http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=5,1,52,701" STANDBY="Loading Microsoft Windows Media Player components..." TYPE="application/x-oleobject"><PARAM NAME="fileName" VALUE="' + src + '"><PARAM NAME="animationatStart" VALUE="true"><PARAM NAME="transparentatStart" VALUE="false"><PARAM NAME="autoStart" VALUE="'+ autostart + '"><PARAM NAME="showControls" VALUE="true"><EMBED type="application/x-mplayer2" pluginspage="http://www.microsoft.com/Windows/MediaPlayer/" SRC="' + src + '" name="mPlayer" width="' + width +'px" height="' + height + 'px" showControls="1" AutoStart="' + autostart + '"></EMBED></OBJECT>');
}

//
// 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" : "");
}


function testCookies() {
    setCookie("test", "ok");
    if (getCookie("test") != "ok") {
        alert("Для работы интернет-магазина необходима поддержка cookies. Пожалуйста включите ее в настройках Вашего браузера.");
    }
}

function isEmpty(s) {
    return ((s == null) || (s.length == 0))
}


var reEmail = /^.+\@.+\..+$/

function isEmail(s) {
    if (isEmpty(s))
       if (isEmail.arguments.length == 1) return false;
       else return (isEmail.arguments[1] == true);
     else {
       return reEmail.test(s);
    }
}


var reFloat = /^((\d+(\.\d*)?)|((\d*\.)?\d+))$/

function isFloat(s) {
    if (isEmpty(s))
       if (isFloat.arguments.length == 1) return false;
       else return (isEmail.arguments[1] == true);
    else {
       return reFloat.test(s);
    }
}

function roundToPrecision(inputNum, desiredPrecision){
    var precisionGuide = Math.pow(10, desiredPrecision);
    return( Math.round(inputNum * precisionGuide) / precisionGuide );
}

function addZeroesToPrecision(inputNum, desiredPrecision){
    var numString = inputNum + "";
    var afterDecimalString = numString.substring(numString.search(/\./) + 1);
    while (afterDecimalString.length < desiredPrecision) {
        afterDecimalString += "0";
        numString += "0";
    }
    return(numString);
}

// SEARCH

function startSearch() {
    document.catalogForm.action = "search.php";
	document.catalogForm.submit();
}

//
// NEWS
//

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


