function redirect(form) {
    var tip_obiect = document.tip_obiect.tip_obiect.value;
	document.location.href='index.php?option=calculator-rate&tip_obiect=' + tip_obiect;
}
function redirect_pr(form) {
    var tip_obiect = document.tip_obiect.tip_obiect.value;
	var predefinit = document.tip_obiect.produs_predefinit.value;
	document.location.href='index.php?option=calculator-rate&tip_obiect=' + tip_obiect + '&produs_predefinit=' + predefinit;
}

function ajaxFunctionDob(){
	var ajaxRequest;  // The variable that makes Ajax possible!
	
	try{
		// Opera 8.0+, Firefox, Safari
		ajaxRequest = new XMLHttpRequest();
	} catch (e){
		// Internet Explorer Browsers
		try{
			ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try{
				ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e){
				// Something went wrong
				alert("Your browser broke!");
				return false;
			}
		}
	}
	// Create a function that will receive data sent from the server
	ajaxRequest.onreadystatechange = function(){
		if(ajaxRequest.readyState == 4){
			var nume=document.calc.tip_rata.value
			dobanda = document.getElementById(nume).value
			m = "m_" + nume
			marja_calc = document.getElementById(m).value
			document.calc.dob_ref.value = dobanda
			document.calc.marja.value = marja_calc
			document.calc.Interest_Rate.value = parseFloat(document.calc.dob_ref.value) + parseFloat(document.calc.marja.value)
		}
	}
	ajaxRequest.open("GET", true);
	ajaxRequest.send(null); 
}

function initRate(){
	var nume=document.calc.tip_rata.value
	dobanda = document.getElementById(nume).value
	m = "m_" + nume
	marja_calc = document.getElementById(m).value
	document.calc.dob_ref.value = dobanda
	document.calc.marja.value = marja_calc
	document.calc.Interest_Rate.value = parseFloat(document.calc.dob_ref.value) + parseFloat(document.calc.marja.value)
}


function ajaxFunction(){
	var ajaxRequest;  // The variable that makes Ajax possible!
	
	try{
		// Opera 8.0+, Firefox, Safari
		ajaxRequest = new XMLHttpRequest();
	} catch (e){
		// Internet Explorer Browsers
		try{
			ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try{
				ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e){
				// Something went wrong
				alert("Your browser broke!");
				return false;
			}
		}
	}
	// Create a function that will receive data sent from the server
	ajaxRequest.onreadystatechange = function(){
		if(ajaxRequest.readyState == 4){
			document.calc.Down_Payment.value = Math.round(document.calc.Avans_Procent.value*document.calc.CIP.value,2);
		}
	}
	ajaxRequest.open("GET", true);
	ajaxRequest.send(null); 
}

function ajaxFunctionVR(){
	var ajaxRequest;  // The variable that makes Ajax possible!
	
	try{
		// Opera 8.0+, Firefox, Safari
		ajaxRequest = new XMLHttpRequest();
	} catch (e){
		// Internet Explorer Browsers
		try{
			ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try{
				ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e){
				// Something went wrong
				alert("Your browser broke!");
				return false;
			}
		}
	}
	// Create a function that will receive data sent from the server
	ajaxRequest.onreadystatechange = function(){
		if(ajaxRequest.readyState == 4){
			document.calc.Residual_Value.value = Math.round(document.calc.Residual_Value_Procent.value*document.calc.CIP.value,2);
			if(document.calc.Residual_Value.value != 0){
				document.calc.Residual_in_rates.checked = false;
			}
			else{
				document.calc.Residual_in_rates.checked = true;
			}
		}
	}
	ajaxRequest.open("GET", true);
	ajaxRequest.send(null); 
}

function ajaxFunctionFrec(){
	var ajaxRequest;
	try{
		ajaxRequest = new XMLHttpRequest();
	} catch (e){
		try{
			ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try{
				ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e){
				alert("Your browser broke!");
				return false;
			}
		}
	}
	ajaxRequest.onreadystatechange = function(){
		if(ajaxRequest.readyState == 4){
			document.calc.tipul_ratei.value = document.calc.id_rate_type_leasing.value;
		}
	}
	ajaxRequest.open("GET", true);
	ajaxRequest.send(null); 
}

function ajaxFunctionCom(){
	var ajaxRequest;  // The variable that makes Ajax possible!
	
	try{
		// Opera 8.0+, Firefox, Safari
		ajaxRequest = new XMLHttpRequest();
	} catch (e){
		// Internet Explorer Browsers
		try{
			ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try{
				ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e){
				// Something went wrong
				alert("Your browser broke!");
				return false;
			}
		}
	}
	// Create a function that will receive data sent from the server
	ajaxRequest.onreadystatechange = function(){
		if(ajaxRequest.readyState == 4){
			if(document.calc.CIP.value != ""){
				document.calc.comision.value = Math.round(document.calc.comision_procent.value*document.calc.CIP.value,2);
				document.calc.Down_Payment.value = Math.round(document.calc.Avans_Procent.value*document.calc.CIP.value,2);
				document.calc.Residual_Value.value = Math.round(document.calc.Residual_Value_Procent.value*document.calc.CIP.value,2);
				if(document.calc.Residual_Value.value != 0){
					document.calc.Residual_in_rates.checked = false;
				}
				else{
					document.calc.Residual_in_rates.checked = true;
				}
			}
			else {
				document.calc.comision.value = 0;
				document.calc.Down_Payment.value = 0;
				document.calc.Residual_Value.value = 0;
			}
		}
	}
	ajaxRequest.open("GET", true);
	ajaxRequest.send(null); 
}
