
DCSDialog = new Object();
DCSDialog.isConfOpen = false;
DCSDialog.imagePath="/images/";//relative to this js file if this file is being included in the normal way
DCSDialog.confFlashIndicator="off";
DCSDialog.DCSInterval="";
DCSDialog.extra_Top=0;
DCSDialog.extra_Left=0;
DCSDialog.saveCurrentConfParams=false;
DCSDialog.currentConfParams = new Array();
DCSDialog.currentFX = "";

DCSDialog.OKConfirmation = function(words,code,text,size,title,img,fx)
{
 try
 {
  if(!title)
  {
   title = "Confirmation";
  }
  if(code.indexOf("SELF_CLOSE") > -1)
  { 
   code = DCSDialog.replaceAll(code,"SELF_CLOSE","DCSDialog.closeConf();");
  }
  buttons = "<input class='Mybutton' type='submit' id='okConfButton' value='"+text+"' onclick='"+code+"' />";
  DCSDialog.centerObjectOnPage(words,title,buttons,size,img,'okConfButton',fx);
  DCSDialog.isConfOpen=true;
 }catch(e)
 {
  alert(e.message + " in DCSDialog.OKConfirmation");
  return false;
 }
}
DCSDialog.yesNoConfirmation = function(words,pos,neg,pos_t,neg_t,size,title,img,fx) 
{
	//words = content | 
	//pos = code to execute on first button | 
	//neg = second button | 
	//pos_t is text of fiorst button | 
	//neg_t = second text for button
	//size = small medium large landscape skyscraper interface_small interface_medium
	//img = 1 - 5 Integer (icons showned in top left hand corner)
 try
 {
  if(!title)
  {
   title = "Respond";
  }
  if(neg.indexOf("SELF_CLOSE") > -1)
  { 
   neg = DCSDialog.replaceAll(neg,"SELF_CLOSE","DCSDialog.closeConf();");
  }
  if(pos.indexOf("SELF_CLOSE") > -1)
  { 
   pos = DCSDialog.replaceAll(pos,"SELF_CLOSE","DCSDialog.closeConf();");
  }
  buttons = "<input class='Mybutton' type='submit' id='yesConfButton' value='"+pos_t+"' onclick='"+pos+"' /> &nbsp; <input class='Mybutton' type='submit' id='noConfButton' value='"+neg_t+"' onclick='"+neg+"' />";
  DCSDialog.centerObjectOnPage(words,title,buttons,size,img,'yesConfButton',fx);
  DCSDialog.isConfOpen=true;
 }catch(e)
 {
  alert(e.message + " in DCSDialog.yesNoConfirmation");
  return false;
 }
}

DCSDialog.closeConf = function()
{
 try
 {
  DCSDialog.unmakeWindowModelMode();
  if(DCSDialog.$("DCSConfBox"))
  DCSDialog.$("DCSConfBox").parentNode.removeChild(DCSDialog.$("DCSConfBox"));
  DCSDialog.isConfOpen=false;
  window.clearInterval(DCSDialog.DCSInterval);
  return 0;
 }catch(e)
 {
  alert(e.message + " in DCSDialog.closeConf");
  return false;
 }
}

DCSDialog.unmakeWindowModelMode = function(removeChildren)
{ 
 try
 {
  if(DCSDialog.$("invisModalTable"))
  {
   DCSDialog.$("invisModalTable").parentNode.removeChild(DCSDialog.$("invisModalTable"));
  }
 
  if(DCSDialog.$("invisModal"))
  {
   DCSDialog.$("invisModal").parentNode.removeChild(DCSDialog.$("invisModal"));
  }
  DCSDialog.unhookEvent('invisModalTable', 'mousewheel', DCSDialog.cancelEvent);//attach the mouse wheel event tot he table and cancel it
 }catch(e)
 {
  alert(e.message + " in DCSDialog.unmakeWindowModelMode");
  return false;
 }
}

DCSDialog.showPreviouseConf=function()
{
 try
 {
  DCSDialog.centerObjectOnPage(DCSDialog.currentConfParams["words"],DCSDialog.currentConfParams["title"],DCSDialog.currentConfParams["buttons"],DCSDialog.currentConfParams["size"],DCSDialog.currentConfParams["img"],DCSDialog.currentConfParams["idforinitfocus"]);
 }catch(e)
 {
  alert(e.message + " in DCSDialog.showPreviouseConf");
  return false;
 }
}

DCSDialog.centerObjectOnPage=function(words,title,buttons,size,img,idforinitfocus,fx)
{
 try
 {
  try
  {
   //close any open tooltips
   UnTip();
  }catch(e)
  {
   //no need to flag, just means tooltip script is not avaliable
  }
  //if(DCSDialog.saveCurrentConfParams==true)
  //{
   DCSDialog.currentConfParams["words"]=words;
   DCSDialog.currentConfParams["title"]=title;
   DCSDialog.currentConfParams["buttons"]=buttons;
   DCSDialog.currentConfParams["size"]=size;
   DCSDialog.currentConfParams["img"]=img;
   DCSDialog.currentConfParams["idforinitfocus"]=idforinitfocus;
   DCSDialog.currentConfParams["fx"]=fx;
   DCSDialog.saveCurrentConfParams = false;
  //}
  fx=DCSDialog.$get(fx,"");
  DCSDialog.currentFX = fx;
  if(DCSDialog.isConfOpen==true)DCSDialog.closeConf();//close any open confirmations
  img = DCSDialog.getConfImage(img);
  
  DCSDialog.makeWindowModelMode(true);
  words = "<div id='tempdivholderconf'style='filter:Alpha(opacity=100);'><table id='confBoxInner' class='DCSConfBoxTop' cellpadding='3' cellspacing='0' onMouseDown='DCSDialog.drag(this.parentNode.parentNode,event);'><tr valign='middle'><td class='DCSConfBoxTitle' id='confIconId'><img src='"+img+"' /></td><td class='DCSConfBoxTitle' id='confTitleId' width='99%'>"+title+"</td></tr></table><table id='confBoxInnerLower' class='DCSConfBoxBottom' cellpadding='3' cellspacing='0' ><tr><td class='DCSConfBoxBody' id='confBoxBody'>"+words+"</td></tr><tr><td class='DCSConfBoxButtons'>"+buttons+"</td></tr></table></div>";
  
  el = document.createElement("div");
  el.innerHTML = words;
  el.style.position = 'absolute';
  el.id="DCSConfBox";
  window.onresize=DCSDialog.makeWindowModelMode;
  document.body.appendChild(el);
  var w=0;
  var h=0;
  if(size.indexOf("/")>-1)
  {
   size=size.split("/");
   w=size[0];
   h=size[1];
   size="specified";
  }
  switch(size)
  {
   case "specified":   DCSDialog.$("tempdivholderconf").style.width=w;DCSDialog.$("confBoxInner").style.width=w;DCSDialog.$("confBoxInnerLower").style.width=w;DCSDialog.$("confBoxBody").style.height=h;break;
   case "small":   DCSDialog.$("tempdivholderconf").style.width=300;DCSDialog.$("confBoxInner").style.width=300;DCSDialog.$("confBoxBody").style.height=100;;break;
   case "medium":   DCSDialog.$("tempdivholderconf").style.width=400;DCSDialog.$("confBoxInner").style.width=400;DCSDialog.$("confBoxInnerLower").style.width=400;DCSDialog.$("confBoxBody").style.height=400;break;
   case "dcsdia":   DCSDialog.$("tempdivholderconf").style.width=500;DCSDialog.$("confBoxInner").style.width=500;DCSDialog.$("confBoxInnerLower").style.width=500;DCSDialog.$("confBoxBody").style.height=100;break;
   case "large":   DCSDialog.$("tempdivholderconf").style.width=500;DCSDialog.$("confBoxInner").style.width=500;DCSDialog.$("confBoxInnerLower").style.width=500;DCSDialog.$("confBoxBody").style.height=500;break;
   case "landscape":  DCSDialog.$("tempdivholderconf").style.width=800;DCSDialog.$("confBoxInner").style.width=800;DCSDialog.$("confBoxInnerLower").style.width=800;DCSDialog.$("confBoxBody").style.height=100;break;
   case "skyscraper":  DCSDialog.$("tempdivholderconf").style.width=200;DCSDialog.$("confBoxInner").style.width=200;DCSDialog.$("confBoxInnerLower").style.width=200;DCSDialog.$("confBoxBody").style.height=550;break;
   case "interface_small": DCSDialog.$("tempdivholderconf").style.width=370;DCSDialog.$("confBoxInner").style.width=370;DCSDialog.$("confBoxInnerLower").style.width=370;DCSDialog.$("confBoxBody").style.textAlign="left";break;
   case "interface_medium":DCSDialog.$("tempdivholderconf").style.width=400;DCSDialog.$("confBoxInner").style.width=400;DCSDialog.$("confBoxInnerLower").style.width=400;DCSDialog.$("confBoxBody").style.height=400;DCSDialog.$("confBoxBody").style.textAlign="left";break;
  }
  var topOffset = Math.max(document.body.scrollTop,document.documentElement.scrollTop);
  var leftOffset = Math.max(document.body.scrollLeft,document.documentElement.scrollLeft);
  var brSize = DCSDialog.getBrowserSize();
  var bodyWidth = brSize[0];
  var bodyHeight = brSize[1];
  var tmpWidth = el.offsetWidth; 
  var tmpHeight = el.offsetHeight;
  el.style.left = (Math.ceil((bodyWidth - tmpWidth) / 2) + leftOffset)+ 'px';
  el.style.top = (Math.ceil((bodyHeight - tmpHeight) / 2) +  topOffset) + 'px';
  el.zIndex = 999999;
  //DCSDialog.DCSInterval = window.setInterval("DCSDialog.centerConf()","10");
  DCSDialog.$(idforinitfocus).focus();//set focus to the first button so user can press space bar or return..
 }catch(e)
 {
  alert(e.message + " in DCSDialog.centerObjectOnPage");
  return false;
 }
}

DCSDialog.centerConf=function()
{
 try
 {
  el = DCSDialog.$("DCSConfBox");
  var topOffset = Math.max(document.body.scrollTop,document.documentElement.scrollTop);
  var brSize = DCSDialog.getBrowserSize();
  var bodyWidth = brSize[0];
  var bodyHeight = brSize[1];
  var tmpWidth = el.offsetWidth; 
  var tmpHeight = el.offsetHeight;
  //el.style.left = DCSDialog.extra_Left + tmpWidth+ 'px';
  //el.style.top = DCSDialog.extra_Top + tmpHeight + 'px';
  el.style.left = Math.ceil((bodyWidth - tmpWidth) / 2) + (DCSDialog.extra_Left / 2)+ 'px';
  el.style.top = (Math.ceil((bodyHeight - tmpHeight) / 2) + (DCSDialog.extra_Top / 2)+  topOffset) + 'px';
 }catch(e)
 {
  alert(e.message + " in DCSDialog.centerConf");
  return false;
 }
}

DCSDialog.makeWindowModelMode=function(run)
{
	try
	{
		if(typeof(run)=="undefined")
		{
			run=false;
		}
		if(DCSDialog.isConfOpen==true)
		{
			var testLayer=document.getElementById("invisModal");
			testLayer.style.width="100%";
			testLayer.style.height="100%";
			var topOffset = Math.max(document.body.scrollTop,document.documentElement.scrollTop);
			var leftOffset = Math.max(document.body.scrollLeft,document.documentElement.scrollLeft);
			var brSize = DCSDialog.getBrowserSize();
			var bodyWidth = brSize[0];
			var bodyHeight = brSize[1];
			var tDCSConfBox=document.getElementById("DCSConfBox");
			var tmpWidth = tDCSConfBox.offsetWidth; 
			var tmpHeight = tDCSConfBox.offsetHeight;
			tDCSConfBox.style.left = (Math.ceil((bodyWidth - tmpWidth) / 2) + leftOffset)+ 'px';
			tDCSConfBox.style.top = (Math.ceil((bodyHeight - tmpHeight) / 2) +  topOffset) + 'px';
			return;
		}
		if(run==false)return;
		var brSize = DCSDialog.getBrowserSize();
		var bodyWidth = brSize[0];
		var bodyHeight = brSize[1];
		var width = bodyWidth+"px";//ok for ie
		if(self.innerHeight)
		{
		width = "100%";//ok for ie
		}
		var hidspan=document.createElement("div");
		hidspan.id="invisModal";
		hidspan.onclick=new Function("DCSDialog.flashConf();");
		hidspan.zIndex = 1000;
		firstChildOfDoc=document.getElementsByTagName("body");
		hidspan.style.backgroundColor="black";
		try
		{
		hidspan.style.opacity = (0 / 100);
		hidspan.style.MozOpacity = (0 / 100);
		hidspan.style.KhtmlOpacity = (0 / 100);
		hidspan.style.filter = "alpha(opacity=" + 20 + ")";
		}
		catch (e)
		{
		}
		firstChildOfDoc[0].appendChild(hidspan);
		hidspan.style.position="absolute";
		hidspan.style.top="0px";
		hidspan.style.left="0px";
		hidspan.className="DCSHidspan";
		hidspan.style.width=document.body.scrollWidth + "px";
		hidspan.style.height=document.body.scrollHeight + "px";
		DCSDialog.hookEvent('invisModalTable', 'mousewheel', DCSDialog.cancelEvent);//attach the mouse wheel event to the table and cancel it
	}catch(e)
	{
		alert(e.message + " in DCSDialog.makeWindowModelMode");
		return false;
	}
}

DCSDialog.getConfImage = function(i)
{
 try
 {
  if(typeof(i)=="undefined" || i=="")i=1;
  /*
   1 = Alert
   2 = Info
   3 = Error
   4 = Key
   5 = Lock
  */
  try
  {
   i = parseInt(i);
  }
  catch (e)
  {
   return DCSDialog.imagePath + "alert.gif";
  }
  switch(i)
  {
   case 1: case "1":return DCSDialog.imagePath + "alert.gif";break;
   case 2: case "2":return DCSDialog.imagePath + "info.gif";break;
   case 3: case "3":return DCSDialog.imagePath + "error.gif";break;
   case 4: case "4":return DCSDialog.imagePath + "key.gif";break;
   case 5: case "5":return DCSDialog.imagePath + "lock.gif";break;
  }
  return DCSDialog.imagePath + "alert.gif";
 }catch(e)
 {
  alert(e.message + " in DCSDialog.getConfImage");
  return false;
 }
}

DCSDialog.flashConf = function()
{
 try
 {
  setTimeout("DCSDialog.flashHelper(0)",1);
  DCSDialog.$(DCSDialog.currentConfParams["idforinitfocus"]).focus();//reset focus to first button
 }catch(e)
 {
  alert(e.message + " in DCSDialog.flashConf");
  return false;
 }
}

DCSDialog.flashHelper = function(times)
{
 try
 {
  times++;
  if(times<7)
  {
   if(DCSDialog.confFlashIndicator=="off")
   {
    DCSDialog.confFlashIndicator="on";
    if(DCSDialog.$("confTitleId"))
    {
     DCSDialog.className(DCSDialog.$("confTitleId"),"DCSConfBoxTitleFlashOn",true);
     DCSDialog.className(DCSDialog.$("confIconId"),"DCSConfBoxTitleFlashOn",true);
    }
   }else{
    DCSDialog.confFlashIndicator="off";
    if(DCSDialog.$("confTitleId"))
    {
     DCSDialog.className(DCSDialog.$("confTitleId"),"DCSConfBoxTitleFlashOn",false);
     DCSDialog.className(DCSDialog.$("confIconId"),"DCSConfBoxTitleFlashOn",false);
    }
   }
  setTimeout("DCSDialog.flashHelper("+times+")",80);
 }
 }catch(e)
 {
  alert(e.message + " in DCSDialog.flashHelper");
  return false;
 }
}
DCSDialog.drag = function(elementToDrag,event)
{
 try
 {
  var brSize = DCSDialog.getBrowserSize();
  var bodyWidth = brSize[0];
  var bodyHeight = brSize[1];
  
  var startX = event.clientX, startY=event.clientY;
  var origX = elementToDrag.offsetLeft, origY=elementToDrag.offsetTop;
  var dX = startX - origX; var dY = startY - origY;
  elementToDrag.setCapture();
  elementToDrag.attachEvent("onmousemove",moveHandler);
  elementToDrag.attachEvent("onmouseup",upHandler);
  elementToDrag.attachEvent("onlosecapture",upHandler);
  event.cancelBubble = true;
  event.returnValue = false;
  function moveHandler(e)
  {
   e=window.event;
   //Stop the alert being dragged of screen
   if((e.clientX - dX) < (bodyWidth - 100) && (e.clientX - dX) > 1)
   {
    elementToDrag.style.left = (e.clientX - dX) + "px";
    DCSDialog.extra_Left = (e.clientX - dX);
   }
   if((e.clientY - dY) < (bodyHeight - 100) && (e.clientY - dY) > 1)
   {
    elementToDrag.style.top = (e.clientY - dY) + "px"; 
    DCSDialog.extra_Top = (e.clientY - dY);
   }
   e. cancelBubble = true;
  }
  function upHandler(e)
  {
   e=window.event;   
   elementToDrag.detachEvent("onmousemove",moveHandler);
   elementToDrag.detachEvent("onmouseup",upHandler);
   elementToDrag.detachEvent("onlosecapture",upHandler);  
   elementToDrag.releaseCapture();
   e.cancelBubble = true; 
  }
 }
 catch (e)
 { alert(e.message)
 }
}

DCSDialog.replaceAll=function(str,from,to)
{ 
 try
 {
  var idx = str.indexOf( from ); while ( idx > -1 ) { str = str.replace( from, to ); idx = str.indexOf( from );}
  return str;
 }catch(e)
 {
  alert(e.message + " in _DCSDialog.replaceAll");
  return false;
 }
}

DCSDialog.$=function()
{
 try
 {
  var elements = new Array();
  for (var i = 0; i < arguments.length; i++)
  {
   var element = arguments[i];
   if (typeof element == 'string')
    try{element = document.getElementById(element);}catch(e){}
   if (arguments.length == 1)
    return element;
   elements.push(element);
  }
  return elements;
 }catch(e)
 {
  alert(e.message + " in _DCSDialog.(s) $");
  return false;
 }
}

DCSDialog.hookEvent = function(element, eventName, callback)
{
 try
 {
  if(typeof(element) == "string")
   element = document.getElementById(element);
  if(element == null)
   return;
  if(element.addEventListener)
  {
   if(eventName == 'mousewheel')
   {
    element.addEventListener('DOMMouseScroll', 
    callback, false);  
   }
   element.addEventListener(eventName, callback, false);
  }
  else if(element.attachEvent)
   element.attachEvent("on" + eventName, callback);
 }catch(e)
 {
  alert(e.message + " in _DCSDialog.hookEvent");
  return false;
 }
}

DCSDialog.unhookEvent = function(element, eventName, callback)
{
 try
 {
  if(typeof(element) == "string")
   element = document.getElementById(element);
  if(element == null)
   return;
  if(element.removeEventListener)
  {
   if(eventName == 'mousewheel')
   {
   element.removeEventListener('DOMMouseScroll', 
   callback, false);  
   }
   element.removeEventListener(eventName, callback, false);
  }
  else if(element.detachEvent)
   element.detachEvent("on" + eventName, callback);
 }catch(e)
 {
  alert(e.message + " in _DCSDialog.unhookEvent");
  return false;
 }
}

DCSDialog.$get = function(v,d)
{
 if(typeof(v)=="undefined" || v=="")v="";
 if(typeof(d)=="undefined" || d=="")return v;
 return d;
}


DCSDialog.getBrowserSize = function()
{
 try
 {
  var bodyWidth = document.documentElement.clientWidth;
  var bodyHeight = document.documentElement.clientHeight;
  
  var bodyWidth, bodyHeight; 
  if (self.innerHeight){ // all except Explorer 
   
     bodyWidth = self.innerWidth; 
     bodyHeight = self.innerHeight; 
  }  else if (document.documentElement && document.documentElement.clientHeight) {
     // Explorer 6 Strict Mode    
     bodyWidth = document.documentElement.clientWidth; 
     bodyHeight = document.documentElement.clientHeight; 
  } else if (document.body) {// other Explorers    
     bodyWidth = document.body.clientWidth; 
     bodyHeight = document.body.clientHeight; 
  } 
  return [bodyWidth,bodyHeight];  
 }catch(e)
 {
  alert(e.message + " in _DCSDialog.getBrowserSize");
  return false;
 }
}



DCSDialog.className = function(el,className,bool)
{
 try
 {
  var cn=el.className;
  if(bool==true)
  {
   if(typeof(cn)=="undefined" || cn=="")
   {
    el.className=className;
   }else{
    el.className=DCSDialog.trim(cn + " " +className);
   }
  }else{
   cn=" "+cn+" ";
   cn=this.replaceAll(cn," "+className+" "," ");
   el.className=DCSDialog.trim(cn);
  }
 }catch(e)
 {
  alert(e.message + " in _DCSDialog.className");
  return false;
 }
}

DCSDialog.trim=function(value)
{
 try
 {
 function LTrim( value )
 {
  var re = /\s*((\S+\s*)*)/;
  return value.replace(re, "$1");
 }
 function RTrim( value )
 {
  var re = /((\s*\S+)*)\s*/;
  return value.replace(re, "$1");
 }
 return LTrim(RTrim(value));
 }catch(e)
 {
 alert(e.message + " in _DCSDialog.trim");
 return false;
 }
}
///</FILE>
