// JavaScript Document
/** odesln XMLHttp poadavku
@param function obsluha funkce zajiujc obsluhu pi zmn stavu poadavku, dostane parametr s XMLHttp objektem
@param string method GET|POST|...
@param string url URL poadavku
@param string [content] tlo zprvy
@param array [headers] pole pedanch hlaviek ve tvaru { 'hlavika': 'obsah' }
@return bool true v ppad spchu, false jinak
*/
function send_xmlhttprequest(obsluha, method, url, content, headers)
{
    var xmlhttp = (window.XMLHttpRequest ? new XMLHttpRequest : (window.ActiveXObject ? new ActiveXObject("Microsoft.XMLHTTP") : false));
	

	if (!xmlhttp) {
        alert(" nemuzu vytvorit xmlhttp object");
		return false;
    }
    xmlhttp.open(method, url);
    xmlhttp.onreadystatechange = function() {
        obsluha(xmlhttp);
    };
    if (headers) {
        for (var key in headers) {
            xmlhttp.setRequestHeader(key, headers[key]);
        }
    }
    xmlhttp.send(content);
    return true;
}


function get_info(id,val)
{
//	if (!send_xmlhttprequest(info_obsluha, 'GET', 'info_xml.php?val=' + val + '&id=' + id)) {  // pozor na cestu k obsluze
//        return false;
//    }
	//	document.getElementById('info').innerHTML = 'loading...';

//	return true;
}

function list_vin(user) {

    id1=document.getElementById('a1').value;
	id4=document.getElementById('a4').value;
	id6=document.getElementById('a6').value;
	id8=document.getElementById('a8').value;
	id9=document.getElementById('a9').value;
	id15=document.getElementById('a15').value;
	id01=document.getElementById('a01').value;

	if (!send_xmlhttprequest(list_vin_obsluha, 'GET', 'list_vin_xml.php?id1=' + id1 + '&id4=' + id4 + '&id6=' + id6+ '&id8=' + id8+ '&id9=' + id9   + '&id15=' + id15 + '&id01=' + id01 + '&user=' + user)) {  // pozor na cestu k obsluze
        return false;
    }
	document.getElementById('list_vin').innerHTML = 'loading...';
	return true;
}

function list_vin_obsluha(xmlhttp)
{
    if (xmlhttp.readyState == 4) {
        // aktualizace odpovd na zklad aktulnho stavu
		//alert("proslo");
		var val= xmlhttp.responseText;
		//var a1 = xmlhttp.responseXML.getElementsByTagName('a1');
        //alert (val);
		//for (var i=0; i < a1.length; i++) {
			//val=a1[0].firstChild.data;
		//insertValue(document.getElementById('a1'), (a1[i].firstChild.data), a1[i].getAttribute('id'));
		//} 
		//setValue(document.getElementById('a1'),pom);
		document.getElementById('list_vin').innerHTML = val;

    }
}

function change_city_reg(id,val)
{
//	document.getElementById('a4').className = 'hide';
// odesln poadavku na aktualizaci dat
    id1=document.getElementById('a1').value;
	id4=document.getElementById('a4').value;
	id6=document.getElementById('a6').value;
	id8=document.getElementById('a8').value;
	id9=document.getElementById('a9').value;
	id15=document.getElementById('a15').value;
	id01=document.getElementById('a01').value;
	
	document.getElementById('zmena').value=val;
	//alert ('val=' + val + '&id1=' + id1 + '&id4=' + id4 + '&id15=' + id15);
	//if (id!=0) { 
	
	if (!send_xmlhttprequest(city_obsluha, 'GET', 'search_xml.php?val=' + val + '&id1=' + id1 + '&id4=' + id4 + '&id6=' + id6+ '&id8=' + id8+ '&id9=' + id9   + '&id15=' + id15 + '&id01=' + id01)) {  // pozor na cestu k obsluze
        return false;
    }
	//alert('search_xml.php?val=' + val + '&id1=' + id1 + '&id4=' + id4 + '&id6=' + id6+ '&id8=' + id8+ '&id9=' + id9   + '&id15=' + id15 + '&id01=' + id01);
    //document.getElementById('stav-search').innerHTML = 'loading...';
    //document.getElementById('stav-search').className = 'full';
	return true;
	//} //else document.getElementById('stav-search').innerHTML = '&nbsp;';
}


function city_obsluha(xmlhttp)
{
    if (xmlhttp.readyState == 4) {
        // aktualizace odpovd na zklad aktulnho stavu
        val=document.getElementById('zmena').value;
		
		//alert("proslo");
		
		pom=document.getElementById('a1').value;
		removeValue(document.getElementById('a1'),document.getElementById('a1').value);
		var a1 = xmlhttp.responseXML.getElementsByTagName('a1');
        for (var i=0; i < a1.length; i++) {
			insertValue(document.getElementById('a1'), (a1[i].firstChild.data), a1[i].getAttribute('id'));
			} 
			setValue(document.getElementById('a1'),pom);
		
		pom=document.getElementById('a4').value;
		removeValue(document.getElementById('a4'),document.getElementById('a4').value);
		var a4 = xmlhttp.responseXML.getElementsByTagName('a4');
        for (var i=0; i < a4.length; i++) {
		insertValue(document.getElementById('a4'), (a4[i].firstChild.data), a4[i].getAttribute('id'));
		} 
		setValue(document.getElementById('a4'),pom);
	   
		pom=document.getElementById('a6').value;
		removeValue(document.getElementById('a6'),document.getElementById('a6').value);
		var a6 = xmlhttp.responseXML.getElementsByTagName('a6');
        for (var i=0; i < a6.length; i++) {
		insertValue(document.getElementById('a6'), (a6[i].firstChild.data), a6[i].getAttribute('id'));
		} 
		setValue(document.getElementById('a6'),pom);

		pom=document.getElementById('a8').value;
		removeValue(document.getElementById('a8'),document.getElementById('a8').value);
		var a8 = xmlhttp.responseXML.getElementsByTagName('a8');
        for (var i=0; i < a8.length; i++) {
		insertValue(document.getElementById('a8'), (a8[i].firstChild.data), a8[i].getAttribute('id'));
		} 
		setValue(document.getElementById('a8'),pom);

		pom=document.getElementById('a9').value;
		removeValue(document.getElementById('a9'),document.getElementById('a9').value);
		var a9 = xmlhttp.responseXML.getElementsByTagName('a9');
        for (var i=0; i < a9.length; i++) {
		insertValue(document.getElementById('a9'), (a9[i].firstChild.data), a9[i].getAttribute('id'));
		} 
		setValue(document.getElementById('a9'),pom);

		pom=document.getElementById('a15').value;
		removeValue(document.getElementById('a15'),document.getElementById('a15').value);
		var a15 = xmlhttp.responseXML.getElementsByTagName('a15');
        for (var i=0; i < a15.length; i++) {
		insertValue(document.getElementById('a15'), (a15[i].firstChild.data), a15[i].getAttribute('id'));
		} 
		setValue(document.getElementById('a15'),pom);

		pom=document.getElementById('a01').value;
		removeValue(document.getElementById('a01'),document.getElementById('a01').value);
		var a01 = xmlhttp.responseXML.getElementsByTagName('a01');
        for (var i=0; i < a01.length; i++) {
		insertValue(document.getElementById('a01'), (a01[i].firstChild.data), a01[i].getAttribute('id'));
		} 
		setValue(document.getElementById('a01'),pom);

	   
	   //document.getElementById('a4').className = 'full'; 
	   //document.getElementById('stav-search').style.display = 'none';
    }
}

function setValue(theSel,set)
{

for(i=theSel.length-1; i>=0; i--)
    {
        if (theSel.options[i].value == set )	theSel.selectedIndex=i;
	}
}


function removeValue(theSel,set)
{
	

for(i=theSel.length-1; i>=0; i--)
    {
        theSel.options[i] = null;
    }
//var newOpt1 = new Option(set, '0');
//    theSel.options[0] = newOpt1;
/*    if (theSel.length > 0) {
      theSel.selectedIndex = selIndex == 0 ? 0 : selIndex - 1;
    } */
  
}

function insertValue(theSel, newText, newValue,sel)
{
  if (theSel.length == 0) {
    var newOpt1 = new Option(newText, newValue);
    theSel.options[0] = newOpt1;
    //theSel.selectedIndex = 0;
  } else {
    
	var newCount=theSel.length;
	var newOpt1 = new Option(newText, newValue);
    theSel.options[newCount] = newOpt1;
	
} 
}

function poslat(pre,firm,dom) {
	//document.write('<a href="mailto:' + pre + '@' + firm + '.' + dom '">' + pre + '@' + firm + '.' + dom + '</a>');
	document.write('<a href="mailto:' + pre + '@' + firm + '.' + dom + '">' +pre + '@' + firm + '.' + dom + '</a>');
}



function setDisplay(elem,property) {
	e = document.getElementById(elem);
	/*	if (e.style.display == property) e.style.display = 'none';
	else e.style.display = property; */
	e.style.display = property;
}

function displayList(at,month) {
	pointer = at+month;
	
	if ( pointer = document.getElementById(pointer) )
	{
	if (pointer.className == 'expand') { pointer.className = 'expanded'; setDisplay(at+'menu'+month,'block'); }
	else { pointer.className = 'expand'; setDisplay(at+'menu'+month,'none'); }
	}
}

      function ukaz(hodnota,pole) {
		//  alert (hodnota.value);
        	if (hodnota.value=="0") {
 	           pole.style.visibility = "visible";
             } else pole.style.visibility = "hidden";
   }
     


