
	var Axon = Class.create( {
		initialize: function() {
		}
	});

	var AxonJobTitleSelector 		= Class.create();
	AxonJobTitleSelector.prototype	= {
	
		options				: {
			minChars		: 2,
			enableCustom	: true,
			limit			: 30
		}, 
		initialize: function( el, options ) {
			Object.extend( this.options, options || {} );		
			return new IDGAutoComplete( el, '/modules/axon/callback.php?op=jobtitle', this.options );
		}
	}

	var AxonCompanySelector 		= Class.create();
	AxonCompanySelector.prototype	= {
	
		options				: {
			minChars		: 2,
			onSelect: function( item ) {
			
				if( $('zip') )
					$('zip').value		= item.zip;
				
				if( $('postal') )
					$('postal').value	= item.zip;
				
				$('city').value		= item.city;
				$('address').value	= item.address;
				$('phone').value	= item.phone;
				$('employees').value	= item.employees;
				
				return;
			}.bind(this)
		}, 
	
		initialize: function( el, options ) {
			Object.extend( this.options, options || {} );
			return new IDGAutoComplete( el, '/modules/axon/callback.php?op=company', this.options );
		}
	}

	var AxonFetchBC 		= Class.create();
	AxonFetchBC.prototype	= {
	
		options				: {
			email			: '',
			key				: '',
			onFetch: function() { }
		}, 
	
		initialize: function( options ) {
			
			Object.extend( this.options, options || {} );
			
			new Ajax.Request( '/modules/axon/callback.php?op=fetchbc', {
				method		: 'POST',
				postBody	: 'email=' + this.options.email + '&key=' + this.options.key,
				onSuccess: function( t, json ) {
					this.options.onFetch( json );
				}.bind(this)
			});
		}
	}
	
	var AxonFillBC			= Class.create();	
	AxonFillBC.prototype	= {

		el_items				: ['name','email','company', 'employeeid', 'phone', 'address', 'zip', 'city', 'countryid', 'businessid', 'jobtitleid', 'jobtitle'], 
		options					: {
			el_name				: 'name',
			el_email			: 'email',
			el_company			: 'company',
			el_employeeid		: 'employees',
			el_phone			: 'phone',
			el_address			: 'address',
			el_zip				: 'postal',
			el_city				: 'city',
			el_countryid		: 'country',
			el_businessid		: 'business',
			el_jobtitle			: 'title',
			el_jobtitleid		: 'title_id',				
			overwriteNonEmpty	: true
		},

		getUrlParm: function( name ) {
			name			= name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
			var results		= new RegExp( '[\\?&]' + name + '=([^&#]*)' ).exec( window.location.href ); // credit: http://www.netlobo.com/url_query_string_javascript.html
			return unescape( ( results && results[1] ) || '' );
		},
		
		initialize: function( options ) {
			new AxonFetchBC( { email: this.getUrlParm('email'), key: this.getUrlParm('key'), onFetch: this.onFetch.bind(this) } );
			Object.extend( this.options, options || {} );
		},
		
		onFetch: function( item ) {
			
			if( item.found ) {
				
				if( $( this.options.el_name ) && ( $F( this.options.el_name ) == '' || this.options.overwriteNonEmpty ) )
					$( this.options.el_name ).value		= item.name;
				
				if( $( this.options.el_email ) && ( $F( this.options.el_email ) == '' || this.options.overwriteNonEmpty ) )
					$( this.options.el_email ).value	= item.email;

				if( $( this.options.el_company ) && ( $F( this.options.el_company ) == '' || this.options.overwriteNonEmpty ) )
					$( this.options.el_company ).value	= item.company;
				
				if( $( this.options.el_phone ) && ( $F( this.options.el_phone ) == '' || this.options.overwriteNonEmpty ) )
					$( this.options.el_phone ).value		= item.phone;

				if( $( this.options.el_address ) && ( $F( this.options.el_address ) == '' || this.options.overwriteNonEmpty ) )
					$( this.options.el_address ).value		= item.address;
				
				if( $( this.options.el_zip ) && ( $F( this.options.el_zip ) == '' || this.options.overwriteNonEmpty ) )
					$( this.options.el_zip ).value		= item.zip;

				if( $( this.options.el_city ) && ( $F( this.options.el_city ) == '' || this.options.overwriteNonEmpty ) )
					$( this.options.el_city ).value		= item.city;

				if( $( this.options.el_employeeid ) && ( parseInt( $F( this.options.el_employeeid ) ) <= 0 || this.options.overwriteNonEmpty ) )
					$( this.options.el_employeeid ).value	= item.employeeid;
				
				if( $( this.options.el_businessid ) && ( parseInt( $F( this.options.el_businessid ) ) <= 0 || this.options.overwriteNonEmpty ) )
					$( this.options.el_businessid ).value		= item.businessid;

				if( $( this.options.el_jobtitle ) && ( $F( this.options.el_jobtitle ) == '' || this.options.overwriteNonEmpty ) )
					$( this.options.el_jobtitle ).value		= item.jobtitle;
				
				if( $( this.options.el_jobtitleid ) && ( parseInt( $F( this.options.el_jobtitleid ) ) <= 0 || this.options.overwriteNonEmpty ) )
					$( this.options.el_jobtitleid ).value		= item.jobtitleid;
				
				if( $( this.options.el_countryid )  )
					$( this.options.el_countryid ).value		= item.countryid;
			}
		}
	}
	
	
/*	
	
function hideSearchframe(){ // Fordi at IE cracher når man laver display = block på searchframe nogen gange, "gemmes" searchframe ved at man bare flytter den væk fra billedet.
	$('searchFrame').style.display = 'none'
	//$('searchFrame').style.top = "-2000px";
}

function updateHidden(txt, li)
{
    hiddenName = 'axon_' + txt.name + '_id';
    id = li.id.replace("auto_","");
    //txt.form[hiddenName].value = id;
    $(hiddenName).value = id;
}

function updateHiddenJobtitle(txt, li)
{
	
    hiddenName = 'axon_' + txt.name + '_id';
    id = li.id.replace("auto_","");
    $(hiddenName).value = id;
    
    $('chosentitle').value = $(txt.name).value;
    
    if(id == -1){
    	$('axon_' + txt.name + '_othertr').className = "";
    	$('axon_' + txt.name + '_other').focus();
    }
    else {
    	$('axon_' + txt.name + '_othertr').className = "hiddenTR"; // Work around to make IE capable of showing the TR instead of using display: table-row
    	$('axon_' + txt.name + '_othertr').value = "";

    	if($('business').type == "select-one"){
    		$('business').focus();
    	}
    	else {
    		if($('name')){
    			$('name').focus();
    		}
    	}
	    
    }
    $('searchFrame').style.display = 'none';
    //hideSearchframe();
    
    
    
    
}

function updateHiddenCompany(txt, li)
{
	updateHidden(txt,li); // update the hidden
	id = li.id.replace("auto_","");
	postBody = 'cid='+id;
    var opt = {
		method: 'post',
		postBody: postBody,
		onSuccess: function(t,json) {
			response_status			= parseInt(t.getResponseHeader('status'));
			if(response_status == 200){
				
				var data = (eval(json));
				
				if($('phone').value == "" || $('address').value == "" || $('postal').value == "" || $('city').value == ""){ 
					if(data["company_phone"]){
						$('phone').value = data["company_phone"];
					}
					$('address').value = data["company_address"];
					$('postal').value = data["company_postal"];
					$('city').value = data["company_city"];
				}
			} 
			
	         
		}		
	}
	new Ajax.Request( '/modules/axon/response.php?type=companybyid' , opt);
}

var axonHandler	= Class.create();
	axonHandler.prototype = {
		options: {
			
		},
		
		initialize:function( options ) {
			this.options = Object.extend( this.options, options || {});
		},
		
		getCompanyList: function( inputID ) {
			try {
				if( !inputID ) {
					inputID = 'axon_company';
				}
				
				if( !$(inputID) ) { 
						throw('Can\'t find id: \'' + inputID + '\' or axon_company');
						return false;
					}
				
				if( $( inputID ).type != "text" ){
					throw('Form element must be type=\'text\': \'' + inputID + '\'');
				}
				
				// Build div for results
				var choices	= Builder.node('div', { className: 'cord_autocomplete', style:'' });
				$(inputID).parentNode.insertBefore(choices,$(inputID));
				
				
									
				// Make hidden input to store the selected value in									
				var hidden	= Builder.node('input', { type:'hidden', id:'axon_'+inputID+'_id',name:'axon_'+inputID+'_id', style:'' });
				$(inputID).parentNode.insertBefore(hidden,$(inputID));
													
				new Ajax.Autocompleter(inputID, choices, "/modules/axon/response.php?type=companylist", {
				  paramName: "search", 
				  minChars: 2,
				  afterUpdateElement: updateHiddenCompany 
				  
				});
			} catch( e ) {
				alert('Der opstod en fejl:\n\n' + e);
			}
			
				
			
		},
		
		getBusinessList: function( inputID ) {
			try {
				if( !inputID ) {
					inputID = 'axon_business';
				}
				
				if( !$(inputID) ) { 
						throw('Can\'t find id: \'' + inputID + '\' or axon_business');
						return false;
					}
				
				if( $( inputID ).type != "text" ){
					throw('Form element must be type=\'text\': \'' + inputID + '\'');
				}
				
				var choices	= Builder.node('div', { className: 'cord_autocomplete', style:'' });
				$(inputID).parentNode.insertBefore(choices,$(inputID));


				// Make hidden input to store the selected value in									
				var hidden	= Builder.node('input', { type:'hidden', id:'axon_'+inputID+'_id',name:'axon_'+inputID+'_id', style:'' });
				$(inputID).parentNode.insertBefore(hidden,$(inputID));
													
				new Ajax.Autocompleter(inputID, choices, "/modules/axon/response.php?type=businesslist", {
				  paramName: "search", 
				  minChars: 2,
				  afterUpdateElement: updateHidden 
				  
				});
			} catch( e ) {
				alert('Der opstod en fejl:\n\n' + e);
			}
			
				
			
		},
		
		
		
		getJobtitleList: function( inputID ) {
			
			try {
				if( !inputID ) {
					inputID = 'axon_jobtitle';
				}
				
				if( !$(inputID) ) { 
						throw('Can\'t find id: \'' + inputID + '\' or axon_jobtitle');
						return false;
					}
				
				if( $( inputID ).type != "text" ){
					throw('Form element must be type=\'text\': \'' + inputID + '\'');
				}
				
				// Build div for results
				var choices	= Builder.node('div', { className: 'cord_autocomplete', style:'' });
				$(inputID).parentNode.insertBefore(choices,$(inputID));
									
				// Make hidden input to store the selected value in									
				var hidden	= Builder.node('input', { type:'ahidden', id:'axon_'+inputID+'_id',name:'axon_'+inputID+'_id', style:'' });
				$(inputID).parentNode.insertBefore(hidden,$(inputID));
				
													
				new Ajax.Autocompleter(inputID, choices, "/modules/axon/response.php?type=jobtitlelist", {
				  paramName: "search", 
				  minChars: 2,
				  afterUpdateElement: updateHiddenJobtitle
				  
				});
			} catch( e ) {
				alert('Der opstod en fejl:\n\n' + e);
			}
			
				
			
		},
		
		showJobtitleSearch: function( inputID ) {
			
			try {
				if( !inputID ) {
					inputID = 'axon_jobtitle';
				}
				
				if( !$(inputID) ) { 
						throw('Can\'t find id: \'' + inputID + '\' or axon_jobtitle');
						return false;
					}
				
				if( $( inputID ).type != "text" ){
					throw('Form element must be type=\'text\': \'' + inputID + '\'');
				}
				var isNew = true;
				var jobtitleSearch = $( inputID );
				if($('searchFrame')){
					var searchFrame = $('searchFrame');
					//alert("2b");
					isNew = false;
					//searchFrame.style.top = 110+"px";
					$('searchFrame').style.display = 'block';
					//$('searchFrame').style.display = 'none';
					//alert("2c");
					//$('searchFrame').setStyle({display: 'block'});
					//alert("2x");
					//$('searchFrame').style.display = 'block';
					//alert("2d");
				}
				else {
					var searchFrame	= Builder.node('div', { id: 'searchFrame', className: 'cord_searchFrame' });
					var helptext	= Builder.node('div', { id: 'searchFrameHelpText', className: 'cord_searchFrameHelpText' });
					helptext.innerHTML = 'Skriv i feltet for at søge i vores jobtitler<br/><b>Søg</b>:';
					searchFrame.appendChild(helptext);
					$(inputID).parentNode.insertBefore(searchFrame,$(inputID));
					
					searchFrame.appendChild(jobtitleSearch);
					
				}
				
				jobtitleSearch.style.display = "block";
				$( inputID ).focus();
				var offset = Position.cumulativeOffset($('chosentitle'));
				searchFrame.style.left = offset[0]+"px";
				searchFrame.style.top = offset[1]-31+"px";
				
				
				if(isNew){
					// Build div for results
					
					var choices	= Builder.node('div', { id:'choices',className: 'cord_autocomplete', style:'' });
					$(inputID).parentNode.insertBefore(choices,$(inputID));
										
					// Make hidden input to store the selected value in									
					var hidden	= Builder.node('input', { type:'hidden', id:'axon_'+inputID+'_id',name:'axon_'+inputID+'_id', style:'' });
					if($('title_preselected')){
						hidden.value = $('title_preselected').value;
					}
					
					$(inputID).parentNode.insertBefore(hidden,$(inputID));
					
					var tr = Builder.node('tr', { id:'axon_'+inputID+'_othertr',name:'axon_'+inputID+'_othertr' });
					tr.className = "hiddenTR"; // Set style after object reation because IE can't handle inline style in the creation
					var td1 = Builder.node('td', { id:'axon_'+inputID+'_othertd1',name:'axon_'+inputID+'_othertd1' });
					td1.className = "head";
					td1.innerHTML = "Skriv jobtitel";
					var td2 = Builder.node('td', { id:'axon_'+inputID+'_othertd2',name:'axon_'+inputID+'_othertd2' });
					td2.className = "even";
					var other	= Builder.node('input', { type:'text', id:'axon_'+inputID+'_other',name:'axon_'+inputID+'_other' });
					td2.appendChild(other);					
					//var othertext = Builder.node('div', { id:'axon_'+inputID+'_othertext',name:'axon_'+inputID+'_othertext', style:'width:240px;' });
					//othertext.innerHTML = "Skriv jobtitel: ";
					
					//otherdiv.appendChild(othertext);
					tr.appendChild(td1);
					tr.appendChild(td2);
					
					// Put <tr> in before business <tr>
					$('business').parentNode.parentNode.parentNode.insertBefore(tr,$('business').parentNode.parentNode);
					
					new Ajax.Autocompleter(inputID, choices, "/modules/axon/response.php?type=jobtitlelist", {
						  paramName: "search", 
						  minChars: 1,
						  afterUpdateElement: updateHiddenJobtitle 
						  
						});
				}
				
				

			} catch( e ) {
				alert('Der opstod en fejl:\n\n' + e);
			}
			
				
			
		}
}
	
	*/
	