﻿    // ConfirmBoXMS V1.0 081219
    //     
    // The magic Confirmbox
    // Created By: Morgan Sundin aKa Windmiller
    //
    // This one is also dedicated to my life so please don't snatch it!
    //
        
	function ConfirmBoXMS(){
	
	//////////////////////////////////
	//Here's the private part for
	//the dragable confirm box.
	var tempX = 0;
	var tempY = 0;
	var drag = false;
	var confirmed = 0;
	var boxIs = false;
	var timeoutID = null;
	var IE = document.all?true:false;
	if (!IE)
		document.captureEvents(Event.MOUSEMOVE)

	document.onmousemove = getMouseXY;

	  function getMouseXY(e) {
		if (IE) 
		{ // grab the x-y pos.s if browser is IE

            var iebody=(document.compatMode && document.compatMode != "BackCompat")? document.documentElement : document.body
            var dsocleft=document.all? iebody.scrollLeft : pageXOffset
            var dsoctop=document.all? iebody.scrollTop : pageYOffset

            if (document.all||document.getElementById)
            {
                tempX = event.clientX + dsocleft;
                tempY = event.clientY + dsoctop;
            }
        }
		else {  // grab the x-y pos.s if browser is NS/FF
		 tempX = e.pageX;
		 tempY = e.pageY;
	   }
	   if (tempX < 0){tempX = 0;}
	   if (tempY < 0){tempY = 0;}
	  
	   if(drag)
	   {
		 document.getElementById('the_confirm_box').style.left = (tempX-150) + 'px';//-150;
		 document.getElementById('the_confirm_box').style.top = (tempY-12) + 'px';//-12;
		}
	   return true;
	  }

	  function startDragBox(e){
		drag = true;
		return false; //FF, same as for IE!
	  }
	  function quitDragBox(e){
		drag = false;
		return false;
	  }
	  function removeBox(){
	 
		var host = document.getElementsByTagName('BODY');
		if(host!=null)
		 host[0].removeChild(document.getElementById('the_confirm_box'));
	  }
	  function confirmNo(){
	 
	    disableSelection(document.body, true);
		removeBox(); 
		confirmed = 1;
	  }
	  function confirmYes(e){
	 
	    disableSelection(document.body, true);
		removeBox();
		confirmed = 2;
	  }
	  
	  function confirmBox(msg, boxTitle){
	  	  
	  //Disable select, to make it look good when draging it.
      disableSelection(document.body, false);
   
	   //The confirm box.
	   var box = document.createElement('DIV');
	   box.id = 'the_confirm_box';
	   box.style.zOrder = '9999';
	   box.style.position = 'absolute';
	   box.style.border = 'solid 1px #000000';
	   box.style.background = '#ffffff';	   
	   box.style.width = '300px';
	   box.style.top = '20px';
	   box.style.left = '20px';
	   	   
		//The titlebar of the window, is dragable!!
	   var title = document.createElement('DIV');
	   title.style.background = 'url(../Img/confirmbox/title_bar4.jpg)';
	   title.id = 'the_confirm_title';
	   title.style.position = 'relative';
	   title.style.textAlign = 'center';
	   title.style.width = '100%';
	   title.style.height = '24px';  
	   //title.style.background = '#bbbbbb';
	   title.onmousedown = startDragBox;
	   title.onmouseup = quitDragBox;	   
	  
		//The titlebar text.
	   var title_text = document.createElement('DIV');
	   title_text.innerHTML = '\<\< '+(boxTitle==null||boxTitle=='' ? 'MOVABLE BOX' : boxTitle)+' \>\>';
	   title_text.style.fontFamily = 'arial, sans-serif';
	   title_text.style.color = '#eee';
	   title_text.style.fontSize = '9px';  
	   title_text.style.padding = '2px';
	   title_text.style.cursor = 'default';
	   	   
		//The message in the dragable confirm window
	   var message = document.createElement('DIV');
	   message.id = 'the_confirm_message';
	   message.style.fontFamily = 'arial, sans-serif';
	   message.style.fontSize = '10px';
	   message.style.position = 'relative';
	   message.style.padding = '10px';
	   message.innerHTML = msg;
	   
	   //Image holder
	   var image_div = document.createElement('DIV');
	   image_div.style.width = '100%';
	   image_div.style.paddingBottom = '20px';	   
	   image_div.style.textAlign = 'center';
	  
	   //Ok image in the image holder
	   var ok = document.createElement('BUTTON');
	   //ok.src = '../Img/icons/msgbox_1.png';
	   ok.id = 'the_confirm_ok_image';	   
	   ok.innerHTML = 'JA';
	   ok.style.fontSize = '11px';
	   ok.onclick = confirmYes;
	   ok.setAttribute('onmouseover','javascript:document.getElementById(\''+ok.id+'\').style.cursor = \'pointer\';');
	  
	   //No image for the image holder
	   var no = document.createElement('BUTTON');	   
	   no.id = 'the_confirm_no_image';
	   no.innerHTML = 'NEJ';	  
	   no.style.fontSize = '11px'; 
	   no.onclick = confirmNo;
	   no.setAttribute('onmouseover','javascript:document.getElementById(\''+no.id+'\').style.cursor = \'pointer\';');
	 
	   //Connect them
	   title.appendChild(title_text);
	  
	   image_div.appendChild(ok);
	   image_div.appendChild(no);
	  
	   var host = document.getElementsByTagName('BODY');
	   box.appendChild(title);
	   box.appendChild(message);
	   box.appendChild(image_div);
	  
	   //Append/connect to the site
	   host[0].appendChild(box);

        if (document.all||document.getElementById||document.layers){
	   
	        var iebody=(document.compatMode && document.compatMode != "BackCompat")? document.documentElement : document.body
            var dsocleft=document.all? iebody.scrollLeft : pageXOffset
            var dsoctop=document.all? iebody.scrollTop : pageYOffset
       
	   	    box.style.left = ((iebody.clientWidth/2)-(box.offsetWidth/2)) + dsocleft + 'px';
		    box.style.top = ((iebody.clientHeight/3)-(box.offsetHeight/2)) + dsoctop + 'px';
	    }
	  }
	  ConfirmBoXMS.prototype.Show = function(confirm_message, okFunction, cancelFunction, boxTitle)
	  {
		ConfirmBoXMS.Show(confirm_message, okFunction,cancelFunction, boxTitle);
	  }
	  
	  ConfirmBoXMS.Show = function(confirm_message, okFunction, cancelFunction, boxTitle){
		
		if(!boxIs){
			confirmBox(confirm_message, boxTitle);
			boxIs = true;
		}
		window.clearTimeout(timeoutID);

			if(confirmed==0)
				timeoutID = window.setTimeout('ConfirmBoXMS.Show(\''+confirm_message+'\',\''+okFunction+'\',\''+cancelFunction+'\',\''+boxTitle+'\');', 200);    //Loop
			else if(confirmed==1){
				confirmed = 0;
				boxIs = false;
				
				eval(cancelFunction);
				
				return false;
			}
			else if(confirmed==2){
					
				boxIs = false;
				confirmed = 0;
				
				eval(okFunction);
				
				return true;
			}    
	  }
	  function disableSelection(target, enable){
            if(typeof target.onselectstart!="undefined")
	            target.onselectstart = function(){return enable;}
            else if(typeof target.style.MozUserSelect!="undefined")
	            target.style.MozUserSelect=enable?"":"none";
            else
	            target.onmousedown=function(){return enable;}
	   
            target.style.cursor = "default"
      }

  }
