var DHTML = (document.getElementById || document.all || document.layers);
var num = 0;

function _ (myvar) {
	return encodeURIComponent(myvar);	
}

function linkTo(url, div,doRunScriptTag) {

	if(!objExist(div)) {	
		alert('Unable to link to ('+div+').');
		return false;
	}
	divDsp(div,'inline');
	var ajax = new hollerBack('GET','/ajax.php'+url, '', div,null,doRunScriptTag);
	return ajax;
}

function removeEntity(url, div, msg) {

	if(!objExist(div)) {	
		alert('Unable to remove ('+div+').');
		return false;
	}
	
	var doThis = confirm(msg);
	
	if(doThis) {
		var ajax = new holler('POST','/ajax.php', url,  Effect.DropOut(div) );
	}
	
	return doThis;
}

function linkToToggle(url, div) {

	if(!objExist(div)) {	
		alert('Unable to link to ('+div+').');
		return false;
	}
	divDsp(div);
	var ajax = new hollerBack('GET','/ajax.php'+url, '', div);
}

function submitTo(formObj, action, div, url) {
	
	if(!objExist(div)) {	
		alert('Unable to submit this form '+div);
		return false;
	}
	var ajax = new hollerAtMe('POST', formObj, '/ajax.php?action='+action+'&'+url, div);
	return ajax;
}

function IsNumeric(sText){
   var ValidChars = "0123456789.";
   var IsNumber=true;
   var Char;
 
   for (i = 0; i < sText.length && IsNumber == true; i++) { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) IsNumber = false;
   }
   
   return IsNumber;
}

function redirect(url){
	window.location.href = url;
}

function getObj(name) {
	if( typeof(name) == 'object' ) {
		this.obj = name;
	} else {
		if (document.getElementById) {
			this.obj = document.getElementById(name);
		} else if (document.all)  {
			this.obj = document.all[name];
		} else if (document.layers)  {
			this.obj = document.layers[name];
		}
	}
	return this.obj;
}

function objExist(name) {

	if( typeof(name) == 'object' ) {
		return true;
	} else {
		if (document.getElementById) {
			this.obj = document.getElementById(name);
		} else if (document.all)  {
			this.obj = document.all[name];
		} else if (document.layers)  {
			this.obj = document.layers[name];
		}
		if(this.obj) {
			return true;
		} else {
			return false;
		}		
	}

}

// Object check added - 11/15/2006
function divDsp(el, dspState)
{
	if (!DHTML) return;
	
	if( typeof(el) == 'object' ) {
		x = el;
	} else {
		var x = new getObj(el);
	}
	x.style.display = (dspState)? (dspState=='inline'?'':dspState) : (x.style.display=='inline'||x.style.display=='') ? 'none' : '';
}

function popup(href,width,height,win_name) {
	    if (!win_name) win_name = 'none';
	    var window_features = "height="+height+",width="+width+",toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=0,copyhistory=0,dependent=1,top=100,left=100";
		win = window.open(href,win_name,window_features);
		if(win) {win.focus();}
		return false;
}

function selectAll(selectBox){
	for(var i=0;i<selectBox.options.length;i++){
		selectBox.options[i].selected = true;
	}
	return;
}

function unSelectAll(selectBox){
	for(var i=0;i<selectBox.options.length;i++){
		selectBox.options[i].selected = false;
	}
	return;
}

function selectAllChecked(selectBox){
	for(var i=0;i<selectBox.length;i++){
		selectBox[i].checked = true;
	}
	return;
}

function unSelectAllChecked(selectBox){
	for(var i=0;i<selectBox.length;i++){
		selectBox[i].checked = false;
	}
	return;
}

function numOnly(el) {
	var tmp 	= el.value.replace(/[^0-9.]/g,'');
	var argv 	= numOnly.arguments;
	if (argv.length==2) {
		if(tmp.length >= argv[1]) {
			el.form[(getIndex(el)+1) % el.form.length].focus();
		}
	}
	return el.value=tmp;
}

function getIndex(input) {
	var index = -1, i = 0, found = false;
	while (i < input.form.length && index == -1)
	if (input.form[i] == input)index = i;
	else i++;
	return index;
}


function checkAll(checkBox){
	for(var i=0;i<checkBox.length;i++){
		checkBox[i].checked = true;
	}
	return;
}

function unCheckAll(checkBox){
	for(var i=0;i<checkBox.length;i++){
		checkBox[i].checked = false;
	}
	return;
}



checked_toggle_check = 0;

function checkToggle(checkBox){
	if(checked_toggle_check==0){
		checkAll(checkBox);
		checked_toggle_check = 1;
	} else {
		unCheckAll(checkBox);
		checked_toggle_check = 0;
	}
	return;
}


// AJAX Functionality
/**
 * AJAX Call: submits parameters and call callback when request returns
 * @internal 7/26/06: Added abillity to run javascript from the response text
 * @internal 1/18/07: added doRunScriptTag as a argument
 *
 * @param string:method		"POST" or "GET" (USE POST PLEASE, GET IS BUGGY DUE TO BROWSER CACHING)
 * @param string:url		the url to post to i.e. "?action=ajax_save_user" or "?system_action=user_ajax_save"
 * @param string:parameters	what gets passed to the handeler and url format i.e. "user_id=56&user_name=john&..."
 * @param string:callback	the function to call when the request returns i.e. "hollered(56)"
 * @param bool:doRunScriptTag	if set to anything, then RunScriptTag is called on the response text
 */
function holler(method,url,parameters,callback,doRunScriptTag) {
	var method = method.toUpperCase();
	 try{
	    if (window.XMLHttpRequest) {
	        var xmlhttp = new XMLHttpRequest();
	    } else if (window.ActiveXObject) {
			try {
				var xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
			} catch (e) {
				try {
					var xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
				} catch (e) {}
			}
	    }
		
		if(method=="POST"){
			xmlhttp.open(method, url, true);
			xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");//application/x-www-form-urlencoded
			xmlhttp.setRequestHeader("Content-length", parameters.length);//parameters.length
			xmlhttp.setRequestHeader("Connection", "close");
			xmlhttp.send(parameters);
		} else{
			xmlhttp.open(method, url+'&'+parameters, true);
			xmlhttp.send(null);
		}
		
     } catch(e){
	 	alert('Error occurred while trying to process your request');
	 	return;
	 }
	
    xmlhttp.onreadystatechange = function () {
	  		if (xmlhttp.readyState == 4 || xmlhttp.readyState == 'complete') {
				if (xmlhttp.status == 200) {
					if(doRunScriptTag){
						RunScriptTag(xmlhttp.responseText); //run any script tag found in the response text
					}
					if (typeof callback == 'function') {
						callback(xmlhttp);
					} else { 
						eval(callback);
					}
				} else{
					alert('An error occurred while trying to return your request. \nError '+xmlhttp.status+': '+xmlhttp.statusText);
					return;
				}
		    }
		};
}

/**
 * AJAX Call: submits parameters and writes the response to thisObj
 * @internal 8/11/06: Added ability to not have a loading image
 * @internal 8/26/06: Added abillity to run javascript from the response text (RunScriptTag)
 * @internal 1/18/07: added doRunScriptTag as a argument
 *
 * @param string:method			"POST" or "GET" (USE POST PLEASE, GET IS BUGGY DUE TO BROWSER CACHING)
 * @param string:url			the url to post to i.e. "?action=ajax_save_user" or "?system_action=user_ajax_save"
 * @param string:parameters		what gets passed to the handeler and url format i.e. "user_id=56&user_name=john&..."
 * @param string:thisObj		the id of the html object to write back to i.e. "user_56_row" 
 * 								(NOTE: there are certian objects you cannot write back to, like <tr>)
 * @param string:LoadingTxt		"none","short","small", "long", some text you want to display, or leave it blank {see setLoadingDiv()}
 * @param bool:doRunScriptTag	if set to anything, then RunScriptTag is called on the response text
 */
function hollerBack(method,url,parameters,thisObj,LoadingTxt,doRunScriptTag) {
	 var xmlhttp 	= null;
	 var method 	= method.toUpperCase();
     var self = this;
	 try{
	 
	    if (window.XMLHttpRequest) {
	        var xmlhttp = new XMLHttpRequest();
	    } else if (window.ActiveXObject) {
			try {
				var xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
			} catch (e) {
				try {
					var xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
				} catch (e) {}
			}
	    }
		
		if(method=="POST"){
			xmlhttp.open(method, url, true);
			xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
			xmlhttp.setRequestHeader("Content-length", parameters.length);
			xmlhttp.setRequestHeader("Connection", "close");
			xmlhttp.send(parameters);
		} else{
			xmlhttp.open(method, url+'&'+parameters, true);
			xmlhttp.setRequestHeader("Pragma", "no-cache");
			xmlhttp.send(null);
		}
		
     } catch(e){
	 	alert('Error occurred while trying to process your request');
	 	return;
	 }


 	if (objExist(thisObj)) { 
		var x = new getObj(thisObj);
	} else if (typeof thisObj != "string") {
		var x = thisObj;
	}
 
	setLoadingDiv(x,LoadingTxt);
 	
	 
    xmlhttp.onreadystatechange = function () {
			
		

		if (xmlhttp.readyState == 4 || xmlhttp.readyState == 'complete') {

			if(doRunScriptTag){
				RunScriptTag(xmlhttp.responseText); //run any script tag found in the response text
			}
			
			//try {
				x.innerHTML = xmlhttp.responseText;
				if (self && (typeof self.onload == 'function')) {
					self.onload(xmlhttp);
				}
			//} catch (e) {
			//	alert('An error occurred while trying to return your request. \nError '+e.description);
			//}
			
			if (xmlhttp.status != 200) {
				alert('An error occurred while trying to return your request. \nError '+xmlhttp.status+': '+xmlhttp.statusText);
				return;
			}
	    } else{
			
			//set the loading text
	    	setLoadingDiv(x,LoadingTxt);
	    	
	    	
			return;
			//x.innerHTML = '<b>Loading...</b>';
		}
	};
	//xmlhttp.setRequestHeader("Content-Length", "66");
}

function hollerBackNow(method, url, parameters, thisObj, LoadingTxt,doRunScriptTag) {

	 var xmlhttp = null;
	 var method = method.toUpperCase();
	 try{
	    if (window.XMLHttpRequest) {
	       var xmlhttp = new XMLHttpRequest();
	    } else if (window.ActiveXObject) {
	        //var xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
			try {
				var xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
			} catch (e) {
				try {
					var xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
				} catch (e) {}
			}
	    }
		
		if(method=="POST"){
			xmlhttp.open(method, url, true);
			xmlhttp.setRequestHeader("Content-type", "text/xml");//application/x-www-form-urlencoded
			xmlhttp.setRequestHeader("Content-length", parameters.length);//parameters.length
			xmlhttp.setRequestHeader("Connection", "close");
			xmlhttp.send(parameters);
		} else{
			xmlhttp.open(method, url+'&'+parameters, true);
			//xmlhttp.setRequestHeader("Content-type", "text/xml");
			xmlhttp.setRequestHeader("Pragma", "no-cache");
			xmlhttp.send(null);
		}
		
     } catch(e){
	 	alert('Error occurred while trying to process your request');
	 	return;
	 }
	
	
    xmlhttp.onreadystatechange = function () {
			
		if (objExist(thisObj)) { 
			var x = new getObj(thisObj);
		}

		if (xmlhttp.readyState == 4 || xmlhttp.readyState == 'complete') {

			if(doRunScriptTag){
				RunScriptTag(xmlhttp.responseText); //run any script tag found in the response text
			}
			
			try {
				//x.innerHTML = xmlhttp.responseXML;
				var response = xmlhttp.responseXML;
				alert(response.Length);
			} catch (e) {
				alert('An error occurred while trying to return your request. \nError '+e.description);
			}
			
			if (xmlhttp.status != 200) {
				alert('An error occurred while trying to return your request. \nError '+xmlhttp.status+': '+xmlhttp.statusText);
				return;
			}
	    } else{
			
	    	//set the loading text
    		//setLoadingDiv(x,LoadingTxt);
    		
			/*
			return;
			//x.innerHTML = '<b>Loading...</b>';*/
		}
	};
	//xmlhttp.setRequestHeader("Content-Length", "66");
}

/**
 * AJAX Call: submits the whole form formObj and writes the response to thisObj
 * @internal 8/11/06: Added LoadingTxt
 * @internal 8/26/06: Added abillity to run javascript from the response text (RunScriptTag)
 * @internal 1/18/07: added doRunScriptTag as a argument
 *
 * @param string:method			"POST" or "GET" (USE POST PLEASE, GET IS BUGGY DUE TO BROWSER CACHING)
 * @param Form:formObj			the form object to submit i.e. document.user_form
 * @param string:url			the url to post to i.e. "?action=ajax_save_user" or "?system_action=user_ajax_save"
 * @param string:thisObj		the id of the html object to write back to i.e. "user_56_row"
 * 								(NOTE: there are certian objects you cannot write back to, like <tr>)
 * @param string:LoadingTxt		"none","short","small", "long", some text you want to display, or leave it blank {see setLoadingDiv()}
 * @param bool:doRunScriptTag	if set to anything, then RunScriptTag is called on the response text
 */
function hollerAtMe(method,formObj,url,thisObj,LoadingTxt,doRunScriptTag) 
{
	
	this.uniqueId = new Date().getTime();
	this.frameName = 'frame_'+this.uniqueId;
	
	try{
		// Create New hidden iframe
		var divElm = document.createElement('DIV');
		divElm.style.display = 'none';
		document.body.appendChild(divElm);
		divElm.innerHTML = '<iframe name=\"'+this.frameName+'\" id=\"'+this.frameName+'\" src=\"about:blank\" onload=\"loadFrame(this,\''+thisObj+'\',\''+doRunScriptTag+'\')\"></iframe>';
	} catch(e){
	 	alert('Error occurred while trying to create frame');
	 	return;
	 }
	
	try{
		
		//alert(formObj.action+"="+url);
		h_action = formObj.action;
		h_method = formObj.method;
		h_target = formObj.target;
		
		// Set target of ajax call to frame
		formObj.action 	= url;
		formObj.method 	= method;
		formObj.target = this.frameName;
		formObj.submit();
		
		formObj.action	= h_action;
		formObj.method 	= h_method;
		formObj.target 	= h_target;
		
	} catch(e){
	 	alert('Error occurred while trying to submit form: ' + e);
	 	return;
	 }

	// the source div to swap out
	if (objExist(thisObj)) { 
		var x = new getObj(thisObj);
		
		//set the loading text
    	setLoadingDiv(x,LoadingTxt);
		
	}
}


function hollerBacki(method, url, thisObj,doRunScriptTag) 
{
	this.uniqueId = new Date().getTime();
	this.frameName = 'frame_'+this.uniqueId;
	
	try{
		// Create New hidden iframe
		var divElm = document.createElement('DIV');
		divElm.style.display = 'none';
		document.body.appendChild(divElm);
		divElm.innerHTML = '<iframe name=\"'+this.frameName+'\" id=\"'+this.frameName+'\" src=\"about:blank\" onload=\"loadFrame(this,\''+thisObj+'\',\''+doRunScriptTag+'\')\"></iframe>';
		var x = new getObj(this.frameName);
		x.src = url;
	} catch(e){
	 	alert('Error occurred while trying to create frame');
	 	return;
	 }
	
	try{
		
	} catch(e){
	 	alert('Error occurred while trying to submit form');
	 	return;
	 }

	// the source div to swap out
	if (objExist(thisObj)) { 
		var x = new getObj(thisObj);
		x.innerHTML = '<div><img src="/img/loading.gif" alt="loading..." width="220" height="19" border="0" /></div>';
	}
	

}




function loadFrame(iframeObj, thisObj, doRunScriptTag) {
	try{
		frameName = iframeObj.id;
		var x = new getObj(thisObj);
		x.innerHTML = '<div><img src="/img/loading.gif" alt="loading..." width="220" height="19" border="0" /></div>';
		x.innerHTML = window.frames[frameName].document.body.innerHTML;
		if(doRunScriptTag){
			RunScriptTag(xmlhttp.responseText); //run any script tag found in the response text
		}
	} catch(e){
	 	alert('Error occurred while trying to load data from frame');
	 	return;
	}
}

/**
 * Looks in the passed in html string for the first javascript tag (<script...>...</script>) and evaluate it
 * @internal 7/27/2006: added the indexOf check
 * 
 * @param string:html the string to look for the script tags in
 */
function RunScriptTag(html){
	//If you don't find a start script tag, don't waste time with the RegExp
	if(html.indexOf("<script")>=0){
		//try{
			//match start and end script tags with anything (including newlines) in the middle
			var re = new RegExp(/<script.*?>((?:.|\s)*?)<\/script>/ig);
			//var re = new RegExp(/<script(?:(?:.*(?<src>(?<=src=")[^"]*(?="))[^>]*)|[^>]*)>(?<content>(?:(?:\n|.)(?!(?:\n|.)<script))*)<\/script>/i);
			var matches = null;
			while(matches = re.exec(html)) {
				//Now run what you found
				if(matches && matches[1]!=""){
					//alert(matches[0]);alert(matches[1]);
					eval(matches[1]);
				}
			}
			
		//} catch(e){
			//alert("RunScriptTag had an error: "+e.description);
		//}
	}
}

/**
 * Sets the innerHTML of x to text or a image
 *
 * @param string:LoadingTxt "none","short","small", "long", some text you want to display, or leave it blank
 */
function setLoadingDiv(x,LoadingTxt){
	if(LoadingTxt=="none"){ //returns nothing
		return ;
	}else if(LoadingTxt=="long"){ //returns long loading gif
		x.innerHTML = '<div><img src="/img/loading.gif" alt="loading..." width="220" height="19" border="0"></div>';
	}else if(LoadingTxt=="short" || LoadingTxt=="small") {//returns small loading gif
		x.innerHTML =  '<div><img src="/img/icon.indicator.gif" alt="loading..." width="16" height="16" border="0"></div>';
	}else if(LoadingTxt){ //returns the text passed
		x.innerHTML =  '<div>'+LoadingTxt+'</div>';
	} else if(x.clientHeight && x.clientHeight < 220) {//returns small loading gif
		x.innerHTML = '<div><img src="/img/icon.indicator.gif" alt="loading..." width="16" height="16" border="0" /></div>';
	} else {
		x.innerHTML = '<div><img src="/img/loading.gif" alt="loading..." width="220" height="19" border="0" /></div>';
	}
}

function getFormValues(fobj,valFunc) {    
	var str         = "";
	var valueArr     = null;
	var val         = "";
	var cmd         = "";

	for(var i = 0;i < fobj.elements.length;i++) {        
		switch(fobj.elements[i].type) {            
			case "hidden":
			case "text":
			case "textarea":
			case "password":
				if(valFunc) {
					//use single quotes for argument so that the value of
					//fobj.elements[i].value is treated as a string not a literal
					cmd = valFunc + "(" + 'fobj.elements[i].value' + ")";
					val = eval(cmd)
				}
				str += fobj.elements[i].name + "=" + escape(fobj.elements[i].value) + "&";
			break;            
			case "select-one":
				str += fobj.elements[i].name + "=" + fobj.elements[i].options[fobj.elements[i].selectedIndex].value + "&";
			break;
			case "select-multiple":                
				for(var z=0;z<fobj.elements[i].options.length;z++){
					if(fobj.elements[i].options[z].selected==true)
						str += fobj.elements[i].name + "=" + fobj.elements[i].options[z].value + "&";
				}
			break;
			case "checkbox":
				if(fobj.elements[i].checked==true)
					str += fobj.elements[i].name + "=" + escape(fobj.elements[i].value) + "&";
			break;
		}
	}
	str = str.substr(0,(str.length - 1)); 
	return str;
} 

function maxlength(obj, len)
{
	if(obj.value.length>=len) { obj.value = obj.value.substr(0,len) }
}

function print_r(obj) {
	big_list = "";
	for (property in obj) {
    	big_list +=property+"="+obj[property]+"\n";
	  }
	alert(big_list);
	return;
}

function URLEncode(plaintext) {
	// The Javascript escape and unescape functions do not correspond
	// with what browsers actually do...
	var SAFECHARS = "0123456789" +					// Numeric
					"ABCDEFGHIJKLMNOPQRSTUVWXYZ" +	// Alphabetic
					"abcdefghijklmnopqrstuvwxyz" +
					"-_.!~*'()";					// RFC2396 Mark characters
	var HEX = "0123456789ABCDEF";


	var encoded = "";
	for (var i = 0; i < plaintext.length; i++ ) {
		var ch = plaintext.charAt(i);
	    if (ch == " ") {
		    encoded += "+";				// x-www-urlencoded, rather than %20
		} else if (SAFECHARS.indexOf(ch) != -1) {
		    encoded += ch;
		} else {
		    var charCode = ch.charCodeAt(0);
			if (charCode > 255) {
			    alert( "Unicode Character '" 
                        + ch 
                        + "' cannot be encoded using standard URL encoding.\n" +
				          "(URL encoding only supports 8-bit characters.)\n" +
						  "A space (+) will be substituted." );
				encoded += "+";
			} else {
				encoded += "%";
				encoded += HEX.charAt((charCode >> 4) & 0xF);
				encoded += HEX.charAt(charCode & 0xF);
			}
		}
	} // for

	return encoded;
}

function URLDecode(encoded) {
   // Replace + with ' '
   // Replace %xx with equivalent character
   // Put [ERROR] in output if %xx is invalid.
   var HEXCHARS = "0123456789ABCDEFabcdef"; 

   var plaintext = "";
   var i = 0;
   while (i < encoded.length) {
       var ch = encoded.charAt(i);
	   if (ch == "+") {
	       plaintext += " ";
		   i++;
	   } else if (ch == "%") {
			if (i < (encoded.length-2) 
					&& HEXCHARS.indexOf(encoded.charAt(i+1)) != -1 
					&& HEXCHARS.indexOf(encoded.charAt(i+2)) != -1 ) {
				plaintext += unescape( encoded.substr(i,3) );
				i += 3;
			} else {
				alert( 'Bad escape combination near ...' + encoded.substr(i) );
				plaintext += "%[ERROR]";
				i++;
			}
		} else {
		   plaintext += ch;
		   i++;
		}
	} // while
   return plaintext;
}

/*

	Added because IE does not support Object.toSource()

*/


/*
    json.js
    2006-12-06

    This file adds these methods to JavaScript:

        array.toJSONString()
        boolean.toJSONString()
        date.toJSONString()
        number.toJSONString()
        object.toJSONString()
        string.toJSONString()
            These method produces a JSON text from a JavaScript value.
            It must not contain any cyclical references. Illegal values
            will be excluded.

            The default conversion for dates is to an ISO string. You can
            add a toJSONString method to any date object to get a different
            representation.

        string.parseJSON(hook)
            This method parses a JSON text to produce an object or
            array. It can throw a SyntaxError exception.

            The optional hook parameter is a function which can filter and
            transform the results. It receives each of the values, and its
            return value is used instead. If it returns what it received, then
            structure is not modified.

            Example:

            // Parse the text. If it contains any "NaN" strings, replace them
            // with the NaN value. All other values are left alone.

            myData = text.parseJSON(function (value) {
                if (typeof value === 'string') {
                    if (value === 'NaN') {
                        return NaN;
                    }
                }
                return value;
            });

    It is expected that these methods will formally become part of the
    JavaScript Programming Language in the Fourth Edition of the
    ECMAScript standard in 2007.
*/

Array.prototype.toJSONString = function () {
    var a = ['['], b, i, l = this.length, v;

    function p(s) {
        if (b) {
            a.push(',');
        }
        a.push(s);
        b = true;
    }

    for (i = 0; i < l; i += 1) {
        v = this[i];
        switch (typeof v) {
        case 'undefined':
        case 'function':
        case 'unknown':
            break;
        case 'object':
            if (v) {
                if (typeof v.toJSONString === 'function') {
                    p(v.toJSONString());
                }
            } else {
                p("null");
            }
            break;
        default:
            p(v.toJSONString());
        }
    }
    a.push(']');
    return a.join('');
};

Boolean.prototype.toJSONString = function () {
    return String(this);
};

Date.prototype.toJSONString = function () {

    function f(n) {
        return n < 10 ? '0' + n : n;
    }

    return '"' + this.getFullYear() + '-' +
            f(this.getMonth() + 1) + '-' +
            f(this.getDate()) + 'T' +
            f(this.getHours()) + ':' +
            f(this.getMinutes()) + ':' +
            f(this.getSeconds()) + '"';
};

Number.prototype.toJSONString = function () {
    return isFinite(this) ? String(this) : "null";
};

Object.prototype.toJSONString = function () {
    var a = ['{'], b, i, v;

    function p(s) {
        if (b) {
            a.push(',');
        }
        a.push(i.toJSONString(), ':', s);
        b = true;
    }

    for (i in this) {
        if (this.hasOwnProperty(i)) {
            v = this[i];
            switch (typeof v) {
            case 'undefined':
            case 'function':
            case 'unknown':
                break;
            case 'object':
                if (v) {
                    if (typeof v.toJSONString === 'function') {
                        p(v.toJSONString());
                    }
                } else {
                    p("null");
                }
                break;
            default:
                p(v.toJSONString());
            }
        }
    }
    a.push('}');
    return a.join('');
};


(function (s) {
    var m = {
        '\b': '\\b',
        '\t': '\\t',
        '\n': '\\n',
        '\f': '\\f',
        '\r': '\\r',
        '"' : '\\"',
        '\\': '\\\\'
    };

    s.parseJSON = function (hook) {
        try {
            if (/^("(\\.|[^"\\\n\r])*?"|[,:{}\[\]0-9.\-+Eaeflnr-u \n\r\t])+?$/.
                    test(this)) {
                var j = eval('(' + this + ')');
                if (typeof hook === 'function') {
                    function walk(v) {
                        if (v && typeof v === 'object') {
                            for (var i in v) {
                                if (v.hasOwnProperty(i)) {
                                    v[i] = walk(v[i]);
                                }
                            }
                        }
                        return hook(v);
                    }
                    return walk(j);
                }
                return j;
            }
        } catch (e) {
        }
        throw new SyntaxError("parseJSON");
    };

    s.toJSONString = function () {
        if (/["\\\x00-\x1f]/.test(this)) {
            return '"' + this.replace(/([\x00-\x1f\\"])/g, function(a, b) {
                var c = m[b];
                if (c) {
                    return c;
                }
                c = b.charCodeAt();
                return '\\u00' +
                    Math.floor(c / 16).toString(16) +
                    (c % 16).toString(16);
            }) + '"';
        }
        return '"' + this + '"';
    };
})(String.prototype);

/**
	 * Returns the height and width of the Browser window
	 * 
	 * @return Object with width and height properties
	 */
	function getWindowSizes() {
		var myWidth = 0, myHeight = 0;
		if( typeof( window.innerWidth ) == 'number' ) {
			//Non-IE
			var scrollbar_width = 0;//13;//this is good for firefox, but not good in safari
			myWidth	= window.innerWidth-scrollbar_width;
			myHeight = window.innerHeight;
		} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
			//IE 6+ in 'standards compliant mode'
			
			myWidth = document.documentElement.clientWidth;
			myHeight = document.documentElement.clientHeight;
		} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
			//IE 4 compatible
			myWidth = document.body.clientWidth;
			myHeight = document.body.clientHeight;
		}
		//window.alert( 'Width = ' + myWidth+' Height = ' + myHeight  );
		
		return {width:myWidth,height:myHeight};
	}

	function scrollToBottom(){
//		if( typeof( window.pageYOffset ) == 'number' ) {
//			//Netscape compliant
//			window.pageYOffset = window.innerHeight;
//		} else 
		if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
			//DOM compliant
			document.body.scrollTop = document.body.scrollHeight;
			
		} else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
		//IE6 standards compliant mode
			document.documentElement.scrollTop = document.documentElement.scrollHeight;
		}
		
		//if(document.documentElement.scrollTop){document.documentElement.scrollTop=document.documentElement.scrollHeight} else {document.body.scrollTop=document.body.scrollHeight}
	}
	
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
