// JavaScript Document
function GetXmlHttpObject1()
{
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;
}


function GetXmlHttpObject2()
{
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;
}

var glb_i='';
function save_news_ajax(uid,nid,i)
{
	xmlHttp=GetXmlHttpObject1();
	if (xmlHttp==null)
    {
	  alert ("Your browser does not support AJAX!");
	  return;
    }
	glb_i=i;
	document.getElementById('span_save_'+i).innerHTML='Saving..';
	var url=root_url+"ajax/ajax.php?uid="+uid+"&nid="+nid+"&from=save_news";
	xmlHttp.onreadystatechange=saveNewsAjax;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

function saveNewsAjax()
{
	if(xmlHttp.readyState==4)
	{ 
	//alert(xmlHttp.responseText);
		document.getElementById('span_save_'+glb_i).innerHTML='Saved';
	}
}



function ajax_flag_comments(cid,item_id)
{
	xmlHttp=GetXmlHttpObject1();
	if (xmlHttp==null)
    {
	  alert ("Your browser does not support AJAX!");
	  return;
    }
	glb_i=cid;
	var url=root_url+"ajax/ajax.php?cid="+cid+"&item_id="+item_id+"&from=flag_comments";
	xmlHttp.onreadystatechange=ajaxFlagComments;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

function ajaxFlagComments()
{
	if(xmlHttp.readyState==4)
	{ 
	if(xmlHttp.responseText!='')
		{
			alert("You have successfully flagged this comments.");
		}
		else
		{
			alert("You already flagged the comments");
		}
		
	//alert(xmlHttp.responseText);
		//document.getElementById('span_save_'+glb_i).innerHTML='Saved';
	}
}

function ajax_like_comments(cid,item_id)
{
	xmlHttp=GetXmlHttpObject1();
	if (xmlHttp==null)
    {
	  alert ("Your browser does not support AJAX!");
	  return;
    }
	glb_i=cid;
	var url=root_url+"ajax/ajax.php?cid="+cid+"&item_id="+item_id+"&from=like_comments";
	xmlHttp.onreadystatechange=ajaxLikeComments;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

function ajaxLikeComments()
{
	if(xmlHttp.readyState==4)
	{ 
		//alert("You have successfully flagged this comments.");
	//alert(xmlHttp.responseText);
		if(xmlHttp.responseText!='')
		{
			document.getElementById('likeid_'+glb_i).innerHTML=xmlHttp.responseText;
			document.getElementById('like_div_1_'+glb_i).style.display='none';
			document.getElementById('like_div_2_'+glb_i).style.display='block';
		}
		else
		{
			alert("You already like the comments");
		}
	}
}


function ajax_get_news_data(page,topic,category)
{
	document.getElementById('ajax_loader').style.display='block';
	xmlHttp=GetXmlHttpObject1();
	if (xmlHttp==null)
    {
	  alert ("Your browser does not support AJAX!");
	  return;
    }
	var url=root_url+"ajax/ajax.php?page="+page+"&topic="+topic+"&cat="+category+"&from=news_home";
	//alert(url);
	xmlHttp.onreadystatechange=ajaxGetNewsData;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

function ajaxGetNewsData()
{
	if(xmlHttp.readyState==4)
	{ 
		document.getElementById('ajax_loader').style.display='none';
		$('#Searchresult').html(xmlHttp.responseText);
	}
}

function ajax_kaaf_it(i,uid,item_id)
{
	glb_i=i;
	xmlHttp=GetXmlHttpObject1();
	if (xmlHttp==null)
    {
	  alert ("Your browser does not support AJAX!");
	  return;
    }
	var url=root_url+"ajax/ajax.php?uid="+uid+"&item_id="+item_id+"&from=kaaf_it";
	//alert(url);
	xmlHttp.onreadystatechange=ajaxKaafIt;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

function ajaxKaafIt()
{
	if(xmlHttp.readyState==4)
	{ 
		document.getElementById('id_kaaf_it_'+glb_i).innerHTML=xmlHttp.responseText;
		document.getElementById('no_kaaf_id_'+glb_i).style.display='none';
		document.getElementById('kaaf_id_'+glb_i).style.display='block';
	}
}


function ajax_get_discussion_data(page,topic_id)
{
	document.getElementById('ajax_loader').style.display='block';
	xmlHttp=GetXmlHttpObject1();
	if (xmlHttp==null)
    {
	  alert ("Your browser does not support AJAX!");
	  return;
    }
	var url=root_url+"ajax/ajax.php?page="+page+"&topic_id="+topic_id+"&from=show_discussion";
	//alert(url);
	xmlHttp.onreadystatechange=ajaxGetDiscussionData;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

function ajaxGetDiscussionData()
{
	if(xmlHttp.readyState==4)
	{ 
		document.getElementById('ajax_loader').style.display='none';
		$('#Searchresult').html(xmlHttp.responseText);
	}
}


function ajax_like_discussion(did,item_id)
{
	xmlHttp=GetXmlHttpObject1();
	if (xmlHttp==null)
    {
	  alert ("Your browser does not support AJAX!");
	  return;
    }
	var url=root_url+"ajax/ajax.php?did="+did+"&item_id="+item_id+"&from=like_discussion";
	//alert(url);
	xmlHttp.onreadystatechange=ajaxLikeDiscussion;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}
function ajaxLikeDiscussion()
{
	if(xmlHttp.readyState==4)
	{ 
	
		document.getElementById('discussion_like').innerHTML=xmlHttp.responseText;
		document.getElementById('like_div_3').style.display='none';
		document.getElementById('like_div_4').style.display='block';
		//document.getElementById('ajax_loader').style.display='none';
		//$('#Searchresult').html(xmlHttp.responseText);
	}
}


function remove_user_image(id)
{
	xmlHttp=GetXmlHttpObject1();
	if (xmlHttp==null)
    {
	  alert ("Your browser does not support AJAX!");
	  return;
    }
	var url=root_url+"ajax/ajax.php?user_id="+id+"&from=remove_user_image";
	//alert(url);
	xmlHttp.onreadystatechange=removeUserImage;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}
function removeUserImage()
{
	if(xmlHttp.readyState==4)
	{ 
		window.location.reload();
	}
}



///RATE OUR DISPLAY WITH PAGINATION
function ajax_get_rate_our_data(page,rate_topic_id)
{
	document.getElementById('ajax_loader').style.display='block';
	xmlHttp=GetXmlHttpObject1();
	if (xmlHttp==null)
    {
	  alert ("Your browser does not support AJAX!");
	  return;
    }
	var url=root_url+"ajax/ajax.php?page="+page+"&rate_topic_id="+rate_topic_id+"&from=rateour";
	//alert(url);
	xmlHttp.onreadystatechange=ajaxGetRateOurData;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

function ajaxGetRateOurData()
{
	if(xmlHttp.readyState==4)
	{ 
		document.getElementById('ajax_loader').style.display='none';
		$('#Searchresult').html(xmlHttp.responseText);
	}
}

/*var glb_r_loader_id='';
var glb_rate_div_id='';
var glb_ratting_id='';
var glb_count_rate='';*/
function ajax_imsert_rateour_rating(count,item_id)
{
	
	var err='';
	var rating_id=document.getElementById('ratting_id_'+count).value;
	var quality_of_work=document.getElementById('quality_of_work_'+count).value;
	var initiative_and_dependability=document.getElementById('initiative_and_dependability_'+count).value;
	var communication_and_leadership_skills=document.getElementById('communication_and_leadership_skills_'+count).value;
	
	
	if(quality_of_work=='')
	{
		err +='Please select Quality of Work.\n';
	}
	if(initiative_and_dependability=='')
	{
		err +='Please select Initiative & Dependability.\n';
	}
	if(communication_and_leadership_skills=='')
	{
		err +='Please select Communication & Leadership Skills.';
	}
	
	if(err!='')
	{
		alert(err);
	}
	else
	{
		glb_r_loader_id='rateour_rating_ajax_loader_'+count;
		glb_rate_div_id='rate_div_'+count;
		glb_ratting_id='ratting_id_'+count;
		glb_count_rate='count_rate_'+count;
		document.getElementById(glb_r_loader_id).style.visibility='visible';
		xmlHttp=GetXmlHttpObject1();
		if (xmlHttp==null)
		{
		  alert ("Your browser does not support AJAX!");
		  return;
		}
		var url=root_url+"ajax/ajax.php?quality_of_work="+quality_of_work+"&initiative_and_dependability="+initiative_and_dependability+"&communication_and_leadership_skills="+communication_and_leadership_skills+"&item_id="+item_id+"&rating_id="+rating_id+"&from=rateour_rating";
		//alert(url);
		xmlHttp.onreadystatechange=ajaxImsertRateourRating;
		xmlHttp.open("GET",url,true);
		xmlHttp.send(null);
		
		
	}
	
	
}

function ajaxImsertRateourRating()
{
	if(xmlHttp.readyState==4)
	{ 
		var arr=xmlHttp.responseText.split('#'); 
		document.getElementById(glb_r_loader_id).style.visibility='hidden';
		document.getElementById(glb_ratting_id).value=arr[0];
		document.getElementById(glb_rate_div_id).style.display='none';
		document.getElementById(glb_count_rate).innerHTML=arr[1]+' Ratings';
	}
}



//Comments Pagination
var glb_comments_div_id;
function ajax_comments_new_page(item_id,start_limit,div_id,page_no,sort_order)
{
	glb_comments_div_id=div_id;
	xmlHttp=GetXmlHttpObject1();
		if (xmlHttp==null)
		{
		  alert ("Your browser does not support AJAX!");
		  return;
		}
		var url=root_url+"ajax/ajax.php?item_id="+item_id+"&start_limit="+start_limit+"&page_no="+page_no+"&sort_order="+sort_order+"&from=comments_new_page";
		//alert(url);
		xmlHttp.onreadystatechange=ajaxCommentsNewPage;
		xmlHttp.open("GET",url,true);
		xmlHttp.send(null);
}

function ajaxCommentsNewPage()
{
	if(xmlHttp.readyState==4)
	{ 
		document.getElementById(glb_comments_div_id).className='';
		document.getElementById(glb_comments_div_id).innerHTML=xmlHttp.responseText;
	}
}

function ajax_comment_page_count(item_id,start_limit,page_no,sort_order)
{
	document.getElementById('comments_loader_for_new_page').style.display='block';
	xmlHttp1=GetXmlHttpObject2();
		if (xmlHttp1==null)
		{
		  alert ("Your browser does not support AJAX!");
		  return;
		}
		var url=root_url+"ajax/ajax.php?item_id="+item_id+"&start_limit="+start_limit+"&page_no="+page_no+"&sort_order="+sort_order+"&from=comments_count_page";
		//alert(url);
		xmlHttp1.onreadystatechange=ajaxCommentPageCount;
		xmlHttp1.open("GET",url,true);
		xmlHttp1.send(null);
}

function ajaxCommentPageCount()
{
	if(xmlHttp1.readyState==4)
	{ 
		document.getElementById('comments_loader_for_new_page').style.display='none';
		document.getElementById("tot_show_comments").innerHTML=xmlHttp1.responseText;
	}
}

function remove_adv_image_ajax(image_name)
{
	if(image_name!='')
	{
		xmlHttp=GetXmlHttpObject1();
		if (xmlHttp==null)
		{
		  alert ("Your browser does not support AJAX!");
		  return;
		}
		var url=root_url+"ajax/ajax.php?image_name="+image_name+"&from=remove_adv_image";
		//alert(url);
		xmlHttp.onreadystatechange=removeAdvImageAjax;
		xmlHttp.open("GET",url,true);
		xmlHttp.send(null);
	}
}
function removeAdvImageAjax()
{
	if(xmlHttp.readyState==4)
	{   
		//window.location.reload();
		//document.getElementById('div_ajax_user_id').innerHTML=xmlHttp.responseText;
	}
}

//---------------------------New validation and updation for rate....................................................
var glb_r_loader_id='';
var glb_rate_div_id='';
var glb_ratting_id='';
var glb_count_rate='';
function ajax_insert_rateour_rating(i,count,item_id)
{
	
	var err=''; 
	var rating_topic_id= count; 
	//alert(item_id);
	var quality_of_work=document.getElementById('1'+i).value; 
	var initiative_and_dependability=document.getElementById('2'+i).value;
	var communication_and_leadership_skills=document.getElementById('3'+i).value;
	//var pid	= document.getElementById('ratting_id_'+i).value;
	
	if(quality_of_work=='')
	{
		err +='Please select Quality of Work.\n';
	}
	if(initiative_and_dependability=='')
	{
		err +='Please select Initiative & Dependability.\n';
	}
	if(communication_and_leadership_skills=='')
	{
		err +='Please select Communication & Leadership Skills.';
	}
	
	if(err!='')
	{
		alert(err);
	}
	else
	{
		
		glb_r_loader_id='rateour_rating_ajax_loader_'+i;
		glb_rate_div_id='rate_div_'+i;
		glb_ratting_id='ratting_id_'+i;
		glb_count_rate='count_rate_'+i;
		document.getElementById(glb_r_loader_id).style.visibility='visible';
		xmlHttp=GetXmlHttpObject1();
	
		
		if (xmlHttp==null)
		{
		  alert ("Your browser does not support AJAX!");
		  return;
		}
		
		var url=root_url+"ajax/ajax.php?quality_of_work="+quality_of_work+"&initiative_and_dependability="+initiative_and_dependability+"&communication_and_leadership_skills="+communication_and_leadership_skills+"&item_id="+item_id+"&rating_id="+rating_topic_id+"&from=rateour_rating";

	xmlHttp.onreadystatechange=ajaxImsertRateourRating;

	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
		//alert(url);
		
	}
	
	
}
