function getXmlHttpObject( )
{
	var xmlHttp;
	try {
		// Gecko / IE 7
		xmlHttp	= new XMLHttpRequest();
	}
	catch (e) {
		// IE <= 6
		try {
			xmlHttp	= new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e) {
			try {
				xmlHttp	= new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (e) {
				alert("Your browser does not support AJAX!");
				return null;
			}
		}
	}
	return xmlHttp;
}

function sendRequest( method, filePath, call_data, callback_ok, callback_err )
{
	var xmlHttp	= getXmlHttpObject();
	if( xmlHttp != null ) {
		if( method == "GET" ) {
			xmlHttp.onreadystatechange = function() {
					if( xmlHttp.readyState == 4 ) {
					    if (xmlHttp.status == 200 && callback_ok)
							callback_ok(xmlHttp.responseText);
						else if (callback_err) // zrejme error
							callback_err(xmlHttp.responseText);
					}
				} 
			;
			xmlHttp.open("GET", filePath + "?" + call_data, true);
			xmlHttp.send(null);
		}
		else if(method == "POST")
		{
			xmlHttp.open("POST", filePath, true);
			//Send the proper header information along with the request
			xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
			xmlHttp.setRequestHeader("Content-length", call_data.length);
			xmlHttp.setRequestHeader("Connection", "close");
			
			xmlHttp.onreadystatechange = function() {//Call a function when the state changes.
				if( xmlHttp.readyState == 4 ) {
				    if (xmlHttp.status == 200 && callback_ok)
						callback_ok(xmlHttp.responseText);
					else if (callback_err) // zrejme error
						callback_err(xmlHttp.responseText);
				}
			}
                        //xmlHttp.open("POST", filePath, true);
			xmlHttp.send(call_data);
		}
	}
}

function get_element( id )
{
	if (document.getElementById)
   		var returnVar = document.getElementById(id);
	else if (document.all)
        var returnVar = document.all[id];
    else if (document.layers)
        var returnVar = document.layers[id];
    return returnVar;
}

function ajax_ok(data)
{
    get_element('obsah').innerHTML = data;
     //spustiFoto();
}

function bad_ajax(data)
{
    //pripadne vykomentuj
    alert(data);
}

function setMenu(cesta, parametre,el)
{
    //parametre = 'p1=prvy_par&p2=druhy_par'
    //param='param='+parameter
    //param='p1=bazmek&p2=param2'
    sendRequest( 'GET', cesta, parametre, ajax_ok, bad_ajax );
    if(el != null)
        el.blur();
}

function  blurMenu(el)
{
    el.blur();
}

function fireEvent(obj,evt){
    var fireOnThis = obj;
    if( document.createEvent ) {
        var evObj = document.createEvent('MouseEvents');
        evObj.initEvent( evt, true, false );
        fireOnThis.dispatchEvent(evObj);
    }
    else if( document.createEventObject ) {
        fireOnThis.fireEvent('on',evt);
    }
}

function defualtClick()
{
    var obj = get_element('a1');
    fireEvent(obj,'click');
    eval(obj.getElementsByTagName("span")[0].getAttribute("onclick"));    
}

// Odoslanie poli formulara na spracovanie
function sendForm()
{
    // Skript pre spracovanie formulara
    var path = "./sk/valAppForm.php";
    // Vyskladanie retazca dotazu
    var query = 'name=' + document.appForm.name.value
              + '&grad=' + document.appForm.grad.value;

    /*var rad_val="";
    for (var i=0; i < document.appForm.gender.length; i++)
    {
       if (document.appForm.gender[i].checked)
       {
          rad_val = document.appForm.gender[i].value;
          break;
       }
    }*/

        query += /*'&gender=' + rad_val
              + '&occupation=' + document.appForm.occupation.value
              +*/ '&day=' + document.appForm.day.value
              + '&month=' + document.appForm.month.value
              + '&year=' + document.appForm.year.value
              + '&street=' + document.appForm.street.value
              + '&city=' + document.appForm.city.value
              + '&postal=' + document.appForm.postal.value
              + '&email=' + document.appForm.email.value
              + '&tel=' + document.appForm.tel.value
              + '&highschool=' + document.appForm.highschool.value
              + '&branch1=' + document.appForm.branch1.value
              + '&dur1=' + document.appForm.dur1.value
              + '&college=' + document.appForm.college.value
              + '&branch2=' + document.appForm.branch2.value
              + '&dur2=' + document.appForm.dur2.value
              + '&courses=' + document.appForm.courses.value
              + '&english=' + document.appForm.english.value
              + '&german=' + document.appForm.german.value
              + '&pcskills=' + document.appForm.pcskills.value
              + '&otherskills=' + document.appForm.otherskills.value
              + '&emp1=' + document.appForm.emp1.value
              + '&job1=' + document.appForm.job1.value
              + '&wdur1=' + document.appForm.wdur1.value
              + '&emp2=' + document.appForm.emp2.value
              + '&job2=' + document.appForm.job2.value
              + '&wdur2=' + document.appForm.wdur2.value
              + '&position=' + document.appForm.position.value
              + '&sallary=' + document.appForm.sallary.value
              + '&hobbies=' + document.appForm.hobbies.value
              + '&comments=' + document.appForm.comments.value
              + '&acceptance=' + document.appForm.acceptance.value;
    // Zobrazenie stavu spracovania
    get_element('obsah').innerHTML = "<b>Údaje sa odosielajú, čakajte prosím...</b>";
    // Odoslanie poziadavky na spracovanie dat
    sendRequest( 'POST', path, query, ajax_ok, bad_ajax );
}

