var ie4 = document.all&&navigator.userAgent.indexOf("Opera")==-1;
var ns6 = document.getElementById&&!document.all;
var ns4 = document.layers;

var setIntervalId = window.setInterval( "Sb1('DsRefresh')", 1700000 );

function preSubmit(){}

function Sb1(button) {
	preSubmit();
	document.forms[0].submitbutton.name=button+".x";
	document.forms[0].submit();
}

function Sb2(button) {
	var x,y;
	preSubmit();

	if(ie4) {
		x=document.body.scrollLeft;
		y=document.body.scrollTop;
	}
	else {
		x=window.pageXOffset;
		y=window.pageYOffset;
	}

	document.forms[0].submitbutton.name=button+"!@!"+x+"!@!"+y+".x";
	document.forms[0].submit();
}

function openPopup(e,topic,w,h) {
	if(ie4) {
		x=window.screenLeft-document.body.scrollLeft;
		y=window.screenTop-document.body.scrollTop+20;
	}
	else
	{
		x=window.screenX-window.pageXOffset;
		y=window.screenY-window.pageYOffset+42;
	}

	for(j=e; j; j=j.offsetParent)
		x+=j.offsetLeft;
	x=Math.min(x,screen.availWidth-w-18);

	for(j=e; j; j=j.offsetParent)
		y+=j.offsetTop;
	y=Math.min(y,screen.availHeight-h-36);
	
	window.open(topic,'','width='+w+',height='+h+',left='+x+',top='+y+',toolbar=0,location=0,directories=0,status=0,menuBar=0,scrollBars=1,resizable=1');
}

function openHelp(e,topic) {
	openPopup(e,'dscript?EXEC-'+sessionid+'-'+topic,425,300);
}

function showmenu(x,y,n,html) {
	if(!document.all&&!document.getElementById&&!document.layers)
		return false;

	clearhidemenu();

	menuobj = ie4 ? document.all.popmenu : ns6 ? document.getElementById("popmenu") : ns4 ? document.popmenu : "";
	menuobj.thestyle = (ie4||ns6) ? menuobj.style : menuobj;

	html = html.replace(/##/g,n);

	if(ie4||ns6) {
		menuobj.innerHTML = html;
	}
	else {
		menuobj.document.write('<layer name=gui bgColor=#E6E6E6 width=120 onmouseover="clearhidemenu()" onmouseout="hidemenu()">'+html+'</layer>');
		menuobj.document.close();
	}
	menuobj.thestyle.left = x;
	menuobj.thestyle.top = Math.min(document.body.clientHeight-menuobj.offsetHeight+document.body.scrollTop,y);
	//menuobj.thestyle.top = y;

	if(SelectedRow)
		SelectedRow.className = "qselect";

	menuobj.thestyle.visibility = "visible";

	return false;
}

function hidemenu() {
	if(window.menuobj)
		menuobj.thestyle.visibility = (ie4||ns6) ? "hidden" : "hide";

	if(SelectedRow) {
		SelectedRow.className = "";
		SelectedRow = null;
	}
}

function delayhidemenu() {
	if(ie4||ns6||ns4)
		delayhide = setTimeout("hidemenu()",500);
}

function clearhidemenu() {
	if(window.delayhide)
		clearTimeout(delayhide);
}

function highlightmenu(e,state) {
	if(state)
		clearhidemenu();
	else
		delayhidemenu();


	if(document.all)
		source_el = event.srcElement;
	else if(document.getElementById)
		source_el = e.target;

	if(source_el.className=="contextmenuitem") {
		source_el.id = state ? "mouseoverstyle" : "";
	}
	else {
		while(source_el.id!="popmenu") {
			source_el = document.getElementById ? source_el.parentNode : source_el.parentElement;
			if (source_el.className=="contextmenuitem"){
				source_el.id = state ? "mouseoverstyle" : "";
			}
		}
	}
}

function thisX(e) {
	for(x=0,j=e; j; j=j.offsetParent)
		x+=j.offsetLeft;
	return x;
}

function thisY(e) {
	for(y=0,j=e; j; j=j.offsetParent)
		y+=j.offsetTop;
	return y;
}

function showmenu1(e,n) {
	var html = "\
<div nowrap class=\"contextmenuitem\" onclick=\"Sb1('P-##')\">Pause/Unpause CMS</div>\
<div nowrap class=\"contextmenuitem\" onclick=\"Sb1('N-##')\">Rename CMS</div>\
<div><img src=\"/Bin/CMS/Bin/images/hbart0.gif\" width=\"160\" height=\"1\"></div>\
<div nowrap class=\"contextmenuitem\" onclick=\"Sb1('A-##')\">Archive/Unarchive CMS</div>\
<div nowrap class=\"contextmenuitem\" onclick=\"Sb1('D-##')\">Delete CMS</div>\
";
	SelectedRow = null;
	showmenu(thisX(e)-74,thisY(e)-3,n,html);
}

function showmenu1a(e,n) {
	var html = "\
<div nowrap class=\"contextmenuitem\" onclick=\"Sb1('C-##')\">Copy CMS</div>\
<div nowrap class=\"contextmenuitem\" onclick=\"Sb1('N-##')\">Rename CMS</div>\
<div><img src=\"/Bin/CMS/Bin/images/hbart0.gif\" width=\"160\" height=\"1\"></div>\
<div nowrap class=\"contextmenuitem\" onclick=\"Sb1('D-##')\">Delete CMS</div>\
";
	SelectedRow = null;
	showmenu(thisX(e)-74,thisY(e)-3,n,html);
}

function showmenu2a(x,y,n) {
	var html = "\
<div nowrap class=\"contextmenuitem\" onclick=\"Sb2('E-##')\">Edit...</div>\
<div nowrap class=\"contextmenuitem\"><font color=\"#A0A0A0\">Insert Before...</font></div>\
<div nowrap class=\"contextmenuitem\"><font color=\"#A0A0A0\">Insert After...</font></div>\
<div nowrap class=\"contextmenuitem\" onclick=\"Sb2('c-##')\">Insert Child...</div>\
<div><img src=\"/Bin/CMS/Bin/images/hbart0.gif\" width=\"110\" height=\"1\"></div>\
<div nowrap class=\"contextmenuitem\"><font color=\"#A0A0A0\">Increase Indent</font></div>\
<div nowrap class=\"contextmenuitem\"><font color=\"#A0A0A0\">Decrease Indent</font></div>\
<div><img src=\"/Bin/CMS/Bin/images/hbart0.gif\" width=\"110\" height=\"1\"></div>\
<div nowrap class=\"contextmenuitem\"><font color=\"#A0A0A0\">Cut</font></div>\
<div nowrap class=\"contextmenuitem\"><font color=\"#A0A0A0\">Copy</font></div>\
<div nowrap class=\"contextmenuitem\"><font color=\"#A0A0A0\">Paste Before</font></div>\
<div nowrap class=\"contextmenuitem\"><font color=\"#A0A0A0\">Paste After</font></div>\
<div nowrap class=\"contextmenuitem\" onclick=\"Sb2('S-##')\">Paste As Child</div>\
<div nowrap class=\"contextmenuitem\"><font color=\"#A0A0A0\">Delete</font></div>\
<div><img src=\"/Bin/CMS/Bin/images/hbart0.gif\" width=\"110\" height=\"1\"></div>\
<div nowrap class=\"contextmenuitem\"><font color=\"#A0A0A0\">Move Up</font></div>\
<div nowrap class=\"contextmenuitem\"><font color=\"#A0A0A0\">Move Down</font></div>\
<div nowrap class=\"contextmenuitem\"><font color=\"#A0A0A0\">Move To...</font></div>\
<div><img src=\"/Bin/CMS/Bin/images/hbart0.gif\" width=\"110\" height=\"1\"></div>\
<div nowrap class=\"contextmenuitem\" onclick=\"Sb2('T-##')\">Test...</div>\
";
	showmenu(x,y,n,html);
}

function showmenu2b(x,y,n) {
	var html = "\
<div nowrap class=\"contextmenuitem\" onclick=\"Sb2('E-##')\">Edit...</div>\
<div nowrap class=\"contextmenuitem\" onclick=\"Sb2('i-##')\">Insert Before...</div>\
<div nowrap class=\"contextmenuitem\" onclick=\"Sb2('I-##')\">Insert After...</div>\
<div nowrap class=\"contextmenuitem\" onclick=\"Sb2('c-##')\">Insert Child...</div>\
<div><img src=\"/Bin/CMS/Bin/images/hbart0.gif\" width=\"110\" height=\"1\"></div>\
<div nowrap class=\"contextmenuitem\" onclick=\"Sb2('A-##')\">Increase Indent</div>\
<div nowrap class=\"contextmenuitem\" onclick=\"Sb2('B-##')\">Decrease Indent</div>\
<div><img src=\"/Bin/CMS/Bin/images/hbart0.gif\" width=\"110\" height=\"1\"></div>\
<div nowrap class=\"contextmenuitem\" onclick=\"Sb2('X-##')\">Cut</div>\
<div nowrap class=\"contextmenuitem\" onclick=\"Sb2('C-##')\">Copy</div>\
<div nowrap class=\"contextmenuitem\" onclick=\"Sb2('V-##')\">Paste Before</div>\
<div nowrap class=\"contextmenuitem\" onclick=\"Sb2('W-##')\">Paste After</div>\
<div nowrap class=\"contextmenuitem\" onclick=\"Sb2('S-##')\">Paste As Child</div>\
<div nowrap class=\"contextmenuitem\" onclick=\"Sb2('D-##')\">Delete</div>\
<div><img src=\"/Bin/CMS/Bin/images/hbart0.gif\" width=\"110\" height=\"1\"></div>\
<div nowrap class=\"contextmenuitem\" onclick=\"Sb2('U-##')\">Move Up</div>\
<div nowrap class=\"contextmenuitem\" onclick=\"Sb2('L-##')\">Move Down</div>\
<div nowrap class=\"contextmenuitem\" onclick=\"Sb2('M-##')\">Move To...</div>\
<div><img src=\"/Bin/CMS/Bin/images/hbart0.gif\" width=\"110\" height=\"1\"></div>\
<div nowrap class=\"contextmenuitem\" onclick=\"Sb2('T-##')\">Test...</div>\
";
	showmenu(x,y,n,html);
}

function showmenu2c(x,y,n) {
	var html = "\
<div nowrap class=\"contextmenuitem\" onclick=\"Sb2('E-##')\">Edit...</div>\
<div nowrap class=\"contextmenuitem\" onclick=\"Sb2('T-##')\">Change Type...</div>\
<div nowrap class=\"contextmenuitem\" onclick=\"Sb2('i-##')\">Insert Before...</div>\
<div nowrap class=\"contextmenuitem\" onclick=\"Sb2('I-##')\">Insert After...</div>\
<div><img src=\"/Bin/CMS/Bin/images/hbart0.gif\" width=\"110\" height=\"1\"></div>\
<div nowrap class=\"contextmenuitem\" onclick=\"Sb2('b-##')\">Break Before...</div>\
<div nowrap class=\"contextmenuitem\" onclick=\"Sb2('B-##')\">Break After...</div>\
<div><img src=\"/Bin/CMS/Bin/images/hbart0.gif\" width=\"110\" height=\"1\"></div>\
<div nowrap class=\"contextmenuitem\" onclick=\"Sb2('X-##')\">Cut</div>\
<div nowrap class=\"contextmenuitem\" onclick=\"Sb2('C-##')\">Copy</div>\
<div nowrap class=\"contextmenuitem\" onclick=\"Sb2('V-##')\">Paste</div>\
<div nowrap class=\"contextmenuitem\" onclick=\"Sb2('D-##')\">Delete</div>\
<div><img src=\"/Bin/CMS/Bin/images/hbart0.gif\" width=\"110\" height=\"1\"></div>\
<div nowrap class=\"contextmenuitem\" onclick=\"Sb2('U-##')\">Move Up</div>\
<div nowrap class=\"contextmenuitem\" onclick=\"Sb2('L-##')\">Move Down</div>\
<div nowrap class=\"contextmenuitem\" onclick=\"Sb2('M-##')\">Move To...</div>\
";
	showmenu(x,y,n,html);
}

function showmenu2d(x,y,n) {
	var html = "\
<div nowrap class=\"contextmenuitem\" onclick=\"Sb2('QE-##')\">Edit Question...</div>\
";
	showmenu(x,y,n,html);
}

function showmenu2e(x,y,n) {
	var html = "\
<div nowrap class=\"contextmenuitem\" onclick=\"Sb2('E-##')\">Edit Statement...</div>\
";
	showmenu(x,y,n,html);
}

function showmenu2f(x,y,n) {
	var html = "\
<div nowrap class=\"contextmenuitem\" onclick=\"Sb2('E-##')\">Edit...</div>\
<div><img src=\"/Bin/CMS/Bin/images/hbart0.gif\" width=\"110\" height=\"1\"></div>\
<div nowrap class=\"contextmenuitem\" onclick=\"Sb2('C-##')\">Copy</div>\
<div nowrap class=\"contextmenuitem\" onclick=\"Sb2('D-##')\">Delete</div>\
";
	showmenu(x,y,n,html);
}

function showmenu2new(x,y,n) {
	var html = "\
<div nowrap class=\"contextmenuitem\" onclick=\"Sb2('C-##')\">Confirm Change</div>\
<div nowrap class=\"contextmenuitem\" onclick=\"Sb2('E-##')\">Edit This Version...</div>\
";
	showmenu(x,y,n,html);
}

function showmenu2orig(x,y,n) {
	var html = "\
<div nowrap class=\"contextmenuitem\" onclick=\"Sb2('R-##')\">Rollback to Original</div>\
<div nowrap class=\"contextmenuitem\" onclick=\"Sb2('O-##')\">Edit This Version...</div>\
";
	showmenu(x,y,n,html);
}

function showmenu2def(x,y,n) {
	var html = "\
<div nowrap class=\"contextmenuitem\" onclick=\"Sb2('E-##')\">Edit...</div>\
<div nowrap class=\"contextmenuitem\" onclick=\"Sb2('i-##')\">Insert Before...</div>\
<div nowrap class=\"contextmenuitem\" onclick=\"Sb2('I-##')\">Insert After...</div>\
<div><img src=\"/Bin/CMS/Bin/images/hbart0.gif\" width=\"110\" height=\"1\"></div>\
<div nowrap class=\"contextmenuitem\" onclick=\"Sb2('X-##')\">Cut</div>\
<div nowrap class=\"contextmenuitem\" onclick=\"Sb2('C-##')\">Copy</div>\
<div nowrap class=\"contextmenuitem\" onclick=\"Sb2('V-##')\">Paste</div>\
<div nowrap class=\"contextmenuitem\" onclick=\"Sb2('D-##')\">Delete</div>\
<div><img src=\"/Bin/CMS/Bin/images/hbart0.gif\" width=\"110\" height=\"1\"></div>\
<div nowrap class=\"contextmenuitem\" onclick=\"Sb2('U-##')\">Move Up</div>\
<div nowrap class=\"contextmenuitem\" onclick=\"Sb2('L-##')\">Move Down</div>\
<div nowrap class=\"contextmenuitem\" onclick=\"Sb2('M-##')\">Move To...</div>\
";
	showmenu(x,y,n,html);
}

function showmenu3(e,n) {
	var html = "\
<div nowrap class=\"contextmenuitem\" onclick=\"Sb1('S-##')\">Send Reminder</div>\
<div><img src=\"/Bin/CMS/Bin/images/hbart0.gif\" width=\"110\" height=\"1\"></div>\
<div nowrap class=\"contextmenuitem\" onclick=\"Sb1('D-##')\">Delete Invitation</div>\
<div nowrap class=\"contextmenuitem\" onclick=\"Sb1('R-##')\">Rename Invitation</div>\
";
	SelectedRow = null;
	showmenu(thisX(e)-74,thisY(e)-3,n,html);
}

function showmenu4a(e,n,url) {
	var html = "\
<div nowrap class=\"contextmenuitem\" onclick=\"Sb2('V-##')\">View Response(s)</div>\
<div nowrap class=\"contextmenuitem\" onclick=\"Sb2('E-##')\">Edit Recipient Data</div>\
<div nowrap class=\"contextmenuitem\" onclick=\"window.open('"+url+"','_blank')\">Start Phone Follow-up</div>\
";
	SelectedRow = null;
	showmenu(thisX(e)-74,thisY(e)-3,n,html);
}

function showmenu4b(e,n) {
	var html = "\
<div nowrap class=\"contextmenuitem\" onclick=\"Sb2('E-##')\">Edit Recipient Data</div>\
";
	SelectedRow = null;
	showmenu(thisX(e)-74,thisY(e)-3,n,html);
}

var SelectedRow;

function rightclick() {
	for(j=event.srcElement; j; j=j.parentElement) {
		if(j.id.substring(0,3)=="QID") {
			n = j.id.substring(3);
			if(SelectedRow)
				SelectedRow.className = "";
			SelectedRow = j;
			x = event.clientX + document.body.scrollLeft - 4;
			y = event.clientY + document.body.scrollTop - 4;
			showmenu2c(x,y,n);
			return false;
		}
		else if(j.id.substring(0,3)=="DID") {
			n = j.id.substring(3);
			if(SelectedRow)
				SelectedRow.className = "";
			SelectedRow = j;
			x = event.clientX + document.body.scrollLeft - 4;
			y = event.clientY + document.body.scrollTop - 4;
			showmenu2def(x,y,n);
			return false;
		}
		else if(j.id.substring(0,3)=="MID") {
			n = j.id.substring(3);
			if(SelectedRow)
				SelectedRow.className = "";
			SelectedRow = j;
			x = event.clientX + document.body.scrollLeft - 4;
			y = event.clientY + document.body.scrollTop - 4;
			showmenu2a(x,y,n);
			return false;
		}
		else if(j.id.substring(0,3)=="NID") {
			n = j.id.substring(3);
			if(SelectedRow)
				SelectedRow.className = "";
			SelectedRow = j;
			x = event.clientX + document.body.scrollLeft - 4;
			y = event.clientY + document.body.scrollTop - 4;
			showmenu2b(x,y,n);
			return false;
		}
		else if(j.id.substring(0,3)=="OID") {
			n = j.id.substring(3);
			if(SelectedRow)
				SelectedRow.className = "";
			SelectedRow = j;
			x = event.clientX + document.body.scrollLeft - 4;
			y = event.clientY + document.body.scrollTop - 4;
			showmenu2f(x,y,n);
			return false;
		}
		else if(j.id.substring(0,4)=="QNID") {
			n = j.id.substring(4);
			if(SelectedRow)
				SelectedRow.className = "";
			SelectedRow = j;
			x = event.clientX + document.body.scrollLeft - 4;
			y = event.clientY + document.body.scrollTop - 4;
			showmenu2d(x,y,n);
			return false;
		}
		else if(j.id.substring(0,4)=="ENID") {
			n = j.id.substring(4);
			if(SelectedRow)
				SelectedRow.className = "";
			SelectedRow = j;
			x = event.clientX + document.body.scrollLeft - 4;
			y = event.clientY + document.body.scrollTop - 4;
			showmenu2e(x,y,n);
			return false;
		}
		else if(j.id.substring(0,4)=="NNID") {
			n =j.id.substring(4);
			if(SelectedRow)
				SelectedRow.className = "";
			SelectedRow = j;
			x = event.clientX + document.body.scrollLeft - 4;
			y = event.clientY + document.body.scrollTop - 4;
			showmenu2new(x,y,n);
			return false;
		}
		else if(j.id.substring(0,4)=="ONID") {
			n = j.id.substring(4);
			if(SelectedRow)
				SelectedRow.className = "";
			SelectedRow = j;
			x = event.clientX + document.body.scrollLeft - 4;
			y = event.clientY + document.body.scrollTop - 4;
			showmenu2orig(x,y,n);
			return false;
		}
	}
	hidemenu();
	return false;
}

function doubleclick() {
	if(window.clientInformation.platform.substring(0,3)=="Mac")
		return rightclick();

	for(j=event.srcElement; j; j=j.parentElement) {
		if(j.id.substring(0,3)=="QID"||j.id.substring(0,3)=="NID"||j.id.substring(0,3)=="DID"||j.id.substring(0,3)=="MID"||j.id.substring(0,3)=="OID") {
			n = j.id.substring(3);
			Sb2("E-"+n);
			return false;
		}
		else if(j.id.substring(0,4)=="QNID") {
			n = j.id.substring(4);
			Sb2("QE-"+n);
			return false;
		}
		else if(j.id.substring(0,4)=="ENID") {
			n = j.id.substring(4);
			Sb2("E-"+n);
			return false;
		}
	}
	return true;
}
/******* Dynamic Loading Popup Code ********/

var Dpath,PopID,Type,Name,Path,TimeoutID;
var PopupWidth=500;
var xOffset = ie4 ? 1 : 0;
var yOffset = ie4 ? -1 : 0;

function LoadPopupInfo(datapath,popid,type,name,path) {
	clearTimeout(TimeoutID);
	TimeoutID=setTimeout(LoadPopupInfo2,500);
	Dpath=datapath;
	PopID=popid;
	Type=type;
	Name=name;
	Path=path;
	
	if(ie4) {
          document.attachEvent("onmousemove", MovePopupInfoEH);
          window.event.cancelBubble = true;
          window.event.returnValue = false;
       }
       else {
          document.addEventListener("mousemove", MovePopupInfoEH, true);
          event.preventDefault();
       }
}

function LoadPopupInfo2(none) {
  var URL="/bin/cms/getdata.dsb?path="+Dpath+"&popid="+PopID+"&type="+Type+"&name="+Name;
  DataFrame.location.replace(URL);

 // show popup now with the spinning wait image while the data is being retrieved
 // var popup=document.getElementById(PopID);
 // popup.style.display = 'block';
 // popup.style.visibility = 'visible';
}

function ResetPopup(popid) {
  window.document.getElementById(unescape(popid)).innerHTML="<div id=\"imagewait\" align=\"center\"><img src=\"/bin/cms/bin/images/spinningwait.gif\" /></div>";
}

function HidePopupInfo(popid,fade) {
	clearTimeout(TimeoutID);
	var popup=document.getElementById(popid);
	if(fade==1) {
		popup.style.filter="blendTrans(duration=.4)";
		if (popup.filters.blendTrans.status != 2) {
			popup.filters.blendTrans.apply();
			popup.style.display = 'none';
			popup.style.visibility='hidden';
			popup.filters.blendTrans.play();
		}
	}
	else {
 		popup.style.display = 'none';
		popup.style.visibility = 'hidden';
	}
        if (ie4)
           document.detachEvent("onmousemove", MovePopupInfoEH);
	else
           document.removeEventListener("mousemove", MovePopupInfoEH, true);
}

function updatepopup(popid,htmldata) {
  var popup=window.document.getElementById(unescape(popid));
  popup.innerHTML=unescape(htmldata);
  popup.style.display = 'block';
  popup.style.visibility = 'visible';
}

function OnPopupInfo(id) {
	document.getElementById(id).style.display='block';
}

function MovePopupInfoEH(event) {
    MovePopupInfo(window.document.getElementById(unescape(PopID)),event);
}

function MovePopupInfo(popup,evt) {
    var scrollOffset=document.body.scrollTop;
    var e= (window.event) ? window.event : evt;
    var x=e.clientX + xOffset + 12;
    var y=e.clientY + yOffset + scrollOffset + 10;

    var xFlipOffset = ie4 ? 0 : 10;

    popup.style.width=null;
    var w = isNaN(parseInt(popup.style.width)) ? PopupWidth : Math.min(parseInt(popup.style.width),PopupWidth);
    w=popup.clientWidth;

    //alert(x+' '+(document.body.clientWidth/2)+' '+Math.max(5,x-w-22)+' '+w);
    //if(x+w>(document.body.clientWidth-10)&&x>document.body.clientWidth/2)
    if(x>document.body.clientWidth/2&&w>(document.body.clientWidth-x-12-xOffset)) {
        //if we're past the halfway point on the x-axis and if the width is wider than the room we have..
        if(w>(x-27-xOffset-xFlipOffset)) {
            //if the popup is wider than the left to the cursor position..
            popup.style.left='5px';
            popup.style.width=(x-27-xOffset-xFlipOffset) + 'px';
	}
	else {
            //set left and get the newly displayed width..
            popup.style.left='5px';
            w=popup.clientWidth;
	    if((x-w-22-xOffset-xFlipOffset)<5) {
              //if the popup expanded and is wider than the dist. b/w cursor and left side (5px buffer and 22px shift around cursor)
	      //then set the left to 5px and width to be at x (but shifted back to the other side of the cursor)
	      //--this case should be quite rare
              popup.style.left='5px';
	      popup.style.width=(x-27-xOffset-xFlipOffset)+'px';
	    }
	    else
              popup.style.left=(x-w-22-xOffset-xFlipOffset) + 'px';
	}
    }
    else {
        //normal:  display to right of cursor
        popup.style.left=x + 'px';
	w=popup.clientWidth;
	if(w>(document.body.clientWidth-x-12-xOffset-5))
           popup.style.width=(document.body.clientWidth-x-12-xOffset-xFlipOffset)+'px';
    }

    popup.style.top=y + 'px';
}

function ShowPopupInfo(id,fade,dontshow,evt) {
    var popup = document.getElementById(id);

    //MovePopupInfo(popup,evt);
    popup.style.width=null;
    
    if(dontshow==undefined||dontshow==false){
      if(fade==1) {
        popup.style.filter="blendTrans(duration=.3)";
        if (popup.filters.blendTrans.status != 2) {
            popup.filters.blendTrans.apply();
            popup.style.display = 'block';
            popup.style.visibility='visible';
            popup.filters.blendTrans.play();
        }
      }
      else {
        popup.style.display = 'block';
        popup.style.visibility = 'visible';
      }
    }
    MovePopupInfo(popup,evt);
}


/************ Auto-Suggest Code ************/

var rule_field_id='';
var rule_field_bookmark;
var cursor_pos=-1;

function showsuggestion(title,datapath,type,question,search) {
  var swin=document.getElementById('suggestwin');

  swin.style.display='none';

  if(title)
    document.getElementById('suggesttitle').innerText=title;

  if(swin.style.left==''){
    swin.style.left=240;
    swin.style.top=244;
  }

  document.getElementById('suggestcont').style.display="none";
  document.getElementById('suggestwait').style.display="block";

  swin.style.display="block";

  if(rule_field_id=='')
    rule_field_id=document.getElementById('rule').children[0].name;

  if(cursor_pos==-1) {
    cursor_pos=getSelectionStart(rule_field_id);
    if(cursor_pos==-1)
      cursor_pos=document.getElementById(rule_field_id).value.length;
  }
  
  question = (question == undefined) ? '' : question;
  search = (search == undefined) ? '' : search;

  var URL="/Bin/CMS/getdata.dsb?path="+datapath+"&type="+type+"&qtn="+escape(question)+"&search="+escape(search);
  DataFrame.location.replace(URL);
}

function updatesuggestwin(info) {
  document.getElementById('suggestcont').innerHTML=unescape(info);
  document.getElementById('suggestcont').style.display='block';
  document.getElementById('suggestwait').style.display='none';
}

function hidesuggestionwin() {
  cursor_pos=-1;
  document.getElementById('suggestwin').style.display='none';
}

function insertinrule(text) {
   var rule=document.getElementById(rule_field_id);
   rule.value=rule.value.substring(0,cursor_pos)+text+rule.value.substring(cursor_pos,9999);
   cursor_pos+=text.length;
   setCursorPosition(rule_field_id,cursor_pos);
   hidesuggestionwin();
}

/********** Cursor/Selection Position **********/

function setCursorPosition(id,pos){
   var e=document.getElementById(id);
   if (e.createTextRange) {
      var range = e.createTextRange();
      range.move('character', pos);
      range.select();
   }
   else if(e.selectionStart) {
      e.focus();
      e.setSelectionRange(pos,pos);
   }
   else
      e.focus();
}

function getSelectionStart(id) {
   var field=document.getElementById(id);
   //if IE..
   if (field.createTextRange) {
      var r = document.selection.createRange().duplicate();
      rule_field_bookmark = r.getBookmark();
      r.moveEnd('character', field.value.length);
      if (r.text == '') 
         return field.value.length;
      return field.value.lastIndexOf(r.text);
   }
   else 
      return field.selectionStart;
}

/*********** Generic Element Dragging **********/

var dragInfo = new Object();
dragInfo.zIndex = 0;

function startdrag(id,event) {
  var el;
  var x, y;

  if (id)
    dragInfo.node = document.getElementById(id);
  else {
    if(ie4)
      dragInfo.node = window.event.srcElement;
    else
      dragInfo.node = event.target;

    if (dragInfo.node.nodeType == 3)
      dragInfo.node = dragInfo.node.parentNode;
  }
  dragInfo.node.style.zIndex = ++dragInfo.zIndex;

  if(ie4) {
    x = window.event.clientX + document.documentElement.scrollLeft + document.body.scrollLeft;
    y = window.event.clientY + document.documentElement.scrollTop + document.body.scrollTop;
  }
  else {
    x = event.clientX + window.scrollX;
    y = event.clientY + window.scrollY;
  }

  dragInfo.cursorBeginX = x;
  dragInfo.cursorBeginY = y;
  dragInfo.beginLeft = parseInt(dragInfo.node.style.left, 10);
  dragInfo.beginTop = parseInt(dragInfo.node.style.top, 10);

  if (isNaN(dragInfo.beginLeft)) dragInfo.beginLeft = 0;
  if (isNaN(dragInfo.beginTop)) dragInfo.beginTop = 0;

  if(ie4) {
    document.attachEvent("onmousemove", duringdrag);
    document.attachEvent("onmouseup", enddrag);
    window.event.cancelBubble = true;
    window.event.returnValue = false;
  }
  else {
    document.addEventListener("mousemove", duringdrag, true);
    document.addEventListener("mouseup", enddrag, true);
    event.preventDefault();
  }
}

function duringdrag(event) {
  var x,y;
  if (ie4) {
    x = window.event.clientX + document.documentElement.scrollLeft + document.body.scrollLeft;
    y = window.event.clientY + document.documentElement.scrollTop + document.body.scrollTop;
  }
  else {
    x = event.clientX + window.scrollX;
    y = event.clientY + window.scrollY;
  }

  dragInfo.node.style.left = (dragInfo.beginLeft+x - dragInfo.cursorBeginX) + 'px';
  dragInfo.node.style.top = (dragInfo.beginTop+y - dragInfo.cursorBeginY) + 'px';

  if(ie4) {
    window.event.cancelBubble = true;
    window.event.returnValue = false;
  }
  else
    event.preventDefault();
}


function enddrag(event) {
  if (ie4) {
    document.detachEvent("onmousemove", duringdrag);
    document.detachEvent("onmouseup", enddrag);
  }
  else {
    document.removeEventListener("mousemove", duringdrag, true);
    document.removeEventListener("mouseup", enddrag, true);
  }
}


