var transparentDiv
var newimg
var name;

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 closeCommentBox ()
{
	if(document.getElementById('background'))
	{
		var a=document.getElementById('background');
		document.body.removeChild(a);
	}

	if(document.getElementById('commentBox'))
	{
		var b=document.getElementById('commentBox');
		document.body.removeChild(b);
	}
}

function savePaperPage(loginId,paperId,paperType,paperLink,actionPage,checkDetailSignup)
{
	if(loginId=="")
	{
		var error="Please login to use this feature.";
		//location.href="/Documents/intermidate_page.php?error_data="+error+"&action_page="+actionPage;//Commented by Rajesh for issue 54 
		location.href="/login_info.php?error_data="+error+"&action="+paperLink;//added by Rajesh for issue 54
	}
	else if(checkDetailSignup=="")
	{
		location.href="/User/registration_page.php?error_type=1&show_page=2";
	}
	else
	{
		xmlHttpPage=GetXmlHttpObject();
		var pageNum = currPageNum;
		var pageWidth = currImgWidth;
		var pageHeight = currImgHeight;
		var pageLink = paperJpegsPathHttp;
		if (xmlHttpPage==null)
		{
			alert ("Browser does not support HTTP Request")
			return
		} 
	
		xmlHttpPage.onreadystatechange=function ()
		{ 
			if (xmlHttpPage.readyState==4 || xmlHttpPage.readyState=="complete")
			{ 
				closeCommentBox();
				document.getElementById('saveMsg').innerHTML = "<font color='green' size='2'><b>"+xmlHttpPage.responseText+"</b></font>";
				document.getElementById('saveMsg').style.display = "";
			} 
		}
		xmlHttpPage.open("GET","/Paper/show_save_page.php?login_id="+loginId+"&paper_id="+paperId+"&paper_type="+paperType+"&page_num="+pageNum+"&paper_link="+paperLink+"&page_link="+pageLink+"&page_width="+pageWidth+"&page_height="+pageHeight+"&sid="+Math.random(),true);
			
		xmlHttpPage.send(null);
	}
}

/*Added by Rajesh Reddy for issue 54 point number 21*/
function showSavePage(e,loginId,paperId,paperType,actionPage,checkDetailSignup,paperLink)
{

	if(loginId=="")
	{
		var error="Please login to use this feature.";
		//location.href="/Documents/intermidate_page.php?error_data="+error+"&action_page="+actionPage;//Commented by Rajesh for issue 54 
		location.href="/login_info.php?error_data="+error+"&action="+paperLink;//added by Rajesh for issue 54
	}
	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("saveDialog1");
		var fullpage = document.getElementById("fullpage1");
		
		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 > 1000)
			{
				dialog.style.left=e.pageX - 240 + "px";
				dialog.style.top=e.pageY + 10 + "px";
			}
			else
			{
				//Changed by balraj on 27-10-2010 for mantis issue #54, Doc #2, Defect ID#16
				dialog.style.left=e.pageX + 10 + "px";
				//dialog.style.left=e.pageX + 120 + "px";
				dialog.style.top=e.pageY + 10 + "px";
				/*dialog.style.left="452px";
				dialog.style.top="425px";*/
			}

			//Commented by balraj on 29-10-2010 for mantis issue #54
			//dialog.style.height="160px";
		}
		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 > 1000)
			{
				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";
			}
		}
		
		var pageNum = currPageNum;
		if(pageNum==0)
		{
			pageNum = 1;
		}
		var pageLink = paperJpegsPathHttp;
		xmlHttpSavePage=GetXmlHttpObject();
			
		if (xmlHttpSavePage==null)
		{
			alert ("Browser does not support HTTP Request")
			return
		} 

		xmlHttpSavePage.onreadystatechange=function ()
		{ 
			if (xmlHttpSavePage.readyState==4 || xmlHttpSavePage.readyState=="complete")
			{ 
				document.getElementById('saveDialog1').innerHTML =xmlHttpSavePage.responseText;
			} 
		}
		xmlHttpSavePage.open("GET","/Paper/show_post_slide.php?login_id="+loginId+"&paper_id="+paperId+"&paper_link="+paperLink+"&page_link="+pageLink+"&page_num="+pageNum+"&paper_type="+paperType+"&sid="+Math.random(),true);
			
		xmlHttpSavePage.send(null);
	}
}
/*end*/

function showSaveDialog(e,loginId,paperId,paperType,actionPage,checkDetailSignup,paperLink)
{

	if(loginId=="")
	{
		var error="Please login to use this feature.";
		//location.href="/Documents/intermidate_page.php?error_data="+error+"&action_page="+actionPage;//Commented by Rajesh for issue 54 
		location.href="/login_info.php?error_data="+error+"&action="+paperLink;//added by Rajesh for issue 54
	}
	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("saveDialog");
		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 > 1000)
			{
				dialog.style.left=e.pageX - 240 + "px";
				dialog.style.top=e.pageY + 10 + "px";
			}
			else
			{
				//dialog.style.left=e.pageX + 10 + "px";
				dialog.style.left=e.pageX + 120 + "px";
				dialog.style.top=e.pageY + 10 + "px";
			}

			dialog.style.height="120px"
		}
		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 > 1000)
			{
				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('saveDialog').innerHTML =xmlHttp.responseText;
			} 
		}
		xmlHttp.open("GET","/Paper/show_save_dialog.php?login_id="+loginId+"&paper_id="+paperId+"&paper_type="+paperType+"&sid="+Math.random(),true);
			
		xmlHttp.send(null);
	}
}

function hideDialog()
{
	var dialog = document.getElementById("saveDialog");
	var fullpage = document.getElementById("fullpage");
	document.getElementById("fullpage").visibility="hidden"
	fullpage.style.visibility="hidden"
	dialog.style.visibility="hidden"

	name="";
}

function hideSlide()
{
	var dialog = document.getElementById("saveDialog1");
	var fullpage = document.getElementById("fullpage1");
	document.getElementById("fullpage").visibility="hidden"
	fullpage.style.visibility="hidden"
	dialog.style.visibility="hidden"

	name="";
}

function validate(saveName)
{
	name=saveName.value;
	alert(name);
}

function saveInfo(loginId,paperId,flag,type,saveName,category)
{
	name=saveName.value;
	categoryName=category.value;
	
	categoryName=encodeURIComponent(categoryName);

	if(flag=="save")
	{
		var errorDisplay = document.getElementById("errorDisplay");
		var errorCombo = document.getElementById("errorCombo");
	
		var str=errorDisplay.innerHTML;
		
		//if you want to bring back the empty error.
		//if(!str.match("empty") && str!="")
		//name="";
	}	

	if(name=="" && flag=="save")
	{
		errorDisplay.innerHTML="<font size='2px' color='red'>Name 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('saveDialog').innerHTML =xmlHttp.responseText;
			} 
		}
		xmlHttp.open("GET","/Paper/save_to_library.php?login_id="+loginId+"&paper_id="+paperId+"&flag="+flag+"&type="+type+"&save_name="+escape(name)+"&category="+categoryName+"&sid="+Math.random(),true);
		
		xmlHttp.send(null);
	}
}

//Added by balraj to trim strings
function trim(str)
{
    return str.replace(/^\s+|\s+$/g, '');
}

String.prototype.trimText = function ()
{

        // If it matches leading and trailing spaces
        var reExtraSpace = /^\s+(.*?)\s+$/;
        return this.replace(reExtraSpace, "$1");

};
/*Added by Rajesh Reddy for issue 54 point number 20 and 21*/

function saveSlide(loginId,paperId,flag,paperType,pageNum,paperLink,pageLink,saveName,category)
{
    	
        name=saveName.value;
	categoryName= category.value;
	
	
	
	var pageWidth = currImgWidth;
	var pageHeight = currImgHeight;
	
	if(flag=="save")
	{
		var errorDisplay = document.getElementById("errorDisplay");
		var errorCombo = document.getElementById("errorCombo");
	
		var str=errorDisplay.innerHTML;
		
		//if you want to bring back the empty error.
		//if(!str.match("empty") && str!="")
		//name="";
	}
         

	//Code Added by balraj on 22-10-2010 for mantis issue #54(QA Defects - Mantis Issue 054.doc, issue#9)
	if(trim(name)=="" && flag=="save")
	{
		errorDisplay.innerHTML="<font size='2px' color='red'>Name cannot be empty</font>";
		return false;
	}else if(trim(categoryName) =="" && flag=="save")
	{
		errorCombo.innerHTML="<font size='2px' color='red'>Description cannot be empty</font>";
		return false;
	}
	else
	{
		categoryName=encodeURIComponent(categoryName);
                xmlHttp=GetXmlHttpObject();
		document.getElementById('save').disabled = true;
		if (xmlHttp==null)
		{
			alert ("Browser does not support HTTP Request")
			return;
		} 

		xmlHttp.onreadystatechange=function ()
		{ 
			if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
			{ 
				document.getElementById('saveDialog1').innerHTML =xmlHttp.responseText;
				document.getElementById('save').disbaled = false;
			} 
		}
		xmlHttp.open("POST","/Paper/post_page_slide.php",true);
xmlHttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
xmlHttp.send("login_id="+loginId+"&paper_id="+paperId+"&flag="+flag+"&paper_type="+paperType+"&page_num="+pageNum+"&paper_link="+paperLink+"&page_link="+pageLink+"&page_width="+pageWidth+"&page_height="+pageHeight+"&save_name="+escape(name)+"&category="+categoryName+"&sid="+Math.random());
		//xmlHttp.send(null);
	}
}

function savePage(loginId,paperId,paperType,pageNum,paperLink,pageLink,flag,savePageId)
{
		xmlHttpSave=GetXmlHttpObject();
		
		if (xmlHttpSave==null)
		{
			alert ("Browser does not support HTTP Request")
			return
		} 

		xmlHttpSave.onreadystatechange=function ()
		{ 
			if (xmlHttpSave.readyState==4 || xmlHttpSave.readyState=="complete")
			{ 
				document.getElementById('saveDialog').innerHTML =xmlHttpSave.responseText;
			} 
		}
		xmlHttpSave.open("GET","/Paper/show_save_page.php?login_id="+loginId+"&paper_id="+paperId+"&paper_type="+paperType+"&page_num="+pageNum+"&paper_link="+paperLink+"&page_link="+pageLink+"&flag="+flag+"&save_page_id="+savePageId+"&sid="+Math.random(),true);
		
		xmlHttpSave.send(null);
}

/*end*/

/**********************************************************Combo Box***********************************************/

function selectIt(segment,combo)
{
	var test=segment.innerHTML;
	test=test.replace("&amp;","&");
	combo.value=test;
	closeList();
}

function closeList()
{
	var listBox=document.getElementById("list");
	if(listBox)
	listBox.style.visibility="hidden"
}
	
function highlight(segment)
{
	if(segment.style.backgroundColor!="skyblue")
	{
		segment.style.backgroundColor="skyblue";
	}
	else
	{
		segment.style.backgroundColor="#ffffff";
	}	
}

function showOptions(textBox)
{
	var word=textBox.value;
	var listBox=document.getElementById("list");
	
	xmlHttp=GetXmlHttpObject();
			
	if (xmlHttp==null)
	{
		alert ("Browser does not support HTTP Request")
		return
	} 

	xmlHttp.onreadystatechange=function ()
	{ 
		if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
		{ 
			listBox.innerHTML =xmlHttp.responseText;
			if(listBox.innerHTML=="")
				listBox.style.visibility="hidden"
			else
			{
				listBox.style.visibility=""
				listBox.style.zIndex="300"
			}
		}
	}
	xmlHttp.open("GET","/Paper/list_options.php?word="+word+"&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;
}
//start :: Saurabh has added this code for issues 416
function saveAdReport(e,loginId,paperId,actionUrl,paperLink,type){
             var ad_input = '';
             var adv_id = document.getElementById("ad_id").value;
             location.href=actionUrl+"?type="+type+"&paperId="+paperId+"&adv_id="+adv_id+"&paperLink="+paperLink; //added by saurabh
}
function showReportPage(e,loginId,paperId,actionUrl,paperLink,type)
{
   
 var ad_input = '';
	if(trim(loginId)=="")
	{
            
		var error="Please login to use this feature.";
		//location.href="/Documents/intermidate_page.php?error_data="+error+"&action_page="+actionPage;//Commented by Rajesh for issue 54
		//location.href="/login_info.php?error_data="+error+"&action="+paperLink;//added by Rajesh for issue 54
                location.href="/login_info.php?error_data="+error+"&action="+paperLink; //added by saurabh
	}
	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("saveDialog1");
		var fullpage = document.getElementById("fullpage1");

		dialog.style.visibility=""
		fullpage.style.visibility=""
            $("#saveDialog1").hide();
            $("#fullpage1").hide();
            $("#saveDialog1").fadeIn('slow');
            $("#fullpage1").fadeIn('slow');
		fullpage.style.width=bodyWidth-10+"px"
		fullpage.style.height=bodyHeight+"px"

		fullpage.style.zIndex="100"
		dialog.style.zIndex="200"

		if(e.pageX!=null)
		{
                    
			if(e.pageX > 1000)
			{
				dialog.style.left=e.pageX - 300 + "px";
				dialog.style.top=e.pageY + 10 + "px";
			}
			else
			{
				//Changed by balraj on 27-10-2010 for mantis issue #54, Doc #2, Defect ID#16
				dialog.style.left=e.pageX - 300  + "px";
				//dialog.style.left=e.pageX + 120 + "px";
				dialog.style.top=e.pageY + 10 + "px";
				/*dialog.style.left="452px";
				dialog.style.top="425px";*/
			}

			//Commented by balraj on 29-10-2010 for mantis issue #54
			//dialog.style.height="160px";
		}
		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 > 1000)
			{
				dialog.style.left= xcoord - 305  + "px";
				dialog.style.top= ycoord + 10 + "px";
			}
			else
			{
				dialog.style.left= xcoord - 300  + "px";
				dialog.style.top= ycoord + 10 + "px";
			}
		}
               
                if(type == 'AD'){
                    var adv_id = document.getElementById("ad_id").value;
                    ad_input = '<input type="hidden" value="'+adv_id+'" name="adv_id" />';

                }
                
  $("#saveDialog1").html('<span id="msg"></span><center><form id="myForm" action="'+actionUrl+'" method="post"><table><tr><td style="vertical-align:top">Comment:</td><td><textarea   name="comment" id="commentId" ROWS="8" COLS="25"></textarea><br/><span class="commentId" style="color:red;"></span></td></tr><tr><td>&nbsp;</td><td ><input type="hidden" value="'+loginId+'" name="loginId" />'+ad_input+'<input type="hidden" value="'+paperId+'" name="paperId" /><input type="submit" value="Submit" /><input type="button" value="Cancel" onclick="closeMyForm()" /></td></tr></table></form></center><script type="text/javascript">$(document).ready(function(){ var options = { beforeSubmit:  checKFields, success: success }; $("#myForm").ajaxForm(options); });</script>');
	}
}
function closeMyForm(){
    
    $("#saveDialog1").fadeOut('slow');
    $("#fullpage1").fadeOut('slow');
    var dialog = document.getElementById("saveDialog1");
    var fullpage = document.getElementById("fullpage1");
   
     dialog.style.visibility="hidden";
    fullpage.style.visibility="hidden";
    $("#saveDialog1").hide();
        $("#fullpage1").hide();
        $("#saveDialog1").fadeIn('slow');
        $("#fullpage1").fadeIn('slow');
}
function success(){
   $("#saveDialog1").html('<center> Thank you for helping us make weSRCH better.<br/><input type="button" value="close" onclick="closeMyForm()" /></center>');
}
function checKFields(){
if(trim($("#commentId").val())!=""){
        $(".commentId").html('');
       return true;
}else{
        $(".commentId").html('Please insert the value of Comment.');
    
    return false;
}
    

}
//End :: Saurabh has added this code for issues 416
