/*
Strip whitespace from the beginning and end of a string
Input : a string
*/
function trim(str)
{
	return str.replace(/^\s+|\s+$/g,'');
}

/*
Make sure that textBox only contain number
*/
function checkNumber(textBox)
{
	while (textBox.value.length > 0 && isNaN(textBox.value)) {
		textBox.value = textBox.value.substring(0, textBox.value.length - 1)
	}
	
	textBox.value = trim(textBox.value);
/*	if (textBox.value.length == 0) {
		textBox.value = 0;		
	} else {
		textBox.value = parseInt(textBox.value);
	}*/
}

/*
	Check if a form element is empty.
	If it is display an alert box and focus
	on the element
*/
function isEmpty(formElement, message) {
	formElement.value = trim(formElement.value);
	
	_isEmpty = false;
	if (formElement.value == '') {
		_isEmpty = true;
		alert(message);
		formElement.focus();
	}
	
	return _isEmpty;
}

/*
	Set one value in combo box as the selected value
*/
function setSelect(listElement, listValue)
{
	for (i=0; i < listElement.options.length; i++) {
		if (listElement.options[i].value == listValue)	{
			listElement.selectedIndex = i;
		}
	}	
}

function delcart() 
{
var c = document.forms[0].hidCartId;
var vyber = '';
if (c.length==undefined) {vyber = c.value;}
	for (i=0; i < c.length; i++) {
		if (c[i].checked) {vyber = c[i].value;}
	}

	if (vyber == '') { alert ("Nevybrali ste nehnuteľnosť (krúžok vedľa značky), ktorú sa má odznačiť!");} 
	else { 
	document.forms[0].hidmycartId.value = vyber;
	document.forms[0].submit();
	//window.location.href = "action=delete&cid=" + vyber ;
	}
};

function editor() {
  Win2 = open('../../editor/editor.htm', '', 'width=710,height=400,toolbar=no,status=yes,resizable=yes')
  //document.forms[0].zdrojeditor.value ... treba nastavit nazov pola, ktore sa edituje
  isDocReady();
};

function isDocReady() {
	try {
		var c = document.forms[0].zdrojeditor.value;
		var d = Win2.document;
		if (d.readyState == "complete") {
			d.myform.myOpener.value = c;
  			d.frames(1).document.body.innerHTML = document.getElementById(c).innerHTML;
		} else {
			window.setTimeout("isDocReady()", 100);
		}
	} catch (e) {}
};

function checkSearchForm()
{
	with (window.document.frmSearchProduct) {
		if (cboCategory.selectedIndex == -1) {
			alert('Vyberte kategóriu nehnuteľnosti!');
			cboCategory.focus();
			return;
		} else {
			submit();
		}
	}
}

function checkInsertForm()
{
	with (window.document.frmSearchProduct) {
		if ((txttxt.value == "") || (txtpriezvisko.value == "") || (txtadresa.value == "") || (txttelefon.value == "") || (txtemail.value == ""))  {
			alert('Vyplňte prosím všetky povinné položky (všade, kde je pri názve hviezdička)!');
			//cboCategory.focus();
			return;
		} else {
			if (code.value == "")	 {
				alert('Nezadali ste text na obrázku!');
				return;
			} else {	
				var mm = document.getElementById('txtemail').value;
				if ((mm.indexOf(".") > 2) && (mm.indexOf("@") > 0)) {				
					submit();
				} else {
					alert('Zadaná kontaktná adresa nezodpovedá pravidlám pre e-mailové adresy! Prekontrolujte prosím jej správnosť!');
					return;
				}
			}
		}
	}
}

function checkKontaktForm()
{
	with (window.document.myform) {
		//if ((odosielatel.value == "") || (odosielatel.value == "@"))  {
		if ((odosielatel.indexOf(".") > 2) && (odosielatel.indexOf("@") > 0)) {
			document.getElementById('priloha').value=document.getElementById('abc').innerHTML;
			submit();
		} else {
			alert('Zadaná kontaktná adresa nezodpovedá pravidlám pre e-mailové adresy! Prekontrolujte prosím jej správnosť!');
			odosielatel.focus();
			return;
		}
	}
}

function checkRegForm()
{
	with (window.document.frmRegt) {
		if ((regemail.value == "") || (regcode.value == ""))  {
			alert('Nezadali ste všetky požadované hodnoty!');
			return;
		} else {
			submit();
		}
	}
}

function ShowPicture(kam)
{
	document.getElementById('ciel').src = kam;	
}

function strpresun(stranka)
{
	document.getElementById('strana').value = stranka;
	window.document.frmSearchProduct.submit();
}
