//=JA=======================================================
//	Function: addToBasket
//	prdID	= product ID
//
//	Example: addToBasket(139)
//	Desc: Adds a product to the basket by completing a form
// 	      and performing a submit.
//==========================================================

function addToBasket(prdID)
{
	if (!prdID) return;
	
	var form = document.forms['basket'];
	
	if (form) {
		
		var quantity = parseFloat(form.elements['product_qty['+prdID+']'].value);
		
		if (!(quantity > 0)) {
			alert("Please be sure to enter a quantity of at least 1");
			return;
		}
		if (quantity % 1 != 0) {
			alert("Please make sure that the quantity is a whole number");
			return;
		}
		
		form.product_id.value = prdID;
		form.product_qt.value = quantity;
		form.product_tm.value = "0";
		form.submit();
	}
}

function showFlash()
{
	var fx = new Fx.Styles($('growingFlash'), {duration:2000, wait:false, transition: Fx.Transitions.Quart.easeOut});
	fx.addEvent('onComplete', finalShowFlash);
	fx.start({
		'width': [0,849],
		'height': [0,462],
		'top': [0,-235],
		'left': [0,-425]
	});
}

function finalShowFlash(e)
{
	//var img = $('killMe');
	var blImg = $('flbl');
	var brImg = $('flbr');
	
	//if (img) img.parentNode.removeChild(img);
	if (blImg) blImg.src = blImg.src.replace('left.gif','left2.gif');
	if (brImg) brImg.src = brImg.src.replace('right.gif', 'right2.gif');
	
	createFlash();
}

function acceptedTCs()
{	
	if (!$('agreeTCs')) return true;
	
	if (!$('agreeTCs').checked) alert("Please agree to our Terms and Conditions above before proceeding to pay.");
	
	return $('agreeTCs').checked;
}

function cardFinished()
{
	document.forms['designSubmit'].addToBasket.value = '1';
	document.forms['designSubmit'].submit();
}

function flashLoaded()
{
	if ($('killMe')) $('killMe').parentNode.removeChild($('killMe'));
}

function saveForLater()
{
	document.forms['designSubmit'].addToBasket.value = '0';
	document.forms['designSubmit'].submit();
}


function replaceLoaderWithLink()
{
	if ($('killMe')) $('killMe').parentNode.removeChild($('killMe'));
	if ($('flashInnerContainer')) {
		$('flashInnerContainer').innerHTML = '<p id="noFlash"><strong>This website uses the latest Adobe Flash Player, please download from <a href="http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash&ogn=UK-gntray_dl_getflashplayer_uk" target="newwindow">http://www.adobe.com/shockwave/download/</a>.</strong><br/><strong>Note :</strong> If you are using Internet Explorer 6 or earlier, we recommend upgrading to <a href="http://www.microsoft.com/windows/downloads/ie/getitnow.mspx" target="newwindow">Internet Explorer 7</a> or <a href="http://www.mozilla-europe.org/en/products/firefox/" target="newwindow">Firefox 2+</a>.<br/><small>Downloading the Flash player can be confusing, once you have seen the following screen then the player is downloaded, otherwise please be patient.</small><br/><img style="border: 1px solid #444" src="/webapp/templates/default/images/flash_installed.jpg" width="712" height="350" alt="" /><br/>Once complete re-visit <a href="http://www.photoidcardpeople.com">www.photoidcardpeople.com</a> and refresh the page or press F5.<br/><br/>Thank you<p>';
	}
}

//=JA=======================================================
//	Function: proceedToDesign
//	prdID	= product ID
//
//	Example: proceedToDesign(139)
//	Desc: Proceed to the design screen for a specified
//	      card template
//==========================================================

function proceedToDesign(prdID)
{
	if (!prdID) return;
	
	var form = document.forms['basket'];
	
	if (form) {
		
		var quantity = parseFloat(form.elements['product_qty['+prdID+']'].value);
		
		if (!(quantity > 0)) {
			alert("Please be sure to enter a quantity of at least 1");
			return;
		}
		if (quantity % 1 != 0) {
			alert("Please make sure that the quantity is a whole number");
			return;
		}
		
		form.product_id.value = prdID;
		form.product_qt.value = quantity;
		form.product_tm.value = "1";
		form.submit();
	}
}

function clearDefault(input, value)
{
	if (input.value == value) {
		input.value = "";
	}
}

function restoreDefault(input, value)
{
	if (input.value == "") {
		input.value = value;
	}
}

//=JA=======================================================
//	Function: showBasket
//
//	Example: showBasket()
//	Desc: Display the dropdown short-basket in a smooth
//	 	  animation using mootools.
//==========================================================

var basSlider = {keepHidden:true};
var sldState = true;

function bodyLoad()
{
	if ($('basketMid') && $('basketEl')) {
		basSlider.main = new Fx.Slide('basketMid', {duration: 700, transition:Fx.Transitions.Bounce.easeOut});
		basSlider.main.addEvent('onComplete',showBHandle);
		if (basSlider.keepHidden)  {
			basSlider.main.hide();
			sldState = false;
		}
		showBHandle();
	}
	var inputs = $$('.hiddenSubmit');
	for (var i=0; i<inputs.length; i++) {
		inputs[i].style.position = 'absolute';
		inputs[i].style.width = 0;
		inputs[i].style.height = 0;
		inputs[i].style.right = '-10px';
		inputs[i].style.border = '0px solid #fff';
		inputs[i].style.backgroundColor = '#fff';
	}
}

function showBHandle()
{
	sldState = !sldState;
	if ($('basketOpen') && $('basketClose')) {
		$('basketOpen').style.display = 'none';
		$('basketClose').style.display = 'none';
		if (sldState) {
			$('basketOpen').style.display = 'block';
			if ($('checkoutLink')) $('checkoutLink').style.display = 'none';
		}
		else {
			$('basketClose').style.display = 'block';
			if ($('checkoutLink')) $('checkoutLink').style.display = 'inline';
		}
	}
}

function keepOpen() {
	basSlider.keepHidden = false;
}

function showBasket() {
	if (basSlider.main) {
		basSlider.main.toggle();
	}
}

//=JA=======================================================
//	Function: updateQuantities
//
//	Example: updateQuantities()
//	Desc: Submit the basket form, because we can't use
//		  input type image
//==========================================================

function updateQuantities()
{
	var form = document.forms['basket'];
	
	if (form && form.button_update) {
		form.button_update.value = 1;
		form.submit();
	}
}

function submitForm(name)
{
	var form = document.forms[name];
	
	if (form) {
		form.submit();
	} else {
		form = $(name);
		if(form)
			form.submit();
	}
}

//=WW=======================================================
// CheckUsername(args)				- REQUIRES MOOTOOLS
// See if a user exists in the database via AJAX
// Call directly or use a setTimeout/clearTimeout with onkeypress
// args is a class with variables:
//
// 	inputid			- ID of inputbox
//	matchclassname	- classname to assign to inputbox if a match is found
//	nomatchclassname- classname to assign to inputbox if no match is found
//	matchelement	- element ID to display if a match is found
//	nomatchelement	- element ID to display if no match is found
//	defaultvalue	- value to ignore - if textbox has this value, do nothing
//  scripturl		- url of local file to call to do check
//	type			- passed in POST string to script called - useful to
//						determine which table to check
//
// Script will be called via POST with 2 variables
//	type			- as set in args
//	username 		- retrieved from $(inputid).value - inputid set in args
// e.g. type=user&username=joe
//
// Script should return simply 'good' or 'bad' 
//==========================================================
function CheckUsername(args) {
	var scripturl = '/webapp/modules/includes/common/CheckUsername.php';
	args.input = $(args.inputid);
	args.scripturl = typeof args.scripturl == 'undefined' ? scripturl : args.scripturl;
	if(args.input.value == args.defaultvalue) {
		$(args.nomatchelement) !== null ? $(args.nomatchelement).style.display = 'none' : null;
		$(args.matchelement)   !== null ? $(args.matchelement).style.display   = 'none' : null;
		if(typeof args.matchclassname   !== 'undefined') args.input.removeClass(args.matchclassname);
		if(typeof args.nomatchclassname !== 'undefined') args.input.removeClass(args.nomatchclassname);
	} else {		
		new Ajax(args.scripturl, {method: 'post', 
					postBody: 'type='+args.type+'&username='+args.input.value, 
					onSuccess: function(t) {
						if(t.indexOf('bad') > -1) {
							$(args.nomatchelement) !== null ? $(args.nomatchelement).style.display = 'none' : null;
							$(args.matchelement)   !== null ? $(args.matchelement).style.display   = ''     : null;
							if(typeof args.matchclassname   !== 'undefined') args.input.addClass(args.matchclassname);
							if(typeof args.nomatchclassname !== 'undefined') args.input.removeClass(args.nomatchclassname);
						} else if(t.indexOf('good') > -1) {
							$(args.nomatchelement) !== null ? $(args.nomatchelement).style.display = ''     : null;
							$(args.matchelement)   !== null ? $(args.matchelement).style.display   = 'none' : null;
							if(typeof args.matchclassname   !== 'undefined') args.input.removeClass(args.matchclassname);
							if(typeof args.nomatchclassname !== 'undefined') args.input.addClass(args.nomatchclassname);
						} else {
							$(args.nomatchelement) !== null ? $(args.nomatchelement).style.display = 'none' : null;
							$(args.matchelement)   !== null ? $(args.matchelement).style.display   = 'none' : null;
							if(typeof args.matchclassname   !== 'undefined') args.input.removeClass(args.matchclassname);
							if(typeof args.nomatchclassname !== 'undefined') args.input.removeClass(args.nomatchclassname);
						}
					},
					onFailure: function(t) {
						$(args.nomatchelement) !== null ? $(args.nomatchelement).style.display = 'none' : null;
						$(args.matchelement)   !== null ? $(args.matchelement).style.display   = 'none' : null;
						if(typeof args.matchclassname   !== 'undefined') args.input.removeClass(args.matchclassname);
						if(typeof args.nomatchclassname !== 'undefined') args.input.removeClass(args.nomatchclassname);
					}}).request();
	}
}

//=WW=======================================================
// CheckEmail(obj, classname)
// Basic email validation check, uses timer so it can be 'live'
// Usage: onkeyup=CheckEmail('id_of_inputbox', 'bademail')
//
// inputid		- inputbox element ID
// classname	- classname to add to inputbox if email invalid
//==========================================================
function CheckEmail(inputid, classname) {
	if(checktimer > 0) window.clearTimeout(checktimer);
	checktimer = window.setTimeout('CheckEmail_Callback("'+inputid+'", "'+classname+'")', 1000);
}
function CheckEmail_Callback(inputid, classname) {
	obj = $(inputid);
	if(obj.value.length == 0) {
		if(typeof classname !== undefined)
   			obj.removeClass(classname);
   		return true;
	}
	var reg = /^([A-Za-z0-9_\-\.\+])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
	if(reg.test(obj.value) == false) {
		if(typeof classname !== undefined)
			obj.addClass(classname);
		return false;
	} else {
		if(typeof classname !== undefined)
   			obj.removeClass(classname);
   		return true;
	}
}

/*=================== [END] AJAX Based Checks ======================= */

//=WW=======================================================
// IsValidDate(date, direction)
// Attempts to validate a date. Depending on the date, can 
// take into account dd/mm or mm/dd. Will also accept 2 or 4
// year dates and the use of - or / as the separator.
// Can also check if the date is before/after today.
//
// date			- string to validate
// direction	- optional. if specified will check if the date
//					is before or after today. Specify -1 for
//					before today, 1 for after today.
//==========================================================
function IsValidDate(date, direction) {
	while(date.indexOf('-') > -1) date = date.replace('-', '/');
	while(date.indexOf(' ') > -1) date = date.replace(' ', '');
	date = date.split('/');
	
	if(date.length != 3) return false;
		
	if(isNaN(date[0]) || isNaN(date[1]) || isNaN(date[2])) return false;
		
	date[0] = parseInt(date[0]); date[1] = parseInt(date[1]); date[2] = parseInt(date[2]);
	
	if(date[0] < 1 || date[1] < 1 || date[2] < 1) return false;
	
	if(date[2].toString().length <= 2 && date[2] < parseInt(new Date("yy"))) date[2] = 2000 + date[2];
	else if (date[2].toString().length <= 2) date[2] = 1900 + date[2];
	
	if(date[1] > 12 && date[0] <= 12) {
		t = date[1];
		date[1] = date[0];
		date[0] = t;	
	}
	
	daysinmonths = new Array(31,(((date[2] % 4 == 0) && ( (!(date[2] % 100 == 0)) || (date[2] % 400 == 0))) ? 29 : 28 ),31,30,31,30,31,31,30,31,30,31);
	if(date[1] > 12 || date[0] > daysinmonths[date[1]-1]) return false;
	
	if(date[0].toString().length == 1) date[0] = '0' + date[0].toString()
	if(date[1].toString().length == 1) date[1] = '0' + date[1].toString()
		
	date = date[2] + '-' + date[1] + '-' + date[0];
	
	real_date = new Date(date.replace('-', '/').replace('-', '/'))
	now = new Date();
		
	if(direction == -1) if(real_date > now) return false;
	else if (direction == 1) if(real_date < now) return false;
	
	return date;
}

//=WW=======================================================
// CreateElement(data)
// Creates a DOM element by passing an object with all 
// the information you want for the element in it.
// To avoid memory leaks in IE, pass one field as parent with a
// string identifying the ID of the parent DOM element to add to
//
// e.g. to create a tr with a class of 'header'
//		tr = CreateElement({tagtype: 'tr', className: 'header'});
//
// or to create a div with text inside
//		div = CreateElement({tagtype: 'div', text: 'Some text'});
//
// or to create a div containing two images
//		div = CreateElement(tagtype: 'div', children: 
//			[{tagtype: 'img', src: 'image1.jpg'}, {tagtype: 'img', src: 'image2.jpg'}]);
//
// Function returns the element to be used in an append
// e.g. table.appendChild(tr);
//==========================================================
function CreateElement_old(data)
{
	var e = document.createElement(data.tagtype);
	if(typeof data.parent == 'string') data.parent = document.getElementById(data.parent);
	if(data.parent != undefined) data.parent.appendChild(e);
	for(var key in data)
		if(key == 'style') for(var s in data.style) eval('e.style.'+s+' = data.style.'+s)
		else if(key == 'text') e.appendChild(document.createTextNode(data.text));
		else if(key == 'children') for(var i=0;i<data.children.length;i++) {data.children[i].parent = e; CreateElement(data.children[i]);}
		else if(key.substr(0,2) == 'on') eval('e.'+key+' = new Function("'+eval('data.'+key).replace(/\"/g, '\\"')+'")');
		else if(key != 'parent' && key != 'id') eval('e.'+key+' = data.'+key);
	if(data.parent == undefined) return e;
}

function CreateElement(data)
{
	var e = document.createElement(data.tagtype);
	if(data.tagtype == 'input') e.type = (data.type == undefined ? 'text' : data.type);
	if(typeof data.parent == 'string') data.parent = document.getElementById(data.parent);
	if(data.parent != undefined) data.parent.appendChild(e);
	for (var key in data) 
		if (key == 'style') for (var s in data.style) eval('e.style.' + s + ' = data.style.' + s);
		else if (key == 'text') e.appendChild(document.createTextNode(data.text));
		else if (key == 'children') for (var i = 0; i < data.children.length; i++) {data.children[i].parent = e;CreateElement(data.children[i]);} 
		else if (key.substr(0, 2) == 'on') $(e).addEvent(key.replace('on', ''), data.bind != undefined ? function(event){eval(eval('data.on'+event.type));}.bind(data.bind) : function(event){eval(eval('data.on'+event.type));});
		else if (key != 'parent' && key != 'bind') eval('e.' + key + ' = data.' + key);
	return e;
}

//=WW=======================================================
// RestrictInput(obj, vals)
// Restricts input in an input field to the specified regex
// e.g. onkeyup="RestricInput(this, /[^\d]/g)" would prevent all
// values except for numbers.
//==========================================================
function RestrictInput(obj, vals)
{
	obj.value = obj.value.replace(vals, '');
}

//=JA=======================================================
//	Function: submitCheckoutWith
//
//	Example: submitCheckoutWith(this,'SHIPPING')
//	Desc: Submit the checkout form that wraps around the
//		  first paramter, set the hidden form field to value
//		  of method.
//==========================================================

function submitCheckoutWith(formEl, method) {
	if (formEl.value) {
		formEl.form.changed.value=method;
		formEl.form.submit();
	}
}

//=WW=======================================================
// CheckUsername(args)
// Validates a username against a database via AJAX
//==========================================================
function CheckUsername(args) {
	var scripturl = rooturl+'webapp/modules/includes/common/CheckUsername.php';
	args.input = typeof args.inputid == 'string' ? $(args.inputid) : args.input;
	args.scripturl = typeof args.scripturl == 'undefined' ? scripturl : args.scripturl;
	if(args.input.value == args.defaultvalue) {
		$(args.nomatchelement) !== null ? $(args.nomatchelement).style.display = 'none' : null;
		$(args.matchelement)   !== null ? $(args.matchelement).style.display   = 'none' : null;
		if(typeof args.matchclassname   !== 'undefined') args.input.removeClass(args.matchclassname);
		if(typeof args.nomatchclassname !== 'undefined') args.input.removeClass(args.nomatchclassname);
	} else {		
		new Ajax(args.scripturl, {method: 'post', 
			postBody: 'type='+args.type+'&username='+args.input.value, 
			onSuccess: function(t) {
			if(t.indexOf('exists') > -1) {
				$(args.nomatchelement) !== null ? $(args.nomatchelement).style.display = 'none' : null;
				$(args.matchelement)   !== null ? $(args.matchelement).style.display   = ''     : null;
				if(typeof args.matchclassname   !== 'undefined') args.input.addClass(args.matchclassname);
				if(typeof args.nomatchclassname !== 'undefined') args.input.removeClass(args.nomatchclassname);
			} else if(t.indexOf('unique') > -1) {
				$(args.nomatchelement) !== null ? $(args.nomatchelement).style.display = ''     : null;
				$(args.matchelement)   !== null ? $(args.matchelement).style.display   = 'none' : null;
				if(typeof args.matchclassname   !== 'undefined') args.input.removeClass(args.matchclassname);
				if(typeof args.nomatchclassname !== 'undefined') args.input.addClass(args.nomatchclassname);
			} else {
				$(args.nomatchelement) !== null ? $(args.nomatchelement).style.display = 'none' : null;
				$(args.matchelement)   !== null ? $(args.matchelement).style.display   = 'none' : null;
				if(typeof args.matchclassname   !== 'undefined') args.input.removeClass(args.matchclassname);
				if(typeof args.nomatchclassname !== 'undefined') args.input.removeClass(args.nomatchclassname);
			}
			},
			onFailure: function(t) {
			$(args.nomatchelement) !== null ? $(args.nomatchelement).style.display = 'none' : null;
			$(args.matchelement)   !== null ? $(args.matchelement).style.display   = 'none' : null;
			if(typeof args.matchclassname   !== 'undefined') args.input.removeClass(args.matchclassname);
			if(typeof args.nomatchclassname !== 'undefined') args.input.removeClass(args.nomatchclassname);
		}}).request();
	}
}

//------------------------------------------------------------------
//
// Functions to deal with the card browse page
//
//------------------------------------------------------------------
arrSort = new Array();
strSortBy = 'draft_datetime';
results = 10;
page = 1;

function DoSort(strSort)
{
	if(arrSort[strSort] == undefined)
		arrSort[strSort] = 0;
	else
		arrSort[strSort] = (arrSort[strSort] == 1 ? 0 : 1);
		
	strSortBy = strSort;
	
	GetCards('');
}

function doPreview(el)
{
	if($(el).getElement('.preview')) return;
	divs = $(el.parentNode).getElements("div");
	divs.each(function(div, j){div.remove();}.bind(this));
	
	var isie = /MSIE/.test(navigator.userAgent)
	
	var style = new Object();
	style.position = 'absolute';
	style.left = '40px'
	style.top = isie? '20px' : '35px';
	style.width = '16px';
	style.height = '16px';
	style.background = 'url(/webapp/templates/default/images/ajax-loader-black.gif) top left no-repeat';
	style.zIndex = 90;
	var loading = new Object();
	loading.tagtype = 'div';
	loading.style = style;
	loading = CreateElement(loading);
	el.insertBefore(loading,el.getElement('img'));

	var img = new Element('img',{'src': el.href+'#'+Math.random(	5000),'width':282,'height':180,'class':'preview','styles':{'position':'absolute','left':'-100px','top':isie ? '-60px' : '-10px','display':'none','zIndex':100},'events':{'load':function(e){divs = $(this.parentNode).getElements("div");divs.each(function(div, j){div.remove();}.bind(this));fadeIn(this);}}});
	el.adopt(img);
	
	//CreateElement(preview);
}

function GetCards(submittype)
{
	var strPost = 'results[0]='+results+'&page[0]='+page;
	
	switch(submittype) {
		case 'limit':
			strPost += '&set[0]=Set';
			break;
			
		case 'previous':
			strPost += '&previous[0]=1';
			break;
			
		case 'next':
			strPost += '&next[0]=1';
			break;
			
		case 'last':
			strPost += '&last[0]=1';
			break;
			
		case 'first':
			strPost += '&first[0]=1';
			break;
			
		case 'page':
			strPost += '&jump[0]=Go';
			break;
	}
	
	$('loading').style.display = '';
	
	var children = $$('#mainResults .cardrow');
	children.each(function(t,i){
		$('mainResults').getElement('tbody').removeChild(t);
	});
	
	new Ajax(root + '/client/_getcards.php?sortby='+strSortBy+'&direct='+arrSort[strSortBy],
		{
			method: 'post',
			postBody: strPost,
			onComplete: function(t) {
				t = t.split('^');
				$('page').value = t[0];
				$('limit').value = t[1];
				$('total').innerHTML = t[3];
				$('numpages').innerHTML = t[4];
				var children = Json.evaluate(t[5]).children;
				
				if (children) {
					children.each(function(child, i){
						CreateElement(child);
					});
						
						
					var links = $$('.cardrow .cardlink');
					links.each(function(link, i){
						$(link).style.position = 'relative';
						$(link).addEvent('mouseenter', function(e) {
							divs = $(this.parentNode).getElements("div");
							divs.each(function(div, j){div.remove();}.bind(this));
							
							var isie = /MSIE/.test(navigator.userAgent)
							
							var style = new Object();
							style.position = 'absolute';
							style.left = '40px'
							style.top = isie ? '20px' : '-20px';
							style.width = '16px';
							style.height = '16px';
							//style.background = 'url('+root+'/webapp/templates/default/images/ajax-loader-black.gif) top left no-repeat';
							style.zIndex = 90;
							var loading = new Object();
							loading.tagtype = 'div';
							loading.style = style;
							loading = CreateElement(loading);
							this.insertBefore(loading,this.getElement('img'));
							
							var style = new Object();
							style.position = 'absolute';
							style.left = '-100px';
							style.top = isie ? '-60px' : '-100px';
							style.display = 'none';
							style.zIndex = 100;
							
							var preview = new Object();
							preview.tagtype = 'img';
							preview.src = this.href;
							preview.parent = this;
							preview.style = style;
							preview.width = '282';
							preview.height = '180';
							preview.onload = 'divs = $(this.parentNode).getElements("div");divs.each(function(div, j){div.remove();}.bind(this))';
							CreateElement(preview);
						});
					});
				}
					
				$('loading').style.display = 'none';
			}
		}
	).request();
	
	return false;
}

function fadeIn(obj)
{
	new Fx.Style($(obj), 'opacity').set(0);
	$(obj).style.display = '';
	var myFx = new Fx.Style($(obj), 'opacity').start(0, 1);
	$(obj).addEvent('mouseleave', function(e) {fadeOut(e.target)});
}

function fadeOut(obj)
{
	if(obj && obj.parentNode)
	new Fx.Style($(obj), 'opacity').start(1, 0).addEvent('onComplete', function(e){obj.parentNode.removeChild(obj)});
}

function CardBrowser()
{
	arrSort['draft_datetime'] = 0;
	
	GetCards('limit');
}

function isOk(e)
{
	e.removeClass('bad');
	e.addClass('good')
}

function isNotOk(e)
{
	e.removeClass('good');
	e.addClass('bad');
}

function isEmpty(e)
{
	e.removeClass('bad');
	e.removeClass('good')
}

val = '';

function sendEnquiry()
{
	if (val.validateForm()) {
		val.form.submit();
	} else {
		alert('You have not filled in all the required fields\nPlease check them and try again.');
	}
}

function contactValidation()
{
	
	val = new Validation(400);

	val.cancelSubmit(true);
	val.setOnSubmit(sendEnquiry);
	
	val.addField('enquiry_forename', 'alphaextended', 1, 40, true, isOk, isNotOk, isEmpty);
	val.addField('enquiry_surname', 'alphaextended', 1, 40, true, isOk, isNotOk, isEmpty);
	val.addField('enquiry_company', 'alphaextended', 0, 80, false, isOk, isNotOk, isEmpty);
	val.addField('enquiry_position', 'alphaextended', 0, 80, false, isOk, isNotOk, isEmpty);
	val.addField('enquiry_region', 'alphaextended', 2, 80, false, isOk, isNotOk, isEmpty);
	val.addField('enquiry_country', 'alphaextended', 2, 80, false, isOk, isNotOk, isEmpty);
	val.addField('enquiry_telephone', 'alphanumericextended', 6, 40, true, isOk, isNotOk, isEmpty);
	val.addField('enquiry_email', 'email', 8, 64, true, isOk, isNotOk, isEmpty);	
	
	val.bindToForm('enquiry_form');
}



function initAccordian() {
	window.addEvent('domready', function() {
		//create our Accordion instance
		var myAccordion = new Accordion($('accordianArea'), 'div.toggler', 'div.element', {
			display: -1,
			opacity: true,
			alwaysHide: true,
			onActive: function(toggler, element){
				//toggler.setStyle('color', '#e58e1a');
			},
			onBackground: function(toggler, element){
				//toggler.setStyle('color', '#0070ad');
			}
		});
	});
}

