function test_javascript() {
    alert("Javascript is working inside functions.js (ok2)!");
}


function test_jquery1() {
    if (jQuery) { alert('jQuery is loaded(ok3)!'); }
    else { alert('jQuery is not loaded!');}
}


function test_jquery2() {
    if (typeof jQuery == 'undefined')  { alert('jQuery is not loaded!'); }
    else { alert('jQuery is loaded(ok3)!');}
}


function test_jquery1a() {
    //using an undefined variable jQuery in IE8 causes a crashing error
    try{
        var jqueryIsLoaded=jQuery;
        jQueryIsLoaded=true;
    }
    catch(err){
        var jQueryIsLoaded=false;
    }
    
    if(jQueryIsLoaded) { alert('jQuery is loaded(ok3)!'); }
    else { alert('jQuery is not loaded!');}
}


function toggle_element(id) {
    var el = document.getElementById(id);
    if ( el.style.display != 'none' )
	el.style.display = 'none'; //hiding
    else
	el.style.display = ''; //showing
}


function show_element(id) {
    document.getElementById(id).style.display=''; //showing
}


function hide_element(id) {
    document.getElementById(id).style.display='none'; //hide
}


function DoTheCheck() {
  alert(0);
  if(document.form1.v) {alert(999);} 
  alert(1);
  if(document.form1.v.checked) {document.form1.v.value=1;} 
  alert(2);
  if(document.form1.v.checked==false) {document.form1.v.value=0;} 
}


function submitform(xform1)
{
  alert('S0');
  if(document.xform1.v) {alert('S111');} 
  else                	      {alert('S000');} 
  
  alert('S1');
  if(document.xform1.v.checked) {document.xform1.v.value=1;} 
  alert('S2');
  if(document.xform1.v.checked==false) {document.xform1.v.value=0;} 

  document.xforms["form1"].submit();
}


var request = new Array();
var timeout = new Array();
function communicate(method, url, querystring, failure, html_id) {
    /*
    alert('Inside #communicate# function parameters::'+
          ' method:'+method+
          ' url:'+url+
          ' querystring:'+querystring+
          ' failure:'+failure+
          ' html_id:'+html_id);
    */
    
    /*
    AJAX Communicate function written by Mango - http://www.toao.net/
    The communicate function takes four arguments: method, which is GET or POST (defaults to GET),
    url and querystring, which are self-explanatory, and failure, which is evaluated in case of
    failure.  The onreadystatechange function does an eval() on the response from the server, so
    queries should return Javascript code to be executed.
    If this function is useful for you, please tell someone about it. 
    */
    
    /* Set requestid */
    var requestid = new Date().getTime() * Math.random();
    /* Set the cursor to "wait".  We want things to be pretty, don't we? */
    document.body.style.cursor = 'wait';
    
    /* Initialize the XMLHTTP Object */
    if (typeof window.ActiveXObject != 'undefined') {
        try {
            request[requestid] = new ActiveXObject("Microsoft.XMLHTTP");
        } catch(e) {
            alert ("Error2:  Could not create the Microsoft.XMLHTTP object.  Please contact your systems administrator.");
        }
    } else if( typeof XMLHttpRequest != 'undefined' ) {
        try {
            request[requestid] = new XMLHttpRequest();
        } catch(e) {
            alert ("Error2:  Could not create the XMLHttpRequest object.  Please contact your systems administrator.");
            }
    } else {
        alert ("Error1:  This browser does not support AJAX.  Please contact your systems administrator.");
    }
        
    request[requestid].onreadystatechange = function() {
     /* This is a slightly confusing part of the script.  We don't wait to hear back from the server before we continue
     with the communicate() function.  It sends the request, and if and when the server gets back to us, whatever's
     specified as request[requestid].onreadystatechange is performed.  So, we have to define .onreadystatechange
     BEFORE we actually make contact with the server.  If you're reading this and trying to learn how it works,
     you may want to take a glance at the last part of the communicate() function first, and then come back here. */
        try {
            /* We use try and catch because Javascript will give an error when we try to access request[requestid].status if the
            server is down or if the user navigates away from the page. */
            if (request[requestid].readyState == 4 && request[requestid].status == 200) {
                //window.clearTimeout(timeout[requestid]);
                document.body.style.cursor = 'default';
                /* 4 = The AJAX Request is complete; 200 = The HTTP server found the data we needed and was able to send it to us. */
                //eval(request[requestid].responseText);
                document.getElementById(html_id).innerHTML=request[requestid].responseText;
            
            } else if (request[requestid].readyState == 4 && request[requestid].status != 200) {
                window.clearTimeout(timeout[requestid]);
                if (failure) eval(failure);
                document.body.style.cursor = 'default';
                alert ('Error3: ' + request[requestid].status + ': Server error/timeout.  If you entered data, it may or may not have been saved.  Please contact your systems administrator.');
		//Eroare de server / timeout.
		//Daca ati introdus date, acestea pot fi sau nu pot fi salvate.
		//Va rugam sa contactati administratorul de sisteme.
            }
        } catch(e) {
            window.clearTimeout(timeout[requestid]);
            document.body.style.cursor = 'default';
            if (failure) eval(failure);
            alert ('Error4:  Unable to communicate with server.  Please contact your systems administrator.  You may want to try again in a few minutes to see if the problem fixes itself. \n\n(Either the server was down, the communication was interrupted, or there was an error in the data sent by the server.)\n' + e + '\n\n' + request[requestid].responseText);
        }
    }
     
    /* IE would NOT stop caching displaying cached data, so I'm now putting the requestid in the query string so it gets fresh data from the server each time. */
    if (method.toLowerCase() == "post") {
        request[requestid].open( "POST", url + "?randomstring=" + requestid, true );
        request[requestid].setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8"); 
        if(querystring.search('-i.php')==-1){
            //request[requestid].setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
        }
        else {
            //alert ("POST image");
            //request[requestid].setRequestHeader("Content-Type", "image/jpeg");
        }
        request[requestid].send(querystring);
    } else {
        request[requestid].open( "GET", url + "?randomstring=" + requestid + "&" + querystring, true );
        request[requestid].setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8"); 
        if(url.search('-i.php')==-1){
            //request[requestid].setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
        }
        else {
            //alert ("GET image");
            //request[requestid].setRequestHeader("Content-Type", "image/jpeg");
        }
        request[requestid].send("");
    }
    
    /* Timeout after 20 seconds.  No need to call failure or put up an alert because onreadystatechange takes care of that. */
    timeout[requestid] = window.setTimeout("timeout['" + requestid + "'] = request['" + requestid + "'].abort()", 300000); //20000 = 20sec
}
