var BrowserDetect = {
	init: function () {
		this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
		this.version = this.searchVersion(navigator.userAgent)
			|| this.searchVersion(navigator.appVersion)
			|| "an unknown version";
		this.OS = this.searchString(this.dataOS) || "an unknown OS";
	},
	searchString: function (data) {
		for (var i=0;i<data.length;i++)	{
			var dataString = data[i].string;
			var dataProp = data[i].prop;
			this.versionSearchString = data[i].versionSearch || data[i].identity;
			if (dataString) {
				if (dataString.indexOf(data[i].subString) != -1)
					return data[i].identity;
			}
			else if (dataProp)
				return data[i].identity;
		}
	},
	searchVersion: function (dataString) {
		var index = dataString.indexOf(this.versionSearchString);
		if (index == -1) return;
		return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
	},
	dataBrowser: [
		{ 	string: navigator.userAgent,
			subString: "OmniWeb",
			versionSearch: "OmniWeb/",
			identity: "OmniWeb"
		},
		{
			string: navigator.vendor,
			subString: "Apple",
			identity: "Safari"
		},
		{
			prop: window.opera,
			identity: "Opera"
		},
		{
			string: navigator.vendor,
			subString: "iCab",
			identity: "iCab"
		},
		{
			string: navigator.vendor,
			subString: "KDE",
			identity: "Konqueror"
		},
		{
			string: navigator.userAgent,
			subString: "Firefox",
			identity: "Firefox"
		},
		{
			string: navigator.vendor,
			subString: "Camino",
			identity: "Camino"
		},
		{		// for newer Netscapes (6+)
			string: navigator.userAgent,
			subString: "Netscape",
			identity: "Netscape"
		},
		{
			string: navigator.userAgent,
			subString: "MSIE",
			identity: "Explorer",
			versionSearch: "MSIE"
		},
		{
			string: navigator.userAgent,
			subString: "Gecko",
			identity: "Mozilla",
			versionSearch: "rv"
		},
		{ 		// for older Netscapes (4-)
			string: navigator.userAgent,
			subString: "Mozilla",
			identity: "Netscape",
			versionSearch: "Mozilla"
		}
	],
	dataOS : [
		{
			string: navigator.platform,
			subString: "Win",
			identity: "Windows"
		},
		{
			string: navigator.platform,
			subString: "Mac",
			identity: "Mac"
		},
		{
			string: navigator.platform,
			subString: "Linux",
			identity: "Linux"
		}
	]

};
BrowserDetect.init();var Calendar = {
	
	now: function() {
		var d = new Date();
		
		if (typeof(arguments[0]) !== "undefined") {
			return (d.getMonth()+1) + "/" + d.getDate() + "/" + d.getFullYear();
		}
		else {
			return (d.getMonth() + 1) + "/" + d.getDate() + "/" + d.getFullYear() + " " +
			d.getHours() +
			":" +
			d.getMinutes() +
			":" +
			d.getSeconds();
		}
	},
	
	human_date: function(d) {
		if(!d) {
			return Calendar.now();
		}
		var mmddyy_regex = /(....)-(.{1,2})-(.{1,2})/;
		if(mmddyy_regex.test(d)) {
			var mdy_parts = mmddyy_regex.exec(d);
			return mdy_parts[2] + "/" + mdy_parts[3] + "/" + mdy_parts[1];
		} else {
			return "-1";
		}
	},
	
	dbDate: function(d) {
		var mmddyy_regex = /(.{1,2})\/(.{1,2})\/(....)/;
		if(mmddyy_regex.test(d)) {
			var mdy_parts = mmddyy_regex.exec(d);
			return mdy_parts[3] + "-" + mdy_parts[1] + "-" + mdy_parts[2];
		} else {
			return "-1";
		}
	},
	
	
	JSDate_to_dbDate: function(d) {
		d = d.getMonth() + "/" + d.getDate() + "/" + d.getFullYear();
		var mmddyy_regex = /(.{1,2})\/(.{1,2})\/(....)/;
		if(mmddyy_regex.test(d)) {
			var mdy_parts = mmddyy_regex.exec(d);
			mdy_parts[1]++;
			if(mdy_parts[1] < 10) {
				mdy_parts[1] = "0" + mdy_parts[1];
			}
			if(mdy_parts[2] < 10) {
				mdy_parts[2] = "0" + mdy_parts[2];
			}
			return mdy_parts[3] + "-" + mdy_parts[1] + "-" + mdy_parts[2];
		} else {
			return "-1";
		}
	},
	
	
	splitDate: function(d) {
		var mmddyy_regex = /(.{1,2})\/(.{1,2})\/(....)/;
		if(mmddyy_regex.test(d)) {
			var d_ar = mmddyy_regex.exec(d);
			return new Array(d_ar[3], d_ar[1], d_ar[2]);
		}
		
		var yyyymmdd_regex = /(....)\-(.{1,2})\-(.{1,2})/;
		if(yyyymmdd_regex.test(d)) {
			var d_ar = yyyymmdd_regex.exec(d);
			return d_ar.slice(1);
		}
		
		//alert("Calendar.splitDate failed: " + d);
		return d;
	},
	
	makeUTC: function(date_ar) {
		if(!is_array(date_ar)) {
			date_ar = this.splitDate(date_ar);
		}
		
		var lhs = new Date();
		lhs.setYear(date_ar[0]);
		lhs.setMonth(date_ar[1]);
		lhs.setDate(date_ar[2]);
		var utc = Date.UTC(lhs.getFullYear(),lhs.getMonth()+1,lhs.getDate());
		delete lhs;
		return utc;
	},
	
	cmpDate: function(lhs,rhs) {
		var lhs_utc = this.makeUTC(lhs);
		var rhs_utc = this.makeUTC(rhs);

		
		if(lhs_utc > rhs_utc) {
			return 1;
		}
		
		if(lhs_utc < rhs_utc) {
			return -1;
		}
		
		return 0;		
	},
	
	
	valiDates: function(lhs,mhs,rhs) {
		lhs = this.makeUTC(lhs);
		mhs = this.makeUTC(mhs);
		rhs = this.makeUTC(rhs);
		
		return ((lhs < mhs) && (mhs < rhs));
	},
	
	
	calculate_weeks: function(startDate, endDate) {
		var startDate_ar;
		if(!is_array(startDate)) {
			startDate_ar = this.splitDate(startDate);
		} else {
			startDate_ar = startDate;
		}
		
		var lhs = this.makeUTC(startDate_ar);
		
		
		var endDate_ar;
		if(!is_array(endDate)) {
			endDate_ar = this.splitDate(endDate);
		} else {
			endDate_ar = endDate;
		}
		
		var rhs = this.makeUTC(endDate_ar);
		
		
		var diff =  rhs - lhs;
		
		var secs_in_day = 24 * 60 * 60;
		var days = diff / secs_in_day;
		var weeks = Math.ceil((days / 7) / 1000); //7 days in a week...
		if(!weeks) {
			weeks = 1;
		}

		return weeks;
	},
	
	set_calendar: function(id_suffix,target_date) {
		if(!target_date) {
			target_date = this.JSDate_to_dbDate(new Date());
		} else {
			if(typeof(target_date) == "object") {
				target_date = this.JSDate_to_dbDate(target_date);
			}
		}
		
		var d_ar = this.splitDate(target_date);
		var y = "obj_year_" + id_suffix;
		var m = "obj_month_" + id_suffix;
		var d = "obj_day_" + id_suffix;
		
		Selectbox.set(y,Selectbox.find(y,d_ar[0]));
		Selectbox.set(m,Selectbox.find(m,d_ar[1]));
		Selectbox.set(d,Selectbox.find(d,d_ar[2]));
	},
	
	set: function(id_suffix,target_date) {
		return Calendar.set_calendar(id_suffix,target_date);
	},
	
	read: function(suffix) {
		return this.read_calendar(suffix);
	},
	
	read_calendar: function(id_suffix) {
		var y = "obj_year_" + id_suffix;
		var m = "obj_month_" + id_suffix;
		var d = "obj_day_" + id_suffix;
		if (typeof(arguments[1]) == "undefined") {
			return Selectbox.get(y) + "-" + Selectbox.get(m) + "-" + Selectbox.get(d);
		} else {
			return Selectbox.get(m) + "/" + Selectbox.get(d) + "/" + Selectbox.get(y);
		}
	},
	
	configure: function(startYear,endYear,id_suffix) {
		var years = new Array();
		if (startYear < endYear) {
			for (var i = startYear; i < endYear + 1; i++) {
				years.push(i);
			}
		} else {
			for (var i = startYear; i > endYear - 1; i--) {
				years.push(i);
			}
		}
		
		var days = new Array();
		for(var i=1;i<32;i++) {
			days.push(i);
		}
		
		var months = {
			"01": "January",
			"02": "February",
			"03": "March",
			"04": "April",
			"05": "May",
			"06": "June",
			"07": "July",
			"08": "August",
			"09": "September",
			"10": "October",
			"11": "November",
			"12": "December"
		};
		
		Selectbox.fill("obj_year_" + id_suffix,years);
		Selectbox.fill("obj_month_" + id_suffix,months);
		Selectbox.fill("obj_day_" + id_suffix,days);
	},
	
	
	
	
	monthDiff: function(lhsCalendar,rhsCalendar) {
		var lhs = Calendar.read(lhsCalendar);
		var rhs = Calendar.read(rhsCalendar);
		
		lhs = Calendar.splitDate(lhs);
		rhs = Calendar.splitDate(rhs);
		
		d1 = new Date();
		d1.setFullYear(lhs[0],(lhs[1]-1),lhs[2]);
		
		d2 = new Date();
		d2.setFullYear(rhs[0],(rhs[1]-1),rhs[2]);
		
		var months = d2.getMonthsBetween(d1);
		if(months < 0) { months *= -1; }
		if(months < 1) { months = 1; }
		return Math.round(months);
	},
	
	monthDiff_datestr: function(lhsCalendar,rhsCalendar) {
		
		lhs = Calendar.splitDate(lhsCalendar);
		rhs = Calendar.splitDate(rhsCalendar);
		
		d1 = new Date();
		d1.setFullYear(lhs[0],(lhs[1]-1),lhs[2]);
		
		d2 = new Date();
		d2.setFullYear(rhs[0],(rhs[1]-1),rhs[2]);
		
		var months = d2.getMonthsBetween(d1);
		if(months < 0) { months *= -1; }
		if(months < 1) { months = 1; }
		return Math.round(months);
	}
	
};









////////////////////


Date.prototype.lastday = function() {
  var d = new Date(this.getFullYear(), this.getMonth() + 1, 0);
  return d.getDate();
};



Date.prototype.getMonthsBetween = function(d) {
  var sDate, eDate;
  var d1 = this.getFullYear() * 12 + this.getMonth();
  var d2 = d.getFullYear() * 12 + d.getMonth();
  var sign;
  var months = 0;

  if (this == d) {
    months = 0;
  } else if (d1 == d2) { //same year and month
    months = (d.getDate() - this.getDate()) / this.lastday();
  } else {
    if (d1 <  d2) {
      sDate = this;
      eDate = d;
      sign = 1;
    } else {
      sDate = d;
      eDate = this;
      sign = -1;
    }

    var sAdj = sDate.lastday() - sDate.getDate();
    var eAdj = eDate.getDate();
    var adj = (sAdj + eAdj) / sDate.lastday() - 1;
    months = Math.abs(d2 - d1) + adj;
    months = (months * sign)
  }
  return months;
};

function getElement(id) {
	if(typeof(id) !== "string") {
		return id;
	}
	return document.getElementById(id);
}

function Element(t) {
	return document.createElement(t);	
}

function FilledElement(t,h) {
	var d = Element(t);
	if(t == "img") {
		d.setAttribute("src",h);
		return d;		
	}
	
	if (is_array(h)) {
		for (var i = 0; i < h.length; i++) {
			var x = h[i];
			switch (typeof(x)) {
				case "string":
					d.innerHTML += x;
					break;
				default:
					d.appendChild(x);
			}
		}
	}
	else {
		switch (typeof(h)) {
			case "string":
				d.innerHTML = h;
				break;
			default:
				d.appendChild(h);
		}
	}
	if(typeof(arguments[2]) !== "undefined") {
		d.className = arguments[2];
	}
	return d;
}


function Clear(d) {
	if(typeof(d) == "string") {
		d = getElement(d);
	}
	d.innerHTML = "";
}



var ElementGroup = {
	getByPrefix: function(type,prefix) {
		var coll = document.body.getElementsByTagName(type);
		var matches = new Array();
		for(var i=0;i<coll.length;i++) {
			//alert(coll[i].id)
			if(coll[i].id.indexOf(prefix) != -1) {
				matches.push(coll[i]);
			}
		}
		return matches;
	}
}









function openHelper(url, width, height){
    var today = new Date();
    var name = today.getTime();
    var helperWindow = window.open(url, name, 'width=' + width + ',height=' + height + ',resizable=yes,scrollbars=yes,menubar=yes,status=yes,location=yes');
}

function openHelper_fixed(url, width, height){
    var today = new Date();
    var name = today.getTime();
    var helperWindow = window.open(url, name, 'width=' + width + ',height=' + height + ',resizable=no,scrollbars=no,menubar=no,status=no,location=no');
}


function geturl(url){
    window.location = url;
}


function show(d){
	if(is_array(d)) {
		for(var i=0;i<d.length;i++) {
			show(d[i]);
		}
	}
	d = getElement(d);
	d.style.display = "block";
	return d;
}

function hide(d) {
	if(is_array(d)) {
		for(var i=0;i<d.length;i++) {
			hide(d[i]);
		}
	}
	d = getElement(d);
	if (typeof(d) !== "undefined") {
		d.style.display = "none";
	}
	return d;
}

function toggle_div(d){
    d = getElement(d);
    if (d.style.display != "none") {
        d.style.display = "none";
    }
    else {
        d.style.display = "block";
    }
}




function toggle_status(d){
    d = getElement(d);
    if (d.style.display != "none") {
        return true;
    }
    else {
        return false;
    }
}


var hilite_bkgds = new Array("transparent", "#ededed");
var hilite_weights = new Array();
function hilite_row(who, how){
    cells = who.getElementsByTagName("td");
    for (i = 0; i < cells.length; i++) {
        cells[i].style.backgroundColor = hilite_bkgds[how];
    }
}





var Table = {
	alternate_backgrounds: function(tid,css_base,css_lite,css_dark) {
		var skip = "__INVALID_CLASSNAME__that_you_would_NEVER_ACTUALLY_USE__";
		if(typeof(arguments[4] == "string")) {
			skip = arguments[4];
		}
		
		var tbody;
		if (typeof(tid) === "string") {
			tbody = getElement(tid).getElementsByTagName("tbody")[0];
		} else {
			tbody = tid.getElementsByTagName("tbody")[0];
		}
		var rows = tbody.getElementsByTagName("tr");
		var index = -1;
		for(var i=0;i<rows.length;i++) {
			var matched = 0;
			var cells = rows[i].getElementsByTagName("td");
			for(var q=0;q<cells.length;q++) {
				var td = cells[q];
				if(td.className == skip) {
					break;
				}
				matched = 1;
				if (index % 2) {
					td.className = css_base + " " + css_dark;
				} else {
					td.className = css_base + " " + css_lite;
				}
			}
			if (matched) {
				index++;
			}
		}
	}
}




function fill_selectbox(boxID, opt_ar){
    var box = getElement(boxID);
    for (var i in opt_ar) {
        var opt = document.createElement("OPTION");
        opt.setAttribute("value", opt_ar[i][0]);
        if (BrowserDetect.browser == "Explorer") {
            opt.setAttribute("label", opt_ar[i][1]);
        }
        else {
            opt.text = opt_ar[i][1];
        }
        box.appendChild(opt);
    }
}


var Selectbox = {
	fill: function(boxID, opt_ar) {
	    var box = getElement(boxID);
		if(!is_array(opt_ar)) {
			var tmpar = new Array();
			for(var i in opt_ar) {
				tmpar.push( { "label": opt_ar[i], "value": i} );
			}
			opt_ar = tmpar;
		}
	    for (var i=0;i<opt_ar.length;i++) {
	        var opt = Element("OPTION");
			var choice = opt_ar[i];
			if(typeof(choice.value) != "string" && typeof(choice.value) != "number") {
				var value = choice;
				choice = { "label": value, "value": value };
			}
	        opt.setAttribute("value", choice.value);
	        if (BrowserDetect.browser == "Explorer") {
	            opt.setAttribute("label", choice.label);
	        }
	        else {
	            opt.text = choice.label;
	        }
	        box.appendChild(opt);
   		}
	},
	
	
	append: function(boxID,label,value) {
		var box = getElement(boxID);
		var opt = Element("OPTION");
		opt.setAttribute("value", value);
		if (BrowserDetect.browser == "Explorer") {
			opt.setAttribute("label", label);
		} else {
			opt.text = label;
		}
		box.appendChild(opt);
	},
	
	
	find: function(id,val) {
		var opts = getElement(id).options;
		for(var i=0;i<opts.length;i++) {
			var test_value = opts[i].value;
			if(test_value == val) {
				return i;
			}
			var test_int = intval(test_value,10);
			var val_int = intval(val,10);
			if(test_int && val_int && test_int == val_int) {
				return i;
			}
		}
		return false;
	},
	
	reset: function(id) {
		getElement(id).selectedIndex = 0;
	},
	
	set: function(id,index) {
		var box = getElement(id);
		if(index < box.options.length) {
			box.selectedIndex = index;
		}
	},
	
	get: function(id,index) {
		var box = getElement(id);
		return box.options[box.selectedIndex].value;
	},
	
	get_label: function(id) {
		var box = getElement(id);
		if(BrowserDetect.browser == "Explorer") {
			return box.options[box.selectedIndex].label;
		}
		return box.options[box.selectedIndex].text;
	},
	
	get_value: function(id) {
		var box = getElement(id);
		if(BrowserDetect.browser == "Explorer") {
			return box.options[box.selectedIndex].value;
		}
		return box.options[box.selectedIndex].value;
	}
	
	
}




var Checkbox = {
	check: function(id,h) {
		if(h !== false) {
			getElement(id).checked = "true";
		} else {
			getElement(id).checked = "";
		}
	},
	
	state: function(id) {
		if(getElement(id).checked) {
			return true;
		}
		return false;
	},
	
	value: function(id) {
		if(this.state(id) !== false) {
			return getElement(id).value;
		}
		return false;		
	}
	
	
}



function radioBtn_getCheckedValue(radioObj){
    //radioObj = document.elements[radioObj];
    if (!radioObj) 
        return "_UNCHECKED_";
    var radioLength = radioObj.length;
    if (radioLength == undefined) 
        if (radioObj.checked) 
            return radioObj.value;
        else 
            return "_UNCHECKED_";
    for (var i = 0; i < radioLength; i++) {
        if (radioObj[i].checked) {
            return radioObj[i].value;
        }
    }
    return "_UNCHECKED_";
}


function radioBtn_setCheckedValue(radioObj, newValue){
    if (!radioObj) 
        return;
    var radioLength = radioObj.length;
    if (radioLength == undefined) {
        radioObj.checked = (radioObj.value == newValue.toString());
        return;
    }
    for (var i = 0; i < radioLength; i++) {
        radioObj[i].checked = false;
        if (radioObj[i].value == newValue.toString()) {
            radioObj[i].checked = true;
        }
    }
}



function toggle_exclusive_pair(obj_on, obj_off, field, val){
    getElement(obj_on).checked = "checked";
    getElement(obj_off).checked = "";
    getElement(field).value = val;
}



function toggle_exclusive_group(obj_on,group_ar,field,val) {
	for(var i=0;i<group_ar.length;i++) {
		var d = group_ar[i];
		if (typeof(obj_on) !== "undefined") {
			if (obj_on != d) {
				d = getElement(d);
				if (typeof(d) !== "undefined") {
					d.checked = "";
				}
			}
		}
	}
	getElement(field).value = val;
	obj_on = getElement(obj_on);
	if (typeof(obj_on) !== "undefined") {
		obj_on.checked = "true";
	}
	//alert(obj_on.id);
}


function reset_exclusive_group(group_ar,field,val) {
	for(var i=0;i<group_ar.length;i++) {
		var d = group_ar[i];
		getElement(d).checked = "";
	}
	getElement(field).value = val;
}













function concat(delim,pieces) {
	return pieces.join(delim);
}




function CRLF_to_BR(s) {
	s = s.replace(/\r/g,"");
	return s.replace(/\n/g,"<br/>");	
}



function remove_escaping(s) {
	if(typeof(s) !== "string") {
		return "";
	}
	s = s.replace(/\&quot;/g,"\"");
	s = s.replace(/\\'/g,"'");
	return s;
}

function add_escaping(s) {
	s = s.replace(/\"/g,"&quot;");
	return s;
}


function set_content(element,content) {
	element.innerHTML = content;
}


var is_array = function(v){
    return v &&
    typeof(v) === "object" &&
    typeof(v.length) === "number" &&
    typeof(v.splice) === "function" &&
    !(v.propertyIsEnumerable("length"));
};



function intval(mixed_var, base){
    // Get the integer value of a variable
    // 
    // +    discuss at: http://kevin.vanzonneveld.net/techblog/article/javascript_equivalent_for_phps_intval/
    // +       version: 809.522
    // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: stensi
    // +   bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // *     example 1: intval('Kevin van Zonneveld');
    // *     returns 1: 0
    // *     example 2: intval(4.2);
    // *     returns 2: 4
    // *     example 3: intval(42, 8);
    // *     returns 3: 42
    // *     example 4: intval('09');
    // *     returns 4: 9
    
    var tmp;
    
    
    
    if (typeof(mixed_var) == 'string') {
        tmp = parseInt(mixed_var * 1);
        if (isNaN(tmp)) {
            return 0;
        }
        else {
            return tmp.toString(base || 10);
        }
    }
    else 
        if (typeof(mixed_var) == 'number') {
            return Math.floor(mixed_var);
        }
        else {
            return 0;
        }
}// }}}




var Include = {
	included_css: new Array(),
	included_js: new Array(),
	
	css: function(file) {
		// todo: check to ensure file is not already included...
		this.included_css.push(file);
		
		var head = document.getElementsByTagName("head")[0];
		var css = document.createElement("link");
		css.type = "text/css";
		css.rel = "stylesheet";
		css.href = file;
		css.media = "screen";
		head.appendChild(css);
	},
	
	JS: function(file) {
		/*this.included_js.push(file);
		var head = document.getElementsByTagName("head")[0];
		var sc = document.createElement("script");
		sc.type = "text/javascript";
		sc.src = file;
		head.appendChild(sc);
		*/
		var ref = "<script type='text/javascript' src='" + file + "'" + ">" + "</" + "script>";
		document.write(ref);
		//alert(ref);
		//document.write("<script type='text/javascript' src='" + file + "'" + ">" + "</" + "script>");
		//alert(file);
	}
	
}


var OnLoad = {
	add: function(fun) {
		if (window.addEventListener) {
			window.addEventListener('load', fun, false);
		} else {
			window.attachEvent("onload",fun);
		}
	}
}






var ThisInstance = {
	onloaders: new Array(),
	
	add_onload: function(funref) {
		this.onloaders.push(funref);		
	},
	
	init: function() {
		for(var i=0;i<this.onloaders.length;i++) {
			eval(this.onloaders[i]);
		}
	}
	
}





var Position = {
	topLeft: function(obj){
		var topValue = 0, leftValue = 0;
		if(typeof(obj) === "string") {
			obj = getElement(obj);
		}
		while (obj) {
			leftValue += obj.offsetLeft;
			topValue += obj.offsetTop;
			obj = obj.offsetParent;
		}
		return {
			"x": leftValue,
			"y": topValue
		};
	}
}



var ConstrainInput = {
	to_numbers: function(obj) {
		obj = getElement(obj);
		obj.value = obj.value.replace(/[^0-9]/g,'');
	}
}

////////////////////////////////////



function grayOut(vis, options) {
  // Pass true to gray out screen, false to ungray
  // options are optional.  This is a JSON object with the following (optional) properties
  // opacity:0-100         // Lower number = less grayout higher = more of a blackout 
  // zindex: #             // HTML elements with a higher zindex appear on top of the gray out
  // bgcolor: (#xxxxxx)    // Standard RGB Hex color code
  // grayOut(true, {'zindex':'50', 'bgcolor':'#0000FF', 'opacity':'70'});
  // Because options is JSON opacity/zindex/bgcolor are all optional and can appear
  // in any order.  Pass only the properties you need to set.
  var options = options || {}; 
  var zindex = options.zindex || 50;
  var opacity = options.opacity || 70;
  var opaque = (opacity / 100);
  var bgcolor = options.bgcolor || '#000000';
  var dark=getElement('darkenScreenObject');
  if (!dark) {
    // The dark layer doesn't exist, it's never been created.  So we'll
    // create it here and apply some basic styles.
    // If you are getting errors in IE see: http://support.microsoft.com/default.aspx/kb/927917
    var tbody = document.getElementsByTagName("body")[0];
    var tnode = document.createElement('div');           // Create the layer.
        tnode.style.position='absolute';                 // Position absolutely
        tnode.style.top='0px';                           // In the top
        tnode.style.left='0px';                          // Left corner of the page
        tnode.style.overflow='hidden';                   // Try to avoid making scroll bars            
        tnode.style.display='none';                      // Start out Hidden
        tnode.id='darkenScreenObject';                   // Name it so we can find it later
    tbody.appendChild(tnode);                            // Add it to the web page
    dark=getElement('darkenScreenObject');  // Get the object.
  }
  if (vis) {
    // Calculate the page width and height 
    if( document.body && ( document.body.scrollWidth || document.body.scrollHeight ) ) {
        var pageWidth = "100%";//document.body.scrollWidth+'px';
        var pageHeight = "100%";document.body.scrollHeight+'px';
    } else if( document.body.offsetWidth ) {
      var pageWidth = "100%";//document.body.offsetWidth+'px';
      var pageHeight = "100%";//document.body.offsetHeight+'px';
    } else {
       var pageWidth='100%';
       var pageHeight='100%';
    }
    //set the shader to cover the entire page and make it visible.
    dark.style.opacity=opaque;                      
    dark.style.MozOpacity=opaque;                   
    dark.style.filter='alpha(opacity='+opacity+')'; 
    dark.style.zIndex=zindex;        
    dark.style.backgroundColor=bgcolor;  
    dark.style.width= pageWidth;
    dark.style.height= "4800px";
	dark.style.top = self.pageYOffset;
    dark.style.display='block';                          
  } else {
     dark.style.display='none';
  }
}

function removeGrayOut() {
	document.body.removeChild(getElement("darkenScreenObject"));
}



function center(div) {
div = getElement(div);
var Xwidth = parseInt(div.offsetWidth);
var Yheight = parseInt(div.offsetHeight);

//alert(Xwidth + "x" + Yheight);
//Xwidth = 463;
//Yheight = 500;

var scrolledX, scrolledY;
if( self.pageYOffset ) {
scrolledX = self.pageXOffset;
scrolledY = self.pageYOffset;
} else if( document.documentElement && document.documentElement.scrollTop ) {
scrolledX = document.documentElement.scrollLeft;
scrolledY = document.documentElement.scrollTop;
} else if( document.body ) {
scrolledX = document.body.scrollLeft;
scrolledY = document.body.scrollTop;
}

// Next, determine the coordinates of the center of browser's window

var centerX, centerY;
if( self.innerHeight ) {
centerX = self.innerWidth;
centerY = self.innerHeight;
} else if( document.documentElement && document.documentElement.clientHeight ) {
centerX = document.documentElement.clientWidth;
centerY = document.documentElement.clientHeight;
} else if( document.body ) {
centerX = document.body.clientWidth;
centerY = document.body.clientHeight;
}

// Xwidth is the width of the div, Yheight is the height of the
// div passed as arguments to the function:
var leftOffset = scrolledX + (centerX - Xwidth) / 2;
var topOffset = scrolledY + (centerY - Yheight) / 2;
// The initial width and height of the div can be set in the
// style sheet with display:none; divid is passed as an argument to // the function
var o=div;//document.getElementById(divid);
var r=o.style;
r.position='absolute';
r.top = topOffset + 'px';
r.left = leftOffset + 'px';
r.display = "block";
return div;
}





//////////////////////////////////////////////////////////////////
function serialize( mixed_value ) {
    // http://kevin.vanzonneveld.net
    // +   original by: Arpad Ray (mailto:arpad@php.net)
    // +   improved by: Dino
    // +   bugfixed by: Andrej Pavlovic
    // +   bugfixed by: Garagoth
    // %          note: We feel the main purpose of this function should be to ease the transport of data between php & js
    // %          note: Aiming for PHP-compatibility, we have to translate objects to arrays
    // *     example 1: serialize(['Kevin', 'van', 'Zonneveld']);
    // *     returns 1: 'a:3:{i:0;s:5:"Kevin";i:1;s:3:"van";i:2;s:9:"Zonneveld";}'
    // *     example 2: serialize({firstName: 'Kevin', midName: 'van', surName: 'Zonneveld'});
    // *     returns 2: 'a:3:{s:9:"firstName";s:5:"Kevin";s:7:"midName";s:3:"van";s:7:"surName";s:9:"Zonneveld";}'
 
    var _getType = function( inp ) {
        var type = typeof inp, match;
        var key;
        if (type == 'object' && !inp) {
            return 'null';
        }
        if (type == "object") {
            if (!inp.constructor) {
                return 'object';
            }
            var cons = inp.constructor.toString();
            if (match = cons.match(/(\w+)\(/)) {
                cons = match[1].toLowerCase();
            }
            var types = ["boolean", "number", "string", "array"];
            for (key in types) {
                if (cons == types[key]) {
                    type = types[key];
                    break;
                }
            }
        }
        return type;
    };
    var type = _getType(mixed_value);
    var val, ktype = '';
    
    switch (type) {
        case "function": 
            val = ""; 
            break;
        case "undefined":
            val = "N";
            break;
        case "boolean":
            val = "b:" + (mixed_value ? "1" : "0");
            break;
        case "number":
            val = (Math.round(mixed_value) == mixed_value ? "i" : "d") + ":" + mixed_value;
            break;
        case "string":
            val = "s:" + mixed_value.length + ":\"" + mixed_value + "\"";
            break;
        case "array":
        case "object":
            val = "a";
            /*
            if (type == "object") {
                var objname = mixed_value.constructor.toString().match(/(\w+)\(\)/);
                if (objname == undefined) {
                    return;
                }
                objname[1] = serialize(objname[1]);
                val = "O" + objname[1].substring(1, objname[1].length - 1);
            }
            */
            var count = 0;
            var vals = "";
            var okey;
            var key;
            for (key in mixed_value) {
                ktype = _getType(mixed_value[key]);
                if (ktype == "function") { 
                    continue; 
                }
                
                okey = (key.match(/^[0-9]+$/) ? parseInt(key) : key);
                vals += serialize(okey) +
                        serialize(mixed_value[key]);
                count++;
            }
            val += ":" + count + ":{" + vals + "}";
            break;
    }
    if (type != "object" && type != "array") val += ";";
    return val;
}


function formatNumber(n) {
	if (!isFinite(n)) {
	    return n;
	}
	
	var s = ""+n, abs = Math.abs(n), _, i;
	
	if (abs >= 1000) {
	    _ = (""+abs).split(/\./);
	    i = _[0].length % 3 || 3;
	
	    _[0] = s.slice(0,i + (n < 0)) +
	           _[0].slice(i).replace(/(\d{3})/g,',$1');
	
	    s = _.join('.');
	}
	
	return s;
}



function hilite(text,target,color) {
	text = text.replace(
		new RegExp(target,"gi"),
		"<span style='background-color:" + color + "'>" + target + "</span>"
	);
	document.write(text);
}














var Debug = {
	
	stringize: function(o) {
		if(typeof(o) == "string") {
			return entify(o);
		}
		var out = "";
		for(var i in o) {
			out += i + ": ";
			if (typeof(o[i]) == "object") {
				out += this.stringize(o[i]);
			} else {
				out += o[i] + "<br/>";
			}
		}
		return out;
	},
	
	debug: function(s) {
		
		var d = getElement("dbg_output");
		if( (typeof(d) == "undefined") || (d == null) ) {
			d = FilledElement("div", this.stringize(s) + "<br/>");
			d.style.width = "800px";
			d.style.height = "400px";
			d.style.overflow = "scroll";
			d.id = "dbg_output";
			document.body.appendChild(d);
		} else {
			d.innerHTML += this.stringize(s) + "<br/>";
		}
		
		if (this.visible) {
			show("dbg_output");
		} else {
			hide("dbg_output");
		}
	}
}




if (typeof Object.beget !== 'function') {
	Object.beget = function(o) {
    	var F = function() {};
        F.prototype = o;
        return new F();
    };
}




function Bless(obj){
	if (BrowserDetect.browser == "Explorer") {
		obj.getElementsByClassName = function(n){
			var c = this.getElementsByTagName('*');
			var m = new Array();
			for (var i = 0; i < c.length; i++) {
				if (c[i].className.indexOf(n) !== -1) {
					m.push(c[i]);
				}
			}
			return m;
		}
	}
}




if (!Array.prototype.indexOf)
{
  Array.prototype.indexOf = function(elt /*, from*/)
  {
    var len = this.length;

    var from = Number(arguments[1]) || 0;
    from = (from < 0)
         ? Math.ceil(from)
         : Math.floor(from);
    if (from < 0)
      from += len;

    for (; from < len; from++)
    {
      if (from in this &&
          this[from] === elt)
        return from;
    }
    return -1;
  };
}


if(!String.prototype.toAssoc) {
	String.prototype.toAssoc = function(outerDelim,innerDelim) {
		var ar = this.split(outerDelim);
		var assoc = [];
		for(var i=0;i<ar.length;i++) {
			var pair = ar[i].split(innerDelim);
			assoc[pair[0]] = pair[1];
		}
		return assoc;		
	}
}



var isset = function(obj) {
	return (typeof(obj) == "undefined"); 
}


var fixCollections = function(obj) {
	if (typeof(obj.getElementsByClassName) == "undefined") {
		obj.getElementsByClassName = function(n){
			var c = this.getElementsByTagName('*');
			var m = new Array();
			for (var i = 0; i < c.length; i++) {
				if (c[i].className.indexOf(n) !== -1) {
					m.push(c[i]);
				}
			}
			return m;
		}
	}
}





/**
 * SWFObject v1.5: Flash Player detection and embed - http://blog.deconcept.com/swfobject/
 *
 * SWFObject is (c) 2007 Geoff Stearns and is released under the MIT License:
 * http://www.opensource.org/licenses/mit-license.php
 *
 */
if(typeof deconcept=="undefined"){var deconcept=new Object();}if(typeof deconcept.util=="undefined"){deconcept.util=new Object();}if(typeof deconcept.SWFObjectUtil=="undefined"){deconcept.SWFObjectUtil=new Object();}deconcept.SWFObject=function(_1,id,w,h,_5,c,_7,_8,_9,_a){if(!document.getElementById){return;}this.DETECT_KEY=_a?_a:"detectflash";this.skipDetect=deconcept.util.getRequestParameter(this.DETECT_KEY);this.params=new Object();this.variables=new Object();this.attributes=new Array();if(_1){this.setAttribute("swf",_1);}if(id){this.setAttribute("id",id);}if(w){this.setAttribute("width",w);}if(h){this.setAttribute("height",h);}if(_5){this.setAttribute("version",new deconcept.PlayerVersion(_5.toString().split(".")));}this.installedVer=deconcept.SWFObjectUtil.getPlayerVersion();if(!window.opera&&document.all&&this.installedVer.major>7){deconcept.SWFObject.doPrepUnload=true;}if(c){this.addParam("bgcolor",c);}var q=_7?_7:"high";this.addParam("quality",q);this.setAttribute("useExpressInstall",false);this.setAttribute("doExpressInstall",false);var _c=(_8)?_8:window.location;this.setAttribute("xiRedirectUrl",_c);this.setAttribute("redirectUrl","");if(_9){this.setAttribute("redirectUrl",_9);}};deconcept.SWFObject.prototype={useExpressInstall:function(_d){this.xiSWFPath=!_d?"expressinstall.swf":_d;this.setAttribute("useExpressInstall",true);},setAttribute:function(_e,_f){this.attributes[_e]=_f;},getAttribute:function(_10){return this.attributes[_10];},addParam:function(_11,_12){this.params[_11]=_12;},getParams:function(){return this.params;},addVariable:function(_13,_14){this.variables[_13]=_14;},getVariable:function(_15){return this.variables[_15];},getVariables:function(){return this.variables;},getVariablePairs:function(){var _16=new Array();var key;var _18=this.getVariables();for(key in _18){_16[_16.length]=key+"="+_18[key];}return _16;},getSWFHTML:function(){var _19="";if(navigator.plugins&&navigator.mimeTypes&&navigator.mimeTypes.length){if(this.getAttribute("doExpressInstall")){this.addVariable("MMplayerType","PlugIn");this.setAttribute("swf",this.xiSWFPath);}_19="<embed type=\"application/x-shockwave-flash\" src=\""+this.getAttribute("swf")+"\" width=\""+this.getAttribute("width")+"\" height=\""+this.getAttribute("height")+"\" style=\""+this.getAttribute("style")+"\"";_19+=" id=\""+this.getAttribute("id")+"\" name=\""+this.getAttribute("id")+"\" ";var _1a=this.getParams();for(var key in _1a){_19+=[key]+"=\""+_1a[key]+"\" ";}var _1c=this.getVariablePairs().join("&");if(_1c.length>0){_19+="flashvars=\""+_1c+"\"";}_19+="/>";}else{if(this.getAttribute("doExpressInstall")){this.addVariable("MMplayerType","ActiveX");this.setAttribute("swf",this.xiSWFPath);}_19="<object id=\""+this.getAttribute("id")+"\" classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" width=\""+this.getAttribute("width")+"\" height=\""+this.getAttribute("height")+"\" style=\""+this.getAttribute("style")+"\">";_19+="<param name=\"movie\" value=\""+this.getAttribute("swf")+"\" />";var _1d=this.getParams();for(var key in _1d){_19+="<param name=\""+key+"\" value=\""+_1d[key]+"\" />";}var _1f=this.getVariablePairs().join("&");if(_1f.length>0){_19+="<param name=\"flashvars\" value=\""+_1f+"\" />";}_19+="</object>";}return _19;},write:function(_20){if(this.getAttribute("useExpressInstall")){var _21=new deconcept.PlayerVersion([6,0,65]);if(this.installedVer.versionIsValid(_21)&&!this.installedVer.versionIsValid(this.getAttribute("version"))){this.setAttribute("doExpressInstall",true);this.addVariable("MMredirectURL",escape(this.getAttribute("xiRedirectUrl")));document.title=document.title.slice(0,47)+" - Flash Player Installation";this.addVariable("MMdoctitle",document.title);}}if(this.skipDetect||this.getAttribute("doExpressInstall")||this.installedVer.versionIsValid(this.getAttribute("version"))){var n=(typeof _20=="string")?document.getElementById(_20):_20;n.innerHTML=this.getSWFHTML();return true;}else{if(this.getAttribute("redirectUrl")!=""){document.location.replace(this.getAttribute("redirectUrl"));}}return false;}};deconcept.SWFObjectUtil.getPlayerVersion=function(){var _23=new deconcept.PlayerVersion([0,0,0]);if(navigator.plugins&&navigator.mimeTypes.length){var x=navigator.plugins["Shockwave Flash"];if(x&&x.description){_23=new deconcept.PlayerVersion(x.description.replace(/([a-zA-Z]|\s)+/,"").replace(/(\s+r|\s+b[0-9]+)/,".").split("."));}}else{if(navigator.userAgent&&navigator.userAgent.indexOf("Windows CE")>=0){var axo=1;var _26=3;while(axo){try{_26++;axo=new ActiveXObject("ShockwaveFlash.ShockwaveFlash."+_26);_23=new deconcept.PlayerVersion([_26,0,0]);}catch(e){axo=null;}}}else{try{var axo=new ActiveXObject("ShockwaveFlash.ShockwaveFlash.7");}catch(e){try{var axo=new ActiveXObject("ShockwaveFlash.ShockwaveFlash.6");_23=new deconcept.PlayerVersion([6,0,21]);axo.AllowScriptAccess="always";}catch(e){if(_23.major==6){return _23;}}try{axo=new ActiveXObject("ShockwaveFlash.ShockwaveFlash");}catch(e){}}if(axo!=null){_23=new deconcept.PlayerVersion(axo.GetVariable("$version").split(" ")[1].split(","));}}}return _23;};deconcept.PlayerVersion=function(_29){this.major=_29[0]!=null?parseInt(_29[0]):0;this.minor=_29[1]!=null?parseInt(_29[1]):0;this.rev=_29[2]!=null?parseInt(_29[2]):0;};deconcept.PlayerVersion.prototype.versionIsValid=function(fv){if(this.major<fv.major){return false;}if(this.major>fv.major){return true;}if(this.minor<fv.minor){return false;}if(this.minor>fv.minor){return true;}if(this.rev<fv.rev){return false;}return true;};deconcept.util={getRequestParameter:function(_2b){var q=document.location.search||document.location.hash;if(_2b==null){return q;}if(q){var _2d=q.substring(1).split("&");for(var i=0;i<_2d.length;i++){if(_2d[i].substring(0,_2d[i].indexOf("="))==_2b){return _2d[i].substring((_2d[i].indexOf("=")+1));}}}return "";}};deconcept.SWFObjectUtil.cleanupSWFs=function(){var _2f=document.getElementsByTagName("OBJECT");for(var i=_2f.length-1;i>=0;i--){_2f[i].style.display="none";for(var x in _2f[i]){if(typeof _2f[i][x]=="function"){_2f[i][x]=function(){};}}}};if(deconcept.SWFObject.doPrepUnload){if(!deconcept.unloadSet){deconcept.SWFObjectUtil.prepUnload=function(){__flash_unloadHandler=function(){};__flash_savedUnloadHandler=function(){};window.attachEvent("onunload",deconcept.SWFObjectUtil.cleanupSWFs);};window.attachEvent("onbeforeunload",deconcept.SWFObjectUtil.prepUnload);deconcept.unloadSet=true;}}if(!document.getElementById&&document.all){document.getElementById=function(id){return document.all[id];};}var getQueryParamValue=deconcept.util.getRequestParameter;var FlashObject=deconcept.SWFObject;var SWFObject=deconcept.SWFObject;
