﻿var amaf_selectedTab;
function amaf_getSelectedTab() {
    return amaf_selectedTab;
}
function amaf_toggleTab(tab) {
    if (amaf_selectedTab != tab.id) {
        amaf_selectedTab = tab.id;
        var obj = document.getElementsByTagName("div");
        for (var i = 0; i < obj.length; i++) {
            var el = obj[i];
            if (el.id.indexOf('amafcontent') > 1) {
                el.style.display = 'none';
            };
            if (el.id.indexOf('_text') > 1) {
                el.className = 'amtabtext';
            };
            if (el.className == 'amtabsel') {
                el.className = 'amtab';
            };
        };
        var tabContent = document.getElementById(tab.id + '_amafcontent');
        var tabtext = document.getElementById(tab.id + '_text');
        var tab = document.getElementById(tab.id);
        tab.className = 'amtabsel';
        tabtext.className = 'amtabseltext';
        tabContent.style.display = 'block';
    };
};

function toggleGroup(whichgroup) {
    var myDate = new Date();
    myDate.setDate(myDate.getDate()+30);
    var oGroup = eval(document.getElementById('group' + whichgroup));
    var oImage = eval(document.getElementById("imgGroup" + whichgroup));
    if (oGroup.style.display == 'none') {
        oGroup.style.display = '';
        oImage.src = af_imgPath + '/arrows_down.png';
        document.cookie = whichgroup + 'Show=True; expires=' + myDate.toGMTString() + '; path=/;';
    }else{
        oGroup.style.display = 'none';
        oImage.src = af_imgPath + '/arrows_left.png';
        document.cookie = whichgroup + 'Show=False; expires=' + myDate.toGMTString() + '; path=/;';
        
    };
};
function aftoggleSection(whichgroup) {
    var oGroup = eval(document.getElementById('section' + whichgroup));
    var oImage = eval(document.getElementById('imgSection' + whichgroup));
    if (oGroup.style.display == 'none') {
        oGroup.style.display = '';
        oImage.src = af_imgPath + '/arrows_down.png';
     }else{
        oGroup.style.display = 'none';
        oImage.src = af_imgPath + '/arrows_left.png';
     };
};
    function af_showLoad(){
        var afdiv = document.getElementById('afgrid');
        if (afdiv.style.position == '' || afdiv.style.position == 'static'){
            afdiv.style.position = 'relative';
        };
        var afloaddiv = document.createElement('div');
        afloaddiv.setAttribute('id', 'afLoadDiv');
        afloaddiv.style.position = 'absolute';
        afloaddiv.style.float = 'left';
        afloaddiv.style.top = '0px';
        afloaddiv.style.left = '0px';
        afloaddiv.style.width = afdiv.offsetWidth + 'px';
        afloaddiv.style.height = afdiv.offsetHeight + 'px';
        afloaddiv.style.zIndex = '1000';
        afloaddiv.className = 'afloader';
        afSpinLg.style.position = 'absolute';
        afSpinLg.style.top = ((afdiv.offsetHeight / 2)-16) + 'px';
        afSpinLg.style.left = ((afdiv.offsetWidth / 2)-16) + 'px';
        afloaddiv.appendChild(afSpinLg);
        afdiv.appendChild(afloaddiv);
    };
function af_clearLoad(){
    var afdiv = document.getElementById('afgrid');
    if (afdiv.style.position == 'relative' || afdiv.style.position == 'static'){
            afdiv.style.position = '';
    };
    var ld = document.getElementById('afLoadDiv');
    if (ld != null) {
        afdiv.removeChild(ld);
    };
    
};
function af_OnTreeClick(evt){
    var src = window.event != window.undefined ? window.event.srcElement : evt.target;
    var isChkBoxClick = (src.tagName.toLowerCase() == 'input' && src.type == "checkbox");
    if(isChkBoxClick){
        var parentTable = af_GetParentByTagName('table', src);
        var nxtSibling = parentTable.nextSibling;
        if(nxtSibling && nxtSibling.nodeType == 1){
            if(nxtSibling.tagName.toLowerCase() == 'div'){
                 af_CheckUncheckChildren(parentTable.nextSibling, src.checked);
            };
        };
          af_CheckUncheckParents(src, src.checked);
    };
};
function af_CheckUncheckChildren(childContainer, check){
    var childChkBoxes = childContainer.getElementsByTagName('input');
    var childChkBoxCount = childChkBoxes.length;
    for(var i = 0; i < childChkBoxCount; i++){
        childChkBoxes[i].checked = check;
    };
};
function af_CheckUncheckParents(srcChild, check){
    var parentDiv = af_GetParentByTagName('div', srcChild);
    var parentNodeTable = parentDiv.previousSibling;
    if(parentNodeTable){
        var checkUncheckSwitch;
        if(check){
            var isAllSiblingsChecked = af_AreAllSiblingsChecked(srcChild);
            if(isAllSiblingsChecked){
                checkUncheckSwitch = true;
            }else{
                return; 
            };
        }else{
            checkUncheckSwitch = false;
        };
        var inpElemsInParentTable = parentNodeTable.getElementsByTagName('input');
        if(inpElemsInParentTable.length > 0){
            var parentNodeChkBox = inpElemsInParentTable[0]; 
            parentNodeChkBox.checked = checkUncheckSwitch; 
            af_CheckUncheckParents(parentNodeChkBox, checkUncheckSwitch);
        };
    };
};
function af_AreAllSiblingsChecked(chkBox){
    var parentDiv = af_GetParentByTagName('div', chkBox);
    var childCount = parentDiv.childNodes.length;
    for(var i=0; i < childCount; i++){
        if(parentDiv.childNodes[i].nodeType == 1){
            if(parentDiv.childNodes[i].tagName.toLowerCase() == 'table'){
                var prevChkBox = parentDiv.childNodes[i].getElementsByTagName('input')[0];
                if(!prevChkBox.checked){
                    return false;
                }; 
            };
        };
    };
    return true;
};
function af_GetParentByTagName(parentTagName, childElementObj){
    var parent = childElementObj.parentNode;
    while(parent.tagName.toLowerCase() != parentTagName.toLowerCase()){
        parent = parent.parentNode;
    };
    return parent; 
};
    function getTop(obj,height){
        var dlg=document.getElementById(obj);
        var winH=document.body.offsetHeight;
        var top=((winH/2)-(height/2));
        dlg.style.top=top+'px';
    };
    function getLeft(obj,width){
        var dlg=document.getElementById(obj);
        var winW=document.body.offsetWidth;
        dlg.style.left=((winW/2)-(width/2))+'px';
    };
    
function amaf_ShowTip(obj,message){
        position = amaf_getTipPosition(obj);
        var tt =document.getElementById('amtip');
        var tttxt = document.getElementById('amtiptext');
        tt.style.left= (position.x - 55) + 'px';
        tt.style.top= (position.y + 15) + 'px';
        tt.style.visibility='visible';
        tt.style.zIndex = '500';
        tt.style.display = '';
        tttxt.innerHTML = message;
    };
function amaf_HideTip(){
        var tt =document.getElementById('amtip');
        tt.style.visibility = 'hidden';
        tt.style.zIndex = '-1000';
        tt.style.display = 'none';
    };
    function amaf_getTipPosition(e){
        var left = 0;
        var top = 0;
        while (e.offsetParent){
            left += e.offsetLeft;
            top += e.offsetTop;
            e = e.offsetParent;
        };
        left += e.offsetLeft;
        top += e.offsetTop;
        return {x:left, y:top};
    };
var amaf_timetoclose;
function amaf_MsgBox(title,text,height,width,type){
    window.scrollTo(0,0);
    getTop("amMsgBox", height);
    getLeft("amMsgBox", width);
    var amMsgBox = document.getElementById("amMsgBox");
    amMsgBox.style.height = height + "px";
    amMsgBox.style.width = width + "px";
    amMsgBox.style.zIndex = 300000;
    amMsgBox.style.display = 'block';
    var amMsgBoxHeaderText = document.getElementById("amMsgBoxHeaderText");
    amMsgBoxHeaderText.innerHTML = title;
    var amMsgBoxText = document.getElementById("amMsgBoxText");
    amMsgBoxText.innerHTML = text;
    if (type == '') {
        amaf_timetoclose = setTimeout('amaf_MsgBoxClose()', 3000);
    } else {
    amaf_timetoclose = null;
    };
};
function amaf_MsgBoxClose(){
   var dlg = document.getElementById("amMsgBox");
   dlg.style.display = 'none';
   if (amaf_timetoclose != null) {
       clearTimeout(amaf_timetoclose);
   };
   
};
    function onlyNumbers(evt){
        var charCode = (evt.which != undefined) ? evt.which : evt.keyCode;
        if (charCode > 31 && (charCode < 48 || charCode > 57) && (charCode != 46) && (charCode != 44))
            return false;
      return true;
    };
function amaf_setParam(name,value,days) {
    if (days) {
	    var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
    }else{
        var expires = "";
	};
    document.cookie = name+"="+value+expires+"; path=/";
};
function afAddBookmark(title, url) {
    if (window.external) {
        window.external.AddFavorite(url, title);
    } else if (window.sidebar) {
        window.sidebar.addPanel(title, url, '');
    } else if (window.opera && window.print) {
        return true;
    };
};
var nmode = '';
var tmpimgsrc = '';
var tmpimgid = '';
function af_notifyComplete() {
    if (nmode == 'ts') {
        nmode = '';
        var img = eval(document.getElementById(tmpimgid));
        if (tmpimgsrc.indexOf('email_unchecked') > 0) {
            tmpimgsrc = tmpimgsrc.replace(/email_unchecked/, 'email_checked');
        } else {
            tmpimgsrc = tmpimgsrc.replace(/email_checked/, 'email_unchecked');
        };
        img.src = tmpimgsrc;
        
    };
};
