var isIE = false;
var isFF = false;
var isOP = false;
var isSafari = false;
function DetectBrowser() {
var val = navigator.userAgent.toLowerCase();
if(val.indexOf("firefox") > -1) { isFF = true; }
else if(val.indexOf("opera") > -1) { isOP = true; }
else if(val.indexOf("msie") > -1) { isIE = true; }
else if(val.indexOf("safari") > -1) { isIE = true; }
}
function trim(str) {
a = str.replace(/^\s+/, '');
a = a.replace(/\s+$/, '');
return a;
}
function $$(obj) {
return document.getElementById(obj);
}
function toggle(id){
if(typeof(id) == 'string' && !$$(id)) return;
if(typeof(id) == 'string')
var div = $$(id);
else
div = id;
if(div.style.display == 'none')
div.style.display = 'block';
else
div.style.display = 'none';
}
function editcell(div){
if(currentCell && currentCell.getAttribute('edit') != 'false') return; //only allow editing if the current cell is not being edited.
currentCell = div;
var str = div.innerHTML;
var editting = div.getAttribute('edit');
if(editting == 'false'){
var width = currentCell.offsetWidth;
div.getElementsByTagName('textarea')[0].style.width = width + "px";
div.style.width = width + "px";
div.setAttribute('edit', 'true');
div.setAttribute('myvalue',div.getElementsByTagName('textarea')[0].value);
toggle(div.getElementsByTagName('div')[0]);
toggle(div.getElementsByTagName('textarea')[0]);
div.getElementsByTagName('textarea')[0].focus();
div.getElementsByTagName('textarea')[0].select();
}
}
function opencell(div){
var url = actioncell(div);
return helppopup(url,w=1400,h=900);
}
function ajaxcell(div,func){
func = (func != null ) ? func : '';
currentCell = div;
var url = actioncell(div);
ajax({url:url,f:func});
}
function ajaxcellpopup2(str){
return ajaxcellpopup(str, true)
}
function ajaxcellpopup(str, goUpThenDownDom){
//FF and IE, can't just set innerHTML,
//FF you need to add to dom, and it works perfectly.
//IE set innerHTML, and then do a runScripts on it to execute all the script tags.
//2nd OPTION - You could add through the dom, and make sure that you have the defer='defer' in the script tag so it works in IE.
var rand=Math.floor(Math.random()*11000);
var newdiv = document.createElement("div");
var div = currentCell;
if(goUpThenDownDom == true){
while(div.className != 'd1'){
div = div.parentNode;
}
div = div.firstChild;
while(div.className != 'inner'){
div = div.nextSibling;
}
}
else{
while(div.className != 'inner'){
div = div.parentNode;
}
}
div.parentNode.insertBefore(newdiv,div);
newdiv.innerHTML = ''+str;
runScripts(newdiv);
document.location = '#jumpto_'+rand;
window.scrollTo(0,window.pageYOffset -50);
return;
}
//this makes it so that you can eval the code and any variables or functions set will be global.
function evalGlobal(code) {
//eval(code); return;
if (!!(window.attachEvent && !window.opera)) {
execScript (code); // ie
} else {
window.eval (code); // not ie
}
}
function runScripts(e) {
if (e.nodeType != 1) return; //if it's not an element node, return
if (e.tagName.toLowerCase() == 'script') {
evalGlobal(e.text); //run the script
}
else {
var n = e.firstChild;
while ( n ) {
if ( n.nodeType == 1 ) runScripts( n ); //if it's an element node, recurse
n = n.nextSibling;
}
}
}
function updateCell(event,div){
var key = getKey(event);
if(!(key == 'ENTER' || key == 'ESCAPE')) return;
if(key == 'ENTER'){
//save
div.getElementsByTagName('textarea')[0].value = trim(div.getElementsByTagName('textarea')[0].value);
div.setAttribute('myvalue', div.getElementsByTagName('textarea')[0].value);
var url = actioncell(div);
ajax({url:url,f:'updateCell2'});
return false;
}
if(key == 'ESCAPE'){
resetCell();
}
}
function updateCell2(str){
if(str != 'true'){
alert(str);
return;
}
resetCell(true);
}
function resetCell(update){
var div = currentCell;
if(!div) return;
if(update){
var temp = div.getElementsByTagName('textarea')[0].value;
var sRegExInput2 = new RegExp("\n", "g");
temp = temp.replace(sRegExInput2, '
');
div.getElementsByTagName('div')[0].innerHTML = temp;
div.setAttribute('myvalue',div.getElementsByTagName('textarea')[0].value);
}
else{
div.getElementsByTagName('textarea')[0].value = div.getAttribute('myvalue');
//div.getElementsByTagName('textarea')[0].value = div.getElementsByTagName('div')[0].innerHTML;
//div.setAttribute('myvalue',div.getElementsByTagName('div')[0].innerHTML);
}
div.setAttribute('edit', 'false');
toggle(div.getElementsByTagName('div')[0]);
toggle(div.getElementsByTagName('textarea')[0]);
}
function actioncell(div){
var str = div.getAttribute('myaction');
var parentrow = div.parentNode;
var columnNames = new Array();
//get the header row of the table.
var div2 = div.parentNode.parentNode.firstChild;
//alert(div2.innerHTML);
//return;
for(var i = 0 ; i < div2.childNodes.length; i++){
if(div2.childNodes[i].nodeType != 1) continue; //if it is not an element tag, skip it.
columnNames.push(div2.childNodes[i].getAttribute('myvalue'));
}
var j = 0;
for(var i = 0 ; i < parentrow.childNodes.length; i++){
if(parentrow.childNodes[i].nodeType != 1) continue; //if it is not an element tag, skip it.
var sRegExInput = new RegExp('##'+columnNames[j]+'##', "g");
str = str.replace(sRegExInput, encodeURIComponent(parentrow.childNodes[i].getAttribute('myvalue')));
j++;
}
return str;
}
function getKey(e){ //e is event object passed from function invocation
var characterCode;// literal character code will be stored in this variable
if(e){
//e = event;
characterCode = e.keyCode //character code is contained in IE's keyCode property
}
if(characterCode == 13) return 'ENTER';
if(characterCode == 27) return 'ESCAPE';
}
var currentCell = null;
//==========TABS===============
function insertAtCursor(myField, myValue) {
//IE support
if (document.selection){
myField.focus();
sel = document.selection.createRange();
sel.text = myValue;
}
//MOZILLA/NETSCAPE support
else if (myField.selectionStart || myField.selectionStart == '0')
{
var startPos = myField.selectionStart;
var endPos = myField.selectionEnd;
restoreTop = myField.scrollTop;
myField.value = myField.value.substring(0, startPos) + myValue + myField.value.substring(endPos, myField.value.length);
myField.selectionStart = startPos + myValue.length;
myField.selectionEnd = startPos + myValue.length;
if (restoreTop>0)
{
myField.scrollTop = restoreTop;
}
}
else
{
myField.value += myValue;
}
}
function interceptTabs(evt, control)
{
//$$('saveContent_ajax').innerHTML = 'There are unsaved changes.';
key = evt.keyCode ? evt.keyCode : evt.which ? evt.which : evt.charCode;
if (key==9)
{
insertAtCursor(control, '\t');
return false;
}
else
{
return key;
}
}
//==========AJAX================================================================
function getFormValues(formId)
{
if(!$$(formId))
return {};
var f = $$(formId);
var obj = new Object;
var str = '';
var elem = f.elements;
for(var i = 0; i < elem.length; i++)
{
elemName = undefined;
if(elem[i].name != "" && elem[i].name != undefined){
elemName= elem[i].name;
}
else if(elem[i].id){
elemName = elem[i].id;
}
//if(elem[i].name){
//elemName = elem[i].name;}
//str += "Type:" + elem[i].type + "  ";
/*
if(elem[i].name==""||elem[i].name==undefined)
elemName= "notNamedElement";
else
elemName= elem[i].name;
*/
switch (elem[i].type) {
case "select-multiple":
var arSelected = new Array();
ob=elem[i];
for(var j=0;j 1 && !vars.skipCheck) {
ajaxConnections--; //added Nov 2, 2010 to fix the bug where you get stuck in a waiting state.
alert("Please wait while other actions are processing. (i.e. don't double-click.)");
return;
ajaxArray.push(vars);
return;
}
var formvars = getFormValues(vars.formid);
var varStr = '';
for(var i in formvars) {
if (formvars[i] instanceof Array) {for (var k in formvars[i]) {varStr += "&" + i + "=" + encodeURIComponent(formvars[i][k]);}}
else {varStr += '&' + i + '=' + encodeURIComponent(formvars[i]);}
}
for(var j in vars.vars){varStr += '&' + j + '=' + encodeURIComponent(vars.vars[j]);}
vars.str += varStr;
// Mozilla/Safari
if (window.XMLHttpRequest) {
xmlHttpReq = new XMLHttpRequest();
}
// IE
else if (window.ActiveXObject) {
xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlHttpReq.open('POST', vars.url, true);
xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
xmlHttpReq.onreadystatechange = function() {
if (this.readyState == 4) {
ajaxConnections--;
var temp = this.responseText;
//alert(temp);
if(vars.f == 'evalHTML'){
var div = vars.params.id;
if($$(div)){
div = $$(div);
div.innerHTML = temp;
runScripts(div);
}
}
else{
eval(vars.f + "(temp,vars.params);");
}
if(ajaxArray.length > 0) {
ajaxConnections--;
var ob2 = ajaxArray.pop();
ob2.skipCheck = true;
ajax(ob2);
}
}
}
xmlHttpReq.send(vars.str);
}
//End Ajax()
function helppopup(mylink,w,h,text)
{
var myref = '';
if (!window.focus)return true;
var href;
if (typeof(mylink) == 'string')
href=mylink;
else
href=mylink.href;
w = (w != null) ? w : '700';
h = (h != null) ? h : '550';
if (text == undefined) {
myref=window.open(href,'_blank','width=' + w + ',height=' + h + ',resizable=yes,scrollbars=yes,location=no,toolbar=yes');
}
else {
myref=window.open('','_blank','width=' + w + ',height=' + h + ',toolbar=yes,resizable=no,scrollbars=no,location=yes');
myref.document.write(""+text);
myref.document.close();
}
return false;
}
//=================
function shiftMouseUp(e) { if (!e.shiftKey) { shiftPressed = 0; } return true; }
function shiftMouseDown(e) { shiftPressed = e.shiftKey; return true; }
var shiftPressed = 0;
var lastClickedCheckbox = new Array();
function shiftclick(chbx) {
document.onmouseup = shiftMouseUp;
document.onmousedown = shiftMouseDown;
shiftClickStart = lastClickedCheckbox[chbx.getAttribute('groupid')];
if (shiftPressed) {
if (shiftClickStart == 0) {
shiftClickStart = parseInt(chbx.getAttribute('shiftclickid'));
}
else {
var clickedto = parseInt(chbx.getAttribute('shiftclickid'));
var a = chbx.checked;
var inputs = document.getElementsByTagName('input');
for (var i = 0; i < inputs.length; i++) {
if (inputs[i].type == 'checkbox') {
if(chbx.getAttribute('groupid') != inputs[i].getAttribute('groupid')) continue;
var csc = parseInt(inputs[i].getAttribute('shiftclickid'));
if (shiftClickStart > clickedto && csc <= shiftClickStart && csc >= clickedto) {
inputs[i].checked = a;
}
else if (shiftClickStart < clickedto && csc >= shiftClickStart && csc <= clickedto) {
inputs[i].checked = a;
}
else if (shiftClickStart == clickedto) {
inputs[i].checked = a;
}
}
}
shiftClickStart = 0;
}
}
lastClickedCheckbox[chbx.getAttribute('groupid')] = chbx.getAttribute('shiftclickid');
}
function clickGroup(groupid){
var boxes = new Array();
var inputs = document.getElementsByTagName('input');
for (var i = 0; i < inputs.length; i++) {
if (inputs[i].type == 'checkbox' && groupid == inputs[i].getAttribute('groupid') && inputs[i].checked) {
boxes.push(inputs[i].getAttribute('myvalue'));
}
}
return boxes.join(',');
}
//==================