// JavaScript Document

//Google Analyltics
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-25210147-1']);
_gaq.push(['_trackPageview']);

(function() {
	var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
	ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
	var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();



function sc(fnc)
{
	if(fnc==1)
	{ if (document.getElementById('q').value == "Search") { document.getElementById('q').value = '' } }
	else
	{ if (document.getElementById('q').value == "") { document.getElementById('q').value = 'Search' } }
}

function sp(state)
{
	if(state==1)
	{$('#personalise2').show(); $('#personalise1').hide();}
	else
	{$('#personalise2').hide(); $('#personalise1').show();}
}

function AutoFill(id, defaultTxt){
	tb = document.getElementById(id);
	if (tb != null && trim(tb.value) == '' )
		tb.value = defaultTxt;	
}

function ClearDefault(id, defaultTxt){
	tb = document.getElementById(id);
	if (tb != null && tb.value == defaultTxt )
		tb.value = '';
}

function ValidateForm() {
	errorCount = 0;
	if (!IsValidTb('forename', 'Forename')){
		errorCount ++;
	}
	
	if (!IsValidTb('surname', 'Surname'))
		errorCount ++;
		
	if (!IsValidTb('phone', 'Phone Number'))
		errorCount ++;
		
	if (!IsValidTb('email', 'Your email address'))
		errorCount ++;

		
	//if (!IsValidList('state')
	//	errorCount ++;
		
	//if (!IsValidList('interest')
	//	errorCount ++;
		
	//if (!IsValidList('interestnature')
	//	errorCount ++;
		
	if (!IsValidTb('question', 'Your question'))
		errorCount ++;
	
	if (errorCount > 0){
		alert('Please complete all enquiry form fields. Thank you.');
		return false;
	}
	return true
	
}

function IsValidTb(id, defaultTxt) {
	tb = document.getElementById(id);
	if (tb != null && (trim(tb.value) == '' || tb.value == defaultTxt)){
		//tb.className += " missingfield";
		return false;
	}
	return true
}

function IsValidList(id) {
	list = document.getElementById(id);
	if (list != null && list.selectedIndex > 0){
		return true;
	}
	return false;
}

function trim(str){
	return str.replace(/^\s\s*/, '').replace(/\s\s*$/, '');
}
