var filter_content="";
var getR;
var selfURL = document.location.href;
//alert(selfURL);

function getMDBresponse(fcontent)
{
	getR = ajaxFunction();
	if (getR) {
		
		getR.onreadystatechange = getReponse;
	    getR.open("GET","http://entertainment.oneindia.in/common/php/getMatchingTags.php?addr="+selfURL+"&tags="+fcontent, true);
    	getR.send(null);
	}
}

function getReponse()
{
	if (getR.readyState == 4){
		if(getR.responseText.length > 1) {
			enableDIV = document.getElementById("right_mdb_box").style.visibility = 'visible';
			statusDiv = document.getElementById("mdbtags");
			var restext = "<table border='0' cellpadding='5' align='center' cellspacing='0' width='300'>";
			restext+= getR.responseText;
			restext+= "</table>";
			statusDiv.innerHTML = restext;
		}
	}
}

function processStateChange(){
		if (req.readyState == 4){
		scontent = req.responseText;
		var strpos = scontent.indexOf('Tags:');
		//alert(strpos);
		var nst = parseInt(strpos)+13;
		var endpos = scontent.indexOf("</p>",nst);
		//alert(endpos);
		filter_content = strip_tags(scontent.substring(nst,endpos));
		getMDBresponse(filter_content);
		//alert(strip_tags(filter_content));
	}
}

var req = ajaxFunction();
if (req) {
	req.onreadystatechange = processStateChange;
    req.open("GET",selfURL, true);
    req.send(null);
}

//Strip html tags
function strip_tags( str ){
    return str.replace(/<\/?[^>]+>/gi, '');
}

function ajaxFunction()
{
	var xmlHttp;
	try
	{
		// Firefox, Opera 8.0+, Safari
		xmlHttp=new XMLHttpRequest();
	}
	catch (e)
	{
		// Internet Explorer
		try
		{
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e)
		{
			try
			{
				xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (e)
			{
				alert("Your browser does not support AJAX!");
				return false;
			}
		}
	}
	return xmlHttp;
}