function $(co){ return document.getElementById(co) }


function $s(co){ return document.getElementById(co).style }
function $sON(co){ return document.getElementById(co).style.display='inline' }
function $sOFF(co){ return document.getElementById(co).style.display='none' }

function $sON2(co){ return document.getElementById(co).style.width=320 }
function $sOFF2(co){ return document.getElementById(co).style.width=1 }

function $i(co){ return document.getElementById(co).innerHTML }
function $t(co,tag) { return co.getElementsByTagName(tag) }
function $ti(co, tag,  num){ return co.getElementsByTagName(tag).item(num) }
function $oiv(co) { return co.options[co.selectedIndex].value }           //option index value
function $oii(co) { return co.options[co.selectedIndex].innerHTML }       //option index innerHTML
function $si(co) { return co.options[co.selectedIndex] }       //option index innerHTML
function $select(co, i) { co.options[i].selected = true;  }


function init(type) {
  if (type='dna') {
    lastLocus1="1"
    $select($('locus1ID'),0)
    lastLocus2="1"
    $select($('locus2ID'),0)
  } else {
    lastLocus1="1"
    $select($('locus1ID_srlg'),0)
    lastLocus2="1"
    $select($('locus2ID_srlg'),0)  
  }  
  changeResolution('locus')
}


function selectLocus(element, locus) {  
  if ($oii($('locus1ID')) == $oii($('locus2ID'))) {     
     alert(TEXT_ALERT_CHANGE_LOCUS)  
     if (locus==1)  $select($('locus1ID'),lastLocus1 - 1)    
     if (locus==2)  $select($('locus2ID'),lastLocus2 - 1)              
  }  
  lastLocus1=$oiv($('locus1ID'))
  lastLocus2=$oiv($('locus2ID'))
  checkLocus2();
}

function checkLocus2() {
  if ($oii($('locus2ID')) == "ALL") {
    $sOFF('subLocus3ID')
    $sOFF('locus3ID')
    $sOFF('locus3_label') 
    $sOFF('subLocus2ID')
  } else {
    $sON('subLocus3ID')
    $sON('locus3ID')
    $sON('locus3_label')
    $sON('subLocus2ID')
  }
}
  /*
function changeResolution(type) {  
  unmarked = 'font-weight: normal; color:blue; cursor:pointer; text-decoration:underline';
  marked   = 'font-weight: bold; color:red; cursor:text; text-decoration:none';
  
  $('res_low').style.cssText   = unmarked; 
  $('res_high').style.cssText  = unmarked;
  $('res_locus').style.cssText = unmarked;   
  $('res_' + type).style.cssText = marked
  document.find.resolution.value=type;
  
  if (type=='high') {
    $sON('subLocus1ID')
    $sON('subLocus2ID')
    $sON('subLocus3ID')
    
    $s('subLocus1ID').cssText = $s('subLocus1ID').cssText + ';width:38px;border-right:1px solid black;'
    $s('subLocus2ID').cssText = $s('subLocus2ID').cssText + ';width:38px;border-right:1px solid black;'
    $s('subLocus3ID').cssText = $s('subLocus3ID').cssText + ';width:38px;border-right:1px solid black;'
    $('subLocus1ID').setAttribute('maxlength', 4);
    $('subLocus2ID').setAttribute('maxlength', 4);
    $('subLocus3ID').setAttribute('maxlength', 4);
    
    $sOFF('subLocus1ID_XX')
    $sOFF('subLocus2ID_XX')
    $sOFF('subLocus3ID_XX')
    
  } else if (type=='low'){
    $('subLocus1ID').value = $('subLocus1ID').value.substring(0,2);
    $('subLocus2ID').value = $('subLocus2ID').value.substring(0,2);
    $('subLocus3ID').value = $('subLocus3ID').value.substring(0,2);
    
    $sON('subLocus1ID')
    $sON('subLocus2ID')
    $sON('subLocus3ID')
    $s('subLocus1ID').cssText = $s('subLocus1ID').cssText + ';width:20px;'
    $s('subLocus2ID').cssText = $s('subLocus2ID').cssText + ';width:20px;'
    $s('subLocus3ID').cssText = $s('subLocus3ID').cssText + ';width:20px;'
    $('subLocus1ID').setAttribute('maxlength', 2);
    $('subLocus2ID').setAttribute('maxlength', 2);
    $('subLocus3ID').setAttribute('maxlength', 2);
    $sON('subLocus1ID_XX')
    $sON('subLocus2ID_XX')
    $sON('subLocus3ID_XX')
    
  } else {
    $sOFF('subLocus1ID');
    $sOFF('subLocus2ID');
    $sOFF('subLocus3ID');
    $sOFF('subLocus1ID_XX');
    $sOFF('subLocus2ID_XX');
    $sOFF('subLocus3ID_XX');     
  }  
}*/

function changeResolution_srlg(type) {  
  unmarked = 'font-weight: normal; color:blue; cursor:pointer; text-decoration:underline';
  marked   = 'font-weight: bold; color:red; cursor:text; text-decoration:none';
  $('res_low').style.cssText   = unmarked;   
  $('res_locus').style.cssText = unmarked;   
  $('res_' + type).style.cssText = marked
  document.find.resolution.value=type;
  
  if (type=='low'){
    //$('subLocus1ID_srlg').value = $('subLocus1ID_srlg').value.substring(0,2);
    //$('subLocus2ID_srlg').value = $('subLocus2ID_srlg').value.substring(0,2);
    //$('subLocus3ID_srlg').value = $('subLocus3ID_srlg').value.substring(0,2);    
    $sON('subLocus1ID_srlg');
    $sON('subLocus2ID_srlg');
    $sON('subLocus3ID_srlg');    
  } else {
    $sOFF('subLocus1ID_srlg');
    $sOFF('subLocus2ID_srlg');
    $sOFF('subLocus3ID_srlg');       
  }  
}


function selectHistory(co) {
  document.find.historyQuery.value = 1
  document.find.submit();
}

function getPosition(e) {
    e = e || window.event;
    var cursor = {x:0, y:0};
    if (e.pageX || e.pageY) {
        cursor.x = e.pageX;
        cursor.y = e.pageY;
    } 
    else {
        var de = document.documentElement;
        var b = document.body;
        cursor.x = e.clientX + 
            (de.scrollLeft || b.scrollLeft) - (de.clientLeft || 0);
        cursor.y = e.clientY + 
            (de.scrollTop || b.scrollTop) - (de.clientTop || 0);
    }      
    //alert(cursor.x)  
    return cursor;    
}

function import_CSV_file(fname) {            
    cntrl = false;
    for (var key in fnames) {  
        //alert();
        $.get("includes/admin/import_nmdp_ajax.php?fname=" + fnames[key], function(html) {         
            if ((html!="")) {
                $("#import_result_ID").html($("#import_result_ID").html() + cnt + ") " + html + " <b>OK</b> <br/>");
                cnt++;
            };
        }); 
    }
}
