var popUps = new Array();

function popUpWin(URLStr, winName, width, height) {
	if (popUps[winName] && !popUps[winName].closed) {
		popUps[winName].close();
	}
	popUps[winName] = window.open(URLStr, winName, 'toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,resizable=yes,copyhistory=yes,width='+width+',height='+height+',left=50, top=50,screenX=50,screenY=50');
}

function popUpImg(URLStr, left, top, width, height) {
    popUpWin = window.open('', 'popUpImg', 'toolbar=no,location=no,directories=no,status=no,menub ar=no,scrollbars=no,resizable=no,copyhistory=yes,width='+width+',height='+height+',left='+left+', top='+top+',screenX='+left+',screenY='+top+'');
    popUpWin.document.writeln("<html><head />");
    popUpWin.document.writeln('<body topmargin="0" leftmargin="0" rightmargin="0" bottommargin="0" marginheight="0" marginwidth="0">');
    popUpWin.document.writeln('<img src="' + URLStr + '" border="0" alt="Закрыть окно" onclick="window.close()">');
    popUpWin.document.writeln("</html>");
}

function loanCalc(obj) {
	var form = obj.form;
	var cost    = form.elements["cost"].value;
	var initial = form.elements["initial"].value;
	var init_me = form.elements["initial_measure"].value;
	var period  = form.elements["period"].value;
	
	popUpWin("/modals/loan-calc.php?cost=" + cost + "&initial=" + initial + "&initial_measure=" + init_me + "&period=" + period,"loanWin",470,560);
	return false;
}

function compareCars() {
	if (popUps["compareCars"] && !popUps["compareCars"].closed) {
		popUps["compareCars"].close();
	}
	popUps["compareCars"] = window.open("/modals/compare-cars.php", "compareCars", 'toolbar=no,location=no,directories=no,status=yes,menubar=yes,scrollbars=yes,resizable=yes,copyhistory=yes,width=870,height=760,left=50, top=50,screenX=50,screenY=50');
	return false;
}

function checkChooseCalc(form) {
	var result = true;
	if (form.elements("initial").value == "") {
		result = false;
	}
	if (form.elements("monthpayment").value == "") {
		result = false;
	}
	if (!result) {
		alert("Заполните все поля");
		return false;
	}
	return true;
}