function voteCheck()
{
    g=document.getElementById('total').value;
    for (var i=1; i<=g; i++)
    {
        if(document.getElementById('choice'+i).checked)
        {
            return true;
        }
    }
    alert('Выберите вариант!');
    return false;
}
function authCheck()
{
    if(document.getElementById('a1').value!='')
    {
        if(document.getElementById('a2').value!='')
        {
            return true;
        }
        else
        {
            alert('Введите пароль!');
            return false;
        }
    }
    else
    {
        alert('Введите E-mail!');
        return false;
    }
}
var m = 0; 
function winOpen5(pic, width, height, title)
{
	m++;
	x = (640 - width)/2, y = (480 - height)/2;
	if (screen) {
		var y = (screen.availHeight - height)/2;
		var x = (screen.availWidth - width)/2;
	}
		if (screen.availWidth > 1800) {
		var x = ((screen.availWidth/2) - width)/2;
	}

	var win = window.open("", m, 'width='+width+',height='+height+',screenX='+x+',screenY='+y+',top='+y+',left='+x+',titlebar=no,resizable=no,scrollbars=no');

	win.document.open();
	win.document.writeln('<html><head><meta http-equiv="Content-Type" content="text/html; charset=windows-1251"><title>'+title+'</title></head><body topmargin="0" leftmargin="0" rightmargin="0" bottommargin="0" marginwidth="0" marginheight="0">');
	win.document.writeln('<table align="center" width="100%" height="100%" cellpadding="0" cellspacing="0" border="0"><tr><td>');
 	win.document.writeln('<a title="Закрыть окно" href="#" onclick="self.close()"><img src="/'+pic+'" width="'+width+'" height="'+height+'" border="0" alt="'+title+'"></a>');
	win.document.writeln('</td></tr></table></body></html>');
	win.document.close();
}

function valid_data()
{
	document.documentElement.style.cursor='wait';	
	f = $("#dataForm :text, #dataForm :radio:checked, #dataForm select, #dataForm :hidden, #dataForm :checkbox:checked");
	$.post('error_booking.php', f, error_req);
}

function error_req(data)
{
	document.documentElement.style.cursor='default';
	if(data == '' || data == '1')
	{
		$('#dataForm').submit();	
	}else
	{
		if($('#div_box').html() == null)
		{
			h1 = parseInt(document.getElementById("hertz_block").offsetHeight);
			p = parseInt(document.documentElement.scrollTop);
			$('body').append('<div class="line-box" id="div_box"><table cellpading="0" cellspacing="0" width="100%"> <tr> <td class="top-left"><img width="10" height="10" src="i/line-box-top-left-rnd-transp.png"/> </td> <td class="top"></td> <td class="top-right"><img width="10" height="10" src="i/pixel.gif"/></td> </tr> <tr> <td class="left"></td> <td class="center"> <div class="content"><p>'+data+'</p><div class="button" style="text-align:center"><table style="margin:0 auto"><tbody><tr><td class="btn-left"/><td class="btn-text"><a onclick="close_window(); return false;" href="#">Закрыть</a></td><td class="btn-right"/></tr></tbody></table></div><div class="clear"></div></div> </td> <td class="right"></td> </tr> <tr> <td class="bottom-left"><img width="10" height="10" src="i/line-box-bottom-left-transp.png"/></td> <td class="bottom"></td> <td class="bottom-right"></td> </tr> </table></div>');
			h = parseInt(document.getElementById('div_box').offsetHeight);	
			pos_y = (h1-h)/2+p;
			$('#div_box').css('top',pos_y).show();
		}
	}
}

function close_window()
{
	$('#div_box').remove();
}

function step1()
{
    $('#step_access').val('reservationOnHomepage');
    $('#quick_access').attr('action', 'https://www.hertz.ru/').submit();
}

function step2()
{
    $('#step_access').val('whatView');
    $('#quick_access').attr('action', 'https://www.hertz.ru/fees_and_order/?targetPage=whatView').submit();    
}

function step3()
{
    $('#step_access').val('extrasView');
    $('#quick_access').attr('action', 'https://www.hertz.ru/fees_and_order/?targetPage=extrasView').submit();    
}

function change_extras()
{
    $('#step').val('bookableQuoteView');
    $('#dataForm').submit();
}

function change_bookableQuoteView()
{
    //$('#step').val('bookableQuoteView');
    $('#dataForm').submit();
}

function change_car(id)
{
    $('#step').val('extrasView');
    $('#mark').val(id);
    $('#dataForm').submit();
}

function changeExtras_input(id, obj)
{
    if(obj.value != '')
    {
        $('#dev'+id).addClass('hertz_ext_selected');
        $('#dev-'+id).attr('checked','checked');
    }else
    {
        $('#dev'+id).removeClass('hertz_ext_selected');
        if($('#quantity'+id).html() != 'null')
        {
            $('#quantity'+id).val('');
        }
        $('#dev-'+id).removeAttr('checked');
    }
}

function changeExtras(id)
{
    if ($('#dev'+id).attr('class') == 'hertz_ext_one hertz_ext_selected') 
    {
        $('#dev'+id).removeClass('hertz_ext_selected');
        $('#quantity'+id).val('');
        $('#dev-'+id).removeAttr('checked');
    } 
    else 
    {
        $('#dev'+id).addClass('hertz_ext_selected');
        $('#quantity'+id).val('1');
        $('#dev-'+id).attr('checked','checked');
    }
}

function open_img(id)
{
    window.open('http://www.hertz.ru/templates/rus/booking/add_services.php?id='+id,'','width=500,height=400,status=no');
}

function valid_data_user()
{
	document.documentElement.style.cursor='wait';
    f = $("#dataForm :text, #dataForm :radio:checked, #dataForm select, #dataForm :hidden, #dataForm :checkbox:checked");
    $.post('error_booking.php', f, error_req);
}

function tab_cleare()
{
	$('#tabs td').removeClass('active').addClass('unactive');
	$('#tabs td').eq(0).removeClass('unactive').addClass('active');
}

function tabs_change(obj, link)
{
	$('#tabs td').removeClass('active').addClass('unactive');
	$(obj).removeClass('unactive').addClass('active');
	tab_load(link);	
}

function tab_load(link)
{
	$('#tab_content').html('<div id="loading"><img src="i/yellow_squares.gif" width="93" height="14"></div>');
	$('#tab_content').load(link);
}

function open_page(id, type, link)
{
	h = document.documentElement.scrollHeight;
	w = document.documentElement.clientWidth;
	h1 = document.documentElement.clientHeight;
	p = document.documentElement.scrollTop;
	y =Math.round((h1-286)/2)+p;
	
	$('#bg_gallery').css({height:h, width:w});
	if($('#img_gallery').html() == null)
	{
		$('#bg_gallery').after('<div id="img_gallery"><div id="car_loading"></div></div>');
		$('#img_gallery').css('top', y);
	}		
	$('#bg_gallery').show();
	$('#car_loading').show();
	navig(id, type, link);
}

function navig(id, type, link)
{
	$('#car_loading').css('background-color', '#FFF');
	$("#car_box").remove();
	$.post(link, {'id':id, 'type':type}, req);
}
function req(data)
{
	if(data != '')
	{
		h1 = parseInt($('#car_loading').css('height'))
		$('#car_loading').html(data);
		h = parseInt($('#car_box').css('height'));
		
		if(h1 == h )
		{
			show_car();
		}else if(h1 < h)
		{
			resize_max(h1, h);
		}else
		{ 
			resize_min(h1, h);
		}
	}else
	{
		windows.location.href="https://www.hertz.ru/?targetPage=reservationOnHomepage";
	}	
}


var i=0;
var t;
function resize_max(h, h1)
{
//alert(h);
	if(h < h1)
	{
		h = parseInt(h)+1;
		$('#car_loading').css('height', h);
		t =	setTimeout("resize_max("+h+", "+h1+")", 1);
	}else
	{
		show_car()
		clearTimeout(t);
	}	
}

function resize_min(h, h1)
{
//alert(h);
	if(h > h1)
	{
		h = parseInt(h)-1;
		$('#car_loading').css('height', h);
		t =	setTimeout("resize_min("+h+", "+h1+")", 1);
	}else
	{
		show_car()
		clearTimeout(t);
	}	
}


function show_car()
{
	$('#car_loading').css('background-color', '#FFD60D');
	$("#car_box").css("opacity",'1');
}

function close_gallery()
{
	$('#img_gallery').remove();
	$('#bg_gallery').hide();
	return false;
}