/*
	Author: Matt Johnson
	Company: Bullhorn.co.uk
	Last Mod: 25/01/2008
*/
function mooLoad() {
	window['mySlide'] = new Fx.Slide('moo_search');

	$('moo_toggle').addEvent('click', function(e){
		e = new Event(e);
		window['mySlide'].toggle();
		e.stop();
	});
}
addEvent(window, 'load', mooLoad, false);
function reOrder(orderType) {
	updateInput('bullhorn_order', String(orderType));
	ajaxResults(null);
}
function alterDisplay(elementId) {
	var myEle = dGetById(elementId);
	if (myEle) {
		if (!window['pie_' + elementId]) {
			try {
				window['pie_' + elementId] = new Fx.Slide(elementId);
				window['pie_' + elementId].hide();
			} catch(ex) {}
		} else {
			window['pie_' + elementId].toggle();
		}
	}
}
function validateForm() {
	var isValid = false;
	var ele = dGetById('bullhorn_postcode');
	if (ele) {
		if (ele.value.length > 4) {
			isValid = true;
		}
	}
	window['selectedTab'] = 'tab1';
	window['__bullhorn_page'] = 1;
	ReportError((!isValid), 'The <b>PostCode<\/b> field does not contain a value, or it does not contain enough characters.');
	return isValid;
}
function switchTab(tabElement) {
	if (tabElement) {
		var tab1 = dGetById('tab1');
		var tab2 = dGetById('tab2');
		var tab3 = dGetById('tab3');
		var tab4 = dGetById('tab4');
		var tabPage1 = dGetById('tab_page_1');
		var tabPage2 = dGetById('tab_page_2');
		var tabPage3 = dGetById('tab_page_3');
		var tabPage4 = dGetById('tab_page_4');
		tab1.className = '';
		tab2.className = '';
		tab3.className = '';
		tab4.className = '';
		tabPage1.style.display = 'none';
		tabPage2.style.display = 'none';
		tabPage3.style.display = 'none';
		tabPage4.style.display = 'none';
		tabElement.className = 'selected';
		var selTab = dGetById(String(tabElement.id).replace('tab', 'tab_page_'));
		if (selTab) {
			selTab.style.display = 'block';
		}
		window['selectedTab'] = tabElement.id;
	}
	return false;
}
function ReportError(isErrors, alertMessage) {
	var ele = dGetById('errorBox');
	if (isErrors) {
		if (ele) {
			ele.innerHTML = alertMessage;
			if (ele.style)
				ele = ele.style;
			ele.display = 'block';
		}
	} else {
		if (ele) {
			if (ele.style)
				ele = ele.style;
			ele.display = 'none';
		}
	}
}
function ajaxResults(isTemp) {
	var updateTagId = 'broadband_result';
	if (isTemp) {
		updateTagId = 'temp_results';
	}
	var order = evaluateObject('bullhorn_order');
	var speed = evaluateObject('bullhorn_speed');
	var limit = evaluateObject('bullhorn_limit');
	var tab = (window['selectedTab']);
	var orderType = 'monthlyCost';
	var speedType = null;
	var limitType = null;
	var tabType = null;
	if (order) {
		if (order != '') {
			orderType = order;
		}
	}
	if (speed) {
		if (speed != '') {
			speedType = speed;
		}
	}
	if (limit) {
		if (limit != '') {
			limitType = limit;
		}
	}
	if (tab) {
		if (tab != '') {
			tabType = tab;
		}
	}
	if (!isTemp) {
		if (window['mySlide']) {
			window['mySlide'].hide();
		}
	}
	dGetById(updateTagId).innerHTML = '<center style="padding-top:100px;"><img src="/images/ajaxLoader.gif" border="0" /><p>Loading...</p></center>';
	var ajaxUrl = '/services/broadbandsearch.aspx'
	ajaxUrl += '?bullhorn_order=' + orderType
	ajaxUrl += '&bullhorn_telephone=' + dGetById('bullhorn_telephone').value;
	ajaxUrl += '&bullhorn_postcode=' + dGetById('bullhorn_postcode').value;
	if (window['__bullhorn_page']) {
		ajaxUrl += '&bullhorn_page=' + String(window['__bullhorn_page']);
	}
	if (speedType) {
		ajaxUrl += '&bullhorn_speed=' + speedType;
	}
	if (limitType) {
		ajaxUrl += '&bullhorn_limit=' + limitType;
	}
	if (tabType) {
		ajaxUrl += '&bullhorn_tab=' + tabType;
	}
	if (isTemp)
		ajaxUrl = '/services/broadbandsearch.aspx?bullhorn_tab=tab1&bullhorn_postcode=SW1A2DB&isTemp=true'
	var bullJax = new BullHorn.Ajax(ajaxUrl);
	bullJax.onDraw = function(message) {
		dGetById(updateTagId).innerHTML = message;
		window['renderer'] = setTimeout('clearTimeout(window[\'renderer\']);\ntry {\neval(dGetById(\'dirtyCode\').innerHTML);\n} catch(err) {\n}', 200);
	}
	bullJax.load();
	window['__bullhorn_page'] = 1;
}
function catchSubmit(e) {
	if (!e)
		e = window.event;
	if (e.keyCode == 13) {
		var bullhorn_search = dGetById('bullhorn_search');
		if (bullhorn_search) {
			bullhorn_search.click();
		}
		cancelBubble(e);
	}
}