function doUpdateSVG() {
    var url = 'statsvg.php?langname=' + document.getElementById('lang').value;
    var html = '<object data="' + url;
    html += '" type="image/svg+xml" height="400" width="600"></object>';
    document.getElementById('graph').innerHTML = html;
    document.getElementById('url').innerHTML = '<a href="' + url + '">' + url + '</a>';
}

function doUpdateSVG2() {
    var opt = 'label=' + document.getElementById('label').value;
    for (var id = 0; id < svg2id; id++) {
        opt += '&';
        opt += 'lang[]=' + document.getElementById('lang' + id).value + '&';
        opt += 'color[]=' + document.getElementById('color' + id).value;
    }
    opt = 'statsvg2.php?' + opt;
    var html = '<object data="' + opt;
    html += '" type="image/svg+xml" height="400" width="600"></object>';
    document.getElementById('graph').innerHTML = html;
    document.getElementById('url').innerHTML = '<a href="' + opt + '">' + opt + '</a>';
}

function doOnLoad() {
    addSVG2();
}

var svg2id = 0;
function addSVG2() {
    doStoreSVG2();
    var addqlang = document.getElementById('addqlang').innerHTML;
    var addqcol  = document.getElementById('addqcol').innerHTML;
    var addqlang = addqlang.substring(9, addqlang.length - 10);
    var addqcol  = addqcol.substring(9, addqcol.length - 10);
    html = '<select name="lang[]" id="lang' + svg2id + '">';
    html += addqlang;
    html += '</select>';
    html += '<select name="color[]" id="color' + svg2id + '">';
    html += addqcol;
    html += '</select>';
    html += '<span id="addsvg2' + svg2id + '">';
    html += '<input type="button" onclick="addSVG2()" value="add lang" />';
    html += '</span>';
    html += '<br />';
    document.getElementById('querycol').innerHTML += html;
    if (svg2id > 0) {
        document.getElementById('addsvg2' + (svg2id - 1)).innerHTML = '';
    }
    svg2id = svg2id + 1;
    doRestoreSVG2();
}

function doClearSVG() {
    document.getElementById('graph').innerHTML = '';
    document.getElementById('querycol').innerHTML = '';
    document.getElementById('url').innerHTML = '';
    svg2id = 0;
    addSVG2();
}

var svg2dat = '';
function doStoreSVG2() {
    svg2dat = '';
    for (var cid = 0; cid < svg2id; cid++) {
        svg2dat += doStoreSVG2ID('lang' + cid);
        svg2dat += doStoreSVG2ID('color' + cid);
    }
}
function doStoreSVG2ID(id) {
    return id + '=' + document.getElementById(id).value + ';';
}
function doRestoreSVG2() {
    var strId;
    var strKey;
    while (svg2dat.length != 0) {
        strId = svg2dat.substr(0, svg2dat.indexOf('='));
        svg2dat = svg2dat.substr(svg2dat.indexOf('=') + 1);
        strKey = svg2dat.substr(0, svg2dat.indexOf(';'));
        svg2dat = svg2dat.substr(svg2dat.indexOf(';') + 1);
        document.getElementById(strId).value = strKey;
    }
}
function doRestoreSVG2Get(id) {
    var strPos = svg2dat.indexOf(id);
    if (strPos == -1) {return ''; }
    strPos = strPos + id.length + 1;
    strCur = svg2dat.substr(strPos);
    strCur = strCur.substr(0, strCur.indexOf(';'));
    return strCur;
}


