$(document).ready(function() {
	$("a.foto_good").fancybox({
		'zoomSpeedIn': 300,
		'zoomSpeedOut': 150,
		"overlayOpacity" : 0.3,
		"zoomSpeedChange" : 170,
		"zoomOpacity" : true
	});
});




function trimLeft(str) {
  return str.replace(/^\s+/, '');
}

function trimRight(str) {
  return str.replace(/\s+$/, '');
}

function trimBoth(str) {
  return trimRight(trimLeft(str));
}

function checkLeasingForm() {
	f = document.forms['leasing_form'];

	city_value = trimBoth(f.elements['city'].value);
	company_value = trimBoth(f.elements['company'].value);
	contacts_value = trimBoth(f.elements['contacts'].value);
	phone_value = trimBoth(f.elements['phone'].value);
	email_value = trimBoth(f.elements['email'].value);
	
	f.elements['city'].value = city_value;
	f.elements['company'].value = company_value;
	f.elements['contacts'].value = contacts_value;
	f.elements['phone'].value = phone_value;
	f.elements['email'].value = email_value;
	
	var norm_color = '1px #a5acb2 solid';
	var alert_color = '1px #AC0000 solid';
	
	if(city_value == "")	f.elements['city'].style.border = alert_color;
	else					f.elements['city'].style.border = norm_color;
	
	if(company_value == "")	f.elements['company'].style.border = alert_color;
	else					f.elements['company'].style.border = norm_color;
	
	if(contacts_value == "")	f.elements['contacts'].style.border = alert_color;
	else						f.elements['contacts'].style.border = norm_color;
	
	if(phone_value == "")	f.elements['phone'].style.border = alert_color;
	else					f.elements['phone'].style.border = norm_color;
	
	if(email_value == "")	f.elements['email'].style.border = alert_color;
	else					f.elements['email'].style.border = norm_color;
	
	if(city_value != "" && company_value != "" && contacts_value != "" && phone_value != "" && email_value != "") {
		f.submit();
	} else {
		alert('Поля, отмеченные звёздочкой *, обязательны для заполнения.');
		return false;
	}
	
}

function addLeasingForm() {
	var html = '<form action="/action.php3" method="POST" name="leasing_form" class="leasing_form">' +
					'<table>' +
					'<tr>' +
						'<td><input type="text" name="forbot" style="position:absolute; left:-999px;"/>Ваш город<sup>*</sup></td>' +
						'<td><input type="text" name="city" class="def_textinput"/></td>' +
					'</tr>' +
					'<tr>' +
						'<td>Наименование</td>' +
						'<td><input type="text" name="carname" class="def_textinput"/></td>' +
					'</tr>' +
					'<tr>' +
						'<td>Марка (модель)</td>' +
						'<td><input type="text" name="model" class="def_textinput"/></td>' +
					'</tr>' +
					'<tr>' +
						'<td>Стоимость, руб.</td>' +
						'<td><input type="text" name="price_leasing" class="def_textinput"/></td>' +
					'</tr>' +
					'<tr>' +
						'<td>Аванс (от 0% до 50%)</td>' +
						'<td><select name="avansov_price"><option value="0%">0%</option><option value="10%">10%</option><option value="20%">20%</option><option value="30%">30%</option><option value="40%">40%</option><option value="50%">50%</option></select></td>' +
					'</tr>' +
					'<tr>' +
						'<td>Срок лизинга (мес.)</td>' +
						'<td><input type="text" name="term_leasing" class="def_textinput"/></td>' +
					'</tr>' +
					'<tr>' +
						'<td>Ежемесячные платежи</td>' +
						'<td><select name="month_payment"><option value="равными долями">равными долями</option><option value="убывающими частями">убывающими частями</option></select></td>' +
					'</tr>' +					
					'<tr>' +
						'<td>Форма собственности предприятия</td>' +
						'<td><input type="text" name="company_type" class="def_textinput"/></td>' +
					'</tr>' +
					
					
					'<tr>' +
						'<td style="padding-top:40px"><strong>Как с вами связаться</strong></td>' +
						'<td></td>' +
					'</tr>' +

					'<tr>' +
						'<td>Название компании<sup>*</sup></td>' +
						'<td><input type="text" name="company" class="def_textinput"/></td>' +
					'</tr>' +
					'<tr>' +
						'<td>Фамилия, имя, отчество<sup>*</sup></td>' +
						'<td><input type="text" name="contacts" class="def_textinput"/></td>' +
					'</tr>' +
					'<tr>' +
						'<td>Телефон<sup>*</sup></td>' +
						'<td><input type="text" name="phone" class="def_textinput"/></td>' +
					'</tr>' +
					'<tr>' +
						'<td>E-mail<sup>*</sup></td>' +
						'<td><input type="text" name="email" class="def_textinput"/></td>' +
					'</tr>' +

					'<tr>' +
						'<td><input type="hidden" name="action" value="leasing_order"/></td>' +
						'<td><input type="button" onclick="checkLeasingForm();" value="Отправить"/></td>' +
					'</tr>' +
					'</table>' +
				'</form>';
				
		var obj = document.getElementById('leasingForm_container');
		obj.innerHTML = html;
}



function toggle_obj(Obj_id){
	
	var Obj = document.getElementById(Obj_id);
	var display = Obj.style.display;
	if (display == 'none' || !display)
		Obj.style.display = 'block';
	else
		Obj.style.display = 'none';
}

function pagenum(p, filename){
    document.forms["nav"].elements["page"].value = p;
    document.forms["nav"].elements["filename"].value = filename;
    document.forms["nav"].submit();
}

function my_confirm(to, what){
	if (confirm(what))
		document.location=to;
}
				
var foto_windows = new Array();
function open_foto(url, winname, width, height){
	foto_windows[foto_windows.length] = window.open(url,winname,'height='+height+',width='+width+',resizable=0,scrollbars=no,menubar=no,status=no');
	for(i = 0; foto_windows.length > i; i++){
		if(!foto_windows[i].closed)
			foto_windows[i].focus();
	}
}

function do_search(text){
	var search_line = document.getElementById('sline');
	search_line.value = text;
	document.forms['web'].submit();
}

function newWindow(url,w,h){
w = w + 18;
h = h + 27;
Win = window.open(url, "Win", "width=" + w + ",height=" + h + "location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=0","top=0,left=0");}

function tableLinesOn(pos)
{
	if (!document.getElementById) return;
	var id1 = document.getElementById('id1' + pos );
	var id2 = document.getElementById('id2' + pos );
	var id3 = document.getElementById('id3' + pos );
	if(id1.className == 'number')
		id1.className = 'numberOn';
	if(id2.className == 'name')
		id2.className = 'nameOn';
	if(id3.className == 'price')
		id3.className = 'priceOn';
	}

function tableLinesOff(pos)
{
	if (!document.getElementById) return;
	var id1 = document.getElementById('id1' + pos );
	var id2 = document.getElementById('id2' + pos );
	var id3 = document.getElementById('id3' + pos );
	if(id1.className == 'numberOn')
		id1.className = 'number';
	if(id2.className == 'nameOn')
		id2.className = 'name';
	if(id3.className == 'priceOn')
		id3.className = 'price';
	
	}

function tableClick(host, mode, pos)
{
	alert("aa1");
	alert(host + mode + pos);
	}