var req;var srcpage;
function in001() {//document.getElementById('stags').innerHTML = "<img border=\"0\" src=\"images/indicator.gif\" width=\"16\" height=\"16\"> Loading Category Suggestions....";
}function loadMatTags(st) {
	srcpage = st;
	in001();
	qryurl = "getyptags.jsp?start=" + st;
	// branch for native XMLHttpRequest object
	if (window.XMLHttpRequest) {req = new XMLHttpRequest();	req.onreadystatechange = processctags;
		req.open("GET",qryurl , true);	req.send(null);	} else if (window.ActiveXObject) {	
		req = new ActiveXObject("Microsoft.XMLHTTP");		if (req) {		
			req.onreadystatechange = processctags;			req.open("GET", qryurl, true);
			req.send();		}		}}
function processctags() {	if (req.readyState == 4) {
		if (req.status == 200) {	d898();	} 	
		else{document.getElementById('stags').innerHTML =""}
	}
}
function d898() {	
	t = "";
	try{		ctags = req.responseXML.getElementsByTagName("ctag");
		if(ctags){			tagCount = ctags.length;
			if(tagCount > 0 ){				t = "";
				atag = "";				for(i=0,j=0; i<tagCount && j<5; i++ , j++){
					if(ctags[i].firstChild){						atag = ctags[i].firstChild.nodeValue;

					t += "<a title=\"Click to add this category\" href=\"javascript:setTag('" + atag +"')\">" + atag + "</a>&nbsp;&nbsp;";
					}				}
				
			}
			else{t ="&nbsp;";}
			}	}	
	catch(e)	{	}document.getElementById('stags').innerHTML = t;
}
function tc1(){ 
	tval = document.getElementById("categories").value;
	if(tval && tval.length >= 1 ){
		cvals = tval.split(',');		lastVal = cvals[cvals.length-1];
		if(lastVal && lastVal.length >= 1 ){
			loadMatTags(lastVal);		}	}}function setTag(c){
	cval = document.getElementById("categories").value;
	if(cval && cval.length > 0 ){
		cvals = cval.split(',');
		added = false;
		cval = "";
		for( i=0; i<cvals.length-1; i++){
			if(cvals[i].length == 0){
				continue;
			}
			if(cvals[i] == c){
				added = true;		
				cval += cvals[i] + ",";
			}
			else{
				cval += cvals[i] + ",";
			}
		}
		if(!added){
				cval += c;
		}
	}
	else{
		cval = c;
	}
	document.getElementById("categories").value = cval; 
}
