//dialog cu yes / no						
function qDialogYesNo(text)
{	
	return confirm(text);
}
	
//dialog cu confirmare a unui cuvant
function qDialogInputCheck(text, confirmare)
{
	inputText = window.prompt(text);
	return inputText == confirmare;
}

//verifica daca e in array-ul de randuri
function qInArray(value)
{
	var i = null;
	for(i = 0; i < qRanduriSelectate.length; i++)
		if(qRanduriSelectate[i] == value) return true;
	return false;
}

//adauga un rand in array-ul de randuri
function qAddInArray(value)
{
	//vefific daca mai exista 
	var i = null;
	for(i = 0; i < qRanduriSelectate.length; i++)
		if(qRanduriSelectate[i] == value) return true;
	//daca nu o adaug
	qRanduriSelectate.push(value);
	return true;
}

//sterge un rand din array-ul de randuri
function qRemoveFromArray(value)
{
	result = new Array();
	var i = null;
	for(i = 0; i < qRanduriSelectate.length; i++)
		if(qRanduriSelectate[i] != null && qRanduriSelectate[i] != value) result.push(qRanduriSelectate[i]);
	qRanduriSelectate	= result;
	return true;
}

//coloreaza un rand
function qColoreaza(rand, tip, checkbox, meniu)
{
	var celule = null;

	if (typeof(rand.style) == 'undefined') return false;
	if (typeof(document.getElementsByTagName) != 'undefined') celule = rand.getElementsByTagName('td');
	else if (typeof(rand.cells) != 'undefined') celule = rand.cells;
	else return false;
	var c = null;
	var nrCelule  = celule.length;
	if(meniu) nrCelule--;
	
	switch(tip)
	{
		case 'over':
			//colorez randul cu culoarea de over
			for (c = 0; c < nrCelule; c++)
					celule[c].className = qClassOver;
		break;
		case 'out':
			if(qInArray(rand))
			{
				//colorez cu culoare de click
				for (c = 0; c < nrCelule; c++)
					celule[c].className = qClassClick;
			}
			else
				//sau scot culoarea
				for (c = 0; c < nrCelule; c++)
					celule[c].className = '';
		break;
		case 'click':
			if(!checkbox) return;
			if(qRandCancel) return true;
			if(qInArray(rand))
			{
				//scot culoarea de pe rand
				for (c = 0; c < nrCelule; c++)
					celule[c].className = '';
				qRemoveFromArray(rand);
				if(checkbox)
				{
					if (typeof(document.getElementsByTagName) != 'undefined') input = celule[0].getElementsByTagName('input');
					else if (typeof(celule[0].cells) != 'undefined') input = celule[0].cells;
					else return false;
					if(typeof(input[0].type) != 'undefined' && input[0].type == 'checkbox') input[0].checked = false;
				}
			}
			else
			{
				//pun culoarea pe rand
				for (c = 0; c < nrCelule; c++)
					celule[c].className = qClassClick;
				qAddInArray(rand);
				if(checkbox)
				{
					if (typeof(document.getElementsByTagName) != 'undefined') input = celule[0].getElementsByTagName('input');
					else if (typeof(celule[0].cells) != 'undefined') input = celule[0].cells;
					else return false;
					if(typeof(input[0].type) != 'undefined' && input[0].type == 'checkbox') input[0].checked = true;
				}
			}
		break;
	}
	return true;
}

//selecteaza, deselecteaza, sau inverseaza selectia checkbox-urilor
function qCheckboxuriSelecteaza(tip, checkbox, meniu)
{		
	tabela = document.getElementById('q_tabela');
	if (typeof(tabela) == 'undefined') return false;
	
	//randuri
	if (typeof(document.getElementsByTagName) != 'undefined') randuri = tabela.getElementsByTagName('tr');
	else if (typeof(tabela.cells) != 'undefined') randuri = tabela.cells;
	else return false;
	
	var i = null;
	for(i = 0; i < randuri.length; i++)
	{
		//coloane
		if (typeof(document.getElementsByTagName) != 'undefined') coloane = randuri[i].getElementsByTagName('td');
		else if (typeof(randuri[i].cells) != 'undefined') coloane = randuri[i].cells;
		else continue;

		//input
		if (typeof(document.getElementsByTagName) != 'undefined') input = coloane[0].getElementsByTagName('input');
		else if (typeof(coloane[0].cells) != 'undefined') input = coloane[0].cells;
		else continue;
		if(typeof(input[0]) != 'undefined' && input[0].type == 'checkbox')
		{
			switch(tip)
			{
				case 'select':
					qRemoveFromArray(randuri[i]);
					qColoreaza(randuri[i], 'click', checkbox, meniu);
				break;
				
				case 'clear':
					qAddInArray(randuri[i]);
					qColoreaza(randuri[i], 'click', checkbox, meniu);
				break;
				
				case 'invert':
					qColoreaza(randuri[i], 'click', checkbox, meniu);
				break;
			}
		}
	}
}

//afiseaza / ascunde un div
function qInchideDeschide(numeRand)
{
	rand = document.getElementById(numeRand);
	if (typeof(rand) == 'undefined') return false;
	if(rand.style.display == 'block') rand.style.display = 'none';
	else rand.style.display = 'block';
}