/* Copyright 2003-2008, Ektron, Inc. */
var g_design_srcPath = "";
//nodeType
var ELEMENT_NODE = 1;
var TEXT_NODE = 3;
var CDATA_SECTION_NODE = 4;
var g_design_ektPlatformInfo = null;
function design_isSafari()
{
if (null == g_design_ektPlatformInfo && "function" == typeof PlatformInfo)
{
g_design_ektPlatformInfo = new PlatformInfo;
}
if (g_design_ektPlatformInfo)
{
return (g_design_ektPlatformInfo.isSafari);
}
else
{
return (false);
}
}
function design_onsubmitForm(form)
// form is name or index of, or reference to, the form element to validate.
// Returns true if valid element, or false.
{
var oElem = design_validateHtmlForm(form);
if (oElem && oElem.title != "") {
alert(oElem.title);
if ('function' == typeof oElem.scrollIntoView || 'object' == typeof oElem.scrollIntoView)
{
oElem.scrollIntoView();
}
if (design_canElementReceiveFocus(oElem))
{
oElem.focus();
}
return false;
}
return true;
}
function design_validateHtmlForm(form)
// form is name or index of, or reference to, the form element to validate.
// Returns first invalid element, or null.
{
// validation is supported for browser NS 6.2+ and IE 5+
if (null == g_design_ektPlatformInfo && "function" == typeof PlatformInfo)
{
g_design_ektPlatformInfo = new PlatformInfo;
}
if (g_design_ektPlatformInfo)
{
if (g_design_ektPlatformInfo.isNetscape && g_design_ektPlatformInfo.browserVersion < 6.2) return null;
if (g_design_ektPlatformInfo.isIE && g_design_ektPlatformInfo.browserVersion < 5) return null;
}
var oForm;
switch (typeof form)
{
case "string":
case "number":
oForm = document.forms[form];
break;
case "object":
oForm = form;
break;
default:
oForm = document.forms[0];
break;
}
if (!oForm) return null;
return design_prevalidateElement(oForm, null);
}
function design_prevalidateElement(oElem, oFirstInvalidElem)
{
if (!oElem) return oFirstInvalidElem;
if ("undefined" == typeof oElem.getAttribute) return oFirstInvalidElem;
if ("design_prototype" == oElem.className) return oFirstInvalidElem;
if ("object" == typeof oElem.currentStyle && oElem.currentStyle != null)
{
if ("none" == oElem.currentStyle.display) return oFirstInvalidElem;
if ("hidden" == oElem.currentStyle.visibility) return oFirstInvalidElem;
}
var validation = oElem.getAttribute("ektdesignns_validation");
if (validation && validation != "none")
{
oElem.removeAttribute("ektdesignns_isvalid");
design_validate_result = true; // just in case onblur handler fails to set the result
if ("function" == typeof oElem.onblur)
{
oElem.onblur(); // return value in global design_validate_result
}
else //if ("string" == typeof oElem.onblur) //for mac browsers
{ // or "object" - again, for mac (safari), see notes below.
// Safari 2.0.4/Mac typeof oElem.onblur is "function"
var sFn = oElem.getAttribute("onblur");
if (sFn)
{
try
{
oElem.fnonblur = new Function(sFn);
oElem.fnonblur();
}
catch (e)
{
// ********************************************************
// ATTENTION
//
// Safari appears to invoke the new function we
// create here (to handle the on-blur event (and
// perform the validation) in the wrong context;
// it runs in the calling windows context - which
// is a problem when we use things like the date
// picker popup, functions/etc that exist in the
// main window are not available in the popup window
// contentext - so the code fails...
//
// If, instead, we evaluate the function then it
// runs in the context of this main window and behaves
// properly. We catch that failure and attempt to
// handle it for Safari (or any other similarly
// mis-behaving browser).
//
// Note that we cannot use the 'this' pointer
// in this case, we must replace it with the variable
// name that points to the element object - in this
// case 'oElem' Also note that we asume that the
// this pointer will only be passed once in the parameter
// list, that it will come before the comments, etc.,
// otherwise the following regular expression will need
// to be updated.
//
// ********************************************************
sFn = sFn.replace(/([\(\,]\s*)this(\s*[\,\)])/, '$1oElem$2');
var fn = new Function(sFn);
eval(sFn);
}
}
}
if (null == oFirstInvalidElem && false == design_validate_result)
{
oFirstInvalidElem = oElem;
}
}
if (typeof oElem.childNodes != "undefined")
{
for (var i = 0; i < oElem.childNodes.length; i++)
{
if (ELEMENT_NODE == oElem.nodeType)
{
oFirstInvalidElem = design_prevalidateElement(oElem.childNodes.item(i), oFirstInvalidElem);
}
}
}
return oFirstInvalidElem;
}
var g_oElemContainerForAttributes = null;
function design_getProtectedAttribute(oElem, name)
{
// Processes attributes that may have be protected by eWebEditPro+XML.
var retValue; // initially undefined
if (oElem)
{
var ektAttr = oElem.getAttribute("ctagattrs");
// eg, " ektdesignns_minoccurs=@zzquote;0@zzquote;" or @zzsquo;
if ("string" == typeof ektAttr)
{
if (null == g_oElemContainerForAttributes)
{
g_oElemContainerForAttributes = document.createElement("span");
}
var strAttrs = ektAttr.replace(/\@zzquote\;/g,'"');
strAttrs = strAttrs.replace(/\@zzsquo\;/g,"'");
strAttrs = strAttrs.replace(/\@zzamp\;/g,"&");
strAttrs = strAttrs.replace(/\@zzlt\;/g,"<");
strAttrs = strAttrs.replace(/\@zzgt\;/g,">");
g_oElemContainerForAttributes.innerHTML = "";
retValue = g_oElemContainerForAttributes.firstChild.getAttribute(name);
}
}
return retValue;
}
function design_getAttribute(oElem, name)
{
// Processes attributes that may have be protected by eWebEditPro+XML.
var retValue; // initially undefined
if (oElem)
{
retValue = oElem.getAttribute(name);
if ("undefined" == typeof retValue || null == retValue)
{
retValue = design_getProtectedAttribute(oElem, name);
}
}
return retValue;
}
function design_getValue(oElem)
{
if (!oElem) return;
var bSupportInnerHTML = (typeof oElem.innerHTML != "undefined");
if (typeof oElem.value != "undefined")
{
if ("INPUT" == oElem.tagName && ("checkbox" == oElem.type || "radio" == oElem.type))
{
var strValue = oElem.value + "";
if (strValue.length > 0 && strValue != "true" && strValue != "on")
{
if (oElem.checked)
{
return strValue;
}
else
{
return "";
}
}
else // boolean
{
if (oElem.checked)
{
return true;
}
else
{
return false;
}
}
}
else
{
return oElem.value + ""; // Note: This string conversion is needed for Safari,
// as the regular expression fails to handle the value
// properly without it until some value has been placed
// into the input field (value may then be removed and it
// still works!). This way it always works properly.
// (Thanks Doug D! -BCB)
}
}
else if (typeof oElem.getAttribute != "undefined" && oElem.getAttribute("datavalue") != null)
{
// Needed for Opera b/c "value" is interpreted as a number and not a string, eg, "2007-01-09" is read as "2007"
return oElem.getAttribute("datavalue");
}
else if (typeof oElem.getAttribute != "undefined" && oElem.getAttribute("value") != null)
{
// In FireFox/Mozilla/Netscape7, the .value attribute is undefined if not standard (e.g., span)
// and .getAttribute("value") is null when .value is standard (e.g., input).
return oElem.getAttribute("value");
}
else if (bSupportInnerHTML && "content-req" == design_getAttribute(oElem, "ektdesignns_validation"))
{
return oElem.innerHTML; // CAUTION: .innerHTML is not well-formed and cannot be processed as XML
}
else if (bSupportInnerHTML && "mixed" == design_getAttribute(oElem, "ektdesignns_datatype"))
{
return oElem.innerText; // .innerHTML needs to be converted to XHTML, that is, well-formed
}
else if (typeof oElem.innerText != "undefined")
{
return oElem.innerText;
}
else if (bSupportInnerHTML)
{
return oElem.innerHTML.replace(/\<[^>]*\>/g, "");
}
else
{
return; // no data to test
}
}
function design_setValue(oElem, value)
{
if (!oElem) return;
if (typeof oElem.value != "undefined")
{
if ("undefined" == typeof oElem.getExpression || "undefined" == typeof oElem.getExpression("value"))//ie5(win)
{
if ("INPUT" == oElem.tagName && ("checkbox" == oElem.type || "radio" == oElem.type))
{
if ("true" == value || true == value || "on" == value) // boolean
{
oElem.checked = true;
}
else if ("false" == value || false == value) // boolean
{
oElem.checked = false;
}
else
{
oElem.value = value;
}
}
else
{
oElem.value = value;
}
}
}
else if (typeof oElem.getAttribute != "undefined" && oElem.getAttribute("value") != null)
{
// In FireFox/Mozilla/Netscape7, the .value attribute is undefined if not standard (e.g., span)
// and .getAttribute("value") is null when .value is standard (e.g., input).
oElem.value = value;
}
else if (typeof oElem.innerHTML != "undefined" && "mixed" == design_getAttribute(oElem, "ektdesignns_datatype"))
{
if ("undefined" == typeof oElem.getExpression || "undefined" == typeof oElem.getExpression("innerHTML"))
{
oElem.innerHTML = value;
}
}
else if (typeof oElem.innerText != "undefined")
{
if ("undefined" == typeof oElem.getExpression || "undefined" == typeof oElem.getExpression("innerText"))
{
oElem.innerText = value;
}
}
}
function design_evaluate(expression, value)
{
var obj = new Object();
obj.text = value + "";
obj.fnDesignEvaluateExpression = new Function("return " + expression);
return obj.fnDesignEvaluateExpression();
}
function design_normalize_re(re, oElem)
{
// only normalize for actual onblur event
if (typeof g_design_prevalidateFormReentry == "undefined" || g_design_prevalidateFormReentry != true)
{
var value = design_getValue(oElem);
if ("undefined" == typeof value) return; // no data to test
if ("undefined" != typeof RegExp.lastIndex)
{
RegExp.lastIndex = 0;
}
re.lastIndex = 0;
var ary = re.exec(value);
value = (null == ary ? "" : ary[0]);
design_normalize_complete(oElem, value);
}
}
function design_validate_re(re, oElem, invalidmsg)
{
var value = design_getValue(oElem);
if ("undefined" == typeof value) return; // no data to test
if ("undefined" != typeof RegExp.lastIndex)
{
RegExp.lastIndex = 0;
}
re.lastIndex = 0;
var result = re.test(value);
design_validate_complete(oElem, result, invalidmsg);
return result;
}
function design_normalize_js(expression, oElem)
{
// only normalize for actual onblur event
if (typeof g_design_prevalidateFormReentry == "undefined" || g_design_prevalidateFormReentry != true)
{
var value = design_getValue(oElem);
if ("undefined" == typeof value) return; // no data to test
var value = design_evaluate(expression, value);
design_normalize_complete(oElem, value);
}
}
function design_validate_js(expression, oElem, invalidmsg)
// value is optional
// returns true if valid or indeterminate, false if value fails reg exp.
{
var value = design_getValue(oElem);
if ("undefined" == typeof value) return; // no data to test
var result = design_evaluate(expression, value);
design_validate_complete(oElem, result, invalidmsg);
return result;
}
function design_normalize_complete(oElem, value)
{
design_setValue(oElem, value);
}
var design_validate_result = true;
function design_validate_complete(oElem, result, invalidmsg)
{
design_validate_result = result;
if (!oElem) return result;
// Netscape 4.7 does not support oElem.title and oElem.style.
if (invalidmsg && "string" == typeof oElem.title)
{
// Remove message from title attribute if it was appended.
var p = oElem.title.indexOf(invalidmsg);
if (p >= 0)
{
if (p > 0 && "\n" == oElem.title.charAt(p-1))
{
p -= 1;
}
oElem.title = oElem.title.substring(0, p);
}
// remove trailing line breaks
p = oElem.title.length - 1;
if (p >= 0 && "\n" == oElem.title.charAt(p))
{
while (p >= 0 && "\n" == oElem.title.charAt(p))
{
p--;
}
oElem.title = oElem.title.substring(0, p);
}
}
if (!result)
{
if (invalidmsg && ("string" == typeof oElem.title))
{
// Append message to title attribute unless it is already present.
if (-1 == oElem.title.indexOf(invalidmsg))
{
if (oElem.title.length > 0)
{
oElem.title += " \n";
}
oElem.title += invalidmsg;
}
}
}
// Check for the presence of a customer defined validation-styling function:
if ("function" == typeof customValidationStyle)
{
// call the users custom validation-styling function:
customValidationStyle(oElem, result);
}
else
{
// use our built-in validation-styling function:
design_validationStyle(oElem, result);
}
}
function design_validationStyle(oElem, isValid)
{
var parent = null;
var elTypeName = oElem.tagName;
// If browser is Safari, or control type is Select, but not both
// Safari And Select-control (because Safari Select controls do not
// generate an onBlur event) then add wrapper for border/style control:
var specialCaseBorder = (design_isSafari() && ("INPUT" == elTypeName))
|| ("SELECT" == elTypeName);
if ("object" == typeof oElem)
{
parent = oElem.parentNode;
if (("object" == typeof oElem.style) && ("object" == typeof parent))
{
if (isValid)
{
if (specialCaseBorder)
{
if (("SPAN" == parent.tagName)
&& ("design_validation_failed" == parent.className))
{
parent.className = "design_validation_passed";
}
}
else
{
// Safari needs the individual properties
oElem.style.borderTopStyle = "";
oElem.style.borderRightStyle = "";
oElem.style.borderBottomStyle = "";
oElem.style.borderLeftStyle = "";
oElem.style.borderTopColor = "";
oElem.style.borderRightColor = "";
oElem.style.borderBottomColor = "";
oElem.style.borderLeftColor = "";
oElem.style.borderTopWidth = "";
oElem.style.borderRightWidth = "";
oElem.style.borderBottomWidth = "";
oElem.style.borderLeftWidth = "";
oElem.style.margin = "2px";
// Do not simply remove style: it doesn't
// re-render in IE 5.5, may destabilize it...
}
}
else
{
if (("undefined" == typeof g_design_designMode) || (g_design_designMode != true))
{
if (specialCaseBorder)
{
// Ensure that the element is wrapped in our own
// span tag, so we can control the border style:
if ((parent.tagName != "SPAN")
|| ((parent.className != "design_validation_failed")
&& (parent.className != "design_validation_passed")))
{
var wrapper = document.createElement("span");
wrapper = parent.insertBefore(wrapper, oElem);
oElem = parent.removeChild(oElem);
oElem = wrapper.appendChild(oElem);
parent = wrapper;
}
parent.className = "design_validation_failed";
}
else
{
oElem.style.borderStyle = "dashed";
oElem.style.borderColor = "red";
oElem.style.borderWidth = "2px";
oElem.style.margin = "0";
}
}
}
}
}
}
function design_validate_select(minIndex, oElem, invalidmsg)
// minIndex = -1, 0, 1 etc.. (-1 = not selected; 0 = 1st on list etc)
// returns true if valid or indeterminate, false if index is 0 or -1.
{
if (!oElem) return;
if ("undefined" == typeof oElem.selectedIndex)
{
return; // not a select element
}
var result = (oElem.selectedIndex >= minIndex);
// this has no visual effect on select tag, but it is needed to set the design_validate_result (global var).
design_validate_complete(oElem, result, invalidmsg);
return result;
}
function design_validate_choice(minSelected, maxSelected, oElem, invalidmsg)
// returns true if valid or indeterminate, false otherwise.
// maxSelected = -1 if it has no limits.
{
if (!oElem) return;
if ("undefined" == typeof oElem.getElementsByTagName) return;
var num_checked = 0;
var oCurrElem;
var bUseChecked;
var aryElements = null;
var validation = oElem.getAttribute("ektdesignns_validation");
if ("choice-req" == validation)
{
aryElements = oElem.getElementsByTagName("input");
bUseChecked = true;
}
else if ("select-req" == validation) //list box
{
aryElements = oElem.getElementsByTagName("option");
bUseChecked = false;
}
if (aryElements)
{
for (var i = 0; i < aryElements.length; i++)
{
oCurrElem = aryElements[i];
if (bUseChecked)
{
if (oCurrElem.checked)
{
num_checked++;
}
}
else //list box
{
if (oCurrElem.selected)
{
num_checked++;
}
}
}
}
var result = (minSelected <= num_checked && (maxSelected <= 0 || num_checked <= maxSelected));
design_validate_complete(oElem, result, invalidmsg);
return result;
}
function design_normalize_isbn(value)
{
value = value + "";
value = value.replace(/[\s\-]/g, "").toUpperCase(); // remove spaces and hyphens
return value;
}
function design_validate_isbn(value)
// returns true if valid or indeterminate, false otherwise.
{
var result = design_validate_isbn10(value) || design_validate_isbn13(value);
return result;
}
function design_validate_isbn10(value)
// returns true if valid or indeterminate, false otherwise.
{
var result = true;
value = value + "";
var re = new RegExp("^[0-9]{9}[0-9X]$"); // or "^[0-9 \-]{9,12}[0-9X]$"
if (!re.test(value)) return false;
// adapted from http://www.merlyn.demon.co.uk/js-misc0.htm#ISBN
var check = 0;
var weight = 10;
for (var i = 0; i < value.length; i++)
{
var c = value.charCodeAt(i);
if (88 == c && 1 == weight) // final X
{
check += 10;
weight--;
}
else if (48 <= c && c <= 57) // 0-9
{
check += (c - 48) * weight--;
}
}
result = (0 == weight && 0 == (check % 11));
return result;
}
function design_validate_isbn13(value)
// returns true if valid or indeterminate, false otherwise.
{
value = value + "";
var re = new RegExp("^[0-9]{13}$"); // or "^[0-9 \-]{13,17}$"
if (!re.test(value)) return false;
// adapted from http://www.merlyn.demon.co.uk/js-misc0.htm#ISBN
var check = 0;
var n = 13;
var weight = 1;
for (var i = 0; i < value.length; i++)
{
var c = value.charCodeAt(i);
if (48 <= c && c <= 57) // 0-9
{
check += (c - 48) * weight;
weight = (1 == weight ? 3 : 1); // toggle b/n 1 and 3
n--;
}
}
return (0 == n && 0 == (check % 10));
}
function design_normalize_issn(value)
{
value = value + "";
value = value.replace(/[\s\-]/g, "").toUpperCase(); // remove spaces and hyphens
return value;
}
function design_validate_issn(value)
// returns true if valid or indeterminate, false otherwise.
{
value = value + "";
var re = new RegExp("^[0-9]{7}[0-9X]$"); // or "^[0-9]{4}\-?[0-9]{3}[0-9X]$"
if (!re.test(value)) return false;
// adapted from http://www.merlyn.demon.co.uk/js-misc0.htm#ISBN
var check = 0;
var weight = 8;
for (var i = 0; i < value.length; i++)
{
var c = value.charCodeAt(i);
if (88 == c && 1 == weight) // final X
{
check += 10;
weight--;
}
else if (48 <= c && c <= 57) // 0-9
{
check += (c - 48) * weight--;
}
}
return (0 == weight && 0 == (check % 11));
}
function design_current_date()
{
// Returns current date in format yyyy-mm-dd
var oCurrentDate = new Date();
var mm = (oCurrentDate.getMonth() + 1);
if (mm <= 9) mm = "0" + mm;
var dd = oCurrentDate.getDate();
if (dd <= 9) dd = "0" + dd;
return (oCurrentDate.getFullYear() + "-" + mm + "-" + dd);
}
//function design_default_current_date(date)
//{
// date = date + "";
// if (date.length != 10)
// {
// date = design_current_date();
// var oTempDate = new Date(date.substr(0,4), parseInt(date.substr(5,2),10)-1, date.substr(8,2));
// var strDate = (oTempDate.toLocaleDateString ? oTempDate.toLocaleDateString() : oTempDate.toLocaleString());
// var oDateElem = oElem.firstChild;
// while (oDateElem && oDateElem.tagName != "INPUT")
// {
// oDateElem = oDateElem.nextSibling;
// }
// if (oDateElem != null) oDateElem.value = strDate;
// }
// return date;
//}
function design_validate_future_date(date)
// returns true if valid or indeterminate, false otherwise.
{
date = date + "";
if (10 == date.length)
{
return (date >= design_current_date());
}
return false;
}
// private
function design_canElementReceiveFocus(oElem)
// Returns true if form element can receive the focus, false if not.
{
if (!oElem) return false;
var strType = oElem.type + "";
if ("hidden" == strType) return false;
if ("object" == typeof oElem.currentStyle)
{
if ("none" == oElem.currentStyle.display) return false;
// Unfortunately, currentStyle.visibility may return "inherit" (even for all parents), which is not helpful.
if ("hidden" == oElem.currentStyle.visibility) return false;
}
var strDisabled = oElem.disabled + "";
if ("true" == strDisabled) return false;
if (oElem.isDisabled) return false;
var strIsTextEdit = oElem.isTextEdit + "";
if ("false" == strIsTextEdit) return false;
var strFocusMethod = typeof oElem.focus;
if ("function" != strFocusMethod && "object" != strFocusMethod) return false;
return true;
}
function design_HTMLEncode(s)
{
var strHTML = s + "";
strHTML = strHTML.replace(/\&/g, "&");
strHTML = strHTML.replace(/\/g, ">");
strHTML = strHTML.replace(/\"/g, """);
return strHTML;
}
function design_serializeHTMLAttribute(oElem, name)
{
if (!oElem) return "";
try
{
var attr = "";
if ("class" == name)
{
attr = oElem.className;
}
else
{
attr = design_getAttribute(oElem, name);
}
if ("string" == typeof attr && attr.length > 0)
{
return " " + name + "=\"" + design_HTMLEncode(attr) + "\"";
}
else if ("boolean" == typeof attr && true == attr)
{
return " " + name + "=\"" + name + "\"";
}
else
{
return "";
}
}
catch (e)
{
return "";
}
}
function design_serializeHTMLElement(oElem, content)
{
if (!oElem) return "";
var tagName = oElem.tagName.toLowerCase();
var sAttrs = "";
var attrNames = ["ektdesignns_bind","ektdesignns_nodetype","ektdesignns_content","class","type","value","selected","checked"];
for (var i = 0; i < attrNames.length; i++)
{
sAttrs += design_serializeHTMLAttribute(oElem, attrNames[i]);
}
if ("undefined" == typeof content)
{
// Recurse through children and serialize each.
content = "";
for (var i = 0; i < oElem.childNodes.length; i++)
{
var oChild = oElem.childNodes[i];
switch (oChild.nodeType)
{
case ELEMENT_NODE:
content += design_serializeHTMLElement(oChild);
break;
case TEXT_NODE:
content += oChild.nodeValue;
break;
// case CDATA_SECTION_NODE:
// content += ?;
// break;
default:
// ignore. note, attributes are handled above
break;
}
}
}
return design_serializeElement(tagName, content, sAttrs);
}
function design_serializeElement(tagName, content, attributes)
{
if ("undefined" == typeof attributes) attributes = "";
if ("undefined" == typeof content || ("string" == typeof content && 0 == content.length) || (null == content))
{
return "<" + tagName + attributes + " />\n";
}
else
{
return "<" + tagName + attributes + ">" + content + "" + tagName + ">\n";
}
}
/* XML functionality dependent on Sarissa */
function design_xml_loadXML(xml)
{
try
{
if (typeof xml != "string") return null;
if (xml.length <= 2) return null;
var xmlDoc = Sarissa.getDomDocument();
if ("string" == typeof xmlDoc || null == xmlDoc) return "Unable to create XML DOM Document";
xmlDoc.async = false;
if (xml.indexOf("<") >= 0)
{
var objParser = new DOMParser();
xmlDoc = objParser.parseFromString(xml, "text/xml");
if (Sarissa.getParseErrorText(xmlDoc) != Sarissa.PARSED_OK)
{
// add root tags in case that is the problem
xml = "" + xml + "";
xmlDoc = objParser.parseFromString(xml, "text/xml");
}
}
else // URL
{
var url = xml;
url = url.replace(/.*(\[|%5B)srcpath(\]|%5D)\/?/i, srcPath);
url = url.replace(/.*(\[|%5B)eWebEditProPath(\]|%5D)\/?/i, srcPath);
xmlDoc.load(url);
}
var strErrMsg = Sarissa.getParseErrorText(xmlDoc);
if (strErrMsg != Sarissa.PARSED_OK)
{
//alert(strErrMsg);
return strErrMsg;
}
return xmlDoc;
}
catch (e)
{
//alert(e.message);
return e.message;
}
}
function design_xml_loadXSLT(xslt)
{
try
{
if (typeof xslt != "string") return null;
if (xslt.length <= 2) return null;
var xslDoc = Sarissa.getXsltDocument();
if ("string" == typeof xslDoc || null == xslDoc) return "Unable to create XSLT DOM Document";
xslDoc.async = false;
if (xslt.indexOf("<") >= 0)
{
if (typeof xslDoc.loadXML != "undefined")
{
xslDoc.loadXML(xslt);
}
else
{
var objParser = new DOMParser();
xslDoc = objParser.parseFromString(xslt, "text/xml");
}
}
else // URL
{
var url = xslt;
url = url.replace(/.*(\[|%5B)srcpath(\]|%5D)\/?/i, srcPath);
url = url.replace(/.*(\[|%5B)eWebEditProPath(\]|%5D)\/?/i, srcPath);
xslDoc.load(url);
}
var strErrMsg = Sarissa.getParseErrorText(xslDoc);
if (strErrMsg != Sarissa.PARSED_OK)
{
//alert(strErrMsg);
return strErrMsg;
}
return xslDoc;
}
catch (e)
{
//alert(e.message);
return e.message;
}
}
function design_transformToDocument(xml, xslt)
{
try
{
var xmlDoc = design_xml_loadXML(xml);
if ("string" == typeof xmlDoc) return xmlDoc;
if (null == xmlDoc) return "Unable to load XML document";
var xsltDoc = design_xml_loadXSLT(xslt);
if ("string" == typeof xsltDoc) return xsltDoc;
if (null == xsltDoc) return "Unable to load XSLT document";
var processor = new XSLTProcessor();
processor.importStylesheet(xsltDoc);
var newDoc = processor.transformToDocument(xmlDoc);
return newDoc;
}
catch (e)
{
//alert(e.message);
return e.message;
}
}
function design_transform(xml, xslt)
{
try
{
var xmlDoc = design_xml_loadXML(xml);
if ("string" == typeof xmlDoc) return xmlDoc;
if (null == xmlDoc) return "Unable to load XML document";
var xsltDoc = design_xml_loadXSLT(xslt);
if ("string" == typeof xsltDoc) return xsltDoc;
if (null == xsltDoc) return "Unable to load XSLT document";
var processor = new XSLTProcessor();
processor.importStylesheet(xsltDoc);
var ownerDoc = Sarissa.getDomDocument();
var newDoc = processor.transformToFragment(xmlDoc, ownerDoc);
if ("string" == typeof newDoc) return newDoc;
var result = (new XMLSerializer()).serializeToString(newDoc);
// Mozilla may wrap output with transformiix:result tags, so remove them
result = result.replace(/]*>/,"").replace("","");
// Mozilla ignores namespace-alias, so use reg exp to manually 'alias'.
result = result.replace(/xslout:/g,"xsl:");
result = result.replace(/<\?[^\?]*\?>/,""); // remove xml declaration, if it exists
// Can't use js extension to call xpathLiteralString in the XSLT, so do it here.
result = result.replace(/xpathLiteralString(.*?)gnirtSlaretiLhtapx/g,
function(s,p1) { return xpathLiteralString(p1); } );
return result;
// Older code for IE
// var xmlDoc = design_xml_loadXML(xml);
// if ("string" == typeof xmlDoc) return xmlDoc;
// if (null == xmlDoc) return "Unable to load XML document";
//
// var xsltDoc = design_xml_loadXML(xslt);
// if ("string" == typeof xsltDoc) return xsltDoc;
// if (null == xsltDoc) return "Unable to load XSLT document";
//
// var result = xmlDoc.transformNode(xsltDoc) + "";
// result = result.replace(/<\?[^\?]*\?>/,""); // remove xml declaration, if it exists
// return result;
}
catch (e)
{
//alert(e.message);
return e.message;
}
}
function xpathLiteralString(s)
{
if (s.indexOf("'") >= 0)
{
return "concat('" + s.replace(/\'/g, "',"'",'") + "')";
}
else
{
return "'" + s + "'";
}
}
/* Dynamic Data Lists */
function design_replaceDataLists()
{
if (!document || !document.body)
{
setTimeout('design_replaceDataLists()', 200); // too soon, try again later
return;
}
var aryDatalistCache = new Array();
var aryTags = new Array();
aryTags[0] = document.body.getElementsByTagName("select");
aryTags[1] = document.body.getElementsByTagName("ektdesignns_choices");
aryTags[2] = document.body.getElementsByTagName("ektdesignns_checklist");
for (var iTag = 0; iTag < aryTags.length; iTag++)
{
var aryElems = aryTags[iTag];
for (var iElem = 0; iElem < aryElems.length; iElem++)
{
var oElem = aryElems[iElem];
var datasrc = design_getAttribute(oElem, "ektdesignns_datasrc");
if ("string" == typeof datasrc && datasrc.length > 0)
{
var datalist = design_getAttribute(oElem, "ektdesignns_datalist");
if ("string" == typeof datalist && datalist.length > 0)
{
if ("undefined" == typeof aryDatalistCache[datalist])
{
var strSelect = design_getAttribute(oElem, "ektdesignns_dataselect");
var strCaptionXPath = design_getAttribute(oElem, "ektdesignns_captionxpath");
var strValueXPath = design_getAttribute(oElem, "ektdesignns_valuexpath");
var strNamespaces = design_getAttribute(oElem, "ektdesignns_datanamespaces");
aryDatalistCache[datalist] = design_getDataList(oElem.tagName, datasrc, strSelect, strCaptionXPath, strValueXPath, strNamespaces);
// Datalist will be empty if running in editor b/c access is denied.
}
if (aryDatalistCache[datalist].length > 0)
{
if ("SELECT" == oElem.tagName)
{
var strOrigDataList = "";
for (var iOption = 0; iOption < oElem.options.length; iOption++)
{
var oOption = oElem.options[iOption];
strOrigDataList += design_serializeHTMLElement(oOption, design_HTMLEncode(oOption.text));
}
var xmlDoc = design_transformDataList(strOrigDataList, aryDatalistCache[datalist]);
if (typeof xmlDoc != "string")
{
var newOptions = xmlDoc.getElementsByTagName("option");
var numOptions = (newOptions != null ? newOptions.length : 0);
if (oElem.options.length > numOptions)
{
oElem.options.length = numOptions;
}
if (oElem.multiple && oElem.size < 2 && numOptions > 12)
{
oElem.size = 12;
}
for (var iOption = 0; iOption < numOptions; iOption++)
{
var newOption = newOptions[iOption];
var attrs = newOption.attributes;
var attr;
var text = (newOption.firstChild ? newOption.firstChild.nodeValue : "");
attr = attrs.getNamedItem("value");
var value = (attr ? attr.nodeValue : "");
attr = attrs.getNamedItem("selected");
var bSelected = ("selected" == (attr ? attr.nodeValue : ""));
oElem.options[iOption] = new Option(text, value, bSelected, bSelected);
}
// oElem.innerHTML NOTE: setting innerHTML for select element is bug-ridden in all browsers
}
else
{
alert(xmlDoc); // transformation error
}
}
else // choices and checklist
{
var oOrigListElem = oElem.nextSibling; // oElem is custom tag and does not contain its lexical children
while (oOrigListElem.tagName != "OL") oOrigListElem = oOrigListElem.nextSibling;
var strOrigDataList = design_serializeHTMLElement(oOrigListElem);
// Can't mix DHTML DOM and XML DOM nodes, so transform returns string of HTML.
var strHtml = design_transformChoiceDataList(strOrigDataList, aryDatalistCache[datalist]);
strHtml = strHtml.replace(/
]*>/,"").replace("",""); // remove OL tag, it's same as orig
oOrigListElem.innerHTML = strHtml; // replace LI elements
}
}
} // if datalist
} // if datasrc
} // for
} // for
}
setTimeout('design_replaceDataLists()',1); // run this automatically after page is loaded
function design_transformChoiceDataList(strOrigDataList, strNewDataList)
{
// Sarissa bug The document('') function is the web page in IE6 and the xml source document in Mozilla
var strXSLT = "";
strXSLT = "";
strXSLT += "\n";
strXSLT += "\n";
strXSLT += "\n";
strXSLT += "\n";
strXSLT += "\n";
strXSLT += "\n";
strXSLT += "\n";
strXSLT += "\n";
strXSLT += "\n";
var strVariables = design_transform(strOrigDataList, strXSLT);
strXSLT = "";
strXSLT += "\n";
strXSLT += "\n";
strXSLT += "\n";
strXSLT += "\n";
strXSLT += " \n";
strXSLT += "\n";
strXSLT += "\n";
strXSLT += " \n";
strXSLT += " \n"; // copy LI element
strXSLT += " \n";
strXSLT += "\n";
strXSLT += "\n";
strXSLT += "\n";
var strOldSelectedSnip = design_transform(strOrigDataList, strXSLT);
strXSLT = "";
strXSLT += "\n";
strXSLT += "\n";
strXSLT += "\n";
strXSLT += "\n";
strXSLT += " \n";
strXSLT += " \n";
strXSLT += " \n";
strXSLT += " \n";
strXSLT += "\n";
strXSLT += "\n";
strXSLT += " \n";
strXSLT += " checked\n";
strXSLT += " \n";
strXSLT += "\n";
strXSLT += "\n";
strXSLT += "\n";
var strNewSelectedSnip = design_transform(strOrigDataList, strXSLT);
strXSLT = "";
strXSLT += "\n";
strXSLT += "\n";
strXSLT += "\n";
//// strXSLT += "\n";
//// strXSLT += strOrigDataList; // original ol/li list
//// strXSLT += "\n";
// Sarissa bug The document('') function is the web page in IE6 and the xml source document in Mozilla
//// strXSLT += "\n";
//// strXSLT += "\n";
//// strXSLT += "\n";
//// strXSLT += "\n";
strXSLT += strVariables;
// copy original OL tag
strXSLT += "\n";
//// strXSLT += " \n";
//// strXSLT += " \n";
var strOlTag = strOrigDataList.match(/]*>/);
strXSLT += " " + strOlTag + "\n";
strXSLT += " \n";
strXSLT += " \n";
strXSLT += "\n";
// copy checked values that are not in the new data list
strXSLT += "\n";
//// strXSLT += " \n";
strXSLT += strOldSelectedSnip;
strXSLT += " \n";
strXSLT += "\n";
// process option tags
strXSLT += "\n";
strXSLT += " \n";
strXSLT += " \n";
strXSLT += " \n";
strXSLT += "
\n";
// copy attributes except 'checked'
strXSLT += " \n";
//// strXSLT += " \n";
// check if checked in the old data list
//// strXSLT += " \n";
//// strXSLT += " checked\n";
//// strXSLT += " \n";
strXSLT += strNewSelectedSnip;
strXSLT += " \n";
strXSLT += " \n";
strXSLT += "
\n";
strXSLT += "\n";
// copy the text
strXSLT += "\n";
strXSLT += " \n";
strXSLT += " \n";
strXSLT += " \n";
strXSLT += " \n";
strXSLT += "\n";
strXSLT += "\n";
// Transform
var strHtml = design_transform(strNewDataList, strXSLT);
return strHtml;
}
function design_transformDataList(strOrigDataList, strNewDataList)
{
// Sarissa bug The document('') function is the web page in IE6 and the xml source document in Mozilla
strOrigDataList = "";
var strXSLT = "";
strXSLT = "";
strXSLT += "\n";
strXSLT += "\n";
strXSLT += "\n";
strXSLT += "\n";
strXSLT += " \n";
strXSLT += "\n";
strXSLT += "\n";
strXSLT += " \n";
strXSLT += " \n";
strXSLT += " \n";
strXSLT += "\n";
strXSLT += "\n";
strXSLT += "\n";
var strOldSelectedSnip = design_transform(strOrigDataList, strXSLT);
strXSLT = "";
strXSLT += "\n";
strXSLT += "\n";
strXSLT += "\n";
strXSLT += "\n";
strXSLT += " \n";
strXSLT += "\n";
strXSLT += "\n";
strXSLT += " \n";
strXSLT += " selected\n";
strXSLT += " \n";
strXSLT += "\n";
strXSLT += "\n";
strXSLT += "\n";
var strNewSelectedSnip = design_transform(strOrigDataList, strXSLT);
strXSLT = "";
strXSLT += "\n";
strXSLT += "\n";
strXSLT += "\n";
//// strXSLT += "\n";
//// strXSLT += strOrigDataList; // original OPTION list
//// strXSLT += "\n";
// Sarissa bug The document('') function is the web page in IE6 and the xml source document in Mozilla
//// strXSLT += "\n";
strXSLT += "\n";
strXSLT += " \n";
strXSLT += "\n";
strXSLT += "\n";
strXSLT += " \n";
strXSLT += " \n";
strXSLT += " \n";
strXSLT += " \n";
//// strXSLT += " \n";
//// strXSLT += " selected\n";
//// strXSLT += " \n";
strXSLT += strNewSelectedSnip;
strXSLT += " \n";
strXSLT += " \n";
strXSLT += " \n";
strXSLT += "\n";
strXSLT += " \n";
strXSLT += " \n";
strXSLT += " \n";
strXSLT += " \n";
strXSLT += " \n";
strXSLT += "\n";
strXSLT += "";
// Transform
var xmlDoc = design_transformToDocument(strNewDataList, strXSLT);
return xmlDoc;
}
function design_getDataList(strDDFieldTagName, strSource, strSelect, strCaptionXPath, strValueXPath, strNamespaces)
{
// Fetches data list from strSource
// assert("SELECT" == strDDFieldTagName || "DIV" == strDDFieldTagName)
var strPrefixes = "";
if ("undefined" == typeof strNamespaces || null == strNamespaces)
{
strNamespaces = "";
}
else
{
strPrefixes = design_extractPrefixesFromNamespaces(strNamespaces);
if (strPrefixes.length > 0)
{
strPrefixes = " exclude-result-prefixes=\"" + strPrefixes + "\"";
}
}
var strXSLT = "";
strXSLT += "\n";
strXSLT += "\n";
strXSLT += "\n";
strXSLT += "\n";
strXSLT += " \n";
strXSLT += "\n";
strXSLT += "";
// Transform
var strHtml = design_transform(strSource, strXSLT);
strHtml = strHtml.replace(/^\s+/,"").replace(/\s+$/,""); // trim
if (strHtml.indexOf("