// JavaScript Document

function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}


function MM_validateForm() { //v4.0
  if (document.getElementById){
    var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
    for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=document.getElementById(args[i]);
      if (val) { nm=val.name; if ((val=val.value)!="") {
        if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
          if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
        } else if (test!='R') { num = parseFloat(val);
          if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
          if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
            min=test.substring(8,p); max=test.substring(p+1);
            if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
      } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; }
    } if (errors) alert('The following error(s) occurred:\n'+errors);
    document.MM_returnValue = (errors == '');
} }



function winBRopen(theURL, Name, popW, popH, scroll) { // V 1.0
	var winleft = (screen.width - popW) / 2;
	var winUp = (screen.height - popH) / 2;
	winProp = 'width='+popW+',height='+popH+',left='+winleft+',top='+winUp+',scrollbars='+scroll+',resizable=no'
	Win = window.open(theURL, Name, winProp)
	if (parseInt(navigator.appVersion) >= 4) { Win.window.focus(); }
	if (navigator.appVersion.indexOf("Mac")!=-1) {
		window.open(theURL,Name,winProp).focus();}
}



// Funkcije za promjene cijena na searchu ovisno dali je odabran buy ili rent
function changePrice(what) {
	
	var dd_price_from = document.getElementById("price_from")
	var dd_price_from_rent = document.getElementById("price_from_rent")
	var dd_price_to = document.getElementById("price_to")
	var dd_price_to_rent = document.getElementById("price_to_rent")
	
	
	
	if (what == 'rent') {
		
		dd_price_from.style.display = 'none';
		dd_price_to.style.display = 'none';
		
		dd_price_from.disabled = true;
		dd_price_to.disabled = true;
		
		
		dd_price_from_rent.style.display = 'block';
		dd_price_to_rent.style.display = 'block';
		
		dd_price_from_rent.disabled = false;
		dd_price_to_rent.disabled = false;
	}
	
	else if (what == 'buy') {
		
		dd_price_from.style.display = 'block';
		dd_price_to.style.display = 'block';
		
		dd_price_from.disabled = false;
		dd_price_to.disabled = false;
		
		
		dd_price_from_rent.style.display = 'none';
		dd_price_to_rent.style.display = 'none';
		
		dd_price_from_rent.disabled = true;
		dd_price_to_rent.disabled = true;
	}
}

function setDefaultPrice() {
	rb_rent = document.getElementById("radio_rent")
	rb_buy = document.getElementById("radio_buy")
	
	// kad dodje sale feed onda treba biti obrnuto
	rb_buy.checked = true;
	rb_rent.checked = false;
	
	//changePrice('buy');
	changePrice('buy');
}

function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      oldonload();
      func();
    }
  }
}
