function openAWindowScrool( pageToLoad, winName, width, height){

xposition=0; yposition=0;
if ((parseInt(navigator.appVersion) >= 4 )){
 xposition = (screen.width - width) / 8;
 yposition = (screen.height - height) / 3;
}

args = "width=" + width + ","
+ "height=" + height + ","
+ "location=0,"
+ "menubar=0,"
+ "scrollbars=1,"
+ "status=0,"
+ "titlebar=0,"
+ "screenx=" + xposition + "," //NN Only
+ "screeny=" + yposition + "," //NN Only
+ "left=" + xposition + "," //IE Only
+ "top=" + yposition; //IE Only

window.open( pageToLoad, winName, args );

}

function openPic2(img,width, height)
{
 openAWindow (img,"_blank",width,height);
// openAWindow ("/main/sert.html?num="+num,"_blank",width,height,1);
// openAWindow ("/main/picture.html?img="+img,"_blank",width,height);
}


function openAWindow( pageToLoad, winName, width, height, scroll){
xposition=0; yposition=0;
if ((parseInt(navigator.appVersion) >= 4 )){
 xposition = (screen.width - width) / 8;
 yposition = (screen.height - height) / 3;
}

args = "width=" + width + ","
+ "height=" + height + ","
+ "location=0,"
+ "menubar=0,"
+ "scrollbars="+scroll+","
+ "status=0,"
+ "resizable=yes,"
+ "titlebar=0,"
+ "screenx=" + xposition + "," //NN Only
+ "screeny=" + yposition + "," //NN Only
+ "left=" + xposition + "," //IE Only
+ "top=" + yposition; //IE Only

window.open( pageToLoad, winName, args );

}

function openPic(img)
{
// openAWindow ("/main/sert.html?num="+num,"_blank",width,height,1);
 openAWindow (img,"_blank",402,302);
}

function showAnounce( id ){
	var anounceDiv = document.getElementById('anounce'+id);
	var anounceLink = document.getElementById('anounceLink'+id);
	var linkLeft = getRelLeft( anounceLink );
	var w = (document.documentElement && document.documentElement.scrollLeft) ? document.documentElement.scrollLeft : document.body.scrollLeft;
	w += getBodyWidth();
	var left;
	if( ( linkLeft + 20 + anounceDiv.clientWidth ) < w )
		left = linkLeft + 30;
	else {
		linkLeft = getRelLeft( anounceLink );
		left = linkLeft - 20 - anounceDiv.clientWidth;
	}
	anounceDiv.style.left = left;
	var linkTop = getRelTop( anounceLink );
	var h = (document.documentElement && document.documentElement.scrollTop) ? document.documentElement.scrollTop : document.body.scrollTop;
	h += getBodyHeight();
	var top;
	if( ( linkTop + 20 + anounceDiv.clientHeight ) < h )
		top = linkTop + 30;
	else {
		linkTop = getRelTop( anounceLink );
		top = linkTop - 20 - anounceDiv.clientHeight;
	}
	anounceDiv.style.top = top;
	anounceDiv.style.visibility = 'visible';
	var shadowImg = document.getElementById('anounceBg'+id);
	shadowImg.style.width = anounceDiv.clientWidth + 36;
	shadowImg.style.height = anounceDiv.clientHeight + 33;
	shadowImg.style.top = top - 12;
	shadowImg.style.left = left - 18;
	shadowImg.style.visibility = 'visible';
}

function hideAnounce( id ){
	var anounceDiv = document.getElementById('anounce'+id);
	anounceDiv.style.visibility = 'hidden';
	var shadowImg = document.getElementById('anounceBg'+id);
	shadowImg.style.visibility = 'hidden';
}

function getRelLeft(el) {
	var pos = el.offsetLeft;
	while (el.offsetParent != null) { el = el.offsetParent; pos += el.offsetLeft; if (el.tagName == 'BODY') break; }
	return pos;
}

function getRelTop(el) {
	var pos = el.offsetTop;
	while (el.offsetParent != null) { el = el.offsetParent; pos += el.offsetTop; if (el.tagName == 'BODY') break; }
	return pos;
}

function getBodyHeight() {
	if (self.innerWidth) return self.innerHeight;
	else if (document.documentElement && document.documentElement.clientWidth) return document.documentElement.clientHeight;
	else if (document.body) return document.body.clientHeight;
}

function getBodyWidth() {
	if (self.innerWidth) return self.innerWidth;
	else if (document.documentElement && document.documentElement.clientWidth) return document.documentElement.clientWidth;
	else if (document.body) return document.body.clientWidth;
}

function startAlignDivs() {
	window.onscroll = alignDivs;
	window.onresize = alignDivs;
	alignDivs();
}

function alignDivs(){
	var gazLogo = document.getElementById('gazLogo');
	var gazCellBg = document.getElementById('gazCellBg');
	gazLogo.style.left = getRelLeft( gazCellBg ) + 75;
	gazLogo.style.visibility = "visible";
}

// url encode string
function url_encode( s )
{
  s = new String( s )
  s = s.replace( "#", "%23" )
  s = s.replace( " ", "+" )
  s = s.replace( "/", "%2F" )
  s = s.replace( "?", "%3F" )
  s = s.replace( "=", "%3D" )
  s = s.replace( "&", "%26" )
  return s;
}

function applyFilter(){
	var priceFrom = document.getElementById('priceFromFilter').value;
	var priceTo = document.getElementById('priceToFilter').value;
	var model = document.getElementById('modelFilter').value;
	var brand = document.getElementById('brandFilter').value;
	var url = '/main/index.html?id=93';
	if( brand != "" )
		url = url + '&parent_id='+brand;
	if( model != "" )
		url = url + '&model='+url_encode(model);
	if( priceFrom != "" )
		url = url + '&priceFrom='+priceFrom;
	if( priceTo != "" )
		url = url + '&priceTo='+priceTo;
	document.location.href = url;
}

function setCookie(sName, sValue)
{
  document.cookie = sName + "=" + escape(sValue) + ";expires=Mon, 3 Dec 2040 23:59:59 UTC;path=/;";
}


function getCookie(sName)
{
  // cookies are separated by semicolons
  var aCookie = document.cookie.split("; ");
  for (var i=0; i < aCookie.length; i++)
  {
    // a name/value pair (a crumb) is separated by an equal sign
    var aCrumb = aCookie[i].split("=");
    if (sName == aCrumb[0]) 
      return unescape(aCrumb[1]);
  }

  // a cookie with the requested name does not exist
  return null;
}
function unsetCookie(sName)
{
 if(getCookie(sName))
  document.cookie = sName + "=" + ";expires=Thu, 1 Jan 1970 00:00:01 GMT;path=/;";
}

