//	Javascript file
//	Created by Gavin Fonseca.
//alert ("loaded");
function GetXmlHttpObject()
{
	var xmlHttp=null;
	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)
			{
			}
		}
	}
	return xmlHttp;
}


function cast()
{
	//alert("HI");
	var xmlHttpfunction 
 	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
	{
		alert ("Browser does not support HTTP Request");
		 return false;
	}
	var optno = document.getElementById("optno").value
	//alert("optno="+optno);
	var id = document.getElementById("ques_id").value
	var val = 0
	for (x=1; x<=optno; x++)
	{
		str = "opt"+x
		//alert("str="+str);
		if (document.getElementById(str).checked == true)
		{
			val = document.getElementById(str).value
		}
	}
	//alert("val="+val+" id="+id);
	if (val == 0)
	{
		document.getElementById("dispmsg").innerHTML = "Please select an option to vote"
		return false;
	}
	//var url="www.imsindia.com/student/modules/poll/cast_vote.php";
	var url="http://www.imsindia.com/cat2007/poll/cast_vote.php";
	url=url+"?val="+val+"&id="+id
	url=url+"&sid="+Math.random()
	xmlHttp.onreadystatechange=stateChanged
	xmlHttp.open("GET",url,true)
	xmlHttp.send(null)	
}

function stateChanged() 
{ 
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	{
		var	data = xmlHttp.responseText
		//alert(data)
		
		if (data == "return")
		{
			//location.replace("http://220.226.203.67/imsindia/")
			location.replace("http://www.imsindia.com/")
		}
		else
		{
			document.getElementById("dispmsg").innerHTML = data
		}
	}			
}
