// Copyright (C) 2005-2008 Ilya S. Lyubinskiy. All rights reserved.
// Technical support: http://www.php-development.ru/
//
// YOU MAY NOT
// (1) Remove or modify this copyright notice.
// (2) Re-distribute this code or any part of it.
//     Instead, you may link to the homepage of this code:
//     http://www.php-development.ru/javascripts/popup-window.php
//
// YOU MAY
// (1) Use this code on your website.
// (2) Use this code as part of another product.
//
// NO WARRANTY
// This code is provided "as is" without warranty of any kind.
// You expressly acknowledge and agree that use of this code is at your own risk.

// USAGE
//
// function popup_show(id, drag_id, exit_id, position, x, y, position_id)
//
// id          - id of a popup window;
// drag_id     - id of an element within popup window intended for dragging it
// exit_id     - id of an element within popup window intended for hiding it
// position    - positioning type:
//               "element", "element-right", "element-bottom", "mouse",
//               "screen-top-left", "screen-center", "screen-bottom-right"
// x, y        - offset
// position_id - id of an element relative to which popup window will be positioned
// ***** Variables *************************************************************

var popup_dragging = false;
var popup_target;
var popup_mouseX;
var popup_mouseY;
var popup_mouseposX;
var popup_mouseposY;
var popup_oldfunction;

// ***** popup_mousedown_window ************************************************

function popup_mousedown_window(e)
{
  var ie = navigator.appName == "Microsoft Internet Explorer";

  if ( ie && window.event.button != 1) return;
  if (!ie && e.button            != 0) return;

  popup_dragging = true;
  popup_target   = this['target'];
  popup_mouseX   = ie ? window.event.clientX : e.clientX;
  popup_mouseY   = ie ? window.event.clientY : e.clientY;

  if (ie)
       popup_oldfunction = document.onselectstart;
  else popup_oldfunction = document.onmousedown;

  if (ie)
       document.onselectstart = new Function("return false;");
  else document.onmousedown   = new Function("return false;");
}


// ***** popup_show ************************************************************

function popup_show()
{
	
  var element = document.getElementById('popup');
  var position = "screen-center";
  var x = 0;
  var y= 0;
  

  var width        = window.innerWidth  ? window.innerWidth  : document.documentElement.clientWidth;
  var height       = window.innerHeight ? window.innerHeight : document.documentElement.clientHeight;
  
  element.style.position = "absolute";
  element.style.display  = "block";
  document.getElementById('overlay').style.display = "block";
  $('user').focus();

  if (position == "screen-center")
  {
    element.style.left = (document.documentElement.scrollLeft+(width -element.clientWidth )/2+x)+'px';
    element.style.top  = (document.documentElement.scrollTop +(height-element.clientHeight)/2+y)+'px';
  }
}

function sumbit()
{
	var url = '/brokerAdmin/validateBrokerAdmin.php';
	var queryString = "uid=" + $('user').value + "&pass=" + escape($('password').value);
	ajaxRequest(url,queryString,
	responseLogin = function(originalRequest)
	{
		var response = originalRequest.responseText;
		if(response==0)
		{
			$('user').focus();
			$('user').value = "";
			$('password').value = "";
			alert('Incorrect login information');
		}
		else
		{
			if(tabValue=="interoTube") /* tabValue which is global in ajaxXML.js*/
				window.location.href="/video/index.php?tab=interoTube"; 
			else
				window.location.href="/video/index.php"; 
		}
	},false
	);
}

function cancel()
{
	document.getElementById('popup').style.display = "none";
	document.getElementById('overlay').style.display = "none";
}

function LoginEnter(event)
{
	if(event && event.keyCode == 13)
	{
		sumbit();
	}
	else if(event && event.keyCode == 27)
	{
		cancel();
	}
}

