var client_element_height = 71;
var client_scroll_step = 4;
var client_scroll_timeout = 10;
var client_max_position = -1;
var client_position = 0;
var new_client_position = 0;
var client_is_scrolling = false;

function UpdateClientScrollButtons() {
	var client = document.getElementById('clientsContainer');
	if (client && (client_max_position < 0)) {
	    client_max_position = client.getElementsByTagName('A').length;
	} // end if
	var top_link = document.getElementById('client_lister_top');
	var bottom_link = document.getElementById('client_lister_bottom');
	if ((top_link) && (bottom_link)) {
		top_link.className = (client_position > 0) ? 'active' : '';
		bottom_link.className = (client_position < (client_max_position - 4) * client_element_height) ? 'active' : '';
	} // end if
} // end if

function ClientScrollTimer() {
	var client = document.getElementById('clientsContainer');
	if (client && client_is_scrolling) {
		if (new_client_position > client_position) {
			client_position += client_scroll_step;
			if (client_position > new_client_position) client_position = new_client_position;
		} else if (new_client_position < client_position) {
			client_position -= client_scroll_step;
			if (client_position < new_client_position) client_position = new_client_position;
		} // end if
		client.style.top = -client_position + 'px';
		UpdateClientScrollButtons();
		if (new_client_position != client_position) setTimeout(ClientScrollTimer, client_scroll_timeout)
		else client_is_scrolling = false;
	} // end if
} // end function

function ClientScroll(increment) {
	var client = document.getElementById('clientsContainer');
	if (client) {
		new_client_position += increment * client_element_height * 4;
		if (new_client_position > (client_max_position - 4) * client_element_height) {
			new_client_position = (client_max_position - 4) * client_element_height;
		} // end if
		if (new_client_position < 0) new_client_position = 0;
		if (new_client_position != client_position) setTimeout(ClientScrollTimer, client_scroll_timeout);
		client.style.top = -client_position + 'px';
		UpdateClientScrollButtons();
	} // end if
	return false;
} // end function

function ClientUpClick() {
    client_is_scrolling = true;
    return ClientScroll(-1);
}

function ClientDownClick() {
    client_is_scrolling = true;
    return ClientScroll(1);
}

function ClientLogoClick(id) {
	var div = document.getElementById('aboutCustomer');
	var list = document.getElementById('clientsContainer');
	var link = document.getElementById('cci' + id);
	client_is_scrolling = false;
	if ((div) && (link) && (list) && (link.className != 'current')) {
		var event = 
			function (result) {
				div.innerHTML = result;
				var items = list.getElementsByTagName('A');
				for (var i=0; i<items.length; i++) items[i].className = '';
				link.className = 'current';
			} // end event
		HttpRequest(site_path + 'AJAX/GetClientInfo.aspx?ClientID=' + id, null, 'client', event);
	} // end if
	return false;
} // end function

function ShowCompleteClientInfo(id) {
	var list = document.getElementById('ourClientsContainer');
	var block = document.getElementById('ourClientsPeojectsContainer');
	var ul = document.getElementById('commentsList');
	var services = document.getElementById('companyServicesContainer');
	var service_order = document.getElementById('twoColsContainer');
	if (block) {
		var event = 
			function (result) {
				var root = XmlRootByText(result);
				var about = GetXmlNodeValue(GetXmlNodeByTagName(root, 'about'));
				var comments = GetXmlNodeValue(GetXmlNodeByTagName(root, 'comments'));
				block.innerHTML = about;
				if (list) list.style.display = 'none';
				if (ul) ul.innerHTML = comments;
				if (services) services.style.display = 'none';
				if (service_order) service_order.style.display = 'none';
				block.style.display = 'block';
			} // end event
		HttpRequest(site_path + 'get_full_client_info.php?city_id=' + current_city_id + '&id=' + id, null, 'clientsprojects', event);
	} // end if
	return false;
} // end function

function ShowCompleteProjectInfo(id) {
	var list = document.getElementById('ourProjectsListContainer');
	var list2 = document.getElementById('ourClientsContainer');
	var block = document.getElementById('ourClientsPeojectsContainer');
	var ul = document.getElementById('commentsList');
	var services = document.getElementById('companyServicesContainer');
	var service_order = document.getElementById('twoColsContainer');
	if (block) {
		var event = 
			function (result) {
				var root = XmlRootByText(result);
				var about = GetXmlNodeValue(GetXmlNodeByTagName(root, 'about'));
				var comments = GetXmlNodeValue(GetXmlNodeByTagName(root, 'comments'));
				block.innerHTML = about;
				if (list) list.style.display = 'none';
				if (list2) list2.style.display = 'none';
				if (ul) ul.innerHTML = comments;
				if (services) services.style.display = 'none';
				if (service_order) service_order.style.display = 'none';
				block.style.display = 'block';
			} // end event
		HttpRequest(site_path + 'get_full_project_info.php?id=' + id, null, 'clientsprojects', event);
		return false;
	} // end if
	return true;
} // end function

function ShowCompleteComment(id) {
	var list = document.getElementById('ourProjectsListContainer');
	var list2 = document.getElementById('ourClientsContainer');
	var block = document.getElementById('ourClientsPeojectsContainer');
	var addNavMenu = document.getElementById('commentsMenu');
	var services = document.getElementById('companyServicesContainer');
	var service_order = document.getElementById('twoColsContainer');
	if (block) {
		var event = 
			function (result) {
				block.innerHTML = result;
				if (list) list.style.display = 'none';
				if (list2) list2.style.display = 'none';
				if (addNavMenu) addNavMenu.style.display = 'block';
				if (services) services.style.display = 'none';
				if (service_order) service_order.style.display = 'none';
				block.style.display = 'block';
			} // end event
		HttpRequest(site_path + 'get_full_comment.php?id=' + id, null, 'clientsprojects', event);
	} // end if
	return false;
} // end function

function OpenAndCloseVcItems(tid, id) {
	var heading = document.getElementById('vilflh' + tid + '_' + id);
	var body = document.getElementById('vilf' + tid + '_' + id);
	if (body.style.display == 'none') {
		body.style.display = 'block';
		heading.className = 'open';
	} else {
		body.style.display = 'none';
		heading.className = '';
	} // end if
	return false;
} // end function

function OpenAndCloseMainVcItems(tid, id) {
	var heading = document.getElementById('vilflh' + tid + '_' + id);
	var body = document.getElementById('vilf' + tid + '_' + id);
	if (body.style.display == 'none') {
		body.style.display = 'block';
		heading.className = 'openmain';
	} else {
		body.style.display = 'none';
		heading.className = '';
	} // end if
	return false;
} // end function

function AdditionalClientInfoClick(id) {
	var div = document.getElementById('aboutOurClient');
	var link = document.getElementById('aboutOurClientMore');
	if (div) {
		if (div.style.display == 'none') {
			if (div.innerHTML.length > 0) {
				div.style.display = 'block';
				if (link) link.className = 'open';
			} else {
				var event = 
					function (result) {
						div.innerHTML = result;
						div.style.display = 'block';
						if (link) link.className = 'open';
					} // end event
				HttpRequest(site_path + 'get_add_client_info.php?city_id=' + current_city_id + '&id=' + id, null, 'clientsprojects', event);
			} // end if
		} else {
			div.style.display = 'none';
			if (link) link.className = '';
		} // end if
	} // end if
	return false;
} // end function

