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 = path+"/images/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 + "',sizingMethod='scale')";
  }
}
function openw(res,title) {
   rand=Math.random().toString().substring(2,15);
   window.open(path + "/lib/show_pic.php?src="+res+"&title="+title, 'new_'+rand, "top=50, left=50, width=50, height=50, channelmode=no, toolbar=no, location=no, status=no, directories=no, menubar=no, resizable=yes, scroll=yes");
}
function open_pic(res,title) {
   rand=Math.random().toString().substring(2,15);
   window.open(path + "/lib/show_pic.php?src="+res+"&title="+title, 'new_'+rand, "top=50, left=50, width=50, height=50, channelmode=no, toolbar=no, location=no, status=no, directories=no, menubar=no, resizable=yes, scrollbars=yes");
}
function get_floor(id,cur) {
   var req = new JsHttpRequest();
   req.onreadystatechange = function() 
   {
      if (req.readyState == 4) {
      	  document.getElementById('search_floor').innerHTML = req.responseText;
      }
   }
   req.open(null, path+'/get_floor.html', true);
   req.send( { id: id, cur: cur } );
}
function get_apartment(id, cur) {
   var req = new JsHttpRequest();
   req.onreadystatechange = function() 
   {
      if (req.readyState == 4) {
      	  document.getElementById('search_apartment').innerHTML = req.responseText;
      }
   }
   req.open(null, path+'/get_apartment.html', true);
   req.send( { id: id, cur: cur } );
}
function go_apartment()
{
	id_ap = document.getElementById("apartment").value;
	if (id_ap > 0)
	{
	   id_korpus = document.getElementById("korpus").value;
	   id_floor = document.getElementById("floor").value;
	   location.href=path+'/apartments/'+id_korpus+'/'+id_floor+'/'+id_ap+'.html';
	}
	else
	{
		alert("Вы должны выбрать апартаменты!");
	}
}
function get_floor_plan(ob,id,pid) {
   var obs = document.getElementsByName('a_floor');
   for (var i=0;i<obs.length;i++)
   {
   	   obs[i].className = 'floor_title';
   }
   ob.className = 'floor_title_on';
   
   var req = new JsHttpRequest();
   req.onreadystatechange = function() 
   {
      if (req.readyState == 4) {
      	  document.getElementById('floor_plan').innerHTML = req.responseText;
      }
   }
   req.open(null, path+'/get_floor_plan.html', true);
   req.send( { id: id, pid: pid } );
}
function recycle_add(id,title,model_title,creator_title) {
        var req = new JsHttpRequest();
        req.onreadystatechange = function() 
        {
           if (req.readyState == 4) {
       	      document.getElementById('recycle_div_'+id).style.display="block";
       	      document.getElementById('recycle_div_'+id).innerHTML=req.responseText;
           	  document.getElementById('recycle_count').innerHTML = req.responseJS.recycle_count;
           	  document.getElementById('recycle_price').innerHTML = req.responseJS.recycle_price;
           }
        }
        req.open(null, path+'/recycle_add.html', true);
        req.send( { id: id, title: title, model_title: model_title, creator_title: creator_title } );
}
		var arrErrors;
		var empty_re = /[ \f\n\r\t\v]/g;
		var email_re = /^([a-z]|[0-9]|_|-|\.)*@(([a-z]|[0-9]|_|-)*\.)+[a-z]{2,4}$/i;
function checkO()
{
	arrErrors = new Array();
	checkEmpty("fio", "Укажите ФИО");
	checkEmpty("phone", "Укажите Телефон");
	//checkEmpty("email", "Укажите Электронную почту");
	checkEmpty("address", "Укажите Адрес");
    /*if ( document.getElementById("email").value != "" )
		    checkRE( "email", "Неправильный формат Электронной почты", email_re);
	*/
	if (arrErrors.length == 0)
	{
		var oSubmitButton = document.getElementById("SubmitButtonO");
		oSubmitButton.disabled = true;
		return true;
	}
	else
	{
		var errMsg = "Пожалуйста, исправьте следующее и попробуйте отправить снова :\n\n";
		for(var i=0; i < arrErrors.length; i++)
			errMsg += "\t" + arrErrors[i].msg + "\n";
		alert(errMsg);
		return false;
	}
}
		function checkEmpty(elementID, errorMessage)
		{
			var oElement = document.getElementById(elementID);
			var sValue = oElement.value.replace(empty_re, "");
			if (  sValue == "")
			{
				var errorObj = new Object();
				errorObj.elem = oElement;
				errorObj.msg =errorMessage;
				arrErrors.push(errorObj);
			}
		}
		function checkRE(elementID, errorMessage, re)
		{
			var oElement = document.getElementById(elementID);
			if ( !re.test(oElement.value) )
			{
				var errorObj = new Object();
				errorObj.elem = oElement;
				errorObj.msg =errorMessage;
				arrErrors.push(errorObj);
			}
		}