if (window != window.top) top.location.href = location.href;
function kasutaja(theURL,winName,features) { window.open("userinfo.php?"+theURL,'','scrollbars=0,menubar=0,status=0,resizable=0,width=300,height=170'); }
function saadas6brale(theURL,winName,features) { window.open("c_saadas6brale.php?"+theURL,'','scrollbars=0,menubar=0,status=0,resizable=0,width=300,height=170'); }
function uusleht(theURL,winName,features) 
{
 
	window.open("add_post.php?"+theURL,'-','scrollbars=1,menubar=0,status=0,resizable=0,width=300,height=300');
}

function uustoode(theURL,winName,features) { window.open("c_uustoode.php?"+theURL,'','scrollbars=1,menubar=0,status=0,resizable=0,width=300,height=440'); }
function uusfirma(theURL,winName,features) { window.open("add_company.php",'','scrollbars=0,menubar=0,status=0,resizable=0,width=370,height=500'); }
function uusfoorumipost(theURL,winName,features) { 
window.open("add_post.php?forum",'','scrollbars=0,menubar=0,status=0,resizable=0,width=300,height=300'); }


function kuulutus(theURL,winName,features) {
window.open("kuulutus.php?id="+theURL,'','scrollbars=0,menubar=0,status=0,resizable=0,width=500,height=300'); }


function uushange(theURL,winName,features) {
window.open("add_post.php?procurement",'','scrollbars=0,menubar=0,status=0,resizable=0,width=300,height=300'); }
function uuskuulutus(theURL,winName,features) {
window.open("add_post.php?ad",'','scrollbars=0,menubar=0,status=0,resizable=0,width=300,height=300'); }
function showLogin() {
window.open("popup_login2.php",'','scrollbars=0,menubar=0,status=0,resizable=0,width=300,height=300'); }

function popUp(URL) {
day = new Date();
id = day.getTime();
eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=300,height=300');");
}

function saadakiri(email) 
{
var tmp_enne = '';
var tmp_p2rast = '';
var uus_string = '';
var start = 0;
var em_hash = email.indexOf ('@');
for (count = 1; count <= em_hash; count ++)
{
tmp_enne += email.substring (start, count);
start++
}
start = em_hash;
start ++
em_hash +=2;
for (count = em_hash; count <=email.length; count++)
{
tmp_p2rast +=email.substring (start, count)
start++
}
uus_string = tmp_p2rast +'@' + tmp_enne;
parent.location = 'mailto:'+uus_string;
}
//-->

<!--
function lisatabel(milline) {
var tmp; 
if (document.images["b_" + milline].src.indexOf("_on") == -1) { 
tmp = document.images["b_" + milline].src.replace("_off", "_on");
document.getElementById('box_' + milline).style.display = "none";
document.images["b_" + milline].src = tmp;
} else { 
tmp = document.images["b_" + milline].src.replace("_on", "_off");
document.getElementById('box_' + milline).style.display = "block";
document.images["b_" + milline].src = tmp;
} 
}
// -->


/**
 * DHTML email validation script. Courtesy of SmartWebby.com (http://www.smartwebby.com/dhtml/)
 */

function echeck(str) {

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   alert("Paranda e-maili aadress")
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert("Paranda e-maili aadress")
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    alert("Paranda e-maili aadress")
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    alert("Paranda e-maili aadress")
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    alert("Paranda e-maili aadress")
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    alert("Paranda e-maili aadress")
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    alert("Paranda e-maili aadress")
		    return false
		 }

 		 return true					
	}

function ValidateForm(){
	var emailID=document.registratsioon.email
	
	if ((emailID.value==null)||(emailID.value=="")){
		alert("Sisesta e-mail")
		emailID.focus()
		return false
	}
	if (echeck(emailID.value)==false){
		emailID.value=""
		emailID.focus()
		return false
	}
	return true
 }
 
 
/**
 * siit lõpuni hansa asjad)
 */ 
 
 	function getEURprice( price ){
		if( price < 200000){
			return 3.52 ;
		}else if ( price >= 200000 && price < 300000 ){
			return 3.42 ;
		}else if( price >= 300000 ){
			return 3.27 ;
		}
	}

	function getLTLprice( price ){
		if( price < 200000){
			return 4.55 ;
		}else if( price > 200000 && price < 300000 ){
			return 4.45 ;
		}else{
			return 4.35 ;
		}
	}

	function fix(value)
	{
		return value.replace(',','.');
	}
	
	function calculate()
	{
		var calc = document.forms['calculator'];
		var price = Math.ceil(fix(calc.price.value));
		var sissemaks = Math.ceil(calc.sissemaks.value);
		var sissemakse = Math.ceil(price/100)*sissemaks;
		var laen = price - sissemakse;
		var intress = fix(calc.intress.value);
		var month = parseInt(calc.years.value * 12);
		if(intress && price && month)
		{
            var intress2 = (intress/100/12) + 1;
            var it = (1 - Math.pow( intress2, -month) ) / (intress2 - 1);
            calc.kuumakse.value = Math.round( laen / it );
            calc.sissemakse.value = Math.round(sissemakse);
		}
		else
		{
            calc.kuumakse.value = ' -';
            calc.sissemakse.value = ' -';
		}
	}


