var ACMEBlinds = {
	Events : {
		PreventDefault:function(e) {
			if( e.keyCode == 13 ) {
				e.returnValue = false;
				e.cancel = true;
			} 		
		}
	},
	Help : {
		Show:function(key) {
			var url = "index.cfm?action=Ajax_Help_Show&key=" + escape( key );
			new Ajax.Request( url, {asynchronous:true, onSuccess:ACMEBlinds.Help.Show_onSuccess, onFailure:errFunc});
		},
		Show_onSuccess:function(t) {
			z = parseJSON( t.responseText );
			LightboxHolder.DestroyCreate("LightboxHolder");		
			$("LightboxHolder").update( z.helpHTML );
			DCLightbox.showBoxByID( "LightboxHolder", 550 , 400, false );
		}
	},
	Products : {
		Contact : {
			Validate:function() {
				if( $("customerFirstname").value.blank() ) {
					ACMEBlinds.HAL("customerFirstname");
					return false;
				}
				if( $("customerLastname").value.blank() ) {
					ACMEBlinds.HAL("customerLastname");
					return false;
				}
				if( $("customerEmailAddress").value.blank() || $("customerEmailAddress").value.indexOf("@") == -1 || $("customerEmailAddress").value.indexOf(".") == -1 ) {
					ACMEBlinds.HAL("customerEmailAddress");
					return false;
				}
				if( $("customerMessage").value.blank() ) {
					ACMEBlinds.HAL("customerMessage");
					return false;
				}
				if( $("outletId").value == 0 ) {
					ACMEBlinds.HAL("outletId");
					return false;
				}
				return true;
			}
		}
	},
	ProductCategory : {
		Contact : {
			Validate:function() {
				if( $("customerFirstname").value.blank() ) {
					ACMEBlinds.HAL("customerFirstname");
					return false;
				}
				if( $("customerLastname").value.blank() ) {
					ACMEBlinds.HAL("customerLastname");
					return false;
				}
				if( $("customerEmailAddress").value.blank() || $("customerEmailAddress").value.indexOf("@") == -1 || $("customerEmailAddress").value.indexOf(".") == -1 ) {
					ACMEBlinds.HAL("customerEmailAddress");
					return false;
				}
				if( $("customerMessage").value.blank() ) {
					ACMEBlinds.HAL("customerMessage");
					return false;
				}
				return true;
			}
		}
	},
	LocalAgents : {
		Contact : {
			Validate:function() {
				if( $("customerFirstname").value.blank() ) {
					ACMEBlinds.HAL("customerFirstname");
					return false;
				}
				if( $("customerLastname").value.blank() ) {
					ACMEBlinds.HAL("customerLastname");
					return false;
				}
				if( $("customerEmailAddress").value.blank() || $("customerEmailAddress").value.indexOf("@") == -1 || $("customerEmailAddress").value.indexOf(".") == -1 ) {
					ACMEBlinds.HAL("customerEmailAddress");
					return false;
				}
				if( $("customerMessage").value.blank() ) {
					ACMEBlinds.HAL("customerMessage");
					return false;
				}
				return true;
			}
		}
	},
	Samples : {
		Order:function(productId,colorId,fabricId) {
			var url = "index.cfm?action=Ajax_Samples_Order&pId=" + productId + "&fId=" + fabricId + "&cId=" + colorId;
			new Ajax.Request( url, {asynchronous:true, onSuccess:ACMEBlinds.Samples.Order_onSuccess, onFailure:errFunc});
		},
		Order_onSuccess:function(t) {
			z = parseJSON( t.responseText );
			LightboxHolder.DestroyCreate("LightboxHolder");		
			$("LightboxHolder").update( z.formHTML );
			DCLightbox.showBoxByID( "LightboxHolder", 680 , 550, false );
		},
		Close:function() {
			LightboxHolder.RemoveAndClose("LightboxHolder");
		},
		Validate:function() {
			if( $("sample_firstName").value.blank() ) {
				ACMEBlinds.HAL("sample_firstName");
				return false;
			}
			if( $("sample_lastName").value.blank() ) {
				ACMEBlinds.HAL("sample_lastName");
				return false;
			}
			if( $("sample_address1").value.blank() ) {
				ACMEBlinds.HAL("sample_address1");
				return false;
			}
			if( $("sample_city").value.blank() ) {
				ACMEBlinds.HAL("sample_city");
				return false;
			}
			if( $("sample_telephone").value.blank() ) {
				ACMEBlinds.HAL("sample_telephone");
				return false;
			}
			$("btn_sample").disabled = true;
			new Ajax.Request('index.cfm', {asynchronous:true, onSuccess:ACMEBlinds.Samples.Validate_onSuccess, onFailure:errFunc, parameters:Form.serialize( $( "orderSampleForm" ) )});
			return false;
		},
		Validate_onSuccess:function(t) {
			z = parseJSON( t.responseText );
			if( $("orderSample_holder") ) {
				$("orderSample_holder").update( z.message );
				ACMEBlinds.Samples.Close();
			}
		}		
	},
	Locations : {
		Map : {
			Load:function() {
				if ( GBrowserIsCompatible() ) {
					var enableControls = true;
					var lat = 53.402982;
					var lng = -7.987061;
					var zoom = 7;
					var map = new GMap2( document.getElementById("map_canvas"));
			        map.setCenter( new GLatLng( lat , lng ) , zoom );
				
				    var customUI = map.getDefaultUI();
					customUI.controls.scalecontrol = false;
					customUI.controls.overviewmapcontrol = false;

					if( !enableControls ) {
						customUI.controls.largemapcontrol3d = false;
					}
					
					map.setUI( customUI );
			 		
					if( !enableControls ) {		
						map.disableDragging();
						map.disableDoubleClickZoom();						
						map.disableGoogleBar();
						map.disableScrollWheelZoom();
					}
					
					map.removeMapType( G_SATELLITE_MAP );
					map.removeMapType( G_PHYSICAL_MAP );
					map.removeMapType( G_HYBRID_MAP );
					
			        // Create a base icon for all of our markers that specifies the
			        // shadow, icon dimensions, etc.
			        var baseIcon = new GIcon(G_DEFAULT_ICON);
			        baseIcon.shadow = "http://www.google.com/mapfiles/shadow50.png";
			        baseIcon.iconSize = new GSize(20, 23);
			        baseIcon.shadowSize = new GSize(37, 34);
			        baseIcon.iconAnchor = new GPoint(9, 34);
			        baseIcon.infoWindowAnchor = new GPoint(9, 2);
			 
			        // Creates a marker whose info window displays the letter corresponding
			        // to the given index.
			        function createMarker( point , index ) {			          
						var letter = String.fromCharCode("A".charCodeAt(0) + index);
						var letteredIcon = new GIcon(baseIcon);
						letteredIcon.image = "images/icons/acmemappin.png";
			 
						// Set up our GMarkerOptions object
						markerOptions = { icon:letteredIcon };
						var marker = new GMarker(point, markerOptions);
						
						var markerHTML = ""; 
						markerHTML += "<strong>" + outletData.data.outletname[ index ] + "</strong>&nbsp;(" + "<a style='font-size:12px' href='index.cfm/page/localagent/id/" + outletData.data.outletid[ index ] + "'>View Web Page &raquo;</a>" + ")<br>";

						markerHTML += outletData.data.outletaddress1[ index ];
						if( outletData.data.outletaddress2[ index ].length ) {
							markerHTML += ", " + outletData.data.outletaddress2[ index ];
						}
						if( outletData.data.outletaddress3[ index ].length ) {
							markerHTML += ", " + outletData.data.outletaddress3[ index ];
						}
						if( outletData.data.outletcity[ index ].length ) {
							markerHTML += ", " + outletData.data.outletcity[ index ];
						}
						markerHTML += ", " + outletData.data.countyname[ index ];
						markerHTML += " - <strong>Telephone:</strong> " + outletData.data.outlettelephone[ index ];
												 
						GEvent.addListener( marker , "click", function() {
							marker.openInfoWindowHtml( markerHTML );
						});
						
						return marker;
			        }
			 			        
					for( i=0; i<outletData.recordcount; i++ ) {						
						var latlng = new GLatLng( outletData.data.outletmaplat[i] , outletData.data.outletmaplng[i] );
						map.addOverlay( createMarker( latlng, i ) );
					}
										
										
			      }
			}
		}
	},
	HAL:function(id) {
		new Effect.Highlight( $(id) );
		$(id).focus();
	},
	QuickSearch : {
		searchString : "search here...",
		Validate:function(section) {
			if( typeof(section) == "undefined" ) {
				section = "";
			}
			if( $("searchBox" + section ).value.blank() || $("searchBox" + section ).value==ACMEBlinds.QuickSearch.searchString ) {
				ACMEBlinds.HAL( "searchBox" + section );
				return false;
			}
			return true;			
		},
		Click:function(section) {
			if( typeof(section) == "undefined" ) {
				section = "";
			}
			if( $("searchBox" + section ).value == ACMEBlinds.QuickSearch.searchString ) {
				$("searchBox" + section ).value = "";
			}
		},
		Blur:function(section) {
			if( typeof(section) == "undefined" ) {
				section = "";
			}
			if( $("searchBox" + section ).value.blank() ) {
				$("searchBox" + section ).value = ACMEBlinds.QuickSearch.searchString;
			}
		}
	},
	HomePageWidget : {		
		Start:function( argSlideSpeed , argSlideFadeSpeed ) {
			new Protofade( "bannerSlides" , { Delay:argSlideSpeed,Duration:argSlideFadeSpeed });
		}
	},
	Forms : {
		MyAddress : {
			Validate:function() {
				if( $("customerAddress1").value.blank() ) {
					ACMEBlinds.HAL( "customerAddress1" );
					return false;
				}
				if( $("customerCity").value.blank() ) {
					ACMEBlinds.HAL( "customerCity" );
					return false;
				}						
				return true;
			}
		},
		Checkout : {
			LocalPickup : {
				Validate:function() {
					if( $("orderDeliveryTelephone").value.blank() ) {
						ACMEBlinds.HAL( "orderDeliveryTelephone" );
						return false;
					}
					if( $("outletId").value == 0 ) {
						alert( "Please choose a local agent to pick your order up from" );
						return false;
					}
					return true;
				}
			},
			Create : {
				Validate:function() {
					if( $("customerFirstname").value.blank() ) {
						ACMEBlinds.HAL( "customerFirstname" );
						return false;
					}
					if( $("customerLastname").value.blank() ) {
						ACMEBlinds.HAL( "customerLastname" );
						return false;
					}
					if( $("customerEmailAddress").value.blank() || $("customerEmailAddress").value.indexOf("@") == -1 || $("customerEmailAddress").value.indexOf(".") == -1 ) {
						ACMEBlinds.HAL( "customerEmailAddress" );
						return false;
					}
					if( $("customerPassword").value.blank() ) {
						ACMEBlinds.HAL( "customerPassword" );
						return false;
					}
					if( $("customerPassword2").value.blank() ) {
						ACMEBlinds.HAL( "customerPassword2" );
						return false;
					}
					if( $("customerPassword").value != $("customerPassword2").value ) {
						alert("Your password and your confirmation password do not match");
						return false;
					}				
					return true;
				}
			},
			Login : {
				Validate:function() {
					if( $("customerEmailAddress").value.blank() || $("customerEmailAddress").value.indexOf("@") == -1 || $("customerEmailAddress").value.indexOf(".") == -1 ) {
						ACMEBlinds.HAL( "customerEmailAddress" );
						return false;
					}
					if( $("customerPassword").value.blank() ) {
						ACMEBlinds.HAL( "customerPassword" );
						return false;
					}
					return true;
				}
			},
			Address : {
				Validate:function() {
					if( $("customerAddress1").value.blank() ) {
						ACMEBlinds.HAL( "customerAddress1" );
						return false;
					}
					if( $("customerCity").value.blank() ) {
						ACMEBlinds.HAL( "customerCity" );
						return false;
					}						
					return true;
				}
			}
		},
		MyDetails : {
			Validate:function() {
				if( $("customerFirstname").value.blank() ) {
					ACMEBlinds.HAL( "customerFirstname" );
					return false;
				}
				if( $("customerLastname").value.blank() ) {
					ACMEBlinds.HAL( "customerLastname" );
					return false;
				}
				if( $("customerEmailAddress").value.blank() || $("customerEmailAddress").value.indexOf("@") == -1 || $("customerEmailAddress").value.indexOf(".") == -1 ) {
					ACMEBlinds.HAL( "customerEmailAddress" );
					return false;
				}
				if( $("customerPassword").value.blank() ) {
					ACMEBlinds.HAL( "customerPassword" );
					return false;
				}
				if( $("customerPassword2").value.blank() ) {
					ACMEBlinds.HAL( "customerPassword2" );
					return false;
				}
				if( $("customerPassword").value != $("customerPassword2").value ) {
					alert("Your password and your confirmation password do not match");
					return false;
				}				
				return true;
			}
		},
		Login : {
			Validate:function() {
				if( $("customerEmailAddress").value.blank() || $("customerEmailAddress").value.indexOf("@") == -1 || $("customerEmailAddress").value.indexOf(".") == -1 ) {
					ACMEBlinds.HAL( "customerEmailAddress" );
					return false;
				}
				if( $("customerPassword").value.blank() ) {
					ACMEBlinds.HAL( "customerPassword" );
					return false;
				}
				return true;
			}
		},
		Amnesia : {
			Validate:function() {
				if( $("customerEmailAddress").value.blank() || $("customerEmailAddress").value.indexOf("@") == -1 || $("customerEmailAddress").value.indexOf(".") == -1 ) {
					ACMEBlinds.HAL( "customerEmailAddress" );
					return false;
				}				
				return true;
			}
		}
	},	
	Cart : {
		RemoveItem : {
			Validate:function() {
				var confirmation = confirm("Are you sure you want to remove this item from your shopping cart?");
				if( confirmation ) {
					return true;
				} else {
					return false;
				}
			}
		},
		Empty : {
			Validate:function() {
				var confirmation = confirm("Are you sure you want to empty all items out of your shopping cart?");
				if( confirmation ) {
					return true;
				} else {
					return false;
				}
			}
		}
	},
	Order : {
		Velux : {
			Validate:function() {
				return true;
			},
			UpdatePrice:function(obj) {
				
				if( obj.id == "veluxSizeId" ) {
					var vW = obj.options[ obj.selectedIndex ].getAttribute("vw");
					var vD = obj.options[ obj.selectedIndex ].getAttribute("vd");
					$("veluxWidthDropSpan").update( vW + "mm X " + vD + "mm");
				}
			
				var veluxSizeId = $("veluxSizeId").value;								
				var selectedAddOns = $$(".addOn:checked");
				var addOnIdList = "";
				var cLen = selectedAddOns.length;
				if( cLen ) {
					selectedAddOns.each(
						function(name,index) {
							addOnIdList+=name.value;
							if(index<cLen-1) {
								addOnIdList+=",";
							}
						}
					);		
				}

				var url = "index.cfm?action=Order_Velux_UpdatePrice&pId=" + $("productId").value + "&cId=" + $("colourId").value + "&sId=" + veluxSizeId + "&al=" + escape( addOnIdList );
				new Ajax.Request( url, {asynchronous:true, evalScripts:false, onSuccess:ACMEBlinds.Order.Velux.UpdatePrice_onSuccess, onFailure:errFunc});				
			},
			UpdatePrice_onSuccess:function(t) {
				z = parseJSON( t.responseText );
				if( z.result ) {
					$("price").update( z.price.toFixed(2) );
					ACMEBlinds.Order.TogglePrice(true);				
				} else {
					ACMEBlinds.Order.TogglePrice(false);
					alert( z.message );
				}
			}
		},		
		Confirmation : {
			Validate:function() {
				$('btnCreateOrder').disabled=false;
				if( $("deliveryMethod").value.toUpperCase()=="POST" ) {
					if( $("orderDeliveryTelephone").value.blank() ) {
						alert("Please enter a contact number we can use to contact you on the day of delivery");
						ACMEBlinds.HAL( "orderDeliveryTelephone" );
						return false;
					}
				} else {
				
				}
				$('btnCreateOrder').disabled=true;
				return true;
			}
		},
		Validate:function() {
			if( $("width").value.blank() || !Toolbox.Number.IsInteger( $("width").value ) ) {
				ACMEBlinds.HAL( "width" );
				return false;
			}
			if( $("drop").value.blank() || !Toolbox.Number.IsInteger( $("drop").value ) ) {
				ACMEBlinds.HAL( "drop" );
				return false;
			}
			return true;
		},
		ChangeBlindEnd:function() {
			var blindEndId = $("blindEndId").value;
			$("blindEndImages").select("img").each(
				function(index,name) {
					index.hide();
				}
			);
			$( "blindEnd_" + blindEndId ).show();
		},
		ShowHideFrictionTypes:function(obj) {
			if( obj.checked ) {
				$("frictionTypes").show();
			} else {
				$("frictionTypes").hide();
			}
		},
		UpdatePrice:function(obj) {
			Toolbox.Number.OnlyAllowInteger(obj);
			var drop = $("drop").value;
			var width = $("width").value;
			var blindEndId = 0;
			var selectedAddOns = $$(".addOn:checked");
			var addOnIdList = "";
			var cLen = selectedAddOns.length;
			
			if( $("blindEndId") ) {
				blindEndId = $("blindEndId").value;
			}
			
			if( cLen ) {
				selectedAddOns.each(
					function(name,index) {
						addOnIdList+=name.value;
						if(index<cLen-1) {
							addOnIdList+=",";
						}
					}
				);		
			}
			if( Toolbox.Number.IsInteger( drop ) && Toolbox.Number.IsInteger( width ) ) {
				var url = "index.cfm?action=Order_UpdatePrice&fId=" + $("fabricId").value + "&pId=" + $("productId").value + "&cId=" + $("colourId").value + "&w=" + width + "&d=" + drop + "&al=" + escape( addOnIdList ) + "&be=" + blindEndId;
				new Ajax.Request( url, {asynchronous:true, evalScripts:false, onSuccess:ACMEBlinds.Order.UpdatePrice_onSuccess, onFailure:errFunc});				
			} else {
				ACMEBlinds.Order.TogglePrice(false);
			}
		},
		UpdatePrice_onSuccess:function(t) {
			z = parseJSON( t.responseText );
			/* TODO : Discuss with Leo
			if( z.width && z.drop ) {
				$("width").value = z.width;
				$("drop").value = z.drop;
			}
			*/
			if( z.result ) {
				$("price").update( z.price.toFixed(2) );
				ACMEBlinds.Order.TogglePrice(true);				
			} else {
				ACMEBlinds.Order.TogglePrice(false);
				alert( z.message );
			}
		},
		TogglePrice:function(onOff) {
			if( onOff ) {
				$("priceHolder").show();
				new Effect.Highlight( $("priceHolder") );
			} else {
				$("priceHolder").hide();
			}
		}
	}
}

var Toolbox = {	
	Number : {
		OnlyAllowInteger:function(obj){
			var val = obj.value;
			val=val.replace(/[^-\d]/g,'')
			val=val.replace(/(\d)-/g,'$1')
			obj.value=val;
			obj.focus();
		},
		IsInteger:function(val) {
			var y = parseInt( val ); 
			if( isNaN( y ) ) {
			   return false; 
			} else {
				return true;
			}
		}
	}
}

var Protofade = Class.create({

	initialize: function(element, options) {		
		this.options = {
      		Duration: 1,
			Delay: 4.0,
			Random: false,
			Slideshow:true,
			Controls:false
    	}
		Object.extend(this.options, options || {});

    	this.element        = $(element);
		this.slides			= this.element.childElements();
		this.num_slides		= this.slides.length;		
		this.current_slide 	= (this.options.Random) ? (Math.floor(Math.random()*this.num_slides)) : 0;
		this.end_slide		= this.num_slides - 1;
		
		this.slides.invoke('hide');
		this.slides[this.current_slide].show();
				
		if (this.options.Slideshow) { 
			this.startSlideshow();
		}				
		if (this.options.Controls) {
			this.addControls();
		}		
	},
	
	addControls: function() {
		this.wrapper 		= this.element.up();
		this.controls		= new Element('div', { 'class': 'controls' });
		this.wrapper.insert(this.controls);
		
		this.btn_next 		= new Element('a', { 'class': 'next', 'title': 'Next', href: '#' }).update('Next');
		this.btn_previous	= new Element('a', { 'class': 'previous', 'title': 'Previous', href: '#' }).update('Previous');
		this.btn_start		= new Element('a', { 'class': 'start', 'title': 'Start', href: '#' }).update('Start');
		this.btn_stop		= new Element('a', { 'class': 'stop', 'title': 'Stop', href: '#' }).update('Stop');
		
		this.btns = [this.btn_next, this.btn_previous, this.btn_start, this.btn_stop];
		this.btns.each(function(el){
			this.controls.insert(el);
		}.bind(this));
		
		this.btn_previous.observe('click', this.moveToPrevious.bindAsEventListener(this));
		this.btn_next.observe('click', this.moveToNext.bindAsEventListener(this));
		this.btn_start.observe('click', this.startSlideshow.bindAsEventListener(this));
		this.btn_stop.observe('click', this.stopSlideshow.bindAsEventListener(this));
	},

	startSlideshow: function(event) {
		if (event) { Event.stop(event); }
		if (!this.running)	{
			this.executer = new PeriodicalExecuter(function(){
	  			this.updateSlide(this.current_slide+1);
	 		}.bind(this),this.options.Delay);
			this.running=true;
		}
	},
	
	stopSlideshow: function(event) {	
		if (event) { Event.stop(event); } 
		if (this.executer) { 
			this.executer.stop();
			this.running=false;
		}	 
	},

	moveToPrevious: function (event) {
		if (event) { Event.stop(event); }
		this.stopSlideshow();
  		this.updateSlide(this.current_slide-1);
	},

	moveToNext: function (event) {
		if (event) { Event.stop(event); }
		this.stopSlideshow();
  		this.updateSlide(this.current_slide+1);
	},
	
	updateSlide: function(next_slide) {
		
		if (next_slide > this.end_slide) { 
				next_slide = 0; 
		} 
		else if ( next_slide == -1 ) {
				next_slide = this.end_slide;
		}
		
		this.fadeInOut(next_slide, this.current_slide);		
	},

 	fadeInOut: function (next, current) {		
		this.slides[current].setStyle({"zIndex":1});
		this.slides[next].setStyle({"zIndex":100});
		new Effect.Parallel([
			new Effect.Fade(this.slides[current], { sync: true }),
			new Effect.Appear(this.slides[next], { sync: true }) 
  		], { duration: this.options.Duration });
		
		this.current_slide = next;		
	}

});

var LightboxHolder = {	
	DestroyCreate:function( id , cClass ) {
		if( typeof( cClass ) == "undefined" ) {
			cClass="";
		}
		if( $('boxContents') ) {
			$('boxContents').update("&nbsp;")
		}
		
		if( $( id ) ) {
			$( id ).remove();			
		}
		if( !$( id ) ) {
			Element.extend( document.getElementsByTagName("body")[0] ).insert("<div class='" + cClass + "' id='" + id + "' style='display:none'></div>");
		}
	},
	Close:function( doConfirm ) {
		if( typeof( doConfirm ) == "undefined" ) {
			doConfirm = false;
		}
		if( doConfirm ) {
			var confirmation = confirm("Are you sure you want to cancel?");
			if( confirmation ) {
				Element.hide('box');
				Element.hide('dcoverlay');
			}
		} else {
			Element.hide('box');
			Element.hide('dcoverlay');
		}
	},
	RemoveAndClose:function(id) {
		if( $('boxContents') ) {
			$('boxContents').update("&nbsp;")
		}
		
		if( $( id ) ) {
			$( id ).remove();			
		}
		
		Element.hide('box');
		Element.hide('dcoverlay');
		
	}
}

String.prototype.isEmail = function () { 
	var rx = new RegExp("\\w+([-+.\’]\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*"); 
	var matches = rx.exec(this); 
	return (matches != null && this == matches[0]); 
}

function isNumeric(x) { 
	var y=parseInt(x); 
	if (isNaN(y)) {
	   return false; 
	} else {
		return true;
	}
} 

function LoadingAjax(txt) {
	if(typeof(txt)=="undefined") {
		txt = "Loading...";
	}
	return "<div class='ajaxMsg' id='widgetAjaxMsg'> "+txt+"</div>";
}

function parseJSON( json ){
	var o = eval('(' + json + ')');
	if( o.redirectURL )
	{
		document.location = o.redirectURL;
		return;
	}
	if( $("message") != null ) new Element.remove( "message" );
	if( o.errMsg )
	{
		if( o.errMsgTitle == null ) o.errMsgTitle = "Error";
		if( o.errMsgTimer == null ) o.errMsgTimer = 5000;
		tw.ShowMessage( o.errMsgTitle, o.errMsg, "error", o.errMsgTimer, o.errMsgPosition );
		return o;
	}
	if( o.msgTitle || o.msg )
	{
		if( o.msgTimer == null ) o.msgTimer = 5000;
		tw.ShowMessage( o.msgTitle, o.msg, o.msgClass, o.msgTimer, o.msgPosition );
	}
	return o;
}

var errFunc = function(t) {
	var win = window.open("", "win", "width=1024,height=700,resizable=yes,scrollbars=yes,status=no"); // a window object
	win.document.open("text/html", "replace");
	win.document.write( "<html><body style='margin:0'><div style='border-bottom:1px solid #222;background:#666;padding:10px;'><h1 style='color:#FFF;margin:0;padding:0;'>Digital Crew Ajax Error</h1></div><div style='padding:10px;'>"+t.responseText.replace(/^\s+|\s+$/, '') + "</div></body></html>" );
	win.document.close();
	win.focus();
}



