// JavaScript Document

var xmlHttp;
var t;
function AddPhotoTag(photo_id,top,left,tag_name,tag_order,tag_user)
{	
	document.getElementById("msg").innerHTML="saving...";
	if (tag_name.length==0)
  	{ 		
  		document.getElementById("msg").innerHTML="";
  		return;
  	}
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
  	{
  		alert ("Your browser does not support AJAX!");
  		return;
  	} 
	var url="phototagging/addPhotoTag.php";
	url=url+"?photo_id="+photo_id+"&top="+top+"&left="+left+"&tag_name="+tag_name+"&tag_order="+tag_order+"&tag_user="+tag_user;	
	xmlHttp.onreadystatechange=stateChanged;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}
function RemovePhotoTag(tag_order,photo_id)
{
	document.getElementById("msg").innerHTML="working...";
	if (tag_order.length==0 || photo_id.length==0)
  	{ 		
  		document.getElementById("msg").innerHTML="";
  		return;
  	}
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
  	{
  		alert ("Your browser does not support AJAX!");
  		return;
  	} 
	var url="phototagging/removePhotoTag.php";
	url=url+"?tag_order="+tag_order+"&photo_id="+photo_id;	
	xmlHttp.onreadystatechange=stateChanged;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
} 


function stateChanged() 
{ 
	if (xmlHttp.readyState==4)
	{ 			
		var xmlDoc=xmlHttp.responseXML;		
		var msg=xmlDoc.getElementsByTagName("msg")[0].childNodes[0].nodeValue;						
		if(msg=="Successfully added"){
			document.getElementById("msg").innerHTML="";
			t=xmlDoc.getElementsByTagName("id")[0].childNodes[0].nodeValue;				
			//SetTagId(t);			
		}
		else if(msg=="Successfully removed"){
			document.getElementById("msg").innerHTML=msg;
			document.getElementById("tagList").innerHTML=xmlDoc.getElementsByTagName("tagList")[0].childNodes[0].nodeValue;
			document.getElementById("tagInfo").innerHTML=xmlDoc.getElementsByTagName("tagInfo")[0].childNodes[0].nodeValue;			
			var totaltags=xmlDoc.getElementsByTagName("totaltags")[0].childNodes[0].nodeValue;
			var tagorder=xmlDoc.getElementsByTagName("tagorder")[0].childNodes[0].nodeValue;
			removeEventListener('mousemove',FindTag,imgObj);
			ResetTotalTags(totaltags,tagorder);
			HideTag();			
		}
	}
}



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;
}
