/*-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
| Support Center :: alteredCart.com
| All code developed by Bill Brewer
| Copyright (c)2009 alteredCart            
| Bill Brewer <bill@alteredcart.com> | All rights reserved.
| This code is licensed for use on a single server.
| This code is licensed for use by the original purchaser only.
| Full license :: www.alteredcart.com/license.php
|-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/

var attachmentsCount = 1;
var searchKBInterval = null;
var err_creator_must_be_logged = 'The creator of this ticket must be logged in to download attachments.'

var support = {
	
	/**
	* Switch the displayed tab
	*
	* @param selected string Elements ID to switch to
	*/
	displayTab:function(selected){
		
		// Tab is already selected //
		if (ac.$(selected).className == 'selectedTab')
			return;
	
		// Get all of the available options //
		var divs = ac.$('ticketTabs').getElementsByTagName('div');
		
		for (i = 0; i < divs.length; i++){
			
			if (!divs[i].id)
				continue;
				
			// Save the current soon to be previous size //
			if (ac.$(divs[i].id).className == 'selectedTab' && divs[i].id != selected){
				prevSize = ac.$(divs[i].id+'_display').offsetHeight;
				prevID = divs[i].id;
			}
	
			if (divs[i].id == selected){
				
				ac.$(divs[i].id).className = 'selectedTab';
				ac.$(divs[i].id).innerHTML = ac.$(divs[i].id).innerHTML.replace(/t-i-/g, 't-a-'); // Set the active images //
					
					} else {
	
				ac.$(divs[i].id).className = 'inactiveTab';
				ac.$(divs[i].id).innerHTML = ac.$(divs[i].id).innerHTML.replace(/t-a-/g, 't-i-'); // Set the inactive images //
				
				}
			}
			
			contentsDiv = ac.$('ticketsContentsDisplay');
			offset = contentsDiv.offsetHeight - prevSize;
			selectedDiv = ac.$(selected+'_display');
			previousDiv = ac.$(prevID+'_display');
	
			// Get the size of the selected div //
			selectedDiv.style.postition = 'absolute';
			selectedDiv.style.left = '-1000px';
			selectedDiv.style.height = '';
			selectedDiv.style.display = '';
		
			newsize = selectedDiv.offsetHeight;
		
			ac.changeOpacity(0, selectedDiv.id);
			selectedDiv.style.postition = 'static';
			
			selectedDiv.style.height = '0px';
			
			ac.changeSize({id:selectedDiv.id, start:0, end:newsize, xy:'y', millisec:200});
			ac.changeSize({id:previousDiv.id, start:prevSize, end:0, xy:'y', millisec:200});
			
			ac.fade(previousDiv.id, 100, 0, 200);
			setTimeout(function(){ac.fade(selectedDiv.id, 0, 100, 300);}, 200);
			
			// This will prevent the contents from being hidden if the texta area size is changed //
			setTimeout(function(){selectedDiv.style.height = '';}, 500);

				if (selected == 'post_reply')
					ac.$('post_descr').focus();
		
		},

	/**
	* Surround selected text with the starttag and endtag parameters
	*
	* @param elem string Id of the textarea with the selected text
	* @param starttag string Text to enter before the selected text
	* @param endtag string Text to enter after the selected text
	*/
	addTags:function(elem, starttag, endtag){
	
		elem = ac.$(elem);
		var scrollpos = elem.scrollTop;
	
		if (elem.setSelectionRange) {
		
			elem.value = elem.value.substring(0,elem.selectionStart) + starttag + elem.value.substring(elem.selectionStart,elem.selectionEnd) + endtag + elem.value.substring(elem.selectionEnd,elem.value.length)
		
			} else {
	
			var selectedText = document.selection.createRange().text;
	
			if (selectedText != "") {
				var newText = starttag + selectedText + endtag;
				document.selection.createRange().text = newText;
			}
		}
	
		// Preserve the scroll position //
		elem.scrollTop = scrollpos;

		},

	/**
	* Add another attachment input field to form
	*/
	addAttachmentInput:function(){
	
		attachments = ac.$('addAttachments').getElementsByTagName('input');
	
		// The last element is empty //
		if (attachments.length > 0 && attachments[attachments.length-1].value == '')
			return;
	
		ac.createElem({node:'input', type:'file', name:'attachment'+attachmentsCount, onclick:support.addAttachmentInput, add_br:true}, 'addAttachments');
		attachmentsCount++;
	
		if (typeof(supportUploadWinLayout) == 'function')
			supportUploadWinLayout();
	
	},

	/**
	* Auto KB search executed when a customer is entering a message 
	* on the contact or reply form
	*/
	autoSearchKB:function(){
	
		str = ac.$('post_descr').value;
		
		// Check if the customer is posting confidential data //
		if (str.match(/\bftp\b|\blogin\b|\bpass\b|\bpassword\b|\badmin\b|\busername\b/i))
			ac.$('secureDataWarning').style.display = '';
	
		if (str.length < 20)
			return;
			
		params = 'q='+encodeURIComponent(str)+'&section=knowledgebase&ajax_function=searchkb';
	
		// Query the db //
		ac.autoSearchKBAJAX = function(html){ ac.$('searchKBResults').innerHTML = html; };
		ac.ajax({url:'support.php', parameters:params, method:'POST', returned:'text', return_func:ac.autoSearchKBAJAX});
	
		},

	/**
	* Add a posts text to the input form field where a direct response can be entered.
	*
	* @param dataid integer Dataid of the post to add to the response field
	* @param ticketid string Main ticketcode [abcde-12345] of the dataid
	*/
	quote:function(dataid, ticketid){
			
		current_desc = document.post_reply_ticket.description.value;
		document.post_reply_ticket.description.value = support.text['js_loading_quoted_text'];
		
		params = 'dataid='+parseInt(dataid)+'&ticketid='+encodeURIComponent(ticketid)+'&section=tickets&action=load_quote';
	
		// Load the quote //
		ac.quoteAJAX = function(html){ 
			document.post_reply_ticket.description.value = current_desc+"\n\n"+html; 
			document.post_reply_ticket.description.scrollTop = document.post_reply_ticket.description.scrollHeight;		
		};
	
		ac.ajax({url:'support.php', parameters:params, method:'POST', returned:'text', return_func:ac.quoteAJAX});
		
		support.displayTab('post_reply'); // Switch to the reply tab //
		ac.scrollToElement('singleTicketDisplay'); // Scroll up to the reply tab //
	
		},

	/**
	* Switch an elements display.  If it is hidden=display it, if it is displayed=hide it.
	* 
	* @param id string Elements id
	* @param effect boolean Grow or shrink the element as it is hidden or revealed
	*/
	showHideElem:function(id, effect){

		// Grow the object //
		if (ac.$(id).style.display == 'none'){
			
			if (effect){

				newsize = ac.offsetHidden(id);
				ac.$(id).style.height = '0px';
				ac.$(id).style.overflow = 'hidden';
				ac.$(id).style.display = '';
				ac.changeSize({id:id, start:0, end:newsize.height, xy:'y', millisec:300});

			} else {

				ac.$(id).style.display = '';

			}
			
			// Shrink the object //
			} else {

				if (effect)
					ac.changeSize({id:id, start:ac.$(id).offsetHeight, end:0, xy:'y', millisec:300});
						else
					ac.$(id).style.display = 'none';
			}
		},

	/**
	* Check all fields, or uncheck all fields based on the status of elem
	*
	* @param field string Name attribute of the checkboxes to be un/checked.
	* @param elem obj Controlling Object that is check or unchecked
	*/
	allCheckboxes:function(field, elem){
	
		fields = document.getElementsByName(field);
	
			if (elem.checked == true){
				for (i = 0; i < fields.length; i++)
					fields[i].checked = true;
					
			} else {
			
				for (i = 0; i < fields.length; i++)
					fields[i].checked = false ;
			}
		},

	/**
	* Regex check on email to insure it has the correct syntax
	*
	* @param email string email address
	* @param alerterr boolean If true a JS alert box will display an error message
	*/
	validateEmail:function(email, alerterr){
		
		if (email.match(/^[A-Z0-9._%+-]+@(?:[A-Z0-9-]+\.)+[A-Z]{2,4}$/i))
			return true;
			
		if (alerterr)
			alert('Email address is invalid.');
			
		return false;
		
		},

	/**
	* Error control for the admin edit post details tab
	*/
	checkEditForm:function(){
	
		// Make sure the fields are filled //
		if (!document.edit_ticket_form.change_subject.value)
			err = "Subject: is a required field.\n\n";

		if (!document.edit_ticket_form.change_name.value)
			err = err+"Name: is a required field.\n\n";
		
		if (!document.edit_ticket_form.change_email.value || !support.validateEmail(document.edit_ticket_form.change_email.value, false))
			err = err+"Email address is invalid.\n";
			
			if (!err)
				document.edit_ticket_form.submit();
					else
				alert(err);
		},

	/**
	* Display a preview of the post with special tags ([B], [CODE], etc.) as it will be displayed
	*
	* @param post string Text to parse and display
	*/
	previewPost:function(post){
		
		ac.createModal({div:'previewPost'});
		ac.$('previewPost').innerHTML = '';
		
		// Background preview image //
		if (!ac.savedPreviewBackImg)
			ac.savedPreviewBackImg = ac.$('previewPost').style.backgroundImage;
			
		ac.$('previewPost').style.backgroundImage = ac.savedPreviewBackImg;
	
		params = 'post='+encodeURIComponent(post)+'&ticketid='+encodeURIComponent(ticketid)+'&section=tickets&action=preview_post&ajax_function=preview_post';
	
		ac.previewPostAJAX = function(html){ 
			ac.$('previewPost').innerHTML = html;
			ac.$('previewPost').style.backgroundImage = '';
		};
	
		ac.ajax({url:'support.php', parameters:params, method:'POST', returned:'text', return_func:ac.previewPostAJAX});
	
		},
		
	/**
	* Quick preview of a file attachment
	*
	* @param attachmentid intval Id of the attachment
	* @param ticketid string Ticket code [12345-abcde]
	*
	*/
	quickView:function(attachmentid, ticketid){
	
		ac.createModal({div:'quickView'});
			ac.$('quickViewContents').innerHTML = '';
	
		// Background preview image //
		if (!ac.savedPreviewBackImg)
			ac.savedPreviewBackImg = ac.$('quickView').style.backgroundImage;
	
		ac.$('quickView').style.backgroundImage = ac.savedPreviewBackImg;
	
		params = 'attachmentid='+encodeURIComponent(attachmentid)+'&ticketid='+encodeURIComponent(ticketid)+'&section=tickets&action=quick_view';
	
		ac.quickViewAJAX = function(html){
			ac.$('quickViewContents').innerHTML = html;
			ac.$('quickView').style.backgroundImage = '';
		};
	
		ac.ajax({url:'support.php', parameters:params, method:'POST', returned:'text', return_func:ac.quickViewAJAX});
	
		},

	/**
	* Add sorting to the tickets when in a multi-ticket row view
	*/
	addDynamicSort:function(){
	
		th = ac.$('ticketsDisplay').getElementsByTagName('th');
		
		for (i=0; i < th.length; i++){
			
			if (!th[i].id)
				continue;
				
			name = th[i].id.substr(2, th[i].id.length);
			
			// Select the current sorting element //
			if (ticketSort == name){
				ac.$(th[i].id).innerHTML = ac.$(th[i].id).innerHTML+' <img id="sort'+name+'" src="'+ac.ImagesDir+'/sort_'+ticketSortDirection+'.png" alt="" />';
			
				} else {
			
			// Add in the sort image //
			ac.$(th[i].id).innerHTML = ac.$(th[i].id).innerHTML+' <img id="sort'+name+'" style="display:none;" src="'+ac.ImagesDir+'/sort_ASC.png" alt="" />';
			
			}
	
			ac.addEvent(ac.$(th[i].id), 'mouseover', function(){ var name = this.id.substr(2, this.id.length); this.className='selected'; if (ticketSort == name) return; ac.$('sort'+name).style.display = ''; });
			ac.addEvent(ac.$(th[i].id), 'mouseout', function(){ var name = this.id.substr(2, this.id.length); this.className=''; if (ticketSort == name) return; ac.$('sort'+name).style.display = 'none'; });
			ac.addEvent(ac.$(th[i].id), 'mousedown', function(){ window.location='support.php?section=tickets&sort='+this.id.substr(2, this.id.length); });
	
			}
		},

	/**
	* Error control for the main ticket create/contact form
	*/
	submitContactForm:function(){
		
		formObj = document.supportForm;
		submitForm = true;

			if (!formObj.name.value){
				support.dynamicControl.displayError(formObj.name, support.text['err_name_is_required']);
				submitForm = false;
			}
			
			if (!formObj.email.value){
				support.dynamicControl.displayError(formObj.email, support.text['err_email_is_required']);
				submitForm = false;
			}
			
			if (!formObj.subject.value){
				support.dynamicControl.displayError(formObj.subject, support.text['err_subject_is_required']);
				submitForm = false;
			}
			
			if (!formObj.description.value){
				support.dynamicControl.displayError(formObj.description, support.text['err_message_is_required']);
				submitForm = false;
			}
			
		if (submitForm){
			
				support.dynamicControl.displaySaving(ac.$('submitButtons'));
				formObj.submit();
		
			} else {
				
				ac.scrollToElement('contactTable'); // Scroll up so the errors are visible //
				
			}
		},

	/**
	* Display the contact form when a customer has 0 points
	*/
	reportBug:function(){
	
		ac.$('contactTable').style.display = '';
	
		},

	/**
	* Show of hide the ticket options displayed at the bottom multi-row ticket page
	*/
	switchTicketOptions:function(){
	
		fields = document.getElementsByName('ticketids[]');
	
			for (i = 0; i < fields.length; i++){
				
				if (fields[i].checked == true){
					ac.unmask('ticketOptions');
						return;
	
				}
			}
	
		ac.mask('ticketOptions');
		
		}

	};



/* Modal Window Image Display */
support.images = {
	
	/**
	* boolean Keep track if the image is currently being moved
	*/
	sliding:false,
	
	/**
	* Array of images on the current page
	*/
	images:[],

	/**
	* Total number of thumbnail images displayed
	*/
	totalThumbs:0,

	/**
	* Image currently selected (by position number)
	*/
	currentImage:0,

	/**
	* Current image position selected (by pixels)
	*/
	currentPosition:0,

	/**
	* Pixel spacing in-between images
	*/
	imageSpacing:5,
	
	/**
	* Scroll the thumbnails up or down
	*
	* @param opt object
	* 		-direction [up, down, left, right], 
	* 		-container_div [the div to adjust the style (top, bottom, left, right)]
	* 		-imgid [scroll to a preset image]
	*/
	elemScroll:function(opt){

		if (this.sliding)
			return;
			
			// Current position //
			if (!this.currentPosition)
				this.currentPosition = parseInt(ac.$(opt.container_div).style.top);
				
			// Scroll to a specific image //
			if (opt.imgid){
		
			ac.$(opt.container_div).style.top = '0px';
			this.currentPosition = 0;
		
			this.sliding = true;
		
			var end = 0;
		
			for (var x=0; x<this.images.length; x++){
			
				if (this.images[x].id == opt.imgid){
		
					this.currentImage = x;
					break;
				}
			
				end += (ac.$(this.images[x].id).offsetHeight + this.imageSpacing);
			}
			
				end = (this.currentPosition - end);
		
				ac.changeStyle({id:opt.container_div, start:this.currentPosition, end:end, style_attr:'top', millisec:600});
				setTimeout(function(){ support.images.sliding = false; }, 610);
		
				this.currentPosition = end; // Update the position to what it will be after the 'slide' //	
				return;		
				
			}
		
			if (opt.direction == 'up'){
		
				if (this.currentImage == 0)
					return;
					
				this.sliding = true;
		
				// Determine how large the previous image is, and scroll as necessary //
				var height = ac.$(this.images[this.currentImage-1].id).offsetHeight;
				var end = this.currentPosition + this.imageSpacing + height;
		
				ac.changeStyle({id:opt.container_div, start:this.currentPosition, end:end, style_attr:'top', millisec:300});
				setTimeout(function() {support.images.sliding=false; }, 310);
		
				this.currentPosition = end; // Update the position to what it will be after the 'slide' //
				this.currentImage--;			
		
			}
		
			else if (opt.direction == 'down'){
		
				if (this.currentImage == this.images.length-1)
					return;
		
				this.sliding = true;
		
				// Determine how large the current image is, and scroll as necessary //
				var height = ac.$(this.images[this.currentImage].id).offsetHeight;
				var end = this.currentPosition - this.imageSpacing - height;
		
				ac.changeStyle({id:opt.container_div, start:this.currentPosition, end:end, style_attr:'top', millisec:300});
				setTimeout(function(){ support.images.sliding = false; }, 310);
		
				this.currentPosition = end; // Update the position to what it will be after the 'slide' //
				this.currentImage++;
		
				}
		
				if (this.currentImage == 0)
					ac.$('imageUP').style.display = 'none';
						else
					ac.$('imageUP').style.display = '';
		
				if (this.currentImage == this.images.length-1)
					ac.$('imageDOWN').style.display = 'none';
						else
					ac.$('imageDOWN').style.display = '';

			},

	/**
	* Choose a thumbnail to display in the main image window
	*
	* @param attachmentid integer Attachmentid of the image to display
	*/
	selectImage:function(attachmentid){
	
		// Set the dimensions of the main image display //
		ac.$('imageDisplaySectionT').style.height = (ac.$('imagesDisplay').offsetHeight - 25)+'px';
		ac.$('imageDisplaySectionT').style.width = (ac.$('imagesDisplay').offsetWidth - 275)+'px';
	
		// Reset the display //
		ac.$('imageDisplaySection').innerHTML = '';
	
		// Display the loading image //
		ac.$('imageDisplaySection').style.backgroundImage = "url('"+ac.ImagesDir+"/loading_a.gif')";
	
		// Create the image //
		ac.createElem({node:'img', id:'id'+attachmentid, src:this.catalogLocation+'/support.php?section=tickets&action=file&modal=1&attachmentid='+parseInt(attachmentid)+'&ticketid='+encodeURIComponent(ticketid)}, 'imageDisplaySection')
	
		// Reset the images //
		for (var x=0; x<this.images.length; x++){		
			ac.$(this.images[x].id).style.backgroundColor = '';
			}

		// Change the background of the selected //
		ac.$('imgid'+attachmentid).style.backgroundColor = '#404040';
		
		// Give the image 3 seconds to load, and then remove the loading image //
		ac.onImageLoad(ac.$('id'+attachmentid), function() { ac.$('imageDisplaySection').style.backgroundImage=''; });
		//setTimeout(function() { ac.$('imageDisplaySection').style.backgroundImage=''; }, 3000);

	},

	/**
	* Links directly to an image to diplay by auto scrolling when the page displays
	*
	* @param attachmentid integer Attachmentid of the image to display
	*/
	displayImgLink:function(attachmentid){

		ac.createModal({div:'imagesDisplay'});
		support.images.selectImage(attachmentid);
		support.images.elemScroll({direction:'down', container_div:'numbers', imgid:'imgid'+attachmentid});

	},

	/**
	* Zoom in or out of the displayed image
	*
	* @parameter dir string Zoom direction "in" or "out"
	*/
	imgZoom:function(dir){
	
		// Image id //
		imgid = ac.$('imageDisplaySection').getElementsByTagName('img');
		obj = ac.$(imgid[0].id);

			if (dir == 'in'){
				obj.height = obj.height * 1.2;
				obj.width = obj.width * 1.2;
			}

			else if (dir == 'out'){
				if ((obj.height * .8) < 1 || (obj.width * .8) < 1)
					return;	

				obj.height = obj.height * .8;
				obj.width = obj.width * .8;
			}
		}

	}


/* Shortcuts */
ac.shortcuts = {
	
	/* Disabled
	
	To enable add this code to the support-tickets.tpl file:
	
	ac.addEvent(window, 'load', function(){ldelim}
	ac.shortcuts.addEHandler(document.getElementsByTagName('input'));
	ac.shortcuts.addEHandler(document.getElementsByTagName('textarea'));
	{rdelim});
ac.addEvent(document, 'keydown', ac.shortcuts.monitorShortcutKeys);

	*/
	
	monitorShortcutKeys: function(e){

	e = e || window.event;

	if (!e.shiftKey || ac.disableShortcut)
		return;

	// Reply Tab //
	if (e.keyCode == 82){
		displayTab('post_reply');
		ac.scrollToElement('ticketTabs');
		return;
		}
	// General Tab //
	else if (e.keyCode == 71){
		if (!ac.$('general'))
			return;
		displayTab('general');
		ac.scrollToElement('ticketTabs');
		return;
		}
	// Edit Tab //
	else if (e.keyCode == 69){
		if (!ac.$('edit'))
			return;
		displayTab('edit');
		ac.scrollToElement('ticketTabs');
		return;
		}
	else if (e.keyCode == 78){
		if (!ac.$('add_note'))
			return;
		displayTab('add_note');
		ac.scrollToElement('ticketTabs');
		return;
		}
	else if (e.keyCode == 67){
		if (!ac.$('customer_info'))
			return;
		displayTab('customer_info');
		ac.scrollToElement('ticketTabs');
		return;
		}
	else if (e.keyCode == 80){
		if (!ac.$('charged_points'))
			return;
		displayTab('charged_points');
		ac.scrollToElement('ticketTabs');
		return;
		}
	else if (e.keyCode == 65){
		displayTab('post_access');
		ac.scrollToElement('ticketTabs');
		return;
		}
	},

 	addEHandler: function(formElem){
	
	if (!formElem)
		return;

	for (x = 0; x < formElem.length; x++){
	
		//console.log(formElem[x].name+' '+formElem[x].type);

		if (formElem[x].type == 'text' || formElem[x].type == 'textarea'){
	
		ac.addEvent(formElem[x], 'focus', function(){ac.disableShortcut = true;});
		ac.addEvent(formElem[x], 'blur', function(){ac.disableShortcut = false;});
			}
		}	
	}
	
	};


/*
* Global dynamic form options object
*/
support.dynamicControl = {

	/**
	* HTML code for large loading image
	*/
	loadingA:function(){ return'<div style="text-align:center; padding:100px;"><img src="'+ac.ImagesDir+'/loading_a.gif" alt="" style="margin-bottom:10px;" /><br />'+support.text['js_loading_ellipsis']+'</span>'; },

	/**
	* Main undo function to restore a deleted item
	*/
	undo:function(maskid, undoid){
		
		params = 'section=undo&undoid='+parseInt(undoid);

		ac.undoAJAX = function(html){
			
			if (html == 'S')
				ac.unmask(maskid);
					else
				alert('error');
			
			}

		ac.ajax({url:'support.php', parameters:params, method:'POST', returned:'text', return_func:ac.undoAJAX});

	},

	/**
	* Highlight a form field with a red border and error message
	*
	* @param node object Form field to highlight
	* @param text string Text to display to the right of the field
	*/
	displayError:function(node, text){

		ac.displayAETextErrorID = span = ac.createElem({node:'span', className:'formErrorMessage'}, node.parentNode);
		id = ac.createElem({node:'img', src:ac.ImagesDir+'/error.png', className:'inlineImg'}, span);
		node.style.border = '1px #F00 solid';
		ac.$(span).appendChild(document.createTextNode(' '+text));

	},

	/**
	* Remove the error message and image
	*
	* @param node object Form field to remove error message from
	*/
	removeError:function(node){

		// Search for the error node //
		spans = node.parentNode.getElementsByTagName('span');
		node.style.border = '';

		for (i=0; i<spans.length; i++){

			// Search for a matching error span //
			if (spans[i].id.match(/^id\d{7}$/g))
				node.parentNode.removeChild(spans[i]);

			}
		},

	/**
	* Replace button or image with animated gif and Saving... text
	*
	* @param node object Button or image object to hide and replace with loading text & img
	*/
	displaySaving:function(node){

		node.style.display = 'none';
		ac.createElem({node:'img', src:ac.ImagesDir+'/horizontal_loading.gif', className:'inlineImg'}, node.parentNode);

		},

	/**
	* Replace saving button with 'Saved' text for 2 seconds, and then replace the original
	*		button or image
	*
	* @param node object Original button or image to restore
	*/
	removeSaving:function(node){

		// Search for the error node //
		elements = node.parentNode.getElementsByTagName('*');

		for (i=0; i<elements.length; i++){

			// Search for a matching error span //
			if (elements[i].id.match(/^id\d{7}$/g))
				node.parentNode.removeChild(elements[i]);

			}

		orig_button_text = node.value;
		node.value = support.text['js_saved'];
		node.style.display = '';

		setTimeout(function() { node.value = orig_button_text; }, 2000);

		}

	};

ac.addEvent(window, 'load', function(){
	ac.preloadImg('horizontal_loading.gif'); } );
