function submitForm(pageNo,lang){
	frm = document.getElementById("frmSearch");
	frm.action = lang + "/2/" + pageNo;
	frm.submit();
}


function trim(str){
   return str.replace(/^\s*|\s*$/g,"");
}

function isValidEmail(src) {
     var emailReg = "^[\\w-_\.]*[\\w-_\.]\@[\\w]\.+[\\w]+[\\w]$";
     var regex = new RegExp(emailReg);
     return regex.test(src);
  }

function FilteredSelect_Item_CreateOption(){
	return new Option(this.text, this.value);
}

function FilteredSelect_Item(value, filter, text){
	this.value = value;
	this.filter = filter;
	this.text = text;
	this.checked = false;
	this.createOption = FilteredSelect_Item_CreateOption;
}


function FilteredSelect_Init(filteredSelectId, parentSelectId, val){
	s = document.getElementById(filteredSelectId);
	if(s){
		if(!s.initialized){
			var items = new Array;
			for(i=0; i<s.options.length; i++){
				var item = new FilteredSelect_Item(s.options[i].value, s.options[i].id, s.options[i].innerHTML);
				items[i] = item;
			}
			document.getElementById(filteredSelectId).Sort = FilteredSelect_Sort;
			document.getElementById(filteredSelectId).Clear = FilteredSelect_Clear;
			document.getElementById(filteredSelectId).Fill = FilteredSelect_Fill;
			document.getElementById(filteredSelectId).AddFilter = FilteredSelect_AddFilter;
			s.items = items;
			s.initialized = true;
			//if we have a parent select hook to its onchange event handler and run it once
			if(parentSelectId){
				s.parentSelectId = parentSelectId;
				s.parentSelect = document.getElementById(parentSelectId);
				document.getElementById(parentSelectId).childFilteredSelect = s;
				document.getElementById(parentSelectId).onchange = FilteredSelect_ParentSelect_OnChange;
				document.getElementById(parentSelectId).change = FilteredSelect_ParentSelect_OnChange;
				document.getElementById(parentSelectId).FilterChild = FilteredSelect_ParentSelect_FilterChild;
				//save selectedIndex (IE bug, IE saves selectedIndex on history.back() rather than the selectedValue)
				//selectedIndex = s.selectedIndex;
				if(val){
					s.value = val
				}
				//run the parents change() to run inital filter
				document.getElementById(parentSelectId).change();
				//restore saved selectedIndex
				//s.selectedIndex = selectedIndex;
				
			}
		}
	}
	else
	{
		alert("FilteredSelect javascript error: "+selectId+" does not exist!");
	}
}

function FilteredSelect_Clear(){
	//preserve the selected value
	this.selectedValue = this.value;
	//uncheck all items
	for(i=0; i<this.items.length; i++){	
		this.items[i].checked = this.items[i].value=="any";
	}
	//clear the select options
	this.innerHTML = '';
}

function FilteredSelect_Fill(){
	for(i=0; i<this.items.length; i++){
		if(this.items[i].checked) {
			//add the option
			this.options[this.options.length] = this.items[i].createOption();
			//preserve the selected value
			if(this.options[this.options.length-1].value==this.selectedValue) {
				this.selectedIndex = this.options.length-1;
			}
		}
	}
}

function FilteredSelect_Sort(){
	for(i=0; i<this.options.length-1; i++){
		for(j=i; j<this.options.length; j++){
			if((this.options[j].innerHTML<this.options[i].innerHTML) && ((this.options[i].value!="any")) || (this.options[j].value=="any")){
				optioni = new Option(this.options[i].innerHTML, this.options[i].value)
				optionj = new Option(this.options[j].innerHTML, this.options[j].value)
				this.options[i] = optionj;
				this.options[j] = optioni;
			}
		}
	}
}

function FilteredSelect_ParentSelect_FilterChild(targetChild){
		if(this.value=="any"){
			//if any is selected then we must loop through the entire options collection
			//and add child options to the child select for each existing option in the parent select options collection
			for(var i=0; i<this.options.length; i++){
				if(this.options[i].value!="any"){
					targetChild.AddFilter(this.options[i].value);	
				}
			}
			//go to the next parent up...		
			if(this.parentSelect){	
				this.parentSelect.FilterChild(targetChild);
			}
		}
		else
		{
			targetChild.AddFilter(this.value);	
		}	
}

function FilteredSelect_ParentSelect_OnChange(){
	if(this.childFilteredSelect && this.childFilteredSelect.initialized){	
		//keep the selectedValue if possible
		selectedValue = this.childFilteredSelect.value;
		//clear the child FilteredSelect
		this.childFilteredSelect.Clear();
		//apply new filters to child
		this.FilterChild(this.childFilteredSelect);
		//fill the child filtered select
		this.childFilteredSelect.Fill();
		//disable the child select if only 1 option is available
		this.childFilteredSelect.disabled = this.childFilteredSelect.options.length<=1
		//call the childs onchange since its options changed its selectedvalue may have also changed
		if(this.childFilteredSelect.childFilteredSelect) this.childFilteredSelect.change();
	}
	else
	{
		//the child FilteredSelect does not exist yet or isn't initialized yet so we'll recall this function in 10ms
		window.setTimeout("document.getElementById('"+this.id+"').change()", 10);
	}
}

function FilteredSelect_AddFilter(filter){
	for(i=0; i<this.items.length; i++){
		if(this.items[i].filter==filter) {
			this.items[i].checked=true;
		}
	}
}


Date.prototype.equalsTo = function(date) {
	return ((this.getFullYear() == date.getFullYear()) &&
		(this.getMonth() == date.getMonth()) &&
		(this.getDate() == date.getDate()) &&
		(this.getHours() == date.getHours()) &&
		(this.getMinutes() == date.getMinutes()));
};

function toggleDateFields(){
	document.forms["frmSearch"].datumOd.disabled = !document.forms["frmSearch"].chkRaspolozivi.checked;
	document.forms["frmSearch"].datumDo.disabled = !document.forms["frmSearch"].chkRaspolozivi.checked;
}