// JavaScript For Ajax Connection
var xmlHttp;
var xmlHttp2;
var xmlHttp3;
var xmlHttp4;
var xmlHttp6;

//////////////////////////////////////////// Register Ajax Script ////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function signup()
{
xmlHttp6=GetXmlHttpObject();
if (xmlHttp6==null)
{
  alert ("Your browser does not support AJAX!");
  return;
  } 
    //For Comment Count
		function stateChanged() 
    	{ 
			if (xmlHttp6.readyState==4)
			{ 
				document.getElementById("signupstatus").innerHTML=xmlHttp6.responseText;
			}
		}
	//passData = 'register';
	var name = document.getElementById("name").value;
	var email = document.getElementById("email").value;
	var username = document.getElementById("username").value;
	var password = document.getElementById("password").value;
	var sex = document.getElementById("sex").value;
	var birth_month = document.getElementById("birth_month").value;
	var birth_day = document.getElementById("birth_day").value;
	var birth_year = document.getElementById("birth_year").value;
	var register = document.getElementById("register").value;
	var sid = (new Date()).getTime();
	
	var passData = 'name='+escape(name)+'&email='+escape(email)+'&username='+escape(username)+'&password='+escape(password)+'&sex='+escape(sex)+'&birth_month='+escape(birth_month)+'&birth_day='+escape(birth_day)+'&birth_year='+escape(birth_year)+'$register='+escape(register)+'&sid='+escape(sid);
	
   xmlHttp6.open("POST", "./applications/registration.php", true);
   xmlHttp6.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
   xmlHttp6.onreadystatechange = stateChanged;                      
   xmlHttp6.send(passData);
} 


///////////////////////////// Beginning of Comment Count Function ///////////////////////////////
function countresponse(str, str2, strID) //Used to count total comments
{
xmlHttp=GetXmlHttpObject();
if (xmlHttp==null)
  {
  alert ("Your browser does not support AJAX!");
  return;
  } 
    //For Comment Count
		function stateChanged() 
    	{ 
			if (xmlHttp.readyState==4)
			{ 
			
			document.getElementById("commentcount"+strID).innerHTML=xmlHttp.responseText;
			if(document.getElementById("commentcount2"+strID))
				{document.getElementById("commentcount2"+strID).innerHTML=xmlHttp.responseText;}
			
			}
		}
	
	
	var url="./applications/responsecount.php";
	url=url+"?refid="+str;
	url=url+"&aps="+str2; //Values should be comment, likeit, views
	url=url+"&sid="+(new Date()).getTime();
	xmlHttp.onreadystatechange=stateChanged;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
} 
/////////////////////////////////Beginning of Likeit Count.////////////////////////////////////////////////
function likeit(str, str2, strID)
{
xmlHttp2=GetXmlHttpObject();
if (xmlHttp2==null)
  {
  alert ("Your browser does not support AJAX!");
  return;
  } 
    //For Comment Count
		function stateChanged() 
    	{ 
			if (xmlHttp2.readyState==4)
			{ 
			
			document.getElementById("likeitcount"+strID).innerHTML=xmlHttp2.responseText;
			if(document.getElementById("likeitcount2"+strID))
				{document.getElementById("likeitcount2"+strID).innerHTML=xmlHttp2.responseText;}			
			}
		}
	
	
	var url="./applications/responsecount.php";
	url=url+"?refid="+str;
	url=url+"&aps="+str2; //Values should be comment, likeit, views
	url=url+"&sid="+(new Date()).getTime();
	xmlHttp2.onreadystatechange=stateChanged;
	xmlHttp2.open("GET",url,true);
	xmlHttp2.send(null);
} 
////////////////////////////////////////// Beginning of Hit Counts ////////////////////////////////////////////
function viewhits(str, str2, strID)
{
xmlHttp3=GetXmlHttpObject();
if (xmlHttp3==null)
  {
  alert ("Your browser does not support AJAX!");
  return;
  } 
    //For Comment Count
		function stateChanged() 
    	{ 
			if (xmlHttp3.readyState==4)
			{ 
			
			document.getElementById("totalhits"+strID).innerHTML=xmlHttp3.responseText;
			//document.getElementById("commentcount2").innerHTML=xmlHttp.responseText;
			
			}
		}
	
	
	var url="./applications/responsecount.php";
	url=url+"?refid="+str;
	url=url+"&aps="+str2; //Values should be comment, likeit, views
	url=url+"&sid="+(new Date()).getTime();
	xmlHttp3.onreadystatechange=stateChanged;
	xmlHttp3.open("GET",url,true);
	xmlHttp3.send(null);
} 

//////////////////////////////////////////// Post Comment Ajax Script ////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function postcomment(strID)
{
xmlHttp4 = GetXmlHttpObject();
if (xmlHttp4==null)
  {
  alert ("Your browser does not support AJAX!");
  return;
  } 
		function stateChanged() 
    	{ 
			if(xmlHttp4.readyState < 4)
			{
			    document.getElementById("loading").innerHTML = '<img src="images/camera-loading.gif"/>';
			}
			if (xmlHttp4.readyState==4)
			{ 
				var refid = document.getElementById("refid"+strID).value;
				document.getElementById("newcomment"+strID).innerHTML=xmlHttp4.responseText;
				document.getElementById("styled"+strID).value = "";
  				document.getElementById('styled'+strID).focus()
				document.getElementById("loading").innerHTML = '';
				//document.getElementById("commentcount2").innerHTML=xmlHttp.responseText;
			}
		}
	var refid = document.getElementById("refid"+strID).value;
	var content = document.getElementById("styled"+strID).value;
	var sid = (new Date()).getTime();
	var passData = 'refid='+escape(refid)+'&content='+escape(content)+'&sid='+escape(sid);
   if(strID == '')
   {
   		xmlHttp4.open("POST", "./applications/post_forum_comment.php", true);
   }else{
   		xmlHttp4.open("POST", "./applications/post_comment.php", true);
   }
   xmlHttp4.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
   xmlHttp4.onreadystatechange = stateChanged;                      
   xmlHttp4.send(passData);
} 

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

function autotxtareaheight(strID)
{
	document.getElementById("styled"+strID).style.height = 0;
	document.getElementById("styled"+strID).style.height = document.getElementById("styled"+strID).scrollHeight + 10 + "px";
}

function clearButton(strID)
{
	if(document.getElementById("styled"+strID).value == "")
	{
		document.getElementById("submitButton"+strID).innerHTML="";
		document.getElementById("styled"+strID).value = "Write a comment...";
 		return;
	}
}

///////////// Beginning of Show Button Function /////////////////////////////
function showSubmit(str, strID)
{  
xmlHttp=GetXmlHttpObject();
if (xmlHttp==null)
  {
  alert ("Your browser does not support AJAX!");
  return;
  } 
  function stateChanged() 
  { 
		if (xmlHttp.readyState==4)
		{ 
		document.getElementById("submitButton"+strID).innerHTML=xmlHttp.responseText;
		}
  }
var url="./applications/get_elements.php";
url=url+"?message="+str;
url=url+"&refid="+strID;
url=url+"&sid="+Math.random();
xmlHttp.onreadystatechange=stateChanged;
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
} 
//////////////////////////// End of Show Button ////////////////////////////////////////////////////

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)
    {
    xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
  }
return xmlHttp;
}

/////////////////////////////////////////// Gets the Recordset ID /////////////////////////////////////////
function getID(strID)
{
	return strID;
}

///////////////////////////////////////////// OnFocus Function ////////////////////////////////////////////
function cleardefaulttext(strID)
{
  if(document.getElementById("styled"+strID).value == document.getElementById("styled"+strID).defaultValue)
  {document.getElementById("styled"+strID).value = "";}
 //if (this.value == this.defaultValue)
  //{ this.value = "";}this.form.styled.onblur = function() {
	//if (this.value == "") this.value = this.defaultValue;
}

/////////////////////////////////////// Set Focus to a Field /////////////////////////////////////////////////
function setFocus(strID)
{
  document.getElementById('styled'+strID).focus();
}

///////////////// Functions for the top post field ////////////////////////////////////////////////////
function post_field_auto_height()
{
	document.getElementById("post_content").style.height = 0;
	document.getElementById("post_content").style.height = document.getElementById("post_content").scrollHeight + 20 + "px";
}

function post_field_auto_height_x()
{
	document.getElementById("post_content").style.height = 200 + "px";
	document.getElementById("post_content").style.height = document.getElementById("post_content").scrollHeight + 20 + "px";
}

function clear_post_field(str)
{
	if(document.getElementById("post_content").value == "")
	{
		document.getElementById("post_content").innerHTML="";
		document.getElementById("post_content").value = str;
 		return;
	}
}

function clear_defaul_post_text()
{
  if(document.getElementById("post_content").value == document.getElementById("post_content").defaultValue)
  {document.getElementById("post_content").value = "";}
}

//Delete comment
function delete_comment(strID)
{
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
	  {
	  alert ("Your browser does not support AJAX!");
	  return;
	  } 
	  function stateChanged() 
	  { 
			if (xmlHttp.readyState < 4)
			{ 
				document.getElementById("cmain"+strID).innerHTML='<img src="images/camera-loading.gif"/>';
			}

			if (xmlHttp.readyState==4)
			{ 
				document.getElementById("cmain"+strID).innerHTML=xmlHttp.responseText;
			}
	  }
	var url="./applications/delete_comment.php";
	url=url+"?com_id="+strID;
	url=url+"&sid="+Math.random();
	xmlHttp.onreadystatechange=stateChanged;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

//Delete feed
function delete_feed(strID)
{
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
	  {
	  alert ("Your browser does not support AJAX!");
	  return;
	  } 
	  function stateChanged() 
	  { 
			if (xmlHttp.readyState==4)
			{ 
				document.getElementById("fmain"+strID).innerHTML=xmlHttp.responseText;
			}
	  }
	
	var url="./applications/delete_feed.php";
	url=url+"?del="+strID;
	url=url+"&sid="+Math.random();
	xmlHttp.onreadystatechange=stateChanged;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}
// ---------------------------------------- Update User Information ---------------------------------
//Update user basic information.
function update_basic_info()
{
xmlHttp=GetXmlHttpObject();
if (xmlHttp==null)
  {
  alert ("Your browser does not support AJAX!");
  return;
  } 
  function stateChanged() 
  { 
	
		if (xmlHttp.readyState < 4)
		{ 
			document.getElementById("basic_info_x").innerHTML= '<center><img src="images/loading.gif" class="profile_loading"/></center>';
		}
		if (xmlHttp.readyState==4)
		{ 
			document.getElementById("basic_info_x").innerHTML=xmlHttp.responseText;
		}
  }
	var city = document.getElementById("city").value;
	var country = document.getElementById("country").value;
	var sex = document.getElementById("sex").value;
	var sid = (new Date()).getTime();
  
	var passData = 'city='+escape(city)+'&country='+escape(country)+'&sex='+escape(sex)+'&sid='+escape(sid);
	
   xmlHttp.open("POST", "./applications/profile/update_basic_info.php", true);
   xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
   xmlHttp.onreadystatechange = stateChanged;                      
   xmlHttp.send(passData);
} 

//Update user contact information.
function update_contact_info()
{
xmlHttp=GetXmlHttpObject();
if (xmlHttp==null)
  {
  alert ("Your browser does not support AJAX!");
  return;
  } 
  function stateChanged() 
  { 
	
		if (xmlHttp.readyState < 4)
		{ 
			document.getElementById("contact_info_x").innerHTML= '<center><img src="images/loading.gif" class="profile_loading"/></center>';
		}
		if (xmlHttp.readyState==4)
		{ 
			document.getElementById("contact_info_x").innerHTML=xmlHttp.responseText;
		}
  }
	var telephone = document.getElementById("telephone").value;
	var address = document.getElementById("address").value;
	var website = document.getElementById("website").value;
	var yahoo_id = document.getElementById("yahoo_id").value;
	var sid = (new Date()).getTime();
  
	var passData = 'telephone='+escape(telephone)+'&address='+escape(address)+'&website='+escape(website)+'&yahoo_id='+escape(yahoo_id)+'&sid='+escape(sid);
	
   xmlHttp.open("POST", "./applications/profile/update_contact_info.php", true);
   xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
   xmlHttp.onreadystatechange = stateChanged;                      
   xmlHttp.send(passData);
} 

//Update user personal information.
function update_personal_info()
{
xmlHttp=GetXmlHttpObject();
if (xmlHttp==null)
  {
  alert ("Your browser does not support AJAX!");
  return;
  } 
  function stateChanged() 
  { 
	
		if (xmlHttp.readyState < 4)
		{ 
			document.getElementById("personal_info_x").innerHTML= '<center><img src="images/loading.gif" class="profile_loading"/></center>';
		}
		if (xmlHttp.readyState==4)
		{ 
			document.getElementById("personal_info_x").innerHTML=xmlHttp.responseText;
		}
  }
	var personal_info = document.getElementById("personal_info").value;
	var sid = (new Date()).getTime();
  
	var passData = 'personal_info='+escape(personal_info)+'&sid='+escape(sid);
	
   xmlHttp.open("POST", "./applications/profile/update_personal_info.php", true);
   xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
   xmlHttp.onreadystatechange = stateChanged;                      
   xmlHttp.send(passData);
} 

//Update user password information.
function update_password_info()
{
xmlHttp=GetXmlHttpObject();
if (xmlHttp==null)
  {
  alert ("Your browser does not support AJAX!");
  return;
  } 
  function stateChanged() 
  { 
	
		if (xmlHttp.readyState < 4)
		{ 
			document.getElementById("password_info_x").innerHTML= '<center><img src="images/loading.gif" class="profile_loading"/></center>';
		}
		if (xmlHttp.readyState==4)
		{ 
			document.getElementById("password_info_x").innerHTML=xmlHttp.responseText;
		}
  }
	var old_pass = document.getElementById("old_pass").value;
	var new_pass = document.getElementById("new_pass").value;
	var con_pass = document.getElementById("con_pass").value;
	var sid = (new Date()).getTime();
  
	var passData = 'old_pass='+escape(old_pass)+'&new_pass='+escape(new_pass)+'&con_pass='+escape(con_pass)+'&sid='+escape(sid);
	
   xmlHttp.open("POST", "./applications/profile/update_password_info.php", true);
   xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
   xmlHttp.onreadystatechange = stateChanged;                      
   xmlHttp.send(passData);
} 

//Show Update Field Refreshed
///////////// Beginning of Show Button Function /////////////////////////////
function show_refresh_update_fields(output_span, update_section)
{  
xmlHttp=GetXmlHttpObject();
if (xmlHttp==null)
  {
  alert ("Your browser does not support AJAX!");
  return;
  } 
  function stateChanged() 
  { 
		if (xmlHttp.readyState < 4)
		{ 
			document.getElementById(output_span).innerHTML= '<center><img src="images/loading.gif" class="profile_loading"/></center>';
		}
		if (xmlHttp.readyState==4)
		{ 
		document.getElementById(output_span).innerHTML=xmlHttp.responseText;
		}
  }
var url="./applications/get_update_elements.php";
url=url+"?update_section="+update_section;
//url=url+"&refid="+strID;
url=url+"&sid="+Math.random();
xmlHttp.onreadystatechange=stateChanged;
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
} 

// ------------------------------ Update Articles --------------------------------------------------
//Update user basic information.
function update_article()
{
xmlHttp=GetXmlHttpObject();
if (xmlHttp==null)
  {
  alert ("Your browser does not support AJAX!");
  return;
  } 
  function stateChanged() 
  { 
		if (xmlHttp.readyState < 4)
		{ 
			document.getElementById("loading_x").innerHTML= '<img src="images/camera-loading.gif"/>';
		}
		if (xmlHttp.readyState==4)
		{ 
			document.getElementById("output_x").innerHTML=xmlHttp.responseText;
			document.getElementById("loading_x").innerHTML= '';
		}
  }
	var post_content = document.getElementById("post_content_x").value;
	var title = document.getElementById("title_x_y").value;
	var art_id = document.getElementById("art_id").value;
	var sid = (new Date()).getTime();
  
	var passData = 'post_content='+escape(post_content)+'&title='+escape(title)+'&art_id='+escape(art_id)+'&sid='+escape(sid);
	
   xmlHttp.open("POST", "./applications/update_post_ajax.php", true);
   xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
   xmlHttp.onreadystatechange = stateChanged;                      
   xmlHttp.send(passData);
} 

//Function to delete all kind of articles, blog or forum
//Delete feed
function delete_posts(strID, section)
{
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
	  {
	  alert ("Your browser does not support AJAX!");
	  return;
	  } 
	  function stateChanged() 
	  { 
			if (xmlHttp.readyState < 4)
			{ 
				document.getElementById("load_me").innerHTML='<img src="images/camera-loading.gif"/>';
			}
			if (xmlHttp.readyState==4)
			{ 
				document.getElementById('main_output').innerHTML=xmlHttp.responseText;
				document.getElementById("load_me").innerHTML='';
			}
	  }
	
	var url="./applications/delete_article.php";
	url=url+"?del="+strID;
	url=url+"&section="+section;
	url=url+"&sid="+Math.random();
	xmlHttp.onreadystatechange=stateChanged;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

//Update Comments
//Update user basic information.
function update_comment()
{
xmlHttp=GetXmlHttpObject();
if (xmlHttp==null)
  {
  alert ("Your browser does not support AJAX!");
  return;
  } 
  function stateChanged() 
  { 
		if (xmlHttp.readyState < 4)
		{ 
			document.getElementById("loading_x").innerHTML= '<img src="images/camera-loading.gif"/>';
		}
		if (xmlHttp.readyState==4)
		{ 
			document.getElementById("output_x").innerHTML=xmlHttp.responseText;
			document.getElementById("loading_x").innerHTML= '';
		}
  }
	var post_content = document.getElementById("comment_content_x").value;
	var title = document.getElementById("title_x_y").value;
	var com_id = document.getElementById("com_id").value;
	var sid = (new Date()).getTime();
  
	var passData = 'post_content='+escape(post_content)+'&title='+escape(title)+'&com_id='+escape(com_id)+'&sid='+escape(sid);
	
   xmlHttp.open("POST", "./applications/update_comment_ajax.php", true);
   xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
   xmlHttp.onreadystatechange = stateChanged;                      
   xmlHttp.send(passData);
} 

//Function to delete all form of category without any variation
function delete_category(output_span, cat_id, section_x)
{
xmlHttp=GetXmlHttpObject();
if (xmlHttp==null)
  {
  alert ("Your browser does not support AJAX!");
  return;
  } 
  function stateChanged() 
  { 
		if (xmlHttp.readyState < 4)
		{ 
			document.getElementById(output_span).innerHTML= '<img src="images/loading7.gif"/>';
		}
		if (xmlHttp.readyState==4)
		{ 
			document.getElementById(output_span).innerHTML=xmlHttp.responseText;
		}
  }
	var category_id = cat_id;
	var section = section_x;
	var sid = (new Date()).getTime();
  
	var passData = 'category_id='+escape(category_id)+'&section='+escape(section)+'&sid='+escape(sid);
	
   xmlHttp.open("POST", "./applications/delete_category.php", true);
   xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
   xmlHttp.onreadystatechange = stateChanged;                      
   xmlHttp.send(passData);
}



//////////////////////////////////////////// Post Comment Ajax Script ////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function send_sms()
{
xmlHttp4 = GetXmlHttpObject();
var to_id = document.getElementById("to_id").value;
var message = document.getElementById("message").value;
var sid = (new Date()).getTime();
var passData = 'to_id='+escape(to_id)+'&message='+escape(message)+'&sid='+escape(sid);

if (xmlHttp4==null)
{
  alert ("Your browser does not support AJAX!");
  return;
} 
if(to_id != "" && message != "")
{
		function stateChanged() 
    	{ 
			if(xmlHttp4.readyState < 4)
			{
			    document.getElementById("loading").innerHTML = '<img src="images/camera-loading.gif"/>';
			}
			if (xmlHttp4.readyState==4)
			{ 
				document.getElementById("output").innerHTML=xmlHttp4.responseText;
				document.getElementById("loading").innerHTML = '';
				document.getElementById("message").innerHTML = '';
				//document.getElementById("commentcount2").innerHTML=xmlHttp.responseText;
			}
		}
}

   xmlHttp4.open("POST", "./applications/send_sms_to_user.php", true);
   xmlHttp4.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
   xmlHttp4.onreadystatechange = stateChanged;                      
   xmlHttp4.send(passData);
} 

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////


