// -----------------------------------------------------------
function ConfirmOperation(operationURL, operation_message)
{
	if (confirm(operation_message + ". \n\nПодтверждаете ?")) window.location.href=operationURL;
	else alert ('Операция отменена');
}
// -----------------------------------------------------------
function PreConfirmOperation(operation_message)
{
	if (confirm(operation_message)) return true;
	else { alert ('Операция отменена'); return false; }
}

function PreConfirmOperation_Message(operation_message, cancel_message)
{
	if (cancel_message == '') cancel_message = 'Операция отменена';
	
	if (confirm(operation_message)) return true;
	else { alert (cancel_message); return false; }
}
// -----------------------------------------------------------
function SubmitFormToAction(form_obj, action)
{
	form_obj.attr('action', action);
	form_obj.submit();
}
// -----------------------------------------------------------
function no_action()
{
	/* системная функция, которая просто ничего не делает */
	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]);
	
	document.write('" ' + params + '>' + text + '</a>');
	
	return;
}

function EMProtect_Text( email )
{
	var address = email.split('_spamAT');
	
	document.write(address[0]);
	document.write('@');
	document.write(address[1]);
	
	return;
}
// -----------------------------------------------------------
function OpenSpace( padding_size )
{
	document.write('<table width="100%"><tr><td style="padding: ' + padding_size + 'px;">');
}
// -----------------------------------------------------------
function CloseSpace()
{
	document.write('</td></tr></table>');
}
// -----------------------------------------------------------
// <MULTI-SELECT> validation (limit number of selected items)
var selectedOptions = [];

function validateMultiSelect( maxItems, selectObj )
{
	for(var i=0; i<selectObj.options.length; i++){
     if(selectObj.options[i].selected && !new RegExp(i,'g').test(selectedOptions.toString())){
        selectedOptions.push(i);
     }

     if(!selectObj.options[i].selected && new RegExp(i,'g').test(selectedOptions.toString())){
      selectedOptions = selectedOptions.sort(function(a,b){return a-b});  
       for(var j=0; j<selectedOptions.length; j++){
         if(selectedOptions[j] == i){
            selectedOptions.splice(j,1);
         }
       }
     }

     if(selectedOptions.length > maxItems){
        alert('You may only choose '+maxItems+' options!');
        selectObj.options[i].selected = false;
        selectedOptions.pop();
        document.body.focus();
     }  
   }    
}

// -----------------------------------------------------------
