var transparentDiv
var newimg
var tag;

function browserSize()
{
	var bodyWidth = document.documentElement.clientWidth;
    var bodyHeight = document.documentElement.clientHeight;
    	
	var bodyWidth, bodyHeight; 
	
	// all except Explorer 
	if (self.innerHeight)
	{ 
		bodyWidth = self.innerWidth; 
		bodyHeight = self.innerHeight; 
	} 
	   // Explorer 6 Strict Mode 		 
	else if (document.documentElement && document.documentElement.clientHeight) 
	{
		bodyWidth = document.documentElement.clientWidth; 
		bodyHeight = document.documentElement.clientHeight; 
	} 
	// other Explorers 		 
	else if (document.body) 
	{
		bodyWidth = document.body.clientWidth; 
		bodyHeight = document.body.clientHeight; 
	} 
		
	return [bodyWidth,bodyHeight];		
}

function showSaveTag(e,loginId,paperId,paperType,actionPage,checkDetailSignup)
{
	if(loginId=="")
	{
		var error="Please login to use this feature.";
		location.href="../Documents/intermidate_page.php?error_data="+error+"&action_page="+actionPage;
	}
	else if(checkDetailSignup=="")
	{
		location.href="../User/registration_page.php?error_type=1&show_page=2";
	}
	else
	{
		var bodyWidth = document.body.scrollWidth;
		var bodyHeight = document.body.scrollHeight;
		
		if(document.body.clientHeight > bodyHeight)
		{
			bodyHeight=document.body.clientHeight;
		}
		
		if(document.body.clientWidth > bodyWidth)
		{
			bodyWidth=document.body.clientWidth;
		}

		var dialog = document.getElementById("saveTag");
		var fullpage = document.getElementById("fullpage");
		
		dialog.style.visibility=""
		fullpage.style.visibility=""

		fullpage.style.width=bodyWidth+"px"
		fullpage.style.height=bodyHeight+"px"

		fullpage.style.zIndex="100"
		dialog.style.zIndex="200"

		if(e.pageX!=null)
		{
			if(e.pageX > 900)
			{
				dialog.style.left=e.pageX - 240 + "px";
				dialog.style.top=e.pageY + 10 + "px";
			}
			else
			{
				dialog.style.left=e.pageX + 10 + "px";
				dialog.style.top=e.pageY + 10 + "px";
			}
		}
		else
		{
			var xcoord = e.clientX;
			var ycoord = e.clientY;
		
			if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) 
			{
				xcoord += document.body.scrollLeft;
				ycoord += document.body.scrollTop;
			} 
			else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) 
			{
				xcoord += document.documentElement.scrollLeft;
				ycoord += document.documentElement.scrollTop;
			}
			if(xcoord > 700)
			{
				dialog.style.left= xcoord - 305  + "px";
				dialog.style.top= ycoord + 10 + "px";
			}
			else
			{
				dialog.style.left= xcoord + 10 + "px";
				dialog.style.top= ycoord + 10 + "px";
			}
		}

		xmlHttp=GetXmlHttpObject();
			
		if (xmlHttp==null)
		{
			alert ("Browser does not support HTTP Request")
			return
		} 

		xmlHttp.onreadystatechange=function ()
		{ 
			if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
			{ 
				document.getElementById('saveTag').innerHTML =xmlHttp.responseText;
			} 
		}
		var params  = "login_id="+loginId+"&paper_id="+paperId+"&paper_type="+paperType+"&sid="+Math.random();
		//*
		//alert (params);
		xmlHttp.open("POST","/Paper/show_save_tag.php",true);				
		xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded; text/xml; charset=ISO-8859-1");
		//xmlHttp.setRequestHeader("Content-type", "text/xml; charset=ISO-8859-1");
		xmlHttp.setRequestHeader("Content-length", params.length);
		xmlHttp.setRequestHeader("Connection", "close");
		xmlHttp.send(params);
		
		//xmlHttp.open("GET","/Paper/show_save_tag.php?login_id="+loginId+"&paper_id="+paperId+"&paper_type="+paperType+"&sid="+Math.random(),true);
		//xmlHttp.send(null);
	}
}

function hideTag()
{
	var dialog = document.getElementById("saveTag");
	var fullpage = document.getElementById("fullpage");
	document.getElementById("fullpage").visibility="hidden"
	fullpage.style.visibility="hidden"
	dialog.style.visibility="hidden"

	tag="";
	
}

function validate(saveTag)
{
	Tag=saveTag.value;
	alert(Tag);
}

function saveTag(loginId,paperId,flag,type,keyword_tag)
{
	tag=keyword_tag.value;

	if(flag=="save")
	{
		var errorDisplay = document.getElementById("errorDisplay");
	
		var str=errorDisplay.innerHTML;
		
		//if you want to bring back the empty error.
		//if(!str.match("empty") && str!="")
		//tag="";
	}	

	//if(tag=="" && flag=="save")
	//{
		//errorDisplay.innerHTML="<font size='2px' color='red'>Tag cannot be empty.</font>";
		//return false;
	//}
	//else
	//{
		xmlHttp=GetXmlHttpObject();
		
		if (xmlHttp==null)
		{
			alert ("Browser does not support HTTP Request")
			return
		} 

		xmlHttp.onreadystatechange=function ()
		{ 
			if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
			{ 
				document.getElementById('saveTag').innerHTML =xmlHttp.responseText;
			} 
		}
		
		
			var params  = "login_id="+loginId+"&paper_id="+paperId+"&flag="+flag+"&type="+type+"&save_tag="+encodeURIComponent(tag)+"&sid="+Math.random();
			//*
			//alert (params);
			xmlHttp.open("POST","/Paper/save_to_tag.php",true);				
			xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded; text/xml; charset=ISO-8859-1");
			//xmlHttp.setRequestHeader("Content-type", "text/xml; charset=ISO-8859-1");
			xmlHttp.setRequestHeader("Content-length", params.length);
			xmlHttp.setRequestHeader("Connection", "close");
			xmlHttp.send(params);
			//xmlHttp.open("GET","/Paper/save_to_tag.php?login_id="+loginId+"&paper_id="+paperId+"&flag="+flag+"&type="+type+"&save_tag="+encodeURIComponent(tag)+"&sid="+Math.random(),true);
			//xmlHttp.send(null);
	//}
}

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;
}