// JavaScript Document
var BrowserDetect = {
	init: function () {
		this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
		this.version = this.searchVersion(navigator.userAgent)
			|| this.searchVersion(navigator.appVersion)
			|| "an unknown version";
		this.OS = this.searchString(this.dataOS) || "an unknown OS";
	},
	searchString: function (data) {
		for (var i=0;i<data.length;i++)	{
			var dataString = data[i].string;
			var dataProp = data[i].prop;
			this.versionSearchString = data[i].versionSearch || data[i].identity;
			if (dataString) {
				if (dataString.indexOf(data[i].subString) != -1)
					return data[i].identity;
			}
			else if (dataProp)
				return data[i].identity;
		}
	},
	searchVersion: function (dataString) {
		var index = dataString.indexOf(this.versionSearchString);
		if (index == -1) return;
		return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
	},
	dataBrowser: [
		{
			string: navigator.vendor,
			subString: "Apple",
			identity: "Safari"
		}
	],
	dataOS : []
};

function roundElems(){
BrowserDetect.init();
if(BrowserDetect.browser == 'Safari'){
	var oldonload = window.onload;
	window.onload = function(){
		if(oldonload)oldonload();
Nifty("div.cpt_survey","bottom");
Nifty("div.cpt_tag_cloud","bottom");
Nifty("#cat_advproduct_search","");

	}
}else{
Nifty("div.cpt_survey","bottom transparent");
Nifty("div.cpt_tag_cloud","bottom transparent");
Nifty("#cat_advproduct_search","")


}
}

function idd(id)
{
  return document.getElementById(id);
}

function getScrollH(){ return (document.documentElement.scrollTop || document.body.scrollTop); }
function getScrollW(){ return (document.documentElement.scrollLeft || document.body.scrollLeft); }

function getWinW(){ return window.innerWidth?window.innerWidth : document.compatMode=='CSS1Compat' && !window.opera?document.documentElement.clientWidth:document.body.clientWidth; }
function getWinH(){ return window.innerHeight?window.innerHeight : document.compatMode=='CSS1Compat' && !window.opera?document.documentElement.clientHeight:document.body.clientHeight; }
function getDocH(){ return document.compatMode!='CSS1Compat' ? document.body.scrollHeight : document.documentElement.scrollHeight; }

function posdiv(id) {
        var e=idd(id);
	e.style.display='block';

        var W=getWinW(); var H=getWinH();
        var w=e.clientWidth; var h=e.clientHeight;
	var x=(W-w)/2+getScrollW();
	var y=(H-h)/2+getScrollH();
	var DH=W-10; if(w<DH && x+w>DH) x=DH-w; if(x<0) x=0; 
	DH=getDocH()-10; if(h<DH && y+h>DH) y=DH-h; if(y<0) y=0;
        e.style.top=y+'px'; e.style.left=x+'px';
}

function mkdiv(id,s) {
        if(idd(id)) { idd(id).innerHTML=s; posdiv(id); return; }
        var div=document.createElement('div'); div.id=id; div.innerHTML=s;
//	document.body.insertBefore(div, document.body.lastChild);
	document.body.appendChild(div);
        posdiv(id);
}

function rmdiv(id) {
  var el = idd(id);
  el.parentNode.removeChild(el);
}

function onNotifyClick(pid)
{
        JsHttpRequest.query(
            '/sm_notify.php', // backend
            {
                'pid': pid
            },
            // Function is called when an answer arrives. 
            function(result, errors) {
                // Write errors to the debug div.
//                document.getElementById("debug").innerHTML = errors; 
                // Write the answer.
                if (result) {
			var message;
                        var timeout = 1200;
			switch(result["res"])
			{
				case "0":
//					message="При поступлении этого товара в продажу мы оповестим Вас по электронной почте";
					message="Оповещение добавлено!";
					break;
				case "1":
					message='Для подписки на оповещения о поступлении товаров необходимо зарегистрироваться'; timeout=4000;break;
				case "2":
//					message="Вы уже подписаны на оповещение об этом товаре";
					message="Оповещение добавлено (повторно)!";
					break;
				case "3":
				default:
					message="Извините, произошла ошибка."; break;
			}
			mkdiv('prd_notify_status',message);			
			setTimeout('rmdiv("prd_notify_status")',timeout);
                }
            },
            true  // disable caching
        );
}



