var animate_popup=0;	//This variable cant take 0 or 1; Set value to 0 for no animations and set value to 1 to show animated popup;

document.onmousedown=function()
{
	//hide_options();	
}

function page_load()
{
	//Used in Left Panel functionality
	document.getElementById("left_panel").style.height=document.body.clientHeight-34+"px";
}

/*
This function will disable the page
*/
function disable_background()
{
	var x=document.createElement('div');	
	x.setAttribute('id','background');
	x.setAttribute('style','display:block');
	document.body.appendChild(x);

	document.getElementById('background').style.position='absolute';
	document.getElementById('background').style.display='block';
	document.getElementById('background').style.top=0;
	document.getElementById('background').style.left=0;
	document.getElementById('background').style.zIndex=2;

	if(document.body.scrollHeight>screen.height)
	{
		document.getElementById('background').style.height=document.body.scrollHeight+"px";
	}
	else
	{
		document.getElementById('background').style.height=screen.height+"px";
	}
	//document.getElementById('background').style.width=document.body.scrollWidth;	
	document.getElementById('background').style.width=document.body.clientWidth+"px";	
	document.getElementById('background').style.MozOpacity=.50;
}

/*
-----------------------------------------------------------------------------------------------------
-------------------------------------Functions for Popup---------------------------------------------
-----------------------------------------------------------------------------------------------------
*/

/*
This function will show popup window.
It needs two parameters
	1) URL of the page which is to be opened in pop up box.
	2) Title to be shown on Pop Up box.
	3) Method to be used (POST,GET)
	4) parameter to be passed if POST method is used
	5) whether it is 'image' or 'text'
*/
function show_popup(url,window_title,method,params,contents)
{
	var popup=document.createElement('div');	
	popup.setAttribute('id','popup');
	document.body.appendChild(popup);

	var title=document.createElement('div');
	title.setAttribute('id','title');
	document.getElementById('popup').appendChild(title);

	var body=document.createElement('div');	
	body.setAttribute('id','popup_body');
	document.getElementById('popup').appendChild(body);

	document.getElementById('popup').style.position='absolute';
	document.getElementById('popup').style.border='0px solid black';
	document.getElementById('popup').style.background="#4E4E4E";
	document.getElementById('popup').align='center';
		
	document.getElementById('title').innerHTML="<span style='float:left'><font style='padding:5px;font-weight:bold;font-size:12px;' face='verdana'>" + window_title + "</font></span><a style='color:white;text-decoration:none' href='#' onClick='hide_popup()'><img src='images/close.gif' border='0' width='20'></a>";
	document.getElementById('title').style.border='1px solid #cccccc';
	document.getElementById('title').style.borderBottom='0px solid #cccccc';
	document.getElementById('title').style.padding='2px';
	document.getElementById('title').align='right';

			
	disable_background();
	if(method=="POST")
	{
		ajax_post(url,'popup_body',params);
	}
	else
	{
		if(contents=="image")
		{
			document.getElementById('popup_body').innerHTML="<img src='"+ url +"' border='0'>";
		}
		else
		{
			ajax(url,'popup_body');
		}		
	}

	document.getElementById('popup').style.top="-500px";
	document.getElementById('popup').style.left="-500px";
	if(animate_popup==1)
	{
		animate(10);
	}
	else if(animate_popup==2)
	{
		animate1(10);
	}
	else
	{
		no_animation(10);
	}
}

/*
Show Popup with animation
*/
function animate(ctr)
{
	if(ctr<(document.body.clientHeight-document.getElementById('popup').clientHeight)/2)	
	{
		document.getElementById('popup').style.top=ctr+"px";
		document.getElementById('popup').style.left=(screen.width-document.getElementById('popup').clientWidth)/2+"px";
		ctr=ctr+5;
		setTimeout("animate("+ ctr +")",1);
	}
}

function animate1(ctr)
{
	if(ctr<document.getElementById('popup').clientHeight)
	{
		document.getElementById('popup').style.top=(-document.getElementById('popup').clientHeight+ctr)+"px";
		document.getElementById('popup').style.left=(screen.width-document.getElementById('popup').clientWidth)/2+"px";
		ctr=ctr+10;
		setTimeout("animate1("+ ctr +")",1);
	}
}


/*
Show Popup without animation
*/
function no_animation(ctr)
{
	document.getElementById('popup').style.top=(document.body.clientHeight-document.getElementById('popup').clientHeight)/2+"px";
	document.getElementById('popup').style.left=(screen.width-document.getElementById('popup').clientWidth)/2+"px";
	setTimeout("no_animation("+ ctr +")",1);
}

/*
This function will hide popup box
*/
function hide_popup()
{
	document.body.removeChild(document.getElementById('popup'));
	document.body.removeChild(document.getElementById('background'));
	//document.getElementById('popup').style.display="none";
}

/*
-----------------------------------------------------------------------------------------------------
-------------------------Functions for Right Click Type Options--------------------------------------
-----------------------------------------------------------------------------------------------------
*/

/*
This function will show option menu like right click.
It takes two parameters:
	1) Event Object
	2) URL of page which will contain options to be shown.
*/
function show_options(e,url)
{
	var outer_box=document.createElement('div');
	outer_box.setAttribute('id','outer_box');
	document.body.appendChild(outer_box);

	var inner_box=document.createElement('div');
	inner_box.setAttribute('id','inner_box');
	document.getElementById('outer_box').appendChild(inner_box);

	document.getElementById("outer_box").style.position='absolute';
	document.getElementById("inner_box").style.border='1px solid';

	var explorer=navigator.userAgent.toLowerCase();
	
	if(explorer.indexOf("msie")>-1)
	{
		document.getElementById("outer_box").style.display='block';
		document.getElementById("outer_box").style.top=event.y +  document.documentElement.scrollTop;
		document.getElementById("outer_box").style.left=event.x + document.documentElement.scrollLeft;	
	}
	else
	{
		document.getElementById("outer_box").style.display='block';
		document.getElementById("outer_box").style.top=e.pageY + "px";
		document.getElementById("outer_box").style.left=e.pageX + "px";
	}
	ajax(url,'inner_box');
}

/*
This function will simply hide options menu
*/
function hide_options()
{	
	if(document.getElementById("outer_box")!=null)
	{
		document.getElementById("outer_box").style.display="none";
	}
}


/*
-----------------------------------------------------------------------------------------------------
------------------------------------Functions for AJAX-----------------------------------------------
-----------------------------------------------------------------------------------------------------
*/

/*
This function call a page dinamically.
It takes two parameters
	1) URL of page to be called
	2) id of element where result is to be shown
*/
function ajax(url,result)
{
	var xmlHttp;
	document.getElementById(result).innerHTML="";
	try	
	{  
		// Firefox, Opera 8.0+, Safari  
		xmlHttp=new XMLHttpRequest();  
	}
	catch (e)
	{  
		// Internet Explorer  
		try
		{   
		  xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");    
		}
		catch (e)
		{    
			try	
			{
				xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");      
			}
			catch (e)
			{      
				alert("Your browser does not support AJAX!");      
				return false;      
			}    
		}  
	}
	
	xmlHttp.onreadystatechange=function()
	{
		if(xmlHttp.readyState==4)
		{			
			document.getElementById(result).innerHTML=xmlHttp.responseText;
		}
	}
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}
/*
This function call a page dinamically using POST method.
It takes three parameters
	1) URL of page to be called
	2) id of element where result is to be shown
	3) Parameter to be posted.
*/
function ajax_post(url,result,params)
{
	var xmlHttp;
	try	
	{  
		// Firefox, Opera 8.0+, Safari  
		xmlHttp=new XMLHttpRequest();  
	}
	catch (e)
	{  
		// Internet Explorer  
		try
		{   
		  xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");    
		}
		catch (e)
		{    
			try	
			{
				xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");      
			}
			catch (e)
			{      
				alert("Your browser does not support AJAX!");      
				return false;      
			}    
		}  
	}	

	xmlHttp.open("POST",url,true);
	xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlHttp.setRequestHeader("Content-length", params.length);
	xmlHttp.setRequestHeader("Connection", "close");

	xmlHttp.onreadystatechange=function()
	{
		if(xmlHttp.readyState==4)
		{
			document.getElementById(result).innerHTML=xmlHttp.responseText;
		}
	}
	xmlHttp.send(params);
}


/*
-----------------------------------------------------------------------------------------------------
-------------------------------Functions for XP like Left Panel--------------------------------------
-----------------------------------------------------------------------------------------------------
*/

function show_left_panel_options(element,element_img)
{
	if(document.getElementById(element).style.display=="none")
	{
		document.getElementById(element).style.display="block";
		document.getElementById(element_img).innerHTML="<img src='images/up_button.gif'/>";
	}
	else
	{
		document.getElementById(element).style.display="none";
		document.getElementById(element_img).innerHTML="<img src='images/down_button.gif'/>";
	}
}
