﻿var ie7 = (document.all && !window.opera && window.XMLHttpRequest) ? true : false;
var favCommentEditMode = false;
var isclicked = false;
var chatUpdateInterval = -1;
var externalScripts = {};
var onLoadFunctions = [];
var $get = $get || function(id) { return document.getElementById(id) };  // document.getElementById is actually faster (2.5x) than $get

/*
* Bootscript (consider using pageLoad instead)
*/
function loadScript() {
    //Setting the submenu correct
    //bootExpand();

    //Adding javascript validators
    if (typeof addValidators == 'function') {
        addValidators();
    }

    //Adding the fields which contains errors
    if (typeof addErrorFields == 'function') {
        addErrorFields();
    }

    for (var i = 0; i < onLoadFunctions.length; ++i)
        onLoadFunctions[i]();
            
    // Start the timer that checks for new chat messages
    //startChatUpdateTimer(10000);
}

/**
 * Add trim function to string if undefined
 */
if (''.trim == undefined)
    String.prototype.trim = function() {
        return this.replace(/^\s+|\s+$/g, '');
    };

/**
 * Add a CSS rule to an existing stylesheet
 */
function addCssRule(selector, attribute, value, styleSheetID) {
    if (!document.styleSheets.length)
        return;
    var i = styleSheetID || document.styleSheets.length-1;
    if (document.styleSheets[i].addRule)
        document.styleSheets[i].addRule(selector, attribute+':'+value);
    else
        document.styleSheets[i].insertRule(selector+' {'+attribute+':'+value+'}', 0);
}

/**
 * document.write Alternative (for external scripts that use it)
 */
function documentWriteAlternative(divID, text) {
    var el = document.getElementById(divID);
    if (el && ('innerHTML' in el))
        el.innerHTML = text;
}

/*
* Initiate a timer that periodically updates the chat notifier div
*/
function startChatUpdateTimer(interval) {
    if (chatUpdateInterval != -1 || typeof (chatUpdatePanelButton) == 'undefined') return;
    chatUpdateInterval = setInterval(function() { chatUpdatePanelButton.click(); }, interval);
}

/*
* Stop the timer that periodically updates the chat notifier div
*/
function stopChatUpdateTimer(interval) {
    clearInterval(chatUpdateInterval);
    chatUpdateInterval = -1;
}

/*
* Go to url
*/
function goTo(url) {
    setTimeout(function () { window.location.href = url }, 0);
}

/*
* Go to url in new tab
*/
function goToNew(url) {
//    if (isFirefox()) {
//        open(url);
//        return;
//    }
//    var link = document.createElement('a');
//    link.href = url;
//    link.target = '_new';
//    link.style.display = 'none';
//    document.body.appendChild(link);
    //    link.click();
    window.open(url);
}

/**
* Test for firefox
*/
function isFirefox() {
    return /\bfirefox\b/i.test(navigator.userAgent);
}

/*
* search for a value in the array and returns the key
*/
function array_search(value, array) {
    for (var i = 0; i < array.length; i++) {
        if (array[i] == value)
            return i;
    }

    return -1;
}

/*
* search the array for the given value, gives true if so
*/
function in_array(value, array, identifier) {
    var i = 0, j = array.length;
    if (identifier == undefined) {
        for (i; i < j; ++i) {
            if (array[i] == value)
                return true;
        }
    } else {
        if (value[identifier] == undefined)
            return false;
        for (i; i < j; ++i) {
            if (array[i][identifier] == value[identifier])
                return true;
        }
    }
    return false;
}

/*
* Finds the X position of an element
*/
function findPosX(obj) {
    var curleft = 0;

    if (obj.offsetParent) {
        while (1) {
            curleft += obj.offsetLeft;
            if (!obj.offsetParent)
                break;
            obj = obj.offsetParent;
        }
    } else if (obj.x) {
        curleft += obj.x;
    }

    obj.style.position = "static";

    return curleft;
}

/*
* Finds the Y position of an element
*/
function findPosY(obj) {
    var curtop = 0;

    if (obj.offsetParent) {
        while (1) {
            curtop += obj.offsetTop;
            if (!obj.offsetParent)
                break;
            obj = obj.offsetParent;
        }
    } else if (obj.y) {
        curtop += obj.y;
    }

    return curtop;
}

/*
* Adds an eventlistener to the element
*/
function addEvent(obj, type, fn) {
    if (obj == undefined)
        return;
    if (obj.addEventListener) {
        obj.addEventListener(type, fn, false);
    } else if (obj.attachEvent) {
        obj["e" + type + fn] = fn;
        obj[type + fn] = function() { obj["e" + type + fn](window.event); }
        obj.attachEvent("on" + type, obj[type + fn]);
    } else {
        obj["on" + type] = fn;
    }
}

/*
* Removes an eventlistener from the element
*/
function removeEvent(obj, type, fn) {
    if (obj.removeEventListener)
        obj.removeEventListener(type, fn, false);
    else if (obj.detachEvent && obj[type + fn]) {
        obj.detachEvent("on" + type, obj[type + fn]);
        obj[type + fn] = null;
        obj["e" + type + fn] = null;
    }
}

/**
 * Format a page's content for printing and print
 */
function formatPrint() {
    var i, gets, ori,
        elements = [],
        classes = ['header_ingelogd', 'main_left', 'main_right', 'sitemap'];
    for (i in classes) {
        gets = getElementsByClassName(classes[i]);
        if (!gets.length) // I.e. the designer changed the CSS classes...
            return;
        elements.push(gets[0].style);
    }
    ori = [elements[0].display, elements[1].display, elements[2].cssFloat,
            elements[2].styleFloat, elements[3].display];
    elements[0].display = 'none';
    elements[1].display = 'none';
    elements[2].cssFloat = 'left';
    elements[2].styleFloat = 'left';
    elements[3].display = 'none';
    print();
    elements[0].display = ori[0];
    elements[1].display = ori[1];
    elements[2].cssFloat = ori[2];
    elements[2].styleFloat = ori[3];
    elements[3].display = ori[4];
    return false;
}

/**
 * Format a date object to string, given a style
 */
function formatDate(date, formatStyle) {
    switch (formatStyle) {
        case 'NL_date_time':
            return [date.getDate(), date.getMonth()+1, date.getFullYear()].join('-') + ', ' + date.getHours() + ':' + leadingZeros(date.getMinutes(),2);
            break;
        default:
            return date.toString();
    }
}

/**
 * Add leading zeros to a number if it has fewer than n digits
 */
function leadingZeros(number,n) {
    return new Array(Math.max(0, n-(number + '').length) + 1).join(0) + number;
}

/**
 * Hide/show menus
 * Does opposite when bizarro is true
 */
function toggleMinimalMode(bizzarro) {
    var i, gets,
        elements = [document.getElementById('minimalBar').style],
        classes = ['header_ingelogd', 'sitemap', 'footer', 'main_left', 'main_right', 'main_main'];
    for (i in classes) {
        gets = getElementsByClassName(classes[i]);
        if (!gets.length) // I.e. the designer changed the CSS classes...
            return;
        elements.push(gets[0].style);
    }
    if (!this.minimalMode != !bizzarro) {
        this.minimalMode = false;
        elements[0].display = 'none';
        elements[1].display = elements[2].display = elements[3].display = elements[4].display = elements[5].cssFloat =
            elements[5].styleFloat = '';
        elements[6].width = '991px'
    } else {
        this.minimalMode = true;
        elements[0].display = 'block';
        elements[1].display = elements[2].display = elements[3].display = elements[4].display = 'none';
        elements[5].cssFloat = 'left';
        elements[5].styleFloat = 'left';
        elements[6].width = '800px';
    }
}

/*
* get Elements by class name
*/
function getElementsByClassName(className, tag, elm) {
    var testClass = new RegExp("(^|\\s)" + className + "(\\s|$)");
    tag = tag || "*";
    elm = elm || document;
    var elements = (tag == "*" && elm.all) ? elm.all : elm.getElementsByTagName(tag);
    var returnElements = [];
    var current;
    var length = elements.length;
    for (var i = 0; i < length; i++) {
        current = elements[i];
        if (testClass.test(current.className)) {
            returnElements.push(current);
        }
    }
    return returnElements;
}

/*
* Aplphabets cannot be entered
*/
function isNumberKey(evt) {
    var charCode = (evt.which) ? evt.which : event.keyCode
    if (charCode > 31 && (charCode < 48 || charCode > 57))
        return false;

    return true;
}

/*
* Get elements by name does not work completly in IE
*/
function getElementsByName_iefix(tag, name) {
    var elem = document.getElementsByTagName(tag);
    var arr = new Array();
    for (i = 0, iarr = 0; i < elem.length; i++) {
        att = elem[i].getAttribute("name");
        if (att == name) {
            arr[iarr] = elem[i];
            iarr++;
        }
    }
    return arr;
}

/*
* To open a popup window for email addressess page in new email page
*/
function PopUP() {
    window.open("EmailPopUp.aspx", "popup", "menubar=0,tollbar=0,statusbars=1,left=100,top=100,width=400,height=300,resizable=yes");
}

/*
* To open a popup window for email addressess page in new email page
*/
function PopUPWithReturnField(returnField) {
    window.open("EmailPopUp.aspx?returnField=" + returnField, "popup", "menubar=0,tollbar=0,statusbars=1,left=100,top=100,width=400,height=300,resizable=yes");
}

/*
*   OPEN POPUP WITH SPECIFIED INFORMATION
*/
function popUp(typePopUp) {
    window.open("popUpScreen.aspx?type=" + typePopUp, "popup", "menubar=0,tollbar=0,statusbars=1,left=100,top=100,width=400,height=300,resizable=yes");
}

/*
*   OPEN POPUP WITH SPECIFIED INFORMATION
*/
function popUpWithReturnField(typePopUp, returnField) {
    window.open("popUpScreen.aspx?type=" + typePopUp + "&returnField=" + returnField, "popup", "menubar=0,tollbar=0,statusbars=1,left=100,top=100,width=400,height=300,resizable=yes");
}

/*
* Show and Hide rating stars.
*/
function changeRating(obj, id, array) {
    var self = array.length;
    for (i = 0; i < array.length; i++) {
        if (i <= self) {
            array[i].src = array[i].src.replace("black", "gold");
        } else {
            array[i].src = array[i].src.replace("gold", "black");
        }
        if (array[i].id == obj.id) {
            self = i;
        }
    }
}

/*
*   SHOW HIDE ELEMENT BY ID
*/
function showHideElementById(elementID) {
    var elem = document.getElementById(elementID);
    if (!elem)
        return;

    if (elem.style.display == "none") {
        elem.style.display = "block";
    } else {
        elem.style.display = "none";
    }
}

function changeImage(elementID, firstImage, secondImage) {
    var elem = document.getElementById(elementID);
    if (!elem)
        return;
    var elemSrc = elem.src.toString();
    if (elemSrc.search(firstImage) != -1) {
        elem.src = elemSrc.replace(firstImage, secondImage);
    } else {
        elem.src = elemSrc.replace(secondImage, firstImage);
    }
}

/*
*   POPUP BOX ARE YOU SURE? YES NO. SUMBIT FORM.
*/
function wantToRemove(text, obj) {
    var reaction = confirm(text);

    if (reaction) {
        return true;
    }

    return false;
}

/*
*   SELECT ALL CHECKBOXES BY NAME
*/
function checkAllCheckboxesByName(name) {
    var elements = getElementsByName_iefix("input", name);

    for (i = 0; i < elements.length; i++) {
        if (elements[i].checked) {
            elements[i].checked = false;
        } else {
            elements[i].checked = true;
        }
    }
}

function showhidecells(name) {
    if (name == "zzper" & document.aspnetForm.ctl00_cphMain_ddlUsertype != null) {
        var namearray = getElementsByName_iefix("td", name);

        if (document.aspnetForm.ctl00_cphMain_ddlUsertype.selectedIndex == 0) {
            for (var i = 0; i < namearray.length; i++) {
                namearray[i].style.display = "table-cell";
            }
        } else {
            for (i = 0; i < namearray.length; i++) {
                namearray[i].style.display = "none";
            }
        }
    } else if (name == "exp" & document.aspnetForm.ctl00_cphMain_ddlTypeOfZZPer != null) {
        if (document.aspnetForm.ctl00_cphMain_ddlTypeOfZZPer.selectedIndex == 0) {
            document.getElementById("ctl00_cphMain_startyear").style.display = "none";
            document.getElementById("ctl00_cphMain_kvknumber").style.display = "none";
            document.getElementById("ctl00_cphMain_startyear2").style.display = "none";
            document.getElementById("ctl00_cphMain_kvknumber2").style.display = "none";
        } else {
            document.getElementById("ctl00_cphMain_startyear").style.display = "table-cell";
            document.getElementById("ctl00_cphMain_kvknumber").style.display = "table-cell";
            document.getElementById("ctl00_cphMain_startyear2").style.display = "table-cell";
            document.getElementById("ctl00_cphMain_kvknumber2").style.display = "table-cell";
        }
    }
}

/*
* Show/hide the icons options on the my favorites page
*/
function switchFavoritesIcons(element, show) {
    if (!favCommentEditMode)
        getElementsByClassName('favorites_icons_container', 'div', element)[0].style["display"] = show ? 'block' : 'none';
}

/*
* Confirm box for deleteing the favorite
*/
function deleteFavorite(fav_id) {
    if (confirm(resources.confirm_delete)) {
        goTo("?delete=" + fav_id)
    }
}

/*
* Edit the comment for a favorite
*/
function editFavoriteComment(element) {
    if (isclicked == false) {

        var parentDiv = element.parentNode;
        var commentBox = parentDiv.getElementsByTagName("div");

        commentBox = commentBox[0];

        commentBox.style["width"] = "250px";
        commentBox.style["height"] = "130px";
        commentBox.style["top"] = "-10px";
        parentDiv.style["left"] = "-135px";

        commentBox.innerHTML = "<textarea style='width:243px; height:100px;' rows='1' columns='2'>" + commentBox.innerHTML;
        commentBox.innerHTML += "</textarea><p align='right'><a href='javascript:;' onclick='hideFavoriteCommentBox(this)'>" + resources.save + "</a></p>";
        var textArea = commentBox.getElementsByTagName('textarea')[0];

        textArea.focus();

        favCommentEditMode = true;
        isclicked = true;
    }
}

/*
* Edit the comment for a favorite (profile)
*/
function editFavoriteCommentProfile(id, note) {
    var commentBox = document.getElementById(id);

    if (isclicked) {
        commentBox.style["display"] = "none"
        favCommentEditMode = false;
        isclicked = false;
        return;
    }

    commentBox.style["display"] = "block";

    var textArea = commentBox.getElementsByTagName('textarea')[0];

    if (typeof (favoriteNote) != 'undefined' && note == undefined)
        try {
            textArea.innerHTML = favoriteNote;
        }catch (e){
            textArea.innerHTML = '';
        }
    textArea.focus();

    favCommentEditMode = true;
    isclicked = true;
}

/*
* Hide the edit box for the comment of a favorite
*/
function hideFavoriteCommentBox(element) {
    var parentDiv = element.parentNode;
    var hiddenID = parentDiv.parentNode.parentNode.getElementsByTagName("input")[1].value;
    var commentBox = parentDiv.parentNode;
    var textArea = commentBox.getElementsByTagName('textarea')[0];

    commentBox.style["width"] = "150px";
    commentBox.style["height"] = "";
    commentBox.style["top"] = "0px";
    parentDiv.parentNode.parentNode.style["left"] = "-85px";

    updateComment(textArea, hiddenID);

    commentBox.innerHTML = textArea.value;
    favCommentEditMode = false;
    isclicked = false;
}

/*
* Hide the edit box for the comment of a favorite (profile)
*/
function hideFavoriteCommentBoxProfile(element, save, note) {
    var hiddenID = element.parentNode.parentNode.parentNode.getElementsByTagName("input")[0].value;
    var icon = element.parentNode.parentNode.parentNode.getElementsByTagName("img")[0];
    var commentBox = element.parentNode.parentNode;
    var textArea = commentBox.getElementsByTagName('textarea')[0];

    commentBox.style["display"] = "none";

    favCommentEditMode = false;
    isclicked = false;

    if (save) {
        if (note == undefined) {
            updateComment(textArea, hiddenID);
            favoriteNote = textArea.value;
        } else
            addNote(textArea.value, hiddenID);
    }
}

/*
 * Hide or show task box
 */
function toggleTaskBox(insertValue,save,id) {
    var taskBox = document.getElementById('taskBox');
    var taskTextbox = taskBox.getElementsByTagName('textarea')[0];
    var deadline = taskBox.getElementsByTagName('input')[0];
    if (taskBox.style.display != 'block'){
        taskBox.style.display = 'block';
        taskTextbox.value = insertValue || '';
        deadline.value = '';
    }else{
        taskBox.style.display = 'none';
        if (save)
            addTask(taskTextbox.value, id, deadline.value);
        taskTextbox.value = '';
    }
    return false;
}



/*
 * Hide or show task edit box
 */
function toggleTaskEdit(insertValue,save,id, dag) {
    var taskBox = document.getElementById('TaskEdit');
    var taskTextbox = taskBox.getElementsByTagName('textarea')[0];
    var deadline = taskBox.getElementsByTagName('input')[0];
    var taskID = document.getElementById('hdnid');
    if (taskBox.style.display != 'block'){
        taskBox.style.display = 'block';
        taskTextbox.value = insertValue || '';
        deadline.value = dag;
        taskID.value = id;
       
	
    }else{
        taskBox.style.display = 'none';
        if (save)
            editTask(taskTextbox.value, taskID.value, deadline.value);
        taskTextbox.value = '';
    }
    return false;
}


/*
* Show the feedback popup 
*/
function showFeedbackPopup(page, querystring, path) {
    path = path || '';
    window.open(path + "hdcall.aspx?page=" + page + "&pagecodes=" + querystring, "MyWindow", "toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=500,height=570");
}

/*
* Show the private chatroom popup
*/
function showPrivateChatPopup(user_id_session, user_id_normal) {
    window.open("privateChat.aspx?id1=" + user_id_session + "&id2=" + user_id_normal, "selftextwillmove", "toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=yes,width=370,height=220");

}


/*
* for gridview selected box
*/
function SelectAllCheckboxes(spanChk) {

    // Added as ASPX uses SPAN for checkbox

    var oItem = spanChk.children;

    var theBox = (spanChk.type == "checkbox") ? spanChk : spanChk.children.item[0];

    xState = theBox.checked;

    elm = theBox.form.elements;

    for (var i = 0; i < elm.length; i++) {

        if (elm[i].type == "checkbox" && elm[i].id != theBox.id) {

            //elm[i].click();

            if (elm[i].checked != xState)

                elm[i].click();

            //elm[i].checked=xState;

        }
    }
}

/*
* Limit the display size of an image
*/
function limitImageSize(img, maxwidth, maxheight) {
    var imgwidth = img.width,
        imgheight = img.height,
        ratio = imgwidth / imgheight;
    if (imgwidth <= maxwidth) {
        if (imgheight <= maxheight)
            return;
        img.height = maxheight;
        img.width = maxheight * ratio;
    } else if (imgheight <= maxheight) {
        img.width = maxwidth;
        img.height = maxwidth / ratio;
    } else {
        if (imgwidth > imgheight) {
            img.width = maxwidth;
            img.height = maxwidth / ratio;
        } else {
            img.height = maxheight;
            img.width = maxheight * ratio;
        }
    }
}

//below functions are meant for document sharing and are mostly used in file.aspx page***************************
function openinnewwindow(param1) {
    //window.open('document.aspx?id=new');
    window.open('document.aspx?mode=' + param1 + '&id=', "Link", "toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1,width=800,height=800,left=220,top=230");
}

function openinnewwindowforedit(mode, fileid) {
    //window.open('document.aspx?id=new');
    window.open('document.aspx?mode=' + mode + '&id=' + fileid, "Link", "toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1,width=800,height=800,left=220,top=230");
}

function chkboxChecked(chkId) {
    var checker = document.getElementById(chkId);
    checker.checked = true;
}
function addFileUploadBox() {
    var uploadArea = document.getElementById("upload-area");

    if (!uploadArea)
        return;

    var newLine = document.createElement("br");
    uploadArea.appendChild(newLine);

    var newUploadBox = document.createElement("input");

    // Set up the new input for file uploads
    newUploadBox.type = "file";
    newUploadBox.className = 'styled_field';

    // The new box needs a name and an ID
    //if (!addFileUploadBox.lastAssignedId)
    //    addFileUploadBox.lastAssignedId = 100;

    //newUploadBox.setAttribute("id", "dynamic" + addFileUploadBox.lastAssignedId);
    //newUploadBox.setAttribute("name", "dynamic:" + addFileUploadBox.lastAssignedId);
    uploadArea.appendChild(newUploadBox);
    //addFileUploadBox.lastAssignedId++;

    //var del = document.getElementById(addFileUploadBox.lastAssignedId - 1);
}

function ChangeRowColor(row, chkId, bckcolor) {

    var checker = document.getElementById(chkId);
    if (checker.checked) {

        document.getElementById(row).style.backgroundColor = "#ffffda";
    }
    else {
        if (bckcolor % 2 == 0) {
            document.getElementById(row).style.backgroundColor = "F7F6F3";
        }
        else {
            document.getElementById(row).style.backgroundColor = "FFFFFF";
        }
    }
}

/* Delete cookies */
function deleteCookies() {
    var i, cookies = document.cookie.split('; '),
        cookieDate = new Date(),
        expires = '; expires=' + cookieDate.toGMTString()
    cookieDate.setTime(cookieDate.getTime() - 1);
    for (i = 0; i < cookies.length; ++i)
        document.cookie = cookies[i] + expires;
}

/* Hide beams (during page rendering) if cookie is set */
function hidePlusbeams() {
    var i, id, matches = document.cookie.match(/pb_[^=]+=1/g);
    this.plusbeamsCollapsed = {};
    if (!matches)
        return;
    for (i=0; i<matches.length; ++i){
        id = matches[i].match(/pb_([^=]+)=1/)[1];
        plusbeamsCollapsed[id] = true;
        addCssRule('#' + id + ' > .profile_section', 'display', 'none');
        addCssRule('#' + id + ' .beam_expand_button', 'background-image', 'url(../images/icons/bullet_toggle_plus.png)');
    }
}

/* Expand/collapse 'plusbeams' */
function plusbeamToggle(self) {
    var content, collapsed,
        cookieDate = 0,
        cookieTime = 0,
        paragraph = self.parentNode,
        section = paragraph.parentNode;
    content = paragraph.nextSibling;
    while (content.nodeType != 1)
        content = content.nextSibling;
    if (!section.id)
        return;
    cookieDate = new Date();
    if (this.plusbeamsCollapsed == undefined)
        this.plusbeamsCollapsed = {};
    collapsed = self.dir == 'rtl' || plusbeamsCollapsed[section.id];
    if (collapsed) {  // beam is collapsed, expand it
        plusbeamsCollapsed[section.id] = false;
        self.dir = 'ltr';
        self.className = self.className.replace(/ .*/,'');
        //self.style.backgroundImage = 'url(~/view/images/icons/bullet_toggle_minus.png)';
        content.style.display = 'block';
        this.alt = '-';
        cookieTime = -1;
        removeCSSRulesByTopSelector(document.styleSheets[0], '#' + section.id);
    } else {  // beam is expanded, collapse it
        self.dir = 'rtl';
        self.className += " toggle_plus";
        //self.style.backgroundImage = 'url(~/view/images/icons/bullet_toggle_plus.png)';
        content.style.display = 'none';
        this.alt = '+';
        cookieDate = 10;
        cookieValue = 1;
    }
    setCookie('pb_' + section.id, 1, cookieTime, cookieDate);
    return collapsed;
}

/* Set a cookie */
function setCookie(key, value, timeOffset, dateOffset) {
    var cookieDate = new Date();
    if (dateOffset)
        cookieDate.setDate(cookieDate.getDate() + dateOffset);
    if (timeOffset)
        cookieDate.setTime(cookieDate.getTime() +  timeOffset);
    document.cookie = key + '=' + value + ' ; expires=' + cookieDate.toGMTString();
}

/* Remove CSS rules in stylesheet that match by the top selector element */
function removeCSSRulesByTopSelector(stylesheet, selector) {
    var i, j = stylesheet.rules.length;
    if (stylesheet.addRule) {
        for (i = 0; i < j; ++i) {
            if (stylesheet.rules[i].selectorText.match('^' + selector))
                stylesheet.removeRule(i++);
        }
    } else {
        for (i = 0; i < j; ++i) {
            if (stylesheet.rules[i].selectorText.match('^' + selector))
                stylesheet.deleteRule(i++);
        }
    }
}

/* Set the body cursor to auto or wait */
function cursorWait(bool) {
    if (bool === false)
        document.body.className = document.body.className.replace(/\bwait\b/, '');
    else
        document.body.className += ' wait';
}

/* Set a textbox text, clear it on focus, reappear on blur */
function textSetFocusClear(textbox, text) {
    var element = (typeof textbox == 'object') ? textbox : document.getElementById(textbox);
    textSetFocusStyle(element, text);
    addEvent(element, 'focus', textFocusClearFactory(text));
    addEvent(element, 'blur', textBlurResetFactory(text));
}
function textSetFocusPassword(fauxPassword, password, text) {
    var element1 = (typeof fauxPassword == 'object') ? fauxPassword : document.getElementById(fauxPassword);
    var element2 = (typeof password == 'object') ? password : document.getElementById(password);
    addEvent(element2, 'focus', hideFactory(element1, element2))
    addEvent(element2, 'blur', displayFactory(element1, 'inline', element2)); ;
    addEvent(element1, 'click', hideFocusFactory(element1, element2));
}
function hideFactory(element) {
    return function() {
        element.style.display = 'none';
    }
}
function displayFactory(element1,display,element2) {
    return function() {
        if (!element2 || !element2.value)
            element1.style.display = display;
    }
}
function hideFocusFactory(element,element2) {
    return function() {
        element.style.display = 'none';
        element2.focus();
    }
}
function swapDisplayFocusFactory(element1, element2, defaultDisplay) {
    return function() {
        var temp = element1.style.display || defaultDisplay;
        element1.style.display = element2.style.display || defaultDisplay;
        element2.style.display = temp;
        if (temp != 'none')
            element2.focus();
    }
}
function textSetFocusStyle(element, text) {
    if (element.value == '' || element.value == text) {
        element.style.color = 'gray';
        element.style.fontStyle = 'italic';
        element.value = text;
    }
}
function textFocusClearFactory(text) {
    return function() {
        if (this.value == text) {
            this.value = '';
            this.style.color = '';
            this.style.fontStyle = '';
        }
    }
}
function textNormalStyle(element,text) {
    if (element.value != text) {
        element.style.color = '';
        element.style.fontStyle = '';
    }
}
function textBlurResetFactory(text) {
    return function() {
        if (this.value == '') {
            this.style.color = 'gray';
            this.style.fontStyle = 'italic';
            this.value = text;
        }
    }
}

/**
 * Truncate a value string to a character limit
 */
function valueTruncate(element, limit) {
    if (element.value.length > limit)
        element.value = element.value.slice(0, limit);
}

/**
* Show siblings with a delayed cascading effect
*/
function cascadeShowSiblings(element, display, className) {
    if (!(element = element.nextSibling) || (className && element.nodeType == 1 && element.className != className))
        return;
    display = display || 'block';
    if (element.style)
        element.style.display = display;
    setTimeout(function() { cascadeShowSiblings(element, display, className); }, 100);
}

/**
* Execute (zero parameter) functions with delays (in ms)
*/
function cascadeExecute(functions, delays) {
    var i, intermediate = 0;
    delays.splice(0, 0, 0);
    for (i = 0; i < functions.length; ++i) {
        intermediate += delays[i];
        setTimeout(functions[i], intermediate);
    }
}

/**
 * Remove an element
 */
function remove(element) {
    if (element)
        element.parentNode.removeChild(element);
}

/**
 * Make an absolutely positioned page element follow the mouse cursor (used for input file upload styling)
 */
function uploadBoxMove(event, elementID) {
    var uploadBox = document.getElementById(elementID || 'uploadBox');
    if (!uploadBox)
        return;
    uploadBox = uploadBox.style;
    uploadBox.left = ((event.offsetX || event.layerX || event.x) - 25) + 'px';
    uploadBox.top = ((event.offsetY || event.layerY || event.y) - 9) + 'px';
}

/**
 * Fake a button press
 */
function fakePress(button) {
    if (typeof (button) != 'object')
        button = document.getElementById(button);
    if (!button.style)
        return;
    button.style.paddingTop = '4px';
    button.style.paddingBottom = '2px';
    button.style.paddingLeft = '6px';
    button.style.paddingRight = '4px';
}
/**
 * Fake a button release
 */
function fakeRelease(button) {
    if (typeof (button) != 'object')
        button = document.getElementById(button);
    if (!button.style)
        return;
    button.style.paddingTop = button.style.paddingBottom = button.style.paddingLeft = button.style.paddingRight = '';
}

/**
 * Use closure to return a function that can be called without arguments (e.g. for setTimeout)
 * Usage: var zeroArguments = zeroArgumentClosure(someFunction, argument1, argument2, ...);
 */
function zeroArgumentClosure(func) {
    var args = Array.prototype.slice.call(arguments,1);
    return function() {
        return func.apply(this,args);
    }
}
/**
 *
 *
 */
function showTab(event, groupname, number) {
    var e = null;
    var i = 0;
    while ((e = document.getElementById(groupname + '' + i))) {
        e.style.display = 'none';
        i = i + 1;
    }

    document.getElementById(groupname + '' + number).style.display = 'block';
}

OverlayObject = new Object();
function showOverlay(event, addTo, content, posX, posY, width, height) {
    var elem = document.createElement('div');
    elem.style.position = "absolute";
    elem.style.border = "1px solid black";
    elem.style.background = "#000000";
    elem.style.width = width + "px";
    elem.style.height = height + "px";
    elem.style.top = posX + "px";
    elem.style.left = posY + "px";
    
    elem.innerHTML = content;

    elem.setAttribute('onMouseOut', 'OverlayObject.removeLayout()');
    
    OverlayObject.removeLayout = function() {
        addTo.removeChild(elem);
    }
    
    
    addTo.appendChild(elem);
}

// Make background click close modal popups
function addModalBackgroundClickFactory(id) {
    return function() {
        $get(id + '_backgroundElement').onclick = popupHiderFactory(id);
        if ($get('DialogContainer'))
            $get('DialogContainer').style.display = 'block';
    }
}

// Make background click close modal popups
function addModalBackgroundClickFactoryAndRedirect(id, url) {
    return function () {
        $get(id + '_backgroundElement').onclick = function () { goTo(url); };
       // if ($get('DialogContainer'))
       //     $get('DialogContainer').style.display = 'block';
    }
}

function popupHiderFactory(id) {
    return function() {
        closePopup(id);
    }
}

// Close the modal popup
function closePopup(popListName) {
    var popup = $find(popListName); 
    if (popup) {
        popup.hide(); 
    }
}

// Close the modal popup and makes a FullPostback
function closePopupAndPostback(popListName) {
    var popup = $find(popListName); 
    if (popup) {
        popup.hide(); 
    } 
}



// Show the popup
function showPopup(popListName) {
    var popup = $find(popListName)
    if (popup) {
        popup.show();
    }
}