function popUpPic(URL, width, height)
{
    var inc_h= 29;
    var inc_w = 5;
    if(!width)
        width = 300;
    if(!height)
        height = 150;
    height = height + inc_h;
    width = width + inc_w;
    window.open(URL, "picWindow", "width="+width+",height="+height+",scrollbars=no,status=no,resizeable=no");
}

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];}}
}

var prev;
function ChangeImg(img, alt, id)
{
    var image, tbl;

    image = document.getElementById('good-big-img');
    tbl = document.getElementById('colors-table-'+id);

    image.src = "/files/Image/Gallery/"+img;
    image.alt = alt;
    tbl.className = "border-03";
    if(prev && prev != tbl) prev.className = "border-02";
    prev = tbl;
}

function changeMap(elemId)
{
	var elem, tr2;
    elem = document.getElementById("tr1-"+elemId);
    tr2  = document.getElementById("tr2-"+elemId);
    if (elem)
    {
        with(elem.style)
            if (display == "block" || display == "")
            {
            	display = "none";
                tr2.style.display = "none";
            }
            else
            {
            	display = "";
                tr2.style.display = "";
            }
    }
}


// расчет платежа по кредиту
function calculate()
{
    with (document.forms['fm1'])
    {
        if(cost.value < 120000)
        {
            alert("Кредит предоставляется на автомобили дороже 120 000 руб."); 
            return false; 
        }
        
        var fpr = firstpersent.value;
        var sum = cost.value*(1-fpr/100);
        var pc = 8;
        
        firstpay.value = Math.round(cost.value*fpr/100);
        monthpay.value = Math.round((sum*pc/1200)/(1-Math.pow(1/(1+pc/1200), period.value)));
    }
}

// описание полностью или сокращенно
function ShowFull()
{
	if($("#full").is(":hidden")) 
	{
		$("#short").fadeOut("slow", function(){ $("#full").fadeIn("slow"); });	
	}
	else 
	{
		$("#full").fadeOut("slow", function(){ $("#short").fadeIn("slow"); });
	}
	
	return false;
}


function winOpen(url, name, w, h)
{
	w = window.open(url, name, 'Toolbar=0, Location=0, Directories=0, Status=0, Menubar=0, Scrollbars=0, Resizable=1, Width='+ w +', Height='+ h); 
	w.focus(); 
	return false;
}


function SelectModel()
{
	brandID = $('#credit_brand').val();

	if( brandID > 0 )
	{  
		$('#credit_model_block').html('<select name="model" class="forms-03"><option value="0">загрузка...</option></select>');
		
		$.ajax({
	       data: { brandid: brandID, getmodels: 'y' },
	       dataType: "script",
	       cache: false,
	       url: "/functions/ajax.php"
	    });
	}
	else
	{
		$('#credit_model_block').html('<select name="model" class="forms-03"><option value="0">выберите модель</option></select>');
	}
}

function SelectMod()
{
	modelID = $('#credit_model').val();

	if( modelID > 0 )
	{  
		$('#credit_mod_block').html('<select name="mod_id" class="forms-03"><option value="0">загрузка...</option></select>');
		
		$.ajax({
	       data: { modelid: modelID, getmods: 'y' },
	       dataType: "script",
	       cache: false,
	       url: "/functions/ajax.php"
	    });
	}
	else
	{
		$('#credit_mod_block').html('<select name="mod_id" class="forms-03"><option value="0">выберите комплектацию</option></select>');
	}
}
