var maxAid = 6;	

function doClick(buttonName,e)
{
	//the purpose of this function is to allow the enter key to 
	//point to the correct button to click.
	var key;

	if(window.event)
		key = window.event.keyCode;     //IE
	else
		key = e.which;     //firefox

	if (key == 13)
	{
		//Get the button the user wants to have clicked
		var btn = document.getElementById(buttonName);
		if (btn != null)
		{ //If we find the button click it
			btn.click();
			event.keyCode = 0
		}
	}
}


/////////// AJAX /////////////////


	var xmlHttpReceive=null;

	//supports all os, not tested on operas
	function GetXmlHttpObject(handler)
	{ 
		var objXmlHttp = null;    
		if (!window.XMLHttpRequest)
		{
			// Microsoft Active X object
			objXmlHttp = GetMSXmlHttp();
			if (objXmlHttp != null)
			{
				objXmlHttp.onreadystatechange = handler;
				
			}
		} 
		else
		{
			//they have home tailored control for request
			// Mozilla | Netscape | Safari
			objXmlHttp = new XMLHttpRequest();
			if (objXmlHttp != null)
			{
				objXmlHttp.onload = handler;
				objXmlHttp.onerror = handler;
				
			}
		} 
		return objXmlHttp; 
	} 

	function GetMSXmlHttp()
	{
		var xmlHttp = null;
		var clsids = ["Msxml2.XMLHTTP.6.0","Msxml2.XMLHTTP.5.0",
					"Msxml2.XMLHTTP.4.0","Msxml2.XMLHTTP.3.0", 
					"Msxml2.XMLHTTP.2.6","Microsoft.XMLHTTP.1.0", 
					"Microsoft.XMLHTTP.1","Microsoft.XMLHTTP"];
		for(var i=0; i<clsids.length && xmlHttp == null; i++) 
		{
			xmlHttp = CreateXmlHttp(clsids[i]);
		}
		return xmlHttp;
	}


	function CreateXmlHttp(clsid) 
	{
		var xmlHttp = null;
		try 
		{
			xmlHttp = new ActiveXObject(clsid);
			lastclsid = clsid;
			return xmlHttp;
		}
		catch(e) {}
	}

	function SendXmlHttpRequest(xmlhttp, url) 
	{ 
		try
		{
			xmlhttp.open('get', url, true);
			xmlhttp.send(null);
		}catch(e)
		{
			//alert('sendhttprequest ' + e)
		}
	}


	//CallbackMethod will fire when the state 
	//has changed, i.e. data is received back 
	function CallbackReceiveRequest() 
	{ 	
	try
		{
			//readyState of 4 or 'complete' represents 
			//that data has been returned
			if (xmlHttpReceive.readyState == 4 || 
				xmlHttpReceive.readyState == 'complete')
			{
				var response = xmlHttpReceive.responseText;				
				if (response.length > 0)
				{	
					document.getElementById("divMostSearch").innerHTML=response;			
					//alert(response)
					document.getElementById("divMostSearch").style.visibility="visible";
				}
			}
		}
		catch(e){ 
			//alert('CallbackReceiveRequest ' + e); 
		}
	}			

	function sendRequest(category,aid)
	{	
		document.getElementById("divMostSearch").style.visibility="hidden";		
		xmlHttpReceive = GetXmlHttpObject(CallbackReceiveRequest);

		//this  will enable last request to complete before new can be requested
		var szURL = "/getResponse.aspx?category="+ category + "&sid=" + Math.random();
		SendXmlHttpRequest(xmlHttpReceive, szURL);
		setCategoryStyle(aid);
	}

function setCategoryStyle(aid)
{

	var theRules = new Array();	
	if (document.styleSheets[1].cssRules) {		
		theRules = document.styleSheets[1].cssRules;	} 
	else if (document.styleSheets[1].rules) {		
		theRules = document.styleSheets[1].rules;	}	

	for(var i=0;i<maxAid;i++)
	{
		if(i==aid)
		{			
			changeRule(i,"#000000",theRules);
		}						
		else
		{
			changeRule(i,"#ffffff",theRules);
		}
	}
}

function changeRule(theNumber,color,theRules)
{
	theRules[theNumber].style.color = color;
}

function openLinkCollector(title,description,url)
{
	title1 = new String();
	title1 = title ;
	title1 = title1.replace("&","-");
	title1 = title1.replace(/<[^>]+>/g,"");
	
	desc = new String();
	desc =document.getElementById(description).innerHTML;
	desc=desc.replace(/<[^>]+>/g,"");
	desc=escape(desc);

	window.open('/LinkCollector/checkLogin.asp?link=sublink&title='+title1+'&description='+desc+'&url='+url,'','width=626,height=600,scrollbars=yes');
}

function showDiv(divid,tid)
{
	t1=document.getElementById(tid);
	document.getElementById(divid).style.display="block";
	t1.className="tabClass2";
	
}
function hidDiv(divid,tid)
{
	t2=document.getElementById(tid);
	document.getElementById(divid).style.display="none";
	t2.className="tabClass1";
}

function openSaveSearch()
{
		if (document.frmAdv.q.value=="")
		{
			alert("please enter title to search")
			document.frmAdv.q.focus();
			return false;
		}
		else
		{
			title=document.frmAdv.q.value;
			country=document.frmAdv.c.value;
			var category="";
			
			for (i=0;i<document.frmAdv.currentSection.length;i++)
			{
				if ( document.frmAdv.currentSection[i].selected == true )
				{
	 				if (category=="")
	 				{
	 					category = eval("document.frmAdv.currentSection[i].value");
	 				}
	 				else
	 				{
	 					category =category + "," + eval("document.frmAdv.currentSection[i].value");
	 				}
				 	
				}			
			}
			
			ltype=document.frmAdv.ltype.value;
			timeperiod=document.frmAdv.tp.value;
			pl=document.frmAdv.pl.value;
			
			var rdOpt;
	
			for (i=0;i<3;i++)
			{
				if ( document.frmAdv.opt[i].checked == true )
				{
	 				rdOpt = eval("document.frmAdv.opt[i].value");
				}
			}
			
			//alert(title+","+country+","+category+","+ltype+","+timeperiod+","+pl+","+rdOpt)	;
			window.open('checkLogin.asp?title='+title+'&country='+country+'&category='+category+'&ltype='+ltype+'&timeperiod='+timeperiod+'&pl='+pl+'&rdOpt='+rdOpt,'','width=626,height=600,scrollbars=yes')
		}
}