function getHTTPObject()
{
    var xmlhttp;
	var _ms_XMLHttpRequest_ActiveX = ""; // Holds type of ActiveX to instantiate
    var self = this;

    // check the dom to see if this is IE or not
    if (window.XMLHttpRequest) {
// Not IE
        self.AJAX = new XMLHttpRequest();
    } else if (window.ActiveXObject) {
        // Instantiate the latest MS ActiveX Objects
        if (_ms_XMLHttpRequest_ActiveX) {
            self.AJAX = new ActiveXObject(_ms_XMLHttpRequest_ActiveX);
        } else {
    // loops through the various versions of XMLHTTP to ensure we're using the latest
    var versions = ["Msxml2.XMLHTTP.7.0", "Msxml2.XMLHTTP.6.0", "Msxml2.XMLHTTP.5.0", "Msxml2.XMLHTTP.4.0", "MSXML2.XMLHTTP.3.0", "MSXML2.XMLHTTP",
                        "Microsoft.XMLHTTP"];

            for (var i = 0; i < versions.length ; i++) {
                try {
                    self.AJAX = new ActiveXObject(versions[i]);

                    if (self.AJAX) {
                        _ms_XMLHttpRequest_ActiveX = versions[i];
                        break;
                    }
                }
                catch (objException) {
                // trap; try next one
                } ;
            }

            ;
        }
    }
    xmlhttp = self.AJAX;
    return xmlhttp;
}
var http = getHTTPObject();

function cat_url(topic,category)
{
	var radio_id = eval("document.form1.cat" + category) ;
	var choose_cate;
	for ( i = 0 ; i < radio_id.length ; i++ )
	{
		if (radio_id[i].checked)
		{
			//alert(radio_id[i].value);
			choose_cate = "category-"+topic+"-"+category+"-"+radio_id[i].value+"-0";
			//alert(choose_cate);
			location.replace(choose_cate);
		}
	}

}
///////////// Radio Button 

function valButton(btn) {
  // alert(btn[1].checked);
   var cnt = -1;
    for (var i=btn.length-1; i > -1; i--) {
        if (btn[i].checked) {cnt = i; i = -1;}
    }
    if (cnt > -1) return btn[cnt].value;
    else return null;
}

var stringarr = new Array("This section is empty right now","Submitted By","View Comments","Blog this story","Email this story","Save to favorite","Commented by ");
var headersearch = new Array("Search Results","User name","Fullname","Stories Voted","Stories Submitted","Stories Commented On");



function save_image()
{
	if (http)
	{
		var y = Math.random() * 10000 ;
		//alert("aaaa");
		http.open("GET", "save_user_image.php?y="+ y , true);
		http.onreadystatechange = imageHttpResponse;
		http.send(null);
	}
}

function imageHttpResponse()
{
	location.replace("profile");
}

function cancel_image()
{
	location.replace("profile");
}

function checkLogin() {
	if(document.getElementById("hf_logged_in").value == "") { // means it is a guest
		alert("Please login to post an idea") ;
		return false ;
	}
	return true ;
}

function showLogin() {
	var show = parseInt(document.getElementById("idshow").value) ;
	document.getElementById("div_message").style.display = "none" ;
	document.getElementById("div_login").style.display = (show%2) ? "inline" : "none" ;
	document.getElementById("idshow").value = ++show ;
}

function user_login() {
	if (http)
	{
		var uname = document.getElementById("user_name").value ;
		var upass = document.getElementById("password").value ;
		var y = Math.random() * 10000 ;
		//alert("aaaa");
		http.open("GET", "get_login.php?y="+ y+"&user_name="+uname+"&password="+upass , true);
		http.onreadystatechange = loginResponse;
		http.send(null);
	}
}

function loginResponse() {
	if (http.readyState == 4)
	 {
		var xmlDocument = http.responseXML; 
		var status ;
		var message ;
		var show = parseInt(document.getElementById("idshow").value) ;
		
		status = xmlDocument.getElementsByTagName('status').item(0).firstChild.data;
		message = xmlDocument.getElementsByTagName('message').item(0).firstChild.data;
		
		if(status == -1)
			document.getElementById("idshow").value = ++show ; // move the counter one ahead because login failed. so, clicking on the login button will show the login area again.

		document.getElementById("div_login").style.display = "none" ;
		document.getElementById("div_message").style.display = "inline" ;
		document.getElementById("div_message").innerHTML = "<span class='smallredBartext'>"+message+"&nbsp;&nbsp;&nbsp;</span>" ;

		if(status == 1) {
			document.getElementById("div_top_nologin").style.display = "none" ;
			document.getElementById("div_top_login").style.display = "inline" ;
			document.location.reload() ;
		}
	 }
}