var pos_x=0;
var pos_y=0;
var cur_html='';
var tempDiv;
function divPosition(event)
{

pos_x = event.offsetX?(event.offsetX):event.pageX-document.getElementById("tpr_top").offsetLeft;
pos_y = event.offsetY?(event.offsetY):event.pageY-document.getElementById("tpr_top").offsetTop;
}
function callCaption()
{
	var caption=show(290,600);
	var signUpDiv=document.getElementById("captionDiv");
	//alert(signUpDiv);
	caption.innerHTML=signUpDiv.innerHTML;
	cur_html = signUpDiv.innerHTML;
	signUpDiv.innerHTML = '';
		
	caption.style.border='1px solid #bfbfbf' ;
	caption.style.padding='5px';
	caption.style.background='#69a9d5';	
	caption.style.overflow='hidden';
	//compact("dd");
}
function signIn()
{
	var caption=show(320,600);
	var signInDiv=document.getElementById("login_pd");
	//alert(signUpDiv);
	caption.innerHTML=signInDiv.innerHTML;
	caption.style.border='1px solid #bfbfbf' ;
	caption.style.padding='5px';
	caption.style.background='#EAEAEA';	
	caption.style.overflow='hidden';
	//document.getElementById('testId').innerHTML='';
	tempDiv=caption;
	if(tempDiv)
	{
		var a=tempDiv.getElementsByTagName('div');		
		if(a.length>0)
		{
		a[1].innerHTML='';
		}
	}
	
	//caption.setAttribute("barek","signInNew");
	
	//compact("dd");
}
function loading_login(node)
{
	var a=tempDiv.getElementsByTagName('div');    
    a[1].innerHTML=document.getElementById('login_loading_img').innerHTML;	
}
function showAgain()
{
	var status=document.getElementById("login_status").value;
	var redirect_to=document.getElementById("login_redirect_to").value;
	if(status=='0')//pass or id did not matched
	{
	document.getElementById('div_login_status').innerHTML='Login Failed !';
	document.getElementById('div_login_status').style.display='block';
	tempDiv.innerHTML=document.getElementById("login_pd").innerHTML;
	}
	else//pass or id did not matched
	{		
	 //alert(redirect_to.substr(0,redirect_to.length-1));
	 if(navigator.appName.indexOf('Microsoft')==0)
	 location.href=redirect_to.substr(0,redirect_to.length-1);	
	 else location.href=redirect_to;
	}

	//alert('ppp');
}

function hide()
{	
	var a = document.getElementById("hidden");
	var b = document.getElementById("hidden2");
	if(a != null)
	{
		document.body.removeChild(a);
	}
	if(b != null)
	{
		document.body.removeChild(b);		
	}
	if( cur_html > '')  
	document.getElementById('captionDiv').innerHTML = cur_html;
}
function show(width, height) {

	
	hide();
  	var newdiv = document.createElement("div");
	//var newdiv3 = document.createElement("frame");
  	var divIdName = "hidden";
  	newdiv.setAttribute("id",divIdName);
	//newdiv.setAttribute("class","select-free");
	newdiv.style.width = document.body.clientWidth;
	newdiv.style.height = document.body.clientHeight;
	newdiv.onmousedown = down;
	newdiv.style.cursor = "move";
	//newdiv.innerHTML = "<div id='itemRight'><b>x</b></div>";
	document.onmouseup = up;
	document.onmousemove = movePosition;
	var newdiv2 = document.createElement("div");
	newdiv2.setAttribute("id","hidden2");

	newdiv2.style.width = width;
	//newdiv2.style.height = height;
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

//var x=document.getElementById("tpr_top").style.top;
//var y=document.getElementById("tpr_top").style.left;

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	newdiv2.style.top =20;
	newdiv2.style.left = 500;

	version=0
	if (navigator.appVersion.indexOf("MSIE")!=-1){
	temp=navigator.appVersion.split("MSIE");
	version=parseFloat(temp[1]);
	}

	if (version>=5.5) //NON IE browser will return 0
	{
		newdiv.style.width = width;
		newdiv.innerHTML = '<div id="itemRight"></div><iframe style="position:absolute;top:20;" width="'+width+'" height="'+(height-30)+'"></iframe>';
	}else
	{
		newdiv.style.width = width+6;
		newdiv.innerHTML = '<div id="itemRight"></div>';
	}
	
	newdiv.style.height = height;
	newdiv.style.top = ((document.body.clientHeight-(height+30))/2) + document.body.scrollTop;
	newdiv.style.left = (document.body.clientWidth-(width))/2;
	document.body.appendChild(newdiv2);
  	//newdiv.appendChild(newdiv3);
	//document.body.appendChild(newdiv);	
	return newdiv2;
}
function compact(a)
{
	
	var b = document.getElementById("hidden2");
	var d = document.getElementById("hidden");
	var c = document.getElementById(a);
	if(b != null && c != null && d != null)
	{
		
		b.style.overflow = "hidden";
		b.style.height = c.style.height;
		
		if(parseInt(b.clientHeight) > 450)
		{
			b.style.overflow = "auto";
			b.style.height = 450;
			d.style.top = ((document.body.clientHeight-(450+30))/2) + document.body.scrollTop;
			b.style.top = ((document.body.clientHeight-450)/2) + document.body.scrollTop;
			d.style.height = parseInt(b.style.height)+15;
		
			var i = d.getElementsByTagName("iframe");
			if(i[0])
			{
				i[0].setAttribute("height",parseInt(b.style.height)-6);
			}
		}else
		{
			b.style.overflow = "visible";
			b.style.height = parseInt(b.clientHeight)+15;
			d.style.height = parseInt(b.style.height)+15;
		
			var i = d.getElementsByTagName("iframe");
			if(i[0])
			{
				i[0].setAttribute("height",parseInt(b.style.height)-15);
				i[0].height = parseInt(b.style.height)-15;
			}else
			{
			}
		}		
	}
}

var move = false;
function down()
{	
	move = true;
	document.body.style.cursor = "move";
}
function up()
{	
	move = false;
	document.body.style.cursor = "default";
}
var oldX = 0;
var oldY = 0;
function movePosition(e)
{
	var x, y;
  		if (window.event) {
  		  x = window.event.clientX;
  		  y = window.event.clientY;
 		 } else {
 		   x = e.pageX;
 		   y = e.pageY;
		  }
	x = parseInt(x);
	y = parseInt(y);
	if(move)
	{
		
		difX = x - oldX;
		difY = y - oldY;
		
		oldX = x;
		oldY = y;

		var newdiv = document.getElementById("hidden");
		var newdiv2 = document.getElementById("hidden2");
		
		newdiv.style.left = parseInt(newdiv.style.left) + difX;
		newdiv.style.top = parseInt(newdiv.style.top) + difY;
		newdiv2.style.left = parseInt(newdiv2.style.left) + difX;
		newdiv2.style.top = parseInt(newdiv2.style.top) + difY;
		return false;
	}else
	{
		oldX = x;
		oldY = y;
	}
}