function OnError(i1, i2, i3){
	errorOnPage = true;
	alert("Javascript error: "+i1+"\n\n Url: "+i2+"\n Line: "+i3+"\n");
	return false;
}
window.onerror = OnError;

function checkField(name, label, fullText){
	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 == ''){
		current.focus();
		if (fullText) alert(label);
		else alert('Пожалуйста заполните поле "' + label + '"');
		return false;
	}
	return true;
}


function checkForm(formName){
	if (formName == 'car'){
		if (checkField('name', 'Имя')==false) return false;
		if (checkField('mail', 'E-mail')==false) return false;
		if (checkField('city', 'Город')==false) return false;
		if (checkField('car', 'Машина')==false) return false;
		return true;
	} else alert('Error: function checkForm - wrong form name "' + formName + '"');

	return false;
}

function imgWin(img){
	var scr='/images/preview.htm';
	var x = screen.width/2 - 400/2;
	var y = screen.height/2 - 300/2;
	var wn=window.open(scr+'?'+escape(img),'win','resizable,width=400,height=300,top='+y+',left='+x+',screenX='+x+',screenY='+y+',status=0');
	wn.focus();
	return false;
}

function isInteger(val){
	if (!val) return false;
	var string="1234567890";

	for(var i=0; i<val.length; i++){
		if (string.indexOf( val.charAt(i) ) == -1) return false;
	}
	return true;
}

function calc(mode){
	var i1 = document.getElementsByName('form_i1')[0];
	var i2 = document.getElementsByName('form_i2')[0];
	var ss = document.getElementById('submit_form');
	if (!isInteger(i2.value)) {
		if (mode){
			alert('People must be integer');
			i2.focus();
		}
		ss.innerHTML = '&nbsp;';
	} else {
		var r = i2.value * 1.0;
		if (i1.value == 1) r = r * 1.0 * 1.5;
		if (i1.value == 3) r = r * 1.0 * 1.75;
		ss.innerHTML = 'Total amount of Ice needed: ' + r + ' lb'
	}
}





function clickImg(el){
	var element = document.getElementById('bigPicture');
	return imgWin('/' + fullPictures[currentIndex]);
}




var currentIndex = 1;
function loadPicture(index){
	var element = document.getElementById('bigPicture');
	var previewElement = document.getElementById('preview_'+currentIndex);
	var previewNewElement = document.getElementById('preview_'+index);

	var url = bigPictures[index];
	var href = element.parentNode;

	if ( !url ) {
		url = '/images/skin/no_foto.png';
	}
	href.href = url;
	element.src = url;
	currentIndex = index;

	if ( !previewElement ) return;
	if ( !previewNewElement ) return;
	previewElement.className = 'i';
	previewNewElement.className = 'i selected';
}



function loginForm(id, mode){
	document.getElementById(id).style.display = mode;
	return false;
}






var flashVersion = 0;
var defErrorHandle = window.onerror;

function Flash () {
	this._swf = '';
	this._width = 0;
	this._height = 0;
	this._params = new Array();
}


Flash.prototype.setSWF = function (_swf, _width, _height){
	this._swf = _swf;
	this._width = _width;
	this._height = _height;
}


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+'">\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"></embed>\n';
	_txt += '</object>\n';
	
	document.write ('<div class="eye_flash">' + _txt + '</div>');
	return true;
}


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++) {
			if (eval('new ActiveXObject("ShockwaveFlash.ShockwaveFlash.'+i+'")')) {
				flashVersion = i;
			}
		}
	}


	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;
