var inShow = ''; var act1; var act2; var act3;
var gal = 0;
var tv = false;
function prepare(){
mT = getTop('menubot').top + getBodyScrollTop();
dT = getTop('btm').top + getBodyScrollTop();
w = mT - dT;

 if(w>-20) document.getElementById("vr").style.height = mT-50;
}

function gid(id){
return document.getElementById(id);
}

function geo(){
gid('geobg').style.display = 'block';
GetContent('geo','/geo/geo_dost.php?'+Math.random( ));
}

function postload(){
	setTimeout("pl();",50);
}
function pl(){
	geo();
	gid('pl2').src = '/images/line.jpg';
	gid('pl3').src = '/images/pers.jpg';
//	gid('pl4').src = '/images/idea.gif';
//	gid('pl5').src = '/images/icq1.gif';
	gid('pl6').src = '/images/otz_bot.jpg';
	gid('pl7').src = '/images/zakladki.gif';
	gid('pl8').src = '/images/menui_arr.gif';
	gid('pl9').src = '/images/subarr.gif';
//	gid('pl10').src = '/images/gora.jpg';
	gid('pl11').src = '/images/ostrov.gif';
//	gid('pl12').src = '/images/sky_r.jpg';
	gid('pl13').src = '/images/phone.gif';
	gid('pl14').src = '/images/key.gif';
	gid('pl15').src = '/images/devochka.gif';
//	gid('pl13').src = '';
//	gid('pl13').src = '';
}

function change_img(medImg,bigImg,id){
	gid('cimg').src = medImg;
	gid('clink').href = bigImg;
	
	gid('gal'+gal).className = '';
	gid('gal'+gal).style.border = '';
	gid('gal'+id).className = 'gal_act';
	gid('gal'+id).style.border = 'dotted 1px #555555';
	
	gal = id;

}
function change_img2(medImg,bigImg,id,g){
	gid('imgg').value = g;
	gid('cimg').src = medImg;
	gid('clink').href = bigImg;
	
	gid('gal'+gal).className = '';
	gid('gal'+gal).style.border = '';
	gid('gal'+id).className = 'gal_act';
	gid('gal'+id).style.border = 'dotted 1px #555555';
	
	gal = id;

}


function roll(num) {
	div = gid('s'+num);
	if (!div) return;
	if (div.style.display=='none') {
		div.style.display = 'block';
	} else {
		div.style.display = 'none';
	}
}
function rolls(num) {
	div = gid('s'+num);
	if (!div) return;
	if (div.style.display=='none'||!div.style.display) {
		div.style.display = 'block';
	} else {
		div.style.display = 'none';
	}
}

function setblock(id){
	gid('s'+id).style.display = 'block';
}

function menuroll(id){
	roll(id); 
	roll(id+'a');
	
	if(id == act1 && gid('s'+id).style.display == 'none'){
		gid('arr').style.display = 'none';
		gid('subarr').style.display = 'none';
	}
	else{
		setact(id);
		setSubact(id);
		prepare();
	}

}

function smenuroll(id){
	if(id == inShow){
		rolls(inShow);
		gid('sm'+inShow).style.fontWeight = 'normal';
		inShow = '';
	}
	else{
		if(inShow) {roll(inShow); gid('sm'+inShow).style.fontWeight = 'normal';}
		rolls(id);
		gid('sm'+id).style.fontWeight = 'bold';
		prepare();
		inShow = id;
	}
	setact();
	setSubact();
}

function setact(){
		if(!gid('_act')) return;
		if(gid('s'+act1).style.display == 'block')
		gid('arr').style.display = 'block';
		coords = getTop('_act');
		gid('arr').style.top = coords.top + coords.height/2 - 23 + getBodyScrollTop();
	}
function setSubact(){
		if(!gid('sub_act')) return;
		gid('subarr').style.display = 'block';
		coords = getTop('sub_act');
		gid('subarr').style.top = coords.top + 9 + getBodyScrollTop();
	}

function menubgOn(id){
		document.getElementById('mm'+id).className = 'mmibg';
}
function menubgOff(id){gid('mm'+id).className = '';}
function ordOn(id){gid(id).className = 'order_over';}
function ordOff(id){gid(id).className = 'order';}
function artOn(id){gid('art'+id).className = 'artimg_b';}
function artOff(id){gid('art'+id).className = 'artimg';}
function moveArrows(id){gid('arr'+id+'right').src = '/images/reg_arr_r_m.gif';
		gid('arr'+id+'left').src = '/images/reg_arr_l_m.gif';}
function unmoveArrows(id){
		gid('arr'+id+'right').src = '/images/reg_arr_r.gif';
		gid('arr'+id+'left').src = '/images/reg_arr_l.gif';
}
	
function getBodyScrollTop()
{
	return self.pageYOffset || (document.documentElement && document.documentElement.scrollTop) || (document.body && document.body.scrollTop);
}
function getTop(id)
{
 element = gid(id);
  var left = element.offsetLeft;
  var top = element.offsetTop;
  for (var parent = element.offsetParent; parent; parent = parent.offsetParent)
  {
    left += parent.offsetLeft - parent.scrollLeft;
    top += parent.offsetTop - parent.scrollTop
  }
  return {left: left, top: top, width: element.offsetWidth, height: element.offsetHeight};
//return top;
}

function ShowMail(user, domain1, domain2) {
	var email = user+'&#64;'+domain1+'&#46;'+domain2;
	if (ShowMail.arguments[3]) name = ShowMail.arguments[3];
	else name = email;
	document.writeln('<a href="mailto:'+email+'">'+name+'</a>');
}

function openImage(image) {
//alert(image);
	if (image) window.open("/popup.php?img="+image, "popupimage", "scrollbars=1, resizable=1, width=750, height=500").focus();
	return false;
}

function openImage2(image,gal) {
//alert(image);
	if (image) window.open("/img.php?p="+image+"&g="+gal, "popupimage", "scrollbars=1, resizable=1, width=750, height=500").focus();
	return false;
}
 
function preload() {
	b=preload.arguments; 
	preload_images = new Array();
	for(i=0; i<b.length; i++) {
		preload_image = new Image;
		preload_image.src=b[i];
		preload_images[i]=preload_image;
	}
}

function cartpopup(url)
{
	return window.open(url, "cart_window", "scrollbars=1, resizable=1, width=700, height=500").focus();
}

function resetframe(){
	window.document.getElementById('cframe').src='about:blank';
}

function hidediv(){
	window.parent.document.getElementById('cartdiv').style.display='none';
}
function hidewelcome(){
	gid('welcome').style.display='none';
}

function hidecart(){
	window.parent.document.getElementById('cframe').src='about:blank';
	window.parent.setTimeout("hidediv();",3900);
}
function hidewlc(){
	setTimeout("hidewelcome();",2500);
}

function buy(id)
{
	jQuery.get('/?pre=cart&act=add&new_id[' + id + ']=1',
		'',
		function(data)
		{
			$("#cartinfo").css('display', 'block');
			$("#cartinfo").html(data);
			$("#justbuy" + id).html("товар добавлен в корзину<br><a href='/cart/'>перейти к оформлению</a>");
			$("#justbuy" + id).css('display', 'block');
			if(check_browser() != 'IE')
			{
				$("#fly" + id).html("<img src='" + $("#img" + id).attr("src") + "' width='100'>");
				$("#fly" + id).css("position", "absolute");
				$("#fly" + id).animate({ width: "-100", height: "-100", top:"-100", left:"-100" }, "slow");
			}
		}
	);
}

function check_browser()
{
		var version = 0;
		if (navigator.userAgent.indexOf ("MSIE") != -1)
			version = "IE";
		else if (navigator.userAgent.indexOf ("Opera") != -1)
			version = "Opera";
		else if (navigator.userAgent.indexOf ("Firefox") != -1)
			version = "Mozilla";
		else if (navigator.userAgent.indexOf ("Chrome") != -1)
			version = "Chrome";
		else if (navigator.userAgent.indexOf ("Safari") != -1)
			version = "Safari";
	return version;
}
function imOvr(src,id,name,price){
	gid('tv').innerHTML = '<table cellpadding=0 cellspacing=0 border=0 width=100% height=145><tr><td align=center style="font-size:11px;padding:3px;letter-spacing:0px;">'+name+'</td></tr><tr><td height=105 align=center valign=middle><img id="tvim" style="margin:2px 0px 4px 0px" src="'+src+'"></td></tr><tr><td align=center style="font-size:11px;" valign=bottom><span style="font-size:11px;padding:5px;background:#944831; color:#ffffff;">'+price+' <strong>р.</strong></span></td></tr><tr><td><img src="images/s.gif" height=1 width=176></td></tr></table>';
	tv = true;	
}
function imOut(){
	tv = false;	window.parent.setTimeout("shum();",1700);
}
function shum(){if(!tv)	gid('tv').innerHTML = '<img src="images/shum.gif">';}
function imcOvr(){gid('imcont').style.display = 'block';}
function imcOut(){gid('imcont').style.display = 'none';}

function fsearch(){setTimeout("fastsearch();",500);}
function fastsearch(){
gid('fsearch').style.display='block';
GetContent('fsearch','/ajax/get_prod.php?name='+gid('inp').value);

}




/* AAAAAAAAAAAAAA */

function createXMLHttpRequest() {
  var xmlReq = false;
  // branch for native XMLHttpRequest object
  if(window.XMLHttpRequest) {
    try {
      xmlReq = new XMLHttpRequest();
    } catch(e) {
      xmlReq = false;
    }
  // branch for IE/Windows ActiveX version
  } else if(window.ActiveXObject) {
    try {
      xmlReq = new ActiveXObject("Msxml2.XMLHTTP");
    } catch(e) {
      try {
        xmlReq = new ActiveXObject("Microsoft.XMLHTTP");
      } catch(e) {
        xmlReq = false;
      }
    }
  }
  return xmlReq;
}

var userAgent = { };
userAgent.isAJAX = (createXMLHttpRequest()?true:false);
userAgent.isMozilla = (navigator.userAgent.match(/\bGecko\b/));
userAgent.isOpera = (navigator.userAgent.match(/\bOpera\b/));
userAgent.isInternetExplorer = (navigator.userAgent.match(/\bMSIE\b/) && !userAgent.isOpera);

function callServer(method, url, data, dataType, func, arg) {
  if (!method) method='GET';
  var xmlReq = createXMLHttpRequest();
  if(xmlReq) {
    xmlReq.onreadystatechange = function() {
        // only if xmlReq shows "loaded"
        if (xmlReq.readyState == 4) {
          func(arg, xmlReq.responseText, xmlReq.responseXML, xmlReq.status, xmlReq.statusText);
        }
      };
    xmlReq.open(method, url, true);
    if (data) {
      if (!dataType) dataType='application/xml';
      if (typeof(data)!="string" && dataType.indexOf("charset=")<0 && userAgent.isMozilla) dataType=dataType+';charset=utf-8'; // in Mozilla XML always serialized as UTF-8
      xmlReq.setRequestHeader('Content-Type', dataType);
    }
    xmlReq.send(data);
    return false;
  }
  return true;
}


function showHTML(element, responseText, responseXML, statusCode, statusText) {
  if (typeof(element)=="string") element=document.getElementById(element);
  if (statusCode==200 || statusCode==201) {
    element.innerHTML=responseText;
  }
  else {
    alert("Загрузить информацию не удалось:\n"+statusText);
  }
}






function ChangeHTML(id,elm) {
	document.getElementById(id).innerHTML = elm.innerHTML;
	document.getElementById(id).onclick = function onclick(event) {GetWordSyns(this)};
	document.getElementById(id).style.borderBottom = '1px #0C0 dashed;';
	return false;
}

function GetContent(id,url) {
	callServer(null, url, null, null, showHTML, id);
}

function gcl(url,id){
	gid(id).innerHTML = '<img src="/images/icons/loading.gif">';
//	callServer(null, url, null, null, showHTML, id);
	$("#prodremind").load(url);
}

function remember(id){
	var lid;
	//callServer(null, '/remember/?id='+id, null, null, showHTML, 'rmbr'+id);
	lid = "#rmbr"+id;
//	alert(id);
//	alert($(lid).attr("ID"));
//	$(lid).load("/l/remember.php/?id="+id);
	$(lid).load("/remember/?id="+id);
	
}

function remind(id,email,phone){
gcl('/l/rem.php/?product_id='+id+'&email='+email+'&phone='+phone, 'prodremind');
}
function remindRoll(id){
  gid('prodremind').innerHTML='';
  Elem = gid('srem');
  Elem.style.display = 'block';
  Elem.style.top=document.body.scrollTop-getClientHeight()/2;
  Elem.style.left=document.body.scrollLeft+getClientWidth()/2-300;
  gid('remprod_id').value=id;
}
function remindRoll2(id){
  gid('prodremind').innerHTML='';
  Elem = gid('srem');
  Elem.style.display = 'block';
  Elem.style.top=document.body.scrollTop+getClientHeight()/2-200;
  Elem.style.left=document.body.scrollLeft+getClientWidth()/2-300;
  gid('remprod_id').value=id;
}

function getClientWidth()
{
  return document.compatMode=='CSS1Compat' && !window.opera?document.documentElement.clientWidth:document.body.clientWidth;
}

function getClientHeight()
{
  return document.compatMode=='CSS1Compat' && !window.opera?document.documentElement.clientHeight:document.body.clientHeight;
}
