/*
 *	ezClick widget engine
 *
 *	@author:	Mark Graves
 *	@copyright:	WhichBudget Ltd - http://www.whichbudget.com
*/
function ezClick_widget( ezLocation ){
	/*
	 * Check IATA code is correct
	*/
	switch( ezLocation ){
		case 'FAO'	: 	var idloc = 122;
						break;
		case 'LIS'	:	var idloc = 120;
						break;
		case 'OPO'	:	var idloc = 201;
						break;
		case 'FNC'	:	var idloc = 119;
						break;
		default		:	var idloc = 0;
	}
	if( idloc == 0 ){
		/*
		 * IATA is wrong return nothing
		*/
		return;
	}else{
		/*
		 * Correct IATA code given
		 * Use mootools request to get data
		*/
		document.write( '<div id="ezClick"></div>' );
		var head = document.getElementsByTagName('head')[0];
		var css = document.createElement('link');
		css.type = 'text/css';
		css.rel = 'stylesheet';
		css.href = 'http://www.whichbudget.com/ezClick/ezClick.css';
		head.appendChild( css );

		window.addEvent('domready', function(){					
			new Request({
				url			: 'http://www.whichbudget.com/ezClick/ezClick_new.php',
				method		: 'POST',
				data		: 'r=s&idloc=' + idloc,
				onComplete	: function( ajaxObj ){
								if( ajaxObj.length > 0 ){
									$('ezClick').innerHTML = stripslashes( ajaxObj );
									$('ezClick').setStyle( 'display', 'block' );
								}
							  }
			}).send();
			/*
			new Ajax( 'http://www.whichbudget.com/ezClick/ezClick_new.php', {
				method : 'POST',
				data : 'r=s&idloc=' + idloc,
				onComplete : function( ajaxObj ){
								if( ajaxObj.length > 0 ){
									$('ezClick').innerHTML = stripslashes( ajaxObj );
									$('ezClick').setStyle( 'display', 'block' );
								}
							}
			}).request();
			*/
		});
	}
	return;
}

/*
 * Strip slashes from return data
*/
function stripslashes( str ) {
    // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: Ates Goral (http://magnetiq.com)
    // +      fixed by: Mick@el
    // +   improved by: marrtins
    // +   bugfixed by: Onno Marsman
    // +   improved by: rezna
    // +   input by: Rick Waldron
    // +   reimplemented by: Brett Zamir (http://brett-zamir.me)
    // *     example 1: stripslashes('Kevin\'s code');
    // *     returns 1: "Kevin's code"
    // *     example 2: stripslashes('Kevin\\\'s code');
    // *     returns 2: "Kevin\'s code"
    return (str+'').replace(/\\(.?)/g, function (s, n1) {
        switch(n1) {
            case '\\':
                return '\\';
            case '0':
                return '\0';
            case '':
                return '';
            default:
                return n1;
        }
    });
}
