
function MM_swapImgRestore() { 
    var i, x, a = document.MM_sr; 
    for(i=0; a && i<a.length && (x=a[i]) && x.oSrc; i++) 
        x.src = x.oSrc;
}

function MM_preloadImages() { 
    var d = document; 
    if(d.images){ 
        if(!d.MM_p) 
            d.MM_p = new Array();
        var i, j = d.MM_p.length, a = MM_preloadImages.arguments; 
        for(i=0; i<a.length; i++)
            if (a[i].indexOf("#")!=0){ 
                d.MM_p[j]=new Image; 
                d.MM_p[j++].src=a[i];
            }
    }
}

function MM_findObj(n, d) { 
    var p, i, x;  
    if(!d) 
        d=document; 
    if((p=n.indexOf("?"))>0 && parent.frames.length){
        d=parent.frames[n.substring(p+1)].document; 
        n=n.substring(0,p);
    }
    if(!(x=d[n])&&d.all) 
        x=d.all[n]; 
    for (i=0; !x && i<d.forms.length; i++)
        x=d.forms[i][n];
    for(i=0; !x && d.layers && i<d.layers.length; i++) 
        x=MM_findObj(n,d.layers[i].document);
    if(!x && d.getElementById) 
        x=d.getElementById(n); 
    return x;
}

function MM_swapImage() { 
    var i, j=0, x, a=MM_swapImage.arguments; 
    document.MM_sr = new Array; 
    for(i=0; i<(a.length-2); i+=3)
        if ((x=MM_findObj(a[i])) != null){
            document.MM_sr[j++]=x; 
            if(!x.oSrc) 
                x.oSrc=x.src; 
            x.src=a[i+2];
        }
}

function MenuHorzMouseIn( e ) {
    if(document.getElementById(e) && document.getElementById(e).name != "selected"){   
        MM_swapImage(e,'','images/meniuLightBanner.jpg',1);
    }
}

function MenuHorzMouseOut( e ) {
    if(document.getElementById(e) && document.getElementById(e).name != "selected"){   
        MM_swapImgRestore();
    }
}

function MenuHorzMouseClick( e ) {
    if(document.getElementById(e)){   
        if(document.getElementById(e).name != "selected") {
            MM_swapImgRestore(); 
        }
        window.location = document.getElementById(e).href;
    }
}

function MenuVertMouseIn( e ) {
    if(document.getElementById(e) /*&& document.getElementById(e).name != "selected"*/ ){
        document.getElementById(e).style.textDecoration = "underline";
    }
}

function MenuVertMouseOut( e ) {
    if(document.getElementById(e) /*&& document.getElementById(e).name != "selected"*/){
        document.getElementById(e).style.textDecoration = "none";
    }
}

function MenuVertMouseClick( e ) {
    if(document.getElementById(e)){        
        //if(document.getElementById(e).name != "selected") {
            document.getElementById(e).style.textDecoration = "none";
        //}
        window.location = document.getElementById(e).href;
    }
}

function getPrice(iAp)
{
	var STANDARD_PRICE = 399;
	var MINIM_UNIT = 95;
	var MINIM_PRICE = 21900;
	var LIMIT_AP_1 = 125;
	var LIMIT_AP_2 = 400;
	var LIMIT_AP_3 = 1000;
	var LIMIT_PRICE_1 = 50000;
	var LIMIT_PRICE_2 = 85000;
	var LIMIT_PRICE_3 = 130000;
		
	var iResult = iAp * STANDARD_PRICE;
	var iUnit;
		
	if(iResult < MINIM_PRICE){
		iResult = MINIM_PRICE;			
	}else if(iAp == LIMIT_AP_1 ){	
		iResult = LIMIT_PRICE_1;
	}else if(iAp > LIMIT_AP_1 && iAp < LIMIT_AP_2){
		iUnit = parseInt((LIMIT_PRICE_2 - LIMIT_PRICE_1) / (LIMIT_AP_2 - LIMIT_AP_1));
		iResult = LIMIT_PRICE_1 + (iAp - LIMIT_AP_1)*iUnit;			
	}else if(iAp == LIMIT_AP_2 ){
		iResult = LIMIT_PRICE_2;			
	}else if(iAp > LIMIT_AP_2 && iAp < LIMIT_AP_3){
		iUnit = parseInt((LIMIT_PRICE_3 - LIMIT_PRICE_2) / (LIMIT_AP_3 - LIMIT_AP_2));
		iResult = LIMIT_PRICE_2 + (iAp - LIMIT_AP_2)*iUnit;			
	}else if(iAp == LIMIT_AP_3 ){
		iResult = LIMIT_PRICE_3;			
	}else if(iAp > LIMIT_AP_3){
		iResult = LIMIT_PRICE_3 + (iAp - LIMIT_AP_3)*MINIM_UNIT;			
	}
	
	return Math.round(iResult / 100);
}

function setPrice(sAp, bErrorMsg)
{
	var iAp = parseInt(sAp);
    var iPretAp = 0;
    var sPretAp = "";
    var ZECIMALE_PRET = 2;
    var i = 0;
    
	if (isNaN(iAp) || iAp <= 0){
		if (bErrorMsg == true){
            alert("Introduceti un numar, mai mare decat zero.");
        }
        document.getPriceForm.result_pret_ap.value = "";
		document.getPriceForm.result.value = "";
	}else{
		document.getPriceForm.result.value = getPrice(iAp) + ",00 ";

        iPretAp = Math.ceil(getPrice(iAp) / iAp * 100) / 100;
        sPretAp = String(iPretAp).replace(".", ",");
        if(sPretAp.search(",") == -1){
            sPretAp = sPretAp + ",";
            for(i=0; i < ZECIMALE_PRET; i++){
                sPretAp = sPretAp + "0";
            }
        }else if(sPretAp.length - sPretAp.search(",") - 1 < ZECIMALE_PRET){
            // Sunt prea putine cifre dupa virgula
            while(sPretAp.length - sPretAp.search(",") - 1 < ZECIMALE_PRET){
                sPretAp = sPretAp + "0";
            }
        }else{
            // Sunt prea multe cifre dupa virgula
            sPretAp = sPretAp.substr(0, sPretAp.search(",") + ZECIMALE_PRET + 1);
        }
        
        document.getPriceForm.result_pret_ap.value = sPretAp + " ";
	}
}
