function new_windowPhoto(strToUrl)
{
 window.open(strToUrl, 'Galeria','toolbar=no,scrollbars=yes,width=800,height=340');
}

function getCookieData(label) 
{
      var labelLen = label.length
      var cLen = document.cookie.length
      var i = 0
      while (i < cLen) {
         var j = i + labelLen
         if (document.cookie.substring(i,j) == label) {
            var cEnd = document.cookie.indexOf(";",j)

            if (cEnd == -1) {
                cEnd = document.cookie.length

            }
            return unescape(document.cookie.substring(j+1,cEnd))
         }
         i++
      }
      return ""
}

var base = new Date(0)
dateAdjustment = base.getTime()

function getExpParam() {        
var expDate = new Date()        
var dateInSecs = expDate.getTime()        

var oneWkFromNow = (7 * 24 * 60 * 60 * 1000) + dateInSecs - (2 * dateAdjustment)        

expDate.setTime(oneWkFromNow)                
                
return ("; expires=" + expDate.toGMTString())        

}

function savecookies(chk)
{

s = getCookieData("cars")

if (chk.checked)
{

	if (s!="") 
	{
		s = s + "|" + chk.value;
	}
    else
	{
		s = "0|" + chk.value;
	}

}
else
{
	a = s.split("|")
	
	s="0"

    for (i=0; i<a.length; i++)
		if(a[i]!=chk.value && a[i]!=0)
		{
			if (s!="") 
			{
				s = s + "|" + a[i];
			}
			else
			{
				s = "0|" + a[i];
			}
		}
	
}

    var expParam = getExpParam();      
	document.cookie="cars=" + escape(s) + expParam;
	//window.location.reload();
	return 0;

}

function deletecookies(chk)
{
s = getCookieData("cars")

if (!chk.checked)
{

	if (s!="") 
	{
		s = s + "|" + chk.value;
	}
    else
	{
		s = "0|" + chk.value;
	}

}
else
{
	a = s.split("|")
	
	s="0"

    for (i=0; i<a.length; i++)
		if(a[i]!=chk.value && a[i]!=0)
		{
			if (s!="") 
			{
				s = s + "|" + a[i];
			}
			else
			{
				s = "0|" + a[i];
			}
		}
	
}
    var expParam = getExpParam();      
	document.cookie="cars=" + escape(s) + expParam;
	window.location.reload();
	return 0;

}

function savecookiesurl(id)
{
s = getCookieData("cars")

if (s!="") 
{
	s = s + "|" + id;
}
   else
{
	s = "0|" + id;
}
    var expParam = getExpParam();      
	document.cookie="cars=" + escape(s) + expParam;
	//window.location.reload();
	window.alert("Samochód zosta³ dodany do ulubionych!");
	return 0;
}

function clearcookie(btn)
{
	
	document.cookie= "cars=0"
	window.location.reload();
	return 0;
}

var decDelimOnServer = '.';
var decDelimOnClient = ',';
var thousandDelim = ' ';
var groupDigit = 3; 

function StrToFloat(x)
{
s = x;
	
re1 = new RegExp(decDelimOnClient,"g");
s = s.replace(re1,".");

k = "";

for (i=0;i<s.length;i++)
{
	if (((s.charAt(i)>='0') && s.charAt(i)<='9') || (s.charAt(i)=='.'))
	{
		k=k+s.charAt(i);
	}
}

return parseFloat(k);

}

function FloatToStr(val){

	var decDelimPos, i, temp;
	val = new String(val);

	if (val.lastIndexOf('.')<0)
	{
		val= val + '.00';
	}

	if (val.length-val.lastIndexOf('.')==2)
	{
		val= val + '0';
	}
	decDelimPos = val.lastIndexOf('.') 
	
	if (decDelimPos < 0 ) {
		decDelimPos = val.length - groupDigit
		temp = ''
	}else {
		temp = decDelimOnClient + val.substr(decDelimPos+1) 
		decDelimPos -= groupDigit
	}
	for (i = decDelimPos; i>0; i-=groupDigit) {
		temp = thousandDelim + val.substr(i ,groupDigit) + temp
	} 		
	return (val.slice(0,i+groupDigit) + temp);
}

function cena(x,cena){

cena=StrToFloat(cena)

if(!x.checked)cena=-cena
	document.auto.Cena_koncowa.value=FloatToStr(Math.round((StrToFloat(document.auto.Cena_koncowa.value)+cena)*100.00)/100.00)
}

function cenafromto(x,cena){

cena=StrToFloat(cena)

if(!x.checked)cena=-cena
	document.auto.Cena_koncowa_od.value=FloatToStr(Math.round((StrToFloat(document.auto.Cena_koncowa_od.value)+cena)*100.00)/100.00)
	document.auto.Cena_koncowa_do.value=FloatToStr(Math.round((StrToFloat(document.auto.Cena_koncowa_do.value)+cena)*100.00)/100.00)
}


function cenaFT(x,cena){

cena=StrToFloat(cena)

if(!x.checked)cena=-cena
	document.auto.Cena_koncowa_od.value=FloatToStr(((StrToFloat(document.auto.Cena_koncowa_od.value)+cena)*100.00)/100.00)
	document.auto.Cena_koncowa_do.value=FloatToStr(((StrToFloat(document.auto.Cena_koncowa_do.value)+cena)*100.00)/100.00)
}

function changeid(x)
{
	document.auto.ids.value=document.auto.idstate.options[document.auto.idstate.options.selectedIndex].value;
	document.contact.ids.value=document.auto.idstate.options[document.auto.idstate.options.selectedIndex].value;
}

function changeall()
{

	if (document.auto.t_ex.checked)
	{
		document.auto.ex.value="1";
		document.contact.ex.value="1";
	} else
	{
		document.auto.ex.value="";
		document.contact.ex.value="";
	}


	if (document.auto.t_limit.checked)
	{
		document.auto.limit.value="1";
		document.contact.limit.value="1";
	} else
	{
		document.auto.limit.value="";
		document.contact.limit.value="";
	}
	
	document.auto.day.value=document.auto.t_day.value;
	document.auto.month.value=document.auto.t_month.value;
	document.auto.year.value=document.auto.t_year.value;
	document.auto.maxprice.value=document.auto.t_maxprice.value;

	document.contact.day.value=document.auto.t_day.value;
	document.contact.month.value=document.auto.t_month.value;
	document.contact.year.value=document.auto.t_year.value;
	document.contact.maxprice.value=document.auto.t_maxprice.value;

}

function change(){
var w=500,h=200,scale
	scale=(tmp.width>w)?scale=w/tmp.width:1
	if(tmp.height*scale>h)scale=h/tmp.height
	document.images["logo"].width=tmp.width*scale
	document.images["logo"].height=tmp.height*scale
}
function getint(x){
var y='',i
	for(i=0;i<x.value.length;i++){
		y+=((x.value.charAt(i)>='0')&&(x.value.charAt(i)<='9'))?x.value.charAt(i):''
	}
	x.value=y
}


function isValidName(field)
{
	var s = field.value;
	if (s.length == 0)
		return false;
	for(i=0; i<s.length; i++)
		if (s.charAt(i) != " ")
			return true;
	return false;
}

function resetval(x)
{
for(var i=0;document.forms[0][i]!=x;i++);
document.forms[0][i-1].value=''
x.blur()
}
