function doMessages() {
	var msgContainer = document.getElementById("messagebox");
	
	if (msgContainer.innerHTML.length > 0)
	{
		msgContainer.style.display = '';
		self.scrollTo(0,0);
	}
}

/**
 * Add function to page load
 * @param func - function to add
 */
function addLoadEvent(func)
{
	var oldonload = window.onload;
	if (typeof window.onload != "function")
	{
		window.onload = func;
	}
	else
	{
		window.onload = function()
		{
			oldonload();
			func();
		}
	}
}

/**
 * Perform quick search
 */
function doQuickSearch(search_region, id_prefix, search_mycompany)
{
	var searchOrigin = 1; // left menu search
	if (id_prefix == 'ucMainLayout_ucContentSection_contentControl_') searchOrigin = 2; // detailed search

	var company_id = $('#' + id_prefix + 'selSeller').val();
	var owner_id = $('#' + id_prefix + 'selDealer').val();

	var category_id = $('#' + id_prefix + 'selCategory').val();
	var body_id = $('#' + id_prefix + 'selBody').val();
	var type_id = $('#' + id_prefix + 'selType').val();

	var textstr = $('#' + id_prefix + 'txtString').val();
	
	var make = $('#' + id_prefix + 'txtMake').val();
	var make_id = $('#' + id_prefix + 'selMake').val();
	var model = $('#' + id_prefix + 'txtModel').val();
	var model_id = $('#' + id_prefix + 'selModel').val();

	var year_from = $('#' + id_prefix + 'selYearFrom').val();
	var year_to = $('#' + id_prefix + 'selYearTo').val();

	var engine_type = $('#' + id_prefix + 'selEngineType').val();
	var starter_type = $('#' + id_prefix + 'selStarterType').val();
	var engine_cooling = $('#' + id_prefix + 'selEngineCooling').val();
	var power_transmission = $('#' + id_prefix + 'selPowerTransmission').val();

	var length_total = $('#' + id_prefix + 'selLengthTotal').val();

	var engine_from = $('#' + id_prefix + 'selEngineSizeFrom').val();
	if (engine_from == undefined) engine_from = $('#' + id_prefix + 'txtEngineSizeFrom').val();
	var engine_to = $('#' + id_prefix + 'selEngineSizeTo').val();
	if (engine_to == undefined) engine_to = $('#' + id_prefix + 'txtEngineSizeTo').val();
	
	

	var power_from = $('#' + id_prefix + 'txtPowerFrom').val();
	var power_to = $('#' + id_prefix + 'txtPowerTo').val();
	
	var mileage_to = $('#' + id_prefix + 'selMileage').val();
	
	var price_from = $('#' + id_prefix + 'txtPriceFrom').val();
	var price_to = $('#' + id_prefix + 'txtPriceLimit').val();
	if (price_to == undefined) price_to = $('#' + id_prefix + 'txtPriceTo').val();
	
	var vin = $('#' + id_prefix + 'txtVinCode').val();
	var regkey = $('#' + id_prefix + 'txtRegKey').val();
	
	var fuel_type = $('#' + id_prefix + 'selFuelType').val();
	var transmission = $('#' + id_prefix + 'selTransmission').val();
	var drive_type = $('#' + id_prefix + 'selDriveType').val();
	var color_id = $('#' + id_prefix + 'selColor').val();
	
	var climate_control = $('#' + id_prefix + 'selClimateControl').val();
	var warranty = $('#' + id_prefix + 'selWarranty').val();

	var location_status = $('#' + id_prefix + 'selLocationStatus').val();
	var invalid_posts = $('#' + id_prefix + 'selInvalidPosts').val();
	var display_unpublished = $('#' + id_prefix + 'chkDisplayUnpublished');
	var has_images = $('#' + id_prefix + 'selHasImages').val();

	var region_1 =  $('#' + id_prefix + 'selRegion1').val();
	var region_2 =  $('#' + id_prefix + 'selRegion2').val();
	var region_3 =  $('#' + id_prefix + 'selRegion3').val();
	
	var chkHasVideo = document.getElementById(id_prefix + 'chkHasVideo');
	
	var chkEstonian = document.getElementById(id_prefix + 'chkEstonianVehicles');
	var chkLatvian = document.getElementById(id_prefix + 'chkLatvianVehicles');
	var chkLithuanian = document.getElementById(id_prefix + 'chkLithuanianVehicles');
	
	var radLocal = document.getElementById(id_prefix + 'radLocalVehicles');
	var radAll = document.getElementById(id_prefix + 'radAllVehicles');

	// create url string
	url = _root + "Default.aspx?page=list&reset=1&pg=0&sort=paid";
	
	// search origin
	url += "&sf=" + searchOrigin;
	
	// If seeking invalid ads, we don't want virtuals (virtuals are considered invalid under different criteria - they always have no color set)
	if ((invalid_posts == undefined) || (invalid_posts != '2'))
		url += "&virtual=1";
	
	if ((company_id != undefined) && (company_id != '-1')) url += "&company_id=" + company_id;
	if ((owner_id != undefined) && (owner_id != '-1')) url += "&owner_id=" + owner_id;

	if ((type_id != undefined) && (type_id != '-1'))
	{
		if (type_id.charAt(0) == 'c')
		{
			url += "&category_id=" + type_id.substr(2);
		}
		else if (type_id.charAt(0) == 'b')
		{
			url += "&body_id=" + type_id.substr(2);
		}
	}
	else
	{
		if ((category_id != undefined) && (category_id != '-1')) url += "&category_id=" + category_id;
		if ((body_id != undefined) && (body_id != '-1')) url += "&body_id=" + body_id;
	}

	if ((textstr != undefined) && (textstr != '')) url += "&string=" + escape(textstr);
	
	if ((make != undefined) && (make != '')) url += "&make=" + escape(make);
	if ((make_id != undefined) && (make_id != '') && (make_id != '-1')) url += "&make_id=" + make_id;
	if ((model != undefined) && (model != '')) url += "&model=" + escape(model);
	if ((model_id != undefined) && (model_id != '-1')) url += "&model_id=" + model_id;

	if ((year_from != undefined) && (year_from != '-1')) url += "&year_from=" + year_from;
	if ((year_to != undefined) && ((year_to != '-1')) && (year_to != '2010')) url += "&year_to=" + year_to;

	if ((engine_from != undefined) && (engine_from != '-1') && (engine_from != '')) url += "&engine_from=" + engine_from;
	if ((engine_to != undefined) && ((engine_to != '-1') && (engine_to != '1000') && (engine_from != ''))) url += "&engine_to=" + engine_to;

	if ((engine_type != undefined) && (engine_type != '-1')) url += "&engine_type=" + engine_type;
	if ((starter_type != undefined) && (starter_type != '-1')) url += "&starter_type=" + starter_type;
	if ((engine_cooling != undefined) && (engine_cooling != '-1')) url += "&engine_cooling=" + engine_cooling;
	if ((power_transmission != undefined) && (power_transmission != '-1')) url += "&power_transmission=" + power_transmission;

	if ((length_total != undefined) && (length_total != '-1')) url += "&length_total=" + length_total;

	if ((power_from != undefined) && (power_from != '')) url += "&power_from=" + power_from;
	if ((power_to != undefined) && (power_to != '')) url += "&power_to=" + power_to;
	
	if ((vin != undefined) && (vin != '')) url += "&vin=" + vin;
	if ((regkey != undefined) && (regkey != '')) url += "&regkey=" + regkey;

	if ((mileage_to != undefined) && (mileage_to != '-1')) url += "&mileage_to=" + mileage_to;
	if ((price_from != undefined) && (price_from != '')) url += "&price_from=" + price_from;
	if ((price_to != undefined) && (price_to != '')) url += "&price_to=" + price_to;
	if ((fuel_type != undefined) && (fuel_type != '-1')) url += "&fuel_type=" + fuel_type;
	if ((transmission != undefined) && (transmission != '-1')) url += "&transmission=" + transmission;
	if ((drive_type != undefined) && (drive_type != '-1')) url += "&drive_type=" + drive_type;
	if ((color_id != undefined) && (color_id != '-1')) url += "&color_id=" + color_id;

	if ((climate_control != undefined) && (climate_control != '-1')) url += "&climate_control=" + climate_control;
	if ((warranty != undefined) && (warranty != '-1')) url += "&warranty=" + warranty;

	if ((location_status != undefined) && (location_status != '-1')) url += "&location_status=" + location_status;
	if ((invalid_posts != undefined) && (invalid_posts != '-1')) url += "&invalid_posts=" + invalid_posts;
	if ((has_images != undefined) && (has_images != '-1')) url += "&has_images=" + has_images;
	if (display_unpublished.attr('checked')) url += "&unpublished=1";
	
	if ((chkHasVideo != null) && (chkHasVideo.checked)) url += "&has_video=1";
	
	if ((region_1 != undefined) && (region_1 != '-1')) url += "&region_1=" + region_1;
	if ((region_2 != undefined) && (region_2 != '-1')) url += "&region_2=" + region_2;
	if ((region_3 != undefined) && (region_3 != '-1')) url += "&region_3=" + region_3;
	
	if ((radLocal != null) && (radLocal.checked)) url += "&search_region=" + search_region;
	else if ((radAll != null) && (radAll.checked)) url += "&search_region=1&search_region=2&search_region=3";
	else
	{
		if ((chkEstonian != null) && (chkEstonian.checked)) url += "&search_region=1";
		if ((chkLatvian != null) && (chkLatvian.checked)) url += "&search_region=2";
		if ((chkLithuanian != null) && (chkLithuanian.checked)) url += "&search_region=3";
	}
	
	if (search_mycompany != null)
	{
		url += "&search_myvehicles=" + escape(search_mycompany);
	}
	
	location.href = url;
}

/**
 * Change listing page we are on
 * @param sel		- selPage dropdown
 * @param url		- url without page parameter
 */
function selPageChange(sel, url)
{
	location.href = url + '&pg=' + sel.options[sel.options.selectedIndex].value;
}

/**
 * Statistics time period dropdown changed
 * @param sel	- time period dropdown
 */
function chStatsPeriod(sel)
{
	if (sel.options.selectedIndex == 0) return;
	
	var _times = sel.options[sel.options.selectedIndex].value.split(';');
	
	document.getElementById('ucMainLayout_ucContentSection_contentControl_txtStartDate').value = _times[0];
	document.getElementById('ucMainLayout_ucContentSection_contentControl_txtEndDate').value = _times[1];
}

/**
 * Article category dropdown changed
 * @param sel	- category dropdown
 */
function chArticleCategory(sel)
{
	if (sel.options.selectedIndex == 0) return;
	
	location.href = 'Default.aspx?page=articlecategory&category_id=' + sel.options[sel.options.selectedIndex].value;
}

/**
 * Change language of comment field
 * @param lang - language to switch to
 */
function chCommentsLang(lang)
{
	switch (lang)
	{
		case "ENG":
			$('#lngTabENG').addClass('selected');
			$('#lngTabEST').removeClass('selected');
			$('#lngTabLAT').removeClass('selected');
			$('#lngTabLIT').removeClass('selected');
			$('#lngTabRUS').removeClass('selected');
			$('#lngTabFIN').removeClass('selected');
			$('#lngTabDescription').text('In english');
			$('#ucMainLayout_ucContentSection_contentControl_txtNotesen').removeClass('hidden');
			$('#ucMainLayout_ucContentSection_contentControl_txtNotesee').addClass('hidden');
			$('#ucMainLayout_ucContentSection_contentControl_txtNoteslv').addClass('hidden');
			$('#ucMainLayout_ucContentSection_contentControl_txtNoteslt').addClass('hidden');
			$('#ucMainLayout_ucContentSection_contentControl_txtNotesru').addClass('hidden');
			$('#ucMainLayout_ucContentSection_contentControl_txtNotesfi').addClass('hidden');
			break;

		case "EST":
			$('#lngTabENG').removeClass('selected');
			$('#lngTabEST').addClass('selected');
			$('#lngTabLAT').removeClass('selected');
			$('#lngTabLIT').removeClass('selected');
			$('#lngTabRUS').removeClass('selected');
			$('#lngTabFIN').removeClass('selected');
			$('#lngTabDescription').text('Eesti keeles');
			$('#ucMainLayout_ucContentSection_contentControl_txtNotesen').addClass('hidden');
			$('#ucMainLayout_ucContentSection_contentControl_txtNotesee').removeClass('hidden');
			$('#ucMainLayout_ucContentSection_contentControl_txtNoteslv').addClass('hidden');
			$('#ucMainLayout_ucContentSection_contentControl_txtNoteslt').addClass('hidden');
			$('#ucMainLayout_ucContentSection_contentControl_txtNotesru').addClass('hidden');
			$('#ucMainLayout_ucContentSection_contentControl_txtNotesfi').addClass('hidden');
			break;

		case "LAT":
			$('#lngTabENG').removeClass('selected');
			$('#lngTabEST').removeClass('selected');
			$('#lngTabLAT').addClass('selected');
			$('#lngTabLIT').removeClass('selected');
			$('#lngTabRUS').removeClass('selected');
			$('#lngTabFIN').removeClass('selected');
			$('#lngTabDescription').text('Latviski');
			$('#ucMainLayout_ucContentSection_contentControl_txtNotesen').addClass('hidden');
			$('#ucMainLayout_ucContentSection_contentControl_txtNotesee').addClass('hidden');
			$('#ucMainLayout_ucContentSection_contentControl_txtNoteslv').removeClass('hidden');
			$('#ucMainLayout_ucContentSection_contentControl_txtNoteslt').addClass('hidden');
			$('#ucMainLayout_ucContentSection_contentControl_txtNotesru').addClass('hidden');
			$('#ucMainLayout_ucContentSection_contentControl_txtNotesfi').addClass('hidden');
			break;

		case "LIT":
			$('#lngTabENG').removeClass('selected');
			$('#lngTabEST').removeClass('selected');
			$('#lngTabLAT').removeClass('selected');
			$('#lngTabLIT').addClass('selected');
			$('#lngTabRUS').removeClass('selected');
			$('#lngTabFIN').removeClass('selected');
			$('#lngTabDescription').text('Lietuviškai');
			$('#ucMainLayout_ucContentSection_contentControl_txtNotesen').addClass('hidden');
			$('#ucMainLayout_ucContentSection_contentControl_txtNotesee').addClass('hidden');
			$('#ucMainLayout_ucContentSection_contentControl_txtNoteslv').addClass('hidden');
			$('#ucMainLayout_ucContentSection_contentControl_txtNoteslt').removeClass('hidden');
			$('#ucMainLayout_ucContentSection_contentControl_txtNotesru').addClass('hidden');
			$('#ucMainLayout_ucContentSection_contentControl_txtNotesfi').addClass('hidden');
			break;

		case "RUS":
			$('#lngTabENG').removeClass('selected');
			$('#lngTabEST').removeClass('selected');
			$('#lngTabLAT').removeClass('selected');
			$('#lngTabLIT').removeClass('selected');
			$('#lngTabRUS').addClass('selected');
			$('#lngTabFIN').removeClass('selected');
			$('#lngTabDescription').text('??-??????');
			$('#ucMainLayout_ucContentSection_contentControl_txtNotesen').addClass('hidden');
			$('#ucMainLayout_ucContentSection_contentControl_txtNotesee').addClass('hidden');
			$('#ucMainLayout_ucContentSection_contentControl_txtNoteslv').addClass('hidden');
			$('#ucMainLayout_ucContentSection_contentControl_txtNoteslt').addClass('hidden');
			$('#ucMainLayout_ucContentSection_contentControl_txtNotesru').removeClass('hidden');
			$('#ucMainLayout_ucContentSection_contentControl_txtNotesfi').addClass('hidden');
			break;

		case "FIN":
			$('#lngTabENG').removeClass('selected');
			$('#lngTabEST').removeClass('selected');
			$('#lngTabLAT').removeClass('selected');
			$('#lngTabLIT').removeClass('selected');
			$('#lngTabRUS').removeClass('selected');
			$('#lngTabFIN').addClass('selected');
			$('#lngTabDescription').text('Suomeksi');
			$('#ucMainLayout_ucContentSection_contentControl_txtNotesen').addClass('hidden');
			$('#ucMainLayout_ucContentSection_contentControl_txtNotesee').addClass('hidden');
			$('#ucMainLayout_ucContentSection_contentControl_txtNoteslv').addClass('hidden');
			$('#ucMainLayout_ucContentSection_contentControl_txtNoteslt').addClass('hidden');
			$('#ucMainLayout_ucContentSection_contentControl_txtNotesru').addClass('hidden');
			$('#ucMainLayout_ucContentSection_contentControl_txtNotesfi').removeClass('hidden');
			break;
	}
}

/**
 * Perform assisted search
 */
function doAssistedSearch(url)
{
	var q = "&sort=paid&pg=0&reset=1&virtual=1&sf=3";
	
	if (document.getElementById('chkBody1').checked) q += "&body_id=1";
	if (document.getElementById('chkBody2').checked) q += "&body_id=2";
	if (document.getElementById('chkBody4').checked) q += "&body_id=4";
	if (document.getElementById('chkBody7').checked) q += "&body_id=7";
	if (document.getElementById('chkBody3').checked) q += "&body_id=3";
	if (document.getElementById('chkBody11').checked) q += "&body_id=11";
	if (document.getElementById('chkBody5').checked) q += "&body_id=5";
	if (document.getElementById('chkBody8').checked) q += "&body_id=8";
	
	if (s != null)
		q += "&age=" + (s.getRealValue() + 1);
	else
		q += "&age=4";
	
	if ((s2 != null) && ((s2.getRealValue() + 1) != 1))
		q += "&equipment=" + (s2.getRealValue() + 1);

	if (document.getElementById('radPriceType1').checked)
	{
		if ($('#selLeasePriceFrom').val() > 0)
			q += "&price_from=" + $('#selLeasePriceFrom').val();
		if ($('#selLeasePriceTo').val() > 0)
			q += "&price_to=" + $('#selLeasePriceTo').val();
	}
	else
	{
		if ($('#selPriceFrom').val() > 0)
			q += "&price_from=" + $('#selPriceFrom').val();
		q += "&price_to=" + $('#selPriceTo').val();
	}
	
	if ((s3 != null) && ((s3.getRealValue() + 1) != 1))
		q += "&power=" + (s3.getRealValue() + 1);
	
	window.location.href = url + q;
}

function toggleAssistedSearch(show)
{
	if (show)
	{
		$('#assistedsearchNotice').hide('fast');
		$('.assistedsearchContainer').show('fast');
		$('#asExpandButton').hide();
		$('#asCollapseButton').show();
	}
	else
	{
		$('.assistedsearchContainer').hide('fast');
		$('#assistedsearchNotice').show('fast');
		$('#asCollapseButton').hide();
		$('#asExpandButton').show();
	}
}

var asInitialized = new Array();
function setAssistedSearchTab(num)
{
	for (var i = 1; i <= 3; i++)
	{
		if (i == num)
		{
			$('#asStep' + i).show();
			$('#asTab' + i).addClass('selected');
		}
		else
		{
			$('#asStep' + i).hide();
			$('#asTab' + i).removeClass('selected');
		}
	}
	setInitialValue(num);
}
function setInitialValue(num)
{
	switch(num)
	{
		case 2: createSlider1(); break;
		case 3:
			createSlider2();
			createSlider3();
		break;
	}
	return;
}

function chAssistedSearchPriceType()
{
	var asPrice1 = document.getElementById('radPriceType1');
	var asPrice2 = document.getElementById('radPriceType2');
	
	if (asPrice1.checked)
	{
		$('#asPrice2').hide();
		$('#asPrice1').show();
		$('#asPrice1Disclaimer').show();
	}
	else
	{
		$('#asPrice1').hide();
		$('#asPrice1Disclaimer').hide();
		$('#asPrice2').show();
	}
}

/**
 * Set visibility of Warranty form table
 */
function chWarrantyVisibility(selWarranty)
{
	if (selWarranty.value != "0")
		$('#tblWarranty').show('fast');
	else
		$('#tblWarranty').hide('fast');
}

// Multiple pic upload
var curRow = 1;
var idPrefix = "rowPicUpload";
function extendPicUpload() {
	curRow++;
	$('#tblUploadPics' + (curRow)).show('fast');
	
	if (curRow == 5) $('#extendPicUpload').hide('fast');
}

/**
 * Fugly old boat elements visibility script.
 * TODO: stop making baby jesus cry with this crappy hacked code
 */
var controlPrefix = "ucMainLayout_ucContentSection_contentControl_ucGeneral_";

var boatCategory = new Array();
boatCategory[11] = new Array(); // Kaater
boatCategory[11][0] = "ucMainLayout_ucContentSection_contentControl_ucTechnical_txtMastHeight";
boatCategory[11][1] = "ucMainLayout_ucContentSection_contentControl_ucEquipment_chkEquipment_boat_sprayhood";

boatCategory[12] = new Array(); // Jaht
boatCategory[12][0] = "ucMainLayout_ucContentSection_contentControl_ucTechnical_txtDepth";
boatCategory[12][1] = "ucMainLayout_ucContentSection_contentControl_ucTechnical_txtClearance";
boatCategory[12][2] = "ucMainLayout_ucContentSection_contentControl_ucTechnical_txtEngineSize";
boatCategory[12][3] = "ucMainLayout_ucContentSection_contentControl_ucEquipment_chkEquipment_boat_trimmid";
boatCategory[12][4] = "ucMainLayout_ucContentSection_contentControl_ucEquipment_chkEquipment_boat_cover";
boatCategory[12][5] = "ucMainLayout_ucContentSection_contentControl_ucEquipment_chkEquipment_boat_ahtrivint";
boatCategory[12][6] = "ucMainLayout_ucContentSection_contentControl_ucEquipment_chkEquipment_boat_window_wipers";
boatCategory[12][7] = "ucMainLayout_ucContentSection_contentControl_ucEquipment_chkEquipment_boat_swim_platform";
boatCategory[12][8] = "ucMainLayout_ucContentSection_contentControl_ucEquipment_chkEquipment_boat_defroster";

boatCategory[13] = new Array(); // Paat
boatCategory[13][0] = "ucMainLayout_ucContentSection_contentControl_ucTechnical_txtLengthHull";
boatCategory[13][1] = "ucMainLayout_ucContentSection_contentControl_ucTechnical_txtLengthWater";
boatCategory[13][2] = "ucMainLayout_ucContentSection_contentControl_ucTechnical_txtLengthDepth";
boatCategory[13][3] = "ucMainLayout_ucContentSection_contentControl_ucTechnical_txtBeds";
boatCategory[13][4] = "ucMainLayout_ucContentSection_contentControl_ucTechnical_txtClearance";
boatCategory[13][5] = "ucMainLayout_ucContentSection_contentControl_ucTechnical_txtMastHeight";
boatCategory[13][6] = "ucMainLayout_ucContentSection_contentControl_ucTechnical_txtFuelTank";
boatCategory[13][7] = "ucMainLayout_ucContentSection_contentControl_ucTechnical_txtWaterTank";
boatCategory[13][8] = "ucMainLayout_ucContentSection_contentControl_ucEngine_selEngineCount";
boatCategory[13][9] = "ucMainLayout_ucContentSection_contentControl_ucEngine_txtEngineSize";

boatCategory[14] = new Array(); // Skuuter
boatCategory[14][0] = "ucMainLayout_ucContentSection_contentControl_ucTechnical_txtLengthHull";
boatCategory[14][1] = "ucMainLayout_ucContentSection_contentControl_ucTechnical_txtLengthWater";
boatCategory[14][2] = "ucMainLayout_ucContentSection_contentControl_ucTechnical_txtWidth";
boatCategory[14][3] = "ucMainLayout_ucContentSection_contentControl_ucTechnical_txtLengthDepth";
boatCategory[14][4] = "ucMainLayout_ucContentSection_contentControl_ucTechnical_txtLengthMax";
boatCategory[14][5] = "ucMainLayout_ucContentSection_contentControl_ucTechnical_selTypeCategory";
boatCategory[14][6] = "ucMainLayout_ucContentSection_contentControl_ucTechnical_txtBeds";
boatCategory[14][7] = "ucMainLayout_ucContentSection_contentControl_ucTechnical_txtClearance";
boatCategory[14][8] = "ucMainLayout_ucContentSection_contentControl_ucTechnical_txtMastHeight";
boatCategory[14][9] = "ucMainLayout_ucContentSection_contentControl_ucTechnical_txtFuelTank";
boatCategory[14][10] = "ucMainLayout_ucContentSection_contentControl_ucTechnical_txtWaterTank";
boatCategory[14][11] = "ucMainLayout_ucContentSection_contentControl_ucEngine_selEngineCount";
boatCategory[14][12] = "ucMainLayout_ucContentSection_contentControl_ucEngine_txtEngineMake";
boatCategory[14][13] = "ucMainLayout_ucContentSection_contentControl_ucEngine_txtEngineModel";
boatCategory[14][14] = "ucMainLayout_ucContentSection_contentControl_ucEngine_selFuelType";
boatCategory[14][15] = "ucMainLayout_ucContentSection_contentControl_ucEngine_txtWorkhours";

// Set input fields visibility by selected boat category
function setBoatCategoryVisibility() {
	var inputs = document.getElementById("content").getElementsByTagName("input");
	var selects = document.getElementById("content").getElementsByTagName("select");
	var categoryId = document.getElementById(controlPrefix + "selCategory").value;
	
	for (var i = 0; i < inputs.length; i++)
	{
		for (var j = 0; j < boatCategory[categoryId].length; j++)
		{
			if (inputs[i].id == (boatCategory[categoryId][j]))
			{
				inputs[i].disabled = "disabled";
				inputs[i].style.filter = "alpha(opacity=25)";
			}
		}
	}
	
	if ((categoryId == "13") || (categoryId == "14"))
	{
		document.getElementById("fsEq0").style.display = "none";
		document.getElementById("fsEq1").style.display = "none";
		document.getElementById("fsEq2").style.display = "none";
	}
}

// Toggle Bill View page contact table visibility
function toggleContactTableVisibility()
{
	var chk = document.getElementById("ucMainLayout_ucContentSection_contentControl_chkCompany");
		
	if ((chk != null) && (chk.checked)) $('#tblContact').show('fast');
	else $('#tblContact').hide('fast');
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
	window.open(theURL,winName,features);
}

function enterpressed(e) {
	if (window.event) {
		if (event.keyCode == 13)
			return true;
	}
	else if (e.which) {
		if (e.which == 13)
			return true;
	}
	
	return false;
}

function keyDown(e) {
	if (enterpressed(e)) {
		if (typeof(Page_ClientValidate) != 'function' ||  Page_ClientValidate())
			__doPostBack('ucMainLayout$ucLeftSection$ucUserSection$ucLoginSection$btnLogin','');
		
		return false;
	}
	return true;
}

function doKeyDown(e, button) {
  if (enterpressed(e)) {
    if ((typeof(Page_ClientValidate) != 'function') || (Page_ClientValidate()))
      __doPostBack(button, '');
  }
}

// anti-spam mailer
function emailTo(name, domain) {
	window.location = "mailto:" + name + "@" + domain;
}
function emailToParse(email) {
	emailElements = email.split("#");
	if (emailElements.length >= 2)
		window.location = "mailto:" + emailElements[0] + "@" + emailElements[1];
}

// Don't let user select more than two checkboxes
function chkClicked(chkBox) {
	var inputElements = document.getElementsByTagName("input");
	var checkedCount = 0;
	
	// Count number of selected checkboxes
	for (var i = 0; i < inputElements.length; i++) {
		if ((inputElements[i].type == "checkbox") && (inputElements[i].onclick == "function anonymous()\n{\nchkClicked(this);\n}") && (inputElements[i].checked == true))
			checkedCount++;
	}
	
	if (checkedCount > 2)
		chkBox.checked = false;
}

// Deselects all options in a listbox
function deSelectListBox(listbox_id) {
	var listbox = document.getElementById(listbox_id);
	if (listbox != null) {
		for (var i = 0; i < listbox.options.length; i++) {
			listbox.options[i].selected = false;
		}
	}
}


/**
 * Validate form
 * @param form - form element
 */
function validateForm(form) {
	var inputs = form.getElementsByTagName("input");
	var selects = form.getElementsByTagName("select");
	var textareas = form.getElementsByTagName("textarea");
	var fields = new Array();
	for (var i = 0; i < inputs.length; i++)
		fields.push(inputs[i]);
	for (var i = 0; i < selects.length; i++)
		fields.push(selects[i]);
	for (var i = 0; i < textareas.length; i++)
		fields.push(textareas[i]);

	for (var i = 0; i < fields.length; i++)
	{
		if (fields[i].getAttribute("valtype") == "required")
		{
			
			if ((fields[i].value.length < 1) || (fields[i].value == ""))
			{
				alert(fields[i].getAttribute("valmessage"));
				fields[i].focus();
				return false;
			}
		}
		else if (fields[i].getAttribute("valtype") == "required group")
		{
			for (var j = 0; j < fields.length; j++)
			{
				if (((fields[i].value.length < 1) || (fields[i].value == "")) && (fields[j].id != fields[i].id) && (fields[j].getAttribute("valgroup") == fields[i].getAttribute("valgroup")) && ((fields[j].value.length < 1) || (fields[j].value == "-1")))
				{
					alert(fields[i].getAttribute("valmessage"));
					fields[i].focus();
					return false;
				}
			}
		}
		else if (fields[i].getAttribute("valtype") == "integer")
		{
			if (fields[i].value.length > 0)
			{
				var parsedInt = parseInt(fields[i].value);
				if (isNaN(parsedInt))
				{
					alert(fields[i].getAttribute("valmessage"));
					fields[i].focus();
					return false;
				}
			}
		}
		else if (fields[i].getAttribute("valtype") == "required integer")
		{
			var parsedInt = parseInt(fields[i].value);
			if (isNaN(parsedInt))
			{
				alert(fields[i].getAttribute("valmessage"));
				fields[i].focus();
				return false;
			}
		}
		else if (fields[i].getAttribute("valtype") == "date")
		{
			if ((fields[i].value.length > 0) && ((fields[i].value.length != 10) || (!validateDate(fields[i].value))))
			{
				alert(fields[i].getAttribute("valmessage"));
				fields[i].focus();
				return false;
			}
		}
		else if (fields[i].getAttribute("valtype") == "time")
		{
			if ((fields[i].value.length > 0) && ((fields[i].value.length != 5) || (!validateTime(fields[i].value))))
			{
				alert(fields[i].getAttribute("valmessage"));
				fields[i].focus();
				return false;
			}
		}
		else if (fields[i].getAttribute("valtype") == "required time")
		{
			if ((fields[i].value.length != 5) || (!validateTime(fields[i].value)))
			{
				alert(fields[i].getAttribute("valmessage"));
				fields[i].focus();
				return false;
			}
		}
		else if (fields[i].getAttribute("valtype") == "datetime")
		{
			if ((fields[i].value.length > 0) && ((fields[i].value.length != 16) || (!validateDateTime(fields[i].value))))
			{
				alert(fields[i].getAttribute("valmessage"));
				fields[i].focus();
				return false;
			}
		}
		else if (fields[i].getAttribute("valtype") == "required datetime")
		{
			if ((fields[i].value.length != 16) || (!validateDateTime(fields[i].value)))
			{
				alert(fields[i].getAttribute("valmessage"));
				fields[i].focus();
				return false;
			}
		}
		else if (fields[i].getAttribute("valtype") == "checked")
		{
			if (!fields[i].checked)
			{
				alert(fields[i].getAttribute("valmessage"));
				fields[i].focus();
				return false;
			}
		}
		else if (fields[i].getAttribute("valtype") == "passmatch")
		{
			var matchField = document.getElementById(fields[i].getAttribute("valmatch"));

			if (fields[i].value != matchField.value)
			{
				alert(fields[i].getAttribute("valmessage"));
				fields[i].focus();
				return false;
			}
		}
		else if (fields[i].getAttribute("valtype") == "passmatch required")
		{
			if ((fields[i].value.length < 1) || (fields[i].value == "-1"))
			{
				alert(fields[i].getAttribute("valmessagerequired"));
				fields[i].focus();
				return false;
			}
		
			var matchField = document.getElementById(fields[i].getAttribute("valmatch"));

			if (fields[i].value != matchField.value)
			{
				alert(fields[i].getAttribute("valmessage"));
				fields[i].focus();
				return false;
			}
		}
		else if (fields[i].getAttribute("valtype") == "username")
		{
			var re = new RegExp('^[\\w]+$');
			if ((fields[i].value.length < 1) || (fields[i].value == "") || (!fields[i].value.match(re)))
			{
				alert(fields[i].getAttribute("valmessage"));
				fields[i].focus();
				return false;
			}
		}
	}

	return true;
}


var _curFLVContainer = null;
var _curFLVFilename = null;
function makePlayer(container, flvFile, vId)
{
	// Remove previous player
	if ((_curFLVContainer != null) && (_curFLVFilename != null))
	{
		var _prevElement = document.getElementById(_curFLVContainer);
		if (_prevElement != null)
		{
			_prevElement.innerHTML = "<div class=\"playbutton\" onclick=\"makePlayer('" + _curFLVContainer + "', '" + _curFLVFilename + "');\"><img src=\"gfx/video_play.gif\" alt=\"\" /></div>\r\n";
			_prevElement.innerHTML += "<img class=\"videoPlaceHolder\" width=\"320\" height=\"240\" onclick=\"makePlayer('" + _curFLVContainer + "', '" + _curFLVFilename + "');\" src=\"" + _curFLVFilename + ".jpg\" alt=\"Video\" border=\"0\" />";
			_curFLVContainer = null;
			_curFLVFilename = null;
		}
	}
	
	var FO = {movie:"flvp.swf",width:"320",height:"240",majorversion:"7",build:"0",bgcolor:"#FFFFFF",allowfullscreen:"false",flashvars:"file=" + flvFile + "&image=" + flvFile + ".jpg&bufferlength=2&autostart=true&shownavigation=false&overstretch=true&logo=gfx/videologo.png&repeat=false&showfsbutton=false"};
	UFO.create(FO, container);
	
	_curFLVContainer = container;
	_curFLVFilename = flvFile;
}


