
<!--


/* *** Credits *** */
/*                                           */
/* AardvarkURL v1.0.1                        */
/* 4th September 2006                        */
/*                                           */
/*                                           */
/* v1.0.1: Fixed problem with + in URL       */
/*                                           */
/*                                           */
/*                                           */
/*                                           */
/* AJAX alternative code by:                 */
/*                                           */
/* XssHttpRequest version 1.0				 */
/* (c) 2005 Jeffrey Sambells				 */
/* <info@jeffreysambells.com>				 */
/* http://jeffreysambells.com/XssHttpRequest */
/*                                           */
/* Allows AJAX to run across domains which   */
/* is normally blocked by most browsers      */
/* 											 */
/*                                           */
/* Another URL worth a look is by:           */
/* Bill Bercik                               */
/* http://www.webpasties.com/xmlHttpRequest/ */
/*                                           */
/*                                           */
/*                                           */
/* Codebase is based on the above with some  */
/* modifications as required. Look for the   */
/* commented out lines in the XssHttpReq     */
/*                                   		 */
/*                                    		 */
/*                							 */
/* Other Code 						  		 */
/*                                    		 */
/* Author: Trev 				      		 */
/* Email:  trev@beammeupnowplease.com 		 */
/* Web:    www.aardvarkurl.net        		 */





/*
*
*
*
*  Instructions
*  ============
*
*
*
*  Usage - All:
*
*   • This tag is required in the head for anything related to this script:
*
*     • Add a script SRC to:
*       <script src="http://www.aardvarkurl.net/uif/url-ajax.js" LANGUAGE="JavaScript" type="TEXT/JAVASCRIPT"></script>
*
*
*
*
*  Basic Usage - Link:
*
*   • Create a link with an onClick event and ID as:
*     <a href="#" onClick="au_get_the_data(); return false;" id="au_content_link">LINKTEXT</a>
*
*   • The ID value tells the script which link to align the dropdown output to although can
*     be altered in au_settings_varib['popup_link_id']
*
*   • Errors will be printed into the DIV tag instead of the URL and explanation text
*     thus keeping things neatly together
*
*
*
*
*  Basic Usage - Form:
*
*   • A form is pretty similar to the textlink, except we're calling it usually from a button press
*     although we still use the same function call and onClick event.
*
*     <form name="au_output_form" onSubmit="return false;">
*       <input type="text" name="au_output_tbox" size="90" onClick="javascript:this.focus();this.select();" onKeyPress="return au_noEnterSubmit();">
*       <input type="button" name="button" value="Get URL" onClick="au_get_the_data()">
*     </form>
*
*   • Although it's not recommended, it is possible to alter the form name & textbox name. Details are
*     shown in the "customised output - part 1" option a little further down.
*
*   • The extra bits of Javascript either stop the form being submitted when the user clicks 'enter'
*     or send the web link off to the script (in the case of the button)
*
*
*   • If an error occurs, the script will try to drop it into the item (usually DIV tag) with the ID
*     as set in au_settings_fixed['error_div_id'] (usually id='au_error_div')
*
*     • If this doesn't exist then no error will be printed and the user will be confused
*
*     • The DIV or similar with the ID should be set as style='display:none' initially and will be
*       made visible. It'll then be removed from view again if the error goes away.
*
*
*
*
*
*  Customised Output - Part 1:
*
*   • There are a number of ways to customise this script with both input and output options.
*
*     au_settings_varib[] and au_language[] variables are made to be altered by including a
*     script block after the <script src=...> call mentioned earlier on. Anything else shouldn't
*     be altered as it'll break the script and won't output correctly.
*
*     The following example changes the form & textbox names when using the form option:
*
*     <script language="JavaScript">
*       au_settings_varib['default_output_form_name'] = 'mynewform';
*       au_settings_varib['default_output_tbox_name'] = 'mynewtextbox';
*     </script>
*
*
*
*
*
*  Customised Output - Part 2:
*
*   • If the above options of the link & form aren't suitable, then we can invoke the raw output
*     which makes either the URL or the error message available to another script. This mode offers
*     much greater freedom than the simpler options shown above, but also more responsibility for
*     assigning the data to the appropriate place.
*
*
*   • To use the script in custom mode, add the script SRC link as normal to this script
*
*   • In the script block set this variable to tell it we're taking control:
*     au_settings_varib['output_set_type'] = 1;
*
*   • Add a function called au_raw_output_finished()
*
*     • This callback function is called once the script has gotten some data or an error
*       and could just call a third party function or assign the data itself. It's simply
*       there so we know when things have finished.
*
*     • After that function is called, it's a good idea to check the au_raw_output['output_error_occured']
*       variable which will be set to 1 if an error occured
*
*   • Error text is available in: au_raw_output['output_raw_error']
*   • The URL is available in: au_raw_output['output_raw_url']
*
*     • If there's an error then no URL will be available and visa versa
*
*
*
*
*
*  Customised Output - Setting the URL:
*
*   • In the vast majority of cases the URL to be shortened will be the one
*     of the page where the form or link are, but occasionally it might be
*     useful to feed in a slightly different URL especially if the content
*     of the page is dynamic
*
*     Normally the au_get_the_data() function will pickup the URL of the page
*     automatically, but it can also be fed this as an argument. The URL
*     doesn't need encoding, just simply drop it in, eg:
*
*     var myurl = 'http://www.example.com/this.php?id=276';
*     au_get_the_data(myurl);
*
*
*
*
*
*  Customised Output - Changing the language:
*
*   • Currently the output messages are only available in English. The messages
*     can however be translated by setting the au_language[] variables although
*     this mainly relates to the error messages currently.
*
*   • If using the dropdown menu option from the link, then the variable
*     au_settings_varib['popup_output_html'] requires editing.
*
*   • The same method as described in customising part 1 is used to achieve this, eg:
*
*     <script language="JavaScript">
*       au_language['error_missing_url'] = "Aucune adresse de site Web n'a été fournie";
*     </script>
*
*
*
*
*
*
*  Any Output - Status Callback:
*
*  • This applies to anything except the dropdown menu (although it's still available there).
*
*    To find out when the script has finished processing data and is ready either with a URL
*    or an error, check the  au_raw_output['output_status_returned']  variable which will go
*    to 0 on error and 1 on success.
*
*    By default it's -1 so checking it is simple with a  self.setInterval()  function by asking:
*
*    if (au_raw_output['output_status_returned'] > -1) {
*        // Output is ready
*    }
*
*
*
*
*
**/





/* *** BEGIN SETTINGS *** */


var au_settings_varib   = new Array();
var au_settings_fixed   = new Array();
var au_language			= new Array();
var au_raw_output		= new Array();


au_settings_fixed['url_error_hpage']  			= 'www.aardvarkurl.net';
au_settings_fixed['url_add_url']  				= 'http://www.aardvarkurl.net/user_scripts/print_hash.php?u=';
au_settings_fixed['url_short_url']				= 'http://www.aardvarkurl.net/q/';

au_settings_fixed['url_ajax1_js']				= 'http://www.aardvarkurl.net/uif/au_xsshttprequest.js';
au_settings_fixed['url_popup_js']				= 'http://www.aardvarkurl.net/uif/au_popup_window.js';
au_settings_varib['url_css_code']				= 'http://www.aardvarkurl.net/uif/au_default_css.css';


au_settings_varib['popup_autohide']				= 0;  // 0 for off, 1 for on
au_settings_varib['popup_position_y']			= 20; // 20 for menu below link, -240 for popup above link
au_settings_varib['popup_position_x']			= 0;  // Amount to start to left/right of link (normally 0)


au_settings_varib['default_output_form_name']	= 'au_output_form';
au_settings_varib['default_output_tbox_name'] 	= 'au_output_tbox';
au_settings_varib['popup_link_id']				= 'au_content_link';
au_settings_varib['popup_div_id']				= 'au_content_div';
au_settings_varib['error_div_id']				= 'au_error_div';


au_settings_varib['output_set_type']			= 0;  // 0=Auto; 1=Raw
au_settings_varib['debug_alert']				= 0;  // Use 0 for live environment


au_settings_varib['popup_output_html']			= '<table width="450" border="0" cellspacing="0" cellpadding="5" class="au_pp_tbl_outer">  <tr>     <td class="au_pp_tbl_toprow">Short Website Link</td>  </tr>  <tr class="au_pp_tbl_rows">     <td>       <form onSubmit="return false;" class="au_pp_frm_output">        <br>        You can use the short address below to link directly to this page:<br>        <br>        <input type="text" name="au_frm_shrturl_oput" size="31" class="au_pp_frm_output_box" value="AUFORMSHORTURL" onClick="javascript:this.focus();this.select();" onKeyPress="return noEnterSubmit()">        <br>        <br>        For example, if you want to send this page to a friend, simply <a href="mailto:?subject=&body=AUEMAILSHORTURL" class="au_pp_frm_output_link">click         here</a> <br>        and the link will be inserted into a new e-mail message for you.<br>        <br>        When the recipient clicks the link, they will be redirected straight back         here<br>        with no messy looking web site addresses or line wrapping to worry about!<br>        <br>        <table width="420" border="0" cellspacing="0" cellpadding="0">          <tr class="au_pp_tbl_rows">             <td><a href="#" onClick="AU_popup_object.hidePopup();return false;">Close               this menu</a></td>            <td>               <div align="right"><a href="http://www.aardvarkurl.net/help-advantages/" target="_blank">More                 details...</a></div>            </td>          </tr>        </table>      </form>    </td>  </tr></table>';
au_settings_varib['popup_error_html']			= '<table width="450" border="0" cellspacing="0" cellpadding="5" class="au_pp_tbl_outer">  <tr>     <td class="au_pp_tbl_toprow">Short Website Link</td>  </tr>  <tr class="au_pp_tbl_rows">     <td> <br>      ERRORMSG<br>      <br>      <table width="420" border="0" cellspacing="0" cellpadding="0">        <tr class="au_pp_tbl_rows">           <td><a href="#" onClick="AU_popup_object.hidePopup();return false;">Close             this menu</a></td>          <td>             <div align="right"><a href="http://www.aardvarkurl.net/help-errors/" target="_blank">More               details...</a></div>          </td>        </tr>      </table>    </td>  </tr></table>';


au_raw_output['output_raw_url']					= ''; // For user to roll their own output (URL) [Fixed]
au_raw_output['output_raw_error']				= ''; // For user to roll their own output (error msg) [Fixed]
au_raw_output['output_error_occured'] 			= 0;  // Goes 1 if error occured [Fixed]
au_raw_output['output_status_returned']			= -1; // 1=OK, 0=Error (tells calling J/S script has finished)


au_language['error_introduction']				= 'Sorry, we are unable to provide you with the short link due to the following error:<br><br>';
au_language['error_missing_url']				= 'No web site address was provided';
au_language['error_invalid_url']				= 'The web site address provided does not appear to be valid';
au_language['error_blocked_url']				= 'This web site address is not allowed to be used in the system';
au_language['error_https_url']					= 'The system can not provide short URLs for https:// addresses';
au_language['error_internal_fault']				= 'An internal error has occured.<br>The site admin has been notified';
au_language['error_ip_temp_block']				= 'Service temporarily unavailable - please again try in a minute or so';
au_language['error_maintainance']				= 'The service is temporarily offline for essential maintainance';



/* *** END SETTINGS *** */







/* *** BEGIN INCLUDES *** */


// A drop-in replacement for xmlHttpRequest() but avoids cross browser scripting restrictions
document.write('<script language="JavaScript" src="' + au_settings_fixed['url_ajax1_js'] + '"></script>');


// Settings for the popup menu option
document.write('<script language="JavaScript" src="' + au_settings_fixed['url_popup_js'] + '"></script>');
document.write('<DIV ID="' + au_settings_varib['popup_div_id'] + '" STYLE="position:absolute; display:none;" class="au_popup_div">&nbsp;</DIV>');


// The stylesheet to use for the menu
document.write('<link rel="stylesheet" type="text/css" name="au_style" href="' + au_settings_varib['url_css_code'] + '">');


/* *** END INCLUDES *** */






/* *** BEGIN AJAX FUNCTIONS *** */





function au_get_the_data(form_submitted_data) {



	if (form_submitted_data != undefined) {
		var url	= (form_submitted_data.length > 10) ? form_submitted_data : location.href;
	}
	else {
		var url = location.href;
	}



	// Create the request URL
	//
	// The .replace fixes a problem with + in a URL being turned into %20 in PHP.
	// This way we preserve the + symbols which is handy for mod_rewrite especially.

	var url 		= escape(url);
		url			= url.replace(/\+/, 'AUPLUSAU');

	var full_url	= au_settings_fixed['url_add_url'] + url;




	http = new XssHttpRequest();
	http.open("GET", full_url, true);

	http.onreadystatechange=function() {

		if (http.readyState == 4) {

			var raw_results_data = http.responseText; 	// The data returning from AJAX call
			au_process_data(raw_results_data);			// Send the received data string for processing

		}

	}

	http.send(null);


}




/* **** END AJAX **** */








/* *** BEGIN NON-AJAX FUNCTIONS *** */




function au_process_data(raw_data_string) {



	var results_data_array 	= new Array();

	results_data_array 		= raw_data_string.split("|");



	if (results_data_array[0] < 1) {


		/* Call an error */

		au_data_error_handling(results_data_array[3]);


	}

	else {


		/* Clear any old error messages */

		if (document.getElementById(au_settings_varib['error_div_id'])) {
			document.getElementById(au_settings_varib['error_div_id']).style.display = 'none';
		}


		var final_short_url = results_data_array[2];

		au_output_the_data(final_short_url); // Send the output URL to the user


	}


} // End of processing raw data







function au_data_error_handling(error_id) {



	switch (error_id) {


		case 'URLMISSING':
		var results_error_msg = au_language['error_missing_url'];
		break;

		case 'URLNOTVALID':
		var results_error_msg = au_language['error_invalid_url'];
		break;

		case 'URLNOTALLOWED':
		var results_error_msg = au_language['error_blocked_url'];
		break;

		case 'URLHTTPSERROR':
		var results_error_msg = au_language['error_https_url'];
		break;

		case 'IPTEMPBLOCK':
		var results_error_msg = au_language['error_ip_temp_block'];
		break;

		case 'MAINTAINANCE':
		var results_error_msg = au_language['error_maintainance'];
		break;

		case 'IERROR':
		var results_error_msg = au_language['error_internal_fault'];
		break;

		default:
		var results_error_msg = au_language['error_internal_fault'];


	} // End switch





	if (au_settings_varib['output_set_type'] == 1) {

		au_raw_output['output_raw_error']	 	= au_language['error_introduction'] + results_error_msg;
		au_raw_output['output_error_occured']	= 1;

		if (window.au_raw_output_finished) {
			au_raw_output_finished(); 			// Call the external "we've finished" function for raw output
		}

	}
	else if (document.getElementById(au_settings_varib['error_div_id'])) {

		document.getElementById(au_settings_varib['error_div_id']).innerHTML 		= au_language['error_introduction'] + results_error_msg;
		document.getElementById(au_settings_varib['error_div_id']).style.display 	= '';

	}
	else if (document.getElementById(au_settings_varib['popup_link_id'])) {

		var tmp_error_msg_whole					= au_language['error_introduction'] + results_error_msg;
		au_settings_varib['popup_output_html'] 	= au_settings_varib['popup_error_html'].replace(/ERRORMSG/g, tmp_error_msg_whole);
		au_output_the_data('');

	}
	else {


		if (au_settings_varib['debug_alert'] == 1) {

			alert("Error occured, but the DIV tag with ID \n'" + au_settings_varib['error_div_id'] + "'\n is missing so error can not be printed\n\nError code was: " + results_data_array[3]);

		}


	} // End of if DIV exists




	au_raw_output['output_status_returned'] = 0; // Tell calling script that output has ended



}







function au_output_the_data(final_short_url) {



	var tbox_form = au_settings_varib['default_output_form_name'];
	var tbox_name = au_settings_varib['default_output_tbox_name'];
	var link_id	  = au_settings_varib['popup_link_id'];



	if (au_settings_varib['output_set_type'] == 1) {


		au_raw_output['output_raw_url'] = final_short_url;


		if (window.au_raw_output_finished) {

			au_raw_output_finished(); // Call the external "we've finished" function for raw output

		}


	}
	else if (eval(document.forms[tbox_form])) {


		if (eval(document.forms[tbox_form].elements[tbox_name])) {

			document.forms[tbox_form].elements[tbox_name].value = final_short_url;

		}


	}
	else if (document.getElementById(link_id)) {


		var final_short_url_email = escape(final_short_url);

		au_settings_varib['popup_output_html'] = au_settings_varib['popup_output_html'].replace(/AUFORMSHORTURL/g, final_short_url);
		au_settings_varib['popup_output_html'] = au_settings_varib['popup_output_html'].replace(/AUEMAILSHORTURL/g, final_short_url_email);

		document.getElementById(au_settings_varib['popup_div_id']).innerHTML = au_settings_varib['popup_output_html'];

		AU_popup_object.showPopup(au_settings_varib['popup_link_id']); // Make the DIV tag appear


	}
	else {


		if (au_settings_varib['debug_alert'] == 1) {

			alert("You need to either provide a link with the id='" + au_settings_varib['popup_link_id'] + "'\n\n\nOr a form called name='" + tbox_form + "'\nand textbox called name='" + tbox_name + "' \nfor this script to print the short URL into...\n\n\nSee details at: " + au_settings_fixed['url_error_hpage']);

		}


	}



	au_raw_output['output_status_returned'] = 1; // Tell calling script that output has ended


}





/* A basic function to prevent a textbox submitting if the user hits 'enter' */
/*                                                                           */
/* Mainly useful if using the form submit method (like on main site), where  */
/* we can't use a onSubmit="return false" statement (eg: if not our form)    */

function au_noEnterSubmit() {
  return !(window.event && window.event.keyCode == 13);
}




/* *** END NON-AJAX FUNCTIONS *** */





// -->
