//CHANGE TAB
function tab(group,num) {
  for (i=1;i<30;i++) {
    tabid = 'tab'+group+'-'+i;
    divid = 'div'+group+'-'+i;
    if (document.getElementById(tabid)) {
      if (i==num)   {
        document.getElementById(tabid).className = 'active';
         document.getElementById(divid).className = 'boxes';
      }
      else {
        document.getElementById(tabid).className = 'a';
        document.getElementById(divid).className = 'boxes dspnone';
      }
    }
    else continue;
  }
}
function disp_not_dsp(elemid,num) {
    if (num==1) {
        document.getElementById(elemid).className = 'popmes dspblock';
     }else{
        document.getElementById(elemid).className = 'dspnone';
    }
}
//END CHANGE TAB
//WINDOW POPUP
function pop_window(pURL, pWidth, pHeight) {
  if (!pURL) {
    return;
  }
  var offsetWidth = 0;
  var offsetHeight = 0;
  var windowFeatures = "toolbar=no,directories=no,location=no,status=no,menubar=no,resizable=yes,scrollbars=yes,"
    + "width=" + (pWidth + offsetWidth) + ",height=" + (pHeight + offsetHeight);
  var popup = window.open(pURL, 'imagePopup', windowFeatures);
  if (popup) {
    popup.focus();
	popup.moveTo(0,0);
  }
}
// END WINDOW  POPUP

// AJAX SEARCH
function getHostname(url) {
	var re = new RegExp('^(?:f|ht)tp(?:s)?\://([^/]+)', 'im');
	return url.match(re)[1].toString();
}
if (getHostname(window.location.href) == 'localhost') dir = 'http://localhost/smartsystem.bg/site/';
else dir = 'http://'+getHostname(window.location.href)+'/';
function ajaxsearch(oEvent) {
    oEvent = oEvent || window.event;
    var txtField = oEvent.target || oEvent.srcElement;
    var oXmlHttp = zXmlHttp.createRequest();
	if (txtField.value.length < 3) return false;
	//dir = window.location.href.indexOf(".com/users.html")==-1 && window.location.href.indexOf(".eu/users.html")==-1 ?  "../" : "";
    oXmlHttp.open("get", dir+"ajax_search.php?s=" + encodeURIComponent(txtField.value), true);
    oXmlHttp.onreadystatechange = function () {
        if (oXmlHttp.readyState == 4) {
            if (oXmlHttp.status == 200) {
                var arrInfo = oXmlHttp.responseText.split("||");
                var divSearch = document.getElementById("ajaxsearch");
                if (!eval(arrInfo[0])) {
                    document.getElementById("ajaxresults").innerHTML = arrInfo[1];
					divSearch.style.display = 'block';
					o = document.getElementById('txtajaxsearch');
					var pos = get_obj_pos(o);
                } else {
                }
            } else {
            }
        }
    };
    oXmlHttp.send(null);
}
function get_obj_pos(obj) {
	var x = 0;
	var y = 0;
	while (obj.offsetParent) {
		x += obj.offsetLeft;
		y += obj.offsetTop;
		obj = obj.offsetParent;	}
	return [ x, y ];
}
window.onload = function () {
	if (document.getElementById("txtajaxsearch")) {
		if (zXmlHttp.isSupported()) {
			var txtSearch = document.getElementById("txtajaxsearch");
			txtSearch.onkeyup = ajaxsearch;
		}
	}
}
document.onclick = function (oEvent) {
	if (document.getElementById("txtajaxsearch")) {
		var oEvent = oEvent || window.event;
		o = oEvent.target || oEvent.srcElement;
		if (o.id != 'ajaxsearch' && o.id != 'txtajaxsearch') { document.getElementById("ajaxsearch").style.display = 'none'; }
	}

}
// END AJAX
//
// RATE
function rate(n) {
	for(var i=1; i<=6; i++) {
		var el = document.getElementById('rate'+i);
		if (i<n) el.innerHTML='<img onmouseover="rate('+i+');" src="'+dir+'ss_vision/star.gif" alt="Rate '+i+'" />';
		else if (i==n) el.innerHTML='<img src="'+dir+'ss_vision/star.gif" alt="Rate '+i+'" />';
		else  el.innerHTML='<img onmouseover="rate('+i+');" src="'+dir+'ss_vision/star-off.gif" alt="Rate '+i+'" />';
	}
}
// END RATE


function selectRadio(n){
    document.forms["myform"]["lizing_monts"][n].checked=true;
}
function selectRadio2(n){
    document.forms["myform"]["copypostadr"][n].checked=true;
}
function select_f(curselect ,elemid, searchvalue) {
    var chosenoption=document.getElementById(curselect).selectedIndex;
    if (chosenoption==searchvalue) {
        document.getElementById(elemid).style.display='block';
     }else{
        document.getElementById(elemid).style.display='none';
    }
}
function hidedispl(act ,elemid) {
    if (act==1) {
        document.getElementById(elemid).style.display='block';
     }else{
        document.getElementById(elemid).style.display='none';
    }
}
