/**
 * @copyright Dvir.net.ua (c) 2004
 * @author Oleksiy Tymoshenko
 * @since 11.06.2005
 */

/**
 * to add this page to bookmarks
 */
function Add2Bookmarks()
{
	var url = self.location.href;
	var title = 'Мегет и партнеры: '+document.title;

	if (window.sidebar)
	{
		title = 'Мегет и партнеры - Продажа недвижимости';		//
		window.sidebar.addPanel(title, url, title);
	}
	else
	{
		window.external.AddFavorite( url, title);
	}
}


function setHome(ob) {
	 if(document.all)
	 {
		ob.style.behavior='url(#default#homepage)';
		ob.setHomePage(document.location);
	 }
}

function setMenuMousOv(ob, bgclr, fntclr){
    if(bgclr.length  > 0)	ob.style.backgroundColor=bgclr;
    if(fntclr.length > 0)	ob.style.color=fntclr;
	ob.style.cursor='pointer';
}



function setMenuMousOut(ob){
    ob.style.backgroundColor='';
    ob.style.color='';
	ob.style.cursor='';
}

function setMenuMousClk(ob, bgclr, fntclr){
    if(bgclr.length  > 0)	ob.style.backgroundColor=bgclr;
    if(fntclr.length > 0)	ob.style.color=fntclr;
	ob.style.cursor='pointer';
}




function shwDiv(s)
{
	obj = document.getElementById(s);
	if(obj.style.display=='block')
		obj.style.display = 'none'
	else
		obj.style.display='block'
}

function expDiv(s)
{
	obj = document.getElementById(s);
	var im_s = 'im_'+s;

	if(obj.style.overflow=='hidden')
	{
		obj.style.height = '';
		obj.style.overflow = 'visible';
		if ( document.images[im_s]!=null && document.images[im_s]!='undefined' )
			document.images[im_s].src='/images/icon-expand_.gif';
	}
	else
	{
		obj.style.overflow='hidden';
		obj.style.height = '37px';
		if (document.images[im_s]!=null && document.images[im_s]!='undefined')
			document.images[im_s].src='/images/icon-expand.gif';
	}
}

// display local time
function ShowDate()
{
  var d, s = '';
  d = new Date();
  s += d.getDate() + "/";
  s += (d.getMonth() ) + "/";
  s += d.getFullYear();
  s += ' ' + d.getHours();
  s += ':' + d.getMinutes();
  return(s);
}

function setChk(th){
	var f=th.form;
	var n=f.elements.length;
	for(i= 0; i< n; i++) if(f.elements[i].name==th.name) th.checked ? f.elements[i+1].value=f.elements[i+2].value : f.elements[i+1].value='' ; // --- передаем idcategory в переменную-масив
}


/**
 * Checks/unchecks all checkbox in given conainer (f.e. a form, fieldset or div)
 *
 * @param   string   container_id  the container id
 * @param   boolean  state         new value for checkbox (true or false)
 * @return  boolean  always true
 */
function setCheckboxes( container_id, state ) {
    var checkboxes = document.getElementById(container_id).getElementsByTagName('input');

    for ( var i = 0; i < checkboxes.length; i++ ) {
        if ( checkboxes[i].type == 'checkbox' ) {
            checkboxes[i].checked = state;
        }
    }

    return true;
} // end of the 'setCheckboxes()' function

// определяем бровзер
isDOM=document.getElementById //DOM1 browser (MSIE 5+, Netscape 6, Opera 5+)
isOpera=isOpera5=window.opera && isDOM //Opera 5+
isOpera6=isOpera && window.print //Opera 6+
isOpera7=isOpera && document.readyState //Opera 7+
isMSIE=document.all && document.all.item && !isOpera //Microsoft Internet Explorer 4+
isMSIE5=isDOM && isMSIE //MSIE 5+
isNetscape4=document.layers //Netscape 4.*
isMozilla=isDOM && navigator.appName=="Netscape" //Mozilla или Netscape 6.*


var mousex = 0
var mousey = 0
function getMouse()
{
	if(isNetscape4) document.captureEvents(Event.MOUSEMOVE)
	if(isMSIE || isOpera7){
	  document.onmousemove=function(){
		mousex=event.clientX+document.body.scrollLeft
		mousey=event.clientY+document.body.scrollTop
		return true
	  }
	}else if(isOpera){
	  document.onmousemove=function(){
		mousex=event.clientX
		mousey=event.clientY
		return true
	  }
	}else if(isNetscape4 || isMozilla){
	  document.onmousemove=function(e){
		mousex = e.pageX
		mousey = e.pageY
		return true
	  }
	}
}




var popUpWin=0;
function popup2(name, url, left, top, width, height, toolbar, menubar, statusbar, scrollbar, resizable){
	if(popUpWin){ if(!popUpWin.closed) popUpWin.close(); }

	var wint=(screen.height - height) / 2;
	var winl=(screen.width - width) / 2;

	toolbar_str=toolbar ? 'yes' : 'no';
	menubar_str=menubar ? 'yes' : 'no';
	statusbar_str=statusbar ? 'yes' : 'no';

	scrollbar_str=scrollbar ? 'yes' : 'no';
	resizable_str=resizable ? 'yes' : 'no';
	return popUpWin=window.open(url, name, 'left='+left+',top='+top+',width='+width+',height='+height+',status='+statusbar_str+',toolbar='+toolbar_str+',menubar='+menubar_str+',scrollbars='+scrollbar_str+',location=no,directories=no,resizable='+resizable_str);
}

function wOpen(URLStr, left, top, width, height)
{
  if(popUpWin)
  {
    if(!popUpWin.closed) popUpWin.close();
  }
  popUpWin = window.open(URLStr, 'popUpWin', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=yes,width='+width+',height='+height+',left='+left+', top='+top+',screenX='+left+',screenY='+top+'');
}


var TestString = 'failed';
function checkPopUp()
{
	initPopUp();

	if(TestString == 'failed' || TestString == null)
	{
		alert('Для добавления выбранного Вами вала в зака необходимо отключить блокировку всплывающих окон (PopUp)!');
		return false;
	}
	return true;
}

function initPopUp()
{
	var TestPopup = window.open('new','','height=100,width=100,left=50,top=50');
	TestString = TestPopup;
	TestPopup.close();
}


// Helen NikitinA
function second_win(img_path,img_alt){
var str, StrBody;
	str = 'resizable=yes,width=189,height=176,screenX=200,screenY=100,left=100,top=100';
	if (document.all){
		//StrBody = '<body marginwidth="0" marginheight="0" topmargin="0" bottommargin="0" leftmargin="0" rightmargin="0" bgcolor="White" onblur="self.window.close();" onresize="self.window.location.reload();">';
		StrBody = '<body marginwidth="0" marginheight="0" topmargin="0" bottommargin="0" leftmargin="0" rightmargin="0" bgcolor="White" onblur="self.window.close();">';
	} else {
		StrBody = '<body marginwidth="0" marginheight="0" topmargin="0" bottommargin="0" leftmargin="0" rightmargin="0" bgcolor="White" onblur="self.window.close();" >';
	}
	var win_op = window.open('','show', str);
	win_op.document.open();
	win_op.document.writeln('<html>');
	win_op.document.writeln('<head>');
	win_op.document.writeln('<title>' + img_alt + '</title>');
	win_op.document.writeln('<script>');
	win_op.document.writeln('function resize_img() {');
	win_op.document.writeln('var width = document.image.width;');
	win_op.document.writeln('var height = document.image.height;');
	win_op.document.writeln('if (!(document.all)){ self.resizeTo(width,height); } else { self.resizeTo((width+12),(height + 31));');
	win_op.document.writeln('self.resizeTo(width,height);');
	win_op.document.writeln(' }');

	win_op.document.writeln('}');

	win_op.document.writeln("</"+"script>");
	win_op.document.writeln("</"+"head>");
	win_op.document.writeln(StrBody);
	win_op.document.writeln('<img name="image" src='+ img_path + ' border=0 alt="'+img_alt+'" onload="resize_img();">');
	win_op.document.writeln("</"+"body>");
	win_op.document.writeln("</"+"html>");
	win_op.document.close();
}


function setObjValue(objID,val)
{
	var obj = document.getElementById(objID);
	obj.innerHTML=val;
	return;
}


function chkLength(obj, inf_objId, maxLen)
{
	if (obj.value.length<=maxLen)
	{
		setObjValue('cntChar',maxLen-obj.value.length);
	}
	else
	{
		obj.value=obj.value.substring(0,maxLen);
		alert('Вы превысили допустимое количество символов ('+maxLen+') для этого поля!');
	}

	return true;
}