var req;var srcpage;
function in001() {document.getElementById('tags').innerHTML = "<img border=\"0\" src=\"../images/indicator.gif\" width=\"16\" height=\"16\"> Getting caste suggestions";
document.getElementById("caste").value = ""; 
}function loadMatTags(religion, sr) {
	srcpage = sr;in001();
	qryurl = "getmtags.jsp?rel=" + religion;
	// 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();	} 	}
}
function d898() {	
	t = "";
	try{		ctags = req.responseXML.getElementsByTagName("ctag");
		if(ctags){			tagCount = ctags.length;
			if(tagCount > 0 ){				t = "<span class=\"ajtag\">Simply click on the following caste suggestions.<br>";
				atag = "";				for(i=0, j=1; i<tagCount; i++, j++ ){

					if(ctags[i].firstChild){						atag = ctags[i].firstChild.nodeValue;
						if(srcpage == 1)
						{							t += "<a href=\"javascript:setCaste('" + atag +"')\">" + atag + "</a>&nbsp;&nbsp;";
						}
						else{							t += "<a href=\"javascript:addCaste('" + atag +"')\">" + atag + "</a>&nbsp;&nbsp;";
						}
						

						if( j % 8 == 0 ){
							t +="<br>";
						}
						}				}
				t += "</span>";				
			}		}	}	
	catch(e)	{	}document.getElementById('tags').innerHTML = t;
}
function setCaste(c){
	document.getElementById("caste").value = c; 
}
function addCaste(c){
	cval = document.getElementById("caste").value;
	if(cval && cval.length > 0 ){
		cvals = cval.split(',');
		added = false;
		cval = "";
		for( i=0; i<cvals.length; i++){
			if(cvals[i].length == 0){
				continue;
			}
			if(cvals[i] == c){
				added = true;		
			}
			else{
				cval += cvals[i] + ",";
			}
		}
		if(!added){
				cval += c;
		}
	}
	else{
		cval = c;
	}
	document.getElementById("caste").value = cval; 
}
