var messageConfirm = 'Подтверждаете';
var messageCancel = 'Операция отменена';


/* WFX : JavaScript Document */

// -----------------------------------------------------------
function MM_findObj(n, d) { //v4.01
  var p,i,x;  
	if(!d) d=document; 
	if ((p=n.indexOf("?"))>0 && parent.frames.length) 
	{ d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p); }
	
  if (!(x=d[n]) && d.all) x=d.all[n]; 
	  for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
		
  for (i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}
// -----------------------------------------------------------
function ToggleVisible(id)
{ 
	var el = MM_findObj(id);
	
	if ( el )
	{
  	if (el.style.display == "none") el.style.display = "";
		else el.style.display = "none";
	}
}

// -----------------------------------------------------------
function SetVisible(id, status)
{ 
	var el = MM_findObj(id);
	
	if ( el )
	{
  	if (status == 1) el.style.display = "";
		else el.style.display = "none";
	}
}
// -----------------------------------------------------------
function ConfirmOperation(operationURL, operation_message)
{
  if (confirm(operation_message + ". \n\n" + messageConfirm + ' ?')) 
	    window.location.href=operationURL;
  else alert (messageCancel);
}
// -----------------------------------------------------------
function ConfirmPostOperation(form_obj, operation_message)
{
  if (confirm(operation_message + ". \n\n" + messageConfirm + ' ?')) 
	    form_obj.submit();
  else alert (messageCancel);
}
// -----------------------------------------------------------
// данная функция отличается от предыдущей тем, что
// запрашивает ответ пользователя до изменения поля
// action в форме
function PreConfirmPostOperation(form_obj, operation_message)
{
  if (confirm(operation_message + ". \n\n" + messageConfirm + ' ?')) return true;
  else { alert (messageCancel); return false; }
}

function PreConfirmOperation(operation_message)
{
  if (confirm(operation_message + ". \n\n" + messageConfirm + ' ?')) return true;
  else { alert (messageCancel); return false; }
}
// -----------------------------------------------------------
function SubmitFormToAction(form_obj, action)
{
	form_obj.action = action;
  form_obj.submit();
}
// -----------------------------------------------------------
function GetCurrentDate()
{
	var today = new Date();
	
	return today.getFullYear() + '-' + (today.getMonth()+1) + '-' + today.getDate() + ' ' +
				 today.getHours() + ':' + today.getMinutes() + ':' + today.getSeconds();
}
// -----------------------------------------------------------
function no_action()
{
	/* системная функция, которая просто ничего не делает */
	// return 0;
}
// -----------------------------------------------------------
/*
function HighLight_ON(object_id)
{
  var el = document.all[object_id];
	el.style.backgroundColor = "#F6F6F6";
} 
// -----------------------------------------------------------
function HighLight_OFF(object_id)
{
  var el = document.all[object_id];
	el.style.backgroundColor = "#FFFFFF";
} 
*/
// -----------------------------------------------------------
function ButtonClick(object_id, action, disable)
{
	var el = MM_findObj(object_id);
	
	if ( disable ) el.onclick = '';
	
	eval(action.replace(/`/g, "'"));
}
// -----------------------------------------------------------
// 
//                    LIST FUNCTIONS
//
// -----------------------------------------------------------
function RowToggle( object_id )
{
	var obj = MM_findObj(object_id);
	var checkbox = MM_findObj('select_ids_' + object_id);
	var new_class_name = '';
	
	switch (obj.className)
	{
		case 'row_light': { new_class_name = 'row_light_selected'; break; }
		case 'row_dark':  { new_class_name = 'row_dark_selected';  break; }
		case 'row_light_selected': { new_class_name = 'row_light'; break; }
		case 'row_dark_selected':  { new_class_name = 'row_dark';  break; }
	}
	
	obj.className = new_class_name;
	checkbox.checked = !checkbox.checked;
}
// -----------------------------------------------------------
function RowMark( object_id, mark_selected )
{
	var obj = MM_findObj(object_id);
	var checkbox = MM_findObj('select_ids_' + object_id);
	
	if ( mark_selected != checkbox.checked ) RowToggle( object_id );
}
// -----------------------------------------------------------
function void_func()
{
	return;
}
// -----------------------------------------------------------
function EMProtect( email, params, text )
{
	var address = email.split('_spamAT');
	
	document.write('<a href="mai');
	document.write('lto');
	document.write(':' + address[0]);
	document.write('@');
	document.write(address[1]);
	
	if ( text == '' ) text = address[0] + '@' + address[1];
	
	document.write('" ' + params + '>' + text + '</a>');
	
	return;
}
// -----------------------------------------------------------
function SelectExtra (selObjID)
{
	var selObj = document.getElementById(selObjID);
	if (!selObj) return;
	
	value = selObj.options[selObj.selectedIndex].value;
	
	// если выбран пункт "другой вариант.."
	if ( value == 1000 )
	{
		$('#'+selObjID+'_extra').fadeIn();
	}
	else
	{
		$('#'+selObjID+'_extra').fadeOut();
	}
	
}
// -----------------------------------------------------------