function showSubCategoryList(id){
		var url="/subCategory.html?method=viewSubCategoryList";
        var pars='&categoryId='+id+'&'+Date();
        url+=pars;
        showSubCategory(url);
    }

function showSubCategory(url){
    var req=initXMLHttp();
    req.open("GET",url,true);
    req.onreadystatechange=function(){
        if(req.readyState==4){
            document.getElementById('subCategory').innerHTML=req.responseText;
            document.getElementById('subCategory').style.display="";
            document.getElementById('category').style.display="none";
            document.getElementById('all').style.display="";
        }
    }
    req.send(url);
}

function initXMLHttp(){
    if(window.XMLHttpRequest){
        return new XMLHttpRequest();
    }else{
        if(window.ActiveXObject){
        return new ActiveXObject("Microsoft.XMLHTTP");
    }else{
        return new ActiveXObject("Msxml2.XMLHTTP");
        }
    }
}
function changeStyle1(id){
    var rowObj=document.getElementById(id);
    rowObj.style.textDecoration="underline";
    rowObj.style.fontWeight="bold";
    rowObj.style.cursor="pointer";
}

function changeStyle2(id){
    var rowObj=document.getElementById(id);
    rowObj.style.textDecoration="none";
    rowObj.style.fontWeight="normal";
}

function showQuestions(id){
    var url="/question.html?method=viewAllQuestions";
    var pars='&subId='+id+'&'+Date();
    url+=pars;
    showQuestionList(url);
}

function showQuestionList(url){
    var req=initXMLHttp();
    req.open("GET",url,true);
    req.onreadystatechange=function(){
        if(req.readyState==4){
            document.getElementById('questionDiv').innerHTML=req.responseText;
            document.getElementById('questionDiv').style.display="";
        }
    }
    req.send(url);
}

function showCategory(){
		document.getElementById('all').style.display="none";
        document.getElementById('category').style.display="";
		document.getElementById('subCategory').style.display="none";
		document.getElementById('questionDiv').style.display="none";
    }

function showcursor(id){
    document.getElementById(id).style.cursor="pointer";
    document.getElementById(id).style.fontWeight="bold";
}
function hidecursor(id){
    document.getElementById(id).style.fontWeight="normal";
}

function gotoFooter(id){
        document.getElementById(id).focus();
	}

function showQuestionSubCategoryList(id){
    var url="/subCategory.html?method=viewSubCategory";
        var pars='&categoryId='+id+'&'+Date();
        url+=pars;
        showQuestionSubCategory(url);
}

function showQuestionSubCategory(url){
    var req=initXMLHttp();
    req.open("GET",url,true);
    req.onreadystatechange=function(){
        if(req.readyState==4){
            document.getElementById('subCategory').innerHTML=req.responseText;
            document.getElementById('subCategory').style.display="";
        }
    }
    req.send(url);
}

function checkFields1(){
    var name=document.getElementById('name').value;
    if(name==""){
        document.getElementById('question').style.color="red";
        return false;
    }
   /* if(id!=null && !"".Equals(id)){

    }*/
    var catObj=document.getElementsByName('categoryId');
    var check;
    var test=true;
    for(var i=0;i<catObj.length;i++){
        if(catObj.length>1){
            check=(catObj[i].checked);
            if(check)break;
        }
    }
    if(!check){
        alert("Please select a category");
        return false;
    }
    return checkFields2();

}
function checkFields2(){
    var subObj=document.getElementsByName('subCatId');
    var check1;
    var test2=true;
    for(var i=0;i<subObj.length;i++){
        if(subObj.length>1){
            check1=(subObj[i].checked);
            if(check1)break;
        }
    }
    if(!check1){
        alert("Please select a subcategory");
        return false;
    }
    return true;
}

function changeStyle3(id)
{
    document.getElementById(id).style.backgroundColor="#D7E9F5";
	document.getElementById(id).style.color="#4F8CC9";
}

function changeStyle4(id)
{
    document.getElementById(id).style.backgroundColor="#FFFFFF";
	document.getElementById(id).style.color="#4F8CC9";
}

function hideText(id1,id2){
	 window.setTimeout(this.hide, 5000,id1,id2);
}
this.hide=function(id1,id2){
	document.getElementById(id1).style.display="none";
    document.getElementById(id2).value="";
}

function saveUserCommunity(groupId){
    var url="/userCommunity.html?method=saveUserCommunity";
    var pars='&groupId='+groupId+'&'+Date();
    url+=pars;
    saveUserGroup(url);
}

function saveUserGroup(url){
    var req=initXMLHttp();
    req.open("GET",url,true);
    req.onreadystatechange=function(){
        if(req.readyState==4){
            if(req.responseText.indexOf("failure") >= 0){
               grayPop('/login.html','overlay','popup_content');
            }else{
                $('joinMsg').innerHTML=req.responseText;
                $('joined').style.visibility="hidden";
                displayMessageCommunity('joinMsg');
                window.location.reload();
            }
        }
    }
    req.send(url);
}

function joinGroup(){
        alert('Please join this group to post a topic');
}

function replyOfTopic(){
    alert('Please join this group to reply');
}

function displayMessage(id){
	var obj=document.getElementById(id);
	obj.style.display='';
	window.setTimeout(hideMessage,5000);
}
function hideMessage(){
	var obj=document.getElementById('msg');
	obj.style.display='none';
}

function displayMessageCommunity(id){
	var obj=document.getElementById(id);
	obj.style.display='';
	window.setTimeout(hideMessageCommunity,5000);
}
function hideMessageCommunity(){
	var obj=document.getElementById('joinMsg');
	obj.style.display='none';
}

function saveUserCommunityReply(groupId){
    var url="/userCommunity.html?method=saveUserCommunity";
    var pars='&groupId='+groupId+'&'+Date();
    url+=pars;
    saveUserGroupReply(url);
}

function saveUserGroupReply(url){
    var req=initXMLHttp();
    req.open("GET",url,true);
    req.onreadystatechange=function(){
        if(req.readyState==4){
            if(req.responseText.indexOf("failure") >= 0){
               grayPop('/login.html','overlay','popup_content');
            }else{
                $('joinMsg').innerHTML=req.responseText;
                $('joined').style.visibility="hidden";
                displayMessageCommunity('joinMsg');
            }
        }
    }
    req.send(url);
}

function viewAnswerPopReply(id, obj, offH, offV) {
	var t = document.getElementById(id);
    var p = getElementPosition(obj);
    t.style.position = 'absolute';
    t.style.left = (p.left - offH + 8) + 'px';
    t.style.top = (p.top + offV) + 'px';
    t.style.display = 'block';
}