$(document).ready(function(){
	 $("#listaproducatori li:odd").addClass("par");
	 $("#listaproducatori li:last-child").addClass("last");
	 $("a.masina:last-child").addClass("last");
	$("#harta a").lightBox();

	  $(".MsoNormal").attr('style', '').removeClass('MsoNormal');
	  $("a[href='#']").attr("href", "javascript:void(0)");
});


function esteIE()
	{
		var browser = navigator.appName;

		if(browser == "Microsoft Internet Explorer") 
			return true;
			
		return false;		
	}
function MakeObject() {
	var xmlhttp=false; 
        try {
                xmlhttp = new ActiveXObject('Msxml2.XMLHTTP'); 
        } catch (e) {
                try {
                        xmlhttp = new
                        ActiveXObject('Microsoft.XMLHTTP'); 
            } catch (E) {
                xmlhttp = false;
                        }
        }
        if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
                xmlhttp = new XMLHttpRequest(); 
        }
		return xmlhttp;
	}
	
	

function preia(param)
{
	var request=MakeObject();
	
	switch(param)
	{
		case "modele":
		{
	
	list = document.getElementById('alegemarca');
			id = list.value;
			request.open('get', 'returnant.php?tip=model&id=' + id);
			request.onreadystatechange = function () {
				
						if(request.readyState == 4)
					{ 
						
						var raspuns = request.responseText;	
				
						var c = document.getElementById('alegemodelul');
						
						if(esteIE() || (navigator.appName.indexOf("Opera") + 1))
						{
							c.outerHTML = '<select name="alegemodelul" id="alegemodelul">'+raspuns+'</select>';
						
						}
						else {
							c.innerHTML = raspuns;
						
						}
						
					} 
			}
			request.send(false);
			break;
			}
			
	   	case "dotari":
		{
	
	list = document.getElementById('modele');
			id = list.value;
			request.open('get', 'returnant.php?tip=dotari&id=' + id);
			request.onreadystatechange = function () {
				
						if(request.readyState == 4)
					{ 
						
						var raspuns = request.responseText;	
						var d = document.getElementById('div_dotari');
						if(esteIE() || (navigator.appName.indexOf("Opera") + 1))
						{
							d.outerHTML = '<div id="div_dotari">'+raspuns+'</div>';
						}
						else {
							d.innerHTML = raspuns;
						}
						
					} 
			}
			request.send(false);
			break;
			}			
			
	}	
}

function formula(dobanda)
{
var rate=dobanda/12;
var nper=$('#nrrate').val();
//if (nper>72) {alert('Cel mult 72 de rate');document.getElementById('nrrate').value=72;nper=72;}

var credit=$('#credit').val();
//alert(credit);


var pv=credit*(1-($('#avans').val())/100)*(-1);

var fv=$('#reziduala').val()*credit;
//var fv=0;

var type=0;
var r = Math.pow(1 + rate, nper);
var pmt = (fv + pv * r) / ((1 + rate * type) * (1 - r) / rate);	
pmt=parseInt(pmt);	
	
if (pmt) $('#valrata').html("&#8364; "+pmt);	
	
}

function calcul_avans()
{
var credit=$('#creditcalcul').val();
var avans=$('#avanscalcul').val();

var val_avans = avans/100*credit;
	
if (val_avans) $('#val_avans').html("("+val_avans+" EUR)");	
	
}

function setspecial(id,total) {
	var i;
	for(i=1;i<=total;i++)
	{
		$("#cartea"+i).removeClass("special");
	}
			$("#cartea"+id).addClass("special");
			
		document.getElementById("divma").innerHTML="Trimite mail lui "+document.getElementById("nume"+id).innerHTML;
		document.getElementById("desthid").value=document.getElementById("email"+id).innerHTML;
				
}


function ImageBlender(container, imgs, d){

 this.imgs = imgs;
 this.container = container;
 this.index = 0;
 this.duration = d;
 this.cache = [];
 this.isCached = false;

 this.startBlending = function(){

 if(this.index == this.imgs.length){
 this.index = 0;
 this.isCached = true;
 }
 var src = this.imgs[this.index++];

 this.changePhoto(src);
 var that = this;

 window.setTimeout(function(){
 that.startBlending();
 }, this.duration);
 }

 this.changePhoto = function(src){

 var oldImg = this.container.getElementsByTagName('img')[0];

 if(this.isCached == true) {
 var newImg = this.cache[this.index];

 if (newImg != undefined) {
 newImg.style.display = 'none';
 this.container.appendChild(newImg);
 $(newImg).fadeIn(1200, function(){$(oldImg).remove();});
 }
 }else {
 var newImg = document.createElement('img');
 this.cache.push(newImg);
 newImg.className = oldImg.className;
 newImg.style.display = 'none';
 this.container.appendChild(newImg);
 newImg.src = src;

 if (newImg.complete) {
 $(newImg).fadeIn(1200, function(){$(oldImg).remove();});
 }
 else {
 newImg.onload = function(){
 $(newImg).fadeIn(1200, function(){$(oldImg).remove();});
 }
 }
 }
 }

 this.startBlending();
};
 


