var XMLHttpRequestObject=false;
if (window.XMLHttpRequest) {
	XMLHttpRequestObject = new XMLHttpRequest();
} else if (window.ActiveXObject) {
	XMLHttpRequestObject = new ActiveXObject("Microsoft.XMLHTTP");
}

function setOdDo(v) {
	re=/\./i;
	tmp=v[0].toString().replace(re, ',');
	if (tmp.indexOf(',')==-1) {tmp=tmp+',0';}
	$('c_od').value=tmp;
	tmp=v[1].toString().replace(re, ',');
	if (tmp.indexOf(',')==-1) {tmp=tmp+',0';}
	$('c_do').value=tmp;
}
function setSlider(obj, handle) {
	re=/,/i;
	v=[1,6];
	v[0]=parseFloat($('c_od').value.replace(re, '.'));
	v[0]=Math.round(v[0]*10)/10;
	v[1]=parseFloat($('c_do').value.replace(re, '.'));
	v[1]=Math.round(v[1]*10)/10;
  if ((handle==0) && (v[0]>=(v[1]-dif))) {v[1]=v[0]+dif;}
  if ((handle==1) && (v[1]<=(v[0]+dif))) {v[0]=v[1]-dif;}
	if (v[0]<minmax[0]) {
		v[0]=minmax[0];
		if (v[1]<=(v[0]+dif)) {v[1]=v[0]+dif;}
	}
	if (v[1]>minmax[1]) {
		v[1]=minmax[1];
		if (v[0]>=(v[1]-dif)) {v[0]=v[1]-dif;}
	}
	if (handle==1) {
  	s1.setValue(v[0], 0);
  	s1.setValue(v[1], 1);
	}
	else {
  	s1.setValue(v[1], 1);
  	s1.setValue(v[0], 0);
	}
	setOdDo(v);
}
var slUpdate = function(v,evt) {
	v[0]=Math.round(v[0]*10)/10;
	v[1]=Math.round(v[1]*10)/10;
  if ((evt.activeHandleIdx==0) && (v[0]>=(v[1]-dif))) {s1.setValue((v[1]-dif),0);}
  if ((evt.activeHandleIdx==1) && (v[1]<=(v[0]+dif))) {s1.setValue((v[0]+dif),1);}
	setOdDo(v);
};

function CheckContactForm(obj) {
	// kontaktní formulář
	// zkontroluje, jestli jsou zadané povinné položky
	if ((obj.email.value=="") || (obj.email.value=="@")) {
		window.alert('Zadejte prosím Váš email.');
		return false
	}
//	re=/(.+@{1}.+\..+)/i;
	re=/^([-_a-zA-Z0-9]+(\.?[-a_a-zA-Z0-9]+)*)+@[-a-zA-Z0-9]+(\.[-a-zA-Z0-9]+)*\.[a-zA-Z]{2,6}$/;
	r=obj.email.value.search(re);
	if (r==-1) {
		window.alert('Zadejte prosím Váš platný email.');
		return false
	}
	if (obj.dotaz.value=="") {
		window.alert('Zadejte prosím text dotazu.');
		return false
	}
	obj.action='cf-kontakt-form-send.php';
	return true;
}

var g_timer=null;
function set_lupa(obr_id, w, h, alink) {
	g_timer=setTimeout("f_lupa('"+obr_id+"', "+w+", "+h+", '"+alink+"')", 100, "JavaScript");
}
function f_lupa(b_id, w, h, alink) {
		obj=document.getElementById(b_id);
		obr=document.getElementById('lupa');
		obrdiv=document.getElementById('lupadiv');
		objlink=document.getElementById('lupalink');
    posx=findPosX(obj);
    posy=findPosY(obj);
    bodyposx=findPosX(document.getElementById('main'));
    //bodyposy=findPosY(document.getElementById('main'));
		//alert(posx+' x '+posy+'       '+bodyposx+' x '+bodyposy);
		objlink.href=alink;
		var re=new RegExp("\/tn\/","i");;
  	obr.src=obj.src.replace(re, '/tnl/');
		obr.alt=obj.alt;
   	obrdiv.style.width=w+'px';
   	obrdiv.style.height=h+'px';
   	obr.style.width=w+'px';
   	obr.style.height=h+'px';
  	obrdiv.style.left=(posx-bodyposx)+'px';
  	obrdiv.style.top=(posy-223)+'px';
		obrdiv.style.display='block';
		obrdiv.style.position='absolute';
}
function f_lupa_hide() {
	if (g_timer!=null) {
		clearTimeout(g_timer);
		g_timer=null;
	}
	obrdiv=document.getElementById('lupadiv');
	obrdiv.style.position='static';
	obrdiv.style.display='none';
	obr=document.getElementById('lupa');
	obr.src='timg/transparent.png';
}
function f_lupa_cancel() {
	if (g_timer!=null) {
		clearTimeout(g_timer);
		g_timer=null;
	}
}

function findPosX(obj)
{
  var curleft = 0;
  if(obj.offsetParent)
    while(1) 
    {
      curleft += obj.offsetLeft;
      if(!obj.offsetParent)
        break;
      obj = obj.offsetParent;
    }
  else if(obj.x)
    curleft += obj.x;
  return curleft;
}

function findPosY(obj)
{
  var curtop = 0;
  if(obj.offsetParent)
    while(1)
    {
      curtop += obj.offsetTop;
      if(!obj.offsetParent)
        break;
      obj = obj.offsetParent;
    }
  else if(obj.y)
    curtop += obj.y;
  return curtop;
}

function logAway(c55, hash) {
	// getne si skript, ktery zaloguje odchozi odkaz
	XMLHttpRequestObject.open('GET', 'logaway.php?c='+c55+'&d='+hash);
	XMLHttpRequestObject.send(null);
}

function CheckContactFormUver(obj) {
	// kontaktní formulář na výpočet uvěru
	// zkontroluje, jestli jsou zadané povinné položky
	if ((obj.kraj.value=="") || (obj.kraj.value=="-")) {
		window.alert('Zadejte prosím kraj.');
		return false
	}
	if ((obj.email.value=="") || (obj.email.value=="@")) {
		window.alert('Zadejte prosím Váš email.');
		return false
	}
//	re=/(.+@{1}.+\..+)/i;
	re=/^([-_a-zA-Z0-9]+(\.?[-a_a-zA-Z0-9]+)*)+@[-a-zA-Z0-9]+(\.[-a-zA-Z0-9]+)*\.[a-zA-Z]{2,6}$/;
	r=obj.email.value.search(re);
	if (r==-1) {
		window.alert('Zadejte prosím Váš platný email.');
		return false
	}
	obj.action='cf-kontakt-form-uvery-send.php';
	return true;
}
