
/*******************************************************
 * 
 * Global JS Variables
 * 
 ******************************************************/
 var langId;
 var storeId;
 var catalogId;
 

/*******************************************************
 * 
 * Miscellaneous Functions/Prototypes
 * 
 ******************************************************/

String.prototype.trim = function() {
	return this.replace(/^\s+|\s+$/g,"");
}

String.prototype.ltrim = function() {
	return this.replace(/^\s+/,"");
}

String.prototype.rtrim = function() {
	return this.replace(/\s+$/,"");
}

function nl2br(input) {
	var regX = new RegExp("\\n", "g");
	var replaceString = "<br />\n";
	return input.replace(regX, replaceString);
}

function stripCarriageReturns(input) {
	var regX = new RegExp("\\r", "g");
	var replaceString = "";
	return input.replace(regX, replaceString);
}

function strReplaceAll(input, findWhat, replaceWith) {
	output = input;
	intIndexOfMatch = output.indexOf(findWhat);
	while (intIndexOfMatch != -1){
		output = output.replace(findWhat, replaceWith);
		intIndexOfMatch = output.indexOf(findWhat);
	}
	return output;
}

function checkEnter(event) {
	var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
	if ((keyCode == 13)) {
		return true;
	}
	else {
		return false;
	}
}

function getHandle(what) {
	var handle;
	if (typeof(what) == 'string') {
		handle = document.getElementById(what);
	}
	else {
		handle = what;
	}
	return handle;
}

function show(what, displayMode) {
	if (typeof(displayMode) == 'undefined') displayMode = 'block';
	getHandle(what).style.display = displayMode;
}

function hide(what) {
	getHandle(what).style.display = 'none';
}

function hideAllMenus() {
	document.getElementById('womensMenu').style.display = 'none';
	document.getElementById('mensMenu').style.display = 'none';
	document.getElementById('nflMenu').style.display = 'none';
	document.getElementById('newMenu').style.display = 'none';
}

function toggle(what, displayMode) {
	if (typeof(displayMode) == 'undefined') displayMode = 'block';
	if (getHandle(what).style.display == displayMode) {
		getHandle(what).style.display = 'none';
	}
	else {
		getHandle(what).style.display = displayMode;
	}
}

function findPos(obj) {
	var left = !!obj.offsetLeft ? obj.offsetLeft : 0;
	var top = !!obj.offsetTop ? obj.offsetTop : 0;
	while(obj = obj.offsetParent) {
		left += !!obj.offsetLeft ? obj.offsetLeft : 0;
		top += !!obj.offsetTop ? obj.offsetTop : 0;
	}
	return{x:left, y:top};
}




/*******************************************************
 * 
 * Tooltip Functions
 * 
 ******************************************************/

//position of the tooltip relative to the mouse in pixels//
var offsetx = 0;
var offsety =  17;
var tooltipwidth = 80;

function newelement(newid) { 
	if(document.createElement) { 
		var el = document.createElement('div'); 
		el.id = newid;     
		with(el.style) { 
			display = 'none';
			position = 'absolute';
		} 
		el.innerHTML = '&nbsp;'; 
		document.body.appendChild(el); 
	} 
} 

var ie5 = (document.getElementById && document.all); 
var ns6 = (document.getElementById && !document.all); 
var ua = navigator.userAgent.toLowerCase();
var isapple = (ua.indexOf('applewebkit') != -1 ? 1 : 0);

function getmouseposition(e) {
	if(document.getElementById) {
		var iebody=(document.compatMode && document.compatMode != 'BackCompat') ? document.documentElement : document.body;
		pagex = (isapple == 1 ? 0:(ie5)?iebody.scrollLeft:window.pageXOffset);
		pagey = (isapple == 1 ? 0:(ie5)?iebody.scrollTop:window.pageYOffset);
		mousex = (ie5)?event.x:(ns6)?clientX = e.clientX:false;
		mousey = (ie5)?event.y:(ns6)?clientY = e.clientY:false;
		
		if (parseInt(navigator.appVersion) > 3) {
			if (navigator.appName=="Netscape") {
				windowx = window.innerWidth - 35;
				windowy = window.innerHeight;
			}
			if (navigator.appName.indexOf("Microsoft") != -1) {
				windowx = document.body.offsetWidth - 26;
				windowy = document.body.offsetHeight;
			}
		}
		
		var lixlpixel_tooltip = document.getElementById('tooltip');
		//window.status='MX=' + mousex + ' MY=' + mousey + ' PX=' + pagex + ' PY=' + pagey + ' WX=' + windowx + ' WY=' + windowy + ' ' + lixlpixel_tooltip.offsetWidth;
		
		lixlpixel_tooltip.style.width = tooltipwidth + 'px';
		
		if ((mousex + pagex + offsetx + tooltipwidth) > windowx) {
			lixlpixel_tooltip.style.left = (windowx - tooltipwidth) + 'px';
		}
		else {
			lixlpixel_tooltip.style.left = (mousex+pagex+offsetx) + 'px';
		}
		lixlpixel_tooltip.style.top = (mousey+pagey+offsety) + 'px';
	}
}

function tooltipShow(tip, newTooltipWidth) {
	tooltipwidth = newTooltipWidth;
	if(!document.getElementById('tooltip')) newelement('tooltip');
	var lixlpixel_tooltip = document.getElementById('tooltip');
	lixlpixel_tooltip.innerHTML = tip;
	lixlpixel_tooltip.style.display = 'block';
	document.onmousemove = getmouseposition;
}

function tooltipHide() {
	document.getElementById('tooltip').style.display = 'none';
}





/*******************************************************
 * 
 * AJAX Basic Functions
 * 
 ******************************************************/

var ajaxIsBusy = false;

function getAjax() {
	var xmlHttp = false;
	try {
		//Firefox, Opera 8.0+, Safari
		xmlHttp = new XMLHttpRequest();
	}
	catch (e) {
		//Internet Explorer
		try {
			xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e) {
			try {
				xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (e) {
				
			}
		}
	}
	return xmlHttp;
}

function ajaxObject(url, callback) {
	var that = this;
		//workaround for some javascript idiosyncrocies
	var updating = false;
		//set to true if this object is already working on a request
	
	this.update = function(params) {
		//calling object.update(params) initiates the server call
		if (updating == true) { return false; }
			//abort if we're already processing a call
		updating = true;
			//set the updating flag
		var AJAX = getAjax();
			//get an xmlHttpRequest object
		if (!AJAX) {
			alert("Your browser does not support AJAX. Please upgrade your browser");
			return false;
		}
		else {
			AJAX.onreadystatechange = function() {
				//when the browser has the request info..
				if (AJAX.readyState == 4 || AJAX.readyState == "complete") {
					//if the complete flag is set...
					/*
					if (typeof LayerID != 'undefined') {
						//if a layer/div/span/object was passed when this 
						//object was created, set the response as its innerHTML
						LayerID.innerHTML = AJAX.responseText;
					}
					*/
					updating = false;
						//set the updating flag to false so we can do a new request
					that.callback(AJAX.responseText,AJAX.status,AJAX.responseXML);
						//that.callback();
						//call the post-processing function
					delete AJAX;
						//delete the AJAX object since it's done
				}
				//end Ajax readystate check
			}                                                           	
			//end create post-process fucntion block
			var timestamp = new Date();
				//get a new date (this will make the url unique)
			var uri = encodeURI(urlCall + '?nocache=' + (timestamp * 1));
				//append date to url (so the browser doesn't cache the call)
			AJAX.open("POST", uri, true);
				//open the url this object was set-up with
			AJAX.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	      	AJAX.setRequestHeader("Content-length", uri.length);
	      	AJAX.setRequestHeader("Connection", "close");
      			//set some headers
			AJAX.send(params);
				//send the request
			return true;
				//everything went well
		}
	}
	//do something with constructor parameters
	/*
	var LayerID;
	if (typeof layer != 'undefined') {
		LayerID = document.getElementById(layer);
	}
	*/
	var urlCall = url;
	this.callback = callback || function() {}
		//post-processing call
}

function evalJavascript(scanThis) {
	var jsSpans = new Array();
	for (var i = 0; i < scanThis.length; i++) {
		if ((scanThis.substr(i, 7) == '<script') && (scanThis.indexOf('<' + '/script>', i) > -1)) {
			jsSpans[jsSpans.length] = scanThis.substring((scanThis.indexOf(">", i) + 1), (scanThis.indexOf("<" + "/script>", i)));
			i = scanThis.indexOf("<" + "/script>", i) + 8;
		}
	}
	if (jsSpans.length > 0) {
		for (var i = 0; i < jsSpans.length; i++) {
			//alert("evaluating: \n\n" + jsSpans[i]);
			eval(jsSpans[i]);
		}
	}
}

function isAjaxBusy() {
	if (ajaxIsBusy == false) {
		return false;
	}
	else {
		return true;
	}
}




/*******************************************************
 * 
 * AJAX "Worker" Functions
 * 
 ******************************************************/

var idOfTargetDivForAjaxResponse = 'ajaxEmailForm';
var idOfEmailInput = 'ajaxEmail';
var idOfNameInput = 'ajaxName';
var idOfBDMonthInput = 'ajaxBDMonth';
var idOfBDDayInput = 'ajaxBDDay';
var idOfBDYearInput = 'ajaxBDYear';
var idOfGenderInput = 'ajaxGender';
				
function getAjaxEmail() {
	if (isAjaxBusy()) {
		alert ('Please wait until your most recent request finishes processing before making another request');
	}
	else {
		var v_email = document.getElementById(idOfEmailInput).value.trim();
		var v_name = document.getElementById(idOfNameInput).value.trim();
		var handle_birthdateMonth = document.getElementById(idOfBDMonthInput);
		var handle_birthdateDay = document.getElementById(idOfBDDayInput);
		var handle_birthdateYear = document.getElementById(idOfBDYearInput);
		var v_gender = document.getElementById(idOfGenderInput).value.trim();
		
		document.getElementById(idOfEmailInput).value = v_email;
		document.getElementById(idOfNameInput).value = v_name;
		document.getElementById(idOfGenderInput).value = v_gender;
		if (v_email.length == 0) {
			alert('Please supply an email address');
			document.getElementById(idOfEmailInput).focus();
		}
		else if (v_name.length == 0) {
			alert('Please supply your name');
			document.getElementById(idOfNameInput).focus();
		}
		else {
			var birthdate = handle_birthdateMonth.options[handle_birthdateMonth.selectedIndex].value + "/" + handle_birthdateDay.options[handle_birthdateDay.selectedIndex].value + "/" + handle_birthdateYear.options[handle_birthdateYear.selectedIndex].value;
			div = document.getElementById(idOfTargetDivForAjaxResponse);
			div.innerHTML = loadingAjaxTopLevel;
			var params = "langId=" + langId + "&storeId=" + storeId + "&catalogId=" + catalogId + "&";
			params += "email=" + encodeURIComponent(v_email) + "&name=" + encodeURIComponent(v_name) + "&birthdate=" + encodeURIComponent(birthdate) + "&gender=" + encodeURIComponent(v_gender);
			var ajaxObject1 = new ajaxObject('/webapp/wcs/stores/servlet/AJAXEmailSignup', ajaxResponseEmail);
			ajaxIsBusy = true;
			ajaxObject1.update(params);
		}
	}
}

function ajaxResponseEmail(response, status, responseXML) {
	div = document.getElementById(idOfTargetDivForAjaxResponse);
	div.innerHTML = response;
	evalJavascript(response);
	ajaxIsBusy = false;
}



/*******************************************************
 * 
 * Form Validation Functions
 * 
 ******************************************************/



/*
Portions of isRFC822ValidEmail function are copyright (C) 2006  Ross Kendall - http://rosskendall.com
Portions of isRFC822ValidEmail function are copyright (C) 1993-2005 Cal Henderson - http://iamcal.com
Licenced under Creative Commons _or_ GPL
Creative Commons Attribution-ShareAlike 2.5 License: http://creativecommons.org/licenses/by-sa/2.5/
GPL: http://www.gnu.org/copyleft/gpl.html
*/
function isRFC822ValidEmail(emailAddy) {
	var sQtext = '[^\\x0d\\x22\\x5c\\x80-\\xff]';
	var sDtext = '[^\\x0d\\x5b-\\x5d\\x80-\\xff]';
	var sAtom = '[^\\x00-\\x20\\x22\\x28\\x29\\x2c\\x2e\\x3a-\\x3c\\x3e\\x40\\x5b-\\x5d\\x7f-\\xff]+';
	var sQuotedPair = '\\x5c[\\x00-\\x7f]';
	var sDomainLiteral = '\\x5b(' + sDtext + '|' + sQuotedPair + ')*\\x5d';
	var sQuotedString = '\\x22(' + sQtext + '|' + sQuotedPair + ')*\\x22';
	var sDomain_ref = sAtom;
	var sSubDomain = '(' + sDomain_ref + '|' + sDomainLiteral + ')';
	var sWord = '(' + sAtom + '|' + sQuotedString + ')';
	var sDomain = sSubDomain + '(\\x2e' + sSubDomain + ')*';
	var sLocalPart = sWord + '(\\x2e' + sWord + ')*';
	var sAddrSpec = sLocalPart + '\\x40' + sDomain; // complete RFC822 email address spec
	var sValidEmail = '^' + sAddrSpec + '$'; // as whole string
	
	var reValidEmail = new RegExp(sValidEmail);
	if (reValidEmail.test(emailAddy)) {
		return true;
	}
	return false;
}

function checkInputSetToLength(idOrHandle, errorDiv, minimumLength) {
	if (typeof(minimumLength) == 'undefined') minimumLength = 1;
	if (getHandle(idOrHandle).value.length < minimumLength) {
		if (typeof(errorDiv) != 'undefined') show(errorDiv);
		return false;
	}
	else {
		if (typeof(errorDiv) != 'undefined') hide(errorDiv);
		return true;
	}
}

function checkEmailValid(idOrHandle, errorDiv) {
	if ((getHandle(idOrHandle).value.length < 1) || (!isRFC822ValidEmail(getHandle(idOrHandle).value))) {
		if (typeof(errorDiv) != 'undefined') show(errorDiv);
		return false;
	}
	else {
		if (typeof(errorDiv) != 'undefined') hide(errorDiv);
		return true;
	}
}

function checkSelectFieldChosen(idOrHandle, errorDiv) {
	if (getHandle(idOrHandle).selectedIndex == 0) {
		if (typeof(errorDiv) != 'undefined') show(errorDiv);
		return false;
	}
	else {
		if (typeof(errorDiv) != 'undefined') hide(errorDiv);
		return true;
	}
}

function compareInputTextFields(idOrHandle1, idOrHandle2, errorDiv, caseSensitive) {
	if (typeof(caseSensitive) == 'undefined') caseSensitive = true;
	if (caseSensitive) {
		if (getHandle(idOrHandle1).value != getHandle(idOrHandle2).value) {
			if (typeof(errorDiv) != 'undefined') show(errorDiv);
			return false;
		}
		else {
			if (typeof(errorDiv) != 'undefined') hide(errorDiv);
			return true;
		}
	}
	else {
		if (getHandle(idOrHandle1).value.toLowerCase() != getHandle(idOrHandle2).value.toLowerCase()) {
			if (typeof(errorDiv) != 'undefined') show(errorDiv);
			return false;
		}
		else {
			if (typeof(errorDiv) != 'undefined') hide(errorDiv);
			return true;
		}
	}
}



/*******************************************************
 * 
 * Other Custom Functions
 * 
 ******************************************************/

function toggleAjaxEmailForm() {
	handleForm = document.getElementById('ajaxEmailForm');
	handleImg = document.getElementById('ajaxEmailFormImg');
	imgPos = findPos(handleImg);
	toggle(handleForm);
	handleForm.style.left = (imgPos.x - 37) + 'px';
	handleForm.style.top = (imgPos.y - 97) + 'px';
}

/*******************************************************
 * 
 * Get contents of external Website
 * 
 ******************************************************/

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;
}


