
function toggle(element) {
    
    i = 0;
    
    do {
        element = element.nextSibling;
        i++;
    } while(i < 24 && element.nodeName && element.nodeName.toLowerCase() != "ul");
    
    if(element.style) {
        
        if(element.style.display == "none") {
            element.style.display = "block";
        } else {
            element.style.display = "none";
        }
        
        return true;
        
    } else {
        
        return false;
        
    }
    
}

function add_clock() {
    
    clocks = document.getElementById('clocks');
    
    clock = document.createElement('div');
    
    clock.innerHTML += '\
        <input type="text" name="clock_name[]" />\
        <input type="text" name="clock_freq[]" size="4" />\
        <select name="clock_unit[]">\
            <option>Hz</option>\
            <option>kHz</option>\
            <option>MHz</option>\
            <option>GHz</option>\
            <option>THz</option>\
        </select>\
    ';
    
    clocks.appendChild(clock);
    
}

function check(object) {
    
    var a, b, c, d;
    
    a=ajax();
    b=object.parentNode.getElementsByTagName('span')[0];
    
    if(object.value) {
        c = object.value;
    } else if(object.options) {
        c = object.options[object.selectedIndex].value;
    } else {
        c = '';
    }
    
    if(c.length > 0) {
        
        d = 'value=' + c;
        b.innerHTML='Loading';
        
        a.open("POST","register,check,"+object.name);
        
        a.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
        a.setRequestHeader("Content-length", d.length);
        a.setRequestHeader("Connection", "close");
        
        a.onreadystatechange=function() {
            if(a.readyState==4) {
                b.innerHTML=a.responseText;
            }
        };
        
        a.send(d);
        
    } else {
        
        b.innerHTML='';
        
    }
    
}

function ajax() {
    
    try {
      return new XMLHttpRequest();
    } catch(e) {}
    
    try {
        return new ActiveXObject("Msxml2.XMLHTTP");
    } catch(e) {}
    
    try {
        return new ActiveXObject("Microsoft.XMLHTTP");
    } catch(e) {}
    
    alert("Your browser does not support AJAX, please upgrade!");
    return false;
    
}var uname_counter = -1;
var email_counter = -1;

function au_filter(id1,id2) {
    sea=document.getElementById(id1).value;
    sel=document.getElementById(id2);
    reg = new RegExp(sea);
    for(i=0;i<sel.length;i=i+1) {
        if(reg.test(sel.options[i].innerHTML)) {
            sel.options[i].style.display="block";
        } else {
            sel.options[i].style.display="none";
        }
    }
}

function au_clear_filter(id1,id2) {
    sea=document.getElementById(id1).value;
    sel=document.getElementById(id2);
    for(i=0;i<sel.length;i=i+1) {
        sel.options[i].style.display="block";
    }
}

function showhide(id) {
    if(document.getElementById(id).style.display != "block")
        document.getElementById(id).style.display = "block";
    else
        document.getElementById(id).style.display = "none";
}

function p_showcat_select(id) {
    a=document.getElementById(id);
    if(a.selectedIndex == 0) {
        p_showallcat();
    } else {
        b=a.options[a.selectedIndex].text.substr(0,3);
        p_showcat(b.toLowerCase());
    }
}


function p_showcat(cat) {
    p_hideallcat();
    document.getElementById('pc_'+cat).style.display="list-item";
}

function p_hideallcat() {
    a= ['ari','pro','com','cop','cry','dsp','ecc','lib','mem','mic','oth','soc','sys','vid'];
    for(b in a) {
        document.getElementById('pc_'+a[b]).style.display="none";
    }
}

function p_showallcat() {
    a= ['ari','pro','com','cop','cry','dsp','ecc','lib','mem','mic','oth','soc','sys','vid'];
    for(b in a) {
        document.getElementById('pc_'+a[b]).style.display="list-item";
    }
}

function printer_switch() {
    if(document.getElementById('dmc')) {
        document.getElementById('main').innerHTML='<img src="img/mid1.png" style="float: left;" class="noprint" onclick="printer_switch()" />' + document.getElementById('dmc').innerHTML;
        document.getElementById('main').style.backgroundColor = "white";
    } else {
        history.go(0);
    }
}

function vote(poll,answer) {
    var a,b;
    a=document.getElementById('poll');
    b=ajax();
    
    b.onreadystatechange=function() {
        if(b.readyState==4) {
            a.innerHTML=b.responseText;
        }
    };
    
    a.innerHTML='<img src="img/loading.gif" />';
    
    b.open("GET","poll.php?poll="+poll+"&ans="+answer,true);
    b.send(null);
}

function bt_add() {
    a=document.getElementById('bt_add_stuff');
    if(a.style.display=="none") {
        a.style.display="block";
        a.innerHTML+='<br />Title:&nbsp;&nbsp;&nbsp;<input type="text" name="title" /><br />';
        a.innerHTML+='Description:<br /><textarea name="desc" rows="10" cols="80"></textarea><br />';
        a.innerHTML+='<input type="submit" />';
    }
}

function svnget(id) {
    var a, b;
    a=document.getElementById(id);
    b=a.options[a.selectedIndex].value;
    window.location.href="svnget/" + b;
}
function showStat(project) {
    var a = document.getElementById('StatsForm');
    var b = document.getElementById('StatsImg');
    var c = a.getElementsByTagName('select');
    var m = null, y = null;
    for(var i in c) {
        if(c[i].name == "StartDateMonth") {
            m = c[i].options[c[i].selectedIndex].value;
        } else
        if(c[i].name == "StartDateYear") {
            y = c[i].options[c[i].selectedIndex].value;
        }
    }
    b.src = "chart,line," + project + "," + y + "," + m;
    return true;
}

function shop_delete_item_from_cart(a) {

    item = a.parentElement;
    
    if(item) { item = item.getElementsByTagName('input'); }
    if(item) { item = item[0]; }
    if(item) { item.value = "0"; }
    if(item) { item = item.parentElement; }
    
    while(item) {
        
        if(item.tagName == "FORM") {
            break;
        } else {
            item = item.parentElement;
        }
        
    }
    
    if(item) {
        item.submit();
        return true;
    }
    
    return false;
    
}
/*
 
Correctly handle PNG transparency in Win IE 5.5 & 6.
http://homepage.ntlworld.com/bobosola. Updated 18-Jan-2006.

Use in <HEAD> with DEFER keyword wrapped in conditional comments:
<!--[if lt IE 7]>
<script defer type="text/javascript" src="pngfix.js"></script>
<![endif]-->

*/

var arVersion = navigator.appVersion.split("MSIE")
var version = parseFloat(arVersion[1])

if ((version >= 5.5) && (document.body.filters)) 
{
   for(var i=0; i<document.images.length; i++)
   {
      var img = document.images[i]
      var imgName = img.src.toUpperCase()
      if (imgName.substring(imgName.length-3, imgName.length) == "PNG")
      {
         var imgID = (img.id) ? "id='" + img.id + "' " : ""
         var imgClass = (img.className) ? "class='" + img.className + "' " : ""
         var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
         var imgStyle = "display:inline-block;" + img.style.cssText 
         if (img.align == "left") imgStyle = "float:left;" + imgStyle
         if (img.align == "right") imgStyle = "float:right;" + imgStyle
         if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle
         var strNewHTML = "<span " + imgID + imgClass + imgTitle
         + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
         + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
         + "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>" 
         img.outerHTML = strNewHTML
         i = i-1
      }
   }
}

function fedit(id) {
    document.getElementById("f_"+id).style.display="block";
    document.getElementById("t_"+id).style.display="none";
}
/* Project functions */

function pedit(id,l) {
    f=document.getElementById('f_'+id);
    p=document.getElementById('p_'+id);
    
    if(l != -1) {
        f.text.style.width="99%";
        f.text.style.height=16*(l+3)+"px";
    }
    p.style.display="none";
    f.style.display="inline";
}

function pdelete(id,pr,pa) {
    if(!confirm("Sure?")) return false;
    
    var a,b;
    a=document.getElementById("d_"+id);
    b=ajax();
    
    b.onreadystatechange=function() {
        if(b.readyState==4) {
            a.innerHTML=b.responseText;
        }
    };
    
    a.innerHTML='<img src="img/loading.gif" />';
    
    b.open("GET","?ajax&do=pdelete&proj="+pr+"&page="+pa+"&sort=1&titl="+id,true);
    b.send(null);
    
    return true;
}

function addmaint(pr) {
    m=prompt("Please enter the new maintainer's username, firstname or lastname.");
    if(m == null) return false;
    if(m.length < 1) return false;
    window.location.href="/project_edit_maintainers," + pr + ",search," + m;
    return true;
}

function psort(dir,id) {
    var a=document.getElementById(id);
    if(dir == "add" || dir == "rem") {
        if(dir == "add") {
            var b = document.createElement('option');
            var c = document.getElementById('addpagename');
            if(c.value == "" || c.value == " ") { return false; }
            b.value=c.value.replace(' ','_').toLowerCase();
            b.text=c.value;
            if(a.selectedIndex == a.length-1) {
                a.add(b,null);
            } else {
                a.add(b,a.options[a.selectedIndex+1]);
            }
            a.selectedIndex += 1;
            a.size += 1;
        } else {
            a.remove(a.selectedIndex);
            a.size -= 1;
        }
    } else {
        if(dir == "upp") {
            if(a.selectedIndex == 0) return false;
        } else {
            if(a.selectedIndex == a.size-1) return false;
        }
        var b = a.options[a.selectedIndex];
        if(dir == "upp") {
            a.selectedIndex-=1;
        } else {
            a.selectedIndex+=1;
        }
        var c = a.options[a.selectedIndex];
        var d = document.createElement('option');
        d.value=b.value;
        d.text=b.text;
        a.remove(b.index);
        if(dir == "upp") {
            a.add(d,c);
            a.selectedIndex = c.index-1;
        } else {
            a.add(d,a.options[c.index+1]);
            a.selectedIndex = c.index+1;
        }
    }
    return true;
}

function psort_done() {
    a=document.getElementById("blocks");
    a.multiple=true;
    for(i=0;i<a.size;i++) {
        //a.options[i].value=a.options[i].innerHTML;
        a.options[i].selected=true;
    }
    return true;
}

/* End project functions */