function hideselectlist() {
    var is_ie5_5 = null;
    var is_ie6 = null;

    try {
        var is_major = parseInt(navigator.appVersion);
        is_ie5_5  = ((is_major == 4) && (browserInfo.userAgent.indexOf("msie 5.5") !=-1));
        is_ie6    = ((is_major == 4) && (browserInfo.userAgent.indexOf("msie 6.")!=-1) );
    } catch(e) {
        // do nothing
    }
    try {
        if(is_ie5_5 || is_ie6){
            var formRoot = getObj('conframe') ? getObj('conframe').contentWindow.document.body : null;
            var formRoot1 = getObj('navframe') ? getObj('navframe').contentWindow.document.body : null;
            var formRoot2 = getObj('jobframe') ? getObj('jobframe').contentWindow.document.body : null;
            var formRoot3 = document.getElementById('formRoot1');
            var formRoot4 = document.getElementById('formRoot2');
            var formRoot5 = document.getElementById('formRoot3');
            var selectLists = null;

            if (formRoot != null) { selectLists = formRoot.getElementsByTagName('select'); for (var i = 0; i < selectLists.length; i++) { selectLists[i].style.visibility = 'hidden'; }}
            if (formRoot1 != null) { selectLists = formRoot1.getElementsByTagName('select'); for (var i = 0; i < selectLists.length; i++) selectLists[i].style.visibility = 'hidden'; }
            if (formRoot2 != null) { selectLists = formRoot2.getElementsByTagName('select'); for (var i = 0; i < selectLists.length; i++) selectLists[i].style.visibility = 'hidden'; }
            if (formRoot3 != null) { selectLists = formRoot3.getElementsByTagName('select'); for (var i = 0; i < selectLists.length; i++) selectLists[i].style.visibility = 'hidden'; }
            if (formRoot4 != null) { selectLists = formRoot4.getElementsByTagName('select'); for (var i = 0; i < selectLists.length; i++) selectLists[i].style.visibility = 'hidden'; }
            if (formRoot5 != null) { selectLists = formRoot5.getElementsByTagName('select'); for (var i = 0; i < selectLists.length; i++) selectLists[i].style.visibility = 'hidden'; }
        }
    } catch(e) {
        // do nothing
    }
}

function showselectlist() {
    var is_ie5_5 = null;
    var is_ie6 = null;

    try {
        var is_major = parseInt(navigator.appVersion);
        is_ie5_5  = ((is_major == 4) && (browserInfo.userAgent.indexOf("msie 5.5") !=-1));
        is_ie6    = ((is_major == 4) && (browserInfo.userAgent.indexOf("msie 6.")!=-1) );
    } catch(e) {
        // do nothing
    }
    try {
        if(is_ie5_5 || is_ie6){
            var formRoot = getObj('conframe') ? getObj('conframe').contentWindow.document.body : null;
            var formRoot1 = getObj('navframe') ? getObj('navframe').contentWindow.document.body : null;
            var formRoot2 = getObj('jobframe') ? getObj('jobframe').contentWindow.document.body : null;
            var formRoot3 = document.getElementById('formRoot1');
            var formRoot4 = document.getElementById('formRoot2');
            var formRoot5 = document.getElementById('formRoot3');
            var selectLists = null;

            if (formRoot != null) { selectLists = formRoot.getElementsByTagName('select'); for (var i = 0; i < selectLists.length; i++) selectLists[i].style.visibility = 'visible'; }
            if (formRoot1 != null) { selectLists = formRoot1.getElementsByTagName('select'); for (var i = 0; i < selectLists.length; i++) selectLists[i].style.visibility = 'visible'; }
            if (formRoot2 != null) { selectLists = formRoot2.getElementsByTagName('select'); for (var i = 0; i < selectLists.length; i++) selectLists[i].style.visibility = 'visible'; }
            if (formRoot3 != null) { selectLists = formRoot3.getElementsByTagName('select'); for (var i = 0; i < selectLists.length; i++) selectLists[i].style.visibility = 'visible'; }
            if (formRoot4 != null) { selectLists = formRoot4.getElementsByTagName('select'); for (var i = 0; i < selectLists.length; i++) selectLists[i].style.visibility = 'visible'; }
            if (formRoot5 != null) { selectLists = formRoot5.getElementsByTagName('select'); for (var i = 0; i < selectLists.length; i++) selectLists[i].style.visibility = 'visible'; }
        }
    } catch(e) {
        // do nothing
    }
}
function top_mm1_alert(text, hrefFunction, icon, headerText) {
    if (Modalbox.initialized)
        setTimeout('messageBox.alert(\''+text+'\',\''+hrefFunction+'\',\''+icon+ '\',\'' + headerText + '\')',750);
    else
        messageBox.alert(text, hrefFunction, icon, headerText);
}
function top_mm1_confirm(text, hrefFunction, headerText) {
    if (Modalbox.initialized)
        setTimeout('messageBox.confirm(\'' + text + '\',\'' + hrefFunction + '\',\'' + headerText + '\')', 750);
    else
        messageBox.confirm(text, hrefFunction, headerText);
}
function top_mm1_prompt(text, feldtext, hrefFunction, headerText) {
    if (Modalbox.initialized)
        setTimeout('messageBox.prompt(\'' + text + '\',\'' + feldtext + '\',\'' + hrefFunction + '\',\'' + headerText + '\')', 750);
    else
        messageBox.prompt(text, feldtext, hrefFunction, headerText);
}

function mmMessageBox() {
    this.alert_text = "Alert";
    this.confirm_text = "Confirm";
    this.promt_text = "Prompt";
    this.ok_text = "OK";
    this.cancel_text = "Cancel"
}
mmMessageBox.prototype = {
    alert:function(text, hrefFunction, icon, headerText) {
        hideselectlist();
        if (hrefFunction) {
            hrefFunction += ';';
        } else {
            hrefFunction = '';
        }
        if(icon==null || icon == "undefined" || icon == "") icon = "message.stop.gif";
        if(!headerText) headerText = this.alert_text;
            Modalbox.show(Builder.build('<table cellspacing="0" cellpadding="0" border="0" style="width:100%">' +
                                            '<tr><td colspan="2">' +
                                                '<table cellspacing="0" cellpadding="0" border="0" style="background-color:#EEEEEE; width:100%">' +
                                                    '<tr style="height:40px"><td style="width:30px; text-align:center; padding-right:10px"><img src="images/buttons/'+icon+'" alt="Warning"></td><td width="*" valign="middle" style="font-weight:bold;font-size:12px">'+text+'<br></td></tr>' +
                                                    '<tr><td colspan="2" width="*" valign="top" style="height:30px">' +
                                                            '<table align="center"><tr>' +
                                                                '<td><div style="white-space: nowrap;" class="glowingtabs"><ul><li><a title="'+this.ok_text+'" href=\'javascript:Modalbox.hide();'+hrefFunction+'\'><span style=\"padding:3px 12px 3px 12px;\">'+this.ok_text+'</span></a></li></ul></div></td>' +
                                                            '</tr></table>' +
                                                     '</td></tr>' +
                                                    '</tr>' +
                                                '</table></td>' +
                                            '</tr>' +
                                        '</table>'), {title: headerText, height: 130, overlayOpacity: 0.4, width: 440});
    },
    confirm:function(text, hrefFunction, headerText) {
        hideselectlist();
        if(!headerText) headerText = this.alert_text;
        Modalbox.show(Builder.build('<table cellspacing="0" cellpadding="0" border="0" style="width:100%">' +
                                            '<tr><td colspan="2">' +
                                                '<table cellspacing="0" cellpadding="0" border="0" style="background-color:#EEEEEE; width:100%">' +
                                                    '<tr style="height:40px"><td style="width:30px; text-align:center; padding-right:10px"><img src="images/buttons/message.warning.gif" alt="Confirm"></td><td width="*" valign="middle" style="font-weight:bold;font-size:12px">'+text+'<br></td></tr>' +
                                                    '<tr><td colspan="2" width="*" valign="top" style="height:30px">' +
                                                            '<table align="center"><tr>' +
                                                                '<td><div style="white-space: nowrap;" class="glowingtabs"><ul><li><a title="'+this.ok_text+'" href=\'javascript:Modalbox.hide();'+hrefFunction+';\'><span style=\"padding:3px 12px 3px 12px;\">'+this.ok_text+'</span></a></li></ul></div></td>' +
                                                                '<td><div style="white-space: nowrap;" class="glowingtabs"><ul><li><a title="'+this.cancel_text+'" href="javascript:Modalbox.hide();"><span style=\"padding:3px 12px 3px 12px;\">'+this.cancel_text+'</span></a></li></ul></div></td>' +
                                                            '</tr></table>' +
                                                     '</td></tr>' +
                                                    '</tr>' +
                                                '</table></td>' +
                                            '</tr>' +
                                        '</table>'), {title: headerText, height: 135, overlayOpacity: 0.4, width: 390});
    },
    prompt:function(text, feldtext, hrefFunction, headerText) {
        hideselectlist();
        if(!headerText) headerText = this.alert_text;
        Modalbox.show(Builder.build('<table cellspacing="0" cellpadding="0" border="0" style="width:100%">' +
                                '<tr><td colspan="2">' +
                                    '<table cellspacing="0" cellpadding="0" border="0" style="background-color:#EEEEEE; width:100%">' +
                                        '<tr style="height:40px"><td style="width:30px; text-align:center; padding-right:10px"><img src="images/buttons/message.about.gif" alt="Prompt"></td><td width="*" valign="middle" style="font-weight:bold;font-size:12px;">'+text+'<br></td></tr>' +
                                        '<tr>'+
                                            '<td style=";width:30px; text-align:center;"><br></td>'+
                                            '<td width="*" valign="middle" style="height:30px;font-weight:bold;font-size:16px;"><input id="dojoName" type="text" name="oldpw" size="60" style="width:350px"onkeypress=\'if(event.which==13){Modalbox.hide();'+hrefFunction+'(this.value);} try {if(window.event.keyCode==13){Modalbox.hide();'+hrefFunction+'(this.value);} } catch(e) {}\' value="'+feldtext+'" style="font-size:11px"></td>' +
                                        '</tr>' +
                                        '<tr><td colspan="2" width="*" valign="top" style="height:30px;">' +
                                                '<table align="center"><tr>' +
                                                    '<td><div style="white-space: nowrap;" class="glowingtabs"><ul><li><a title="'+this.ok_text+'" href=\'javascript:Modalbox.hide();'+hrefFunction+'(document.getElementById(\"dojoName\").value);\'><span style=\"padding:3px 12px 3px 12px;\">'+this.ok_text+'</span></a></li></ul></div></td>' +
                                                    '<td><div style="white-space: nowrap;" class="glowingtabs"><ul><li><a title="'+this.cancel_text+'" href="javascript:Modalbox.hide();"><span style=\"padding:3px 12px 3px 12px;\">'+this.cancel_text+'</span></a></li></ul></div></td>' +
                                                '</tr></table>' +
                                         '</td></tr>' +
                                        '</tr>' +
                                    '</table></td>' +
                                '</tr>' +
                            '</table>'), {title: headerText, height: 150, overlayOpacity: 0.4, width: 440});
    }
}

/* dom object retrieval functions */

function getObj(name) {
  if (document.getElementById) {
    return document.getElementById(name);
  } else if (document.all) {
    return document.all[name];
  } else if (document.layers) {
    return getObjNN4(document,name);
  }
}

/** Find the first object containing an attribute of the given name, starting
    at the source element of the given event. */
function getDragObject(event, attributeName) {
    var cur = document.all ? window.event.srcElement : event.target;
    while (cur != null && cur.tagName != "BODY" && cur.getAttribute(attributeName) == null)
        cur = cur.parentNode;
    return cur;
}

function getFrameObj(frame, name) {
  if (frames[frame] == null || frames[frame].document == null) {
    return null;
  } else if (frames[frame].document.getElementById) {
    return frames[frame].document.getElementById(name);
  } else if (frames[frame].document.all) {
    return frames[frame].document.all[name];
  } else if (frames[frame].document.layers) {
    return getObjNN4(frame, frames[frame].document,name);
  }
}

function getObjNN4(obj,name) {
    var x = obj.layers;
    var thereturn;
    for (var i=0;i<x.length;i++) {
        if (x[i].id == name)
            thereturn = x[i];
        else if (x[i].layers.length)
            var tmp = getObjNN4(x[i],name);
        if (tmp) thereturn = tmp;
    }
    return thereturn;
}

function findPosX(obj,ignoreScrollOffset) {
    if (!obj)
        return;
    var curleft = 0;
    if (obj.offsetParent)
    {
        while (obj.offsetParent && obj.style.position!='absolute')
        {
            curleft += obj.offsetLeft;
            if (ignoreScrollOffset) {
                // ignore offset
            } else {
                if (obj.scrollLeft!=0) curleft -= obj.scrollLeft;
            }
            obj = obj.offsetParent;
        }
    }
    else if (obj.x)
        curleft += obj.x;
    return curleft;
}

function findPosY(obj,ignoreScrollOffset) {
    if (!obj)
        return;
    var curtop = 0;
    if (obj.offsetParent) {
        while (obj.offsetParent && obj.style.position!='absolute') {
            curtop += obj.offsetTop;
            if (ignoreScrollOffset) {
                // ignore offset
            } else {
                if (obj.scrollTop!=0) curtop -= obj.scrollTop;
            }
            obj = obj.offsetParent;
        }
    } else if (obj.y)
        curtop += obj.y;
    return curtop;
}

function getScrollTop(document) {
    var scrollTop = 0;
    if (document.documentElement && document.documentElement.scrollTop) {
        scrollTop = document.documentElement.scrollTop;
    } else if (document.body && document.body.scrollTop) {
        scrollTop = document.body.scrollTop;
    }
    return scrollTop;
}

/* navigation area slider functions */

var slPageDivider;
var slPageDividerBottom;
var slLeftArea;
var slLeftAreaBottom;
var slNavArea;
var slNavAreaBottom;
var slRightArea;
var slRightAreaBottom;
var slDoResize = false;
var slToggleOn = false;
var lockMouseOver = false;

function slOnMouseOver(ev) {
    if(!lockMouseOver) {
        var slidertoggle = document.getElementById('slidertoggle');

        if(slidertoggle != null) {
            var pagedivider = document.getElementById('pagedivider');

            if(pagedivider != null) {
                pagedivider.style.cursor = 'default';
            }

            slidertoggle.src = "images/hide_slider_border.gif";
            slToggleOn = true;
        }
    }
}

function slOnMouseOut(ev) {
    var slidertoggle = document.getElementById('slidertoggle');

    if(slidertoggle != null) {
        var pagedivider = document.getElementById('pagedivider');

        if(pagedivider != null) {
            pagedivider.style.cursor = 'move';
        }

        slidertoggle.src = "images/hide_slider.gif";
        slToggleOn = false;
    }
}

function slBeginDrag(ev) {
    var slidertoggle = document.getElementById('slidertoggle');
    var navframe = document.getElementById('navframe');

    lockMouseOver = true;

    if(slidertoggle != null) {
        if(slToggleOn) {
            if(navframe != null) {
                var clientX = 260;

                slPageDivider = getObj('pagedivider');
                slPageDividerBottom = getObj('pagedividerbottom');
                slLeftArea = getObj('leftarea');
                slLeftAreaBottom = getObj('leftareabottom');
                slNavArea = getObj('navarea');
                slNavAreaBottom = getObj('navareabottom');
                slRightArea = getObj('rightarea');
                slRightAreaBottom = getObj('rightareabottom');

                if(navframe.style.display == 'none') {
                    clientX=260;
                    navframe.style.display = '';
                }
                else {
                    clientX = 5;
                    navframe.style.display = 'none';
                }

                if ( slPageDivider && get_cookie(slPageDivider.id) && navframe.style.display != 'none') {
                    slPageDivider.style.left = get_cookie(slPageDivider.id);
                }
                else if (slPageDivider) {
                    slPageDivider.style.left = clientX + "px";
                }

                if ( slPageDividerBottom && get_cookie(slPageDividerBottom.id) && navframe.style.display != 'none') {
                    slPageDividerBottom.style.left = get_cookie(slPageDividerBottom.id);
                }
                else if(slPageDividerBottom) {
                    slPageDividerBottom.style.left = clientX + "px";
                }

                if ( slLeftArea && get_cookie(slLeftArea.id) && navframe.style.display != 'none') {
                    slLeftArea.style.width = get_cookie(slLeftArea.id);
                }
                else if(slLeftArea) {
                    slLeftArea.style.width = clientX + "px";
                }

                if ( slLeftAreaBottom && get_cookie(slLeftAreaBottom.id) && navframe.style.display != 'none') {
                    slLeftAreaBottom.style.width = get_cookie(slLeftAreaBottom.id);
                }
                else if(slLeftAreaBottom) {
                    slLeftAreaBottom.style.width = clientX + "px";
                }

                if ( slNavArea && get_cookie(slNavArea.id) && navframe.style.display != 'none') {
                    slNavArea.style.width = get_cookie(slNavArea.id);
                }
                else if(slNavArea) {
                    slNavArea.style.width = clientX-5 + "px";
                }

                if ( slNavAreaBottom && get_cookie(slNavAreaBottom.id) && navframe.style.display != 'none') {
                    slNavAreaBottom.style.width = get_cookie(slNavAreaBottom.id);
                }
                else if(slNavAreaBottom) {
                    slNavAreaBottom.style.width = clientX-5 + "px";
                }

                if ( slRightArea && get_cookie(slRightArea.id) && navframe.style.display != 'none') {
                    slRightArea.style.left = get_cookie(slRightArea.id);
                }
                else if(slRightArea) {
                    slRightArea.style.left = clientX + "px";
                }

                if ( slRightAreaBottom && get_cookie(slRightAreaBottom.id) && navframe.style.display != 'none') {
                    slRightAreaBottom.style.left = get_cookie(slRightAreaBottom.id);
                }
                else if(slRightAreaBottom) {
                    slRightAreaBottom.style.left = clientX + "px";
                }

                adjustDiv();

                try {
                    ev.stopPropagation(); //Stop propagation so no
                    ev.preventDefault(); //one else handles it
                    slOnMouseOut(ev);
                } catch(e) {
                    slOnMouseOut(ev);
                }
            }
            else {
                slOnMouseOut(ev);
            }
            return false;
        }
    }

    if(navframe != null) {
        if(navframe.style.display == 'none') {
            try {
                ev.stopPropagation(); //Stop propagation so no
                ev.preventDefault(); //one else handles it
                slOnMouseOut(ev);
            } catch(e) {
                slOnMouseOut(ev);
            }
            return false;
        }
    }

  slDoResize = true;
  slPageDivider = getObj('pagedivider');
  slPageDividerBottom = getObj('pagedividerbottom');
  slLeftArea = getObj('leftarea');
  slLeftAreaBottom = getObj('leftareabottom');
  slNavArea = getObj('navarea');
  slNavAreaBottom = getObj('navareabottom');
  slRightArea = getObj('rightarea');
  slRightAreaBottom = getObj('rightareabottom');
  var slbg = getObj('slbg');
  slbg.style.display='block';
  try {
    ev.stopPropagation(); //Stop propagation so no
    ev.preventDefault(); //one else handles it
    slOnMouseOut(ev);
  } catch(e) {
      slOnMouseOut(ev);
  }
  return true;
}

function slDrag(ev) {
	if(!slToggleOn) {
        var clientX = ev.clientX;
        var navframe = document.getElementById('navframe');

        if(navframe != null) {
            if(navframe.style.display != 'none') {
                if (clientX<260) clientX=260;
            }
            else {
                return true;
            }
        }
        else {
            if (clientX<260) clientX=260;
        }

        if (slDoResize) {
            if (slPageDivider) slPageDivider.style.left = clientX + "px";
            if (slPageDividerBottom) slPageDividerBottom.style.left = clientX + "px";
            if (slLeftArea) slLeftArea.style.width = clientX + "px";
            if (slLeftAreaBottom) slLeftAreaBottom.style.width = clientX + "px";
            if (slNavArea) slNavArea.style.width = clientX-5 + "px";
            if (slNavAreaBottom) slNavAreaBottom.style.width = clientX-5 + "px";
            if (slRightArea) slRightArea.style.left = clientX + "px";
            if (slRightAreaBottom) slRightAreaBottom.style.left = clientX + "px";
            adjustDiv();
        }
    }
    return true;
}

function slDrop(ev) {
    var navframe = document.getElementById('navframe');

    if(navframe != null) {
        if(navframe.style.display == 'none') {
            if(lockMouseOver) {
                lockMouseOver = false;
            }
            return true;
        }
    }

    slDrag(ev);
	slDoResize = false;
	  var slbg = getObj('slbg');
  	slbg.style.display='none';

	var expdays = 365;
    var expdate = new Date ();
    expdate.setTime (expdate.getTime() + (expdays*24*60*60*1000)); // expiry date
    var path="/"; // path="/" top directory, path=null this documents root directory

    if (slPageDivider) set_cookie(slPageDivider.id,slPageDivider.style.left,expdate,path);
    if (slPageDividerBottom) set_cookie(slPageDividerBottom.id,slPageDividerBottom.style.left,expdate,path);
    if (slLeftArea) set_cookie(slLeftArea.id,slLeftArea.style.width,expdate,path);
    if (slLeftAreaBottom) set_cookie(slLeftAreaBottom.id,slLeftAreaBottom.style.width,expdate,path);
    if (slNavArea) set_cookie(slNavArea.id,slNavArea.style.width,expdate,path);
    if (slNavAreaBottom) set_cookie(slNavAreaBottom.id,slNavAreaBottom.style.width,expdate,path);
    if (slRightArea) set_cookie(slRightArea.id,slRightArea.style.left,expdate,path);
    if (slRightAreaBottom) set_cookie(slRightAreaBottom.id,slRightAreaBottom.style.left,expdate,path);

    if(lockMouseOver) {
        lockMouseOver = false;
    }

    return true;
}

function slLoad(ev) {
	slPageDivider = getObj('pagedivider');
	slPageDividerBottom = getObj('pagedividerbottom');
	slLeftArea = getObj('leftarea');
	slLeftAreaBottom = getObj('leftareabottom');
	slNavArea = getObj('navarea');
	slNavAreaBottom = getObj('navareabottom');
	slRightArea = getObj('rightarea');
	slRightAreaBottom = getObj('rightareabottom');
    if ( slPageDivider && get_cookie(slPageDivider.id) ) slPageDivider.style.left = get_cookie(slPageDivider.id);
    if ( slPageDividerBottom && get_cookie(slPageDividerBottom.id) ) slPageDividerBottom.style.left = get_cookie(slPageDividerBottom.id);
    if ( slLeftArea && get_cookie(slLeftArea.id) ) slLeftArea.style.width = get_cookie(slLeftArea.id);
    if ( slLeftAreaBottom && get_cookie(slLeftAreaBottom.id) ) slLeftAreaBottom.style.width = get_cookie(slLeftAreaBottom.id);
    if ( slNavArea && get_cookie(slNavArea.id) ) slNavArea.style.width = get_cookie(slNavArea.id);
    if ( slNavAreaBottom && get_cookie(slNavAreaBottom.id) ) slNavAreaBottom.style.width = get_cookie(slNavAreaBottom.id);
    if ( slRightArea && get_cookie(slRightArea.id) ) slRightArea.style.left = get_cookie(slRightArea.id);
    if ( slRightAreaBottom && get_cookie(slRightAreaBottom.id) ) slRightAreaBottom.style.left = get_cookie(slRightAreaBottom.id);
    adjustDiv();
    return true;
}

function stopSelect(ev){
    if (slDoResize) {
        ev.returnValue=false;
    }
}

/* cookie functions */

function set_cookie(name, value, expires, path, domain, secure) {
	document.cookie =
		escape(name) + '=' + escape(value)
		+ (expires ? '; expires=' + expires.toGMTString() : '')
		+ (path ? '; path=' + path : '')
		+ (domain ? '; domain=' + domain : '')
		+ (secure ? '; secure' : '');
}

function get_cookie(name) {
	var cookieValue = '';
	var posName = document.cookie.indexOf(escape(name) + '=');
	if (posName != -1) {
		var posValue = posName + (escape(name) + '=').length;
		var endPos = document.cookie.indexOf(';', posValue);
		if (endPos != -1) cookieValue = unescape(document.cookie.substring(posValue, endPos));
		else cookieValue = unescape(document.cookie.substring(posValue));
	}
	return (cookieValue);
}

function delete_cookie(name,path,domain) {
    document.cookie = name + '=' +
    ((path == null) ? '' : '; path=' + path) +
    ((domain == null) ? '' : '; domain=' + domain) +
    '; expires=Thu, 01-Jan-00 00:00:01 GMT';
}

/* scrollposition functions */

function saveScroll(divId, pageId, expdays) { // added function
	if (!expdays) expdays = 365;
    var expdate = new Date ();
    expdate.setTime (expdate.getTime() + (expdays*24*60*60*1000)); // expiry date
    var path="/"; // path="/" top directory, path=null this documents root directory
    var x = getObj(divId).scrollLeft;
    var y = getObj(divId).scrollTop;
    var Data = x + "_" + y;
    set_cookie(pageId,Data,expdate,path);
}

function loadScroll(divId, pageId) { // added function
    var inf = get_cookie(pageId);
    if (!inf) { return }
    var ar = inf.split("_");
    if (ar.length == 2) {
        getObj(divId).scrollTop = parseInt(ar[1]);
        getObj(divId).scrollLeft = parseInt(ar[0]);
    }
}

/* function to swap images */
function changeImg(img_name,img_src) {
    if(img_name!='jobbar_barmode') {
        img = new Image();
        img.src = img_src;
        getObj(img_name).src=img_src;
    }
}

function trimPx(value) {
	if (value && (""+value).charAt(value.length-1)=="x") {
        value = value.substring(0, value.length-2);
	    return parseInt(value);
    } else {
        return value;
    }
}

/* loads page to top frame if it was loaded into any other frame */
function forceTopFraming() {
    if (self != top) {
	    if (document.images)
	        top.location.replace(window.location.href);
	    else
	        top.location.href = window.location.href;
	}
	//if (self != top) {
    //    top.location.href = self.location.href;
    //}
}

function URLencode(value) {
    return encodeURIComponent(value);
}

// unescapes text filtered with FormUtils.filter
function unescapeFilteredText(text) {
    return text.replace(/&#39;/g, "'").replace(/&quot;/g, '"').replace(/&lt;/g, "<").replace(/&gt;/g, ">");
}

// escape text filtered with FormUtils.filter
function escapeText(text) {
    return text.replace(/'/g,"&#39;").replace(/"/g,'&quot;').replace(/</g, "&lt;").replace(/>/g, "&gt;");
}

function formatDate(value) {
    if (value==null || value.length==0) return "";
    var date = new Date(parseInt(value));
    var month = ''+(date.getMonth()+1);
    var day = ''+date.getDate();
    return (date.getFullYear())+'-'+(month.length==1 ? '0'+month : month)+'-'+(day.length==1 ? '0'+day : day);
}

// -------- URL loading functions ---------
var globalCheckEditMessage = 'globalCheckEditMessage';
function globalCheckEditModeActive() {
    try {
        if( !parent.frames['conframe'])
            return false;
        var searchForm = parent.frames['conframe'].searchForm;
        var instanceForm = parent.frames['conframe'].instanceForm;
        if (searchForm && searchForm["instanceForm.editMode"] && searchForm["instanceForm.editMode"].value == "true") {
            top.top_mm1_alert(globalCheckEditMessage);
            return true;
        } else if (instanceForm && instanceForm.editMode && instanceForm.editMode.value == "true") {
            top.top_mm1_alert(globalCheckEditMessage);
            return true;
        } else
            return false;
    } catch(e) {
        return false;
    }
}

function loadOnCondition(checkFrame, checkString, targetFrame, targetUrl) {
    try {
        if (parent.frames[checkFrame].location.toString().indexOf(checkString)<0) {
            throw "Search page not loaded.";
        }
    } catch (e) {
        loadFrame(targetFrame, targetUrl);
    }
}

function loadUnlessPresent(object, targetFrame, targetUrl) {
    if (object && object == true) {
        // ignore
    } else {
        loadFrame(targetFrame, targetUrl);
    }
}

/* Media manager helper */
function loadFrame(targetFrame, targetUrl) {
    if (document.images) {
        parent.frames[targetFrame].location.replace(targetUrl);
    } else {
        parent.frames[targetFrame].location.href = targetUrl;
    }
}

function loadPage(targetUrl) {
    if (document.images) {
        top.document.location.replace(targetUrl);
    } else {
        top.document.location.href = targetUrl;
    }
}

/* Mars helper */
function loadUrl(frameName, url) {
    var frame = frames[frameName] != null ? frames[frameName] : parent.frames[frameName];
    if (frame == null) {
        return;
    }
    if (document.images) {
        frame.location.replace(url);
    } else {
        frame.location.href = url;
    }
}

function loadWindowAndCenter(targetUrl, windowName, width, height, style) {
    var left=(screen.width-width)/2;
    var top=(screen.height-height)/2;
    if (style == null)
        style = "resizable=yes,menubar=no,toolbar=no,status=no";
    style += ",width="+width;
    style += ",height="+height;
    style += ",left="+left;
    style += ",top="+top;
    return window.open(targetUrl, windowName, style);
}

function loadWindow(targetUrl, windowName, style) {
    if (style == null)
        style = "width=800,height=600,resizable=yes,menubar=no,toolbar=no,status=no";
    var theWindow = window.open(targetUrl, windowName, style);
    theWindow.focus();
}

function top_openEditSelectList(id,Uploadtitle) {
    hideselectlist();
    var srcUrl = getBase() + "admin/selectlist.do?action=editModalbox&modalbox=true&id="+id+"";
    var html = '<div id="iframediv">'+
                    '<iframe name="editselectlist" id="editselectlist" frameborder="no" scrolling="no" src=\''+srcUrl+'\' style="background-color:transparent;height:100%; width:100%" allowTransparency="true"></iframe>'+
               '</div>';
    var modalBoxHeight = top.document.body.clientHeight > 650 ? 650 : top.document.body.clientHeight;
    Modalbox.show(Builder.build(html), {title: Uploadtitle, overlayClose: false, overlayOpacity: 0.4, width:900, height:modalBoxHeight });
}

function top_openUploadPopup(targetUrl,Uploadtitle) {
    hideselectlist();
    var html = '<div id="iframediv">'+
                    '<iframe name="uploadpopup" id="uploadpopup" frameborder="no" scrolling="no" src=\''+targetUrl+'\' style="background-color:transparent;height:100%; width:100%" allowTransparency="true"></iframe>'+
               '</div>';
    var modalBoxHeight = top.document.body.clientHeight > 350 ? 350 : top.document.body.clientHeight;
    Modalbox.show(Builder.build(html), {title: Uploadtitle, overlayClose: false, overlayOpacity: 0.4, width:500, height:modalBoxHeight });
}

function top_showFullscreen(targetUrl) {
    hideselectlist();
    var html = '<div id="iframediv">'+
                    '<iframe name="fullscreen" id="fullscreen" frameborder="no" scrolling="no" src=\''+targetUrl+'\' style="background-color:transparent;height:100%; width:100%" allowTransparency="true"></iframe>'+
               '</div>';
    var modalBoxHeight = top.document.body.clientHeight > 600 ? 600 : top.document.body.clientHeight;
    Modalbox.show(Builder.build(html), {title:false, height: modalBoxHeight, overlayOpacity: 0.4, width: 800});
}

function top_showFullscreenInfo(target) {
    var targetUrl = getBase() + "archive/instance/node.popup.jsp" + target;
    hideselectlist();
    var html = '<div id="iframediv">'+
                    '<iframe name="fullscreen" id="fullscreen" frameborder="no" scrolling="no" src=\''+targetUrl+'\' style="background-color:transparent;height:100%; width:100%" allowTransparency="true"></iframe>'+
               '</div>';
    var modalBoxHeight = top.document.body.clientHeight > 600 ? 600 : top.document.body.clientHeight;
    Modalbox.show(Builder.build(html), {title:false, height: modalBoxHeight, overlayOpacity: 0.4, width: 800});
}

function top_showKeywordeditor(targetUrl, windowName) {
    hideselectlist();
    var html = '<div id="iframediv">'+
                    '<iframe name="keywordspopup" id="keywordspopup" frameborder="no" scrolling="no" src=\''+targetUrl+'\' style="background-color:transparent;height:100%; width:100%" allowTransparency="true"></iframe>'+
               '</div>';
    var modalBoxHeight = top.document.body.clientHeight > 650 ? 650 : top.document.body.clientHeight;
    Modalbox.show(Builder.build(html), {title: windowName, overlayClose: false, height: modalBoxHeight, overlayOpacity: 0.4, width: 800});
}

function top_openAssignItemsPopup(location,assignObjecttitle) {
    hideselectlist();
    var html = '<div id="iframediv">'+
                    '<iframe name="assignobjects" id="assignobjects" frameborder="no" scrolling="no" src=\''+location+'\' style="background-color:transparent;height:100%; width:100%" allowTransparency="true"></iframe>'+
               '</div>';
    var modalBoxHeight = top.document.body.clientHeight > 400 ? 400 : top.document.body.clientHeight;
    Modalbox.show(Builder.build(html), {title: assignObjecttitle, height: modalBoxHeight, overlayOpacity: 0.4, width: 500});
}
/* Opens a popup window to assign */
function openAssignItemsPopup(oid, linkOidsLocation, assignObjecttitle) {
    var location = getBase() + 'archive/assign.do?fromOid=' + oid + '&linkOidsLocation=' + linkOidsLocation;
    top.top_openAssignItemsPopup(location,assignObjecttitle);
}

function top_openContactSearchPopup(ContactSearchTitle) {
    hideselectlist();
    var html = '<div id="iframediv"><iframe name="usecontact" id="usecontact" frameborder="no" scrolling="no" src=\''+getBase()+'users/contactSearchPopup.do?openerCallback=importContactData'+'\' style="background-color:transparent;height:100%; width:100%" allowTransparency="true"></iframe></div>';
    var modalBoxHeight = top.document.body.clientHeight > 600 ? 600 : top.document.body.clientHeight;
    Modalbox.show(Builder.build(html), {title: ContactSearchTitle, height: modalBoxHeight, overlayOpacity: 0.4, width: 710});
}

function top_closeContactSearchPopup() {
    Modalbox.hide();
}

function top_addArchiveNumbers(jobId, addArchiveNumbersTitle) {
    hideselectlist();
    var html = '<div id="iframediv"><iframe name="addarchivenumbers" id="addarchivenumbers" frameborder="no" scrolling="no" src=\''+getBase()+'archive/addArchiveNumbers.do?jobId='+jobId+'\' style="background-color:transparent;height:100%; width:100%" allowTransparency="true"></iframe></div>';
    var modalBoxHeight = top.document.body.clientHeight > 600 ? 600 : top.document.body.clientHeight;
    Modalbox.show(Builder.build(html), {title: addArchiveNumbersTitle, height: modalBoxHeight, overlayOpacity: 0.4, width: 710});
}

var createCartOids;
function top_createCart(windowTitle, jobId, oids) {
    hideselectlist();
    if (oids != null) {
        createCartOids = oids;   // store in global variable, pass reference
    }
    var html = '<div id="iframediv"><iframe name="createCart" id="createCart" frameborder="no" scrolling="no" src=\''
            +getBase()+'orders/cart.do?popup=true&action=createForm'
            +(jobId != null ? '&jobId=' + jobId : '')
            +(oids != null ? '&jsOids=top.createCartOids' : '')
            +'\' style="background-color:transparent;height:100%; width:100%" allowTransparency="true"></iframe><iframe name="usecontact" id="usecontact" frameborder="no" scrolling="no" src=\''+getBase()+'users/contactSearchPopup.do?openerCallback=importContactData'+'\' style="background-color:transparent;height:100%; width:100%; display:none" allowTransparency="true"></iframe></div>';
    var modalBoxHeight = top.document.body.clientHeight > 560 ? 560 : top.document.body.clientHeight;
    Modalbox.show(Builder.build(html), {title: windowTitle, overlayClose: false, height: modalBoxHeight, overlayOpacity: 0.4, width: 710});
}

var createExportOids;
function top_createExport(windowTitle, jobId, oids) {
    hideselectlist();
    if (oids != null) {
        createExportOids = oids;   // store in global variable, pass reference
    }
    var html = '<div id="iframediv"><iframe name="createCart" id="createCart" frameborder="no" scrolling="no" src=\''
            +getBase()+'orders/create.do?popup=true&action=orderFromSelection&email=false'
            +(jobId != null ? '&jobId=' + jobId : '')
            +(oids != null ? '&jsOids=top.createExportOids' : '')
            +'\' style="background-color:transparent;height:100%; width:100%" allowTransparency="true"></iframe><iframe name="usecontact" id="usecontact" frameborder="no" scrolling="no" src=\''+getBase()+'users/contactSearchPopup.do?openerCallback=importContactData'+'\' style="background-color:transparent;height:100%; width:100%; display:none" allowTransparency="true"></iframe></div>';
    var modalBoxHeight = top.document.body.clientHeight > 570 ? 570 : top.document.body.clientHeight;
    Modalbox.show(Builder.build(html), {title: windowTitle, overlayClose: false, height: modalBoxHeight, overlayOpacity: 0.4, width: 650});
}

function replaceAll( inText, inFindStr, inReplStr, inCaseSensitive ) {
   //	inText is the text in which to do the search;
   //	inFindStr is the string to find;
   //	inReplStr is the string to substitute into inText in place of inFindStr; and
   //	inCaseSensitive is a boolean value (defaults to false).

   var searchFrom = 0;
   var offset = 0;
   var outText = "";
   var searchText = "";
   if ( inCaseSensitive == null ) {
      inCaseSensitive = false;
   }
   if ( inCaseSensitive ) {
      searchText = inText.toLowerCase();
      inFindStr = inFindStr.toLowerCase();
   } else {
      searchText = inText;
   }
   offset = searchText.indexOf( inFindStr, searchFrom );
   while ( offset != -1 ) {
      outText += inText.substring( searchFrom, offset );
      outText += inReplStr;
      searchFrom = offset + inFindStr.length;
      offset = searchText.indexOf( inFindStr, searchFrom );
   }
   outText += inText.substring( searchFrom, inText.length );

   return ( outText );
};


// MM popup functions

function mm_alert(text) {
    fadeBackground();
    alert(text);
    restoreBackground();
}

function mm_confirm(text) {
    fadeBackground();
    var result = confirm(text);
    restoreBackground();
    return result;
}

function mm_prompt(text, defaultValue) {
    fadeBackground();
    var result = prompt(text, defaultValue);
    restoreBackground();
    return result;
}

function fadeBackground() {
    //setDocumentOpacity(0.7);
}

function restoreBackground() {
    //setDocumentOpacity(1);
}

function setDocumentOpacity(opacity) {
    var doc = parent != null ? parent.document : document;
    if (!document.all)
        doc.body.style.opacity = opacity;
    else
        doc.body.style.filter = "alpha(opacity:" + opacity*100 + ")";
}


function getClientSizeX() {
    return document.body.clientWidth;
}

function getClientSizeY() {
    return document.body.clientHeight;
}

// returns the "base" for URL's of the given document (if null, then "document." is used)
function getBase(doc) {
    try {
        var el = (doc != null) ? doc : document;
        var baseUrl = el.getElementsByTagName("base")[0].href;
        if (baseUrl.indexOf(":80/") > 0) {
            baseUrl = baseUrl.replace(":80/","/");
        }
        return baseUrl;
    } catch (e) {
        return "";
    }
}

function openScreenViewPopup(oid, version) {
        var ver = (version != null) ? version : 1;
        var location = getBase() + "archive/screenview.do?oid=" + oid + "&version=" + ver;
        window.open(location, "screenview" + oid, "left=0,top=0,width=400,height=300,resizable=yes,menubar=no,toolbar=no,status=no");
}

function openScreenViewPopupExt(oid, version, fdRnr, previewRnr) {
        var ver = (version != null) ? version : 1;
        var location = getBase() + "archive/screenview.do?oid=" + oid + "&version=" + ver + "&finedataRunningNumber=" + fdRnr + "&previewRunningNumber=" + previewRnr;
        window.open(location, "screenview" + oid, "left=0,top=0,width=400,height=300,resizable=yes,menubar=no,toolbar=no,status=no");
}

function openScreenViewPopupOverride(oid, version, angle, flipH, flipV) {
        var ver = (version != null) ? version : 1;
        var location = getBase() + "archive/screenview.do?oid=" + oid + "&version=" + ver + "&overrideRotateFlip=true&angle=" + angle + "&flipH=" + flipH + "&flipV=" + flipV;
        window.open(location, "screenview" + oid, "left=0,top=0,width=400,height=300,resizable=yes,menubar=no,toolbar=no,status=no");
}

function openScreenViewPopupOverrideExt(oid, version, fdRnr, previewRnr, angle, flipH, flipV) {
        var ver = (version != null) ? version : 1;
        var location = getBase() + "archive/screenview.do?oid=" + oid + "&version=" + ver + "&overrideRotateFlip=true&angle=" + angle + "&flipH=" + flipH + "&flipV=" + flipV + "&finedataRunningNumber=" + fdRnr + "&previewRunningNumber=" + previewRnr;
        window.open(location, "screenview" + oid, "left=0,top=0,width=400,height=300,resizable=yes,menubar=no,toolbar=no,status=no");
}

/**
    Generic mouseover/mouseout effect. color is optional.
 */
function genericMouseOver(event, element, color) {
    if (color == null)
        color = "#D8DEE6";
    element.setAttribute("oldBackgroundColor", element.style.backgroundColor);
    element.style.backgroundColor = color;
}

function genericMouseOut(event, element) {
    var oldColor = element.getAttribute("oldBackgroundColor");
    if (oldColor != null)
        element.style.backgroundColor = oldColor;
}

// ----------- Toolbar functions ------------

function onToolButtonClick(form, imgBaseId, imgId, group, formFieldId, formValue, reload, optFunction) {
    if (group) {    // disable all other elements, called imgBaseId_[id]
        var myImgId = imgBaseId + "_0";
        var img = document.getElementById(myImgId);
        var ctr = 1;
        while (img != null) {
            if (myImgId != imgId)
                setButtonImage(img, false);
            myImgId = imgBaseId + "_" + ctr++;
            img = document.getElementById(myImgId);
        }
    }
    if (form[formFieldId] != null)
        form[formFieldId].value = formValue;
    if (optFunction != null)    // call optional event handler
        optFunction();
    if (reload) {
        var expdays = 365;
        var expdate = new Date();
        expdate.setTime (expdate.getTime() + (expdays*24*60*60*1000)); // expiry date
        if (formValue == "ko" || formValue == "mo") {
            set_cookie("SEARCHTYPE",formValue,expdate,"/");
        } else {
            set_cookie("VIEWTYPE",formValue,expdate,"/");
        }
    }
    if (setButtonImage(document.getElementById(imgId), true) && reload) { // reload result page
        form.submit();
    }
}

function setButtonImage(img, enabled) {
    if (img == null) return;
    var pos_on = img.src.indexOf("_on.");
    var pos_ext = img.src.lastIndexOf(".");
    if (!enabled && pos_on != -1) // disable button
        img.src = img.src.substring(0, pos_on) + img.src.substring(pos_on + 3, img.src.length);
    else if (enabled && pos_on == -1) { // enable button
        img.src = img.src.substring(0, pos_ext) + "_on" + img.src.substring(pos_ext, img.src.length);
        return true;
    }
    return false;
}


// -------------- input element functions -----------------

/* Evaluates the given expression if the return key was pressed.
   This function is to be passed to an onkeypress event handler of a HTML input element. */
function onReturnEval(e, expression) {
    var keycode;
    if (e && e.keyCode) keycode = e.keyCode
    else if (window.event) keycode = window.event.keyCode;
    else if (e && e.which) keycode = e.which;
    else return true;
    if (keycode == 13) {
        eval(expression);
        return false;
    } else {
        return true;
    }
}

// ---------------- misc utility functions -----------------
function trim(str) {
   return str.replace(/^\s*|\s*$/g, "");
}


// ----------------- keyCode functions --------------------

function getKeyCode(event) {
    event = event || window.event;

    if (event.which)
        return event.which;
    else if (event.keyCode)
        return event.keyCode;
}

function getCharCode(event)
{
    var keyCode  = getKeyCode(event);

    return String.fromCharCode(keyCode);
}

// ----------- element valuetype check functions ----------
function checkInputValue(e, srcElement, type) {
    var propertyTypes = new Array();
    var infoTypes = new Array();

    propertyTypes.push('CLIP_BEGIN_TC');
    propertyTypes.push('CLIP_END_TC');
    propertyTypes.push('CDURATION');
    propertyTypes.push('DAUER');
    propertyTypes.push('PAGES');
    propertyTypes.push('SORT');
    propertyTypes.push('TAKE_CITY');
    propertyTypes.push('TAKE_COUNTRY');
    propertyTypes.push('TAKE_KREIS');
    propertyTypes.push('VID_DURATION');
    propertyTypes.push('AUD_DURATION');

    var typeCase = null;

    for (var i = 0; i < propertyTypes.length; i++) {
        if (srcElement.name.indexOf(propertyTypes[i]) != -1) {
            typeCase = propertyTypes[i];
            break;
        }
    }

    switch (typeCase) {
        case "CLIP_BEGIN_TC":
            return formatTimeValue(e, srcElement);
            break;
        case "CLIP_END_TC":
            return formatTimeValue(e, srcElement);
            break;
        case "CDURATION":
            return formatTimeValue(e, srcElement);
            break;
        case "DAUER":
            return formatTimeValue(e, srcElement);
            break;
        case "PAGES":
            return formatNumericValue(e, srcElement);
            break;
        case "SORT":
            return formatNumericValue(e, srcElement);
            break;
        case "AUD_DURATION":
            return formatTimeValue(e, srcElement);
            break;
        case "VID_DURATION":
            return formatTimeValue(e, srcElement);
            break;
        default:
            break;
    }

    if (type) {
        if (type == "double") {
            formatNumericValue(e, srcElement,true);
        } else if (type == "numeric") {
            formatNumericValue(e, srcElement,false);
        }
    }

    return false;
}

function removeLink(inputElement,name) {
    if (inputElement.value == '') {
        var hiddenInputE = document.getElementById(name);
        hiddenInputE.value = '';
    }

}

function formatNumericValue(e, srcElement, isDouble) {
    var checkDouble = false;
    if (isDouble) {
        checkDouble = true;
    }
    if (e == null) {
        return false;
    }

    var keyCode = getKeyCode(e);
    var keyChar = getCharCode(e);

    var space = null;
    var backSpace = null;

    var value = srcElement.value;

    if (keyCode == 8) {
        cancelChar(e);
        backSpace = true;
    } else if (keyCode == 32) {
        cancelChar(e);
        space = true;
    }

    if (keyCode == 103) {
        keyChar = '7';
    } else if (keyCode == 104) {
        keyChar = '8';
    } else if (keyCode == 105) {
        keyChar = '9';
    } else if (keyCode == 100) {
        keyChar = '4';
    } else if (keyCode == 101) {
        keyChar = '5';
    } else if (keyCode == 102) {
        keyChar = '6';
    } else if (keyCode == 97) {
        keyChar = '1';
    } else if (keyCode == 98) {
        keyChar = '2';
    } else if (keyCode == 99) {
        keyChar = '3';
    } else if (keyCode == 96) {
        keyChar = '0';
    }

    if (!isNaN(keyChar) || space || backSpace || keyCode == 35 ||
        keyCode == 36 || keyCode == 37 || keyCode == 39 || keyCode == 46) {
        if (space) {
            cancelChar(e);

            return false;
        } else if (backSpace) {
            if (value != "") {
                if (value.length > 1) {
                    value = value.substr(0, value.length - 1);
                    srcElement.value = value;
                }
                else {
                    value = "";
                    srcElement.value = value;
                }
            }

            return true;
        }

        return true;
    } else {
        if (checkDouble && (keyCode == 188 || keyCode == 190 || keyCode == 110)) {
            if (value != "") {
                if (value.indexOf(".") >= 0 || value.indexOf(",") >= 0) {
                    cancelChar(e);

                    return false;
                }
            }
            return true;
        } else {
            cancelChar(e);
        }
    }

    return false;
}

function formatTimeValue(e, srcElement) {
    if (e == null) {
        return false;
    }

    var keyCode = getKeyCode(e);
    var keyChar = getCharCode(e);

    var space = null;
    var backSpace = null;

    var value = srcElement.value;
    if (keyCode == 8) {
        cancelChar(e);

        backSpace = true;
    }
    else if (keyChar == " ") {
        cancelChar(e);

        space = true;
    }

    if (!isNaN(keyChar) || keyChar == ":" || keyChar == "." || space || backSpace ||
        keyCode == 35 || keyCode == 36 || keyCode == 37 || keyCode == 39 || keyCode == 46) {
        if (space) {
            cancelChar(e);

            return false;
        }
        else if (backSpace) {
            if (value != "") {
                if (value.length > 1) {
                    value = value.substr(0, value.length - 1);
                    srcElement.value = value;
                }
                else {
                    value = "";
                    srcElement.value = value;
                }
            }

            return true;
        }

        if (keyCode != 35 && keyCode != 36 && keyCode != 37 && keyCode != 39 && keyCode != 46 ||
            keyChar == ":" || keyChar == ".") {
            if (value.length >= 12) {
                cancelChar(e);

                return false;
            }

            if (keyChar == ":") {
                if (value.length < 2) {
                    cancelChar(e);

                    return false;
                }
                else if (value.indexOf(":") != -1) {
                    if (value.length > 5) {
                        cancelChar(e);

                        return false;
                    }
                    else if (value.substr(value.length - 1) == ":") {
                        cancelChar(e);

                        return false;
                    }
                    else if (value.substr(value.length - 2, 1) == ":") {
                        cancelChar(e);

                        return false;
                    }
                }
            }
            else if (keyChar == ".") {
                if (value.length < 8) {
                    cancelChar(e);

                    return false;
                }
                else if (value.indexOf(".") != -1) {
                    cancelChar(e);

                    return false;
                }
            }
            else {
                if (value.length == 2 || value.length == 5 || value.length == 8) {
                    cancelChar(e);

                    return false;
                }
            }

            return true;
        }

        return true;
    }
    else {
        cancelChar(e);
    }

    return false;
}

function cancelChar(e) {
    e.returnValue = false;

    if (!window.event) {
        e.preventDefault();
    }
    else {
        e.cancelBubble = true;
    }
}

// HTML editor functions
function initHtmlEditor(lang,varConvertUrls) {
    // varConvertUrls: needed for mail, do NOT convert urls to relative paths
    try {
        tinyMCE.baseURL = getBase() + "js/tiny_mce";
        tinyMCE.srcMode = ""; // "_src" to enable original sourcefiles
        tinyMCE.init({
                mode: "specific_textareas",
                dialog_type: "window",
                editor_selector: "htmlEditor",  // textareas with this class are converted to html areas
                theme: "advanced",
                plugins: "paste,fullscreen,inlinepopups",
                theme_advanced_toolbar_location : "top",
                language: lang,      // set by JSP code
                convert_urls : varConvertUrls,
                entity_encoding: "raw",     // don't replace special characters (like umlaut) with HTML entities

                // general layout options
                theme_advanced_layout_manager: "SimpleLayout",
                theme_advanced_buttons1: "bold,italic,underline,strikethrough,sub,sup,separator,forecolorpicker,fontsizeselect,removeformat",
                theme_advanced_buttons2: "pastetext,pasteword,separator,undo,redo"
                    + ",separator,link,unlink,separator,bullist,justifyleft,justifycenter,justifyright,justifyfull,separator,code,fullscreen",
                theme_advanced_buttons3: "",
                theme_advanced_toolbar_align: "left",
                // fix alert when switching between multiple editors
                focus_alert: false,
                apply_source_formatting : true,
                width: "100%"
        });
    } catch (e) {
        alert("initHtml exception: " + e);
        // HTML editor component not configured
    }
}

function updateHtmlEditors(document) {
    try {
        tinyMCE.onLoad(document);
    } catch (e) {
        alert("updateHtmlEditors exception: " + e);
        // HTML editor component not configured
    }
}

/**
 * Browser detection - stored in global variable browserInfo
 */

function browserDetection() {
    var agent = navigator.userAgent.toLowerCase();
    this.userAgent = agent;
    this.isSafari = agent.indexOf("safari") != -1 || agent.indexOf("mediamid") != -1;
    this.isIE = agent.indexOf("msie") != -1;
    this.isMozilla = !this.isSafari && agent.indexOf("gecko") != -1;
    this.isKonqueror = agent.indexOf("konqueror") != -1;
    this.isOpera = agent.indexOf("opera") != -1;
}

var browserInfo = new browserDetection();


function getCSSRule(frame,ruleName,deleteFlag) {               // Return requested style obejct
    var d;
    if (parent.frames[frame] == null || parent.frames[frame].document == null) {
        return false;
    } else if (parent.frames[frame].document) {
        d = parent.frames[frame].document;
    }

   if (d.styleSheets) {                            // If browser can play with stylesheets
      for (var i=0; i<d.styleSheets.length; i++) { // For each stylesheet
         var styleSheet=d.styleSheets[i];          // Get the current Stylesheet
         var ii=0;                                        // Initialize subCounter.
         var cssRule=false;                               // Initialize cssRule.
         do {                                             // For each rule in stylesheet
            try {
                if (styleSheet.cssRules) {                    // Browser uses cssRules?
                   cssRule = styleSheet.cssRules[ii];         // Yes --Mozilla Style
                } else {                                      // Browser usses rules?
                   cssRule = styleSheet.rules[ii];            // Yes IE style.
                }                                             // End IE check.
            } catch (e) {
            }
            if (cssRule)  {                               // If we found a rule...
               if (cssRule.selectorText==ruleName) {      // Does current rule match ruleName?
                  if (deleteFlag=='delete') {             // Yes.  Are we deleteing?
                     if (styleSheet.cssRules) {           // Yes, deleting...
                        styleSheet.deleteRule(ii);        // Delete rule, Moz Style
                     } else {                             // Still deleting.
                        styleSheet.removeRule(ii);        // Delete rule IE style.
                     }                                    // End IE check.
                     return true;                         // return true, class deleted.
                  } else {                                // found and not deleting.
                     return cssRule;                      // return the style object.
                  }                                       // End delete Check
               }                                          // End found rule name
            }                                             // end found cssRule
            ii++;                                         // Increment sub-counter
         } while (cssRule)                                // end While loop
      }                                                   // end For loop
   }                                                      // end styleSheet ability check
   return false;                                          // we found NOTHING!
}                                                         // end getCSSRule

function killCSSRule(ruleName) {                          // Delete a CSS rule
   return getCSSRule(ruleName,'delete');                  // just call getCSSRule w/delete flag.
}                                                         // end killCSSRule

function addCSSRule(ruleName) {                           // Create a new css rule
   if (document.styleSheets) {                            // Can browser do styleSheets?
      if (!getCSSRule(ruleName)) {                        // if rule doesn't exist...
         if (document.styleSheets[0].addRule) {           // Browser is IE?
            document.styleSheets[0].addRule(ruleName, null,0);      // Yes, add IE style
         } else {                                         // Browser is IE?
            document.styleSheets[0].insertRule(ruleName+' { }', 0); // Yes, add Moz style.
         }                                                // End browser check
      }                                                   // End already exist check.
   }                                                      // End browser ability check.
   return getCSSRule(ruleName);                           // return rule we just created.
}

/* works for ie only */
function moveCursorToEnd( x ) {
    try {
        var txtRange = x.createTextRange();
        txtRange.moveStart( "character", 0);
        txtRange.moveEnd( "character", x.value.length);
        txtRange.select();
    } catch (e) {}
}

function showUseContact() {
    document.getElementById("createCart").style.display = "none";
    document.getElementById("usecontact").style.display = "";
}

function showCreateCart() {
    document.getElementById("createCart").style.display = "";
    document.getElementById("usecontact").style.display = "none";
}

function top_useContact(oid, archiveNumber, caption, company) {
    if(top.parent.frames[4].importContactData) { //for Mozilla
        var fn = eval("top.parent.frames[4].importContactData");
        fn(oid, archiveNumber, caption, company);
        showCreateCart();
    } else {
        var fn = eval("top.parent.frames['createCart'].importContactData");
        fn(oid, archiveNumber, caption, company);
        showCreateCart();
    }
}

var __jsonrpc;
function getJsonRpc() {
    if (__jsonrpc == null) {
        try {
            __jsonrpc = new JSONRpcClient("/mediamanager/MMJSON");
        } catch(e) {
            top.top_mm1_alert(e);
        }
    }
    return __jsonrpc;
}

