    function changeModel(sform,x)
    {
		modification_div(x);  
	}

    function changeModel1(sform,x)
    {
        var subs = sform.copart_model;
        for (var m = subs.options.length - 1; m > 0; m --) subs.options[m] = null;
        for (var key = 0; key < a_models[x].length; key ++) subs.options[key] = new Option(a_models[x][key], a_models[x][key]);
        subs.options.selectedIndex = 0;
    }

    function changeModel2(sform,x)
    {
        var subs = sform.iaai_model;
        for (var m = subs.options.length - 1; m > 0; m --) subs.options[m] = null;
        if (b_models[x])
        {
            for (var key = 0; key < b_models[x].length; key ++) subs.options[key+1] = new Option(b_models[x][key], b_models[x][key]);
        }
        subs.options.selectedIndex = 0;
    }

    function changeModelOrder(sform,x)
    {
        order_modification_div(x);  
    }

    function postAuctionData(url)
    {
        var sform=document.auctionform;
        sform.action=url;
        sform.submit();
        return false;
    }

    function postData(url)
    {
        var sform=document.searchform;
        sform.action=url;
        sform.submit();
        return false;
    }

    function openPreview(url,width,height)
    {
        win=window.open('','','left='+(screen.width/2-(width/2))+',top='+(screen.height/2-(height/2)-50)+',width=' + width + ',height=' + height);
        win.document.write ('<html><head><title>Просмотр</title></head><body style="margin:0px"><img src="' + url + '" width="'+ width +'" height="' + height + '" border="0"></body></html>');
        win.document.close();
        win.focus();
    }

    function openWin(url,width,height)
    {
        win=window.open(url,'','left='+(screen.width/2-(width/2))+',top='+(screen.height/2-(height/2)-50)+',width=' + width + ',height=' + height +',scrollbars=yes');
        win.focus();
        return false;
    }

    function changeImage(url,width,height)
    {
        //openPreview(url,width,height);
        var image=document.getElementById('im');
//        image.width=width;
//        image.height=height;
        image.src=url;
        document.getElementById('big_photo_link').href = url;
        return false;
    }

    function checkShortOrderForm(sform)
    {
        if (sform.order_brand.value==0)
        {
            alert('Выберите марку');
            sform.order_brand.focus();
            return false;
        }
        if (sform.order_model.value==0)
        {
            alert('Выберите модель');
            sform.order_model.focus();
            return false;
        }
        if (sform.order_year_from.value=='' && sform.order_year_to.value=='')
        {
            alert('Выберите год');
            sform.order_year_from.focus();
            return false;
        }
    }

    function checkOrderForm(sform, mode)
    {
        if (mode==0)
        {
            if (sform.order_brand.value==0)
            {
                alert('Выберите марку');
                sform.order_brand.focus();
                return false;
            }
            if (sform.order_model.value==0)
            {
                alert('Выберите модель');
                sform.order_model.focus();
                return false;
            }
            if (sform.order_year_from.value=='')
            {
                alert('Выберите год');
                sform.order_year_from.focus();
                return false;
            }
            if (sform.order_year_to.value=='')
            {
                alert('Выберите год');
                sform.order_year_to.focus();
                return false;
            }
            if (sform.order_year_from.value>sform.order_year_to.value)
            {
                alert("Введите корректное значение 'до' для года выпуска");
                sform.order_year_from.focus();
                return false;
            }
        }
        if (sform.order_name.value==0)
        {
            alert('Введите имя');
            sform.order_name.focus();
            return false;
        }
        if (sform.order_middle.value==0)
        {
            alert('Введите отчество');
            sform.order_middle.focus();
            return false;
        }
        if (sform.order_phone.value==0)
        {
            alert('Введите телефон');
            sform.order_phone.focus();
            return false;
        }
        if (sform.order_email.value==0)
        {
            alert('Введите E-mail');
            sform.order_email.focus();
            return false;
        }
    }

    function checkSearchForm(sform, shorts)
    {
        if (!shorts && sform.year_from.value && sform.year_to.value)
        {
            if (sform.year_from.value>sform.year_to.value)
            {
                alert("Введите корректное значение 'до' для года выпуска");
                sform.year_to.focus();
                return false;
            }
        }
    }

    function checkLot(sform)
    {
        if (!sform.lot.value.length)
        {
            alert("Введите номер лота");
            sform.lot.focus();
            return false;
        }
        var prefix = sform.lot.value.substr(0,1);
        if (prefix != 'P' && prefix != 'S' && prefix != 'C' && prefix != 'I')
        {
            alert("Неправильный номер лота");
            sform.lot.focus();
            return false;
        }
        return true;
    }

    function checkFeedback()
    {
        var sform=document.feedbackform;
        if (sform.name.value==0)
        {
            alert('Введите имя');
            sform.name.focus();
            return false;
        }
        if (sform.phone.value==0)
        {
            alert('Введите телефон');
            sform.phone.focus();
            return false;
        }
        if (sform.comments.value==0)
        {
            alert('Введите сообщение');
            sform.comments.focus();
            return false;
        }
    }

    function checkFAQ()
    {
        var sform=document.faqform;
        if (sform.question.value==0)
        {
            alert('Введите вопрос');
            sform.question.focus();
            return false;
        }
        if (sform.name.value==0)
        {
            alert('Введите имя');
            sform.name.focus();
            return false;
        }
    }

    function checkSubscribe()
    {
        var sform=document.emailform;
        if (sform.email.value.length==0)
        {
            alert("Не задан E-mail");
            sform.email.focus();
            return false;
        }
    }

function isRegion(val)
{
	if (val.substr(val.length-2, val.length) == '00') return true;
	return false;
}

function changeLocation(obj)
{
    var i,j;
	j = obj.selectedIndex;
	if (window.event.ctrlKey || window.event.shiftKey)
	{
    	for(i = 1; i <int_length; i ++)
		{
			if (arIndex[i][1] == 1)
				obj.options[i].selected = true;
			else if (arIndex[i][1] == 0)
				obj.options[i].selected = false;
		}
		return;
	}
	if (j == 0)
	{
    	for(i = 1; i <int_length; i++)
		{
			obj.options[i].selected = false;
			arIndex[i][1] = 0;
		}
		obj.options[0].selected = true;
		arIndex[0][1] = 1;
		return;
	}
	else
	{
		obj.options[0].selected = false;
		arIndex[0][1] = 0;
		if (isRegion(arIndex[j][0]))
		{
			if (arIndex[j][1] == 0)
			{
				for(i = j; i <int_length; i++)
				{
					arIndex[i][1] = 1;
					if (i+1 !== int_length)
						if (isRegion(arIndex[i+1][0])) break;
				}
			}
			else if (arIndex[j][1]==1)
			{
				for( i = j; i<int_length; i ++)
				{
					arIndex[i][1] = 0;
					if (i+1 !== int_length)
						if (isRegion(arIndex[i+1][0])) break;
				}
			}
		}
		else
		{
			if (arIndex[j][1] == 0)
    			arIndex[j][1] = 1;
			else if (arIndex[j][1] == 1)
			{
				arIndex[j][1] = 0;
				for(i = j; i >= 1; i --)
				{
    				if (isRegion(arIndex[i][0]))
					{
						arIndex[i][1] = 0;
						break;
					}
				}
			}
		}
	}
	for(i = 1; i < int_length; i++)
	{
    	if (arIndex[i][1] == 1)
    		obj.options[i].selected = true;
		else if (arIndex[i][1] == 0)
			obj.options[i].selected = false;
	}
}

function modification_div(div_id)
{
	 var req;
	    if (window.XMLHttpRequest) {
	        req = new XMLHttpRequest();
	    } else if (window.ActiveXObject) {
	        req = new ActiveXObject("Msxml2.XMLHTTP");
	    }
	    req.onreadystatechange = function()
	 {
	  if (req.readyState == 4) {
	   if (req.status == 200) {
		    document.getElementById('modification').innerHTML = req.responseText;
	   }
	   else {
	    alert('Error AJAX');
	   }
	  }
	 }
	 var ajax_url = "http://www.palmoreimports.com/modifications/set_modifications.php?id="+div_id;
	
	 var tmp = ajax_url.split('?');
	 parameters=encodeURI(tmp[1]);
	 req.open("GET", ajax_url, true);
	    if (window.XMLHttpRequest) {
	  req.send(null);
	    } else if (window.ActiveXObject) {
	     req.send();
	    }
}

function order_modification_div(div_id)
{
	 var req;
	    if (window.XMLHttpRequest) {
	        req = new XMLHttpRequest();
	    } else if (window.ActiveXObject) {
	        req = new ActiveXObject("Msxml2.XMLHTTP");
	    }
	    req.onreadystatechange = function()
	 {
	  if (req.readyState == 4) {
	   if (req.status == 200) {
		    document.getElementById('order_modification').innerHTML = req.responseText;
	   }
	   else {
	    alert('Error AJAX');
	   }
	  }
	 }
	 var ajax_url = "http://www.palmoreimports.com/modifications/set_modifications.php?id="+div_id;
	
	 var tmp = ajax_url.split('?');
	 parameters=encodeURI(tmp[1]);
	 req.open("GET", ajax_url, true);
	    if (window.XMLHttpRequest) {
	  req.send(null);
	    } else if (window.ActiveXObject) {
	     req.send();
	    }
}

function getData(form)
{
    var data = '';
    for(i = 1; i <int_length; i++)
		if (obj.options[i].selected) data += obj.options[i].value + ',';

    form.iaai_place_list.value = data;
}

function changeAuction(index)
{
    var copart1 = document.getElementById('copart1');
    var copart2 = document.getElementById('copart2');
    var iaai1 = document.getElementById('iaai1');
    var iaai2 = document.getElementById('iaai2');

    copart1.style.display = 'none';
    copart2.style.display = 'none';
    iaai1.style.display = 'none';
    iaai2.style.display = 'none';

    switch (index)
    {
        case 0:
        case 3:
            copart1.style.display = '';
            copart2.style.display = '';
            break;
        case 1:
            iaai1.style.display = '';
            iaai2.style.display = '';
            break;
    }
}

function checkAuction(sform)
{
    var index = sform.auction.selectedIndex;
    if (index && !sform.year_from.value.length)
    {
        alert("Выберите значение");
        sform.year_from.focus();
        return false;
    }
    if (index && !sform.year_to.value.length)
    {
        alert("Выберите значение");
        sform.year_to.focus();
        return false;
    }
    if (sform.year_from.value && sform.year_to.value && sform.year_from.value>sform.year_to.value)
    {
        alert("Введите корректное значение 'до' для года выпуска");
        sform.year_to.focus();
        return false;
    }
    return true;
}
