var opened_id;
function DivDisplay(IDElement,display){
	var el = document.getElementById(IDElement);
	if (!el) return false;
	el.style.display = display?'block':'none';
}

function DivCheckScroll(IDElement,display) {
DivCheck(IDElement,display);
StartScroller(false);
}
function DivCheck(IDElement){
	var el = document.getElementById(IDElement);
	if (!el) return false;
	if (el.style.display != 'block') {
	  if (opened_id) {
	  	document.getElementById(opened_id).style.display = 'none';
	  }
	  opened_id=IDElement;
	  el.style.display = 'block';
	} else {
	  opened_id='';
	  el.style.display = 'none';
	}  
}
function DivWrite(IDElement,city, write_id){
	var citywrite = document.getElementById(write_id);
	citywrite.value = city;
	var el = document.getElementById(IDElement);
	if (!el) return false;
	el.style.display = 'none';
}

function popup(path, width, height) {
    window.open(path, "_blank", "toolbar=no, location=no, directories=no, status=yes, menubar=no, resizable=no, copyhistory=no, scrollbars=no, width=" + width + ", height=" + height + "");
    return false;
}

function OpenMiniWin(url,x,y) {
	if(y < (screen.availHeight - 20) )
		str3="scrollbars=no,status=no,resizable=no,width="+x+",height="+y+",left="+(screen.availWidth-x)/2+",top="+(screen.availHeight-y)/2;
	else
		str3="scrollbars= yes,width="+ (x + 20) +",height="+ (screen.availHeight - 50)  +",left="+(screen.availWidth-x)/2+",top= 10";

	newWindow = window.open("","newWindow",str3);
	newWindow.document.open();
	newWindow.document.write('<html><title>Glamour</title> <body leftmargin="0" topmargin="0" marginheight="0" marginwidth="0">');  
	newWindow.document.write('<table width="100%" border="0" cellspacing="0" cellpadding="0" align="center" height="100%"><tr><td>');
	newWindow.document.write('<img src="'+url+'" width="'+x+'" height="'+y+'">'); 
	newWindow.document.write('</td></tr></table></body></html>');
	newWindow.document.close();
	newWindow.focus();
	}

function changeDiv(open,close) {
	if (close != '') {
		document.getElementById(close).style.display='none';
	}
	document.getElementById(open).style.display='block';
}

var forClose = 'lab_main';
function changeLabDiv(curdiv) {
	changeDiv(curdiv, forClose);
	forClose = curdiv;
	StartScroller(true);
}

function fixPNG(element)
{
  if (/MSIE (5\.5|6).+Win/.test(navigator.userAgent))
  {
    var src;
	
    if (element.tagName=='IMG')
    {
      if (/\.png$/.test(element.src))
      {
        src = element.src;
        element.src = "/theme/img/blank.gif";
      }
    }
    else 
    {
      src = element.currentStyle.backgroundImage.match(/url\("(.+\.png)"\)/i);
      if (src)
      {
        src = src[1];
        element.runtimeStyle.backgroundImage="none"; //������� ������� �����������
      }
    }
    if (src) element.runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + src + ")";
  }
}

function tryToClear(el, def_value) {
	if (el.value == def_value)
		el.value = '';
}

function showShopResult(url, params) {
	$('fog').style.display="block";
	$('popup').style.display="block";
	$('loader').style.display="block";
	//var url = '/code/';
	var ajxObj = createAjxObj();
	ajxObj.onreadystatechange = function() { 
		if (ajxObj.readyState == 4) {
			if (ajxObj.status == 200) {
				eval("res="+ajxObj.responseText);
				$('loader').style.display="none";
				$('popup_result').style.display="block";
				//console.log(res);
				if ($('code')) {
					$('code').value = '';
					$('code_count').innerHTML = decodeURIComponent(res.points);
					$('code_txt').innerHTML = decodeURIComponent(res.txt_points);
				}
					$('popup_content').innerHTML = decodeURIComponent(res.res_text);
				
				//$('im_log').innerHTML = $('im_log').innerHTML+"<b>��: </b>"+decodeURIComponent(res.res)+"<br />";
				//$('im_message').value = '';
			}
		}
	}
	if (!params) var params = ''
	//var params = 'code='+encodeURIComponent($('code').value);
	ajxObj.open("POST", url, true);
	ajxObj.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	ajxObj.setRequestHeader("Content-length", params.length);
	ajxObj.setRequestHeader("Connection", "close");
	ajxObj.send(params);
}

function hideShopResult() {
	$('fog').style.display="none";
	$('popup').style.display="none";
	$('loader').style.display="none";
	$('popup_result').style.display="none";
}

function setShopCats(cat_id) {
	for (i=1;i<=3;i++) {
		if (i == cat_id) {
			$('shop_cat_'+i).src = '/theme/img/shop/ban_'+i+'bl.png';
		} else {
			$('shop_cat_'+i).src = '/theme/img/shop/ban_'+i+'sh.png';
		}
		fixPNG($('shop_cat_'+i));
	}
	
}

function clearShopCats() {
	for (i=1;i<=3;i++) {
		$('shop_cat_'+i).src = '/theme/img/shop/ban_'+i+'.png';
		fixPNG($('shop_cat_'+i));
	}
}

function setShopVariant(id) {
	$('order_but').href = '/shop/'+id+'/order.html';
	$('reserve_but').href = '/shop/'+id+'/reserve.html';
}

function hidePinkPopup() {
	$('fog').style.display="none";
	$('popup').style.display="none";
	//$('loader').style.display="none";
	$('popup_result').style.display="none";
}
function showPinkPopup(content) {
	//console.log(content);
	$('fog').style.display="block";
	$('popup').style.display="block";
	$('popup_result').style.display="block";
	$('popup_content').innerHTML = content;
}

