var targer_obj = '';


function close_pix() {
var div_out = document.getElementById('message_div');
div_out.innerHTML = '';
div_out.style.width = '10px';
div_out.style.height =  '10px';
div_out.style.top = '-1000px';
div_out.style.left = '-1000px';
}

function open_pix(pix_path, w_w, w_h) {
var div_out = document.getElementById('message_div');
var x_w = document.documentElement.scrollTop + (document.documentElement.clientHeight/2) - (w_h/2);
var y_w = document.documentElement.scrollLeft + (document.documentElement.clientWidth/2) - (w_w/2);

div_out.innerHTML = '<IMG src="'+pix_path+'" style="border:1px solid #888888; cursor:pointer;" onClick="close_pix();" />';


div_out.style.width = 'auto';
div_out.style.height =  'auto';

div_out.style.top = x_w+'px';
div_out.style.left = y_w+'px';

}

function actyvation_set(id_pred, url_dom) {



url_dom +='/moduls/set_actuality.php';


targer_obj = id_pred;
//alert(id_pred.value);

SendRequest("GET", url_dom, '&sett='+id_pred.id+'&sett2='+id_pred.value,  actyvation_mess2);

//request_in(url_dom, id_pred.value);
}


function actyvation_mess2(message) {

//alert (message);

}

function actyvation_mess(message) {

targer_obj.value = message;

}

function date_set(id_pred, url_dom) {



url_dom +='/moduls/set_date.php';


targer_obj = id_pred;
//alert(id_pred.value);

SendRequest("GET", url_dom, '&sett='+id_pred.name, actyvation_mess);

//request_in(url_dom, id_pred.value);
}




// сокрытие полей 




// Изменения, связанные с выбором типа предложения
function set_type_price(type_price)
{
	var e = type_price.parentNode;
	var div_out = document.getElementById('add_div_1');
	var out_price_type='';
	var all_checked='';
    // формирование надписи рядом с полем "Цена объекта"
	for (var i=0; i<e.childNodes.length;i++)
	{
		if (e.childNodes[i].checked)
		{
			out_price_type+=', '+e.childNodes[i+1].innerHTML;
			all_checked+=e.childNodes[i].value;
		} 
	}
	div_out.innerHTML='( '+out_price_type.substr(2)+' )';
    // проверка, если аренда, то выводить все, если нет, то только часть =)
	var re = /(arenda)/;
	if (re.test(all_checked)) 
	{
		if (document.getElementById('price_out_0')) show_pol(0);
		if (document.getElementById('price_out_1')) show_pol(1);
		if (document.getElementById('price_out_2')) show_pol(2);	
		if (document.getElementById('price_out_3')) show_pol(3);
	}
	else
	{
		if (document.getElementById('price_out_0')) hidde_pol(0);
		if (document.getElementById('price_out_1')) hidde_pol(1);
		if (document.getElementById('price_out_2')) hidde_pol(2);
		if (document.getElementById('price_out_3')) hidde_pol(3);
	}
}

// добавление еще одного поля "Цена"
function add_more_price(butt)
{
	var div_out_1 = document.getElementById('price_out_0');
	var div_out_2 = document.getElementById('price_out_other');
	var numb_div = 1;
    for (var i=0; i<div_out_2.childNodes.length;i++)
	{
		if (div_out_2.childNodes[i].id) numb_div++;
	}
    numb_div++;
    if (numb_div>=3) butt.disabled=true;
    div_out_2.innerHTML +='<div id="price_out_'+ numb_div +'">'+div_out_1.innerHTML+'</div>';
    var div_out_3 = document.getElementById('price_out_'+ numb_div);
    for (var i=0; i<div_out_3.childNodes.length;i++)
	{
		if (div_out_3.childNodes[i].name) 
		{
			div_out_3.childNodes[i].name = div_out_3.childNodes[i].name.substr(0, (div_out_3.childNodes[i].name.length-3))+'['+numb_div+']';
		}
	}
}

// определение количества полей при загрузке
function get_more_price() 
{
var div_out_2 = document.getElementById('price_out_other');
var butt = document.getElementById('add_more_price_butt');
var numb_div = 1;

for (var i=0; i<div_out_2.childNodes.length;i++) {
	if (div_out_2.childNodes[i].id) numb_div++;
}


if (numb_div>=3) butt.disabled=true; else butt.disabled=false;

}



// сокрытие полей

function hidde_pol(numb_div) {
	var div_hp = document.getElementById('price_out_'+numb_div);
	var j=0;


	
for (var i=0; i<div_hp.childNodes.length; i++) {
	if ((div_hp.childNodes[i].name)  && (div_hp.childNodes[i].name=='price_type['+numb_div+']') )
		{
			j++;

				if ((j>1) && (j<4))	
					{ 

						div_hp.childNodes[i].disabled=true; 
							if (div_hp.childNodes[i].checked) div_hp.childNodes[2].checked=true;

					}

		}

	if ((div_hp.childNodes[i].name) && (div_hp.childNodes[i].name=='price_time['+numb_div+']') ) 
		{
						div_hp.childNodes[i].childNodes[1].selected=true;
						div_hp.childNodes[i].style.display="none";

				
		}
	

}

}

// показ полей
function show_pol(numb_div) {
	var div_hp = document.getElementById('price_out_'+numb_div);
	var j=0;

for (var i=0; i<div_hp.childNodes.length;i++) {
	if ((div_hp.childNodes[i].name)  && (div_hp.childNodes[i].name=='price_type['+numb_div+']') )
		{
			j++;

				if ((j>1) && (j<4))	
					{ 
						div_hp.childNodes[i].disabled=false; 

					}

		}
	if ((div_hp.childNodes[i].name)  && (div_hp.childNodes[i].name=='price_time['+numb_div+']') ) 
		{


			div_hp.childNodes[i].style.display="inline";

		}


}

}

function opt_disabled(se_obj){
try {
var selIndex = se_obj.selectedIndex;
if(se_obj.options[selIndex].disabled){
while (se_obj.options[selIndex].disabled) selIndex +=1;
se_obj.selectedIndex = selIndex; }
return true;
}catch(e){ }
}



// превью на видео

function show_icons(icon_now) {
var div_out = document.getElementById('message_div');
var w_h = 400;
var w_w = 400;
var outer = '';



div_out.innerHTML = '<div style="border:1px solid #888888; cursor:pointer; padding:3px; float:right; margin:5px; margin-top:-5px; margin-right:-5px; //margin-right:0px;" onClick="close_mess();"><small>закрыть X</small></div>';


div_out.innerHTML +='<b>Выбор превью: </b><br/><span id="now_img"></span><br/><div style=" padding:5px; text-align:center;" id="message_div2"></div>'; 
//<span id="now_img"><IMG src="'+icon_now.src+'" /></span>

SendRequest('get', '/moduls/preview_list.php', 'id='+icon_now.id, 'message_div2', 'message_div2', 2);



div_out.style.width = '468px';
div_out.style.height =  'auto';


var y_w = getImageX(icon_now);
var x_w = getImageY(icon_now);

div_out.style.top = x_w+'px';
div_out.style.left = y_w+'px';


}


function close_mess() {
var div_out = document.getElementById('message_div');
div_out.innerHTML = '';
div_out.style.width = '10px';
div_out.style.height =  '10px';
div_out.style.top = '-1000px';
div_out.style.left = '-1000px';
}


function getImageX(imgElem) {
  xPos = eval(imgElem).offsetLeft;
  tempEl = eval(imgElem).offsetParent;
    while (tempEl != null) {
     xPos += tempEl.offsetLeft;
     tempEl = tempEl.offsetParent;
    }
  return xPos;
}
function getImageY(imgElem) {
   xPos = eval(imgElem).offsetTop;
   tempEl = eval(imgElem).offsetParent;
     while (tempEl != null) {
      xPos += tempEl.offsetTop;
      tempEl = tempEl.offsetParent;
     }
   return xPos;
}


function icon_set(icon, id_raz, id_video) {
var icon_list = document.getElementById('message_div2').getElementsByTagName('IMG');
var image_title = document.getElementById(id_video).parrentNode;


for (var i=0; i<icon_list.length; i++)
{
	icon_list[i].parentNode.style.border="1px solid #cfcfcf";
//	icon_list[i].parentNode.style.background="#ffffff";
}

icon.parentNode.style.border="1px solid #6DABAA";
//icon.parentNode.style.background="#6DABAA";

SendRequest('get', '/moduls/video_prev_set.php', 'id='+id_raz+'&set_img='+icon.src+'&id_video='+id_video, id_video, id_video, 2);

//image_title.src = icon.src;

//document.getElementById('icon;'+id_raz).src = icon.src;

}



function dell_photo(id_img, file_img, id_dir) {
var div_img = document.getElementById(id_img);

//div_img.innerHTML = 'Удаленно';

SendRequest('get', '/moduls/dell_photo.php', 'file_img='+file_img+'&id_img='+id_dir, id_img, id_img, 2);

}
