    isIE = document.all;
	isNN = !document.all && document.getElementById;
	isN4 = document.layers;
	
	String.prototype.trim = function(){ return this.replace( /^\s*|\s*$/g , "" ); }
	
	function centerX( width ){
    	iWidth 	= (!isIE)?window.innerWidth:document.body.clientWidth;     
		return (iWidth/2) - (width/2);
	}
	
	function centerY( height ){
		iHeight = (!isIE)?window.innerHeight:document.body.clientHeight;
		return (iHeight/2) - (height/2);
	}


	function selectCategory( element ){
		
		var _email = "";
		if( document.getElementById( 'email' ) )
			_email = document.getElementById( 'email' ).value;
			
		var _username = "";
		if( document.getElementById( 'username' ) )
			_username = document.getElementById( 'username' ).value;

		dojo.io.bind({
			url: "ajaxproxy.php",
			content: {
				action: "ticketdatastore",
				subject: document.getElementById( 'subject' ).value,
				message: document.getElementById( 'message' ).value,
				email: _email,
				username: _username
			},
			handler:function( type, data, evt ){
				var sel     		 = element.options[element.selectedIndex].value;
				window.location.href = "?select=" + sel;
			},
			method: "POST"
		});
	} 
	
	function changeLanguage( element ){
		sel = element.options[element.selectedIndex].value;
		if( sel.length > 0 )
			window.location.href = "?language=" + sel;
	}
	
	function reminder( e ){
		var x = window.open("reminder.php","reminder","width=360,height=150,top=" + centerX( 360 ) + ",left=" + centerY( 150 ) + ",resizable=no,scrollbars=no,menubar=no,toolbar=no,status=no,location=no" );	
		x.moveTo( screen.width/2 - 180, screen.height/2 - 75 )			
		return false;	
	}
	
	function validate( e ){
		var x = window.open("validate.php","validation","width=360,height=150,top=" + centerX( 360 ) + ",left=" + centerY( 150 ) + ",resizable=no,scrollbars=no,menubar=no,toolbar=no,status=no,location=no" );	
		x.moveTo( screen.width/2 - 180, screen.height/2 - 75 )			
		return false;	
	}
	
	function setOpacity( imageobject, opacity ){
		if( navigator.appName.indexOf( "Netscape" )!= -1 && parseInt ( navigator.appVersion ) >= 5 )
			imageobject.style.MozOpacity = opacity/100;
		else if( navigator.appName.indexOf( "Microsoft" )!= -1  && parseInt( navigator.appVersion ) >= 4 )
			if( imageobject.filters.alpha != null )
				imageobject.filters.alpha.opacity = opacity;
	}
	
	function showDiv( id ){
		if( document.layers )
			document.layers[id].visibility = "show";
   		else 
			document.getElementById(id).style.visibility = "visible";		
	}
	
	function hideDiv( id ){
		if( document.layers ){
   			if( document.layers[id] )
				document.layers[id].visibility = "hide";
   		}
   		else{
   			if( document.getElementById(id) )
				document.getElementById(id).style.visibility	= "hidden";
   		}		
	}
	
	function showPop( str ){
		document.getElementById('invitation').innerHTML = str;
		showDiv( 'invitecard' );
	}
	
	function hidePop(){
   		hideDiv( 'invitecard' );
		return false;
	}
	
	/**
	 * Show the warning box.
	 */
	function showWarning( str ){
		document.getElementById('warningtext').innerHTML = str;
   		if( document.layers ){
			document.layers['warningcard'].top 			= centerY( 300 );
			document.layers['warningcard'].left			= centerX( 550 );
			document.layers['warningcard'].visibility 	= "show";
		}
   		else{
			document.getElementById('warningcard').style.top		= centerY( 300 );
			document.getElementById('warningcard').style.left		= centerX( 550 );
			document.getElementById('warningcard').style.visibility = "visible";
		}
	}
	
	/**
	 * Hide the warning box
	 */
	function hideWarning(){
   		if( document.layers ){
   			if( document.layers['warningcard'] )
				document.layers['warningcard'].visibility = "hide";
   		}
   		else{
   			if( document.getElementById('warningcard') )
				document.getElementById('warningcard').style.visibility	= "hidden";
   		}
		return false;
	}
	
	/**
	 * Search tickets from previous tickets list
	 * -ticketsearchresults
	 */
	function ticketSearch( str ){
		document.getElementById( 'ticketsearchresult' ).innerHTML = str;
		dojo.io.bind({
			url: "ajaxproxy.php",
			content: {
				action: "ticketsearchresults",
				param: document.getElementById( 'ticketsearchparam' ).value
			},
			handler:function( type, data, evt ){
				document.getElementById( 'ticketsearchresult' ).innerHTML = data;
			},
			//mimetype: "text/json"
			mimetype: "text/plain"
		});

		return false;
	}	

	
	/**
	 * Find suggestions during ticket submission stages
	 */
	function suggestionList(){		

		dojo.io.bind({
			url: "ajaxproxy.php",
			content: {
				action: "suggestionlist",
				param: document.getElementById( 'message' ).value
			},
			handler:function( type, data, evt ){
				if( data != 'nochange' ){
					if( data == 'noresult' )
						dojo.widget.byId("suggestions").setContent( "" );
					else{
						dojo.widget.byId("suggestions").setContent( data );
					}
				}				
				setTimeout( "suggestionList()", 4000 );
			},
			method: "POST"
		});	
	}
	
	
	
	
	/**
	 * Toggle vis on a component
	 */
	function toggleVisibility( nr, vis ){

		if( document.layers ){
			document.layers[nr].visibility = (vis)?'show':'hide';
		}
		else if( document.all ){
			document.all[nr].style.visibility = (vis)?'visible':'hidden';
		}
		else if (document.getElementById){
			document.getElementById(nr).style.visibility = (vis)?'visible':'hidden';
		}		
	}
	

	
	/**
	 * Used on profile page to check alternate emails
	 */
	function checkAlternateEmails( str ){
		document.getElementById( 'altemailsubmit' ).disabled = true;
		var count = 1;
		var check = true;		
		while( check ){
			if( document.getElementById( 'email' + count ) != null ){
				if( document.getElementById( 'email' + count ).value.length > 0 )
					document.getElementById( 'warning' + count ).innerHTML = str;
				count++;
			}
			else
				check = false;						
		}
		
		dojo.io.bind({
			url: "ajaxproxy.php",
			content: {
				action: "altemailcheck"
			},
			formNode: document.getElementById( 'altemails' ),			
			handler:function( type, data, evt ){
				for( i in data )
					if( i.indexOf( "warning" ) >= 0 )
						if( data[i] )
							document.getElementById( i ).innerHTML = data[i];
				
				document.getElementById( 'altemailsubmit' ).disabled = false;
			},
			mimetype: "text/json"
		});	
	}
	
	var pCheckTimer;
	function passwordCheck(){
		if( pCheckTimer )
			clearTimeout( pCheckTimer );
			
		pCheckTimer = setTimeout( "passwordCheckFilter()", 750 );	
	}
	
	function passwordCheckFilter(){
		dojo.io.bind({
			url: "ajaxproxy.php",
			content: {
				action: "passwordstrength",
				param: document.getElementById( 'password' ).value
			},
			handler:function( type, data, evt ){
				submit.setState( (data.submitdisabled)? "disabled" : "normal" );
				document.getElementById( 'warning' ).innerHTML	 		= data.warning;
				document.getElementById( 'weak' ).style.background 		= data.weakcolor;
				document.getElementById( 'better' ).style.background 	= data.bettercolor;
				document.getElementById( 'perfect' ).style.background 	= data.perfectcolor;	
			},
			mimetype: "text/json"
		});	

	}
	
	
	function storePasswords(){
		if( document.getElementById( 'current' ).value.length == 0 ){
			alert( 'Please enter your current password.' );
			return;
		}
		
		if( document.getElementById( 'password' ).value.length == 0 ){
			alert( 'You must fill out the password box!' );
			return;
		}
		
		if( document.getElementById( 'passcheck' ).value.length == 0 ){
			alert( 'You must fill out the password box!' );
			return;
		}
		
		if( document.getElementById( 'passcheck' ).value != document.getElementById( 'password' ).value ){
			alert( 'The verification password does not match the new password!' );
			return;
		}
		
		submit.setState( "disabled" )

		dojo.io.bind({
			url: "ajaxproxy.php",
			content: {
				action: "passwordchange",
				current: document.getElementById( 'current' ).value,
				change: document.getElementById( 'password' ).value
			},
			handler:function( type, data, evt ){
				submit.setState( (data.submitdisabled)? "disabled" : "normal" );
				document.getElementById( 'warning' ).innerHTML	= data.warning;
			},
			mimetype: "text/json",
			sync: true,
			method: "POST"
		});	
	}

	
	function fetchAttachments( str ){
		document.getElementById( 'searchnotice' ).innerHTML = str;		
		document.getElementById( 'attachmentslist' ).innerHTML = "";
		dojo.io.bind({
			url: "ajaxproxy.php",
			content: {
				action: "attachmentslist"
			},
			handler:function( type, data, evt ){
				document.getElementById( 'searchnotice' ).innerHTML 	= "&nbsp;";
				document.getElementById( 'attachmentslist' ).innerHTML 	= data;
			}
		});	
	}
	
	
	/**
	 * Display a preview of the last message posted
	 */
	var previewMsg;
	var previewTimer;
	function showMessagePreview( id ){
		previewMsg 		= id;
		previewTimer 	= setTimeout( "loadMessagePreview()", 750 );
	}
	
	function loadMessagePreview(){
		document.getElementById( 'previewtext').innerHTML = previewWait;
		var block 				= document.getElementById( "preview" );	
		var msgLink				= document.getElementById( previewMsg );			
		var offsets 			= cumulativeOffset( msgLink );
		block.style.top 		= offsets[1] + 30 + 'px';
		block.style.left 		= offsets[0] + 48 + 'px';
		dojo.fx.html.fadeShow( block, 200 );				
					
		dojo.io.bind({
			url: "ajaxproxy.php",
			content: {
				action: "messagepreview",
				messageid: previewMsg
			},
			handler:function( type, data, evt ){
				if( data && data.text ){
					document.getElementById( 'previewtext').innerHTML = data.text;
					
				}
			},
			mimetype: "text/json"
		});			
	}
	
	function hideMessagePreview(){
		if( previewTimer )
			clearTimeout( previewTimer );
		var block = document.getElementById( "preview" );
		dojo.fx.html.fadeHide( block, 200 );
		previewMsg = null;
	}
	
	function cumulativeOffset(element) {
		var valueT = 0, valueL = 0;
		do {
			valueT += element.offsetTop || 0;
			valueL += element.offsetLeft || 0;
			element = element.offsetParent;
		} while (element);
		return [valueL, valueT];
	} 

	
	/**
	 * Load a KB frame into the KB viewer
	 */
	function loadKBFrame( cat ){ 
		document.getElementById( 'viewscreen' ).innerHTML	= '<table align="center" style="margin-top:150px;"><tr><td><img src="templates/system/images/waitstate.gif"></td></tr></table>';
		dojo.io.bind({
			url: "ajaxproxy.php",
			method: "POST",
			content: {
				action: "knowledgebaseload",
				id: kbid,
				category: cat		
			},
			handler:function( type, data, evt ){
				document.getElementById( 'viewscreen').innerHTML 	= data.text;
			},
			mimetype: "text/json"
		});	
	}
	
	function KBPrinterVersion(){
		var x = window.open( "kbfriendly.php?act=" + kbid, "print","width=600,height=600,top=" + centerX( 600 ) 
					   + ",left=" + centerY( 600 ) + ",resizable=yes,scrollbars=yes,menubar=yes,toolbar=no,status=no,location=no" );	
		return false;			
	}
	
	/**
	 * Mail out a KB article
	 */
	function KBMailpage( cat ){
		dojo.io.bind({
			url: "ajaxproxy.php",
			content: {
				action: "knowledgebasemail",
				id: kbid,
				category: cat		
			},
			handler:function( type, data, evt ){	
				mail_str  = "mailto:?subject=Auracle Knowledgebase - " + data.title;
				mail_str += "&body=This is a knowledgebase arcticle link to " + data.title;
				mail_str += ".%0A%0AIt can be viewed at :" + data.link;
				location.href = mail_str;
			},
			mimetype: "text/json"
		});	
	}
	
	
	/**
	 * Fetch a form select value
	 */
	function getSelectValue( selectObj ){
		for( var i = 0 ; i < selectObj.options.length ; i++ )
			if( selectObj.options[i].selected )
				return selectObj.options[i].value;
				
		return null;
	}
	
	
	/**
	 * Fetch a form select key
	 */
	function getSelectKey( selectObj ){
		for( var i = 0 ; i < selectObj.options.length ; i++ )
			if( selectObj.options[i].selected )
				return selectObj.options[i].text;
				
		return null;
	}
	
	/**
	 * Fetch a form radio select value
	 */
	function getRadioValue( controlName, formObj ){	

		if( formObj )		
			for( var i = 0 ; i < formObj[controlName].length ; i++ )
				if( formObj[controlName][i].checked )
					return formObj[controlName][i].value;
		
		return null;
	}
	
	function setRadioValue( form, controlName, data ){
		for( var i = 0 ; i < form[controlName].length; i++ ){
			if( form[controlName][i].value == data ){
				form[controlName][i].checked = true;
				break;
			}
		}
	}
	
	
	/**
	 * Show the 'undiv' div if the email does not exist, otherwise, hide it
	 */
	undiv_visible = false;
	function ticketEmailUserCheck(){
		dojo.io.bind({
			url: "ajaxproxy.php",
			content: {
				action: "ticketsendemailcheck",
				email: document.getElementById( 'email' ).value
			},
			handler:function( type, data, evt ){	
				var block = document.getElementById( 'undiv' );

				if( data.exists ){
					dojo.fx.wipeOut( block, 300 );
					undiv_visible = false;
					document.getElementById( 'username' ).value = "";
					document.getElementById( 'subject' ).focus();
				}
				else{
					if( !undiv_visible ){
						undiv_visible = true;
						dojo.fx.wipeIn( block, 200 );
						document.getElementById( 'username' ).focus();
					}
				}
			},
			mimetype: "text/json"
		});		
	}	
	
		
	/**
	 * Show file attachments
	 */
	fileAttachmentPanel = null;
	function showFileAttachPanel( id ){
		fileAttachmentPanel = window.open( "ticket_send_attach.php?tid=" + id, "attach","width=500,height=335,top=" + centerX( 500 ) + ",left=" + centerY( 335 ) + ",resizable=no,scrollbars=yes,menubar=no,toolbar=no,status=yes,location=no" );	
		return false;			
	}
	
	/**
	 * List a set of file attachments on window 'win'
	 */
	function listFileAttachments( win, ext, tid ){
		dojo.io.bind({
			url: "ajaxproxy.php",
			content: {
				action: "fileattachmentlist",
				extra: ext,
				topicID: tid
			},
			method: "POST",
			handler:function( type, data, evt ){	
				var block = win.document.getElementById( 'fileattachments' )
				// adjust dynamic block as required
				if( block ){					
					block.innerHTML = data;
					dojo.fx.fadeShow( block, 200 );
				}
			}
		});	
	}
	
	
	/**
	 * Delete a file attachment
	 */
	function deleteFileAttachment( id, tid, update, ext ){
		dojo.io.bind({
			url: "ajaxproxy.php",
			content: {
				action: "fileattachmentdelete",
				attachmentID: id,
				topicID: tid,
				extra: ext
			},
			method: "POST",
			handler:function( type, data, evt ){	
				var block = document.getElementById( 'fileattachments' );
				// adjust dynamic block as required
				if( block ){
					block.innerHTML = data;
					dojo.fx.fadeShow( block, 200 );
				}
				
				if( update && !update.closed ){
					block = update.document.getElementById( 'fileattachments' );
					block.innerHTML = data;
					dojo.fx.fadeShow( block, 200 );					
				}
			}
		});			
	}
	
	/**
	 * Add an option to a javascript select list
	 */
	function addSelectOption( selectList, key, value ){
		if( selectList ){
			selectList.options[selectList.options.length] = new Option( key, value );	
			return selectList.options.length - 1;
		}	
		return 0;
	}
	
	function setSelectValue( selectList, titleValue ){
		for( var i in selectList.options ){
			if( selectList.options[i].text == titleValue ){
				selectList.options[i].selected = true;
				break;
			}
		}			
	}
	
	function setSelectKey( selectList, keyValue ){
		for( var i in selectList.options ){
			if( selectList.options[i].value == keyValue ){
				selectList.options[i].selected = true;
				break;
			}
		}			
	}
	
	/**
	 * Clear a select list
	 */
	function clearSelectList( list ){
		list.options.length = 0;
	}
	
	
	/**
	 * Used on showtopic.php to permit the insertion of recorded responses
	 */
	function insertRecordedResponse( rrid ){
		dojo.io.bind({		
			url: "ajaxproxy.php",
			content: {
				action: "adminrecordedentry",
				id: rrid
			},	
			handler:function( type, data, evt ){
				if( data.title && data.entry ){
					document.getElementById( 'message' ).value 	= document.getElementById( 'message' ).value + " " + data.entry;
				}
			},
			mimetype: "text/json"
		});	
	}
	
	
	/**
	 * Forward a ticket to a given admin
	 */
	function forwardTicketTo( ticketID, adminID ){
		dojo.io.bind({		
			url: "ajaxproxy.php",
			content: {
				action: "adminticketforward",
				ticket: ticketID,
				admin: adminID
			},	
			handler:function( type, data, evt ){
				window.location.href = "index.php";
			}
		});		
	}
	
	
	/**
	 * Release a forward on a ticket
	 */
	function releaseTicket( ticketID ){
		dojo.io.bind({		
			url: "ajaxproxy.php",
			content: {
				action: "adminticketrelease",
				ticket: ticketID
			},	
			handler:function( type, data, evt ){
				window.location.href = "showtopic.php?id=" + ticketID;
			}
		});			
	}
	
	
	/**
	 * Change a ticket's category
	 */
	function changeTicketCategory( ticketID, categoryID ){
		dojo.io.bind({		
			url: "ajaxproxy.php",
			content: {
				action: "adminticketcategorychange",
				ticket: ticketID,
				category: categoryID
			},	
			handler:function( type, data, evt ){
				window.location.href = "index.php";
			}
		});			
	}
	
	
	
	fade_active = false;
	/**
	 * Show the banner application
	 */
	function showSplash( image, text ){	
		if( isIE )
			return;
			
		fade_active 	= true;
		var container	= document.getElementById( 'splashContainer' );
		var index		= document.getElementById( 'indexBox' );
		var myWidth 	= 0, 
			myHeight 	= 0;
			
		if( typeof( window.innerWidth ) == 'number' ) {
			//Non-IE
			myWidth = window.innerWidth;
			myHeight = window.innerHeight;
		}else if( document.documentElement 
				 && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
			//IE 6+ in 'standards compliant mode'
			myWidth = document.documentElement.clientWidth;
			myHeight = document.documentElement.clientHeight;
		} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
			//IE 4 compatible
			myWidth = document.body.clientWidth;
			myHeight = document.body.clientHeight;
		}		
		
		document.getElementById( 'splashIcon' ).innerHTML 		= '<img src="' + image + '">';				
		document.getElementById( 'splashCaption' ).innerHTML 	= text;
		
		
		container.style.top 	= ((myHeight / 2) - 150) + "px";
		container.style.left	= ((myWidth / 2 ) - 225) + "px";

		//this code looked really neat in Firefox, but unfortunately Safari and IE misbehaved
		//container.style.display	= "block";
		//dojo.fx.html.fade( container, 300, 0, .99 );
		//dojo.fx.html.fade( index, 400, .99, .3, function( node, anim ){ fade_active = false; } );
		showDiv( 'splashContainer' );
	}
	
	/**
	 * Hide the banner application
	 */
	function hideSplash(){
		if( isIE )
			return;
			
		var container	= document.getElementById( 'splashContainer' );
		var index		= document.getElementById( 'indexBox' );
		//dojo.fx.html.fade( container, 300, .99, 0, function( node, anim ){ if( !fade_active ) container.style.display = 'none'; } );
		//dojo.fx.html.fade( index, 400, .3, .99 );
		hideDiv( 'splashContainer' );
		
	}
	
	
// Script Source: CodeLifter.com
// Copyright 2003
// Do not remove this header

var isIE	=	document.all;
var isNN	=	!document.all&&document.getElementById;
var isN4	=	document.layers;
var isHot	=	false;

function ddInit(e){
	
  	topDog		= isIE ? "BODY" : "HTML";
  	whichDog	= isIE ? document.all.invitecard : document.getElementById("invitecard");  
  	hotDog		= isIE ? event.srcElement : e.target;    
	
  	if( hotDog.id == "titleBar" ){
    	offsetx		= isIE ? event.clientX : e.clientX;
    	offsety		= isIE ? event.clientY : e.clientY;
    	nowX		= parseInt( whichDog.style.left );
   	 	nowY		= parseInt( whichDog.style.top );
    	ddEnabled	= true;
    	document.onmousemove = dd;
	}
}

function dd(e){
  if (!ddEnabled) return;
  whichDog.style.left=isIE ? nowX+event.clientX-offsetx : nowX+e.clientX-offsetx; 
  whichDog.style.top=isIE ? nowY+event.clientY-offsety : nowY+e.clientY-offsety;
  return false;  
}

function ddN4(whatDog){
  if (!isN4) return;
  N4=eval(whatDog);
  N4.captureEvents(Event.MOUSEDOWN|Event.MOUSEUP);
  N4.onmousedown=function(e){
    N4.captureEvents(Event.MOUSEMOVE);
    N4x=e.x;
    N4y=e.y;
  }
  N4.onmousemove=function(e){
    if (isHot){
      N4.moveBy(e.x-N4x,e.y-N4y);
      return false;
    }
  }
  N4.onmouseup=function(){
    N4.releaseEvents(Event.MOUSEMOVE);
  }
}

document.onmousedown = ddInit;
document.onmouseup	 = Function("ddEnabled=false");