//******************************************************************************

function GetXmlHttpObject()
{ 
	var objXMLHttp=null;
	if (window.XMLHttpRequest)
	{
		objXMLHttp=new XMLHttpRequest();
	}
	else if (window.ActiveXObject)
	{
		objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	return objXMLHttp;
}
////////////////////////////////////////AJAX PAGE//////////////////////////
var xmlHttp;
var divId="";
var txt='';
//*****************************************************************************
function htmlData(url,did)
{
	divId=did;	
    document.getElementById(divId).innerHTML="<img src='images/load.gif' border='0'>";

	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
	{
		alert ("Browser does not support HTTP Request");
		return;
	}
	
	var url=url;

	xmlHttp.onreadystatechange=stateChanged1 ;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
} 

function stateChanged1()
{ 
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	{	
	 document.getElementById(divId).innerHTML="";
	    msg=xmlHttp.responseText ;
		msg1=	msg.split("-");
		if(msg1[0]=='no'){
			document.getElementById(divId).style.display="block"
			document.getElementById(divId).innerHTML=msg1[1] ;
		}else{
			document.getElementById(divId).style.display="block"
			document.getElementById(divId).innerHTML=msg1[1] ;
		}
		
	}
} 

function displaystate1(val,siteurl)
{ 
	
	var xmlHttp
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null){
		alert ("Your browser does not support AJAX!");
		return;
	} 
	var url=siteurl+'action.php?action=getstateUs&id='+val;
	xmlHttp.onreadystatechange=function(){
		if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){ 
			
			//document.getElementById('showDIV').style.display="block";		
			document.getElementById('showDIV').innerHTML=xmlHttp.responseText;
		}
	}
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

// Add Doc comment

function CommentOnDoc(did,comment)
{	
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
	{
		alert ("Browser does not support HTTP Request");
		return;
	}
	var url="userclass.php?action=CommentOnDoc&did="+did+"&comment="+comment;
	xmlHttp.onreadystatechange=function(){
		if(xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){
			
			document.getElementById("comment_list").innerHTML=xmlHttp.responseText+document.getElementById("comment_list").innerHTML;
			
			document.getElementById("doc_cmmnt").value = "";
			
			document.getElementById('addcmmt').style.display='none';
			
			if(document.getElementById("commentcount").value==0){
				document.getElementById('no_record').style.display='none';
				document.getElementById("commentcount").value=1;
				
			}
		}
	}
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}



function ADDAnswer(qid,answer)
{	
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
	{
		alert ("Browser does not support HTTP Request");
		return;
	}
	var url="userclass.php?action=addAnswer&qid="+qid+"&answer="+answer;
	xmlHttp.onreadystatechange=function(){
		if(xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){
			
			
			document.getElementById("comment_list").innerHTML=xmlHttp.responseText+document.getElementById("comment_list").innerHTML;
			
			document.getElementById("doc_answer").value = "";
			
			document.getElementById('addcmmt').style.display='none';
			
			
			if(document.getElementById("countAnswer").value==0){
				document.getElementById('no_record').style.display='none';
				document.getElementById("countAnswer").value=1;
				
			}
		}
	}
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}








function trainerNav(val,section)
{   
	var xmlHttp
	xmlHttp=GetXmlHttpObject();
	
	document.getElementById('trainerNavId').innerHTML="<div align='center' style='height:209px; padding-top:20px;'><img src='images/loadingAnimation.gif'></div>";	
	
	for(var a=1;a<4;a++)
	{ //SET CURRENT CLASS FROM HERE
		if(a==section)
		document.getElementById('mem'+a).className='Light11 Gray1 current2';
		else
		document.getElementById('mem'+a).className='Light11 Gray1';
	}
	
	if (xmlHttp==null){
		alert ("Your browser does not support AJAX!");
		return;
	} 
	var url='action.php?action=change_member_nav&val='+val;
	
	xmlHttp.onreadystatechange=function(){
		
		if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){ 
			var result	=	xmlHttp.responseText;
			//alert(result);
			document.getElementById('trainerNavId').innerHTML=result;
		}
	}
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);		
	
}

function documentNav(val,section)
{   
	var xmlHttp
	xmlHttp=GetXmlHttpObject();
	
	document.getElementById('documentNavId').innerHTML="<div align='center' style='height:209px; padding-top:20px;'><img src='images/loadingAnimation.gif'></div>";	
	
	for(var a=1;a<4;a++)
	{ //SET CURRENT CLASS FROM HERE
		
		if(a==section) {
		
		document.getElementById('doc'+a).className='Light11 Gray1 current2';
		}
		else {
		document.getElementById('doc'+a).className='Light11 Gray1';
		}
	}
	
	if (xmlHttp==null){
		alert ("Your browser does not support AJAX!");
		return;
	} 
	var url='action.php?action=change_document_nav&val='+val;
	
	xmlHttp.onreadystatechange=function(){
		
		if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){ 
			var result	=	xmlHttp.responseText;
			//alert(result);
			document.getElementById('documentNavId').innerHTML=result;
		}
	}
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);		
	
}



function rate_this_topic(did,rating)
{   
	var xmlHttp
	xmlHttp=GetXmlHttpObject();
	
	if (xmlHttp==null){
		alert ("Your browser does not support AJAX!");
		return;
	} 
	var url='rating_document.php?did='+did+'&rate='+rating+'&action=doc_rating';
	xmlHttp.onreadystatechange=function(){
		
		
		if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){ 	
		var result	=	xmlHttp.responseText;
			//alert(result);
			document.getElementById('rating').innerHTML=result;
		}
	}
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);		
	
}

function rate_this_member(did,rating)
{   
	
	var xmlHttp;
		
			
	xmlHttp=GetXmlHttpObject();
	
	if (xmlHttp==null){
		alert ("Your browser does not support AJAX!");
		return;
	} 
	var url='rating_document.php?did='+did+'&rate='+rating+'&action=member_rating';
	xmlHttp.onreadystatechange=function(){
		
		if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){ 
		
			var result	=	xmlHttp.responseText;
			//alert(result);
			//document.getElementById('orgrating').style.display='none';
	         //document.getElementById('mem_rating').style.display='block';	
			 document.getElementById('orgrating').innerHTML=result;
			
		}
	}
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);		
	
}

function makefriend_newfunction(id)
{	

	//alert(id);
	var xmlHttp
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null){
		alert ("Your browser does not support AJAX!");
		return;
	} 
	var url='userclass.php?action=AddNetwork&friendid='+id;
	xmlHttp.onreadystatechange=function(){
		if(xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){
			
			
			var response	=	xmlHttp.responseText;
			
			if(response==1){
				alert("You can not add yourself in a network");
			}else if(response==2){
				alert("A network request already sent for this user to accept");
			}else if(response==3){
				alert("this member already added in your network");
			}else if(response==5){
				alert("This member already sent network request to you!!");
			}else{
				alert("This member added in your network list");
				//alert("A friend request has been sent for this user to accept");
			}
			
		}
	}
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);	
}

function make_inappropriate(id,act,section)
{	
	
	var xmlHttp;
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null){
		alert ("Your browser does not support AJAX!");
		return;
	} 
	var url='userclass.php?action='+act+'&id='+id;
	xmlHttp.onreadystatechange=function(){
		if(xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){
			var response	=	xmlHttp.responseText;
			
			if(response==1){
				alert("You can not mark your own "+section+" as Inappropriate!");
			} else if(response==2){
				alert("Selected "+section+" already Marked as Inappropriate");
			}else{
				document.getElementById('preInapp').style.display='none';
				document.getElementById('postInapp').style.display='';
				alert("You have successfully makred this "+section+" as inappropriate");
			}
			
		}
	}
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);	
}

function getSubcatFunction(parent_id)
{
	var xmlHttp;
  	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
	{
		alert ("Browser does not support HTTP Request");
		return;
	}
 	var url="userclass.php?action=GetSubcat&parent_id="+parent_id;
  	
	xmlHttp.onreadystatechange=function(){
		if(xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
		{
			
			document.getElementById('123').style.display='none';
  		    document.getElementById('subcat').style.display='block';
			document.getElementById('subcat').innerHTML=xmlHttp.responseText;
			
		}
	}
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);	
}


function GetCourseSubcat(parent_id)
{
	
	var xmlHttp
  	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
	{
		alert ("Browser does not support HTTP Request");
		return;
	}
 	var url="userclass.php?action=GetCourseSubcat&parent_id="+parent_id;
  	
	xmlHttp.onreadystatechange=function(){
		if(xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
		{
			
			document.getElementById('123').style.display='none';
  		    document.getElementById('subcat').style.display='block';
			document.getElementById('subcat').innerHTML=xmlHttp.responseText;
			
		}
	}
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);	
}


//function for ajax based event paging on group page
function getTodoDetail(date,month)
{
  	xmlHttp=GetXmlHttpObject();
  	if (xmlHttp==null)
	{
		alert ("Browser does not support HTTP Request");
		return;
	}
 	var url="action.php?action=getTodoDetail&month="+month+"&date="+date;
  	xmlHttp.onreadystatechange=function(){
		if(xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){
 			document.getElementById('todo_list').innerHTML=xmlHttp.responseText;
			 
 		}
	}
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);	
	
 }
 
 function compliment(id)
{	
	
	var xmlHttp
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null){
		alert ("Your browser does not support AJAX!");
		return;
	} 
	var url='userclass.php?action=addcompliments&rec_id='+id;
	xmlHttp.onreadystatechange=function(){
		if(xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){
			
			
			var response	=	xmlHttp.responseText;
			
			if(response==1){
				alert("You can not compliment Yourself");
			}else if(response==2){
				alert("You have already compliment this user");
			}else{
				alert("You have successfully compliment selected user");
				//alert("A friend request has been sent for this user to accept");
			}
			
		}
	}
	
 	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);	
	 
}

function getTotalCompliment(user_id)
{
	//alert("test");
  	xmlHttp=GetXmlHttpObject();
  	if (xmlHttp==null)
	{
		alert ("Browser does not support HTTP Request");
		return;
	}
 
  	var url='userclass.php?action=total_user_complement&user_id='+user_id;
  	xmlHttp.onreadystatechange=function(){
		if(xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){
  			document.getElementById('compliment').innerHTML=xmlHttp.responseText;
  		}
	}
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);	
	
 }
 
 
 function make_inappropriate_notes(id,act,section)
{	
	
	var xmlHttp;
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null){
		alert ("Your browser does not support AJAX!");
		return;
	} 
	var url='userclass.php?action='+act+'&id='+id;
	xmlHttp.onreadystatechange=function(){
		if(xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){
			var response	=	xmlHttp.responseText;
			
			if(response==1){
				alert("You can not mark your own "+section+" as Inappropriate!");
			} else if(response==2){
				alert("Selected "+section+" already Marked as Inappropriate");
			}else{
				document.getElementById('preInapp').style.display='none';
				document.getElementById('postInapp').style.display='';
				alert("You have successfully makred this "+section+" as inappropriate");
			}
			
		}
	}
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);	
}


function make_favorite_notes(id,act,section)
{	
	
	var xmlHttp;
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null){
		alert ("Your browser does not support AJAX!");
		return;
	} 
	var url='userclass.php?action='+act+'&id='+id;
	xmlHttp.onreadystatechange=function(){
		if(xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){
			var response	=	xmlHttp.responseText;
			
			if(response==1){
				alert("You can not add your own "+section+" as Favorites!");
			} else if(response==2){
				alert("Selected "+section+" already added in your Favorites");
			}else{
				document.getElementById('preFav').style.display='none';
				document.getElementById('postFav').style.display='';
				alert("You have successfully added this "+section+" in your Favorites list");
			}
			
		}
	}
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);	
}


function CommentOnNotes(did,comment)
{	
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
	{
		alert ("Browser does not support HTTP Request");
		return;
	}
	var url="userclass.php?action=CommentOnNotes&did="+did+"&comment="+comment;
	xmlHttp.onreadystatechange=function(){
		if(xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){
			
			document.getElementById("comment_list").innerHTML=xmlHttp.responseText+document.getElementById("comment_list").innerHTML;
			
			document.getElementById("doc_cmmnt").value = "";
			
			document.getElementById('addcmmt').style.display='none';
			
			if(document.getElementById("commentcount").value==0){
				document.getElementById('no_record').style.display='none';
				document.getElementById("commentcount").value=1;
				
			}
		}
	}
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}



function rate_this_note(did,rating)
{   
	//alert(did);
	var xmlHttp
	xmlHttp=GetXmlHttpObject();
	
	if (xmlHttp==null){
		alert ("Your browser does not support AJAX!");
		return;
	} 
	var url='rating_document.php?did='+did+'&rate='+rating+'&action=notes_rating';
	xmlHttp.onreadystatechange=function(){
		
		if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){ 			
			var result	=	xmlHttp.responseText;
			//alert(result);
			document.getElementById('rating').innerHTML=result;
		}
	}
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);		
	
}


function GetCity(state)
{ 
alert(state)
   var xmlHttp
  	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
	{
		alert ("Browser does not support HTTP Request");
		return;
	}
 	var url='userclass.php?action=getcity&state='+state;
  	
	xmlHttp.onreadystatechange=function(){
		if(xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
		{
			
			//alert(xmlHttp.responseText);
			document.getElementById('hidecity').style.display='none';
			document.getElementById('getcity').style.display='block';
			document.getElementById('getcity').innerHTML=xmlHttp.responseText;
			
		
			
		}
	}
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);	


	
}


function GetState(country)
{ 

//alert(country)
   var xmlHttp
  	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
	{
		alert ("Browser does not support HTTP Request");
		return;
	}
 	var url='userclass.php?action=getstate&country='+country;
  	
	xmlHttp.onreadystatechange=function(){
		if(xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
		{
			
			//alert(xmlHttp.responseText);
			document.getElementById('hidestate').style.display='none';
			document.getElementById('getstate').style.display='block';
			document.getElementById('getstate').innerHTML=xmlHttp.responseText;
			
		
			
		}
	}
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);	


	
}


function GetDocSubCat(parent_id)
{
	
	var xmlHttp
  	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
	{
		alert ("Browser does not support HTTP Request");
		return;
	}
 	var url="userclass.php?action=GetDocSubCat&parent_id="+parent_id;
  	
	xmlHttp.onreadystatechange=function(){
		if(xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
		{
			
			document.getElementById('subcat1').style.display='none';
  		    document.getElementById('subcat').style.display='block';
			document.getElementById('subcat').innerHTML=xmlHttp.responseText;
			
		}
	}
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);	
}


//new one
function downloadnotes(id)
{ 
	var xmlHttp
  	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
	{
		alert ("Browser does not support HTTP Request");
		return;
	}
 	var url="userclass.php?action=downloadnotes&id="+id;
  	
	xmlHttp.onreadystatechange=function(){
		if(xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
		{
			//window.location.href='http://comp15'+downloadurl;
		}
	}
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);	
}

//new one
function downloaddocs(id)
{ 
	var xmlHttp
  	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
	{
		alert ("Browser does not support HTTP Request");
		return;
	}
 	var url="userclass.php?action=downloaddocs&id="+id;
  	
	xmlHttp.onreadystatechange=function(){
		if(xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
		{
			//window.location.href='http://comp15'+downloadurl;
		}
	}
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);	
}

