////  extra variable for random use ------------
var container_feed_id;



////////////   
function GetXmlHttpObject()
{
	var xmlHttp=false;
	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)
			{        
				alert("Your browser does not support AJAX!");        
				return false;        
			}      
		}    
	}
	return xmlHttp;
}
var http = GetXmlHttpObject(); // We create the HTTP Object

//////  object creation complete 

///////////////--------------Main functions--------------

function getupcomingdata(dataSource,divid)

{

//alert(dataSource)

	

	var XMLHttpRequestObject1 =false;

	

	if (window.XMLHttpRequest)

	{

		XMLHttpRequestObject1 = new XMLHttpRequest();

	}

	else if (window.ActiveXObject)

	{

		XMLHttpRequestObject1 = new ActiveXObject("Microsoft.XMLHTTP");

	}

	

	//alert(dataSource);

	if(XMLHttpRequestObject1)

	{

		//var obj1 =document.getElementById('paginateitook');

		var obj1 =document.getElementById(divid);

			

		XMLHttpRequestObject1.open("GET",dataSource);

		XMLHttpRequestObject1.onreadystatechange =function()

		{

			if (XMLHttpRequestObject1.readyState ==4 && XMLHttpRequestObject1.status ==200)

			{

				obj1.innerHTML =XMLHttpRequestObject1.responseText;

			}

		}

		XMLHttpRequestObject1.send(null);

	}

}


function requestServerResponse(url,containerid)
{
  
  //alert(containerid);
 
 container_feed_id=containerid;
  http.open("GET", url, true);
  http.onreadystatechange = function()
{
   if (http.readyState == 4) 
   {
	 var results = http.responseText;
	 
	// alert(results);
	   document.getElementById(container_feed_id).innerHTML = results;
	  
	}
	else
	{
         /*document.getElementById(container_feed_id).innerHTML ='<div style="padding-left:100px;padding-top:30px;"><img src="images/loading_images/animated_loading.gif" height="50"  width="50" /></div>' ;*/
		 
		  document.getElementById(container_feed_id).innerHTML ='<img src="images/loading_images/loading.gif"/>' ;
	}
}
  http.send(null);



   

}

function requestServerWithoutResponse(url)
{
  
  //alert(url);
 
 
  http.open("GET", url,true);
  http.onreadystatechange = function()
{
   if (http.readyState == 4) 
   {
	    return true;
		
	}
	
	
}
 http.send(null);




}

///////////////--------------Sub helper function--------------
function setInnerHtml(divid,val)
{
	
	document.getElementById(id).innerHTML=val;
}

function deleteInnerHtml(id)
{
	
	document.getElementById(id).innerHTML="";
	
}

function deleteAfterConfirm(id,confirm_mesg)
{
   var	confval=null;
	 confval=confirm(confirm_mesg);
	if(confval==true)
	{
	  	deleteInnerHtml(id);
	    return false
	}
	else
	{
		return false;
	}
	
}


/////   forum functions -----------

// this function is for populate the reply form---
function reply_get_form_html(p_wallid,roomid,reply_cotainer_id,tottopic)
{
     
	  var setcontid;
	  var i;
	  for(i=0;i<tottopic; i++ )
	  {
	  
	     //alert(tottopic+" -- "+i);
	      
	       setcontid="reply_topic_"+i;
		   
		   if(i==reply_cotainer_id)
		   {
		   
		      reply_topic_form_divid="reply_topic_"+i;
			  reply_result_divid="reply_result_"+i;
			  			  
			  //alert(setcontid);
			  
			   var url="ajax_pages_all/roompage/forum_process.php?pmode=open_reply_form&p_wallid="+p_wallid+"&roomid="+roomid+"&reply_topic_form_divid="+reply_topic_form_divid+"&reply_result_divid="+reply_result_divid+"&tottopic="+tottopic;
		      //alert(url);
			  
			   requestServerResponse(url,reply_topic_form_divid);
		   
		       //show_topic_reply_list(p_wallid,roomid,reply_result_divid,tottopic);
		   
		   // document.getElementById(setcontid2).innerHTML="-------";
		   
		   
		   }
		   else
		   {
		      deleteInnerHtml(setcontid);
		   
		      //document.getElementById(setcontid).innerHTML="";
		   
		   }
		   
		   
	  
	  
	  }


}

// this function is for save the reply data
function forum_save_reply(p_wallid_reply,r_id_reply,emote_id_reply,wall_desc_reply,reply_topic_form_divid,reply_result_divid,tottopic) 
{
					   
					  
					   var p_wallid=p_wallid_reply.value;
					   var roomid=r_id_reply.value;
					   var emote_id=emote_id_reply.value;
					   var wall_desc=wall_desc_reply.value;
					   var reply_topic_form_divid=reply_topic_form_divid.value;
					   var reply_result_divid=reply_result_divid.value;
					   
					   					  
						if(wall_desc=="")
						  {
							  wall_desc_reply.focus();
							 
						  }
						  else
						  {
						      						  
					         //  alert(p_wallid+"--"+roomid+"--"+emote_id+"--"+wall_desc+"--"+reply_topic_form_divid+"--"+reply_result_divid);	  
						  
						      var url="ajax_pages_all/roompage/forum_process.php?pmode=save_reply&p_wallid="+p_wallid+"&roomid="+roomid+"&emote_id="+emote_id+"&wall_desc="+wall_desc+"&reply_result_divid="+reply_result_divid+"&tottopic="+tottopic;
		      //alert(url);
			                    
			                   deleteInnerHtml(reply_topic_form_divid)
							   deleteInnerHtml(reply_result_divid)
							   // encrese the total number of reply
							   var TotReplyDivId="tot_reply_for_"+p_wallid;
							 		  
							    requestServerResponse(url,TotReplyDivId);
							 
							    // after save show the all reply list with new one 
							 
						       //requestServerWithoutResponse(url);
							   
							  
							   //show_topic_reply_list(p_wallid,roomid,reply_result_divid,tottopic);
							   
							  					  
						  
						  }
					
					
					}

function show_topic_reply_list(p_wallid,roomid,reply_result_divid,tottopic)
{
	
      var reply_res_id=null;
	  var i=null;
	  for(i=0;i<tottopic; i++ )
	  {
	         
	       topic_reply_container_id="reply_result_"+i;
		    topic_reply_form_box_id="reply_topic_"+i;
		   
		   if(reply_result_divid==topic_reply_container_id)
		   {
		   
		     // reply_topic_form_divid="reply_topic_"+i;
			//  reply_result_divid="reply_result_"+i;
			  			  
			  //alert(setcontid);  // +"&startPoint="+startPoint+"&endPoint="+endPoint
			  
			   var url="ajax_pages_all/roompage/forum_process.php?pmode=get_reply_list&p_wallid="+p_wallid+"&roomid="+roomid;
		      //alert(url);
			  
			   requestServerResponse(url,reply_result_divid);
		   
		   
		   
		   
		   }
		   else
		   {
		      deleteInnerHtml(topic_reply_container_id);
		   
		      //document.getElementById(setcontid).innerHTML="";
		   
		   }
		   
		    deleteInnerHtml(topic_reply_form_box_id); 
	  
	  
	  }	
	
	
}


