count=0;
sum1=0;

window.onload=initial;
function rowover(thisRow) {
    if (thisRow.className == "row") {
        thisRow.className = "row-over";
    }
}

function rowout(thisRow) {
    if (thisRow.className == "row-over") {
        thisRow.className = "row";
    }
}


function piclick(thispic) {
	inputel=document.getElementById(thispic.title);
	if (inputel.checked)  inputel.checked=false;
	else inputel.checked=true;
	if (thispic.className=="icontainerout")
		thispic.className="icontainerover";
	else
	   thispic.className="icontainerout";
}

function inpiclick (thisin) {
	divc=document.getElementById(thisin.id+"d");
	if (thisin.checked)
		divc.className="icontainerover";
	else
		divc.className="icontainerout";
}

function getElementsByClass(searchClass,tag,node)
{
        var classElements = [];

        if (node == null)
        {
          node = document;
        }

        if (tag == null)
        {
          tag = '*';
        }

        var els = node.getElementsByTagName(tag);
        var elsLen = els.length;

        var pattern = new RegExp("(^|\\s)"+searchClass+"(\\s|$)");
        var i;
        for (i = 0; i < elsLen; i++)
        {
          if (pattern.test(els[i].className))
          {
            classElements[classElements.length] = els[i];
          }
        }

        return classElements;
}

function checkclick(e) {
	masclassel=getElementsByClass(e.id);
	if (e.checked) count++;
	else count--;

	skeys=document.getElementById("sumsearch");
	opt=document.getElementById(e.id);
	/*var zip=/Searches: (\d+)/;
	var kwinf=opt.parentNode.parentNode.childNodes;
	if (kwinf.length==4) kwinf=kwinf[1].firstChild.title;
	else {
		if (navigator.appName=="Microsoft Internet Explorer" || navigator.appName=="Opera") kwinf=kwinf[2].firstChild.title;
		else kwinf=kwinf[4].firstChild.title;
		}
	var found=new Array();
	found[1]="";
	if (zip.test(kwinf))
		found=zip.exec(kwinf);
	if (!isNaN(parseInt(found[1])))
		if (e.checked) sum1=sum1-(-found[1]);
		else sum1-=found[1];
	skeys.innerHTML="Retrieval count (DT): "+sum1;*/

	for (val in masclassel) {
        if (e.checked)  {
        	Highlight(masclassel[val]);
        	masclassel[val].checked=true;
        	}
	    else  {
	    	Unhighlight(masclassel[val]);
	    	masclassel[val].checked=false;
	    	}
        }
	qp=document.getElementById("qphotos");
	qp.innerHTML="Number of marked keywords: "+count;
 }

function Highlight(val) {
    r = val.parentNode.parentNode;
    if (r) {
        r.className = "row-active";
    }
}

function Unhighlight(val) {
	r = val.parentNode.parentNode;
    if (r) {
        r.className = "row";
    }
}

function copytobuf() {
	but=document.getElementById("but1");
	but2=document.getElementById("but2");
	if (navigator.appName=="Microsoft Internet Explorer") {
		but.style.display="inline";
		if (but2) but2.style.display="inline";
		}
	}

function copytoclipboard(f) {
	if (f)
		ta=document.getElementById("chwords");
	else ta=document.getElementById("chwords_user");
	ta.createTextRange().execCommand("Copy");
	}

function doenter(ev) {
     if (navigator.appName=="Microsoft Internet Explorer") {
	     if ((ev.which && ev.which == 13) || (ev.keyCode && ev.keyCode == 13)) {
		     but=document.getElementById("buts");
		     but.click();
		     event.returnValue = false;
	         event.cancel = true;
		     }
	    }
	}

function doenter2(ev) {
     if (navigator.appName=="Microsoft Internet Explorer") {
	     if ((ev.which && ev.which == 13) || (ev.keyCode && ev.keyCode == 13)) {
		     but=document.getElementById("addwords");
		     but.click();
		     event.returnValue = false;
	         event.cancel = true;
		     }
	    }
	}

function changengine(thissel) {
	if (thissel.className=="shut") {
		document.getElementById('sortshut').style.display="none";
		document.getElementById('sortlucky').style.display="inline";
		document.getElementById('showshut').style.display="none";
		document.getElementById('thumbshut').style.display="none";
		document.getElementById('phname').style.display="none";
		document.getElementById('phlink').style.display="none";
		thissel.className="lucky";
		}
	else {
		document.getElementById('sortshut').style.display="inline";
		document.getElementById('sortlucky').style.display="none";
		document.getElementById('showshut').style.display="inline";
		document.getElementById('thumbshut').style.display="inline";
		document.getElementById('phname').style.display="block";
		document.getElementById('phlink').style.display="inline";
		thissel.className="shut";
		}
	}

function showexclude() {
	buf=document.getElementById("exclude");
	if (buf.style.display=="none")
		buf.style.display="block";
	else
		buf.style.display="none";
	}

function loadeng() {
	sel=document.getElementById("seng");
	if (sel.className=="lucky")  {
		document.getElementById('sortshut').style.display="none";
		document.getElementById('sortlucky').style.display="inline";
		document.getElementById('showshut').style.display="none";
		document.getElementById('thumbshut').style.display="none";
		document.getElementById('phname').style.display="none";
		document.getElementById('phlink').style.display="none";
		}
	}

function updatecount() {
	qp=document.getElementById("qphotos");
	qp.innerHTML="Number of marked keywords: "+count;
	skeys=document.getElementById("sumsearch");
	skeys.innerHTML="Retrieval count (DT): "+sum1;
	qp.style.background="#f5f5ea";
	qp.style.color="#000000";
	if (count>50) {
		qp.style.background="#C84144";
	    qp.style.color="#ffffff";
	    }
	}

function uncheckall () {
	arr=getElementsByClass("row-active");
	for (val=0; val<arr.length; val++) {
		arr[val].className="row";
		arr[val].firstChild.firstChild.checked=false;
		}
	count=0;
	sum1=0;
	updatecount();
	}

function eraseall() {
	document.getElementById("allkeywords").innerHTML="";
	document.getElementById("userkeywords").innerHTML="";
	sum1=0;
	count=0;
	updatecount();
	arrkw=Array();
	}

function showwait()  {
	if (document.getElementById("waitingstr").style.display=="none")
		document.getElementById("waitingstr").style.display="block";
	}

function showphname() {
	buf=document.getElementById("phname");
	if (buf.style.display=="none")
		buf.style.display="block";
	else
		buf.style.display="none";
	}

function initial () {
	document.getElementById("eakw").style.display="inline";
	}

function marktop50()  {
	remidentical();
	arr=getElementsByClass("row-active");
	for (val=0; val<arr.length;  val++) {
		arr[val].className="row";
		arr[val].firstChild.firstChild.checked=false;
		}
	arr=getElementsByClass("row");
	count=0;
	sum1=0;
	i=0;
	for (val=0; val<arr.length;  val++){
		arr[val].className="row-active";
		arr[val].firstChild.firstChild.checked=true;
		count++;

		/*var zip=/Searches: (\d+)/;
		var kwinf=arr[val].childNodes;
		if (kwinf.length==4) kwinf=kwinf[1].firstChild.title;
		else {
			if (navigator.appName=="Microsoft Internet Explorer" || navigator.appName=="Opera") kwinf=kwinf[2].firstChild.title;
			else kwinf=kwinf[4].firstChild.title;
			}
		var found=new Array();
		found[1]="";
		if (zip.test(kwinf))
			found=zip.exec(kwinf);
		if (!isNaN(parseInt(found[1]))) sum1=sum1-(-found[1]);*/

		i++;
		updatecount();
		if (i>=50) break;
		}
	document.body.className="body";
	}

function remuncheck() {
	arr=getElementsByClass("row");
	kolvo=arr.length;
	for (val=0; val<kolvo; val++)  {
		arr[val].parentNode.parentNode.style.display="none";
		arr[val].parentNode.parentNode.parentNode.removeChild(arr[val].parentNode.parentNode);
    	}
    }


function remidentical() {
	var uniq=new Array();
	str="";
	arr=getElementsByClass("row-active");
	arr=arr.concat(getElementsByClass("row"));
	for (val=0; val<arr.length; val++)  {
		f=0;
		for (val2=0; val2<uniq.length; val2++) {
			if (uniq[val2]==arr[val].firstChild.firstChild.id) {
				f=1;
				break;
				}
			}
		if (f) {
			arr[val].parentNode.parentNode.style.display="none";
			arr[val].parentNode.parentNode.parentNode.removeChild(arr[val].parentNode.parentNode);
			}
		else {
			uniq[uniq.length]=arr[val].firstChild.firstChild.id;
			}
		}
	document.body.className="body";
    }

function changesum(thistr,addition) {
	var zip=/Searches: (\d+)/;
	var kwinf=thistr.childNodes;
	if (kwinf.length==4) kwinf=kwinf[1].firstChild.title;
	else {
		if (navigator.appName=="Microsoft Internet Explorer" || navigator.appName=="Opera") kwinf=kwinf[2].firstChild.title;
		else kwinf=kwinf[4].firstChild.title;
		}
	var found=new Array();
	found[1]="";
	if (zip.test(kwinf))
		found=zip.exec(kwinf);
	if (!isNaN(parseInt(found[1])))
		if (addition)
			sum1=sum1-(-found[1]);
		else sum1-=found[1];
	if (addition)
		count++;
	else count--;
	updatecount();
	}

function delkw (thiskw) {
	if (thiskw.parentNode.firstChild.checked) {
		thiskw.parentNode.firstChild.checked=false;
		checkclick(thiskw.parentNode.firstChild);
		}
	thiskw.parentNode.parentNode.parentNode.parentNode.style.display="none";
	thiskw.parentNode.parentNode.parentNode.parentNode.parentNode.removeChild(thiskw.parentNode.parentNode.parentNode.parentNode);
	}