
function playerLoad() {
    var anchors = document.getElementsByTagName('a');
    var anchors_length = anchors.length;
    
    for (var i = 0; i < anchors_length; i++) {
   
        if (anchors[i].className == 'taggedlink' && anchors[i].href.match(/\.flv$/i)) {
            _playerAdd(anchors[i]);
        }
          if (anchors[i].className == 'taggedlink' && anchors[i].href.match(/\.mp4$/i)) {
            _playerAdd(anchors[i]);
        }
        if (anchors[i].className == 'taggedlink' && anchors[i].href.match(/http:\/\/www.youtube.com\/watch\?v=(.*)$/i)) {
            _playerAdd(anchors[i]);
            
        }
        if (anchors[i].className == 'taggedlink' && anchors[i].href.match(/https:\/\/www.youtube.com\/watch\?v=(.*)$/i)) {
            _playerAdd(anchors[i]);
            
        }
	//	if (anchors[i].className == 'taggedlink' && anchors[i].href.match(/http:\/\/video.google.com\/videoplay\?docid=(.*)$/i)) {
      //      _playerAdd(anchors[i]);
            
     //   }

        /*
          if (anchors[i].className == 'taggedlink' && anchors[i].href.match(/vimeo\.com/i) )
          {
          	
          var $urlvimeo = anchors[i].href;
//	$url1 = array($url);
	$id = str_replace( "http://www.vimeo.com/", "", "http://www.vimeo.com/5698852");
          	
             vimeoid2url($id);
            
            
        }
        
   */

        
           if (anchors[i].className == 'taggedlink' && anchors[i].href.match(/http:\/\/gdata.youtube+\.[^.]+$/i)) {
            _playerAdd(anchors[i]);
     // http://gdata.youtube.com/feeds/videos?author=USERNAME&orderby=updated&alt=atom&racy=include&playlist=over&         
       
        }
    }
}



function playerLoad2() {
    var anchors = document.getElementsByTagName('a');
    var anchors_length = anchors.length;
    
    for (var i = 0; i < anchors_length; i++) {
        if (anchors[i].className == 'taggedlink' && anchors[i].href.match(/\.mp3$/i)) {
            _playerAdd2(anchors[i]);
        }
       
    }
    for (var i = 0; i < anchors_length; i++) {
        if (anchors[i].className == 'taggedlink' && anchors[i].href.match(/\.aac$/i)) {
            _playerAdd2(anchors[i]);
        }
       
    }
    
}



function playerLoad3() {
    var anchors = document.getElementsByTagName('a');
    var anchors_length = anchors.length;
    
    for (var i = 0; i < anchors_length; i++) {
        if (anchors[i].className == 'taggedlink' && anchors[i].href.match(/\.jpg$/i)) {
            _playerAdd3(anchors[i]);
        }
       
    }
    
        for (var i = 0; i < anchors_length; i++) {
        if (anchors[i].className == 'taggedlink' && anchors[i].href.match(/\.png$/i)) {
            _playerAdd3(anchors[i]);
        }
       
    }
    
           for (var i = 0; i < anchors_length; i++) {
        if (anchors[i].className == 'taggedlink' && anchors[i].href.match(/\.gif$/i)) {
            _playerAdd3(anchors[i]);
        }
       
    }
}

function playerLoad4() {
    var anchors = document.getElementsByTagName('a');
    var anchors_length = anchors.length;
    
    for (var i = 0; i < anchors_length; i++) {

 if ((anchors[i].className == 'taggedlink' && anchors[i].href.match(/maps\.google\.fr/i)) || (anchors[i].className == 'taggedlink' && anchors[i].href.match(/maps\.google\.com/i))) {
  
            _playerAdd4(anchors[i]);
        }
       
    }
  
}


function playerLoad5() {
    var anchors = document.getElementsByTagName('a');
    var anchors_length = anchors.length;
    
    for (var i = 0; i < anchors_length; i++) {

 if (anchors[i].className == 'taggedlink' && anchors[i].href.match(/vimeo\.com.[0-9]+/i)) {
  
	 
            _playerAdd5(anchors[i]);
        }
       
    }
  
}

//
function media() { 
StkFunc(playerLoad);
StkFunc(playerLoad2);
StkFunc(playerLoad3);
StkFunc(playerLoad4);
StkFunc(playerLoad5);
}




/* http://www.vimeo.com/5698852 */
/*
function vimeoid2url(anchor) {
	
	$xmlurl = "http://www.vimeo.com/moogaloop/load/clip:"+ $id;
	//$xmlurl = "http://www.vimeo.com/moogaloop/load/clip:{$id}";
	//var code = $xmlurl + $id;
	$videoxml = file_get_contents($xmlurl);

preg_match('|<request_signature>(.*)</request_signature>|i',$videoxml,$sig);
preg_match('|<request_signature_expires>(.*)</request_signature_expires>|i',$videoxml,$sigexp);

$url = "http://www.vimeo.com/moogaloop/play/clip:{$id}/{$sig[1]}/{$sigexp[1]}/?q=sd";
return $url;
}


if (window.location.href.match(/vimeo.com\/\d+\/?$/)) {
		var vimeoid = window.location.href.match(/vimeo.com\/(\d+)\/?$/)[1];
		GM_xmlhttpRequest({
			method: 'GET',
			url: 'http://www.vimeo.com/moogaloop/load/clip:' + vimeoid,
			onload: function(responseDetails) {
				var request_signature = responseDetails.responseText.match(/request_signature>([^<]+)</)[1];
				var request_signature_expires = responseDetails.responseText.match(/request_signature_expires>([^<]+)</)[1];
				var videourl = 'http://www.vimeo.com/moogaloop/play/clip:' + vimeoid + '/' + request_signature + '/' + request_signature_expires + '/?q=sd';
				document.getElementById('vimeo_player_' + vimeoid).innerHTML = videoReplaceHTML(videourl);
			}
		});






*/











function vimeoid2url(id) {
    var videourl;
    var vimeoid = id;

XMLHttpRequest({
			method: 'GET',
			url: 'http://www.vimeo.com/' + vimeoid,
		//	url: 'http://www.vimeo.com/moogaloop/load/clip:' + vimeoid,
			
			onload: function(responseDetails) {
				var request_signature = responseDetails.responseText.match(/request_signature>([^<]+)</)[1];
				var request_signature_expires = responseDetails.responseText.match(/request_signature_expires>([^<]+)</)[1];
				var videourl = 'http://www.vimeo.com' + vimeoid + '/' + request_signature + '/' + request_signature_expires + '/?q=sd';
				//var videourl = 'http://www.vimeo.com/moogaloop/play/clip:' + vimeoid + '/' + request_signature + '/' + request_signature_expires + '/?q=sd';
				
				return videourl;
				playerAdd(videourl);
		//		document.getElementById('vimeo_player_' + vimeoid).innerHTML = videoReplaceHTML(videourl);
			}
		});

return videourl;
//$videoxml = file_get_contents($xmlurl);

//preg_match('|<request_signature>(.*)</request_signature>|i',$videoxml,$sig);
//preg_match('|<request_signature_expires>(.*)</request_signature_expires>|i',$videoxml,$sigexp);

//$url = "http://www.vimeo.com/moogaloop/play/clip:{$id}/{$sig[1]}/{$sigexp[1]}/?q=sd";

}


// Flv, Mp4, Youtube, Youtube userfeed
// http://gdata.youtube.com/feeds/videos?author=USERNAME&orderby=updated&alt=atom&racy=include&playlist=over&  

function _playerAdd(anchor) {
	
//	if (anchor.href.match(/http:\/\/video.google.com.com\/videoplay\?docid=(.*)$/i)) {
/*
	    	$re1='.*?';	
		  $re2='(\\d+)';

		  if ($c=preg_match_all ("/".$re1.$re2."/is", $url, $matches))
		  {
		      $int1=$matches[1][0];		     
		  } 
//var url = anchor.href;
	var url = opium.php?docid=$int1&type=flv
*/
 //} else {
	
	var url = anchor.href;
	
//}

    
    /*
   		 $strToSearch = "?v=";
		 preg_match(anchor.href, $strToSearch, $matches ); 
      	 $idyoutube = $matches[1];
      	 $file =  anchor.href; 
      	 preg_match_all('/http:\\/\\/.*[v]\"/', $file, $idyoutube, PREG_SET_ORDER);

		$url = $out[0][0];

		$video = str_replace( '"', '', $url);

		echo $video; 
 		echo $idyoutube;
     */
  /*  
  http://www.youtube.com/watch?v=zLYAjR2JvMw

1. View high quality videos

Youtube gives you the option to switch to high quality videos for some of the videos, however you can check if a video is available in high quality format by appending ‘&fmt=18′(stereo, 480 x 270 resolution) or ‘&fmt=22′(stereo, 1280 x 720 resolution) for even higher quality.
2. Embed Higher Quality Videos

While the above trick works for playback, if however you want to embed hig quality videos you need to append “&ap=%2526fmt%3D18″ and “&ap=%2526fmt%3D22″ to the embed url.


<embed src='http://links.fluate.net/includes/mediaplayer/player.swf' height='407' width='540' allowscriptaccess='always' allowfullscreen='true' flashvars='controlbar=over&skin=http%3A%2F%2Flinks.fluate.net%2Fincludes%2Fmediaplayer%2Fbekle.swf&image=http%3A%2F%2Flinks.fluate.net%2Fvideo.jpg&file=http%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DeuAeJuFaIsY&volume=70'/>




  
  
  var anchors_length = anchors.length;
    
     for (var i = 0; i < anchors_length; i++) {  if (anchors[i].href.match(/\.v$/i)) {  var urlyt = anchors[i];  }
         echo urlyt; 
    } 
    */
		
  //  url = encodeURIComponent(url);
 
     var code = '<embed src="http://links.fluate.net/includes/mediaplayer/player.swf" id="player" width="634" height="478" allowscriptaccess="always" allowfullscreen="true" flashvars="file='+ url +'&autostart=false&volume=70&controlbar=over&overstretch=false&showdigits=true&fullscreen=true&skin=http://links.fluate.net/includes/mediaplayer/bekle.zip" >';
    
 
    
 /*   var code = '<embed src="http://links.fluate.net/includes/mediaplayer/player.swf" width="634" height="478" allowscriptaccess="always" allowfullscreen="true" flashvars="file='+ url +'&autostart=false&volume=70&controlbar=over&overstretch=true&showdigits=true&fullscreen=true&image=http://img.youtube.com/vi//2.jpg" >';*/
    
    var code = code + '<param bgcolor="#FFFFFF" backcolor="0xFFFFFF" screencolor="0xFFFFFF" />';
    var code = code + '</embed>';
    
	//var code = code + '<a href=# onclick=\"document.getElementById(\'player\').sendEvent(\'PLAY\');return 	false;\">play-pause toggle</a>';
      
    anchor.parentNode.innerHTML = anchor.parentNode.innerHTML +'<br><div class=video >'+ code +'</div>';
    
// <image>http://img.youtube.com/vi//2.jpg</image>

}

// Mp3, Aac

function _playerAdd2(anchor) {
    var url = anchor.href;
    
    var code = '<embed src="http://links.fluate.net/includes/mediaplayer/player.swf" width="634" height="50" allowscriptaccess="always" flashvars="file='+ url +'&autostart=false&volume=70&showdigits=true&skin=http%3A%2F%2Flinks.fluate.net%2Fincludes%2Fmediaplayer%2Fbekle.zip" >';
    
    var code = code + '<param bgcolor="#FFFFFF" backcolor="#FFFFFF" />';
    var code = code + '</embed>';
     
      anchor.parentNode.innerHTML = anchor.parentNode.innerHTML +'<br><div class=video >'+ code +'</div>';

}

// Gif, Jpg, Png

function _playerAdd3(anchor) {
    var url = anchor.href;
  var code = '<a href="'+ url +'" target="_blank" border=0 ><img border=0 src="http://links.fluate.net/tb/phpThumb.php/?src='+ url +'&w=634&q=95"></a>';
/*    var code = '<embed src="http://links.fluate.net/includes/mediaplayer/player.swf" width="634" height="478" allowscriptaccess="always" allowfullscreen="true"  flashvars="file='+ url +'&controlbar=none&autostart=true&caption=false&displayclick=fullscreen&fullscreen=true" >';
    
    var code = code + '<param bgcolor="#FFFFFF" backcolor="0xFFFFFF" screencolor="0xFFFFFF" />';
    var code = code + '</embed>';
    */
      anchor.parentNode.innerHTML = anchor.parentNode.innerHTML +'<br><div class=video >'+ code +'</div>';

}


// Google map

function _playerAdd4(anchor) {
    var url = anchor.href;
var code = '<iframe width="634" height="478" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="'+ url +'&amp;output=embed"></iframe><br><a href="'+url+'" target=_blank>fullscreen</a>';
      anchor.parentNode.innerHTML = anchor.parentNode.innerHTML +'<br><div class=video >'+ code +'</div>';

}

function _playerAdd5(anchor) {
    var url = anchor.href;
	var url2 = str_replace( "http://vimeo.com/", "", url);

var code = '<br><iframe src="http://player.vimeo.com/video/'+ url2 +'?title=0&amp;byline=0&amp;portrait=0&amp;color=994d00" width="634" height="478" frameborder="0" webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe>';
     // anchor.parentNode.innerHTML = anchor.parentNode.innerHTML +'<br><div class=video >'+ code +'</div>';
		var upnode = anchor.parentNode;
		var upnode2 = upnode.nextSibling;
		upnode.innerHTML =  upnode.innerHTML +'<br><div class=video >'+ code +'</div>';

}

/*function _playerAdd2(anchor) {
    var url = anchor.href;
    var code = '<object type="application/x-shockwave-flash" data="http://links.fluate.net/includes/mediaplayer/musicplayer_f6.swf?song_url=' + url +'&amp;b_bgcolor=ffffff&amp;b_fgcolor=000000&amp;b_colors=0000ff,0000ff,ff0000,ff0000&buttons=http://links.fluate.net/includes/mediaplayer/load.swf,http://links.fluate.net/includes/mediaplayer/play.swf,http://links.fluate.net/includes/mediaplayer/stop.swf,http://links.fluate.net/includes/mediaplayer/error.swf" width="14" height="14">';
    var code = code + '<param name="movie" value="http://links.fluate.net/includes/mediaplayer/musicplayer.swf?song_url=' + url +'&amp;b_bgcolor=ffffff&amp;b_fgcolor=000000&amp;b_colors=0000ff,0000ff,ff0000,ff0000&amp;buttons=http://links.fluate.net/includes/mediaplayer/load.swf,http://links.fluate.net/includes/mediaplayer/play.swf,http://links.fluate.net/includes/mediaplayer/stop.swf,http://links.fluate.net/includes/mediaplayer/error.swf" />';
    var code = code + '</object>';
    anchor.parentNode.innerHTML = code +' '+ anchor.parentNode.innerHTML;
}
*/

















String.prototype.trim = function() {
    return this.replace(/^\s+|\s+$/g, '');
};

var deleted = false;
function deleteBookmark(ele, input){
    var confirmDelete = "<span>Are you sure? <a href=\"#\" onclick=\"deleteConfirmed(this, " + input + ", \'\'); return false;\">Yes</a> - <a href=\"#\" onclick=\"deleteCancelled(this); return false;\">No</a></span>";
    ele.style.display = 'none';
    ele.parentNode.innerHTML = ele.parentNode.innerHTML + confirmDelete;
}

function deleteCancelled(ele) {
    var del = previousElement(ele.parentNode);
    del.style.display = 'inline';
    ele.parentNode.parentNode.removeChild(ele.parentNode);
    return false;
}

function deleteConfirmed(ele, input, response) {
    if (deleted == false) {
        deleted = ele.parentNode.parentNode.parentNode.parentNode;
    }
    var post = deleted;
    post.className = 'xfolkentry deleted';
    if (response != '') {
        post.style.display = 'none';
        deleted = false;
    } else {
        loadXMLDoc('http://links.fluate.net/ajaxDelete.php?id=' + input);
    }
}

function previousElement(ele) {
    ele = ele.previousSibling;
    while (ele.nodeType != 1) {
        ele = ele.previousSibling;
    }
    return ele;
}

function isAvailable(input, response){
    var usernameField = document.getElementById("username");
    var username = usernameField.value;
    username = username.toLowerCase();
    username = username.trim();
    var availability = document.getElementById("availability");
    if (username != '') {
        usernameField.style.backgroundImage = 'url(http://links.fluate.net/loading.gif)';
        if (response != '') {
            usernameField.style.backgroundImage = 'none';
            if (response == 'true') {
                availability.className = 'available';
                availability.innerHTML = 'Available';
            } else {
                availability.className = 'not-available';
                availability.innerHTML = 'Not Available';
            }
        } else {
            loadXMLDoc('http://links.fluate.net/ajaxIsAvailable.php?username=' + username);
        }
    }
}

function useAddress(ele) {
    var address = ele.value;
    if (address != '') {
        if (address.indexOf(':') < 0) {
            address = 'http:\/\/' + address;
        }
        getTitle(address, null);
        ele.value = address;
    }
}

function getTitle(input, response){
    var title = document.getElementById('titleField');
    if (title.value == '') {
        title.style.backgroundImage = 'url(http://links.fluate.net/loading.gif)';
        if (response != null) {
            title.style.backgroundImage = 'none';
            title.value = response;
        } else if (input.indexOf('http') > -1) {
            loadXMLDoc('http://links.fluate.net/ajaxGetTitle.php?url=' + input);
        } else {
            return false;
        }
    }
}

var xmlhttp;
function loadXMLDoc(url) {
    // Native
    if (window.XMLHttpRequest) {
        xmlhttp = new XMLHttpRequest();
        xmlhttp.onreadystatechange = processStateChange;
        xmlhttp.open("GET", url, true);
        xmlhttp.send(null);
    // ActiveX
    } else if (window.ActiveXObject) {
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
        if (xmlhttp) {
            xmlhttp.onreadystatechange = processStateChange;
            xmlhttp.open("GET", url, true);
            xmlhttp.send();
        }
    }
}

function processStateChange() {
    if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
        response = xmlhttp.responseXML.documentElement;
        method = response.getElementsByTagName('method')[0].firstChild.data;
        result = response.getElementsByTagName('result')[0].firstChild.data;
        eval(method + '(\'\', result)');
    }
}


// Fonction de stockage des scripts à charger 
FuncOL = new Array(); 
function StkFunc(Obj) { 
    FuncOL[FuncOL.length] = Obj; 
} 
         
// Execution des scripts au chargement de la page 
window.onload = function() { 
    for(i=0; i<FuncOL.length; i++) 
        {FuncOL[i]();} 
}


function str_replace(search, replace, subject, count) {
    // http://kevin.vanzonneveld.net
    // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: Gabriel Paderni
    // +   improved by: Philip Peterson
    // +   improved by: Simon Willison (http://simonwillison.net)
    // +    revised by: Jonas Raoni Soares Silva (http://www.jsfromhell.com)
    // +   bugfixed by: Anton Ongson
    // +      input by: Onno Marsman
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +    tweaked by: Onno Marsman
    // +      input by: Brett Zamir (http://brett-zamir.me)
    // +   bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   input by: Oleg Eremeev
    // +   improved by: Brett Zamir (http://brett-zamir.me)
    // +   bugfixed by: Oleg Eremeev
    // %          note 1: The count parameter must be passed as a string in order
    // %          note 1:  to find a global variable in which the result will be given
    // *     example 1: str_replace(' ', '.', 'Kevin van Zonneveld');
    // *     returns 1: 'Kevin.van.Zonneveld'
    // *     example 2: str_replace(['{name}', 'l'], ['hello', 'm'], '{name}, lars');
    // *     returns 2: 'hemmo, mars'
 
    var i = 0, j = 0, temp = '', repl = '', sl = 0, fl = 0,
            f = [].concat(search),
            r = [].concat(replace),
            s = subject,
            ra = r instanceof Array, sa = s instanceof Array;
    s = [].concat(s);
    if (count) {
        this.window[count] = 0;
    }
 
    for (i=0, sl=s.length; i < sl; i++) {
        if (s[i] === '') {
            continue;
        }
        for (j=0, fl=f.length; j < fl; j++) {
            temp = s[i]+'';
            repl = ra ? (r[j] !== undefined ? r[j] : '') : r[0];
            s[i] = (temp).split(f[j]).join(repl);
            if (count && s[i] !== temp) {
                this.window[count] += (temp.length-s[i].length)/f[j].length;}
        }
    }
    return sa ? s : s[0];
}





function file_get_contents( url, flags, context, offset, maxLen ) {
    // Read the entire file into a string
    //
    // version: 906.111
    // discuss at: http://phpjs.org/functions/file_get_contents
    // +   original by: Legaev Andrey
    // +      input by: Jani Hartikainen
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: Brett Zamir (http://brett-zamir.me)
    // +   input by: Raphael (Ao) RUDLER
    // +   bugfixed by: Brett Zamir (http://brett-zamir.me)
    // %        note 1: This function uses XmlHttpRequest and cannot retrieve resource from different domain without modifications.
    // %        note 2: Synchronous by default (as in PHP) so may lock up browser. Can
    // %        note 2: get async by setting a custom "phpjs.async" property to true and "notification" for an
    // %        note 2: optional callback (both as context params, with responseText, and other JS-specific
    // %        note 2: request properties available via 'this'). Note that file_get_contents() will not return the text
    // %        note 2: in such a case (use this.responseText within the callback). Or, consider using
    // %        note 2: jQuery's: $('#divId').load('http://url') instead.
    // %        note 3: The context argument is only implemented for http, and only partially (see below for
    // %        note 3: "Presently unimplemented HTTP context options"); also the arguments passed to
    // %        note 3: notification are incomplete
    // *     example 1: file_get_contents('http://kevin.vanzonneveld.net/pj_test_supportfile_1.htm');
    // *     returns 1: '123'
    // Note: could also be made to optionally add to global $http_response_header as per http://php.net/manual/en/reserved.variables.httpresponseheader.php
 
    var tmp, headers = [], newTmp = [], k=0, i=0, href = '', pathPos = -1, flagNames = '', content = null, http_stream = false;
    var func = function (value) { return value.substring(1) !== ''; };
 
    // BEGIN REDUNDANT
    this.php_js = this.php_js || {};
    this.php_js.ini = this.php_js.ini || {};
    // END REDUNDANT
    context = context || this.php_js.default_streams_context || null;
 
    if (!flags) {flags = 0;}
    var OPTS = {
        PHP_FILE_USE_INCLUDE_PATH : 1,
        PHP_FILE_TEXT : 32,
        PHP_FILE_BINARY : 64
    };
    if (typeof flags === 'number') { // Allow for a single string or an array of string flags
        flagNames = flags;
    }
    else {
        flags = [].concat(flags);
        for (i=0; i < flags.length; i++) {
            if (OPTS[flags[i]]) {
                flagNames = flagNames | OPTS[flags[i]];
            }
        }
    }
    if ((flagNames & OPTS.PHP_FILE_USE_INCLUDE_PATH) && this.php_js.ini.include_path &&
            this.php_js.ini.include_path.local_value) {
        var slash = this.php_js.ini.include_path.local_value.indexOf('/') !== -1 ? '/' : '\\';
        url = this.php_js.ini.include_path.local_value+slash+url;
    }
    else if (!/^(https?|file):/.test(url)) { // Allow references within or below the same directory (should fix to allow other relative references or root reference; could make dependent on parse_url())
        href = this.window.location.href;
        pathPos = url.indexOf('/') === 0 ? href.indexOf('/', 8)-1 : href.lastIndexOf('/');
        url = href.slice(0, pathPos+1)+url;
    }
 
    if (context) {
        var http_options = context.stream_options && context.stream_options.http;
        http_stream = !!http_options;
    }
 
    if (!context || http_stream) {
        var req = this.window.ActiveXObject ? new ActiveXObject('Microsoft.XMLHTTP') : new XMLHttpRequest();
        if (!req) {throw new Error('XMLHttpRequest not supported');}
 
        var method = http_stream ? http_options.method : 'GET';
        var async = !!(context && context.stream_params && context.stream_params['phpjs.async']);
        req.open(method, url, async);
        if (async) {
            var notification = context.stream_params.notification;
            if (typeof notification === 'function') {
                req.onreadystatechange = function (aEvt) { // aEvt has stopPropagation(), preventDefault(); see https://developer.mozilla.org/en/NsIDOMEvent
 
// Other XMLHttpRequest properties: multipart, responseXML, status, statusText, upload, withCredentials; overrideMimeType()
/*
PHP Constants:
STREAM_NOTIFY_RESOLVE   1     A remote address required for this stream has been resolved, or the resolution failed. See severity  for an indication of which happened.
STREAM_NOTIFY_CONNECT   2   A connection with an external resource has been established.
STREAM_NOTIFY_AUTH_REQUIRED 3   Additional authorization is required to access the specified resource. Typical issued with severity level of STREAM_NOTIFY_SEVERITY_ERR.
STREAM_NOTIFY_MIME_TYPE_IS  4   The mime-type of resource has been identified, refer to message for a description of the discovered type.
STREAM_NOTIFY_FILE_SIZE_IS  5   The size of the resource has been discovered.
STREAM_NOTIFY_REDIRECTED    6   The external resource has redirected the stream to an alternate location. Refer to message .
STREAM_NOTIFY_PROGRESS  7   Indicates current progress of the stream transfer in bytes_transferred and possibly bytes_max as well.
STREAM_NOTIFY_COMPLETED 8   There is no more data available on the stream.
STREAM_NOTIFY_FAILURE   9   A generic error occurred on the stream, consult message and message_code for details.
STREAM_NOTIFY_AUTH_RESULT   10   Authorization has been completed (with or without success).
 
STREAM_NOTIFY_SEVERITY_INFO 0   Normal, non-error related, notification.
STREAM_NOTIFY_SEVERITY_WARN 1   Non critical error condition. Processing may continue.
STREAM_NOTIFY_SEVERITY_ERR  2   A critical error occurred. Processing cannot continue.
*/
 
                    var objContext = {}; // properties are not available in PHP, but offered on notification via 'this' for convenience
                    objContext.responseText = req.responseText;
                    objContext.responseXML = req.responseXML;
                    objContext.status = req.status;
                    objContext.statusText = req.statusText;
                    objContext.readyState = req.readyState;
                    objContext.evt = aEvt;
 
                    // notification args: notification_code, severity, message, message_code, bytes_transferred, bytes_max (all int's except string 'message')
                    // Need to add message, etc.
                    var bytes_transferred;
                    switch(req.readyState) {
                        case 0: //   UNINITIALIZED   open() has not been called yet.
                            notification.call(objContext, 0, 0, '', 0, 0, 0);
                            break;
                        case 1: //   LOADING   send() has not been called yet.
                            notification.call(objContext, 0, 0, '', 0, 0, 0);
                            break;
                        case 2: //   LOADED   send() has been called, and headers and status are available.
                            notification.call(objContext, 0, 0, '', 0, 0, 0);
                            break;
                        case 3: //   INTERACTIVE   Downloading; responseText holds partial data.
                            bytes_transferred = Math.floor(req.responseText.length/2); // Two characters for each byte
                            notification.call(objContext, 7, 0, '', 0, bytes_transferred, 0);
                            break;
                        case 4: //   COMPLETED   The operation is complete.
                            if (req.status >= 200 && req.status < 400) {
                                bytes_transferred = Math.floor(req.responseText.length/2); // Two characters for each byte
                                notification.call(objContext, 8, 0, '', req.status, bytes_transferred, 0);
                            }
                            else if (req.status === 403) { // Fix: These two are finished except for message
                                notification.call(objContext, 10, 2, '', req.status, 0, 0);
                            }
                            else { // Errors
                                notification.call(objContext, 9, 2, '', req.status, 0, 0);
                            }
                            break;
                        default:
                            throw 'Unrecognized ready state for file_get_contents()';
                    }
                }
            }
        }
 
        if (http_stream) {
            var sendHeaders = http_options.header && http_options.header.split(/\r?\n/);
            var userAgentSent = false;
            for (i=0; i < sendHeaders.length; i++) {
                var sendHeader = sendHeaders[i];
                var breakPos = sendHeader.search(/:\s*/);
                var sendHeaderName = sendHeader.substring(0, breakPos);
                req.setRequestHeader(sendHeaderName, sendHeader.substring(breakPos+1));
                if (sendHeaderName === 'User-Agent') {
                    userAgentSent = true;
                }
            }
            if (!userAgentSent) {
                var user_agent = http_options.user_agent ||
                                                                    (this.php_js.ini.user_agent && this.php_js.ini.user_agent.local_value);
                if (user_agent) {
                    req.setRequestHeader('User-Agent', user_agent);
                }
            }
            content = http_options.content || null;
            /*
            // Presently unimplemented HTTP context options
            var request_fulluri = http_options.request_fulluri || false; // When set to TRUE, the entire URI will be used when constructing the request. (i.e. GET http://www.example.com/path/to/file.html HTTP/1.0). While this is a non-standard request format, some proxy servers require it.
            var max_redirects = http_options.max_redirects || 20; // The max number of redirects to follow. Value 1 or less means that no redirects are followed.
            var protocol_version = http_options.protocol_version || 1.0; // HTTP protocol version
            var timeout = http_options.timeout || (this.php_js.ini.default_socket_timeout && this.php_js.ini.default_socket_timeout.local_value); // Read timeout in seconds, specified by a float
            var ignore_errors = http_options.ignore_errors || false; // Fetch the content even on failure status codes.
            */
        }
        // We should probably change to an || "or", in order to have binary as the default (as it is in PHP), but this method might not be well-supported; check for its existence instead or will this be to much trouble?
        if (flagNames & OPTS.PHP_FILE_BINARY && !(flagNames & OPTS.PHP_FILE_TEXT)) { // These flags shouldn't be together
            req.sendAsBinary(content); // In Firefox, only available FF3+
        }
        else {
            req.send(content);
        }
 
        tmp = req.getAllResponseHeaders();
        if (tmp) {
            tmp = tmp.split('\n');
            for (k=0; k < tmp.length; k++) {
                if (func(tmp[k])) {
                    newTmp.push(tmp[k]);
                }
            }
            tmp = newTmp;
            for (i=0; i < tmp.length; i++) {
                headers[i] = tmp[i];
            }
            this.$http_response_header = headers; // see http://php.net/manual/en/reserved.variables.httpresponseheader.php
        }
 
        if (offset || maxLen) {
            if (maxLen) {
                return req.responseText.substr(offset || 0, maxLen);
            }
            return req.responseText.substr(offset);
        }
        return req.responseText;
    }
    return false;
}








