// JavaScript Document
function addConversation(){
	
	if(isEmpty(document.getElementById('category').value)){
	alert('Please Select Category');
	return false;
	}else if(isEmpty(document.getElementById('topic').value)){
	alert('Please Enter Topic For Conversation');
	return false;
	}else{
	document.conver.submit();
	}

}





function show_hideTr(){
document.getElementById('postbutton').style.display='';
document.getElementById('showtr').style.display='';
}

function addUserReply(){

if(isEmpty(document.getElementById('reply').value)){
	alert('Please Enter Your Reply');
	return false;
	}else{
	    var reply=document.getElementById('reply').value;
		reply=stripHTML(reply);
		var conId=document.getElementById('conId').value;
		var strDomain='';
			var ajax = new Ajax();
			ajax.doGet('conversationReply.php?act=add_reply&reply='+reply+'&conId='+conId,addConversationResult,'text');
	}
}

function addConversationResult(str){
document.getElementById('all_conversation_reply').innerHTML=str;
}


function changeClassName(num){
if(num=='1'){
document.getElementById('read-btn').className='read-btn1';
}else{
document.getElementById('read-btn').className='read-btn';
}
}

function showRemove(show,i){
if(show==1){
document.getElementById('corrImage'+i).style.display='';
}else{
document.getElementById('corrImage'+i).style.display='none';
}
}

function removeReply(replyId){
	var conId=document.getElementById('conId').value;
	var ok =confirm('Are you sure you want to be remove this reply');
	if(ok){
	var strDomain='';
			var ajax = new Ajax();
			ajax.doGet('conversationReply.php?act=delete_reply&replyId='+replyId+'&conId='+conId,removeReplyResult,'text');
	}
}

function removeReplyResult(str){
document.getElementById('all_conversation_reply').innerHTML=str;
}


function stripHTML(oldString) {

   var newString = "";
   var inTag = false;
   for(var i = 0; i < oldString.length; i++) {
   
        if(oldString.charAt(i) == '<') inTag = true;
        if(oldString.charAt(i) == '>') {
              if(oldString.charAt(i+1)=="<")
              {
              		//dont do anything
	}
	else
	{
		inTag = false;
		i++;
	}
        }
   
        if(!inTag) newString += oldString.charAt(i);

   }

   return newString;
}


function changeClassNameQuestion(num){
if(num=='1'){
document.getElementById('read-btn2').className='read-btn3';
}else{
document.getElementById('read-btn2').className='read-btn2';
}
}

function pastVisitorQuestion(){
if(isEmpty(document.getElementById('visitorQuestion').value)){
	alert('Please Enter Your Question');
	return false;
	}else{
	var question=stripHTML(document.getElementById('visitorQuestion').value);
	document.getElementById('visitorQuestion').value=question;
	document.question.submit();
	}
}

	function changeClassNameAnswer(num,id){
	
		if(num=='1'){
		document.getElementById('read-btn3'+id).className='read-btn3';
		}else{
		document.getElementById('read-btn3'+id).className='read-btn2';
		}

	}
	
	function showAnswerDiv(num){
	 document.getElementById('localanswer'+num).style.display='';
	}
	
	function changeClassNamepostAnswer(num,id){
		
	   if(num=='1'){
		document.getElementById('read-btn4'+id).className='read-btn3';
		}else{
		document.getElementById('read-btn4'+id).className='read-btn2';
		}
	}
	
	var page_number='1';
	function pastlocalAnswer(num,qId){
		
	 var userAnswer=stripHTML(document.getElementById('localUserPostAnswer'+num).value);
	 page_number = document.getElementById('page_number').value;
	if(isEmpty(userAnswer)) {
		alert('Please Enter Your Answer');
	      return false;
	  }
	  var strDomain='';
			var ajax = new Ajax();
			ajax.doGet('conversationReply.php?act=add_localanswer&answer='+userAnswer+'&qId='+qId,pastlocalAnswerResult,'text');
	}
	
	function pastlocalAnswerResult(str){
	
	  document.location.href='localQuestionAnswer.php?page='+page_number;
	}
	
	function showMoreAnsDiv(count,num){
	  
	 if(count>1){
	    if(document.getElementById('moreAns'+num).style.display=='none'){
	    
		document.getElementById('moreAns'+num).style.display='';
		
		}else{
		
		document.getElementById('moreAns'+num).style.display='none';
		
		}
	  }
	}



    function changeClassNameCancelAnswer(num,id){
		
	   if(num=='1'){
		document.getElementById('read-btn5'+id).className='read-btn1';
		}else{
		document.getElementById('read-btn5'+id).className='read-btn';
		}
	}
	
	function CancellocalAnswer(num){
	document.getElementById('localanswer'+num).style.display='none';
	}
	
	
	var total_score=divCount='';
	function addScoreforAnswer(type,ansId){
		var  rate='';
		var score=document.getElementById('previousScore'+ansId).value;
		if(type=='0'){
		 rate='Average';
		score= parseInt(score) + 50;
		}else if(type=='1'){
		rate='Good';
		score=parseInt(score) + 100;
		}else if(type=='2'){
		rate='Best';
		score=parseInt(score) + 200;
		}else{
		rate='Excellent';
		score=parseInt(score) + 500;
		}
		total_score=score;
		
		divCount=ansId;
		ok=confirm('Are you sure want to rate this answer for '+rate);
		if(ok){
		
		document.getElementById('totalScoreDIv'+divCount).innerHTML='<img src="images/loading.gif" align="wait" />';
		page_number = document.getElementById('page_number').value;
		
		 var strDomain='';
				var ajax = new Ajax();
				ajax.doGet('conversationReply.php?act=add_answerScore&type='+type+'&ansId='+ansId,addScoreforAnswerResult,'text');
		}else{
		return false;
		}
	}
	
	
	function addScoreforAnswerResult(str){
		str=str.split('?');
		if(str.length>1){
		total_score=str[1];
		alert(str[0]);
		}
	document.getElementById('previousScore'+divCount).value=total_score;
	document.getElementById('totalScoreDIv'+divCount).innerHTML='&nbsp;&nbsp;Total score for this answer:<strong>'+ total_score +'</strong>';
	}
