// Standard functions copied from Dreamweaver
function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}
function MM_validateForm() { //v4.0
  var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
  for (i=0; i<(args.length-2); i+=3) { nm="\""+args[i+1]+"\""; test=args[i+2]; val=MM_findObj(args[i]);
    if (val) { if ((val=val.value)!="") {
      if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
        if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
      } else if (test!='R') { num = parseFloat(val);
        if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
        if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
          min=test.substring(8,p); max=test.substring(p+1);
          if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
    } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; }
  } if (errors) alert('The following error(s) occurred:\n'+errors);
  document.MM_returnValue = (errors == '');
}

// ExpressBuilder Functions
function EBAdmin_str_valid(str,charset){
	var result = true;
	for (var i=0;i<str.length;i++)
		if (charset.indexOf(str.substr(i,1))<0){ result = false; break; }
	return result;
}
function EBAdmin_color_button_click(fldnm){
	var arr = showModalDialog("ebadmin_selcolor.asp","","status=no;scroll=no;resizable=no;toolbar=no;dialogWidth:331px;dialogHeight:350px;");
	var x;
	if (arr != null){ if ((x=MM_findObj(fldnm))!=null){ x.value=arr; } }
}
// @@@@@@@@@@@@@@@@@@@@@@@ TF Modify 2007-02-14 >>>>>>>>>>>>>>>>>>>>>>
function EBAdmin_popdatetime_button_click(fldnm, dateformat, w, h){
	var x;
	var oldv;
	if ((x=MM_findObj(fldnm))!=null){ oldv = x.value; }
	var arr = showModalDialog("ebadmin_seldatetime.asp?d="+oldv+"&dsp="+dateformat,"","status=no;scroll=no;resizable=yes;toolbar=no;dialogWidth:"+w+"px;dialogHeight:"+h+"px;");
	if (arr != null){ if ((x=MM_findObj(fldnm))!=null){ x.value=arr; } }
}
// @@@@@@@@@@@@@@@@@@@@@@@ TF Modify 2007-02-14 <<<<<<<<<<<<<<<<<<<<<<
function EBAdmin_image_button_click(fldnm, fldpath){
	var arr = showModalDialog("ebadmin_selimage.asp?start="+fldpath,"","status=no;scroll=yes;resizable:yes;toolbar=no;dialogWidth:475px;dialogHeight:383px;");
	var x;
	if (arr != ""){ if ((x=MM_findObj(fldnm))!=null){ x.value=arr; } }
}
function EBAdmin_small_button_over(eButton){
	eButton.style.backgroundColor = "#D4D0C8";
	eButton.style.borderColor = "#EEEEEE #999999 #999999 #EEEEEE";
}
function EBAdmin_small_button_out(eButton){
	eButton.style.backgroundColor = "#D4D0C8";
	eButton.style.borderColor = "#D4D0C8";
}
function EBAdmin_small_button_down(eButton){
	eButton.style.backgroundColor = "#BCB6A9";
	eButton.style.borderColor = "#999999 #EEEEEE #EEEEEE #999999";
}
function EBAdmin_small_button_up(eButton){
	eButton.style.backgroundColor = "#D4D0C8";
	eButton.style.borderColor = "#EEEEEE #999999 #999999 #EEEEEE";
	eButton = null;
}
function EBAdmin_set_rowcolor(theRow, thePointerColor){
    if (thePointerColor == '' || typeof(theRow.style) == 'undefined') return false;
    if (typeof(document.getElementsByTagName) != 'undefined') {
        var theCells = theRow.getElementsByTagName('td');
    }else if (typeof(theRow.cells) != 'undefined') {
        var theCells = theRow.cells;
    }else {
        return false;
    }
    var rowCellsCnt  = theCells.length;
    for (var c = 0; c < rowCellsCnt; c++) {
        theCells[c].style.backgroundColor = thePointerColor;
    }
    return true;
}

var sEBAdmin_FullScreenDivName="";
function EBAdmin_ResizeHtmlArea(){
	if(sEBAdmin_FullScreenDivName!=""){
		var div=MM_findObj("idHtmlArea_"+sEBAdmin_FullScreenDivName);
		var cont=MM_findObj("idContent_"+sEBAdmin_FullScreenDivName);
		if(div!=null){
			div.style.width=document.body.clientWidth;
			div.style.height=document.body.clientHeight;
			if(cont!=null){
				if(div.style.pixelWidth>6){
					cont.style.width=div.style.pixelWidth-6;
				}
				if(div.style.pixelHeight>94){
					cont.style.height=div.style.pixelHeight-94;
				}
			}
		}
	}
}
function EBAdmin_FullScreenHtmlArea(divName){
	var div=MM_findObj("idHtmlArea_"+divName);
	var cont=MM_findObj("idContent_"+divName);
	var upl=MM_findObj("imageupload_"+divName);
	if(div.style.position!="absolute"){
		document.body.scrollTop="0px";
		document.body.style.overflow="hidden";
		onresize=new Function("EBAdmin_ResizeHtmlArea();");
		if(div!=null){
			div.style.position="absolute";
			div.style.border="3px solid #FFFFFF"
			div.style.left="0px";
			div.style.top="0px";
			div.style.width=document.body.clientWidth;
			div.style.height=document.body.clientHeight;
			if(cont!=null){
				if(div.style.pixelWidth>6){
					cont.style.width=div.style.pixelWidth-6;
				}
				if(div.style.pixelHeight>94){
					cont.style.height=div.style.pixelHeight-94;
				}
			}
			if(upl!=null){
				upl.style.width="100%";
			}
		}
		sEBAdmin_FullScreenDivName=divName;
	}else{
		document.body.style.overflow="auto";
		onresize="";
		if(div!=null){
			div.style.position="static";
			div.style.border="0px none #000000"
			div.style.left="0px";
			div.style.top="0px";
			div.style.width="";
			div.style.height="";
			if(cont!=null){
				cont.style.width="";
				cont.style.height="";
			}
			if(upl!=null){
				upl.style.width="";
			}
		}
		sEBAdmin_FullScreenDivName="";
	}
}

function EBAdmin_GetDocumentURL(){
	var docLoc = document.location.toString();
	docLoc = docLoc.substring(0,docLoc.lastIndexOf("/")+1);
	return docLoc;
}
function EBAdmin_ReplaceAbsoluteURL(html) {
	var sRet, sRe;
	var sFullURL = document.location.toString();
	var sRelativeURL = sFullURL.substring(0,sFullURL.lastIndexOf("/")+1);
	var sPageName = sFullURL.replace(sRelativeURL, "");
	sRelativeURL = sRelativeURL.replace(/&/gi, "&amp;")
	sRelativeURL = sRelativeURL.replace(/\//gi,"\\\/");
	sRelativeURL = sRelativeURL.replace(/\./gi,"\\\.");
	sRelativeURL = sRelativeURL.replace(/\?/gi,"\\\?");
	sPageName = sPageName.replace(/&/gi, "&amp;")
	sPageName = sPageName.replace(/\//gi,"\\\/");
	sPageName = sPageName.replace(/\./gi,"\\\.");
	sPageName = sPageName.replace(/\?/gi,"\\\?");
	sRe = eval("/"+sRelativeURL+"/gi");
	sRet = html.replace(sRe, "")
	sRe = eval("/"+sPageName+"/gi");
	sRet = sRet.replace(sRe, "")
	return sRet;
}

///////////// HtmlArea Table Tool Function Start
var preRange;
var prevRangeType = "None";
var parentNode;
var BorderCurrent = 0;

function EBAdmin_showTableToolkitMenu(theFrameName, objSelection) {
	var parentNodeTagName = "None"
	
	parentNode = EBAdmin_getParentNode(objSelection);
	if(parentNode){
		parentNodeTagName = parentNode.tagName
	}
	if(!document.all.EBAdminHA_contextmenu) {
		var ne=document.createElement("DIV");
		ne.id = 'EBAdminHA_contextmenu';
		ne.unselectable = 'on';
		ne.style.position = 'absolute';
		ne.style.visibility = 'hidden';
		ne.style.top = '0px';
		ne.style.border = '1px solid #7C7C7C';
		ne.style.backgroundColor = '#F4F4F4';
		ne.style.width = 'auto';
		ne.className = 'ebadmin_smalltext';
		
		ne.oncontextmenu = new Function("event.returnValue=false");
		ne.onmousedown =  new Function("event.cancelBubble = true;");
		ne.onmouseout = new Function("cleanTableToolkitMenu(this);");
		
		document.body.appendChild(ne);
	} else {ne = document.all.EBAdminHA_contextmenu;}
	
	var divs = ne.getElementsByTagName("DIV")
	for (var i = divs.length - 1; i >= 0; i--){
		if (divs[i].isDynamic){
			divs[i].removeNode(true);
		}
	}
	ne = EBAdmin_contextItem('tableOption', "Table Options", 1, "");
	//ne.isDynamic = false;
	EBAdminHA_contextmenu.appendChild(ne);
	ne = EBAdmin_contextItem('toggleTableborder',"Toggle Table Border", 0, "EBAdmin_toggleTableBorder('" + theFrameName.toString() +"', 1); ");
	EBAdminHA_contextmenu.appendChild(ne);	
	
	if(parentNodeTagName=="TD" || parentNodeTagName == "None") {
		ne = EBAdmin_contextItem('tableAddnew',"Add New Table", 0, "EBAdmin_AddNewTable(); ");
		EBAdminHA_contextmenu.appendChild(ne);
	}	
	if(parentNodeTagName=="TABLE" || parentNodeTagName=="TD") {
		ne = EBAdmin_contextItem('tableEdit',"Edit Table Properties", 0, "EBAdmin_editTable(parentNode); ");	
		EBAdminHA_contextmenu.appendChild(ne);
	}
	if(parentNodeTagName=="TD") {
		ne = EBAdmin_contextItem('EBAdminHA_rowOptions',"Row Options", 1, "");	
		EBAdminHA_contextmenu.appendChild(ne);
		ne = EBAdmin_contextItem('EBAdminHA_addRowBelow',"Add Row Below", 0, "EBAdmin_addRow(parentNode, 'afterEnd');");	
		EBAdminHA_contextmenu.appendChild(ne);
		ne = EBAdmin_contextItem('EBAdminHA_addRowAbove',"Add Row Above", 0, "EBAdmin_addRow(parentNode, 'beforeBegin');");	
		EBAdminHA_contextmenu.appendChild(ne);
		ne = EBAdmin_contextItem('EBAdminHA_delelteRow',"Delete Current Row", 0, "EBAdmin_deleteRow(parentNode);");	
		EBAdminHA_contextmenu.appendChild(ne);
		
		ne = EBAdmin_contextItem('EBAdminHA_cellOptions',"Cell Options", 1, "");	
		EBAdminHA_contextmenu.appendChild(ne);
		ne = EBAdmin_contextItem('EBAdminHA_editCell',"Edit Cell Properties", 0, "EBAdmin_editCell(parentNode);");	
		EBAdminHA_contextmenu.appendChild(ne);
		ne = EBAdmin_contextItem('EBAdminHA_mergeCellRight',"Merge Cell Right", 0, "EBAdmin_mergeCell(parentNode, 'right');");	
		EBAdminHA_contextmenu.appendChild(ne);
		ne = EBAdmin_contextItem('EBAdminHA_addColumnAfter',"Add column after", 0, "EBAdmin_addColumn(parentNode, 'right');");	
		EBAdminHA_contextmenu.appendChild(ne);
		ne = EBAdmin_contextItem('EBAdminHA_addColumnBefore',"Add column before", 0, "EBAdmin_addColumn(parentNode, 'right');");	
		EBAdminHA_contextmenu.appendChild(ne);
		ne = EBAdmin_contextItem('EBAdminHA_deleteColumn',"Delete column", 0, "EBAdmin_deleteColumn(parentNode, 'right');");	
		EBAdminHA_contextmenu.appendChild(ne);				
	}

    EBAdminHA_contextmenu.style.left = event.clientX + document.body.scrollLeft;
    EBAdminHA_contextmenu.style.top = event.clientY + document.body.scrollTop;
    EBAdminHA_contextmenu.style.visibility="visible";
    EBAdminHA_contextmenu.style.zIndex = 100;
    EBAdminHA_contextmenu.focus();
    event.returnValue = false;
}


function cleanTableToolkitMenu(menudiv){
    var divs = menudiv.getElementsByTagName("DIV")
    if (event.toElement.tagName!=='DIV') {
	    for (var i = divs.length - 1; i >= 0; i--){
	      if (divs[i].isDynamic){
	        divs[i].removeNode(true);
	      }
	    }
	    menudiv.style.visibility = "hidden";
	}
}

function cleanTableMenuItemList() {
	if(document.all.EBAdminHA_contextmenu){
		var ne = document.all.EBAdminHA_contextmenu;
		var divs = ne.getElementsByTagName("DIV");
		for (var i = divs.length - 1; i >= 0; i--){
			if (divs[i].isDynamic){
				divs[i].removeNode(true);
			}
		}
		ne.style.visibility = "hidden";
	}		
}

function EBAdmin_contextItem(id, title, isHead, clickFunc){
  var ne = document.createElement("DIV");
  ne.id = id;
  ne.innerText = title;
  ne.isDynamic = true;
  ne.unselectable = 'on';
  if (isHead){
    ne.style.fontWeight = 'bold';
    ne.style.backgroundColor = '#CCCCCC';
  }else{
  	ne.innerHTML = "&nbsp; &nbsp; " + ne.innerHTML;
    ne.onmouseover = new Function("EBAdmin_contextItemOver(this);");
    ne.onmouseout = new Function("EBAdmin_contextItemOut(this);");
  }
  if (clickFunc) ne.onclick = new Function(clickFunc);
  ne.style.borderLeft = '4px solid #999999';
  ne.style.padding = '3px';
  return ne;
}

function EBAdmin_contextItemOver(item){
  item.style.backgroundColor='#DDDDDD'; 
  item.style.cursor = 'hand';
}
function EBAdmin_contextItemOut(item){
	item.style.removeAttribute('backgroundColor');
	event.cancelBubble = true;
}

function getTargetParentNode(srcNode, targetTagName) {
	var tempNode
	tempNode = srcNode
	if (srcNode.parentElement) {
		tempNode = srcNode.parentElement
		while(tempNode.tagName!="BODY" && tempNode) {
			if(tempNode.tagName==targetTagName) {
				return tempNode;
				break;
			}
			tempNode = tempNode.parentElement
		}
	}
	return tempNode
}

function EBAdmin_getParentNode(objSelection){
	prevRangeType = objSelection.type;
	preRange = objSelection.createRange();
	
	var objParentElement
	var temp 
	
	if(prevRangeType == "Control") {
		parentNode = preRange(0)
		return parentNode
	}
	else {	 	
		parentNode = preRange.parentElement();
		while(parentNode.tagName != "BODY") {
			  switch (parentNode.tagName){
				  case "TABLE":
				    return parentNode;
				    break;
				  case "TD":
				    return parentNode;
				    break;
			  }
			  parentNode = parentNode.parentElement;
		}
	}
}

function EBAdmin_AddNewTable() {
	cleanTableMenuItemList();
	var arr = showModalDialog("ebadmin_htmlarea_instbl.asp","","status=no;scroll=no;resizable=no;toolbar=no;dialogWidth:360px;dialogHeight:330px;");
	if (arr != null){ preRange.pasteHTML(arr); }
}

function EBAdmin_editTable(parentNode) {
	var tempTableNode;
	tempTableNode = parentNode;
	cleanTableMenuItemList();
	if(tempTableNode) {
		while(tempTableNode.tagName !="BODY"){
			if(tempTableNode.tagName =="TABLE") break; 
			tempTableNode = tempTableNode.parentElement;
		}
		if(tempTableNode.tagName == "TABLE"){
			showModalDialog("ebadmin_htmlarea_edittbl.asp",tempTableNode,"status=no;scroll=no;resizable=no;toolbar=no;dialogWidth:360px;dialogHeight:268px;");
		}
	}
}

function EBAdmin_toggleTableBorder(theFrameName, toggle) {
  if (toggle) BorderCurrent = !BorderCurrent;
  var frame = document.all(theFrameName)
  var tables = frame.contentWindow.document.body.getElementsByTagName("TABLE");
  cleanTableMenuItemList();
  for (var i = 0; i < tables.length; ++i){
    if (tables[i].border == 0){
      var tds = tables(i).getElementsByTagName("td");
      for (var j = 0; j < tds.length; ++j){
        if (BorderCurrent) tds[j].runtimeStyle.border = '1 dashed #3C3C3C';
        else tds[j].runtimeStyle.cssText = '';
      }
    }
  }
}


function EBAdmin_addRow(parentNode, loc) {
	cleanTableMenuItemList();
	var tr, table
	var tempNode
	if(parentNode.tagName == "TD") {
		tr = getTargetParentNode(parentNode, "TR")
		if(tr.tagName != "TR") return;
		var newTr = tr.cloneNode(true);
		var tds = newTr.getElementsByTagName("TD");
		for (var i = 0; i < tds.length; ++i){
			tds[i].runtimeStyle.border = '1 dashed #3C3C3C';
			tds[i].innerHTML = '&nbsp;';
		}
		tr.insertAdjacentElement(loc, newTr);
	}
}

function EBAdmin_deleteRow(parentNode) {
	cleanTableMenuItemList();
	var tr, table
	var tempNode
	
	if(parentNode.tagName=="TD") {
		tr = getTargetParentNode(parentNode, "TR")
		if(tr.tagName != "TR") return;
		table = getTargetParentNode(parentNode, "TABLE")
		if(table.tagName != "TABLE") return;
		tr.removeNode(true);
		if (!table.getElementsByTagName("TR").length) table.removeNode(true);
		tr=null;	
	}
}

function EBAdmin_editCell(parentNode) {
	cleanTableMenuItemList();
	if(parentNode.tagName=="TD") {
		showModalDialog("ebadmin_htmlarea_edittd.asp",parentNode,"status=no;scroll=no;resizable=no;toolbar=no;dialogWidth:360px;dialogHeight:235px;");
	}
}

function EBAdmin_mergeCell(parentNode, dir) {
	cleanTableMenuItemList();
	if(parentNode.tagName == "TD") {
		var td = parentNode;
		if (dir == 'left') td = td.previousSibling;
		td.innerHTML += td.nextSibling.innerHTML;
		td.colSpan += td.nextSibling.colSpan;
		td.nextSibling.removeNode(true);
	}
}

function EBAdmin_addColumn(parentNode, loc) {
	
	cleanTableMenuItemList();
	var pos;
	var table
	if(parentNode.tagName == "TD") {
		td = parentNode
		if (loc == 'left') td = td.previousSibling;
		table = getTargetParentNode(parentNode, "TABLE")
		if(table.tagName != "TABLE") return;
		
		for (pos = 1; td;pos+=td.colSpan, td = td.previousSibling);
		var trs = table.getElementsByTagName("TR");
		for (var i = 0; i < trs.length; ++i){
			var tds = trs(i).getElementsByTagName("TD");
			var currentCol = 0;
			for (var j = 0; j < tds.length; ++j){
				currentCol += tds(j).colSpan;
				if ((currentCol+1) >= pos){
					if (tds(j).colSpan > 1 && (currentCol + 1) != pos) tds(j).colSpan += 1;
					else{
						var neTD = document.createElement("TD");
						if (BorderCurrent) neTD.runtimeStyle.border = '1 dashed #3C3C3C';
						if (pos == 1) tds(j).insertAdjacentElement('beforeBegin', neTD);
						else tds(j).insertAdjacentElement('afterEnd', neTD);
					}
					break;
				}
			}
		}
	}
}

function EBAdmin_deleteColumn(parentNode) {
	cleanTableMenuItemList();
	var pos;
	var table;
	if(parentNode.tagName == "TD") {
		td = parentNode
		table = getTargetParentNode(parentNode, "TABLE")
		if(table.tagName != "TABLE") return;
		
		td = td.previousSibling;
		for (pos = 1; td;pos+=td.colSpan, td = td.previousSibling);
		var trs = table.getElementsByTagName("TR");
		for (var i = 0; i < trs.length; ++i){
			var tds = trs(i).getElementsByTagName("TD");
			var currentCol = 0;
			for (var j = 0; j < tds.length; ++j){
			  currentCol += tds(j).colSpan;
			  if (currentCol >= pos){
			    if (tds(j).colSpan > 1) tds(j).colSpan -= 1;
			    else tds(j).removeNode(true);
			    break;  
			  }
			}
		}
		for (var i = 0; i < trs.length; ++i){
			var tds = trs(i).getElementsByTagName("TD");
			if (tds.length == 0){
			  EBAdmin_deleteRow(tds);
			  --i;
			}
		} 
	}
}

///////////// HtmlArea Table Tool Function End

///////////// User Defined
function MM_preloadImages()
{
	var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
	var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    	if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_goToURL()
{
	var i, args=MM_goToURL.arguments; document.MM_returnValue = false;
	for (i=0; i<(args.length-1); i+=2) eval(args[i]+".location='"+args[i+1]+"'");
}

function MM_swapImgRestore() {
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_swapImage() {
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
///////////// User Defined End