var animate_popup=2; //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();
}
/*
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;
}
/*
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.
*/
function show_popup(url,window_title,method,params)
{
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','body');
document.getElementById('popup').appendChild(body);
document.getElementById('popup').style.position='absolute';
document.getElementById('popup').style.border='2px solid black';
//document.getElementById('popup').style.display="block";
document.getElementById('title').innerHTML="
" + window_title + "";
document.getElementById('title').style.border='1px solid black';
disable_background();
if(method=="POST")
{
ajax_post(url,'body',params);
}
else
{
ajax(url,'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-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";
}
}
/*
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);
}
function findPosLeft(obj)
{
var curleft = curtop = 0;
if (obj.offsetParent)
{
do {
curleft += obj.offsetLeft;
curtop += obj.offsetTop;
} while (obj = obj.offsetParent);
}
return curleft;
}