/* *************************************************************************

Subor: main.js
Autor: Matus Moravcik
Popis: bezne JS funckie
-------------------------------------------------------------------------------
Historia zmien:
2008-04-14 Matus Moravcik, vytvorenie suboru

************************************************************************* */


//ziskat objekt elementu podla id
function get_element(id) {
	if (document.getElementById) return document.getElementById(id);
	else if (document.all) return document.all[id];
}

//potvrdzovacia funckia
function confirm_submit(txt)
{
	if (!txt) txt = "Pokračovať?";
	var agree=confirm(txt);
	if (agree)
	return true ;
	else
	return false ;
}


//zisti ci pozivam IE alebo nie
function isIe() {
	var browser=navigator.appName;
	if (browser == 'Microsoft Internet Explorer') return true;
	else return false;
}


//pridanie input type foto do TBODY s id ID
//next id
var next_count = 2;
function add_foto_input(id) {
	if (window.next_count > 10) alert ('Max 10 obrázkov!');
	else {
		var tr = document.createElement('tr');
		var td = document.createElement('td');
		var td2 = document.createElement('td');
		td2.innerHTML = ' ';
		tr.appendChild(td2);
		td.innerHTML = '<input type="file" name="file_'+next_count+'">';
		tr.appendChild(td);		
		document.getElementById(id).appendChild(tr);
		next_count++;
	}
}

function add_foto_input_un(id) {
		var tr = document.createElement('tr');
		var td = document.createElement('td');
		var td2 = document.createElement('td');
		td2.innerHTML = ' ';
		tr.appendChild(td2);
		td.innerHTML = '<input type="file" name="file_'+next_count+'">';
		tr.appendChild(td);		
		document.getElementById(id).appendChild(tr);		
		next_count++;
}



//kopirovanie kontaktnych udajov do fakturacnych
function copy_fields() {
	var prefix = '_inv';
	var fields=new Array();
	fields[0]='street';
	fields[1]='city';
	fields[2]='zip';

	for(i=0;i<fields.length;i++) {
		element_source = get_element(fields[i]);
		element = get_element('inv_'+fields[i]);
		element.value = element_source.value;
	}

	//skopirovanie select box hodnoty
	element_source = get_element('country');
	element = get_element('inv_country');
	element.selectedIndex = element_source.selectedIndex;

}

function display_row(what,where,how_many) {

	var element_str;
	var display_property;

	for (i=0; i < how_many; i++) {
		element_str = where + i;
		element = get_element(element_str);
		element.style.display='none';
	}
	element_str = where + what;

	element = get_element(element_str);

	//	if (isIe()) display_property = 'block';
	//	else display_property = 'table-row-group';
	display_property = 'block';

	element.style.display = display_property;
}

function is_selected(input_form,field,message) {
	alert(input_form.field);
	alert(input_form.field.options[form.field.selectedIndex].value);
	alert(input_form.field.options[input_form.field.selectedIndex].value);
	if (element.value == 0 || element.value=='') {
		alert('Zadajte prosím pole ' + message);
		return false;
	}
	return true;
}

function check_boxes(min_to_be_checked,message) {
	var total=0;
	frm = document.porovnaj_nehnutelnosti;
	for(var i=0; i < frm.comp_id.length; i++){
		if(frm.comp_id[i].checked) {
			total++;
		}
	}
	if( total < min_to_be_checked ) {
		alert(message);
		return false;
	} else {
		return true;
	}
}

