/*
#===============================================================================
#
#         FILE:  sm.js
#
#        USAGE:  ---
#
#      PURPOSE:  JavaScript - Routines for Browser
#
#      OPTIONS:  ---
#      RETURNS:  ---
# REQUIREMENTS:  ---
#     COMMENTS:  
#      
#       AUTHOR:  Konstantin
#      COMPANY:  SIB & Biozentrum University of Basel
#      VERSION:  $version$
#      CREATED:  9:40:08 AM Aug 26, 2008
#     REVISION:  $rev$
#===============================================================================
*/

function ClearField(field_id) {
  if(document.getElementById(field_id)) {
    if(document.getElementById(field_id).type == "textarea"){
      document.getElementById(field_id).innerHTML = "";
      document.getElementById(field_id).value = "";
    } else {
      document.getElementById(field_id).value = "";
    }
  }
}
function FillField(field_id, value) {
if(document.getElementById(field_id)) {
    if(document.getElementById(field_id).type == "textarea"){
      document.getElementById(field_id).innerHTML = value;
      document.getElementById(field_id).value = value;
    } else {
      document.getElementById(field_id).value = value;
    }
  }
}


function FillSMRUP(upac) { document.smr_query.query_1_input.value=upac; }

function FillField(fieldid, text) { document.getElementById(fieldid).value = text; }

function printDivToggle(div_id){
    document.write("<a href=\"javascript:toggleDivVisibility('" + div_id + "')\" > [+/-]</a>");
}


function toggleDivVisibility(div_id){
    var arr = document.getElementById(div_id)
    if ( arr!= null ) {
        arr.style.display = (arr.style.display == 'none')? 'block':'none';
    } 
}


function asyncPart(async_url, field) {
    document.getElementById(field).innerHTML = "loading data ...";

    var xmlHttp;
    try{
        // Firefox, Opera 8.0+, Safari
        xmlHttp=new XMLHttpRequest();
    }catch (e){
        // Internet Explorer
        try{
            xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
        }catch (e){
            try{
                xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
            }catch (e){
                alert("Your browser does not support AJAX!");
                return false;
            }
        }
    }
    xmlHttp.onreadystatechange=function(){
        if(xmlHttp.readyState==4){
            document.getElementById(field).innerHTML = xmlHttp.responseText;
        }
    }
    xmlHttp.open("GET",async_url,true);
    xmlHttp.send(null);
}


function changeLinkToAsync(){
    for (var i = 0; i < document.links.length; ++i){
        if((document.links[i].href.search("smr") != -1 || 
            document.links[i].href.search("sms") != -1 || 
            document.links[i].href.search("smw") != -1) &&
            document.links[i].href.search("&zid=async") == -1){
            document.links[i].href = document.links[i].href+"&zid=async"; 
            }
        }
    if(document.smr_query){         document.smr_query.action =         document.smr_query.action+"&zid=async"; }
//  if(document.queryBySeq){        document.queryBySeq.action =        document.queryBySeq.action+"&zid=async"; }
//  if(document.statusQueryBySeq){  document.statusQueryBySeq.action =  document.statusQueryBySeq.action+"&zid=async"; }
//  if(document.queryByTemplateID){ document.queryByTemplateID.action = document.queryByTemplateID.action+"&zid=async"; }
}


function restoreAnchorLinks(){
    var anchors = document.getElementsByTagName("a");
    var basehref = document.getElementsByTagName("base")[0].href;
    var url = window.location.href;
    if(url.indexOf("#") > 0) url = url.substr(0, url.indexOf("#")); //strip hash
    if(basehref) {
        for(var i = 0; i < anchors.length; i++) {
            var anchor = anchors[i];
            poundPos = anchor.href.indexOf("/#");
            if (poundPos > 0) {
                anchor.href = url + anchor.href.substr(poundPos + 1);
            }
        }
    }

}


