
//dv = document.getElementById('test');

function showLoad(id)
{

	dv = document.getElementById(id);
	//alert(dv.style.opacity);
	//dv.style.display='inline';
	if(parseFloat(dv.style.opacity)<1)
	{
		dv.style.opacity=parseFloat(dv.style.opacity)+0.05 ;
		dv.style.filter='alpha(opacity='+(parseFloat(dv.style.opacity)*100)+')' ;
		//alert(dv.style.filter);
		setTimeout('showLoad("'+id+'");',1);
	}

}
function stopLoad(id,sLink)
{

	dv = document.getElementById(id);
	//dv.style.display='inline';
	if(parseFloat(dv.style.opacity)>0)
	{
		//alert(dv.style.opacity);
		dv.style.opacity=parseFloat(dv.style.opacity)-0.1;
		dv.style.filter='alpha(opacity='+(parseFloat(dv.style.opacity)*100)+')' ;
		setTimeout('stopLoad("'+id+'","'+sLink+'");',1);
	}
	else {
		location.replace(sLink);
	}

}
function startFade(id)
{

	//dv=obj;
	//alert('yoo');
	//document.getElementById(textId).style.color='white';
	dv = document.getElementById(id);
	if(parseFloat(dv.style.opacity)==0)
	setTimeout('showLoad("'+id+'");',1);

}
function endFade(id,sLink)
{
	//document.getElementById(textId).style.color='#999';
	//dv=obj;
	//alert('yoo');
	dv = document.getElementById(id);
	//if( parseFloat(dv.style.opacity)==1)
	setTimeout('stopLoad("'+id+'","'+sLink+'");',1);

}










function showLoadImage(id,sLimit)
{

	dv = document.getElementById(id);
	//alert(dv.style.opacity);
	//dv.style.display='inline';
	if(parseFloat(dv.style.opacity)<parseFloat(sLimit))
	{
		dv.style.opacity=parseFloat(dv.style.opacity)+0.1;
		dv.style.filter='alpha(opacity='+(parseFloat(dv.style.opacity)*100)+')' ;
		//alert(dv.style.filter);
		setTimeout('showLoadImage("'+id+'","'+sLimit+'");',1);
	}

}
function stopLoadImage(id)
{

	dv = document.getElementById(id);
	//dv.style.display='inline';
	if(parseFloat(dv.style.opacity)>0)
	{
		//alert(dv.style.opacity);
		dv.style.opacity=parseFloat(dv.style.opacity)-0.2;
		dv.style.filter='alpha(opacity='+(parseFloat(dv.style.opacity)*100)+')' ;
		setTimeout('stopLoadImage("'+id+'");',1);
	}
	else {
		//alert('ddd');
		document.getElementById(id).style.zIndex='-15';
		document.getElementById(id).innerHTML='';
	}

}
//увеличивает из превюхив большое изображение
function fnEnlarge(path,width,height)
{

	document.getElementById('img_big').innerHTML='<img onclick="endFadeImage();" style=\'cursor:pointer;\' src="images/'+path+'">';
	document.getElementById('imgBlock').style.marginLeft='-' +(parseFloat(width)/2)+'px';
	document.getElementById('imgBlock').style.marginTop='-' +(parseFloat(height)/2)+'px';

}


function startImage(sLink,width,height,good_key)
{
	document.getElementById('imgBlock').style.backgroundColor="none";
	//	document.getElementById('imgBlock').style.textAlign="center";

	document.getElementById('imgBlock').innerHTML='<div id="img_big" style="vertical-align:top;"><img onclick="endFadeImage();" style="cursor:pointer;" src="'+sLink+'"></div><div style="float:right"><img style="cursor:pointer;" onclick="endFadeImage();" src="images2/b_drop.png"></div><div style="width:500px; text-align:center;"';

	JsHttpRequest.query(
	'load_info.php', // backend
	{
		// pass a text value
		'action': 'get_image_by_key',
		'good_key': good_key
	},
	// Function is called when an answer arrives.
	function(result, errors) {
		if (errors && errors!=='') {
			//document.getElementById('test').appendChild(document.createTextNode(errors));
			//alert(errors);
		}
		// Write errors to the debug div.
		// document.getElementById("debug").innerHTML = errors;
		// Write the answer.
		if (result) {
			//alert(result['res']);
			for(i=0;i<result.length;i++)
			{
				res=result[i];
				document.getElementById('imgBlock').innerHTML+='<img onclick="fnEnlarge(\''+res['path']+'\',\''+res['width']+'\',\''+res['height']+'\');" style="cursor:pointer;" src="thumbnails/'+res['path']+'">';

			}
		}
	},
	true  // do not disable caching
	);
	//alert(document.body.scrollTop);

	//??????? ??????
	document.body.style.overflow='hidden';
	//alert(document.getElementById('imgBack').style.zIndex);
	//??????? ?????? ??????
	document.getElementById('imgBack').style.zIndex='3';
	document.getElementById('imgBlock').style.zIndex='4';

	//?????????????
	document.getElementById('imgBlock').style.marginLeft='-' +(parseFloat(width)/2)+'px';
	//alert(height);
	document.getElementById('imgBlock').style.marginTop='-' +(parseFloat(height)/2)+'px';

	id='imgBack';
	dv = document.getElementById(id);
	//if(parseFloat(dv.style.opacity)==0)
	setTimeout('showLoadImage("'+id+'","0.5");',1);


	id='imgBlock';
	dv = document.getElementById(id);
	//	if(parseFloat(dv.style.opacity)==0)
	setTimeout('showLoadImage("'+id+'","1");',1);

}
function endFadeImage()
{
	//document.getElementById('imgBlock').style.backgroundColor="none";
	
	id='imgBlock';

	dv = document.getElementById(id);
	//if( parseFloat(dv.style.opacity)==1)
	setTimeout('stopLoadImage("'+id+'");',1);

	id='imgBack';

	dv = document.getElementById(id);
	//if( parseFloat(dv.style.opacity)==1)
	setTimeout('stopLoadImage("'+id+'");',1);

	document.body.style.overflow='auto';
}

function fnAddCart(good_key,newNum)
{
	//alert(newNum);

	width=500;
	height=500;
	document.getElementById('imgBlock').style.backgroundColor="#fff";
	document.getElementById('imgBlock').style.width=parseInt(width+5)+"px";

	out='	<table class="cart" cellpadding="0" cellspacing="0"><tr class="cart_head">  <td>&nbsp;</td>  <td>Наименование</td><td>Модель</td><td>Цена</td><td>Кол-во</td><td>Сумма</td><td style="background-color:#fff;padding:0px;"><img style=" cursor:pointer;" onclick="endFadeImage();" src="images2/b_drop.png"></td></tr>';
	sum=0;
	JsHttpRequest.query(
	'load_info.php', // backend
	{
		// pass a text value
		'action': 'add_to_client_cart',
		'new_num':newNum,
		'good_key': good_key
	},
	// Function is called when an answer arrives.
	function(result, errors) {
		if (errors && errors!=='') {
			//document.getElementById('test').appendChild(document.createTextNode(errors));
			//alert(errors);
		}
		// Write errors to the debug div.
		// document.getElementById("debug").innerHTML = errors;
		// Write the answer.
		if (result) {

			//alert(result['res']);
			for(i=0;i<result.length;i++)
			{
				res=result[i];
				sum=sum+parseFloat(res['sum']);
				out+='<tr><td >'+(i+1)+'</td><td class="name">'+res['good_name']+'</td><td class="name">'+res['model']+'</td><td>'+res['price']+'</td><td><input type="text" size=3 onkeyup="fnAddCart(\''+res['good_key']+'\',this.value);" value="'+res['val']+'"></td><td>'+res['sum']+'</td></tr>';

			}

			out+='<tr><Td colspan="5" style="text-align:right;"><strong>Итого</strong></Td><td>'+sum+'</td></tr><tr><td colspan="2" ><a href="javascript:endFadeImage();"><< Продолжить покупки (закрыть)</a></td><td colspan="4">&nbsp;&nbsp;&nbsp;<a href="javascript:fnShowForm();">Продолжить оформление >></a></td></tr></table>';
			document.getElementById('imgBlock').innerHTML=out;

			//??????? ??????
			document.body.style.overflow='hidden';
			//alert(document.getElementById('imgBack').style.zIndex);

			document.getElementById('imgBack').style.zIndex='3';
			document.getElementById('imgBlock').style.zIndex='4';

			//?????????????
			document.getElementById('imgBlock').style.marginLeft='-' +(parseFloat(width)/2)+'px';
			document.getElementById('imgBlock').style.marginTop='-' +(parseFloat(height)/2)+'px';

			id='imgBack';
			dv = document.getElementById(id);
			//if(parseFloat(dv.style.opacity)==0)
			setTimeout('showLoadImage("'+id+'","0.5");',1);


			id='imgBlock';
			dv = document.getElementById(id);
			//	if(parseFloat(dv.style.opacity)==0)
			setTimeout('showLoadImage("'+id+'","1");',1);

		}
		else {

			out+='</table>';
			document.getElementById('imgBlock').innerHTML=out;


		}
	},
	true  // do not disable caching
	);
	//alert(document.body.scrollTop);


}


function fnShowBlock(out)
{
	//alert(newNum);

	width=500;
	height=500;
	document.getElementById('imgBlock').style.backgroundColor="#fff";
	document.getElementById('imgBlock').style.width=parseInt(width+5)+"px";
	document.getElementById('imgBlock').style.height=parseInt(height)+"px";

	//out='Посмострите новое видео у нас на сайте ';
	
	
	
	document.getElementById('imgBlock').innerHTML=out;

	//??????? ??????
	document.body.style.overflow='hidden';
	//alert(document.getElementById('imgBack').style.zIndex);

	document.getElementById('imgBack').style.zIndex='3';
	document.getElementById('imgBlock').style.zIndex='4';

	//?????????????
	document.getElementById('imgBlock').style.marginLeft='-' +(parseFloat(width)/2)+'px';
	document.getElementById('imgBlock').style.marginTop='-' +(parseFloat(height)/2)+'px';

	id='imgBack';
	dv = document.getElementById(id);
	//if(parseFloat(dv.style.opacity)==0)
	setTimeout('showLoadImage("'+id+'","0.5");',1);


	id='imgBlock';
	dv = document.getElementById(id);
	//	if(parseFloat(dv.style.opacity)==0)
	setTimeout('showLoadImage("'+id+'","1");',1);

}


function fnSaveOrder()
{
	//alert(newNum);

	width=500;
	height=500;
	document.getElementById('imgBlock').style.backgroundColor="#fff";
	document.getElementById('imgBlock').style.width=parseInt(width+5)+"px";

	out='<img style="float:right; cursor:pointer;" onclick="endFadeImage();" src="images2/b_drop.png">';


	err=0;
	if(document.getElementById('pass').value!=document.getElementById('repeat_pass').value)
	{ err=1; alert('Пароли не совпадают. Повторите ввод!');}
	if(document.getElementById('name').value=='')
	{ err=1; alert('Вы не ввели свое имя!'); document.getElementById('name').focus(); }
	if(document.getElementById('phone').value=='')
	{ err=1; alert('Вы не ввели свой телефон!'); document.getElementById('phone').focus(); }

	if(err!=1)
	{

		JsHttpRequest.query(
		'load_info.php', // backend
		{
			// pass a text value
			'action': 'save_order',
			'name':document.getElementById('name').value,
			'phone':document.getElementById('phone').value,
			'adress':document.getElementById('adress').value,
			'pass':document.getElementById('pass').value,
			'email':document.getElementById('email').value
		},
		// Function is called when an answer arrives.
		function(result, errors) {
			if (errors && errors!=='') {
				//document.getElementById('test').appendChild(document.createTextNode(errors));
				//alert(errors);
			}
			// Write errors to the debug div.
			// document.getElementById("debug").innerHTML = errors;
			// Write the answer.
			if (result) {

				//if(result['res']=='1')
				out+='Ваш заказ успешно сохранен! В самое ближайшее время с Вами свяжется наш менеджер.<br>Для получения счета для оплаты по безналу, перейдите по <a target="_blank" href="bill.php?shop_order_key='+result['shop_order_key']+'">ссылке</a>';


				//out+='<tr><Td colspan="5" style="text-align:right;"><strong>Итого</strong></Td><td>'+sum+'</td></tr><tr><td colspan="3" ></td><td colspan="3"><a href="javascript:fnShowForm();">Продолжить оформление >></a></td></tr></table>';
				document.getElementById('imgBlock').innerHTML=out;

				//??????? ??????
				document.body.style.overflow='hidden';
				//alert(document.getElementById('imgBack').style.zIndex);

				document.getElementById('imgBack').style.zIndex='3';
				document.getElementById('imgBlock').style.zIndex='4';

				//?????????????
				document.getElementById('imgBlock').style.marginLeft='-' +(parseFloat(width)/2)+'px';
				document.getElementById('imgBlock').style.marginTop='-' +(parseFloat(height)/2)+'px';

				id='imgBack';
				dv = document.getElementById(id);
				//if(parseFloat(dv.style.opacity)==0)
				setTimeout('showLoadImage("'+id+'","0.5");',1);


				id='imgBlock';
				dv = document.getElementById(id);
				//	if(parseFloat(dv.style.opacity)==0)
				setTimeout('showLoadImage("'+id+'","1");',1);

			}
			else {

				out+='</table>';
				document.getElementById('imgBlock').innerHTML=out;


			}
		},
		true  // do not disable caching
		);
		//alert(document.body.scrollTop);
	}


}


function fnShowForm()
{
	//alert(newNum);

	width=500;
	height=500;
	document.getElementById('imgBlock').style.backgroundColor="#fff";
	document.getElementById('imgBlock').style.padding="10px";
	document.getElementById('imgBlock').style.width=parseInt(width+5)+"px";

	out='<img style="float:right; cursor:pointer;" onclick="endFadeImage();" src="images2/b_drop.png">Для окончания оформления заказа, заполните несколько полей ниже (все обязательны).';
	out+='<table>';
	out+='<tr><td style="width:300px;">Ваше имя (желательно с фамилией)</td><td><input id="name" type="text" size="20" /></td></tr>';
	out+='<tr><td>Контактный телефон</td><td><input type="text" size="20" id="phone"  /></td></tr>';
	out+='<tr><td>Адрес доставки (если необходима)</td><td><input type="text" id="adress" size="20" /></td></tr>';
	out+='</table>';
	out+='<br />';
	out+='Если Вы хотите зарегистрироваться на сайте, чтобы в дальнейшем иметь возможность получать бонусы от нашего интернет магазина, заполните еще парочку полей ниже';

	out+='<table>';
	out+='<tr><td style="width:300px;">E-mail</td><td><input id="email" type="text" size="20" /></td></tr>';
	out+='<tr><td>Пароль</td><td><input type="password" id="pass" size="20" /></td></tr>';
	out+='<tr><td>Повторите пароль</td><td><input type="password" id="repeat_pass" size="20" /></td></tr>';
	out+='</table>';

	out+='<input type="button" onclick="fnSaveOrder();" value="Отправить заказ" />';
	document.getElementById('imgBlock').innerHTML=out;

	//??????? ??????
	document.body.style.overflow='hidden';
	//alert(document.getElementById('imgBack').style.zIndex);

	document.getElementById('imgBack').style.zIndex='3';
	document.getElementById('imgBlock').style.zIndex='4';

	//?????????????
	document.getElementById('imgBlock').style.marginLeft='-' +(parseFloat(width)/2)+'px';
	document.getElementById('imgBlock').style.marginTop='-' +(parseFloat(height)/2)+'px';

	id='imgBack';
	dv = document.getElementById(id);
	//if(parseFloat(dv.style.opacity)==0)
	setTimeout('showLoadImage("'+id+'","0.5");',1);


	id='imgBlock';
	dv = document.getElementById(id);
	//	if(parseFloat(dv.style.opacity)==0)
	setTimeout('showLoadImage("'+id+'","1");',1);




}