	//Edge impact javascript library - using mootools 1.11
	var load_method = (window.ie ? 'load' : 'domready');
	
	function getRequest(varUrl,varParam ) {
		// Get variable from XHR /Json
		var response = null;
		var xhr = new XHR({
			method: 'get',
			async: false
		}).send(varUrl,varParam);
		if(xhr.transport.responseText){
			return Json.evaluate(response || xhr.transport.responseText)
		}else{
			return false;	
		};
	}

	function toggle(obj,val){
		if(val){
			$(obj).setStyles({'display':'none'})
		}else{
			$(obj).setStyles({'display':'block'})
		}
	}
	
	function $F(element){ //implementation for mootools - equivalent to prototype js.
		element = $(element);
		switch (element.type.toLowerCase()) {
			case 'checkbox':
			case 'radio':
				var group = $(element);
				if (group.length>0){
					for(x=0;x<group.length;x++){
						if(group[x].checked){return true};
					}
				}else{
					if(group.checked){return true};
				}
			break;
			default:
				return element.value;
		}
	}
	
	Element.extend(
	{
		enable:function(element){
			this.disabled='';
			this.setStyle('display','block');
		},
		disable:function(element){
			this.disabled='disabled';
			this.setStyle('display','none')
		},
		
		hide: function() 
		{
			(function(){
				if(this.getProperty('tohide')=='yes'){
					return this.setStyle('opacity',0);
				}
			}.bind(this).delay(1500))
			return true
		},
		
		show: function(el) 
		{
			if(this.getStyle('opacity')!=1){
				return this.effect('opacity', {duration: 500}).start(0,1)
			}
		},
		
		wraps: function(el, where){
			el = $(el, true);
			return this.replaces(el).grab(el);
		},
		replaces: function(el){
			el = $(el, true);
			el.parentNode.replaceChild(this, el);
			return this;
		},
		grab: function(el, where){
			Element.Inserters.get(where || 'bottom')($(el, true), this);
			return this;
		}
	});
	
	var EiJsDropdown = new Class({
		options: {
			id: 'eidropdown'
		},
		initialize: function(options) {
			$ES('div[eimenuchild^=]').each(function(element){
				var temp=element.getProperty('eimenuchild');
				if(temp){
					var type=temp.split(',')[1];
					this.apply_menu(element,type);//type - horizontal, vertical
				}
			}.bind(this))
		},
		apply_menu: function(e,eitype){
			var propname = e.getProperty('eimenuchild').split(",")[0];
			e.setStyle('opacity',0)
			$(propname).addEvent('mouseover',function(){
				e.setProperty('tohide','');
				e.show();
				pos = $(e).getPosition();
				if($(propname)){
					var pos = $(propname).getPosition();
					var size = $(propname).getSize()
					if(eitype=='h'){
						e.setStyle('left',pos.x);
						e.setStyle('top',pos.y+size.size.y);
					}else{
						e.setStyle('left',pos.x+size.size.x);
						e.setStyle('top',pos.y);
					}
				}
				var temp;
				var __size=$(e).getSize().size;
				temp = $(e).getPosition();
			}.bind(this))
			
			$(propname).addEvent('mouseout',function(){
				if($(e).getProperty('tohide')=='yes'){
					$(e).hide();
					$(e).setProperty('tohide','');
				}
			}.bind(this))
	
			e.addEvent('mouseover',function(){
				e.setProperty('tohide','');
			}.bind(this))
	
			e.addEvent('mouseout',function(){
				//console.log('mouseo11ut');
				(e).setProperty('tohide','yes');
				$(e).hide();
			}.bind(this))
			
		}.bind(this)
	}) 
	
	EiJsDropdown.implement(new Options);
	EiJsDropdown.implement(new Events);
	
	window.addEvent('load',function(){
		var x = new EiJsDropdown();
	})
	
	function popup(url){
		newwindow=window.open(url,'name','width=800,height=600,toolbar=no,scrollbars=yes,resizable=yes,menubar=no,location=no');
		newwindow.moveTo(200,100);
		if (window.focus) {newwindow.focus()}
		return false;
	}
	function stripHTMLreg(oldString) {
		return oldString.replace(/<&#91;^>&#93;*>/g, "");
	}
	function stripHTML(oldString) {
	   var newString = "";
	   var inTag = false;
	   for(var i = 0; i < oldString.length; i++) {
			if(oldString.charAt(i) == '<') inTag = true;
			if(oldString.charAt(i) == '>') {
				  inTag = false;
				  i++;
			}
			if(!inTag) newString += oldString.charAt(i);
	   }
	   return newString;
	}
	
	function LTrim( value ) {
		var re = /\s*((\S+\s*)*)/;
		return value.replace(re, "$1");
	}
	
	// Removes ending whitespaces
	function RTrim( value ) {
		var re = /((\s*\S+)*)\s*/;
		return value.replace(re, "$1");
	}
	
	// Removes leading and ending whitespaces
	function trim( value ) {
		return LTrim(RTrim(value));
	}
	
	var EiJsValidate = new Class({
		options: {
			styleMsgPrefix: 'msg',
			validateForm:true
		},
		global_message:null,
		first_not_valid:null,
		initialize: function(form, options) {
			this.setOptions(options);
			this.form = $(form)||$('form1');
			if($(this.form)){
				$(form).addEvent('submit',function(e){
					e = new Event(e)
					if(this.options.validateForm&&!this.validate_all()){e.stop();}
				}.bind(this))
			}
			
			$ES('select,textarea,input[eivalidation^=]',this.form).each(
			function(element){
				if(element.getProperty('eivalidation')){
					element.addEvent('blur',function(e){
						this.validate_element(element);
					}.bind(this))
					element.addEvent('change',function(e){
						//this.validate_element(element);
					}.bind(this))
				}
			}.bind(this))
		},
		validate_all:function(){
			this.global_message = '';
			this.exists=false;
			var mmm=false;
			this.first_not_valid = null;
			$ES('input,select,textarea',this.form).each(
			function(element){
				if(element.getProperty('eivalidation')){
					mmm = this.validate_element(element,true);
					if(mmm){
						this.exists=true;
						if(!this.first_not_valid){
							this.first_not_valid=element;
						}
					}
				}
			}.bind(this))
			if(this.exists){
				if(this.first_not_valid.type!='hidden'){
					this.first_not_valid.focus()
				}
			}
			
			return !this.exists;// not submitting a form
		},
		//validateElement:function(element,type){
//			return validate_element(element,type);
//		},
		validate_element:function(element,type){
			//alert(element.id)
			var own_fieldname=element.name.replace(/_/g," ");
			var own_message = null;
			var validate = true;
			var the_same_string;
			var do_not_validate;
			var message = '';
			var not_the_same_string;
			var or_string;
			var ajax_string;
			var max_length_string;
			element.getProperty('eivalidation').split(';').each(function(a){
				var param = a.split(':')
				switch(param[0]){
					case 'FieldName':	
						own_fieldname = param[1];
					break;
					case 'ErrMsg':	
						own_message = param[1];
					break;
					case 'IfOn':
						if (!this.val($(param[1]))){do_not_validate="Yes"}
					break;
					case 'HTML':
						if ((param[1])=='nostrip'){do_not_strip="Yes"}
					break;
					case 'Trim':
						if ((param[1])=='notrim'){do_not_trim="Yes"}
					break;
				}
			}.bind(this))
			if(do_not_validate!="Yes"&&own_fieldname){
			element.getProperty('eivalidation').split(';').each(function(a){
					var param = a.split(':')
					var subparam=null;
					switch(param[0]){
						case 'EiTheSameAs':	
							not_the_same_string = param[1]
							if (not_the_same_string&&type){ 
								not_the_same_string.split(',').each(function(elements){
									if($(elements).value!=element.value){
										message+='<BR>'+own_fieldname+" must be the same as " + $(elements).name;
									}
								})
							}
							break;
						case 'EiNotTheSameAs':	
							not_the_same_string = param[1]
							if (not_the_same_string&&type){ 
								not_the_same_string.split(',').each(function(elements){
									if(this.val($(elements))==this.val($(element))){
										message+='<BR>'+own_fieldname+" can't be the same as " + $(elements).name;
									}
								})
							}
							break;
						case 'EiOr':	
							or_string = param[1]
							if (or_string&&type){ 
								var exists = false;
								var message_string = $(element).getAttribute('name') + ", " + or_string;
								or_string.split(',').each(function(elements){
									//alert($(elements).id);
									if(this.val($(elements))!=''){
										exists = true;	
									}
								}.bind(this))
								if(this.val($(element))&&this.val($(element))!=''){
										exists = true;	
								}
								if (!exists){
									message+='<BR>Enter one of: ' + message_string.replace(/_/g," ").replace(/,/g,", ")
								}
							}
							break;
						case 'EiAnd':	
							or_string = param[1]
							if (or_string&&type){ 
								//alert('orstring');
								var exists = false;
								var at_least_one=false;
								//alert(element.id)
								var message_string = $(element).getAttribute('name') + ", " + or_string;
								or_string.split(',').each(function(elements){
									
									if(this.val($(elements))+'#'=='#'){
										exists = true;	
									}else{
										at_least_one = true;
									}
								}.bind(this))
								
								if(this.val($(element))+'#'=='#'){
										exists = true;	
								}else{
									at_least_one = true;	
								}
								if (exists&&at_least_one){
									message+='<BR>Enter all of: ' + message_string.replace(/_/g," ").replace(/,/g,", ")
								}
							}
							break;
						case 'EiAjaxExists':	
							ajax_string = param[1];
							
							if (ajax_string&&$(element).value!=''){
								var data = new Date();
								data = data.getMinutes() +'' +data.getSeconds()
								var url = EiWorkbench_path + 'Ajax/ajax_exists.asp';
								var pars = "t=" + ajax_string + "&s=" + $(element).value+'&da='+data;
								
								aj_response = getRequest(url,pars);
								var x=$(element).getAttribute('eiajaxexistsparam');
								if(x){
									var y=x.replace(/.asp/g,"");
									
								}
								if(aj_response&&x!=$(element).value&&y!=$(element).value){
									message+='<BR>'+own_fieldname+ " already exists. Please enter another one.";
								}
							}
							
							break;
						case 'maxlength':	
							max_length_string = param[1]
							if(element.tagName.toUpperCase() == "TEXTAREA") {
								if (max_length_string){ 
									if($(element).value.length >= $(element).getAttribute('maxlength')){
										message+='<BR>'+own_fieldname+ "can't have more characters then " + $(element).getAttribute('maxlength')
									}
								}
							}
							break;
						case 'Validate':	
							validation_string = param[1]
							if(validation_string){
								var validation_array = validation_string.split(',');
								var reg_expr = '';
								validation_array.each(function(b){
									switch(b){
										case "required":
												//alert(element.id+':'+this.val(element));
												if ((!$(element).value||(this.val(element)==''||this.val(element)==false||this.val(element)==null))&&$(element).value!='0'){
													message+='<BR>'+own_fieldname+ " is required";
													//EiJsValidate.addReqError(element); // Add required error to the stack											
												}
											break;
											case "date_time":
												date_time_validation = KgDateTimeValidate($(element),'Time')
												if (date_time_validation!=''){
													message+='<BR>'+own_fieldname + " " +date_time_validation;
												}
											break;
											case "date_notime":
												date_time_validation = KgDateTimeValidate($(element),'NoTime');
												if (date_time_validation!=''){
													message+='<BR>'+own_fieldname + " " +date_time_validation;
												}
											break;
											case "positive":
												if (this.val(element)<0){
													message+='<BR>'+own_fieldname+ " must be positive number.";
													//EiJsValidate.addReqError(element); // Add required error to the stack
												}
											break;
											case "negative":
												if (this.val(element)>=0){
													message+='<BR>'+own_fieldname+ " must be negative number.";
													//EiJsValidate.addReqError(element); // Add required error to the stack
												}
											break;
											case "currency":
												//message+=own_fieldname+ " must be currency.";
												if($(element).value!=''&&!/^[0-9]{1,3}(?:,?[0-9]{3})*(?:\.[0-9]{2})?$/.test($(element).value)){
													message+='<BR>'+own_fieldname+ " must be a currency value.";
												}
											break;
											case "filename":
												//message+=own_fieldname+ " must be currency.";
												if($(element).value!=''&&!(/\S+\.\S+/).test($(element).value)){
													message+='<BR>'+own_fieldname+ " must be a valid filename.";
												}
											break;
											case "only-letters":
												//message+=own_fieldname+ " is required";
												if($(element).value!=''&&!/^[a-zA-Z\s]+$/.test($(element).value)){
													message+='<BR>'+own_fieldname+ " must be an alphabetic value.";
												}
											break;
											case "number":
												if($(element).value!=''&&!/^([-]|[0-9])[0-9]*$/.test($(element).value)){
													message+='<BR>'+own_fieldname+ " must be an integer/whole number.";
												}
											break;
											case "email":
												if($(element).value!=''&&!/\w{1,}[@][\w\-]{1,}([.]([\w\-]{1,})){1,3}$/.test($(element).value)){
													message+='<BR>'+own_fieldname+ " must be a valid email address.";
												}
											break;
											case "alpha-numeric":
												if($(element).value!=''&&!/^[\w\s]+$/.test($(element).value)){
													message+='<BR>'+own_fieldname+ " must be an alphanumeric value.";
												}
											break;
											case "uk-postcode":
												if($(element).value!=''&&!/^((([A-PR-UWYZ](\d([A-HJKSTUW]|\d)?|[A-HK-Y]\d([ABEHMNPRVWXY]|\d)?))\s*(\d[ABD-HJLNP-UW-Z]{2})?)|GIR\s*0AA)$/.test($(element).value)){
													message+='<BR>'+own_fieldname+ " must be a UK Postcode.";
												}
											break;
											case "rar-file":
												if($(element).value!=''&&!/^\.([rR]([aA][rR]|\d{2})|(\d{3})?)$/.test($(element).value)){
													message+='<BR>'+own_fieldname+ " must be the rar file.";
												}
											break;
											case "uk-nin":
											if($(element).value!=''&&!/^[A-CEGHJ-PR-TW-Z]{1}[A-CEGHJ-NPR-TW-Z]{1}[0-9]{6}[A-DFM]{0,1}$/.test($(element).value)){
												message+='<BR>'+own_fieldname+ " must be a UK National Insurance Number.";
											}
											break;
											case "uk-telephone":
												if($(element).value!=''&&!/(\s*\(?0\d{4}\)?\s*\d{6}\s*)|(\s*\(?0\d{3}\)?\s*\d{3}\s*\d{4}\s*)/.test($(element).value)){
													message+='<BR>'+own_fieldname+ " must be a UK Telephone number.";
												}
											break;
											case "uk-mobile":
												if($(element).value!=''&&!/^07([\d]{3})[(\D\s)]?[\d]{3}[(\D\s)]?[\d]{3}$/.test($(element).value)){
													message+='<BR>'+own_fieldname+ " must be a UK Mobile number.";
												}
											break;
											case "uk-driver":
												if($(element).value!=''&&!/[A-Z0-9]{5}\d[0156]\d([0][1-9]|[12]\d|3[01])\d[A-Z0-9]{3}[A-Z]{2}/.test($(element).value)){
													message+='<BR>'+own_fieldname+ " must be a UK Driver License number.";
												}
											break;
											case "strongish-password":
												if($(element).value!=''&&!/^[a-zA-Z]\w{3,14}$/.test($(element).value)){
													message+='<BR>'+own_fieldname+ " must be a strongish Password.";
												}
											break;
											case "float":
												if($(element).value!=''&&!/^[-+]?\d*\.?\d*$/.test($(element).value)){
													message+='<BR>'+own_fieldname+ " must be a number.";
												}
											break;
											case "mm_dd_yyyy": //    m/d/y and mm/dd/yyyy
												if($(element).value!=''&&!/^(0?[1-9]|1[012])[/](0?[1-9]|[12][0-9]|3[01])[/](19|20|21|22|23|24|25|26|27|28|29|30|31)?[0-9]{2}\b/.test($(element).value)){
													message+='<BR>'+own_fieldname+ " must be a date in format (mm/dd/yyyy or m/d/y).";
												}
											break;
											case "uk-debits":
												if($(element).value!=''&&!/(^(5[0678])\d{11,18}$)|(^(6[^05])\d{11,18}$)|(^(601)[^1]\d{9,16}$)|(^(6011)\d{9,11}$)|(^(6011)\d{13,16}$)|(^(65)\d{11,13}$)|(^(65)\d{15,18}$)|(^(49030)[2-9](\d{10}$|\d{12,13}$))|(^(49033)[5-9](\d{10}$|\d{12,13}$))|(^(49110)[1-2](\d{10}$|\d{12,13}$))|(^(49117)[4-9](\d{10}$|\d{12,13}$))|(^(49118)[0-2](\d{10}$|\d{12,13}$))|(^(4936)(\d{12}$|\d{14,15}$))/.test($(element).value)){
													message+='<BR>'+own_fieldname+ " must be a number.";
												}
											 // Matches any of Solo, Switch or Maestro. International safe. Will not match on Discover, Visa or Mastercard. For example; Most recommendations for matching Visa are that they start with "4". If outside the US, this are incomplete on will falsly ID most Switch cards as Visa.
											break;
											case "security":
												if ($(element).value!=''){
													var data = new Date();
													data = data.getMinutes() +'' +data.getSeconds()
													var url = EiWorkbench_path + 'Ajax/ajax_seccode.asp';
													var pars = "s=" + $(element).value+'&da='+data;
													aj_response = getRequest(url,pars);
													if(aj_response){
														message+='<BR>security code doesn\'t match.';
													}
												}
											break;
									}
								}.bind(this))
							}
						break;
					}
				}.bind(this))
				this.mess(element,message);
				//alert(message)
				return message;
			}
		},
		val:function(element){ //gets value from element - changed for checkbox and radio
			element=$(element);
			if(element){
				if(element.type){
					switch (element.type.toLowerCase()) {
						case 'checkbox':
							var group = this.form[element.getProperty("name")];
							if (group.length>0){
								for(x=0;x<group.length;x++){
									if(group[x].checked){return true};
								}
							}else{
								if(group.checked){return true};
							}
						break;
						case 'radio':
							var group = this.form[element.getProperty("name")];
							if (group.length>0){
								for(x=0;x<group.length;x++){
									if(group[x].checked){return true};
								}
							}else{
								if(group.checked){return true};
							}
						break;
						default:
							return element.value;
					}
				}else{
					if(element.value){return element.value}
				}
			}else{
				return false;	
			}
		},
		mess:function(owner,message,options){
			var el = $(this.options.styleMsgPrefix+owner.id);
			message = message.replace('<BR>','')
			if(!el&&message){
				var el = new Element('span',{'id':this.options.styleMsgPrefix+owner.id,'class':'err_msg'}).setStyle("opacity", 0).setHTML(message).injectAfter(owner);
				el.effect("opacity", {
					duration: 500,
					transition: Fx.Transitions.linear
				}).start(0, 1);
			}else{
				if(el&&message!=el.getText()){
					el.effect("opacity", {
					duration: 500,
					transition: Fx.Transitions.linear,
					onComplete: function() {
						options = this.options
						if(el){
							try{el.remove()}
							catch(e){}
						};
						if(message){
							var xcd = new Element('span',{'id':this.options.styleMsgPrefix+owner.id,'class':'err_msg'}).setStyle("opacity", 0).setHTML(message).injectAfter(owner);
							xcd.effect("opacity", {
								duration: 500,
								transition: Fx.Transitions.linear
							}).start(0, 1);
						}
					}.bind(this)}).start(1, 0);
				}
			}
		}
	})
	EiJsValidate.implement(new Events);
	EiJsValidate.implement(new Options);
