
function ShowBanner(_ele_id, _id) {
		var div_id = document.getElementById(_ele_id);
	
		/*new Ajax.Request('/show_banner.php', {
			asynchronous: true,
			method: 'post',
			postBody: 'id=' + _id,
			onSuccess: function (r) {
				div_id.innerHTML = r.responseXML.getElementsByTagName('content')[0].firstChild.nodeValue;
			
				
				//current_banner[_id] = _id;
			}
		});*/
		
		$.ajax({
		   type: "POST",
		   url: '/show_banner.php',     // this is the path from above
		   data: 'id=' + _id,
		   success: function(s) {
		     div_id.innerHTML = s.getElementsByTagName('content')[0].firstChild.nodeValue;
		   }
		});
}

function SwitchBanner(_ele_id, _without_id, _location) {
		var div_id = document.getElementById(_ele_id);
	
		/*new Ajax.Request('/show_banner.php', {
			asynchronous: true,
			method: 'post',
			postBody: 'without=' + _without_id + '&location=' + _location,
			onSuccess: function (r) {
				div_id.innerHTML = r.responseXML.getElementsByTagName('content')[0].firstChild.nodeValue;
				
				setTimeout("SwitchBanner('" + _ele_id + "', '" + r.responseXML.getElementsByTagName('id')[0].firstChild.nodeValue + "', '" + _location + "')", delay);
			}
		});*/
		
		$.ajax({
		   type: "POST",
		   url: '/show_banner.php',     // this is the path from above
		   data: 'without=' + _without_id + '&location=' + _location,
		   success: function(s) {
		     div_id.innerHTML = s.getElementsByTagName('content')[0].firstChild.nodeValue;
				
				setTimeout("SwitchBanner('" + _ele_id + "', '" + s.getElementsByTagName('id')[0].firstChild.nodeValue + "', '" + _location + "')", delay);
		   }
		});
}

function OpenNewPage(_id){
	var select = document.getElementById(_id);
	var selected_value = null;
	
	if (select.selectedIndex != -1 && select.selectedIndex != 0) {
		selected_value = select.options[select.selectedIndex].value;
	}
	
	if(selected_value != '') {
		//document.location = selected_value;
		var width = null;
		var height = null;
		if (self.screen) {
			width = screen.width
			height = screen.height
		}
		else if (self.java) {
			var jkit = java.awt.Toolkit.getDefaultToolkit();
			var scrsize = jkit.getScreenSize();
			width = scrsize.width;
			height = scrsize.height;
		}
		my_window = window.open(selected_value, "new_window", "height=" + height + ", width=" + width + ", scrollbars=yes");
	}
}

function ChooseRegion(_id, _href){
	var select = document.getElementById(_id);
	var selected_value = null;
	
	if (select.selectedIndex != -1 && select.selectedIndex != 0) {
		selected_value = select.options[select.selectedIndex].value;
	}
	
	if(selected_value != '') document.location = _href + selected_value + '/';
}

function SelectModels(){
	var select_mark = document.getElementById('selector_mark');
	var select_model = document.getElementById('selector_model');
	var selected_value = null;
	var option_item = null;
	
	if (select_mark.selectedIndex != -1 && select_mark.selectedIndex != 0) {
		selected_value = select_mark.options[select_mark.selectedIndex].value;
		select_model.options.length = 0;
		for(var j = 1; j < cars.length; j++){
			if(cars[j][0] == selected_value){
				for (var i = 1; i <= (cars[j].length - 1); i++) {
					option_item = select_model.options[select_model.options.length] = new Option(cars[j][i][1], cars[j][i][0]);
				}
			}
		}
	}
	
	select_model.disabled = false;
}

function fixPNG(element)
{
  if (/MSIE (5\.5|6).+Win/.test(navigator.userAgent))
  {
    var src;
    if (element.tagName=='IMG')
    {
      if (/\.png$/.test(element.src))
      {
        src = element.src;
        element.src = "/f/blank.gif";
        element.width = element.width;
        element.height = element.height;
      }
    }
    else
    {
      src = element.currentStyle.backgroundImage.match(/url\("(.+\.png)"\)/i);
      if (src)
      {
        src = src[1];
        element.runtimeStyle.backgroundImage="none";
      }
    }
    if (src) element.runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + src + "',sizingMethod='scale')";
  }
}

function ShowHide(_id) {
	var div = document.getElementById(_id);
	
	if(div.style.display == 'block') {div.style.display = 'none';}
	else div.style.display = 'block';
	
	return false;
}

function openImage(url, width, height, name) {
	var w = (width) ? width : 700;
	var h = (height) ? height : 560;
	var window_name = (name) ? name : 'w_' + getRandom();

	wind = window.open('', window_name, 'width=' + w + ',height=' + h + ',top=50, left=50,location=no,status=no,resizable=yes,scrollbars=no,titlebar=no');
	wind.document.writeln('<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"><style>img {border:0;} body {padding:0px; margin:0px;}</style></head><body><a href="" title="Закрыть" alt="Закрыть" onclick="window.close();"><img src="' + url + '" alt="Закрыть" /></a><div style="position:absolute; top:10px; right:10px;"><a href="" onclick="window.close();">Закрыть</a></div></body></html>');
//	wind.close();
}



function dropclose()
{
	$("#dropperdiv").hide();	
}

function dropout(o)
{
	$("#dropperdiv").empty();

	switch(o)
	{
		case "1":
	  		$("#dropperdiv").css("top","0px");
	  		$("#dropperdiv").css("left","-60px");
	  		$("#dropperdiv").append(GetId('hidden_text_1').innerHTML);	
	  		break;
	  	case "2":
	  		$("#dropperdiv").css("top","80px");
	  		$("#dropperdiv").css("left","-100px");
	  		$("#dropperdiv").append(GetId('hidden_text_2').innerHTML);
	  		break;
	  	case "3":
	  		$("#dropperdiv").css("top","17px");
	  		$("#dropperdiv").css("left","330px");
	  		$("#dropperdiv").append(GetId('hidden_text_4').innerHTML);
	  		break;
	  	case "4":
	  		$("#dropperdiv").css("top","150px");
	  		$("#dropperdiv").css("left","440px");
	  		$("#dropperdiv").append('<h3>Цвет канистры</h3><p>Каждому виду масла соответствует свой цвет канистры.</p>');
	  		break;
	  	case "5":
	  		$("#dropperdiv").css("top","290px");
	  		$("#dropperdiv").css("left","480px");
	  		$("#dropperdiv").append(GetId('hidden_text_5').innerHTML);
	  		break;
	  	case "6":
	  		$("#dropperdiv").css("top","400px");
	  		$("#dropperdiv").css("left","480px");
	  		$("#dropperdiv").append(GetId('hidden_text_6').innerHTML);
	  		break;
	  	case "7":
	  		$("#dropperdiv").css("top","280px");
	  		$("#dropperdiv").css("left","-120px");
	  		$("#dropperdiv").append(GetId('hidden_text_3').innerHTML);
	  		break;    
	}
	
	
	
	
	$("#dropperdiv").fadeIn();
}

var pre_load = new Array();


function ShowImage(_uri, _width, _height) {
	var body_height = document.getElementsByTagName('BODY')[0].offsetHeight;
	var offset = (document.layers) ? window.pageYOffset : document.documentElement.scrollTop;

	/*GetId('popup_bg').style.height = body_height + 'px';*/
	GetId('site_select').style.display = 'none';
	GetId('popup_bg').style.display = 'block';
	
	GetId('popup_image').innerHTML = '';
	
	GetId('popup_image').style.marginTop = -1 * (Math.floor(_height / 2) + 10) + 'px';
	GetId('popup_image').style.marginLeft = -1 * (Math.floor(_width / 2) + 10) + 'px';
	
	GetId('popup_image').style.width = (_width) + 'px';
	GetId('popup_image').style.height = (_height) + 'px';
	
	if(pre_load.length == 0 || !inArray(pre_load, _uri)) {
		image = new Image();
		image.src = _uri;
		
		CheckComplete(_width, _height);
		
		pre_load[pre_load.length] = _uri;
	} else {
		GetId('popup_image').innerHTML = '<img src="' + _uri + '" alt="Закрыть" width="' + _width + '" height="' + _height + '" style="cursor:pointer;" onclick="HideImage();" />';	
	}
	
	GetId('popup_image').style.display = 'block';
}

function ShowHide(_id) {
	if(document.getElementById(_id).style.display == 'none') {
		document.getElementById(_id).style.display = 'block';
	} else {
		document.getElementById(_id).style.display = 'none';
	}
}

function HideImage() {
	GetId('popup_image').innerHTML = '';
	GetId('popup_image').style.display = 'none';
	GetId('popup_bg').style.display = 'none';
	GetId('site_select').style.display = 'block';
}

function inArray(_array, _value) {
	
	for(var i = 0; i < _array.length; i++) {
		if(_array[i] == _value) {return true;}
	}
	return false;
}

function CheckComplete(_width, _height) {
	if(image.complete) {
		GetId('popup_image').innerHTML = '<img src="' + image.src + '" alt="Закрыть" width="' + _width + '" height="' + _height + '" style="cursor:pointer;" onclick="HideImage();" />';	
	} else {
		timer = setTimeout("CheckComplete(" + _width + "," + _height + ")",10);
	}
}

/* Function */

function GetId(_id) {
	return document.getElementById(_id);
}

