theObjects = document.getElementsByTagName("object");
for (var i = 0; i < theObjects.length; i++) {
	theObjects[i].outerHTML = theObjects[i].outerHTML;
}

function checkOrder(form)
{
	var fph1 = document.getElementById('fphone1');
	var fph2 = document.getElementById('fphone2');
	var uph1 = document.getElementById('uphone1');
	var uph2 = document.getElementById('uphone2');
	if (!fph1.value && !fph2.value && !uph1.value && !uph2.value) {
		alert('Пожалуйста укажите хотя бы один Телефон');
		fph1.parentNode.style.background = '#F6AEAF';
		uph1.parentNode.style.background = '#F6AEAF';
		scroll(0,0);
	} else {
		form.submit();
	}
}


function showUr()
{
	//var select = document.getElementById('faceselect');
	//select.innerHTML = '<a href="#" onclick="showFiz(); return false;">Физическое лицо</a> Юридическое лицо';
	toggle('fizface');
	toggle('urface');
}

function showFiz()
{
	//var select = document.getElementById('faceselect');
	//select.innerHTML = 'Физическое лицо <a href="#" onclick="showUr(); return false;">Юридическое лицо</a>';
	toggle('urface');
	toggle('fizface');
}


function menuOver(obj)
{
	obj.style.background='url(/img/cont/header_blue.gif) repeat-x';
	obj.style.color='#FFF';
	obj.firstChild.style.color='#FFF';
}

function menuOut(obj)
{
	obj.style.background='';
	obj.style.color='#535353';
	obj.firstChild.style.color='#535353';
}


function newsRefresh()
{
	var cont = document.getElementById('newsOne');
	var rnd  = Math.floor(Math.random()*9) + 1;
	cleanNode(cont);
	cont.appendChild(document.getElementById('newsOne' + rnd).cloneNode(true));
}

function sendAnswer()
{
	var req = new JsHttpRequest();
	document.getElementById('supportBodyRightTop').innerHTML = 'Идет отправка ответа...';
	var email = document.getElementById('supportMail').value;
	var text = document.getElementById('supportText').value;
	req.onreadystatechange = function() {
		if (req.readyState == 4) {
			if (req.responseJS) {
				document.getElementById('supportMail').value = '';
				document.getElementById('supportText').value = '';
				document.getElementById('supportBodyRightTop').innerHTML = 'Спасибо за вопрос!<br />Наши консультанты в ближайщее время ответят Вам на него.';
			}
		}
	}
	req.caching = false;
	req.open('POST', '/ajax.php', true);
	req.send({ action: 'answer', email: email, text: text});
}

function changeMedia(path, file)
{
	//document.getElementById('galleryShow').style.height='525px';
	var cont = QT_GenerateOBJECTText_XHTML(path + file , '480', '520', '', 'AUTOPLAY', 'True', 'Controller', 'False', 'Cashe', 'True', 'Showlogo', 'False') ;
	//document.getElementById('galleryShow').innerHTML = '<object width="480" height="520" type="video/quicktime" data="' + path + file + '" id="mediaQT"><param value="true" name="autoplay"/><param value="false" name="controller"/><param value="true" name="cache"/><param value="false" name="showlogo"/><param value="true" name="saveembedtags"/></object><br />';
	document.getElementById('galleryShow').innerHTML = cont;
}


function changePic(path, file)
{
	//document.getElementById('galleryShow').style.height='200px';
	document.getElementById('galleryShow').innerHTML = '<img src="/image/' + path + file + '" />';
}

function setElementOpacity(oElem, nOpacity)
{
	var p = getOpacityProperty();
	(setElementOpacity = p=="filter"?new Function('oElem', 'nOpacity', 'nOpacity *= 100;	var oAlpha = oElem.filters["DXImageTransform.Microsoft.alpha"] || oElem.filters.alpha;	if (oAlpha) oAlpha.opacity = nOpacity; else oElem.style.filter += "progid:DXImageTransform.Microsoft.Alpha(opacity="+nOpacity+")";'):p?new Function('oElem', 'nOpacity', 'oElem.style.'+p+' = nOpacity;'):new Function)(oElem, nOpacity);
}

function delLast()
{
	var cont = document.getElementById('newsRefresh');
	cont.removeChild(cont.lastChild);
}

function addFirst()
{
	var cont = document.getElementById('newsRefresh');
	var el = document.createElement('div');
	el.innerHTML = 'news refresh test';
	cont.insertBefore(el, cont.firstChild);
}

function icq_submit(event){
	if (event.keyCode==13 && event.ctrlKey) {
		document.getElementById('compose').submit();
	}
}

function fromCart(goods)
{
	var req = new JsHttpRequest();
	req.onreadystatechange = function() {
		if (req.readyState == 4) {
			if (req.responseJS) {
				var cart	= document.getElementById('cartBody');
				var del		= document.getElementById('cartGoods' + goods);
				cart.removeChild(del);
				if (! req.responseJS.sum) {
					//cart.removeChild(document.getElementById('cartGoodsShirt'));
					cart.removeChild(document.getElementById('cartGoodsCare'));
					document.getElementById('cartSum').innerHTML = '<div style="text-align:center;font-style:italic;color:#999;">пока ничего нет</div>';
				} else {
					document.getElementById('cartSum').innerHTML = 'всего: <b>' + req.responseJS.sum + ' руб.</b><br /><a href="/cart/"><img style="padding-top:0.6em; border:0;" alt="оформить заказ" src="/img/cart/custom.gif"/></a>';
				}

				// @TODO: Удаление и из большой корзины тоже
			}
		}
	}
	req.caching = false;
	req.open('POST', '/ajax.php', true);
	req.send({ action: 'fromCart', goods: goods});
}

function sendCartForm()
{
	var req = new JsHttpRequest();
	var name = document.getElementById('cartFormName').value;
	var contact = document.getElementById('cartFormContact').value;
	var ext = document.getElementById('cartFormExt').value;

	req.onreadystatechange = function() {
		if (req.readyState == 4) {
			if (req.responseJS) {
				var cart = document.getElementById('cartBody');
				var cont = document.createElement("div");
				cont.setAttribute('class', 'cartEl');
				cont.setAttribute('id', 'cartGoods' + goods);
				cont.setAttribute('className', 'cartEl');
				cont.innerHTML = req.responseJS.t;

				cart.insertBefore(cont, document.getElementById('cartSum'));
				document.getElementById('cartSum').innerHTML = 'всего: <b>' + req.responseJS.sum + ' руб.</b>';
			}
		}
	}
	req.caching = false;
	req.open('POST', '/ajax.php', true);
	req.send({ action: 'sendCartForm', name: name, contact: contact, ext: ext});
}

function inCart(goods)
{
	var req = new JsHttpRequest();
	req.onreadystatechange = function() {
		if (req.readyState == 4) {
			if (req.responseJS) {
				var cart = document.getElementById('cartBody');
				var cont = document.createElement("div");
				cont.setAttribute('class', 'cartEl');
				cont.setAttribute('id', 'cartGoods' + goods);
				cont.setAttribute('className', 'cartEl');
				cont.innerHTML = req.responseJS.t;

				if (! document.getElementById('cartGoodsCare')) {
					var care = document.createElement("div");
					care.setAttribute('class', 'cartEl');
					care.setAttribute('id', 'cartGoodsCare');
					care.setAttribute('className', 'cartEl');
					care.innerHTML = req.responseJS.icare;
					cart.insertBefore(care, document.getElementById('cartSum'));
				}
				cart.insertBefore(cont, document.getElementById('cartGoodsCare'));
				document.getElementById('cartSum').innerHTML = 'всего: <b>' + req.responseJS.sum + ' руб.</b><br /><a href="/cart/"><img style="padding-top:0.6em; border:0;" alt="оформить заказ" src="/img/cart/custom.gif"/></a>';
				location.href = 'http://www.istoreone.ru/cart/';
			}
		}
	}
	req.caching = false;
	req.open('POST', '/ajax.php', true);
	req.send({ action: 'inCart', goods: goods});
}

function showCartForm()
{
	if (document.body.style.overflow != 'hidden') {
		document.body.style.overflow = 'hidden';
	} else {
		document.body.style.overflow = '';
	}
	if (toggle('cartPanel')) {
		toggle('cartInner');
	} else {
		toggle('cartInner');
	}
	return false;
}

function showCare()
{
	if (document.body.style.overflow != 'hidden') {
		document.body.style.overflow = 'hidden';
	} else {
		document.body.style.overflow = '';
	}
	if (toggle('carePanel')) {
		toggle('careInner');
	} else {
		toggle('careInner');
	}
	return false;
}

function cleanNode(dest) {
	var child;
	while (child = dest.firstChild) {
		dest.removeChild(child);
	}
}

function showPanel()
{
	if (document.body.style.overflow != 'hidden') {
		document.body.style.overflow = 'hidden';
	} else {
		document.body.style.overflow = '';
	}
	if (toggle('supportPanel')) {
		toggle('supportInner');
	} else {
		toggle('supportInner');
	}
	return false;
}

function toggle(obj)
{
	var el = document.getElementById(obj);
	if ( el.style.display != 'none' ) {
		el.style.display = 'none';
		return false;
	} else {
		el.style.display = '';
		return true;
	}
}

///
var slideMenu=function(){
	var sp,st,t,m,sa,l,w,gw,ot;
	return{
		build:function(sm,sw,mt,s,sl,h){
			sp=s; st=sw; t=mt;
			m=document.getElementById(sm);
			sa=m.getElementsByTagName('li');
			l=sa.length; w=m.offsetWidth; gw=w/l;
			ot=Math.floor((w-st)/(l-1)); var i=0;
			for(i;i<l;i++){s=sa[i]; s.style.width=gw+'px'; this.timer(s)}
			if(sl!=null){m.timer=setInterval(function(){slideMenu.slide(sa[sl-1])},t)}
		},
		timer:function(s){
			s.onmouseover=function(){clearInterval(m.htimer);clearInterval(m.timer);m.timer=setInterval(function(){slideMenu.slide(s)},t)}
			s.onmouseout=function(){clearInterval(m.timer);clearInterval(m.htimer);m.htimer=setInterval(function(){slideMenu.slide(s,true)},t)}
		},
		slide:function(s,c){
			var cw=parseInt(s.style.width);
			if((cw<st && !c) || (cw>gw && c)){
				var owt=0; var i=0;
				for(i;i<l;i++){
					if(sa[i]!=s){
						var o,ow; var oi=0; o=sa[i]; ow=parseInt(o.style.width);
						if(ow<gw && c){oi=Math.floor((gw-ow)/sp); oi=(oi>0)?oi:1; o.style.width=(ow+oi)+'px';
						}else if(ow>ot && !c){oi=Math.floor((ow-ot)/sp); oi=(oi>0)?oi:1; o.style.width=(ow-oi)+'px'}
						if(c){owt=owt+(ow+oi)}else{owt=owt+(ow-oi)}}}
						s.style.width=(w-owt)+'px';
			}else{clearInterval(m.timer);clearInterval(m.htimer)}
		}
	};
}();

