// JavaScript Document
var xmlHttp;
var rootpath="http://localhost/quotes";
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;
}

function increVisit(quoteid)
{
  // alert(quoteid);
   xmlHttp=GetXmlHttpObject();
	var url="ajaxquote.php?for=increvisit&quoteid="+quoteid+"&bustcache="+new Date().getTime();
	//alert(url);
	xmlHttp.open("GET",url,true);
	xmlHttp.onreadystatechange=function()
							   {
							     //alert("dddd");
									if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
									 {
										 	//alert(xmlHttp.responseText);
									 }
							   }
	xmlHttp.send(null);						   
}
function changerating(quoteid,rate)
{
	
	var rateText=document.getElementById("ratetext"+quoteid);
	xmlHttp=GetXmlHttpObject();
    var url="ajaxquote.php?for=changerate&rate="+rate+"&quoteid="+quoteid+"&bustcache="+new Date().getTime();
	//alert(url);
    xmlHttp.open("GET",url,true);
	xmlHttp.onreadystatechange=function()
							   {
									if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
									 {
										 //	alert(xmlHttp.responseText);
											rateText.innerHTML=xmlHttp.responseText;
									 }
							   }
	xmlHttp.send(null);						   
	
}
function addtofavorite(quoteid,uid,spanid,ff)
{
	//alert(quoteid);
//	alert(uid);
	//alert(spanid);
	//alert(ff);
	xmlHttp=GetXmlHttpObject();
	if(ff=="u")
	{
		
		var url="ajaxquote.php?for=removefavorite&uid="+uid+"&quoteid="+quoteid+"&bustcache="+new Date().getTime();
    }
	else
	{
		var url="ajaxquote.php?for=addfavorite&uid="+uid+"&quoteid="+quoteid+"&bustcache="+new Date().getTime();
	}
	
	//alert(url);
    xmlHttp.open("GET",url,true);
	xmlHttp.onreadystatechange=function()
							   {
									if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
									 {
										 //	alert(xmlHttp.responseText);
										 var favoriteText=document.getElementById(spanid);
										 favoriteText.style.visibility='visible';
										// alert(favoriteText);
										 favoriteText.innerHTML=xmlHttp.responseText;
										// var sURL = unescape(window.location.pathname);
										// alert(location.href);
										var nurl=location.href.split('#');
										window.location.href=nurl[0];
									 }
							   }
	xmlHttp.send(null);		
}
function addintofavorite(quoteid,uid,spanid,ff)
{
	
	 xmlHttp=GetXmlHttpObject();
	if(ff=="u")
	{
		var url="ajaxquote.php?for=removefavorite&uid="+uid+"&quoteid="+quoteid+"&bustcache="+new Date().getTime();
    }
	else
	{
		var url="ajaxquote.php?for=addfavorite&uid="+uid+"&quoteid="+quoteid+"&bustcache="+new Date().getTime();
	}
	
    xmlHttp.open("GET",url,true);
	xmlHttp.onreadystatechange=function()
							   {
									if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
									 {
										 //	alert(xmlHttp.responseText);
										 var favoriteText=document.getElementById(spanid);
										 favoriteText.style.visibility='visible';
										// alert(favoriteText);
										 favoriteText.innerHTML=xmlHttp.responseText;
										// var sURL = unescape(window.location.pathname);
										window.location.href="comment.php?quoteid="+quoteid;

									 }
							   }
	xmlHttp.send(null);		
}

function deltofavorite(quoteid,uid,spanid)
{
	//alert(quoteid);
	//alert(uid);
	//alert(spanid);
	xmlHttp=GetXmlHttpObject();
    var url="ajaxquote.php?for=delfavorite&uid="+uid+"&quoteid="+quoteid+"&bustcache="+new Date().getTime();
	//alert(url);
    xmlHttp.open("GET",url,true);
	xmlHttp.onreadystatechange=function()
							   {
									if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
									 {
										 //alert(xmlHttp.responseText);
										 var favoriteText=document.getElementById(spanid);
										 favoriteText.style.visibility='visible';
										// alert(favoriteText);
										 favoriteText.innerHTML=xmlHttp.responseText;
									 }
							   }
	xmlHttp.send(null);		
}


function createtextbox(myid)
{
	
  var ele=document.getElementById(myid);
  var ele2=document.getElementById('txtauthor');
  var ele3=document.getElementById('categoryid');
  if(ele.value=="other1")
  {
  	ele2.style.visibility='visible';
	ele2.value="";
  }
 if(ele.value=="other0")
  {
	ele3.style.visibility='visible'; 
	ele3.value="";

  }

}

	function showeditdiv1()
		{
			var ele=document.getElementById("editdiv");
			var aname = document.getElementById("aname");
			var adesc = document.getElementById("adesc");

			ele.style.visibility='visible';
			var url;
		xmlHttp=new GetXmlHttpObject();
		url="ajax_author.php?aname="+aname+"&adesc="+adesc+"&burstcache="+new Date().getTime();
		alert(url);
		xmlHttp.open("GET",url,true);
		xmlHttp.onreadystatechange=function()
										{
											
											if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
											{ 
												if(xmlHttp.responseText=="empty")
												{
													aname.value="";
													adesc.value="";
												}
												else
												{
													var response=(xmlHttp.responseText).split("*");
													aname.value=response[0];
													adesc.value=response[1];
												}
												
											}
														
										}
		xmlHttp.send(null);
	
		}
function deleteuser(userid)
{
  //alert(userid);
   xmlHttp=GetXmlHttpObject();
    var url="ajaxquote.php?for=deleteuser&uid="+userid+"&bustcache="+new Date().getTime();
	//alert(url);
    xmlHttp.open("GET",url,true);
	xmlHttp.onreadystatechange=function()
							   {
									if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
									 {
										 	//alert(xmlHttp.responseText);
											window.location.href=xmlHttp.responseText;
									 }
							   }
	xmlHttp.send(null);		
  
}	
function deletequote(quoteid)
{
  //alert(quoteid);
   xmlHttp=GetXmlHttpObject();
    var url="ajaxquote.php?for=deletequote&qid="+quoteid+"&bustcache="+new Date().getTime();
	//alert(url);
    xmlHttp.open("GET",url,true);
	xmlHttp.onreadystatechange=function()
							   {
									if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
									 {
										 	//alert(xmlHttp.responseText);
											window.location.href=xmlHttp.responseText;
									 }
							   }
	xmlHttp.send(null);		
  
}	
function showeditcategory(catid)
{
	var ele=document.getElementById("editdiv");
		var ele1=document.getElementById("h1");
		var cname=document.getElementById("cname");
		var desc=document.getElementById("desc");
		ele.style.visibility='visible';
		ele1.value=catid;
		var url;
		xmlHttp=new GetXmlHttpObject();
		url="ajaxquote.php?for=editcategory&id="+catid+"&burstcache="+new Date().getTime();
		//alert(url);
		xmlHttp.open("GET",url,true);
		xmlHttp.onreadystatechange=function()
		                                  {
											if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
											{ 
												if(xmlHttp.responseText=="empty")
												{
													cname.value="";
													desc.value="";
												}
												else
												{
													var response=(xmlHttp.responseText).split("&");
													cname.value=response[0];
													desc.value=response[1];
												}
												
											}
														
										 }
		xmlHttp.send(null);
	
	
}
function deletecategory(catid)
{
	//alert(catid);
   xmlHttp=GetXmlHttpObject();
    var url="ajaxquote.php?for=deletecategory&cid="+catid+"&bustcache="+new Date().getTime();
	//alert(url);
    xmlHttp.open("GET",url,true);
	xmlHttp.onreadystatechange=function()
							   {
									if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
									 {
										 	//alert(xmlHttp.responseText);
											window.location.href=xmlHttp.responseText;
									 }
							   }
	xmlHttp.send(null);		
	
}


function getList(eleId,divId)
	{
		 //alert(eleId);
		// alert(divId);
		xmlHttp=GetXmlHttpObject();
		var url="ajaxquote.php?for="+eleId+"&keyword="+document.getElementById(eleId).value+"&bustcache="+new Date().getTime();
		//alert(url);
		xmlHttp.open("GET",url,true);
		xmlHttp.onreadystatechange=function()
							   {
									if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
									 {
										
										 	if((xmlHttp.responseText).length>22)
											{
											document.getElementById(divId).innerHTML=xmlHttp.responseText;
											document.getElementById(divId).style.border="1px solid #3399FF";
											document.getElementById(divId).style.visibility='visible';
											}
											else
											{
												document.getElementById(divId).style.visibility='hidden';
												document.getElementById(divId).innerHTML="";
											}
									 }
							   }
	xmlHttp.send(null);						   
	
	
	}


/*function sortMe(ele,catid)
{
		var menuselect=ele.value;
        var menuselect1= menuselect.split('.');
		//alert(menuselect1[0]);
		xmlHttp=GetXmlHttpObject();
    var url="ajaxquote.php?for=sortdata&menuselect="+menuselect1[0]+"&cid="+catid+"&bustcache="+new Date().getTime();
	//alert(url);
    xmlHttp.open("GET",url,true);
	xmlHttp.onreadystatechange=function()
							   {
									if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
									 {
										 //	alert(xmlHttp.responseText);
											//window.location.href=xmlHttp.responseText;
											 var showdiv=document.getElementById('sortresult');
											showdiv.innerHTML=xmlHttp.responseText;
									 }
							   }
	xmlHttp.send(null);		

}*/
function showdiv(qid,uid,quote,author,tag)
{
   // alert(qid);
	//alert(uid);
	//alert(quote);
	//alert(tag);
	 var showdiv1=document.getElementById('editquotediv');
	  showdiv1.style.visibility='visible';
	var textquote=document.getElementById('editquote');
	var textauthor=document.getElementById('editauthor');
	/*for(var i=0;i<(textcat.options.length);i++)
	{
		//alert(textcat.options[i].value);
		if(cat==textcat.options[i].text)
		{
			textcat.selectedIndex=i;
			break;
		}
	}*/
	for(var i=0;i<(textauthor.options.length);i++)
	{
		//alert(textcat.options[i].value);
		if(author==textauthor.options[i].text)
		{
			textauthor.selectedIndex=i;
			break;
		}
	}
	 textquote.value=quote;
	  var ele1=document.getElementById('hid1');
	  var ele2=document.getElementById('hid2');
	  var tagv=document.getElementById('edittag');
	 // alert(tagv);
	  ele1.value=qid;
	  ele2.value=uid;
	  tagv.value=tag;
	 // alert(tagv.value);
	  		
}
function submitMe()
{ 
	     var url;
		 var uid=document.getElementById("aquote");
		 //alert(uid.value);
		 var author=document.getElementById("author");
		 var tag=document.getElementById("txttag");
		 
			if(author.value=="")
			{
			   alert("You are not enter Author");
			} 
			var quote=document.getElementById("quote");
			if(quote.value=="")
			{
			     alert("You are not enter Quote");
			}
			/*var cate=document.getElementById("cat"); 
			if(cate.value=="")
			{
			   alert("You are not enter Category");
			}*/
		xmlHttp=new GetXmlHttpObject();
		
		url="ajaxquote.php?for=addquote&author="+author.value+"&quote="+quote.value+
		"&uid="+uid.value+"&tag="+tag.value+"&burstcache="+new Date().getTime();
		xmlHttp.open("GET",url,true);
		xmlHttp.onreadystatechange=function()
										{
											
											if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
											{ 
											    alert(xmlHttp.responseText);
												window.location.href="index.php";
											}
														
										}
		xmlHttp.send(null);
			
		
}
function deltag(qid,tag)
{
     //alert(qid);
	  //alert(tag);
	  xmlHttp=GetXmlHttpObject();
    var url="ajaxquote.php?for=deltag&qid="+qid+"&bustcache="+new Date().getTime();
	//alert(url);
    xmlHttp.open("GET",url,true);
	xmlHttp.onreadystatechange=function()
							   {
									if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
									 {
										 	alert(xmlHttp.responseText);
											//window.location.href="index.php";
										  var nurl=location.href.split('#');
										   window.location.href=nurl[0];
									 }
							   }
	xmlHttp.send(null);		
	
}
function edituser(uid,roleid,uname)
{
	//alert(uid);
	//alert(roleid);
	var ele=document.getElementById("editdiv");
		var ele1=document.getElementById("h1");
		var aname=document.getElementById("aname");
	  ele1.value=uid;
	aname.value=uname;
    xmlHttp=GetXmlHttpObject();
    var url="ajaxquote.php?for=editutype&uid="+uid+"&roleid="+roleid+"&bustcache="+new Date().getTime();
	//alert(url);
	xmlHttp.open("GET",url,true);
	xmlHttp.onreadystatechange=function()
							   {
									if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
									 {
										   var utypestr=(xmlHttp.responseText).split('*');
										   //alert(xmlHttp.responseText);
										    var opt = document.createElement("option");
											 document.getElementById("utype").options.add(opt);
											  var utypestr1=utypestr[0].split(',');
											   opt.text = utypestr1[1];
											   opt.value = utypestr1[0];
										   for(var i=1;i<4;i++)
										   {
											   var opt = document.createElement("option");
											   document.getElementById("utype").options.add(opt);
											   var utypestr1=utypestr[i].split(',');
											   opt.text = utypestr1[1];
											   opt.value = utypestr1[0];
											   ele.style.visibility='visible';
										   }
										   
									 }
							   }
	xmlHttp.send(null);		
}
