function include_once( filename ) {
    // http://kevin.vanzonneveld.net
    // +   original by: Legaev Andrey
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: Michael White (http://getsprink.com)
    // -    depends on: include
    // *     example 1: include_once('http://www.phpjs.org/js/phpjs/_supporters/pj_test_supportfile_2.js');
    // *     returns 1: true
 
    var cur_file = {};
    cur_file[window.location.href] = 1;
 
    if (!window.php_js) window.php_js = {};
    if (!window.php_js.includes) window.php_js.includes = cur_file;
    if (!window.php_js.includes[filename]) {
        if(include(filename)){
            return true;
        }
    } else{
        return true;
    }
}

function include( filename ) {
    // http://kevin.vanzonneveld.net
    // +   original by: mdsjack (http://www.mdsjack.bo.it)
    // +   improved by: Legaev Andrey
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: Michael White (http://getsprink.com)
    // %        note 1: Force Javascript execution to pause until the file is loaded. Usually causes failure if the file never loads. ( Use sparingly! )
    // %        note 2: The included file does not come available until a second script block, so typically use this in the header.
    // *     example 1: include('http://www.phpjs.org/js/phpjs/_supporters/pj_test_supportfile_2.js');
    // *     returns 1: 1
 
    var js = document.createElement('script');
    js.setAttribute('type', 'text/javascript');
    js.setAttribute('src', filename);
    js.setAttribute('defer', 'defer');
    document.getElementsByTagName('HEAD')[0].appendChild(js);
 
    // save include state for reference by include_once
    var cur_file = {};
    cur_file[window.location.href] = 1;
 
    if (!window.php_js) window.php_js = {};
    if (!window.php_js.includes) window.php_js.includes = cur_file;
    if (!window.php_js.includes[filename]) {
        window.php_js.includes[filename] = 1;
    } else {
        window.php_js.includes[filename]++;
    }
 
    return window.php_js.includes[filename];
}

function is_array( mixed_var ) {
    // http://kevin.vanzonneveld.net
    // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: Legaev Andrey
    // +   bugfixed by: Cord
    // *     example 1: is_array(['Kevin', 'van', 'Zonneveld']);
    // *     returns 1: true
    // *     example 2: is_array('Kevin van Zonneveld');
    // *     returns 2: false
 
    return ( mixed_var instanceof Array );
}

function print_r(theObj){
  if(theObj.constructor == Array ||
     theObj.constructor == Object){
    document.write("<ul>")
    for(var p in theObj){
      if(theObj[p].constructor == Array||
         theObj[p].constructor == Object){
document.write("<li>["+p+"] => "+typeof(theObj)+"</li>");
        document.write("<ul>")
        print_r(theObj[p]);
        document.write("</ul>")
      } else {
document.write("<li>["+p+"] => "+theObj[p]+"</li>");
      }
    }
    document.write("</ul>")
  }
}

function uncheck_all(str)
{
	//function for when the all value is unchecked so should return to previously selected values
	document.getElementById(str).checked=false;
	/*var field = document.getElementsByName(str);
	for (i = 0; i < field.length; i++)
	{
		field[i].checked = false ;
	}*/
}
function uncheck_all_checkbox(str)
{
	//function for when the all value is unchecked so should return to previously selected values
	//document.getElementById(str).checked=false;
	var field = document.getElementsByName(str);
	for (i = 0; i < field.length; i++)
	{
		field[i].checked = false ;
	}
}

function returnPreviousValues(str)
{
	var field = document.getElementsByName(str + "[]");
	for (j = 0; j < field.length; j++)
	{
		field[j].checked = false;
	}
	for (i = 0; i < eval('previousValues_' + str).length; i++)
	{
		for (j = 0; j < field.length; j++)
		{
			var val = eval('previousValues_' + str + "[" + i + "]");
			if (field[j].value == val)
			{
				field[j].checked = true;
			}
		}
	}
}

function changePreviousValues(str)
{
	var field = document.getElementsByName(str + "[]");
	
	eval('previousValues_' + str + " = []");
	for (i = 0; i < field.length; i++)
	{
		if (field[i].checked)
		{
			eval('previousValues_' + str + ".push(field[i].value);");
		}
	}
}

function check_all(str)
{
	var field = document.getElementsByName(str);
	for (i = 0; i < field.length; i++)
	{
		field[i].checked = true ;
	}
}

//form creator stuff
function switch_checkbox_display_fields(id, fieldName)
{
	var elem = document.getElementById(id);
	if (elem.checked) 
		document.getElementById(fieldName).style.display = "block"; 
	else if (!elem.checked) 
		document.getElementById(fieldName).style.display = "none";
}

function dump(arr,level) {
var dumped_text = "";
if(!level) level = 0;

//The padding given at the beginning of the line.
var level_padding = "";
for(var j=0;j<level+1;j++) level_padding += "    ";

if(typeof(arr) == 'object') { //Array/Hashes/Objects
 for(var item in arr) {
  var value = arr[item];
 
  if(typeof(value) == 'object') { //If it is an array,
   dumped_text += level_padding + "'" + item + "' ...\n";
   dumped_text += dump(value,level+1);
  } else {
   dumped_text += level_padding + "'" + item + "' => '" + value + "'\n";
  }
 }
} else { //Stings/Chars/Numbers etc.
 dumped_text = "===>"+arr+"<===("+typeof(arr)+")";
}
return dumped_text;
} 
include_once('/scripts/js/lib.js');
include_once('/scripts/js/popup.js');
include_once('/scripts/js/keep_alive.js');