function changeSort(new_id, current_id) {
  if ( new_id != current_id ) {
    var masterform = document.np_masterform;
    masterform.removeAttribute('target');
    masterform.oper.value='change_sort';
    masterform.sort.value=new_id;
    masterform.submit();
  }
}

function addAdvice() {
  var masterform = document.np_masterform;
  masterform.oper.value='add_advice';
  masterform.setAttribute('target', 'add_adv_window');
  windowPopup('masterform', 'add_adv_window', 380, 460)
  masterform.submit();
}

function addComment() {
  var masterform = document.np_masterform;
  masterform.oper.value='add_comment';
  masterform.setAttribute('target', 'add_comm_window');
  windowPopup('masterform', 'add_comm_window', 380, 340)
  masterform.submit();
}

function windowPopup(formName, targetName, ipWidth, ipHeight, ipShowScroll)
{
  ipShowScroll = typeof(ipShowScroll) != 'undefined' ? ipShowScroll : 0;
  ipShowScroll = ipShowScroll == 0 ? 0 : 1;

  var nleft = (screen.width - ipWidth)/2;
  var ntop = (screen.height - ipHeight)/2;
  window.open("",targetName,"height="+ipHeight+"px,width="+ipWidth+"px,status=0,toolbar=0,resizable=0,scrollbars="+ipShowScroll+",location=0,statusbar=0,menubar=0,left="+nleft+",top="+ntop).focus();
  var a = window.setTimeout("document."+formName+".submit();",100);
}

function addMark(adv_id, mark) {
  var masterform = document.np_masterform;
  masterform.removeAttribute('target');
  masterform.mark.value=mark;
  masterform.adv_id.value=adv_id;
  masterform.oper.value='add_mark';
  masterform.submit();
}

function loadAdvice(adv_id) {
  var masterform = document.np_masterform;
  masterform.removeAttribute('target');
  masterform.oper.value='';
  masterform.adv_id.value=adv_id;
  masterform.submit();
}

function loadAuthorAdvice(author_name) {
  var masterform = document.np_masterform;
  masterform.removeAttribute('target');
  masterform.oper.value='';
  masterform.adv_id.value=-1;
  masterform.sel_gro_id.value=0;
  masterform.sel_sgr_id.value=0;
  masterform.author_mode.value=1;
  masterform.author_name.value=author_name;
  masterform.submit();
}

function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}


