	have_to_change=0

	function change_priority(bug_id) {
//		if (have_to_change!=document.forms['prioriteti']['priority'+bug_id].text) {
			ddm=document.forms['prioriteti']['priority'+bug_id]
			htcvalue = ddm.options[ddm.selectedIndex].text

			priority_href='inc/frame_priority.asp?'+
				'bug_id='+bug_id+'&newpriority='+htcvalue
					
			document.forms['prioriteti']['button'+	bug_id].style.backgroundColor='#F0D0D0';
			window.frames['frame_priority'].document.location = priority_href
//		}
	}
	
	function set_priority(bug_id) {
		have_to_change=document.forms['prioriteti']['priority' + bug_id].value;
	}
	
	function change_srok(bug_id, name) {
		if (have_to_change!=document.forms['prioriteti'][name+bug_id].value) {
			priority_href='inc/frame_priority.asp?'+
				'bug_id='+bug_id+'&'+name+'='+document.forms['prioriteti'][name+
				bug_id].value
				
			document.forms['prioriteti'][name + 'btn' +
				bug_id].style.backgroundColor='#F0D0D0';

			window.frames['frame_priority'].document.location = priority_href
		}
	}
	
	function set_srok(bug_id, name) {
		have_to_change=document.forms['prioriteti'][name + bug_id].value;
	}

	function getES(bug_id) {
		return "change_srok(" + bug_id + ", 'srok')" ;
	}

	function star(bug_id) {
		a=document.images['star'+bug_id].src;
		asterix=a.substr(a.length-5, 1);
		
		if (asterix=='1') {
			document.images['star'+bug_id].src='i/star0.gif';
			asterix=0;
		}
		else {
			document.images['star'+bug_id].src='i/star1.gif';
			asterix=1;
		}
		
		priority_href='inc/frame_priority.asp?bug_id='+bug_id+'&star=' + asterix;
		
		window.frames['frame_priority'].document.location = priority_href;
	}

	function chst(bug_id, sO) {
		if (!sO)publicstatus=document.getElementById('chst'+bug_id).innerHTML;
		else publicstatus = ''+sO.options[sO.selectedIndex].value+'&force=1';
		priority_href='inc/frame_priority.asp?bug_id='+bug_id+'&publicstatus=' + publicstatus;
		window.frames['frame_priority'].document.location = priority_href;
	}


	function lckd(bug_id) {
		a=document.images['lckd'+bug_id].src;
		asterix=a.substr(a.length-5, 1);
		
		if (asterix=='1') {
			document.images['lckd'+bug_id].src='i/lckd0.gif';
			asterix=0;
		}
		else {
			document.images['lckd'+bug_id].src='i/lckd1.gif';
			asterix=1;
		}
		
		priority_href='inc/frame_priority.asp?bug_id='+bug_id+'&lckd=' + asterix;
		window.frames['frame_priority'].document.location = priority_href;
	}

	function acpt(bug_id) {
		a=document.images['acpt'+bug_id].src;
		asterix=a.substr(a.length-5, 1);
		
		if (asterix=='1') {
			document.images['acpt'+bug_id].src='i/acpt2.gif';
			asterix=0;
		}
		else {
			document.images['acpt'+bug_id].src='i/acpt1.gif';
			asterix=1;
		}
		
		document.getElementById('b' +bug_id).style.backgroundColor='#F0D0D0';
		priority_href='inc/frame_priority.asp?bug_id='+bug_id+'&acpt=1';
		window.frames['frame_priority'].document.location = priority_href;
		
		hide_new(bug_id);
	}

	function hide_new(bug_id) {
		if (document.getElementById('ban'+bug_id) && document.getElementById('ban'+bug_id).getElementsByTagName('img')) {
			foo = document.getElementById('ban'+bug_id).getElementsByTagName('img');
			for (jj = 0; jj < foo.length; jj++) {
				if (foo[jj].src.substr(foo[jj].src.length-6, foo[jj].src.length) == 'nw.gif' ) {
					foo[jj].src = '/a2/i/null.gif';
				}
			}
		}
	}

	function acp (bug_id, val) {
		document.getElementById('b' +bug_id).style.backgroundColor='#F0D0D0';
		priority_href='inc/frame_priority.asp?bug_id='+bug_id+'&acp='+val;
		window.frames['frame_priority'].document.location = priority_href;
		
		hide_new(bug_id);
	}
	
	function chs (bug_id) {
		sl=document.forms['prioriteti']['allem' + bug_id];
		va=sl.options[sl.selectedIndex].value;
		vt=sl.options[sl.selectedIndex].text;
		confirmRequired = 0;
		for (i=0; i<sl.options.length; i++) {
			if (sl.options[i].text.substring(0, vt.length) == vt && 
				sl.options[i].text.length != vt.length
			) confirmRequired = 1;
		}
						
		if (va>=0) {
			if (!confirmRequired || confirm('Сигурен ли сте, че искате да прехвърлите към '+vt+'?')) {
				ow(bug_id, va);
			}
		}
	}

	function chs3 (bug_id) {
		sl=document.forms['prioriteti']['allen' + bug_id];
		va=sl.options[sl.selectedIndex].value;
		vt=sl.options[sl.selectedIndex].text;
		confirmRequired = 0;
		for (i=0; i<sl.options.length; i++) {
			if (sl.options[i].text.substring(0, vt.length) == vt && 
				sl.options[i].text.length != vt.length
			) confirmRequired = 1;
		}
		
		if (va>=0) {

			if (!confirmRequired || confirm('Сигурен ли сте, че искате да уведомите '+vt+'?')){
				priority_href='inc/frame_priority.asp?bug_id='+bug_id+'&ping='+va;
				document.getElementById('b' +bug_id).style.backgroundColor='#F0D0D0';
				window.frames['frame_priority'].document.location = priority_href;
			}
		}
	}

	function ow(bug_id, newtarget) {
		priority_href='inc/frame_priority.asp?bug_id='+bug_id+'&newtarget='+newtarget;
		document.getElementById('b' +bug_id).style.backgroundColor='#F0D0D0';
		window.frames['frame_priority'].document.location = priority_href
	}

	function os(bug_id, newstatus) {
		priority_href='inc/frame_priority.asp?bug_id='+bug_id+'&newstatus='+newstatus;
		if (newstatus==2) {
			document.getElementById('b' +bug_id).style.backgroundColor='#E0E0E0';
		} else {
			document.getElementById('b' +bug_id).style.backgroundColor='#F0D0D0';
		}
		
		window.frames['frame_priority'].document.location = priority_href
	}

	function me(employee_id) {
		vclist=document.forms['bugs']['victim']
		oc=vclist.options.length
		for (i=0; i<oc; i++) {
			if (vclist.options[i].value==employee_id) {
				vclist.options[i].selected=true
			}
		}
	}

	function attachproject(possibleTarget, SpanID) {
		k=document.forms['bugs']['victim']
		victim=k.options[k.selectedIndex].value
		
		if (!victim) victim=possibleTarget;
		
		priority_href='inc/frame_priority.asp?SpanID='+SpanID+'&target='+victim
		window.frames['frame_priority'].document.location = priority_href
	}

	function atp(possibleTarget, SpanID) {
		priority_href='inc/frame_priority.asp?SpanID='+SpanID+'&target='+possibleTarget
		document.getElementById('h'+SpanID).style.display='none';
		window.frames['frame_priority'].document.location = priority_href
	}
	
	function setProject(bug_id) {
		k=document.forms['prioriteti']['project_id'+bug_id]
		priority_href='inc/frame_priority.asp?bug_id='+bug_id+'&project_id='+k.options[k.selectedIndex].value
		window.frames['frame_priority'].document.location = priority_href
	}
	

function findinvictim(conf, formname, victim, srch) {
	vi=document.forms[formname][victim]
	vic=document.forms[formname][srch].value
		
	viclen=vic.length

	i=0
	notFound=1
	while (i<vi.options.length && notFound) {
		notFound=true
		if (vi.options[i].text.substring(0,viclen).toLowerCase()==vic.toLowerCase()) {
			if (conf && (i!=vi.selectedIndex)) foo=confirm('Към ' + vi.options[i].text + ' ли да бъде задачата?'); else foo=true;
			if (foo) vi.options[i].selected=true;
			notFound=0

		if (document.body.createTextRange) {
			var cursorKeys ="8;46;37;38;39;40;33;34;35;36;45;";
				if (cursorKeys.indexOf(event.keyCode+";") == -1) {
					var r1 = document.forms[formname][srch].createTextRange();
					var newValue = notFound ? vic : vi.options[i].text;
					if (newValue.toLowerCase() != vic.toLowerCase()) {
						document.forms[formname][srch].value = newValue;
						var rNew = document.forms[formname][srch].createTextRange();
						rNew.moveStart('character', viclen) ;
						rNew.select();
					}
				}
			}
		}
		i++
	}
}

function autoComplete (field, select, property, forcematch) {
	var found = false;
	for (var i = 0; i < select.options.length; i++) {
	if (select.options[i][property].toUpperCase().indexOf(field.value.toUpperCase()) == 0) {
		found=true; break;
		}
	}
	if (found) { select.selectedIndex = i; }
	else { select.selectedIndex = -1; }
	if (field.createTextRange) {
		if (forcematch && !found) {
			field.value=field.value.substring(0,field.value.length-1); 
			return;
			}
		var cursorKeys ="8;46;37;38;39;40;33;34;35;36;45;";
		if (cursorKeys.indexOf(event.keyCode+";") == -1) {
			var r1 = field.createTextRange();
			var oldValue = r1.text;
			var newValue = found ? select.options[i][property] : oldValue;
			if (newValue != field.value) {
				field.value = newValue;
				var rNew = field.createTextRange();
				rNew.moveStart('character', oldValue.length) ;
				rNew.select();
				}
			}
		}
	}

function ansf(bug_id, bug2_id) {
	document.forms['bugs2']['answer_to'].value=bug_id
	document.forms['bugs2']['answer2_to'].value=bug2_id
	document.getElementById('fastanswer').style.display=''
	document.getElementById('prioritetidiv').style.display='none'
	document.forms['filtyr'].style.display='none'
	document.forms['bugs'].style.display='none'
	document.forms['bugs2']['url'].value=''
	document.forms['bugs2']['description'].value=''
	document.forms['bugs2']['url'].focus()
	showbug = document.getElementById('showb');
	showbug.innerHTML = document.getElementById('b'+bug_id).innerHTML;
	showbug.style.display='block';
	
	scroll(0,0)
}

function antiansf() {
	document.getElementById('fastanswer').style.display='none'
	document.getElementById('prioritetidiv').style.display='block'
	document.forms['bugs'].style.display=''
	document.forms['filtyr'].style.display=''
	showbug = document.getElementById('showb');
	showbug.innerHTML = '';
	showbug.style.display='none';
	
	obj=document.getElementById('b'+document.forms['bugs2']['answer_to'].value);
	scroll(0,findPosY(obj));
}

function attachfile() {
	document.getElementById('attach').innerHTML='<input type=file name=blob class=b3>'
}
	
function attachfile2() {
	document.getElementById('attach2').innerHTML='<input type=file name=blob class=b3>'
}

function attachsrok() {
	document.getElementById('att-vreme').style.display='none'
	document.getElementById('att-vreme2').style.display=''
}

function attachsro2(subidx) {
	document.getElementById('att-vreme'+subidx).style.display='none'
	document.getElementById('att-vreme2'+subidx).style.display=''
}

function attachsuma() {
	document.getElementById('attach6').innerHTML='Сума: <input type=text name=suma value=0 size=5> '+
	'<select name=exchange_code><option>BGN<option>EUR<option>USD</select> <input type=radio name=razhod value=1 checked>'+
	' разход <input type=radio name=razhod value=0> приход';
}

function findPosY(obj) {
	var curtop = 0;
	if (obj.offsetParent){
		while (obj.offsetParent){
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	}
	else if (obj.y)
		curtop += obj.y;
	return curtop;
}

function spu(bug_id, name) {
	priority_href='inc/frame_priority.asp?'+
		'bug_id='+bug_id+'&action='+name+'&value='+document.forms['prioriteti'][name+
		bug_id].value

	document.forms['prioriteti'][name + bug_id].style.backgroundColor='#F0D0D0';
	window.frames['frame_priority'].document.location = priority_href
}

function lz(a){ 
	if (a<10) return '0'+a; else return a;
}
function defa(bug_id, hours, priority, deadline, employee_id) {
	var today=new Date();
	priostr = '<option>100<option>200<option>300<option>400<option>500<option>600<option>700'+
				'<option>800<option>900<option>1000'
				
	if (!priority) {
		priority = 500;
	}
	
	priostr = '<option>' + priority  + priostr 
	
	if (!deadline) {
		today.setDate(today.getDate()+5);
		deadline = today.getDate() + '.'+lz(today.getMonth()+1) + '.'+((today.getYear()<=200)?today.getYear()+1900:today.getYear());
	}
	
	WRY = ((today.getYear()>1900)?today.getYear():today.getYear()+1900)
	
	document.getElementById('k' + bug_id).innerHTML = '';
	
	document.getElementById('kj'+bug_id).innerHTML +=	'<select name=priority'+
	bug_id+' value="'+priority+'" '+
	' onchange="change_priority('+bug_id+')">'+priostr+
	'</select> <input type=button name=button'+bug_id+
	' value=P title=\'Приоритети\' onclick="incP('+bug_id+')">'+
	'<input type=text size=10 name="srok'+bug_id+'" value="'+deadline+'"'+
	' onfocus="set_srok('+bug_id+', \'srok\')" '+
	' onblur="change_srok('+bug_id+', \'srok\')" '+
	'> <input type=button name="srokbtn'+bug_id+'" value="КД" title="Календарче" '+
	'onclick="set_srok('+bug_id+', \'srok\'); evalstr=getES('+bug_id+'); '+
	' showcal(document.forms[\'prioriteti\'][\'srok'+bug_id+
	'\'],event);">'+
	'<input type=text size=3 name="hours'+bug_id+
	'" onfocus="set_srok('+bug_id+', \'hours\');" '+
	'onblur="change_srok('+bug_id+', \'hours\');" '+
	' value="'+hours+'"> <input type=button name=hoursbtn'+bug_id+
	' value=h title=\'Срок в часове\' onclick="incH('+bug_id+
	')"> &nbsp; <select name=dfv'+bug_id+
	' onchange=\'ajdfv('+bug_id+', this)\'>'+
	option_list + '</select>' +
	"<input type=text name=sr"+bug_id+" size=5 value='' "+ 
	"onkeyup=\" findinvictim(0, 'prioriteti', 'dfv"+bug_id+"', 'sr"+bug_id+"') \" "+
	"onblur= \" findinvictim(1, 'prioriteti', 'dfv"+bug_id+"', 'sr"+bug_id+"') \" >";

	selbox = document.getElementById('dfv'+bug_id);
	
	notFoundSB=0;
	i=0;
	
	while ((i<selbox.options.length) && (notFoundSB == 0) ) {
		if (selbox.options[i].value == employee_id) {
			selbox.options[i].selected = true;
			notFoundSB=1;
		}
		i++;
	}
}

function check_for_poluchatel(employee_id){
	if (opt=document.forms['bugs']['victim']) {
		if (opt.options.selectedIndex==0) {
			if (confirm('Не сте посочил получател. \nНатиснете OK за да поставите себе си.\nНатиснете CANCEL за ръчен избор.')) {
				me (employee_id);
				return true;
			} else {
				return false;
			}
		}
	} else {
		return 'foobar';
	}
}

function seen(bug_id, seenstatus) {
	priority_href='inc/frame_priority.asp?bug_id='+bug_id+'&seen=' + seenstatus;
	window.frames['frame_priority'].document.location = priority_href;
}

function sotdrug(oopt) {
	foobar=document.getElementById('abza').innerHTML
	var re = /victim/gi
	var re1 = /разпределяне/gi
	foobar=foobar.replace(re, 'forcedsender');
	foobar=foobar.replace(re1, 'от името на');
	if (foobar) document.getElementById('otdrug' + oopt).innerHTML=foobar;
}

function attachfile3(sessid, employee_id, resultspan) {
	stl1=window.open("pub/bigfup.php?sesskey=" + sessid + "&employee_id=" + employee_id + "&resultspan="+ resultspan, 
	"AbraCadabra","scrollbars,resizable=no,height=250,width=500,top=175,left=" + 300);
}

	
function fillit (id) {
	document.getElementById("oshte"+id).innerHTML = "<select onchange=\"chs("+id+
				"); this.blur();\" name=allem"+id+">"+ option_list+"</select>"+
				"<input type=text name=srchid"+id+" size=5 value='' "+ 
				"onkeyup=\" findinvictim(0, 'prioriteti', 'allem"+id+"', 'srchid"+id+"') \" "+
				"onblur= \" findinvictim(1, 'prioriteti', 'allem"+id+"', 'srchid"+id+"'); chs("+id+
				"); \"> ";
	
	document.getElementById("hd"+id).style.display='none';
}

function fillit2(tagid) {
	document.getElementById(tagid).innerHTML = "<select name=victim>" +
		option_list + "</select>"
}

function fillit3 (id) {
	//tova ne e dobre taka, dublira code na fillit()
	document.getElementById('wro'+id).innerHTML = "<select onchange=\"chs3("+id+
				"); this.blur();\" name=allen"+id+"><option value=0>Уведоми"+ option_list.substr(28) +"</select>"+
				"<input type=text name=srchi"+id+" size=5 value='' "+ 
				"onkeyup=\" findinvictim(0, 'prioriteti', 'allen"+id+"', 'srchi"+id+"') \" "+
				"onblur= \" findinvictim(1, 'prioriteti', 'allen"+id+"', 'srchi"+id+"'); chs3("+id+
				"); \"> ";
	
}

function fillit4(tagid) {
	document.getElementById(tagid).innerHTML = "<select name=ping_id size=10 multiple onblur='summarize_ping(this)'>" +
		option_list.substr(10) + "</select><br />"
}

function summarize_ping(pings) {
	strout = ''
	for (i=0; i<pings.options.length; i++) 
		if (pings.options[i].selected) strout += ',' + pings.options[i].value ;
	if (strout) document.forms['bugs']['ping'].value = strout.substring(1);
}

function ajdfv(id, seltag) {
	selemp = seltag.options[seltag.selectedIndex].value;
	priority_href='inc/frame_priority.asp?bug_id='+id+'&newtarget='+selemp;
	window.frames['frame_priority'].document.location = priority_href;
}

function incBase(ddm) {
	if (ddm.options[ddm.selectedIndex].text)
		htcvalue = parseFloat(ddm.options[ddm.selectedIndex].text) + 100;
	else htcvalue=600;
	
	notFoundHT =0;
	i=0;
	
	while ((i<ddm.options.length) && (notFoundHT == 0) ) {
		if (ddm.options[i].text == htcvalue.toString()) {
			ddm.options[i].selected = true;
			notFoundHT=1;
		}
		i++;
	}
}

function incP(bug_id) {
	ddm=document.forms['prioriteti']['priority'+bug_id];
	incBase(ddm);
	change_priority(bug_id);
}

function in2P(subidx) {
	fname = (subidx)?'2':'';
	ddm = document.forms['bugs'+fname]['priority'+subidx];
	incBase(ddm);
}

function incH(bug_id) {
	set_srok(bug_id, 'hours');
	document.forms['prioriteti']['hours' + bug_id].value =
		parseFloat(document.forms['prioriteti']['hours'+ bug_id].value) + 1;
	change_srok(bug_id, 'hours');
}

function inc2(subidx) {
	fname = (subidx)?'2':'';
	ddm = document.forms['bugs'+fname]['hours0'+subidx];
	if (ddm.value) ddm.value = parseFloat(ddm.value)+1; else ddm.value=1;
}

function editsuma(bug_id, suma) {
	document.getElementById('suma'+bug_id).innerHTML = 'Редактиране на сума: <input type=text name=bugsuma'+
	bug_id+' '+' value="'+suma+'" onblur="javascript:sendsuma('+bug_id+', this.value)">'
}

function sendsuma(bug_id, suma) {
	priority_href='inc/frame_priority.asp?bug_id='+bug_id+'&newsuma='+suma;
	window.frames['frame_priority'].document.location = priority_href;
}

function editdesc(bug_id) {
	priority_href='inc/frame_priority.asp?bug_id='+bug_id+'&action=loaddesc';
	window.frames['frame_priority'].document.location = priority_href;
	
	document.getElementById('edbt'+bug_id).style.display='none';
}

function savedesc(bug_id) {
	document.forms['ssf']['sf'].value = document.forms['prioriteti']['editbugdesc'+bug_id].value
	document.forms['ssf'].target = 'frame_priority';
	document.forms['ssf'].action = 'inc/frame_priority.asp?bug_id='+bug_id+'&action=savebug';
	document.forms['ssf'].method = 'post';
	document.forms['ssf'].submit();
}

function diffbug_id(bug_id, answer_to) {
	if (confirm('Това ще раздели 1 фийдбек на 2, операцията е необратима!')) {
		priority_href='inc/frame_priority.asp?bug_id='+bug_id+'&splitfrom='+answer_to;
		window.frames['frame_priority'].document.location = priority_href;
	}
}

function hdb(pos_id, showpos) {
	priority_href='inc/frame_priority.asp?pos_id='+pos_id+'&showpos='+showpos
	window.frames['frame_priority'].document.location = priority_href;
	if (!showpos) document.getElementById('dw'+pos_id).style.display='none';
}

function unsub(bug_id, employee_id) {
	priority_href='inc/frame_priority.asp?bug_id='+bug_id+'&unsub=' + employee_id;
	window.frames['frame_priority'].document.location = priority_href;
}

function copyp(bug_id) {
	priority_href='inc/frame_priority.asp?bug_id='+bug_id+'&copytoanswer=1'
	window.frames['frame_priority'].document.location = priority_href;
}

function findallfb(bug_id) {
	priority_href='inc/frame_priority.asp?bug_id='+bug_id+'&allanswers=1'
	window.frames['frame_priority'].document.location = priority_href;
}
