/* http://www.desertdispatch.com/common/tools/load.php?js=common_fi_oas,common_freedom,common_ads,common_page */
function getLast(s, num)
	{
	return s.substr(s.length - num, num);
	}


function approveAd(tagpos)
	{
	var last = getLast(location.href, 7);

	if(last.toLowerCase() == "?google")
		{
		if(tagpos == "Right3")
			return false;
		}

	return true;
	}


function FI_OAS_RICH(tagpos)
	{
	if(approveAd(tagpos))
		OAS_RICH(tagpos);
	}

function resize_iframe(obj)
	{
	var h=obj.contentWindow.document.body.scrollHeight;
	obj.style.height=h;
	}Freedom = function() {
	this.initialize.apply(this, arguments);
};

Freedom.prototype = {
	initialize: function() {
		var args;
		if ((arguments.length == 1) && (typeof(arguments[0]) == 'object')) {
			args = arguments[0];
		}
		else {
			args = {};
			switch(arguments.length) {
				case 1:
					args.domain = arguments[0];
					break;
				case 2:
					args.domain = arguments[0];
					args.taxonomy = arguments[1];
					break;
				case 2:
					args.domain = arguments[0];
					args.taxonomy = arguments[1];
					args.positions = arguments[2];
					break;
				default:
					break;
			}
		}

		if (typeof(args.positions) == 'undefined') { args.positions = 'Top,Right,Right1,Left1,Middle,Middle1'; }

		this.positions = args.positions;
		this.domain = typeof(args.domain) != 'undefined' ? args.domain : 'ocregister.com';
		this.taxonomy = typeof(args.taxonomy) != 'undefined' ? args.taxonomy : '/homepage';

		this.page = new Page(args);
		this.ads = new Ads(args);
	},

	'$': function(id) {
		return document.getElementById(id);
	}
};
Ads = function() {
	this.iframeSource = 'http://common.onset.freedom.com/oas/jx/';
	this.RNS = new String (Math.random()).substring(2, 11);
	this.autoRefresh = false;
	this.refreshTime = 2 * 60 * 1000; // Milliseconds
	this.queryValues = "";
	this.initialize.apply(this, arguments);
};

Ads.prototype = {
	initialize: function() {
		var args;
		if ((arguments.length == 1) && (typeof(arguments[0]) == 'object')) {
			args = arguments[0];
		}
		else {
			args = {};
			switch(arguments.length) {
				case 1:
					args.domain = arguments[0];
					break;
				case 2:
					args.domain = arguments[0];
					args.taxonomy = arguments[1];
					break;
				case 3:
					args.domain = arguments[0];
					args.taxonomy = arguments[1];
					args.positions = arguments[2];
					break;
				default:
					break;
			}
		}

		this.domain = typeof(args.domain) != 'undefined' ? args.domain : 'ocregister.com';
		this.taxonomy = typeof(args.taxonomy) != 'undefined' ? args.taxonomy : '/homepage';
		this.positions = typeof(args.positions) != 'undefined' ? args.positions : '';
	},
	setQuery:function() {
		if (arguments.length) 
			this.queryValues = arguments[0];
	},
	iframe: function () {
		var args;
		var domain;
		var taxonomy;

		if (arguments.length == 1) {
			if (typeof(arguments[0]) == 'object') {
				args = arguments[0];
			}
			else {
				args = {};
				switch(arguments.length) {
					case 1:
						args.position = arguments[0];
						break;
					case 2:
						args.position = arguments[0];
						args.positions = arguments[1];
						break;
					default:
						break;
				}
			}
		}

		if (typeof(args) == 'undefined') { return; }
		if (typeof(args.position) == 'undefined') { return; }

		var width = (typeof(args.width) != 'undefined') ? args.width : this.defaultWidth(args.position);
		var height = (typeof(args.height) != 'undefined') ? args.height : this.defaultHeight(args.position);
		var positions = (typeof(args.positions) != 'undefined') ? args.positions : this.positions;

		var pos = -1;
		if (typeof(args.domain) != 'undefined') {
			domain = args.domain;
		}
		else if (typeof(OAS_sitepage) != 'undefined') {
			pos = OAS_sitepage.indexOf('/');
			if (pos != -1) {
				domain = OAS_sitepage.substr(0, pos);
			}
			else {
				domain = this.domain;
			}
		}
		else {
			domain = this.domain;
		}

		if (typeof(args.taxonomy) != 'undefined') {
			taxonomy = args.taxonomy;
		}
		else if (typeof(OAS_sitepage) != 'undefined') {
			pos = OAS_sitepage.indexOf('/');
			if (pos != -1) {
				taxonomy = OAS_sitepage.substr(pos);
			}
			else {
				taxonomy = this.taxonomy;
			}
		}
		else {
			taxonomy = this.taxonomy;
		}

		document.write('<iframe id="position' + args.position + '" name="position' + args.position + '" width="' + width + '" height="' + height + '" frameborder="0" marginheight="0" marginwidth="0" scrolling="no" src="' + this.iframeSource + '?domain=' + domain + '&taxonomy=' + taxonomy + '&positions=' + positions + '&position=' + args.position + '&rand=' + this.RNS + '&query=' + this.queryValues + '"></iframe>');

		if (this.autoRefresh) {
			document.write('<scr' + 'ipt type="text/javascript">setInterval("reloadFrame(\\"position' + args.position + '\\")", ' + this.refreshTime + ');<\/scr' + 'ipt>');
		}
	},

	defaultWidth: function (position) {
		var width = 0;
		switch(position) {
			case 'Top':
				width = 728;
				break;
			case 'Right1':
				width = 120;
				break;
			case 'Right':
				width = 160;
				break;
			case 'Left1':
				width = 120;
				break;
			case 'Middle':
			case 'Middle1':
				width = 300;
				break;
			default:
				width = 0;
		}
		return width;
	},

	defaultHeight: function (position) {
		var height = 0;
		switch(position) {
			case 'Top':
			case 'Right1':
				height = 90;
				break;
			case 'Right':
			case 'Left1':
				height = 600;
				break;
			case 'Middle':
			case 'Middle1':
				height = 250;
				break;
			default:
				height = 0;
		}
		return height;
	},

	'$': function(id) {
		return document.getElementById(id);
	}
};

function reloadFrame(frm) {
	var f = document.getElementById(frm);
	if (f) f.src = f.src;
}
Page = function() {
	this.initialize.apply(this, arguments);
};

Page.prototype = {
	initialize: function() {
		var args;
		if ((arguments.length == 1) && (typeof(arguments[0]) == 'object')) {
			args = arguments[0];
		}
		else {
			args = {};
			switch(arguments.length) {
				case 1:
					args.domain = arguments[0];
					break;
				case 2:
					args.domain = arguments[0];
					args.taxonomy = arguments[1];
					break;
				default:
					break;
			}
		}

		this.domain = typeof(args.domain) != 'undefined' ? args.domain : 'ocregister.com';
		this.taxonomy = typeof(args.taxonomy) != 'undefined' ? args.taxonomy : '/homepage';
	},

	onload: function () {
	},

	'$': function(id) {
		return document.getElementById(id);
	}
};
