function strReplace(s, r, w)
{
	return s.split(r).join(w);
}

function addslashes(str) 
{
	str=str.replace(/\'/g,'\\\'');
	str=str.replace(/\"/g,'\\"');
	str=str.replace(/\\/g,'\\\\');
	str=str.replace(/\0/g,'\\0');
	return str;
}
function stripslashes(str) 
{
	str=str.replace(/\\'/g,'\'');
	str=str.replace(/\\"/g,'"');
	str=str.replace(/\\\\/g,'\\');
	str=str.replace(/\\0/g,'\0');
	return str;
}

function trim(str)
{ 
	str = str.replace(/&nbsp;/g, '');
	return str.replace(/(^\s+)|(\s+$)/g, '');
}


function getObj(nid)
{
	if (document.getElementById(nid))
	{
		return document.getElementById(nid);
	}
	else
	{
		return false;
	}
}

function getObjValue(nid)
{
	var ret = "";
	if (document.getElementById(nid).type == "checkbox")
	{
		if (document.getElementById(nid).checked == true)
		{
			ret = document.getElementById(nid).value;
		}
	}
	else
	{
		ret = document.getElementById(nid).value;
	}
	return ret;
}

function getValFromUrl(url, varname)
{
	var vars = new Array();
	vars = url.split("&");
	var ret = "error";

	for (i = 0; i < vars.length; i++)
	{
		var value = new Array();
		value = vars[i].split("=");
		if (value[0] == varname)
		{
			ret = value[1];
		}
	}
	return ret;	
}


function makeRequest(url, param1, param2, param3, param4, param5, param6, param7, param8, param9, param10, param11, param12, param13, param14, param15, param16, param17, param18, param19, param20) 
{
	var http_request = false;

	if (window.XMLHttpRequest) 
	{ // Mozilla, Safari, ...
		http_request = new XMLHttpRequest();
		if (http_request.overrideMimeType) 
		{
			http_request.overrideMimeType('text/html');
			// ??????? ???? ?? ???? ??????
		}
	} 
	else if (window.ActiveXObject) 
	{ // IE
		try 
		{
			http_request = new ActiveXObject("Msxml2.XMLHTTP");
		} 
		catch (e) 
		{
			try 
			{
				http_request = new ActiveXObject("Microsoft.XMLHTTP");
			} 
			catch (e) 
			{
			}
		}
	}

	if (!http_request) 
	{
		alert('Unfortunatly your browser doesn\'t support XMLHTTP.');
		return false;
	}


	http_request.onreadystatechange = function() 
	{ 
		if (http_request.readyState == 4)
		{
            if (http_request.status == 200)
			{
				if (getValFromUrl(http_request.responseText, "answer") == "getModelInfo")
				{
					if (getValFromUrl(http_request.responseText, "error") != "")		//Âîçíèêëè îøèáêè
					{
						alert(getValFromUrl(http_request.responseText, "error"));
					}
					else
					{
						var newHTML = getValFromUrl(http_request.responseText, "newcontent");
						
						newHTML = strReplace(newHTML, "::ravno::", "=");
						newHTML = strReplace(newHTML, "::amp::", "&");
						document.getElementById('commentsTable').innerHTML = newHTML;
					}
				}
			}
			else
			{
				alert('Connection wasn\'t successful.');
			}
		}
	}


	//************** ÎÁÐÀÁÀÒÛÂÀÅÌ ÊËÈÊÈ
	if (url == "getModelInfo")
	{
		
		http_request.open('POST', "/getAnswer.php", true);
		http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		http_request.setRequestHeader("Connection", "close");
		http_request.send("q=getModelInfo&p1=" + param1 + "&p2=" + param2 + "&p3=" + param3 + "&p4=" + param4 + "&p5=" + param5 + "&p6=" + param6 + "&p7=" + param7 );
	}
	
}


















function absPosition(obj)
{ 
      var x = y = 0; 
      while(obj) { 
            x += obj.offsetLeft; 
            y += obj.offsetTop; 
            obj = obj.offsetParent; 
      } 
      return {x:x, y:y}; 
}




var obj_tempX = 0;
var obj_tempY = 0;
var mouseClickX = -1;
var mouseClickY = -1;

document.ondragstart = function()
{
	return false;
}



var ua = navigator.userAgent.toLowerCase();
isIE = (ua.indexOf("msie") != -1 && ua.indexOf("opera") == -1 && ua.indexOf("webtv") == -1); 
isOpera = (ua.indexOf("opera") != -1);
isGecko = (ua.indexOf("gecko") != -1); 
isSafari = (ua.indexOf("safari") != -1); 


function getMouseXY(e)
{

	var obj = document.getElementById('bigImage');
	var cont = document.getElementById('bigImageContainer');

	if (!isGecko || (isGecko && isSafari))
	{
		obj_tempX = event.clientX + document.body.scrollLeft - absPosition(obj).x;
		obj_tempY = absPosition(obj).y;
	}
	else 
	{
		
		obj_tempX = absPosition(document.body).x + absPosition(obj).x;
		//document.getElementById('test').innerHTML = mouseClickX;
		//obj_tempY = e.pageY;
	}
	

	if (mouseClickX != -1 && mouseClickY != -1)
	{
		obj.style.marginTop = -mouseClickY + event.clientY - cont.offsetHeight + "px";
		obj.style.marginLeft = -mouseClickX + event.clientX - cont.offsetWidth + "px";
	}
	
	
	
	if (strReplace(obj.style.marginTop, "px" ,"") * 1 < -obj.offsetHeight + cont.offsetHeight)
	{
		obj.style.marginTop = -obj.offsetHeight + cont.offsetHeight;
	}
	if (strReplace(obj.style.marginTop, "px" ,"") * 1 > 0)
	{
		obj.style.marginTop = 0;
	}
	if (strReplace(obj.style.marginLeft, "px" ,"") * 1 < -obj.offsetWidth + cont.offsetWidth)
	{
		obj.style.marginLeft = -obj.offsetWidth + cont.offsetWidth;
	}
	if (strReplace(obj.style.marginLeft, "px" ,"") * 1 > 0)
	{
		obj.style.marginLeft = 0;
	}
}



function getMouseClickP()
{
	getMouseXY();
	var obj = document.getElementById('bigImage');
	var cont = document.getElementById('bigImageContainer');
	mouseClickX = event.clientX + cont.offsetWidth - absPosition(obj).x + 47;
	mouseClickY = event.clientY + cont.offsetHeight - absPosition(obj).y + 33;
}

function resetMouseP()
{
	mouseClickX = -1;
	mouseClickY = -1;
}



function loadPreviewImages(pic, haveBig, defaultBig)
{
	var middle = document.getElementById('previewProduct');
	
	middle.src = "/userfiles/370_" + pic;
	middle.onclick = function()
	{
		if (haveBig != 0)
		{
			window.open('/userfiles/800_' + pic,'displayWindow','width=600,height=800,resizeable=no,scrollbars=0,toolbar=no,top=0');
		}
		else
		{
			window.open('/userfiles/800_' + defaultBig,'displayWindow','width=600,height=800,resizeable=no,scrollbars=0,toolbar=no,top=0');
		}
	}
}


var speed = 0;
var scroll_timer = null;
function scrollMe()
{
	var s = document.getElementById('scrollTable');
	var left = strReplace(s.style.marginLeft, "px", "");
	
	left *= 1; 
	left += speed;
	
	
	if (left > 0)
	{
		left = 0;
	}
	
	if (left < s.offsetWidth * -1 + getObj('aaa').offsetWidth)
	{
		left = s.offsetWidth * -1 + getObj('aaa').offsetWidth;
	}
	
	
	s.style.marginLeft = left + "px";
	
	if (speed != 0)
	{
		scroll_timer = setTimeout("scrollMe()", 10);
	}
}
