var fx = false;
//var fx_text = '';
var flashVersion = 0;
var isOpera = Boolean(window["opera"]);
var isIE = (navigator.userAgent.indexOf("MSIE") != -1) && !isOpera;


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 getCookie(name){
	var cname = name + "="; 
	var dc = document.cookie; 
	var begin = '';
	var end = '';
	if (dc.length > 0) { 
		begin = dc.indexOf(cname); 
		if (begin != -1) { 
			begin += cname.length; 
			end = dc.indexOf(";", begin);
			if (end == -1) end = dc.length;
			return unescape(dc.substring(begin, end));
		} 
	}
	var blank = "";
	return blank;
}

function setCookie(name, value) {
	var expires = new Date ();
	expires.setTime (expires.getTime() + (24 * 60 * 60 * 1000 * 365));
	document.cookie = name + "=" + escape(value) + ((expires != null) ? "; expires=" + expires.toGMTString() : "") + "; path=/";
}


function selectYear(y){
	var i = document.getElementById('history_img');
	var i2 = document.getElementById('history_img2');
	i.style.backgroundImage = 'url(/images/history/'+y+'.jpg)';

	var f = document.getElementById('iframe');
	f.src = '/images/history/'+y+'.php';

	if (y == 2007){
		i.style.display = 'none';
		i2.style.display = 'block';
		makeCall();
	} else {
		i.style.display = 'block';
		i2.style.display = 'none';
	}
	f.style.display = 'block';
	//alert(y);
}


function makeCall() {
	try{
	getSWF("swf2007").asFunc('');
	} catch(e){}
}


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++)
		{
			if (f_childs[i].clientHeight > 0) new_height += f_childs[i].scrollHeight;
		}
		if (new_height > 0) f.height = new_height + 25;
	}
}


var ill = getCookie('ill_num');
if (ill == '') ill = 1;
ill++;
if (ill > 3) ill = 1;
setCookie('ill_num', ill);

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 == 'faq'){
		if (checkField('name', 'Ваше имя')==false) return false;
		if (checkField('mail', 'E-mail')==false) return false;
		if (checkField('q', 'Вопрос')==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 calc2(mode){
	var c1 = document.getElementById('c1');
	var c2 = document.getElementById('c2');
	var c3 = document.getElementById('c3');

	var i1 = document.getElementById('i1');
	var i2 = document.getElementById('i2');
	var i3 = document.getElementById('i3');
	var r = document.getElementById('calc_res');

	var summ = 0;

	if (c1.checked) summ = summ + (parseInt(i1.value * 1.0) * 2.0)
	if (c2.checked)	summ = summ + (parseInt(i2.value * 1.0) * 2.5);
	if (c3.checked)	summ = summ + (parseInt(i3.value * 1.0) * 2.75);

	r.innerHTML = summ + ' lb.';
}



function clickImg(el){
	var element = document.getElementById('bigPicture');
	return imgWin('/' + fullPictures[currentIndex]);
}


function setHook(){
	var el = document.getElementsByName('hookEx')[0];
	el.value = 'true';
}


function getSWFxxx(name){
	//return (navigator.appName.indexOf("Microsoft") != -1) ? window["cube"] : document["cube"];
	var  opera= Boolean(window["opera"]);
	var MSIE = (navigator.userAgent.indexOf("Microsoft") != -1) && !opera;
	var flash = MSIE ?   window[name] : document[name];
	return flash;
}

function stop(name){
	try{
	var swf = getSWFxxx(name);
	getSWFxxx(name).pauseVideo();
	} catch (e) { }
}

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 fx_div = document.getElementById('fx_div');
	//var fx_swf = document.getElementById('fx_swf');

	if ( !previewElement ) return;
	if ( !previewNewElement ) return;

	previewElement.className = 'i';
	previewNewElement.className = 'i selected';
		    
	if ( !url ) {
		url = '/images/skin/no_foto.png';
	}

	// var href = element.parentNode;
	// href.href = url;

	if (fx && index == 1){
		//if (fx_text == '') fx_text = fx_div.innerHTML;
		//if (fx_div.innerHTML == '') fx_div.innerHTML = fx_text;
		if (fx_div) fx_div.style.display = 'block';
		if (element) element.style.display = 'none';
	} else
	if (fx) {
		//if (fx_text == '') fx_text = fx_div.innerHTML;
		//fx_div.innerHTML = '';
		stop('fx_swf');
		if (fx_div) fx_div.style.display = 'none';
		//getSWF('fx_swf').pauseVideo();
		if (element) element.style.display = 'block';
	}

	if (element) element.style.background = 'url("'+url+'") center center no-repeat';
	currentIndex = index;
}







function Flash(name) {
	this._swf = '';
	this._params = new Array();
	this._attributes = new Array();
	this._spliter = '|||';
	this._htmlBefore = '';
	this._htmlAfter = '';
	if (name){
		if (isIE) this.setAttribute('id', name);
		else this.setAttribute('name', name);
	}
}

Flash.prototype.setSWF = function (_swf, _width, _height){
	this._swf = _swf;
	this.setAttribute('width', _width);
	this.setAttribute('height', _height);
}

Flash.prototype.setParam = function (paramName, paramValue){
	this._params[this._params.length] = paramName+this._spliter+paramValue;
}

Flash.prototype.setAttribute = function (attributeName, attributeValue){
	this._attributes[this._attributes.length] = attributeName+this._spliter+attributeValue;
}

Flash.prototype.getAttributeFromArray = function(arr){
	var attributes = '';
	var attribute = '';
	for (var i=0;i<arr.length;i++ ) {
		attribute = arr[i].split(this._spliter);
		attributes += attribute[0] + '="' + attribute[1] + '" ';
	}
	return attributes;
}

/* указывает html обвертку для flash */
Flash.prototype.inHtml = function(html){
	var parts = html.split(this._spliter);
	this._htmlBefore = parts[0];
	this._htmlAfter = parts[1];
}

Flash.prototype.display = function(alertTxt) {
	var attributes = this.getAttributeFromArray(this._attributes);
	var params = this.getAttributeFromArray(this._params);

	var _txt = this._htmlBefore;
	_txt += '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" '+attributes+'>\n';
	_txt += '<param name="movie" value="'+this._swf+'" />\n'
	_txt += '<param name="quality" value="high" />\n';
	_txt += '<param name="menu" value="false" />\n';

	var _param = '';
	var i = 0;
	for (var i=0;i<this._params.length;i++ ) {
		_param = this._params[i].split ('|||');
		_txt += '\t<param name="'+_param[0]+'" value="'+_param[1]+'" />\n';
	}

	_txt += '<embed menu="false" '+attributes+' src="'+this._swf+'" '+params+' quality="high" type="application/x-shockwave-flash"></embed>\n';
	_txt += '</object>\n';
	_txt += this._htmlAfter;
	if (alertTxt) alert(_txt);
	document.write(_txt);
}

function getSWF(name){
	if (isOpera) return document[name];
	return isIE ? window[name] : document[name][1];
}

/* GetFlashVersion - must be last function in file */
function GetFlashVersion() {
	try {
		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;
				}
			}
		}
	} catch(e) {}
	if (flashVersion == 1) flashVersion = 10;
}
GetFlashVersion();
