
var posX;
var posY;

var sizeY;
var sizeX;


function keyPressHandler(e) {

      var kC  = (window.event) ?    // MSIE or Firefox?
                 event.keyCode : e.keyCode;
      var Esc = (window.event) ?   
                27 : e.DOM_VK_ESCAPE // MSIE : Firefox
      if(kC==Esc){
		document.body.focus();
      	return closevWinBtn();
      	
      }
   }
   
   
  function closevWinBtn(){
  	
  	       
	if(document.getElementById('vwinoncloseaction') && document.getElementById('vwinoncloseaction').value && confirm('Save changes?')){
		
			document.getElementById('vwinoncloseaction').value = '';
			if(document.getElementById("requestbtn"))
			return submitForm(document.neworderform, 'mainContent', '', true);
			else
			return submitForm(document.neworderform, 'submit_form_status', '&checkvans=1');	
	}else
	  closevWin();
  	
  }

function getPosition(e) {
    e = e || window.event;
    var cursor = {x:0, y:0};
    if (e.pageX || e.pageY) {
        cursor.x = e.pageX;
        cursor.y = e.pageY;
    } 
    else {
        var de = document.documentElement;
        var b = document.body;
        cursor.x = e.clientX + 
            (de.scrollLeft || b.scrollLeft) - (de.clientLeft || 0);
        cursor.y = e.clientY + 
            (de.scrollTop || b.scrollTop) - (de.clientTop || 0);
    }
    posX = cursor.x;
    posY = cursor.y;
    
    	if(mcofX){
	$("vWin").style.left = (posX - mcofX) + "px";
	$("vWin").style.top = (posY - 8) + "px";

	if(posX - mcofX < 0)
	$("vWin").style.left = "0px";
	
	if(posY - 8 < 0)
	$("vWin").style.top = "0px";
    	
    	}
    
}

if (document.layers) document.captureEvents(Event.MOUSEMOVE);
document.onmousemove=getPosition;

function f_scrollTop() {
	return f_filterResults (
		window.pageYOffset ? window.pageYOffset : 0,
		document.documentElement ? document.documentElement.scrollTop : 0,
		document.body ? document.body.scrollTop : 0
	);
}

function f_filterResults(n_win, n_docel, n_body) {
	var n_result = n_win ? n_win : 0;
	if (n_docel && (!n_result || (n_result > n_docel)))
		n_result = n_docel;
	return n_body && (!n_result || (n_result > n_body)) ? n_body : n_result;
}



function openvWin(url, width, height, vwintitle){
	
	
	
	if(!width) width = 350;
	if(!height) height = 200;
	
	closevWin();
	

	var bEla = document.createElement("div");
	
	bEla.id = 'alphabg';
	bEla.style.position = 'absolute';
	bEla.style.top = '0px';
	
	
	
	bEla.style.left = '0px';
	bEla.style.backgroundColor = 'black';
	
	if(document.getElementsByTagName('body')[0].scrollWidth)
	bEla.style.width = document.getElementsByTagName('body')[0].scrollWidth+"px";
	else bEla.style.width = '100%';
	
	
	if(document.getElementsByTagName('body')[0].scrollHeight < 600)
	bEla.style.height = "100%";
	else
	bEla.style.height = document.getElementsByTagName('body')[0].scrollHeight+"px";
	
	
	bEla.style.zIndex = '190';
	bEla.style.opacity = '0.7';
	bEla.style.filter = 'Alpha(opacity=70)';
	
	
	
	var bEl = document.createElement("div");
	
	var bElBar = document.createElement("div");
	
	if(vwintitle){
	bElBar.innerHTML = '<span>'+vwintitle+'</span>';
	}
	
	var bElContent = document.createElement("div");
	
	var bElBarXa = document.createElement("a");
	var bElBarX = document.createElement("img");
	
	var bodyEl = document.getElementsByTagName("body");
	
	bEl.setAttribute("id", "vWin");
	bElBar.setAttribute("id", "vWinBar");
	bElContent.setAttribute("id", "vWinContent");
	
	bElBarX.setAttribute("src", "/images/vwinclose.gif");
	bElBarX.setAttribute("border", "0");
	bElBarXa.setAttribute("href", "#close");
	bElBarXa.onclick = closevWinBtn;
	
	//bElBarX.innerHTML = 'x';
   
	bodyEl[0].appendChild(bEla);
	
	bElBarXa.appendChild(bElBarX);
	
	bElBar.appendChild(bElBarXa);

		if(vwintitle != '-hide-titlebar-')
	bEl.appendChild(bElBar);
	
  /*
  var nposX = posX;
  
  if(height >= posY)
	var nposY = posY+10;
  else
  	var nposY = posY-height-10;
  */
  if(width > 1000){
  	
  var nposY = document.body.scrollTop;
  var nposX = document.body.scrollLeft;
  }
  
  else{
  var nposY = document.body.scrollTop+100;
  var nposX = document.body.scrollLeft+100;
  }
  sizeY = height;
  sizeX = width;
  
   bEl.style.left = nposX+"px";
   bEl.style.top = nposY+"px";
   
   
	if(f_scrollTop())
	bEl.style.top = f_scrollTop()+"px";
   
   bEl.style.width = width+"px";
   bEl.style.height = height+"px";
   
   bElContent.style.width = (width-5)+"px";
   if(vwintitle != '-hide-titlebar-')
   bElContent.style.height = (height-14)+"px";
   else
   bElContent.style.height = (height)+"px";
   
   bElContent.innerHTML = '-';
   
	bEl.appendChild(bElContent);
   
	bodyEl[0].appendChild(bEl);
	
if(vwintitle != '-hide-titlebar-')	
$('vWinBar').onmousedown = vclicked;
//$('vWinBar').onmousemove = vstartmove;
document.onkeypress = keyPressHandler;
if(vwintitle != '-hide-titlebar-')
$('vWinBar').onmouseup = vunclicked;
if(vwintitle != '-hide-titlebar-')
$('vWinBar').ondblclick = resizevWin;



   if(vwintitle == '-hide-titlebar-')
   $('vWinContent').style.padding = '0';

if(url)
aGet(url, "vWinContent");
	return false;
}

function closevWin(){
	
	var bodyEl = document.getElementsByTagName("body");
	
	
	if(document.getElementById("vWin"))
	 
	bodyEl[0].removeChild(document.getElementById("vWin"));
	
	if(document.getElementById("alphabg"))
	 
	bodyEl[0].removeChild(document.getElementById("alphabg"));
	
		
}

var mcofX;
var mcofY;

function vclicked(){
	
	mcofX = posX - parseFloat($("vWin").style.left);
$('vWinBar').style.cursor = "move";
	
}
function vunclicked(){
	mcofX = '';
	mcofY = '';	
$('vWinBar').style.cursor = "default";
}
function vstartmove(){
	if(mcofX){
	$("vWin").style.left = (posX - mcofX) + "px";
	$("vWin").style.top = (posY - 8) + "px";

	
	}
}


function resizevWin(){
  
	var nposY = document.body.scrollTop;
  var nposX = document.body.scrollLeft;
  
  
  
	if($('vWin').style.width != "100%"){
				
  
  
   $('vWin').style.left = nposX+"px";
   $('vWin').style.top = nposY+"px";
   $('vWin').style.width = "100%";
   $('vWin').style.height = "100%";
   $('vWinContent').style.width = "100%";
   $('vWinContent').style.height = "100%";
   
   $('vWinContent').style.padding = "0";
		
		
	}
	else{
  
  
   $('vWin').style.left = (nposX+100)+"px";
   $('vWin').style.top = (nposY+100)+"px";
   $('vWin').style.width = sizeX+"px";
   $('vWin').style.height = sizeY+"px";
   $('vWinContent').style.width = (sizeX-5)+"px";
   $('vWinContent').style.height = (sizeY-14)+"px";
	}
	
}
