function rssNav(rssPos){
//	lftPos=rssPos-1;
//	rtPos=rssPos+1;
//	intResults=arrRSS.length-1;
//	
//	if (lftPos<0) lftPos=intResults;
//	if (rtPos>intResults) rtPos=0;
//	
//	html="<a href="+arrRSS[rssPos].link+"' class='rss' target='_blank'>"+arrRSS[rssPos].channel+":&nbsp;&nbsp;&nbsp;"+arrRSS[rssPos].title+"</a>";
//	document.getElementById('rssLeft').innerHTML=html;
//	html="<a target='_blank' href="+arrRSS[rssPos].link+"' class='rss' style='font-size:11px;'>[Read More]</a>&nbsp;&nbsp;";
//	html+="<a href='javascript:rssNav("+lftPos+");' class='outlineButton'><</a>&nbsp;";
//	html+="<a href='javascript:rssNav("+rtPos+");' class='outlineButton'>></a>";
//	document.getElementById('rssRight').innerHTML=html;	
}
function swapContent(file){
	//code that handles actual ajax call is at bottom of index.php
	YAHOO.util.History.navigate("page", file);
	return false;		
}
function loadDialog(file,strHead,post) {		 
	var AjaxCall = {
			handleSuccess:function(o){
				this.processResult(o);
			},
			handleFailure:function(o){
				alert('Failed to load.');
			},
			processResult:function(o){
				var returnSplit=o.responseText.split('~||~');
				var content = returnSplit[0];
				var js = returnSplit[1];				
				loadPanel = new YAHOO.widget.Panel("dlgLoading", { visible:true, draggable:true, constraintoviewport:true, modal:true, close:true, underlay:'shadow', fixedcenter:true} );
				if (strHead) loadPanel.setHeader(strHead);
				loadPanel.setBody(content);
				loadPanel.render(document.body);
				if (js) eval(js);
				if (file.indexOf('dlg')){
					if (activeForm) {
						if (activeForm.postDialog) activeForm.postDialog();
					}
				}
				_gaq.push(['_trackPageview', '/'+file]);
			},
			startRequest:function(){
				if(!post){
					YAHOO.util.Connect.asyncRequest('GET', 'content/'+file, callback);
				} else {
					YAHOO.util.Connect.asyncRequest('POST', 'content/'+file, callback, post);
				}
			}
		};
		var callback = {
			success:AjaxCall.handleSuccess,
			failure:AjaxCall.handleFailure,
			scope:AjaxCall
		};
		AjaxCall.startRequest();	
}
//FORM FUNCTIONS FOLLOW
limitText=function(id, max, e){
//Limit characters in a form filed.  id represents field, max the limit, and e the browser event
	var field = document.getElementById(id);
	//i represents # of chars remaining
	var i = max - field.value.length;
	//k represents the key pressed
	var k = window.event || e;
	k = k.which || k.keyCode;
	//ignore left and right arrow
	if (k == 37 | k == 39) return false;
	//stop typing if max has been reached.
	if (field.value.length > max){
		field.value = field.value.substring(0, max);
		var warningStr = 'You have reached the maximum number of characters.';
		warningText(warningStr, field);
	//this condition will put warning text if limit is more than 5 and user is approaching limit
	} else if (max > 5) {
		var w = max / 3;
		if (i < w) {
			var warningStr = 'You have '+i+' characters remaining.';
			warningText(warningStr, field);
		} else {
			if (field.value.length!=0) warningText(0);
		}
	//if neither of above conditions are true, destroy warning element once a character is typed
	} else {
		if (field.value.length!=0) warningText(0);
	}	
};
warningText=function(warningStr, el){
//Controls the warning text providing useful feedback to the user
	//Remove warning node if it already exists
	if (document.getElementById('warning')){
		var node = document.getElementById('warning');
		document.getElementById('content').removeChild(node);
	}
	//If warning text is available, create and display a new node. 
	if (warningStr){
		var curtop = 0;
		var curleft = 0;
		field = el;
		var txtBox=document.createElement('div');
		txtBox.id='warning';
		txtBox.style.float='left';
		txtBox.style.position='absolute';
		txtBox.className = 'warn';
		document.getElementById('content').appendChild(txtBox);
		var txtWarn=document.createTextNode(warningStr);
		document.getElementById('warning').appendChild(txtWarn);
		var region = YAHOO.util.Dom.getRegion(field);
		var x=region.left;
		YAHOO.util.Dom.setX('warning',x);
		var y=region.bottom;
		YAHOO.util.Dom.setY('warning',y+5);
	}
};
mainError=function(strMessage, id){
//Used when an error is found during validation that prevents form from submitting.
	//id of the element to attach the messsage to defaults to formHead if not specified.
	if (!id) id='formHead';
	//Remove any existing errors if they exist
	if (document.getElementById('mainError')){
		var node = document.getElementById('mainError');
		document.getElementById(id).removeChild(node);
	}
	//If a message is available, create and display the same.
	if (strMessage){			
		var txtBox=document.createElement('div');
		txtBox.id='mainError';
		var txtError=document.createTextNode(strMessage);
		txtBox.className = 'error';
		document.getElementById(id).appendChild(txtBox);
		document.getElementById('mainError').appendChild(txtError);		
		scroll(0,0);
	}
};
function fixNumber(id, strFormat, intDec, blnNeg){
//Strips away non-numeric data and returns a number formatted as specified
//id represents the id of the field we are working with
//strFormat will format string (see switch statement for valid options)
//intDec recpresents # of decimal places to display for a fixed format
//blnNeg controls whether or not negative values are allowed. Default behavior is NOT to allow negative values
	//create pointer to our form field
	var field=document.getElementById(id);
	//create additional variables for string manipulation
	var beginStr = field.value;
	var endStr = '';
	var negative = false;
	//exit if original string is blank
	if (beginStr == '')	return false;
	//Stripping away invalid characters
	endStr=stripNonNumeric(beginStr);
	//Checking to see if any numbers are left.
	if (endStr != ''){
		if (!isNaN(endStr)){
			//Check for negative
			if(!blnNeg){
				if (endStr<0){
					warningText("Negative numbers are not allowed.",field);
					field.value = "";
					return 1;	
				}
			}
			//Fix decimals
			if (strFormat=="currency") intDec=2;
			//if(!intDec) inDec=0
			endStr=parseFloat(endStr);
			if (intDec>0) endStr = Math.round(endStr*Math.pow(10,intDec))/Math.pow(10,intDec);
			endStr = endStr.toFixed(intDec);
			//Format string
			switch(strFormat){
				case "currency":
					//Add $ and commas
					endStr=addCommas(endStr);
					endStr="$"+endStr;
					break;
				case "general":
					//adds commas
					if (intDec>=4){
						var x=addCommas(endStr.substring(0,endStr.indexOf(".")));
						endStr=x+endStr.substring(endStr.indexOf("."));
					} else {
						endStr=addCommas(endStr);
					}
					break;
				default:
					//defaults to no formatting making number database ready
			}
			field.value=endStr;
		} else {
			warningText("Not a valid number.",field);
			field.value = "";
			return 1;			
		}
	} else {
		//Create error code for invalid entries
		if(beginStr!=''){
			warningText("Not a valid number.",field);
			field.value = "";
			return 1;
		}
	}
	//clear error if correct
	warningText();
}
function stripNonNumeric( sValue ){
	var nValue="";
	var validChars = "0123456789.-";
	for (var n=0;n<sValue.length;n++){
		if (validChars.indexOf(sValue.charAt(n)) > -1) nValue += sValue.charAt(n);
	}
	return nValue;
}
function addCommas( sValue ){
	var sRegExp = new RegExp('(-?[0-9]+)([0-9]{3})');
	
	while(sRegExp.test(sValue)) {
		sValue = sValue.replace(sRegExp, '$1,$2');
	}
	return sValue;
}
fixDate=function(id, blnFuture){
//Validates dates and udpates to desired format
//id represents the id of the field we are working with
//blnFuture controls whether dates in the future are allowed.  The default behavior is to disallow future dates.	
	var field=document.getElementById(id);
	if (field.value=='') return true;
	var d=parseDate(field.value);
	if(d==null){
		//testing for valid date
		warningText("Not a valid date.",field);
		field.value='';
		return false;
	} else {
		//testing for future date
		var curdate = new Date();
		if (!blnFuture){
			if (d > curdate){
				warningText("You cannot use a future date.",field);
				field.value='';
				return false;
			}
		}
	}
	//correct formatting
	field.value=formatDate(d,'M/d/yyyy');
	//clear warning text if succesful
	warningText();
};
sendMail=function(subject,body,to,from,funct){
	var AjaxCall = {
		handleSuccess:function(o){
			this.processResult(o);
		},
		handleFailure:function(o){
			alert('Failed to send email.');
		},
		processResult:function(o){
			if(funct) funct();
		},
		startRequest:function(){
			//creating json to supply the email info
			var json = new Object();
			var post="";
			post+="sender="+escape(from?from:'info@innovativeclaims.com');
			post+="&to="+escape(to?to:'info@innovativeclaims.com');
			post+="&subject="+escape(subject?subject:'No Subject');
			post+="&body="+escape(body?body:'No Content');
			YAHOO.util.Connect.asyncRequest('POST', 'ajax/sendMail.php', callback, post);
		}
	};
	var callback = {
			success:AjaxCall.handleSuccess,
			failure:AjaxCall.handleFailure,
			scope:AjaxCall
	};
	AjaxCall.startRequest();
};
sqlReady=function(id,format,val){
//Converts data into an sql friendly format
	//val is optional and is overwritten if not obtaining value from an element
	if(id)val=document.getElementById(id).value;
	
	switch (format){
		case "text":
			if (!val) return val;
			//mimics php's addslashes
			val=val.replace(/[\\"']/g, '\\$&').replace(/\u0000/g, '\\0');
			break;
		case "date":
			if (!val) return val;
			val = formatDate(parseDate(val),'yyyy-MM-dd');
			break;
		case "number":
			if (!val) return 0;
			val = stripNonNumeric(val);
			break;
	}
	return val;
};
runSQL=function(sql, resFunct){
//Will run sql on the server and return appropriate results
	var AjaxCall = {
		handleSuccess:function(o){
			this.processResult(o);
		},
		handleFailure:function(o){
			sendMail('SQL ERROR','The following SQL did not run:'+sql);
		},
		processResult:function(o){
			var responseText=eval(o.responseText);
			//Alert ICS if error running SQL
			if (responseText[0]!=0){
				sendMail('SQL FAILED','The following SQL did not run:'+sql+"<BR><BR>"+responseText[0]);
			}
			if (resFunct) resFunct(responseText);
		},
		startRequest:function(){
			var post="sql="+escape(sql);
			YAHOO.util.Connect.asyncRequest('POST','ajax/sql.php',callback,post);
		}
	};
	var callback = {
		success:AjaxCall.handleSuccess,
		failure:AjaxCall.handleFailure,
		scope:AjaxCall
	};
	AjaxCall.startRequest();
};
//Object and code pertinent to handling uploads
//To use code the following divs must exist: uploadError, uploadResult, uploadSpacer, uploadProgress
upload=new Object;
upload.startUpload=function(formID){
//Notify user we have started uploading
	if (formID) {
		document.getElementById('formID').value = formID;
		document.getElementById('uploadProgress').innerHTML="&nbsp;Uploading...";
		return true;
	}
};
upload.stopUpload=function(json){
//This function runs once upload is complete
	var fileName=json.fileName;
	var error=json.uploadResult;
	//remove existing errors and spacers
	if (document.getElementById('uploadError')){
		var d=document.getElementById('uploadError');
		document.getElementById('uploadResult').removeChild(d);
	}
	if (document.getElementById('uploadSpacer')){
		var d=document.getElementById('uploadSpacer');
		document.getElementById('uploadResult').removeChild(d);
	}	
	//if upload succeeds, update screen accordingly
	if (json.success==1){
		document.getElementById('uploadResult').innerHTML += "<div id='upload"+fileName+"'>"+fileName+"</div>";
		if (!upload.uploads[json.ID])upload.uploads[json.ID]=new Object();
		upload.uploads[json.ID]=json;
	} else {
	//if upload fails, present error
		document.getElementById('uploadResult').innerHTML = "<div id='uploadError' class='error'>Error: "+error+"</div>"+document.getElementById('uploadResult').innerHTML;
	}
	//add spacer
	document.getElementById('uploadResult').innerHTML += "<div id='uploadSpacer'><BR></div>";
	//clear loading
	document.getElementById('uploadProgress').innerHTML='';
	//update list of files uploaded
	var fileNode=document.getElementById('fileNode');
	fileNode.removeChild(fileNode.childNodes[0]);
	fileNode.innerHTML="<input type='file' name='uploadFile' id='uploadFile' size='0' />";
	return true;
};
upload.uploads=new Object();
//Date Conversion Code www.mattkruse.com
var MONTH_NAMES=new Array('January','February','March','April','May','June','July','August','September','October','November','December','Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec');
var DAY_NAMES=new Array('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday','Sun','Mon','Tue','Wed','Thu','Fri','Sat');
function LZ(x) {return(x<0||x>9?"":"0")+x;};

function formatDate(date,format) {
	format=format+"";
	var result="";
	var i_format=0;
	var c="";
	var token="";
	var y=date.getYear()+"";
	var M=date.getMonth()+1;
	var d=date.getDate();
	var E=date.getDay();
	var H=date.getHours();
	var m=date.getMinutes();
	var s=date.getSeconds();
	var yyyy,yy,MMM,MM,dd,hh,h,mm,ss,ampm,HH,H,KK,K,kk,k;
	// Convert real date parts into formatted versions
	var value=new Object();
	if (y.length < 4) {y=""+(y-0+1900);}
	value["y"]=""+y;
	value["yyyy"]=y;
	value["yy"]=y.substring(2,4);
	value["M"]=M;
	value["MM"]=LZ(M);
	value["MMM"]=MONTH_NAMES[M-1];
	value["NNN"]=MONTH_NAMES[M+11];
	value["d"]=d;
	value["dd"]=LZ(d);
	value["E"]=DAY_NAMES[E+7];
	value["EE"]=DAY_NAMES[E];
	value["H"]=H;
	value["HH"]=LZ(H);
	if (H==0){value["h"]=12;}
	else if (H>12){value["h"]=H-12;}
	else {value["h"]=H;}
	value["hh"]=LZ(value["h"]);
	if (H>11){value["K"]=H-12;} else {value["K"]=H;}
	value["k"]=H+1;
	value["KK"]=LZ(value["K"]);
	value["kk"]=LZ(value["k"]);
	if (H > 11) { value["a"]="PM"; }
	else { value["a"]="AM"; }
	value["m"]=m;
	value["mm"]=LZ(m);
	value["s"]=s;
	value["ss"]=LZ(s);
	while (i_format < format.length) {
		c=format.charAt(i_format);
		token="";
		while ((format.charAt(i_format)==c) && (i_format < format.length)) {
			token += format.charAt(i_format++);
			}
		if (value[token] != null) { result=result + value[token]; }
		else { result=result + token; }
		}
	return result;
}

//parseDate( date_string [, prefer_euro_format] )
//Returns a Date object or null if no patterns match.
function parseDate(val) {
	var preferEuro=(arguments.length==2)?arguments[1]:false;
	generalFormats=new Array('y-M-d','MMM d, y','MMM d,y','y-MMM-d','d-MMM-y','MMM d','m/d/yyyy h:mm a','m/d/yyyy HH:mm','m/d/yyyy H:mm');
	monthFirst=new Array('M/d/y','M-d-y','M.d.y','MMM-d','M/d','M-d','m/d/yyyy h:mm a','m/d/yyyy HH:mm','m/d/yyyy H:mm');
	dateFirst =new Array('d/M/y','d-M-y','d.M.y','d-MMM','d/M','d-M','d/m/yyyy h:mm a','m/d/yyyy HH:mm','m/d/yyyy H:mm');
	var checkList=new Array('generalFormats',preferEuro?'dateFirst':'monthFirst',preferEuro?'monthFirst':'dateFirst');
	var d=null;
	for (var i=0; i<checkList.length; i++) {
		var l=window[checkList[i]];
		for (var j=0; j<l.length; j++) {
			d=getDateFromFormat(val,l[j]);
			if (d!=0) { return new Date(d); }
			}
		}
	return null;
}

function parseTime(val) {
	generalFormats=new Array('M/d/y h:mm a','HH:mm:ss','hh:mm a','h:mm a','MMM d,y','y-MMM-d','d-MMM-y','MMM d');
	monthFirst=new Array('M/d/y','M-d-y','M.d.y','MMM-d','M/d','M-d');
	dateFirst =new Array('d/M/y','d-M-y','d.M.y','d-MMM','d/M','d-M');
	var checkList=new Array('generalFormats','monthFirst','monthFirst');
	var d=null;
	for (var i=0; i<checkList.length; i++) {
		var l=window[checkList[i]];
		for (var j=0; j<l.length; j++) {
			d=getDateFromFormat(val,l[j]);
			if (d!=0) { return new Date(d); }
			}
		}
	return null;
}

function getDateFromFormat(val,format) {
	val=val+"";
	format=format+"";
	var i_val=0;
	var i_format=0;
	var c="";
	var token="";
	var token2="";
	var x,y;
	var now=new Date();
	var year=now.getFullYear();
	var month=now.getMonth()+1;
	var date=1;
	var hh=now.getHours();
	var mm=now.getMinutes();
	var ss=now.getSeconds();
	var ampm="";
	
	while (i_format < format.length) {
		// Get next token from format string
		c=format.charAt(i_format);
		token="";
		while ((format.charAt(i_format)==c) && (i_format < format.length)) {
			token += format.charAt(i_format++);
			}
		// Extract contents of value based on format token
		if (token=="yyyy" || token=="yy" || token=="y") {
			if (token=="yyyy") { x=4;y=4; }
			if (token=="yy")   { x=2;y=2; }
			if (token=="y")    { x=2;y=4; }
			year=_getInt(val,i_val,x,y);
			if (year==null) { return 0; }
			i_val += year.length;
			if (year.length==2) {
				if (year > 70) { year=1900+(year-0); }
				else { year=2000+(year-0); }
				}
			}
		else if (token=="MMM"||token=="NNN"){
			month=0;
			for (var i=0; i<MONTH_NAMES.length; i++) {
				var month_name=MONTH_NAMES[i];
				if (val.substring(i_val,i_val+month_name.length).toLowerCase()==month_name.toLowerCase()) {
					if (token=="MMM"||(token=="NNN"&&i>11)) {
						month=i+1;
						if (month>12) { month -= 12; }
						i_val += month_name.length;
						break;
						}
					}
				}
			if ((month < 1)||(month>12)){return 0;}
			}
		else if (token=="EE"||token=="E"){
			for (var i=0; i<DAY_NAMES.length; i++) {
				var day_name=DAY_NAMES[i];
				if (val.substring(i_val,i_val+day_name.length).toLowerCase()==day_name.toLowerCase()) {
					i_val += day_name.length;
					break;
					}
				}
			}
		else if (token=="MM"||token=="M") {
			month=_getInt(val,i_val,token.length,2);
			if(month==null||(month<1)||(month>12)){return 0;}
			i_val+=month.length;}
		else if (token=="dd"||token=="d") {
			date=_getInt(val,i_val,token.length,2);
			if(date==null||(date<1)||(date>31)){return 0;}
			i_val+=date.length;}
		else if (token=="hh"||token=="h") {
			hh=_getInt(val,i_val,token.length,2);
			if(hh==null||(hh<1)||(hh>12)){return 0;}
			i_val+=hh.length;}
		else if (token=="HH"||token=="H") {
			hh=_getInt(val,i_val,token.length,2);
			if(hh==null||(hh<0)||(hh>23)){return 0;}
			i_val+=hh.length;}
		else if (token=="KK"||token=="K") {
			hh=_getInt(val,i_val,token.length,2);
			if(hh==null||(hh<0)||(hh>11)){return 0;}
			i_val+=hh.length;}
		else if (token=="kk"||token=="k") {
			hh=_getInt(val,i_val,token.length,2);
			if(hh==null||(hh<1)||(hh>24)){return 0;}
			i_val+=hh.length;hh--;}
		else if (token=="mm"||token=="m") {
			mm=_getInt(val,i_val,token.length,2);
			if(mm==null||(mm<0)||(mm>59)){return 0;}
			i_val+=mm.length;}
		else if (token=="ss"||token=="s") {
			ss=_getInt(val,i_val,token.length,2);
			if(ss==null||(ss<0)||(ss>59)){return 0;}
			i_val+=ss.length;}
		else if (token=="a") {
			if (val.substring(i_val,i_val+2).toLowerCase()=="am") {ampm="AM";}
			else if (val.substring(i_val,i_val+2).toLowerCase()=="pm") {ampm="PM";}
			else {return 0;}
			i_val+=2;}
		else {
			if (val.substring(i_val,i_val+token.length)!=token) {return 0;}
			else {i_val+=token.length;}
			}
		}
	// If there are any trailing characters left in the value, it doesn't match
	if (i_val != val.length) { return 0; }
	// Is date valid for month?
	if (month==2) {
		// Check for leap year
		if ( ( (year%4==0)&&(year%100 != 0) ) || (year%400==0) ) { // leap year
			if (date > 29){ return 0; }
			}
		else { if (date > 28) { return 0; } }
		}
	if ((month==4)||(month==6)||(month==9)||(month==11)) {
		if (date > 30) { return 0; }
		}
	// Correct hours value
	if (hh<12 && ampm=="PM") { hh=hh-0+12; }
	else if (hh>11 && ampm=="AM") { hh-=12; }
	var newdate=new Date(year,month-1,date,hh,mm,ss);
	return newdate.getTime();
}

//Utility functions for parsing in getDateFromFormat()
function _isInteger(val) {
	var digits="1234567890";
	for (var i=0; i < val.length; i++) {
		if (digits.indexOf(val.charAt(i))==-1) { return false; }
		}
	return true;
}
function _getInt(str,i,minlength,maxlength) {
	for (var x=maxlength; x>=minlength; x--) {
		var token=str.substring(i,i+x);
		if (token.length < minlength) { return null; }
		if (_isInteger(token)) { return token; }
		}
	return null;
}
function json_encode(mixed_val) {
// Returns the JSON representation of a value  
    var indent;
    var value = mixed_val;
    var i;

    var quote = function (string) {
        var escapable = /[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g;
        var meta = {    // table of character substitutions
            '\b': '\\b',
            '\t': '\\t',
            '\n': '\\n',
            '\f': '\\f',
            '\r': '\\r',
            '"' : '\\"',
            '\\': '\\\\'
        };

        escapable.lastIndex = 0;
        return escapable.test(string) ?
        '"' + string.replace(escapable, function (a) {
            var c = meta[a];
            return typeof c === 'string' ? c :
            '\\u' + ('0000' + a.charCodeAt(0).toString(16)).slice(-4);
        }) + '"' :
        '"' + string + '"';
    };

    var str = function(key, holder) {
        var gap = '';
        var indent = '    ';
        var i = 0;          // The loop counter.
        var k = '';          // The member key.
        var v = '';          // The member value.
        var length = 0;
        var mind = gap;
        var partial = [];
        var value = holder[key];

        // If the value has a toJSON method, call it to obtain a replacement value.
        if (value && typeof value === 'object' &&
            typeof value.toJSON === 'function') {
            value = value.toJSON(key);
        }
        
        // What happens next depends on the value's type.
        switch (typeof value) {
            case 'string':
                return quote(value);

            case 'number':
                // JSON numbers must be finite. Encode non-finite numbers as null.
                return isFinite(value) ? String(value) : 'null';

            case 'boolean':
            case 'null':
                // If the value is a boolean or null, convert it to a string. Note:
                // typeof null does not produce 'null'. The case is included here in
                // the remote chance that this gets fixed someday.

                return String(value);

            case 'object':
                // If the type is 'object', we might be dealing with an object or an array or
                // null.
                // Due to a specification blunder in ECMAScript, typeof null is 'object',
                // so watch out for that case.
                if (!value) {
                    return 'null';
                }

                // Make an array to hold the partial results of stringifying this object value.
                gap += indent;
                partial = [];

                // Is the value an array?
                if (Object.prototype.toString.apply(value) === '[object Array]') {
                    // The value is an array. Stringify every element. Use null as a placeholder
                    // for non-JSON values.

                    length = value.length;
                    for (i = 0; i < length; i += 1) {
                        partial[i] = str(i, value) || 'null';
                    }

                    // Join all of the elements together, separated with commas, and wrap them in
                    // brackets.
                    v = partial.length === 0 ? '[]' :
                    gap ? '[\n' + gap +
                    partial.join(',\n' + gap) + '\n' +
                    mind + ']' :
                    '[' + partial.join(',') + ']';
                    gap = mind;
                    return v;
                }

                // Iterate through all of the keys in the object.
                for (k in value) {
                    if (Object.hasOwnProperty.call(value, k)) {
                        v = str(k, value);
                        if (v) {
                            partial.push(quote(k) + (gap ? ': ' : ':') + v);
                        }
                    }
                }

                // Join all of the member texts together, separated with commas,
                // and wrap them in braces.
                v = partial.length === 0 ? '{}' :
                gap ? '{\n' + gap + partial.join(',\n' + gap) + '\n' +
                mind + '}' : '{' + partial.join(',') + '}';
                gap = mind;
                return v;
        }
    };

    // Make a fake root object containing our value under the key of ''.
    // Return the result of stringifying the value.
    return str('', {
        '': value
    });
}
