try
{
	document.execCommand('BackgroundImageCache', false, true);
}
catch(e)
{
}

function IsIE() {
  return (navigator.appName.indexOf('Microsoft', 0) > -1);
}

var is_ie = IsIE();


if (typeof(WWW_ROOT) == 'undefined')
	var WWW_ROOT = '/';


function ctl_by_id(id){
	return document.getElementById(id);
}

function loadPicture(index){
	var element = document.getElementById('bigPicture');
	var url = bigPictures[index];

	if ( !url ) {
		url = WWW_ROOT + 'images/skin/no_foto.png';
	}
	element.src = url;
}

function calcFrameHeight(f)
{
	//var f = document.getElementById('frame')
	var height = f.contentWindow.document.body.scrollHeight;
	f.height = height + 25; // Запас для горизонтальной прокрутки

	if (navigator.appName == 'Netscape' /*|| navigator.appName == 'Opera'*/) // В опереглючит
	{
		var f_childs = f.contentWindow.document.childNodes;
		var new_height = 0;
	
		for (var i = 0; i < f_childs.length; i++)
		{
			new_height += f_childs[i].clientHeight;
		}
		if (new_height > 0) f.height = new_height + 25;
	}

	if (lbl = ctl_by_id('waitlabel'))
	{
		lbl.style.display = 'none';
	}
}

function checkRegisterForm()
{
	var f = document.forms('register');
	
	if (f.name.value == '')
	{
		alert('Вы не ввели свое имя!');
		return false;
	}
	if (f.surname.value == '')
	{
		alert('Вы не ввели свою фамилию!');
		return false;
	}
	if (f.fathername.value == '')
	{
		alert('Вы не ввели свое отчество!');
		return false;
	}
	if (f.email.value == '')
	{
		alert('Вы не ввели свой E-mail!');
		return false;
	}
	if (f.phone.value == '')
	{
		alert('Вы не ввели свой телефон!');
		return false;
	}
	return true;
}




function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}



function MM_showHideLayers() { //v6.0
	var i,p,v,obj,args=MM_showHideLayers.arguments;
	for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
	if (obj.style) { obj=obj.style; v=(v=='show')?'block':(v=='hide')?'none':v; }
	obj.display=v; }
}

function carsClassShow() {
	var el = document.getElementById('carsClass');

	var f_childs = document.getElementById('carsYears').childNodes;
	for (var i = 0; i < f_childs.length; i++) {
		if (f_childs[i].tagName == 'P') f_childs[i].style.display = 'none';
	}

	if (el.value == '') return;

	var cl = el.options[el.selectedIndex].className;
	var ca = document.getElementById(cl);
	if (ca) ca.style.display = 'block';
}

function calcCar($y, $d) {
	calcAuc = document.getElementById('calcAuc');
	carsClass = document.getElementById('carsClass');
	aucPrice = document.getElementsByName('aucPrice')[0];

	if (calcAuc.value == '') {
		alert("Вы должны выбрать название аукциона");
		return false;
	}

	if (carsClass.value == '') {
		alert("Вы должны выбрать класс автомобиля");
		return false;
	}

	if (aucPrice.value == '') {
		alert("Вы должны указать стоимтость на аукционе");
		return false;
	}

	var f_childs = document.getElementById('carsYears').childNodes;
	var carPrice = -1;
	for (var i = 0; i < f_childs.length; i++) {
		if (f_childs[i].tagName == 'P' && f_childs[i].style.display != 'none'){
			var sel = f_childs[i].childNodes[1];
			carPrice = sel.value;
		}
		
	}
	
//	var yTOd = ( ((aucPrice.value/100) * $y) / $d );

	var yTOd = (aucPrice.value / $y);
	
	var sum = parseFloat(calcAuc.value);
	sum = parseFloat(sum) + parseFloat(carPrice);
	sum = parseFloat(sum) + parseFloat(yTOd);
	sum = Math.round(sum) + 1;

	r = document.getElementById('res');
	r.innerHTML = '' + 
	'<h3>Исходные данные</h3>'+
	'<p>'+
	'<span>Аукцион:</span> ' + calcAuc.options[calcAuc.selectedIndex].title + '<br/>'+
	'<span>Класс автомобиля:</span> ' + carsClass.options[carsClass.selectedIndex].title + '<br/>'+
	'<span>Год выпуска:</span> ' + carYear + '<br/>'+
	'<span>Стоимость на аукционе:</span> ' + aucPrice.value + ' &yen;<br/>'+
	'</p>'+
	'<h3>Результат расчета</h3>'+
	'<p>Цена собранной машины во Владивостоке: <span style="color: red; font-size: 1.1em;">' + sum + ' $</span></p>';
	
	r.style.display = 'block';
}




function calcCar2($y, $d) {
	calcAuc = document.getElementById('calcAuc');
	carsClass = document.getElementById('carsClass');
	aucPrice = document.getElementsByName('aucPrice')[0];

	if (aucPrice.value == '') {
		alert("Вы должны указать стоимтость на аукционе");
		return false;
	}
	if (carsClass.value == '') {
		alert("Вы должны выбрать класс автомобиля");
		return false;
	}
	if (calcAuc.value == '') {
		alert("Вы должны выбрать название аукциона");
		return false;
	}

	var aucPrice1 = calcAuc.value.split('|')[0];
	var aucPrice2 = calcAuc.value.split('|')[1];

	$y = parseFloat($y);
	$d = parseFloat($d);
	var A = parseFloat(aucPrice.value) / $y * 1.2;
	var B = A + parseFloat(carsClass.value);
	var C = Math.round(B + (aucPrice2 / $y));
	var D = Math.round(C*$d);
	
	//alert(A+'\r\n'+B+'\r\n'+C+'\r\n'+$y+'\r\n'+$d);
	//alert($y+'\r\n'+$d+'\r\n'+carsClass.value+'\r\n'+aucPrice1+'\r\n'+aucPrice2);

	r = document.getElementById('res');
	r.innerHTML = '' + 
	'<h3>Исходные данные</h3>'+
	'<p>'+
	'<span>Аукцион:</span> ' + calcAuc.options[calcAuc.selectedIndex].title + '<br/>'+
	'<span>Класс автомобиля:</span> ' + carsClass.options[carsClass.selectedIndex].title + '<br/>'+
	'<span>Стоимость на аукционе:</span> ' + aucPrice.value + ' &yen;<br/>'+
	'</p>'+
	'<h3>Результат расчета</h3>'+
	'<p>Предварительный расчет стоимости автомобиля под ПТС во Владивостоке: <span style="color: red; font-size: 1.1em;">' + C + ' $ ('+D+' руб.)</span></p>';
	r.style.display = 'block';
}



var redir_location = '';
var stop_redir = false;

function __redir()
{
	if (stop_redir)
	{
		stop_redir = false;
	}
	else
	{
		location.href = redir_location;
	}
}

function redirect($location, $timeout)
{
	stop_redir = false;
	redir_location = $location;
	setTimeout(__redir, ($timeout >= 0) ? $timeout : 10000);
}

// Если у нас на странице стоит редирект, то при клике на любую другую ссылку пока 
// браузер ждет ответа сервера все-равно сработает функция редиректа и браузер уйдет по 
// редиректу, а не туда, куда кликнул пользователь.
function stop_redirect() 
{
	stop_redir = true;
}




function bodyOnClick(event)
{
	if (!event)
		event = window.event;
	if (typeof(event.srcElement) != 'undefined')
	{
		var e = event.srcElement;
	}
	else
	{
		var e = event.target; // Для мозиллы
	}

	if (typeof(e) != 'undefined')
	{
		if (e.tagName == "A") 
			stop_redirect();
		//alert(e.tagName);
	}
}






var checking_form;
var skip_lost;


function checkField2(name, label, minvalue)
{
	if (typeof(minvalue) == 'undefined')
		var minvalue = 1;
	var ctl = checking_form.elements[name];
	if (typeof(ctl) != 'object')
		ctl = false;

	if (ctl && typeof(ctl.length) == 'undefined')
	{
		if (ctl.value.length < minvalue) {
			if (minvalue == 1)
				var s = 'Вы должны заполнить поле  "' + label + '"';
			else
				var s = 'Поле "' + label + '" заполнено неверно';
				//var s = 'Поле "' + label + '" должно иметь не менее ' + minvalue + ' символов';
			alert(s);
			return false;
		}
	}
	else
	{
		if (!skip_lost)
		{
			alert('Field "' + name + '" was not found');
			return false;
		}
	}
	return true;
}


function checkForm2(formName, _skip_lost)
{
	if (typeof(_skip_lost) == 'undefined')
		var _skip_lost = 0;
	skip_lost = Number(_skip_lost);
	checking_form = document.forms[formName];
	if (!checking_form) return true;

	switch (formName)
	{
	case 'register':
		if (
		    !checkField2('name', 'Ваше имя', 2) ||
		    !checkField2('surname', 'Фамилия', 2) ||
		    !checkField2('fathername', 'Отчество', 2) ||
		    !checkField2('email', 'E-Mail', 6) ||
		    !checkField2('phone', 'Телефон', 6) ||
		    !checkField2('city', 'Город')
		) return false;
		break;

	case 'catalog':
		if (
		    !checkField2('name', 'Ваше имя', 2) ||
		    !checkField2('surname', 'Фамилия', 2) ||
		    !checkField2('fathername', 'Отчество', 2) ||
		    !checkField2('email', 'E-Mail', 6) ||
		    !checkField2('phone', 'Телефон', 6) //||
		    //!checkField2('city', 'Город')
		) return false;
		break;

	case 'ask':
		if (
		    !checkField2('name', 'Ваше имя', 2) ||
		    !checkField2('surname', 'Фамилия', 2) ||
		    !checkField2('fathername', 'Отчество', 2) ||
		    !checkField2('email', 'E-Mail', 6) ||
		    !checkField2('phone', 'Телефон', 6) ||
		    //!checkField2('city', 'Город')
		    !checkField2('adv', 'Вопрос', 10)
		) return false;
		break;	
	
	case 'car_order':
		if (
		    /*!checkField2('c_type', 'Тип оформления') ||*/
		    !checkField2('name', 'Ваше имя', 2) ||
		    !checkField2('surname', 'Фамилия', 2) ||
		    !checkField2('fathername', 'Отчество', 2) ||
		    !checkField2('email', 'E-Mail', 6) ||
		    !checkField2('phone', 'Телефон', 6) ||
		    /*!checkField2('firm', 'Производитель') ||
		    !checkField2('model', 'Модель') ||*/
		    !checkField2('body', 'Модель кузова') ||
		    !checkField2('volume', 'Объем двигателя') ||
		    /*!checkField2('fuel', 'Тип топлива') ||*/
		    !checkField2('year', 'Год выпуска') ||
		    /*!checkField2('trans', '') ||
		    !checkField2('drive', '') ||*/
		    !checkField2('km', 'Максимальный пробег') ||
		    !checkField2('auc_mark', 'Желаемая аукционная оценка') ||
		    !checkField2('max_price', 'Максимальный бюджет')
		) return false;
		break;
	}
}



function checkField(name, label){
	if (name=='' || label=='') return true;
	var current = '';
	for(i=0; i<document.getElementsByName(name).length; i++) {
		current = document.getElementsByName(name).item(i);
		if (current.tagName == 'input') break;
	}

	if (current == ''){
		alert("Error: can't find input - " + name);
		return false;
	}
	if (current.value == ''){
		alert('Вы должны заполнить поле  "' + label + '"');
		return false;
	}
	return true;
}



function checkForm(formName){
	if (formName == 'catalog'){
		if (checkField('name', 'Ваше имя')==false) return false;
		if (checkField('phone', 'Телефон')==false) return false;
	}
	if (formName == 'faq'){
		if (checkField('n', 'Ваше имя')==false) return false;
		if (checkField('e', 'Ваш e-mail')==false) return false;
		if (checkField('q', 'Ваш вопрос')==false) return false;
	}
	if (formName == 'ask'){
		if (checkField('name2', 'Ваше имя')==false) return false;
		if (checkField('phone2', 'Телефон')==false) return false;
		if (checkField('adv', 'Вопрос')==false) return false;
	}
	
	if (formName == 'car_order'){
		if (checkField('fio', 'Фамилия')==false) return false;
		if (checkField('name', 'Имя')==false) return false;
		if (checkField('city', 'Город')==false) return false;
		if (checkField('phone', 'Телефон')==false) return false;
		if (checkField('mail', 'E-mail')==false) return false;
		if (checkField('a_price2', 'Максимальный бюджет для этой покупки')==false) return false;
	}
	
	
	
	return true;
}



function showElementsOnLogin(hide)
{
	// Если НЕ эксплорер - то ничего не делаем, ибо только в нем глюк с комбобоксами
	if (!is_ie)
		return;
	//var els_id = Array('calcAuc', 'carsClass', 'calcForm');
	var els_id = Array('calcForm');
	for (idx in els_id)
	{
		var ctl = ctl_by_id(els_id[idx]);
		if (typeof(ctl) == 'object' && ctl != null)
		{
			if (hide)
			{
				ctl.style.old_display = ctl.style.display;
				ctl.style.display = 'none'; 
			}
			else
			{
				ctl.style.display = ctl.style.old_display;
			}
		}
	}
}



function showLogin(redir_idx)
{
	var f_name = 'float_login_form';
	var f = document.forms[f_name];
	var redir = f.elements['redirect'];
	var timeout = f.elements['timeout'];
	var title = f.elements['redirect_title'];
	
	if (typeof(redir_idx) == 'undefined')
		var redir_idx = 0;
	var loc = '';
	var timeout = '';
	var title = '';
	switch (redir_idx)
	{
	case 1:
		loc = WWW_ROOT + 'user/aucaccess';
		break;
	case 2:
		loc = WWW_ROOT + 'user/history';
		break;
	}
	
	if (loc != '')
	{
		redir.value = loc;
	}
		
	document.getElementById('loginForm').style.display = 'block';
	
	showElementsOnLogin(true);
}


function hideLogin()
{
	document.getElementById('loginForm').style.display = 'none';
	showElementsOnLogin(false);
}






































function changeSize(height){
	var el1 = document.getElementById('HIGASHI_FLASH');
	if (!el1) {
		alert('Error: can not find object with id=HIGASHI_FLASH');
	}else el1.height = height;

	var el1 = document.getElementById('HIGASHI_FLASH2');
	if (el1) el1.height = height;

	var el2 = document.getElementById('iframe');
	if (!el2) {
		alert('Error: can not find object with id=iframe');
	} else {
		if (el2.style.display == 'none') {
			el2.style.display = 'block';
			el2.height = 200;
			calcFrameHeight2('iframe');
		}
	}
}


function calcFrameHeight2(id)
{
	var f = document.getElementById(id)
	var height = f.contentWindow.document.body.scrollHeight;
	f.height = height + 25; // Запас для горизонтальной прокрутки

	if (navigator.appName == 'Netscape' /*|| navigator.appName == 'Opera'*/) // В опереглючит
	{
		var f_childs = f.contentWindow.document.childNodes;
		var new_height = 0;
	
		for (var i = 0; i < f_childs.length; i++)
		{
			new_height += f_childs[i].clientHeight;
		}
		if (new_height > 0) f.height = new_height + 25;
	}
}










var flashVersion = 0;
var defErrorHandle = window.onerror;

function Flash () {
	this._swf = '';
	this._width = 0;
	this._height = 0;
	this._params = new Array();
	this._divClass = '';
}


Flash.prototype.setSWF = function (_swf, _width, _height, _divClass){
	this._swf = _swf;
	this._width = _width;
	this._height = _height;
	this._divClass = _divClass;
}


Flash.prototype.setParam = function (paramName, paramValue){
	this._params[this._params.length] = paramName+'|||'+paramValue;
}


Flash.prototype.display = function () {
	if (flashVersion < 6) return false;
	
	var _txt = '';
	var params = '';
	var _param = '';
	var i = 0;

	_txt += '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="'+this._width+'" height="'+this._height+'" id="'+this._divClass+'">\n';
	_txt += '<param name="movie" value="'+this._swf+'" />\n'
	_txt += '<param name="quality" value="high" />\n';
	for ( i=0;i<this._params.length;i++ ) {
		_param = this._params[i].split ('|||');
		_txt += '\t<param name="'+_param[0]+'" value="'+_param[1]+'" />\n';
		_txt += '\t<param name="menu" value="false" />\n';
		params += _param[0]+'="'+_param[1]+'" ';
	}

	_txt += '<embed menu="false" width="'+this._width+'" height="'+this._height+'" src="'+this._swf+'" '+params+' quality="high" type="application/x-shockwave-flash" id="'+this._divClass+'2"></embed>\n';
	_txt += '</object>\n';
	
	document.write (_txt);
}


function GetFlashVersion() {
	// GetFlashVersion - must be last function in file 
	window.onerror = function() {
		return true;
	}
	var ie=0
	var fz=0
	var n=navigator

	if (n.platform=='Win32' && !window.opera && n.appName!='Netscape') {
		ie=1
		for (var i=3;i<10;i++) {
			try
			{
				if (eval('new ActiveXObject("ShockwaveFlash.ShockwaveFlash.'+i+'")')) {
					flashVersion = i;
				}
			}
			catch(e)
			{
			}
		}
	}


	if ((ie==0)&&(n.plugins)) {
		for (var i=0;i<n.plugins.length;i++) {
			if (n.plugins[i].name.indexOf('Flash')> -1) {
				fz = parseInt(n.plugins[i].description.charAt(16));
				if (fz > flashVersion) flashVersion = fz;
			}
		}
	}
}
GetFlashVersion();
window.onerror = defErrorHandle;


