/* This file is based on Macromedia's JavaScriptFlashGateway.js - it is an exact
   copy of this file, with a small omnidate.com-specific addition at the end of
   the file. */
   
/*
Macromedia(r) Flash(r) JavaScript Integration Kit License


Copyright (c) 2005 Macromedia, inc. All rights reserved.

Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.

2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation and/or
other materials provided with the distribution.

3. The end-user documentation included with the redistribution, if any, must
include the following acknowledgment:

"This product includes software developed by Macromedia, Inc.
(http://www.macromedia.com)."

Alternately, this acknowledgment may appear in the software itself, if and
wherever such third-party acknowledgments normally appear.

4. The name Macromedia must not be used to endorse or promote products derived
from this software without prior written permission. For written permission,
please contact devrelations@macromedia.com.

5. Products derived from this software may not be called "Macromedia" or
"Macromedia Flash", nor may "Macromedia" or "Macromedia Flash" appear in their
name.

THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL MACROMEDIA OR
ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
DAMAGE.

--

This code is part of the Flash / JavaScript Integration Kit:
http://www.macromedia.com/go/flashjavascript/

Created by:

Christian Cantrell
http://weblogs.macromedia.com/cantrell/
mailto:cantrell@macromedia.com

Mike Chambers
http://weblogs.macromedia.com/mesh/
mailto:mesh@macromedia.com

Macromedia

Modified by Media Semantics, Inc. (MSI) as marked to add setWMode(), setBase().
*/

/**
 * Create a new Exception object.
 * name: The name of the exception.
 * message: The exception message.
 */
function Exception(name, message)
{
    if (name)
        this.name = name;
    if (message)
        this.message = message;
}

/**
 * Set the name of the exception. 
 */
Exception.prototype.setName = function(name)
{
    this.name = name;
}

/**
 * Get the exception's name. 
 */
Exception.prototype.getName = function()
{
    return this.name;
}

/**
 * Set a message on the exception. 
 */
Exception.prototype.setMessage = function(msg)
{
    this.message = msg;
}

/**
 * Get the exception message. 
 */
Exception.prototype.getMessage = function()
{
    return this.message;
}

/**
 * Generates a browser-specific Flash tag. Create a new instance, set whatever
 * properties you need, then call either toString() to get the tag as a string, or
 * call write() to write the tag out.
 */

/**
 * Creates a new instance of the FlashTag.
 * src: The path to the SWF file.
 * width: The width of your Flash content.
 * height: the height of your Flash content.
 */
function FlashTag(src, width, height)
{
    this.src       = src;
    this.width     = width;
    this.height    = height;
    this.version   = '7,0,14,0';
    this.id        = null;
    this.style     = null;
    this.bgcolor   = 'ffffff';
	this.flashVars = null;
    this.wmode     = null; // MSI
    this.base      = null; // MSI
    this.allowscriptaccess      = null; // MSI
}

/**
 * Sets the Flash version used in the Flash tag.
 */
FlashTag.prototype.setVersion = function(v)
{
    this.version = v;
}

/**
 * Sets the ID used in the Flash tag.
 */
FlashTag.prototype.setId = function(id)
{
    this.id = id;
}


/**
 * Sets the ID used in the Flash tag.
 */
FlashTag.prototype.setStyle = function(style)
{
    this.style = style;
}

/**
 * Sets the background color used in the Flash tag.
 */
FlashTag.prototype.setBgcolor = function(bgc)
{
    this.bgcolor = bgc;
}



/**
 * Sets any variables to be passed into the Flash content. 
 */
FlashTag.prototype.setFlashvars = function(fv)
{
    this.flashVars = fv;
}

// Begin MSI

/**
 * Sets wmode
 */
FlashTag.prototype.setWmode = function(wm)
{
    this.wmode = wm;
}

/**
 * Sets base
 */
FlashTag.prototype.setBase = function(b)
{
    this.base = b;
}

/**
 * Sets allowscriptaccess
 */
FlashTag.prototype.setAllowScriptAccess = function(b)
{
    this.allowscriptaccess = b;
}

// End MSI

/**
 * Get the Flash tag as a string. 
 */
FlashTag.prototype.toString = function()
{
    var ie = (navigator.appName.indexOf ("Microsoft") != -1) ? 1 : 0;
    var flashTag = new String();
    if (ie)
    {
        flashTag += '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" ';
        if (this.id != null)
        {
            flashTag += 'id="'+this.id+'" ';
        }
        if (this.style != null)
        {
            flashTag += 'style="'+this.style+'" ';
		}
		flashTag += 'codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version='+this.version+'" ';
        flashTag += 'width="'+this.width+'" ';
        flashTag += 'height="'+this.height+'">';
        flashTag += '<param name="movie" value="'+this.src+'"/>';
        flashTag += '<param name="quality" value="high"/>';
        flashTag += '<param name="bgcolor" value="#'+this.bgcolor+'"/>';
        if (this.flashVars != null)
        {
			//alert(this.flashVars);
            flashTag += '<param name="flashvars" value="'+this.flashVars+'"/>';
        }
        // Begin MSI
        if (this.wmode != null)
        {
            flashTag += '<param name="wmode" value="'+this.wmode+'"/>';
        }
        if (this.base != null)
        {
            flashTag += '<param name="base" value="'+this.base+'"/>';
        }
        if (this.allowscriptaccess != null)
        {
            flashTag += '<param name="allowscriptaccess" value="'+this.allowscriptaccess+'"/>';
        }
        // End MSI
        flashTag += '</object>';
    }
    else
    {
        flashTag += '<embed src="'+this.src+'" ';
        flashTag += 'quality="high" '; 
        flashTag += 'bgcolor="#'+this.bgcolor+'" ';
        flashTag += 'width="'+this.width+'" ';
        flashTag += 'height="'+this.height+'" ';
        flashTag += 'type="application/x-shockwave-flash" ';
        if (this.flashVars != null)
        {
 		//alert(this.flashVars);
           flashTag += 'flashvars="'+this.flashVars+'" ';
        }
        if (this.style != null)
        {
            flashTag += 'style="'+this.style+'" ';
		}
      // Begin MSI
        if (this.wmode != null)
        {
            flashTag += 'wmode="'+this.wmode+'" ';
        }
        if (this.base != null)
        {
            flashTag += 'base="'+this.base+'" ';
        }
        if (this.allowscriptaccess != null)
        {
            flashTag += 'allowscriptaccess="'+this.allowscriptaccess+'" ';
        }
        // End MSI
        if (this.id != null)
        {
            flashTag += 'name="'+this.id+'" ';
        }
        flashTag += 'pluginspage="http://www.macromedia.com/go/getflashplayer">';
        flashTag += '</embed>';
    }
    return flashTag;
}

/**
 * Write the Flash tag out. Pass in a reference to the document to write to. 
 */
FlashTag.prototype.write = function(doc)
{
    doc.write(this.toString());
}

/**
 * The FlashSerializer serializes JavaScript variables of types object, array, string,
 * number, date, boolean, null or undefined into XML. 
 */

/**
 * Create a new instance of the FlashSerializer.
 * useCdata: Whether strings should be treated as character data. If false, strings are simply XML encoded.
 */
function FlashSerializer(useCdata)
{
    this.useCdata = useCdata;
}

/**
 * Serialize an array into a format that can be deserialized in Flash. Supported data types are object,
 * array, string, number, date, boolean, null, and undefined. Returns a string of serialized data.
 */
FlashSerializer.prototype.serialize = function(args)
{
    var qs = new String();

    for (var i = 0; i < args.length; ++i)
    {
        switch(typeof(args[i]))
        {
            case 'undefined':
                qs += 't'+(i)+'=undf';
                break;
            case 'string':
                qs += 't'+(i)+'=str&d'+(i)+'='+escape(args[i]);
                break;
            case 'number':
                qs += 't'+(i)+'=num&d'+(i)+'='+escape(args[i]);
                break;
            case 'boolean':
                qs += 't'+(i)+'=bool&d'+(i)+'='+escape(args[i]);
                break;
            case 'object':
                if (args[i] == null)
                {
                    qs += 't'+(i)+'=null';
                }
                else if (args[i] instanceof Date)
                {
                    qs += 't'+(i)+'=date&d'+(i)+'='+escape(args[i].getTime());
                }
                else // array or object
                {
                    try
                    {
                        qs += 't'+(i)+'=xser&d'+(i)+'='+escape(this._serializeXML(args[i]));
                    }
                    catch (exception)
                    {
                        throw new Exception("FlashSerializationException",
                                            "The following error occurred during complex object serialization: " + exception.getMessage());
                    }
                }
                break;
            default:
                throw new Exception("FlashSerializationException",
                                    "You can only serialize strings, numbers, booleans, dates, objects, arrays, nulls, and undefined.");
        }

        if (i != (args.length - 1))
        {
            qs += '&';
        }
    }

    return qs;
}

/**
 * Private
 */
FlashSerializer.prototype._serializeXML = function(obj)
{
    var doc = new Object();
    doc.xml = '<fp>'; 
    this._serializeNode(obj, doc, null);
    doc.xml += '</fp>'; 
    return doc.xml;
}

/**
 * Private
 */
FlashSerializer.prototype._serializeNode = function(obj, doc, name)
{
    switch(typeof(obj))
    {
        case 'undefined':
            doc.xml += '<undf'+this._addName(name)+'/>';
            break;
        case 'string':
            doc.xml += '<str'+this._addName(name)+'>'+this._escapeXml(obj)+'</str>';
            break;
        case 'number':
            doc.xml += '<num'+this._addName(name)+'>'+obj+'</num>';
            break;
        case 'boolean':
            doc.xml += '<bool'+this._addName(name)+' val="'+obj+'"/>';
            break;
        case 'object':
            if (obj == null)
            {
                doc.xml += '<null'+this._addName(name)+'/>';
            }
            else if (obj instanceof Date)
            {
                doc.xml += '<date'+this._addName(name)+'>'+obj.getTime()+'</date>';
            }
            else if (obj instanceof Array)
            {
                doc.xml += '<array'+this._addName(name)+'>';
                for (var i = 0; i < obj.length; ++i)
                {
                    this._serializeNode(obj[i], doc, null);
                }
                doc.xml += '</array>';
            }
            else
            {
                doc.xml += '<obj'+this._addName(name)+'>';
                for (var n in obj)
                {
                    if (typeof(obj[n]) == 'function')
                        continue;
                    this._serializeNode(obj[n], doc, n);
                }
                doc.xml += '</obj>';
            }
            break;
        default:
            throw new Exception("FlashSerializationException",
                                "You can only serialize strings, numbers, booleans, objects, dates, arrays, nulls and undefined");
            break;
    }
}

/**
 * Private
 */
FlashSerializer.prototype._addName= function(name)
{
    if (name != null)
    {
        return ' name="'+name+'"';
    }
    return '';
}

/**
 * Private
 */
FlashSerializer.prototype._escapeXml = function(str)
{
    if (this.useCdata)
        return '<![CDATA['+str+']]>';
    else
        return str.replace(/&/g,'&amp;').replace(/</g,'&lt;');
}

/**
 * The FlashProxy object is what proxies function calls between JavaScript and Flash.
 * It handles all argument serialization issues.
 */

/**
 * Instantiates a new FlashProxy object. Pass in a uniqueID and the name (including the path)
 * of the Flash proxy SWF. The ID is the same ID that needs to be passed into your Flash content as lcId.
 */
function FlashProxy(uid, proxySwfName)
{
    this.uid = uid;
    this.proxySwfName = proxySwfName;
    this.flashSerializer = new FlashSerializer(false);
}

/**
 * Call a function in your Flash content.  Arguments should be:
 * 1. ActionScript function name to call,
 * 2. any number of additional arguments of type object,
 *    array, string, number, boolean, date, null, or undefined. 
 */
FlashProxy.prototype.call = function()
{
    if (arguments.length == 0)
    {
        throw new Exception("Flash Proxy Exception",
                            "The first argument should be the function name followed by any number of additional arguments.");
    }

    var qs = 'lcId=' + escape(this.uid) + '&functionName=' + escape(arguments[0]);

    if (arguments.length > 1)
    {
        var justArgs = new Array();
        for (var i = 1; i < arguments.length; ++i)
        {
            justArgs.push(arguments[i]);
        }
        qs += ('&' + this.flashSerializer.serialize(justArgs));
    }
	//qs += '&s=1';
	//alert(qs);

    var divName = '_flash_proxy_' + this.uid;
    if(!document.getElementById(divName))
    {
        var newTarget = document.createElement("div");
        newTarget.id = divName;
        document.body.appendChild(newTarget);
    }
    var target = document.getElementById(divName);
    var ft = new FlashTag(this.proxySwfName, 1, 1);
    ft.setVersion('6,0,65,0');
    ft.setFlashvars(qs);
	ft.setId('tempObj');
	target.innerHTML = ft.toString();
}

/*
function removeElement(divNum) {
  var d = document.getElementById('myDiv');
  var olddiv = document.getElementById(divNum);
  d.removeChild(olddiv);
}
*/

/**
 * This is the function that proxies function calls from Flash to JavaScript.
 * It is called implicitly.
 */
FlashProxy.callJS = function()
{
    var functionToCall = eval(arguments[0]);
    var argArray = new Array();
    for (var i = 1; i < arguments.length; ++i)
    {
        argArray.push(arguments[i]);
    }
    functionToCall.apply(functionToCall, argArray);
}





/***************************************************************************************************************
************	OmniDate Include
***************************************************************************************************************/
jQuery.noConflict();
var Omni_BannerProxy;
var Omni_lcId = new Date().getTime();
var Omni_Unique = 1;

var Omni_data = "";

var Omni_Frequency = 10;
var PingInterval = 0;
var Omni_ArStatus = [];
var Omni_Unique = 0;

var Omni_userid = "";
var username = "";
var gender = "";
var dbid = "";
var siteCode = "";
var dating = "";

var You = "";
var YourId = "";
var YourName = "";
var YourDate = "";
var YourDateId = "";
var YourDateName = "";

var Omni_Table = "";
var StorylineFile = "";
var RedirectLink = "";

var LoadStarted = false;
var InviteOverShowing = false;
var DateHasBeenRequested = false;
var TimeRemaining = "";
var BannerShowing = false;

var Omni_Server = "http://www.omnidate.com/partnerships/";
var IntegFolder = "partnerships/";
var popup = false;
var Omni_landing = "";
var Omni_bannerStyle = "";
var bannerExists = false;
var Omni_profile = "";
var IgnorePingReturn = false;


/***************************************************************************************************************
************	Button UI Default Values
***************************************************************************************************************/
var uiObj01 = new Object;
uiObj01.offline = "http://www.omnidate.com/partnerships/images/offline.gif";
uiObj01.online = "http://www.omnidate.com/partnerships/images/online.gif";
uiObj01.inactive = "http://www.omnidate.com/partnerships/images/online2.gif";
uiObj01.dating = "http://www.omnidate.com/partnerships/images/dating.gif";
uiObj01.info = "http://www.omnidate.com/partnerships/images/info01.png";
uiObj01.height = "18";
uiObj01.width = "65";
uiObj01.iheight = "18";
uiObj01.iwidth = "18";

var uiObj02 = new Object;
uiObj02.offline = "http://www.omnidate.com/partnerships/images/offline-omnidate.gif";
uiObj02.online = "http://www.omnidate.com/partnerships/images/online-omnidate.gif";
uiObj02.inactive = "http://www.omnidate.com/partnerships/images/online2-omnidate.gif";
uiObj02.dating = "http://www.omnidate.com/partnerships/images/dating-omnidate.gif";
uiObj02.info = "http://www.omnidate.com/partnerships/images/omnidate-info.gif";
uiObj02.iposition = "bottom";
uiObj02.height = "37";
uiObj02.width = "41";
uiObj02.iheight = "12";
uiObj02.iwidth = "41";

var PQui01 = new Object;
PQui01.offline = "http://www.omnidate.com/partnerships/images/pq-offline.gif";
PQui01.online = "http://www.omnidate.com/partnerships/images/pq-online.gif";
PQui01.inactive = "http://www.omnidate.com/partnerships/images/pq-inactive.gif";
PQui01.dating = "http://www.omnidate.com/partnerships/images/pq-dating.gif";
PQui01.info = "http://www.omnidate.com/partnerships/images/info01.png";
PQui01.height = "18";
PQui01.width = "84";
PQui01.iheight = "18";
PQui01.iwidth = "18";

var STBui01 = new Object;
STBui01.offline = "http://www.omnidate.com/partnerships/images/stb1-offline.gif";
STBui01.online = "http://www.omnidate.com/partnerships/images/stb1-online.gif";
STBui01.inactive = "http://www.omnidate.com/partnerships/images/stb1-inactive.gif";
STBui01.dating = "http://www.omnidate.com/partnerships/images/stb1-dating.gif";
STBui01.info = "http://www.omnidate.com/partnerships/images/info01.gif";
STBui01.height = "18";
STBui01.width = "135";
STBui01.iheight = "18";
STBui01.iwidth = "18";

var STBui02 = new Object;
STBui02.offline = "http://www.omnidate.com/partnerships/images/stb2-inactive.gif";
STBui02.online = "http://www.omnidate.com/partnerships/images/stb2-online.gif";
STBui02.inactive = "http://www.omnidate.com/partnerships/images/stb2-inactive.gif";
STBui02.dating = "http://www.omnidate.com/partnerships/images/stb2-dating.gif";
STBui02.info = "http://www.omnidate.com/partnerships/images/info01.gif";
STBui02.height = "20";
STBui02.width = "62";
STBui02.iheight = "18";
STBui02.iwidth = "18";

var AFui01 = new Object;
AFui01.offline = "http://www.omnidate.com/partnerships/images/af-offline.gif";
AFui01.online = "http://www.omnidate.com/partnerships/images/af-online.gif";
AFui01.inactive = "http://www.omnidate.com/partnerships/images/af-inactive.gif";
AFui01.dating = "http://www.omnidate.com/partnerships/images/af-dating.gif";
AFui01.info = "http://www.omnidate.com/partnerships/images/info01.gif";
AFui01.height = "18";
AFui01.width = "65";
AFui01.iheight = "18";
AFui01.iwidth = "18";


var AFui02 = new Object;
AFui02.offline = "http://www.omnidate.com/partnerships/images/af-offline2.gif";
AFui02.online = "http://www.omnidate.com/partnerships/images/af-online2.gif";
AFui02.inactive = "http://www.omnidate.com/partnerships/images/af-inactive2.gif";
AFui02.dating = "http://www.omnidate.com/partnerships/images/af-dating2.gif";
AFui02.info = "http://www.omnidate.com/partnerships/images/info01.gif";
AFui02.height = "29";
AFui02.width = "129";
AFui02.iheight = "18";
AFui02.iwidth = "18";





var uiDefaults = new Object;
uiDefaults['uiObj01'] = uiObj01;
uiDefaults['uiObj02'] = uiObj02;
uiDefaults['PQui01'] = PQui01;
uiDefaults['STBui01'] = STBui01;
uiDefaults['STBui02'] = STBui02;
uiDefaults['AFui01'] = AFui01;
uiDefaults['AFui02'] = AFui02;

var uiObj;
var btnUiAr = new Object;

var OmniTitles = new Object;
OmniTitles.offline = "Unavailable for a Virtual Date. Message Them Now to Schedule a Date.";
OmniTitles.online = "Invite This User on a Virtual Date Now!";
OmniTitles.inactive = "";
OmniTitles.dating = "This User is on a Virtual Date";
OmniTitles.info = "View More Info / Select Your Virtual Character";



/***************************************************************************************************************
************	Registration and Broadcasting
***************************************************************************************************************/

// Pinging function
function Send()
{
	clearInterval(PingInterval);

	// Accumulate a string of the active users (defined by the number of dynamic buttons)
	var interests = "";
	for (i = 0; i < Omni_ArStatus.length; i++)
	{
		interests += Omni_ArStatus[i] + (i < Omni_ArStatus.length-1 ? "," : "");
	}
	registerStr = Omni_Server + "_register.php?dbid=" + dbid + "&domain=www.omnidate.com&user=" + Omni_userid + "&interests=" + interests + "&username=" + username + "&gender=" + gender;
	registerStr += (dating != "") ? "&dating=true" : "";
	registerStr += "&jsonp=?";

	//document.getElementById("container").innerHTML = registerStr + document.getElementById("container").innerHTML;

	// Call register.php and parse the return xml using OnSendComplete.
	jQuery.getJSON(registerStr, 
	function(p)
	{
		Omni_data += registerStr + "<br />";
		jQuery("#containerX").html(Omni_data);
		OnSendComplete(p);
	}
	);
}

// Parse the return XML
function OnSendComplete(_this)
{
	if (!IgnorePingReturn)
	{

		var buttonCode = ""; 
		var messageIn = "";
		var removeInvite = "";
		var showBanner = "";
		var inviteStatus = "";
		var DateName = ""; 
		var DateId = ""; 
		var TimeRem = ""; 

		var ResultOnline =  _this.online;
		var ResultRequested =  _this.requested;
		var ResultRequesting =  _this.requesting;
		var ResultReqName = _this.reqName;
		var ResultGender =  _this.gender;
		var ResultTable = _this.table;
		var ResultChar =  _this.char;
		var ResultAccept =  _this.accept;
		var ResultDating =  _this.dating;
		var ResultVenue =  _this.venue;
		var ResultMyChar =  _this.mychar;
		var ResultTime =  _this.time;


		if (ResultRequesting != "" || ResultRequested != "") {
			ResultOnline = ReturnOffline(ResultOnline);
		}

		Omni_Table = ResultTable;
		StorylineFile = ResultVenue;

		// Feb27 - The downfall to picking up the character at each register is that if you go and change your character after you
		// make a request for a date, you might get some inconsistency, since your date may still think you're the old character.
		if (ResultMyChar != "")
			You = ResultMyChar;

		if (ResultChar != "" && ResultChar != "None")
			YourDate = ResultChar;

		if (ResultReqName != "")
			YourDateName = ResultReqName;
		else
			YourDateName = ResultRequesting;
			
		if (ResultTime >= 0)
			TimeRemaining = ResultTime;
		else
			TimeRemaining = "";

		// Someone is requesting me.
		if (ResultRequesting != "")
		{  
			// review this flow.  if you get invites once, should you be able to be invited again? if the invitor cancels, 
			//and you dont respond, you can get anotehr invite, but still show the banner, either that functionality needs 
			//to change or we need to allow musltiple invites perhaps.

			YourDateId = ResultRequesting;

			if (ResultReqName != "")
				YourDateName = ResultReqName;
			else
				YourDateName = ResultRequesting;

			if (ResultTime != "" && ResultTime > 0)
			{
				// Not expired

				if (!LoadStarted) {
					//StartLoading();
					LoadStarted = true;
				}

				inviteStatus = "1";
				DateName = YourDateName;
				DateId = YourDateId;
				TimeRem = TimeRemaining;
				InviteOverShowing=true;

				Omni_Table = ResultTable; // Do we need this? We do it above, don't we?
			}
			else
			{
				buttonCode = "1"; 
				messageIn = "1";
				removeInvite = "1";
				DateName = YourDateName;
				DateId = YourDateId;
				TimeRem = TimeRemaining;
			}

			showBanner = "1";
		}


		//If this is not "", then I've requested someone.
		if (ResultRequested == "expired") 
		{   // we should use the "time" to determine expiration, not the name field incase someoen is named "expired"

			buttonCode = "1"; 
			messageIn = "2";
			removeInvite = "0";
			inviteStatus = "";
			showBanner = "1";
			DateName = YourDateName;
			DateId = YourDateId;
		}
		else if (ResultRequested != "")
		{ // I've requested someone

			if (!LoadStarted) {
				//StartLoading();
				LoadStarted = true;
			}

			//We still have an active request, make sure we're handling that!
			inviteStatus = "2";
			showBanner = "1";
			DateName = YourDateName;
			DateId = YourDateId;
			TimeRem = TimeRemaining;
		}
		else if (ResultRequested == "") 
		{
			DateHasBeenRequested = false;
		}


		//Pass back "expired" if it has expired.
		//Expired will be set from register.php, it will then delete any trace of the invite.


		if (ResultDating == "true")
		{
			buttonCode = "0";
			messageIn = "3";
			removeInvite = "0";
			buttonStatus = ReturnOffline(ResultOnline);
		}
		else if (ResultRequested == "" && ResultRequesting == "")
		{
			buttonCode = "0"; 
			messageIn = "";
			removeInvite = "0";
			showBanner = "0";
		}


		// We have invited someone on a date and they have accepted.
		if (ResultAccept != "") // might also want to check to see if we actually initiated a date... could catch some bugs in the mean time.
		{
			if (ResultReqName != "")
				YourDateName = ResultReqName;
			else
				YourDateName = ResultRequested;
			
			if (ResultRequested != "" && ResultChar != "None")
				YourDateId = ResultRequested;

			
			//clearInterval(ImInvitingIntv);
			// we assume by this point you know who you're inviting so we could also check if you know YourDate to check we actually invited.
			if (ResultAccept == "true")
			{
				buttonCode = "0"; 
				messageIn = "4";
				removeInvite = "1";
				inviteStatus = "";
				showBanner = "1";

				inviter_id = YourId;
				TakeMeOnTheDate();
			}
			else if (ResultAccept == "false")
			{
				buttonCode = "1";
				messageIn = "5";
				removeInvite = "0";
				inviteStatus = "";
				showBanner = "1";
			}
			else if (ResultAccept == "cancel")
			{
				buttonCode = "1";
				messageIn = "7";
				removeInvite = "1";
				showBanner = "1";
				inviteStatus = "";
			}
			else if (ResultAccept == "unavail")
			{
				buttonCode = "1";
				messageIn = "9";
				removeInvite = "1";
				showBanner = "1";
				inviteStatus = "";
			}				
			else
			{
				buttonCode = "1";
				messageIn = "6";
				removeInvite = "0";
				inviteStatus = "";
				showBanner = "1";
				//alert("Error");
			}

			DateName = YourDateName;
			DateId = YourDateId;
			TimeRem = TimeRemaining;
		}


		var d = new Date();
		var curr_hour = d.getHours();
		var curr_min = d.getMinutes();
		var curr_sec = d.getSeconds();

		// print return data (just for test purposes)
		Omni_data = Omni_data + "[" + (curr_hour < 10 ? "0" : "") + curr_hour + ":" + (curr_min < 10 ? "0" : "") + curr_min + ":" + (curr_sec < 10 ? "0" : "") + curr_sec + "] ";
		Omni_data = Omni_data + "online=" + ResultOnline + ", requested=" + ResultRequested + ", requesting=" + ResultRequesting + ", reqName=" + ResultReqName 
			+ ", gender=" + ResultGender + ", table=" + ResultTable + ", character=" + ResultChar + ", accept=" + ResultAccept
			+ ", dating=" + ResultDating + ", venue=" + ResultVenue + ", mychar=" + ResultMyChar + ", time=" + ResultTime + "<br />";

		jQuery("#containerX").html(Omni_data);

		// Broadcast the online status of the buttons + communicate with the banner
		BroadcastStatus(buttonCode, messageIn, removeInvite, showBanner, inviteStatus, DateName, DateId, You, YourDate, TimeRem, ResultOnline);

	}

	// Define the next ping interval
	PingInterval = setInterval( "Send()", Omni_Frequency * 1000 );

}

function ReturnOffline (OnlineString)
{
	InactiveAll();
	return OnlineString;
}

// Interface between the controller and banner/buttons.
function BroadcastStatus(buttonCode, messageIn, removeInvite, showBanner, inviteStatus, DateName, DateId, YourChar, DateChar, TimeRem, online)
{
	var outString = buttonCode + "/" + messageIn + "/" + removeInvite + "/" + showBanner + "/" + inviteStatus + "/" + DateName + "/" + DateId + "/" + YourChar + "/" + DateChar + "/" + TimeRem + "/" + online;
	Omni_data = Omni_data + outString + "<br />";
	updateStatus(outString);
}

function updateStatus(statusString)
{
	var splitStatus = statusString.split("/");

	var buttonCode = splitStatus[0];
	var messageIn = splitStatus[1];
	var removeInvite = splitStatus[2];
	var showBanner = splitStatus[3];
	var inviteStatus = splitStatus[4];
	var DateName = splitStatus[5];
	var DateId = splitStatus[6];
	var YourChar = splitStatus[7];
	var DateChar = splitStatus[8];
	var TimeRem = splitStatus[9];
	var s = splitStatus[10];

	if (showBanner == "0")
	{
		if (bannerExists)
 			changeUI(buttonCode, messageIn, removeInvite, inviteStatus, DateName, DateId, YourChar, DateChar, TimeRem);
		OmniDate_HideBanner();
	}
	else if (showBanner == "1")
	{
		OmniDate_ShowBannerAndChangeUI(buttonCode, messageIn, removeInvite, inviteStatus, DateName, DateId, YourChar, DateChar, TimeRem);
	}

	if (s != "")
	{
		var i;
		var pCur = 0;
		for (i = 0; i < Omni_ArStatus.length; i++)
		{
			var pComma = s.indexOf(",", pCur);
			var n = s.substr(pCur,1);

			updateButton(Omni_ArStatus[i], n);

			if (pComma == -1) break;
			else pCur = pComma+1;
		}
	}
}

// Update the button text and enable/disable
function updateButton(buttonid, status)
{

	var Status = "";
	var Disabled = true;

	if (status == "0")
	{
		Status = "Offline";
		if (typeof(btnUiAr[buttonid]['offline']) != "undefined")
			swapImage(buttonid, btnUiAr[buttonid]['offline'], 'offline');
	}
	else if (status == "1")
	{
		Status = "Date Me";
		if (!BannerShowing)
		{
			Disabled = false;
			if (typeof(btnUiAr[buttonid]['online']) != "undefined")
				swapImage(buttonid, btnUiAr[buttonid]['online'], 'online');
		}
		else
		{
			if (typeof(btnUiAr[buttonid]['inactive']) != "undefined")
				swapImage(buttonid, btnUiAr[buttonid]['inactive'], 'inactive');
		}
	}
	else if (status == "2")
	{	
		Status = "Dating";
		if (typeof(btnUiAr[buttonid]['dating']) != "undefined")
			swapImage(buttonid, btnUiAr[buttonid]['dating'], 'dating');
	}

	if(document.layers)	   //NN4+
	{
		document.layers[buttonid].cursor = (Disabled) ? "default" : "pointer";
	}
	else if(document.getElementById)	  //gecko(NN6) + IE 5+
	{
		var obj = document.getElementById(buttonid);
		obj.style.cursor = (Disabled) ? "default" : "pointer";
	}
	else if(document.all)	// IE 4
	{
		document.all[buttonid].style.cursor = (Disabled) ? "default" : "pointer";
	}


	//document.getElementById(buttonid).value = Status;
	document.getElementById(buttonid).disabled = Disabled;
}




/***************************************************************************************************************
************	Button Functions
***************************************************************************************************************/
function Omni_Button()
{
	var btnUserId = "";
	var btncontainer = "";
	var btnreturn = "";

	for (var i=0; i < arguments.length; i=i+2)
	{
		var currArg = arguments[i].toLowerCase();

		switch (currArg){	
			case "user":
			case "userid":
				btnUserId = arguments[i+1];
				break;
			case "style":
			case "uiobj":
				uiObj = new Object();
				if (typeof(uiDefaults[arguments[i+1]]) == "undefined")
				{
					var btn = arguments[i+1];
					uiObj = uiObj01; 
				}
				else
					uiObj = uiDefaults[arguments[i+1]];
				break;
			case "container":
				btncontainer = arguments[i+1];
				break;
			case "return":
				btnreturn = arguments[i+1];
				break;
			default:
		}
	}

	// If we defined a username create the button
	if (btnUserId != "")
	{
		Omni_ArStatus[Omni_ArStatus.length] = btnUserId; // thereby increasing length by 1
		// If we didn't specify ANY definition, use a default
		if (typeof(window['uiObj']) == "undefined") {
			uiObj = new Object();
			uiObj = uiDefaults['uiObj01'];
		}
		// Check each specific image, if there is one missing, set a default
		else if (typeof(uiObj['offline']) == "undefined")
			uiObj['offline'] = uiObj01['offline'];
		else if (typeof(uiObj['online']) == "undefined")
			uiObj['online'] = uiObj01['online'];
		else if (typeof(uiObj['inactive']) == "undefined")
			uiObj['inactive'] = uiObj01['inactive'];
		else if (typeof(uiObj['dating']) == "undefined")
			uiObj['dating'] = uiObj01['dating'];
		else if (typeof(uiObj['height']) == "undefined")
			uiObj['height'] = uiObj01['height'];
		else if (typeof(uiObj['width']) == "undefined")
			uiObj['width'] = uiObj01['width'];

		// Add the UI obj to the array
		btnUiAr[btnUserId] = uiObj;

		var printOmniButton = ''
		if (uiObj['iposition'] == 'bottom') { printOmniButton += '<span style="float:none;"><div>'; }
		var inviteButton = '<input type="button" id="' + btnUserId + '" name="' + btnUserId + '" onclick="OnDate(\''+btnUserId+'\');" '
			+ 'value="" disabled="true" style="height:'+uiObj['height']+'px;width:'+uiObj['width']+'px;background:url(\'' + uiObj['offline'] + '\');border:0px;" title="' + OmniTitles['offline'] + '" />';
		printOmniButton += inviteButton;
		if (uiObj['iposition'] == 'bottom') { printOmniButton += '</div><div>'; }
		// if not button off
		var infoButton = '<input type="button" id="' + btnUserId + 'Info" name="' + btnUserId + 'Info" onclick="MoreInfo();" '
			+' value="" style="cursor:pointer;height:'+uiObj['iheight']+'px;width:'+uiObj['iwidth']+'px;background:url(\'' + uiObj['info'] + '\');border:0px;" title="' + OmniTitles['info'] + '" />';
		printOmniButton += infoButton;
		if (uiObj['iposition'] == 'bottom') { printOmniButton += '</div></span>'; }
		
		//printOmniButton = inviteButton + infoButton;


		if (btncontainer != "")
			document.getElementById(btncontainer).innerHTML += printOmniButton;
		else if (btnreturn != "")
			return printOmniButton;
		else
			document.write(printOmniButton);
	}
}

function swapImage (imgName, imgSrc, statusType)
{
	if(document.layers)	   //NN4+
	{
		document.layers[imgName].background = "url('"+imgSrc+"')";
		document.layers[imgName].height = btnUiAr[imgName]['height'] + "px";
		document.layers[imgName].width = btnUiAr[imgName]['width'] + "px";
		document.layers[imgName].title = OmniTitles[statusType];
	}
	else if(document.getElementById)	  //gecko(NN6) + IE 5+
	{
		var obj = document.getElementById(imgName);
		obj.style.background = "url('"+imgSrc+"')";
		obj.style.height = btnUiAr[imgName]['height'] + "px";
		obj.style.width = btnUiAr[imgName]['width'] + "px";
		obj.title = OmniTitles[statusType];
	}
	else if(document.all)	// IE 4
	{
		document.all[imgName].style.background = "url('"+imgSrc+"')";
		document.all[imgName].style.height = btnUiAr[imgName]['height'] + "px";
		document.all[imgName].style.width = btnUiAr[imgName]['width'] + "px";
		document.all[imgName].title = OmniTitles[statusType];
	}
}

function InactiveAll()
{
	Omni_data += "InactiveAll()<br />";
	for (i = 0; i < Omni_ArStatus.length; i++)
	{
		document.getElementById(Omni_ArStatus[i]).disabled = true;
	}
}

// The MoreInfo
function MoreInfo()
{
	//var target = document.getElementById('OmniFloatingLayerInfo');
	//target.innerHTML = Omni_Avatar('userid',Omni_userid, 'username',username, 'gender',gender, 'account',dbid, 'style','Avatar01', 'return','true');
	//target.innerHTML += '<br /><div onclick="HideInfo();" style="cursor:pointer;">[close]</div>';
	var tag = new FlashTag(Omni_Server+'OmniInfoBox.swf', 480, 320, "8,0,0,0");
	tag.setFlashvars("lcId=" + Omni_lcId+"_"+Omni_Unique + "&dbid="+dbid+"&userid="+Omni_userid+"&username="+username+"&gender="+gender);
	tag.setAllowScriptAccess("always");
	tag.setWmode("transparent");
	Omni_Unique++;

	var target = document.getElementById('OmniFloatingLayerInfo');
	target.innerHTML = tag.toString();

	if (BannerShowing == false)
	{
		if(document.layers)	   //NN4+
		{
		   document.layers['OmniFloatingLayerInfo'].visibility = "show";
		   document.layers['OmniFloatingLayerInfo'].display = "block";
		}
		else if(document.getElementById)	  //gecko(NN6) + IE 5+
		{
			var obj = document.getElementById('OmniFloatingLayerInfo');
			obj.style.visibility = "visible";
			obj.style.display = "block";
		}
		else if(document.all)	// IE 4
		{
			document.all['OmniFloatingLayerInfo'].style.visibility = "visible";
			document.all['OmniFloatingLayerInfo'].style.display = "block";
		}
	}
}

function HideInfo()
{
	if(document.layers)	   //NN4+
	{
	   document.layers['OmniFloatingLayerInfo'].visibility = "hide";
	   document.layers['OmniFloatingLayerInfo'].display = "none";
	}
	else if(document.getElementById)	  //gecko(NN6) + IE 5+
	{
		var obj = document.getElementById('OmniFloatingLayerInfo');
		obj.style.visibility = "hidden";
		obj.style.display = "none";
	}
	else if(document.all)	// IE 4
	{
		document.all['OmniFloatingLayerInfo'].style.visibility = "hidden";
		document.all['OmniFloatingLayerInfo'].style.display = "none";
	}
}


/***************************************************************************************************************
************	Request Date
***************************************************************************************************************/
function OnDate(userid)
{
	InactiveAll();
	requestStr = Omni_Server + "_requestdate.php?dbid=" + dbid + "&user="+Omni_userid+"&requests="+userid +"&invite=true" + "&jsonp=?";	

	// Call request.php and parse the return xml using OnRequestComplete.
	jQuery.getJSON(requestStr, 
	function(p)
	{
		OnRequestComplete(p);
		Omni_data += requestStr + "<br />";
		jQuery("#containerX").html(Omni_data);
	}
	);
}
function OnRequestComplete(_this)
{
	var RequestRequested = _this.requested;
	var RequestReqName = _this.reqName;
	var RequestStatus = _this.status;
	var RequestGender = _this.gender;
	var RequestTable = _this.table;
	var RequestMyChar = _this.mychar;
	var RequestChar = _this.char;
	var RequestVenue = _this.venue;
	var RequestTime = _this.time;


	if (RequestMyChar != "")
		You = RequestMyChar;
	
	if (RequestChar != "" && RequestChar != "None")
		YourDate = RequestChar;

	if (RequestReqName != "")
		YourDateName = RequestReqName;

	if (RequestRequested != "")
		YourDateId = RequestRequested;

	if (RequestTable != "")
		Omni_Table = RequestTable;

	if (RequestVenue != "")
		StorylineFile = RequestVenue;

	TimeRemaining = RequestTime;

	if (RequestStatus == '1')
		BroadcastStatus("0", "", "0", "1", "2", YourDateName, YourDateId, You, YourDate, TimeRemaining, "")
	else if (RequestStatus == '2')
		BroadcastStatus("1", "9", "0", "1", "", YourDateName, YourDateId, You, YourDate, TimeRemaining, "");

	Send();
}




/***************************************************************************************************************
************	Avatar Selector
***************************************************************************************************************/
var Avatar01 = new Object;
Avatar01.source = Omni_Server+'OmniAvatar1.swf';
Avatar01.height = "220";
Avatar01.width = "440";

var AvatarObj = new Object;
AvatarObj['Avatar01'] = Avatar01;
var avtObj;

//omnidateController('X', 'userid=jackie&username=Jackie&gender=female');
function Omni_Avatar()
{

	var avtUserId = "";
	var avtUserName = "";
	var avtUserGender = "";
	var avtDbId = "";
	var avtcontainer = "";
	var avtreturn = "";

	for (var i=0; i < arguments.length; i=i+2)
	{
		var currArg = arguments[i].toLowerCase();
		avtObj = Avatar01;

		switch (currArg){	
			case "user":
			case "userid":
				avtUserId = arguments[i+1];
				break;
			case "name":
			case "username":
				avtUserName = arguments[i+1];
				break;
			case "gender":
			case "usergender":
				avtUserGender = arguments[i+1];
				break;
			case "account":
				avtDbId = arguments[i+1];
				break;
			case "style":
				avtObj = new Object();			
				if (typeof(AvatarObj[arguments[i+1]]) == "undefined")
					avtObj = Avatar01;
				else
					avtObj = AvatarObj[arguments[i+1]];
				break;
			case "container":
				avtcontainer = arguments[i+1];
				break;
			case "return":
				avtreturn = arguments[i+1];
				break;
			default:
		}
	}

	var tag = new FlashTag(avtObj.source, avtObj.width, avtObj.height, "8,0,0,0");
	tag.setFlashvars("lcId=" + Omni_lcId+"_"+Omni_Unique + "&dbid="+avtDbId+"&userid="+avtUserId+"&username="+avtUserName+"&gender="+avtUserGender);
	tag.setAllowScriptAccess("always");
	tag.setWmode("transparent");
	Omni_Unique++;

	if (avtcontainer != "")
		document.getElementById(avtcontainer).innerHTML += tag.toString();
	else if (avtreturn != "")
		return tag.toString();
	else
		document.write(tag.toString());
}




/***************************************************************************************************************
************	Banner Functions
***************************************************************************************************************/
var Banner00 = new Object;
Banner00.source = "";
Banner00.height = "150";
Banner00.width = "300";

// Uses UserID Link
var Banner01 = new Object;
Banner01.source = Omni_Server+'OmniBanner1.swf';
Banner01.height = "150";
Banner01.width = "300";

// Uses UserName Link
var Banner02 = new Object;
Banner02.source = Omni_Server+'OmniBanner2.swf';
Banner02.height = "150";
Banner02.width = "300";

var Skipthebar01 = new Object;
Skipthebar01.source = Omni_Server+'OmniBannerSTB1.swf';
Skipthebar01.height = "150";
Skipthebar01.width = "300";

var Anotherfriend01 = new Object;
Anotherfriend01.source = Omni_Server+'OmniBannerAF.swf';
Anotherfriend01.height = "150";
Anotherfriend01.width = "300";

var Banner03 = new Object;
Banner03.source = Omni_Server+'OmniBanner3.swf';
Banner03.height = "150";
Banner03.width = "300";



var BannerObj = new Object;
BannerObj['Banner00'] = Banner00;
BannerObj['Banner01'] = Banner01;
BannerObj['Banner02'] = Banner02;
BannerObj['Skipthebar01'] = Skipthebar01;
BannerObj['Anotherfriend01'] = Anotherfriend01;
BannerObj['Banner03'] = Banner03;
var bnrObj;

function omnidateBanner(variables)
{
	var flashVars = "lcId=" + Omni_lcId+"_"+Omni_Unique+"&"+variables;

	Omni_BannerProxy = new FlashProxy(Omni_lcId+"_"+Omni_Unique, Omni_Server+"JavaScriptFlashGateway.swf"); 
	var tag = new FlashTag(bnrObj.source, bnrObj.width, bnrObj.height, "8,0,0,0");
	tag.setFlashvars(flashVars);
	tag.setAllowScriptAccess("always");
	tag.setId("OmniBanner");

	Omni_Unique++;
	return tag.toString();
}

function BannerStyle(bannerStyleIn)
{
	if (bannerStyleIn == "")
	{
		if (dbid == "omnidate")
			siteCode = "3";
		else if (dbid == "datecouk")
			siteCode = "DCU";
		else if (dbid == "anotherfriend")
			siteCode = "AF";
		else if (dbid == "personalquest")
			siteCode = "PQ";
		else if (dbid == "skipthebar")
			siteCode = "STB";
		else if (dbid == "uhooo")
			siteCode = "UH";
		else
			siteCode = "X";

		Banner00.source = Omni_Server+'OmniBanner'+siteCode+'.swf';
		BannerObj['Banner00'] = Banner00;
		bnrObj = BannerObj['Banner00'];
	}
	else
	{
		if (typeof(BannerObj[bannerStyleIn]) == "undefined")
			bnrObj = BannerObj["Banner01"];
		else
			bnrObj = BannerObj[bannerStyleIn];
	}
	Omni_data += "BANNER="+bnrObj.source+"<br />";
}

function changeUI(buttonCode, messageIn, removeInvite, inviteStatus, DateName, DateId, YourChar, DateChar, TimeRem)
{
	Omni_data += "Omni_BannerProxy.call('ChangeUI', "+buttonCode+", "+messageIn+", "+removeInvite+", "+inviteStatus+", "+DateName+", "+DateId+", "+YourChar+", "+DateChar+", "+TimeRem+");<br />";
	Omni_BannerProxy.call('ChangeUI', buttonCode, messageIn, removeInvite, inviteStatus, DateName, DateId, YourChar, DateChar, TimeRem);
}

function OmniDate_ShowBannerAndChangeUI(buttonCode, messageIn, removeInvite, inviteStatus, DateName, DateId, YourChar, DateChar, TimeRem)
{
	if (!bannerExists)
	{
		OmniDate_VisibleBanner('OmniFloatingLayer', 1);
		var target = document.getElementById('OmniFloatingLayer');

		var BannerVars = 'buttonCode=' + buttonCode + '&messageIn=' + messageIn + '&removeInvite=' + removeInvite + '&inviteStatus=' + inviteStatus + '&DateName=' + DateName + '&DateId=' + DateId + '&You=' + YourChar + '&YourDate=' + DateChar + '&TimeRem=' + TimeRem + '&profile=' + Omni_profile;
		target.innerHTML = omnidateBanner(BannerVars);

		bannerExists = true;
	}
	else
	{
		OmniDate_VisibleBanner('OmniFloatingLayer', 1);
 		changeUI(buttonCode, messageIn, removeInvite, inviteStatus, DateName, DateId, YourChar, DateChar, TimeRem);
	}
}

function OmniDate_HideBanner()
{
	OmniDate_VisibleBanner('OmniFloatingLayer', 0);
	var target = document.getElementById('OmniFloatingLayer');
	target.innerHTML = "";
	bannerExists = false;
}

function OmniDate_VisibleBanner(OmniLayer, ShowOnScreen)
{
	// Banner starts "visible=true" and off the page at -750px (see CSS)
	// This function hides the banner "visible=false" and moves it to the center of the page.
	BannerShowing = false;

	if(document.layers)	   //NN4+
	{
	   document.layers[OmniLayer].visibility = ShowOnScreen ? "show" : "hide";
	   document.layers[OmniLayer].display = ShowOnScreen ? "block" : "none";
	}
	else if(document.getElementById)	  //gecko(NN6) + IE 5+
	{
		var obj = document.getElementById(OmniLayer);
		obj.style.visibility = ShowOnScreen ? "visible" : "hidden";
		obj.style.display = ShowOnScreen ? "block" : "none";
	}
	else if(document.all)	// IE 4
	{
		document.all[OmniLayer].style.visibility = ShowOnScreen ? "visible" : "hidden";
		document.all[OmniLayer].style.display = ShowOnScreen ? "block" : "none";
	}

	if (ShowOnScreen) {
		BannerShowing = true;
		InactiveAll();
		HideInfo();
	}
}

function onCancelDateClick()
{
	Omni_data += "onCancelDateClick()<br />";
	OmniDate_HideBanner();
	
	var cancelStr = Omni_Server + "_canceldate.php?dbid=" + dbid + "&user="+Omni_userid + "&jsonp=?";
	jQuery.getJSON(cancelStr, 
	function(p)
	{
		OnCancelComplete(p);
		Omni_data += cancelStr + "<br />";
		jQuery("#containerX").html(Omni_data);
	}
	);
}
function OnCancelComplete(_this)
{
	Omni_data += "OnCancelComplete()<br />";
	Send();
}

function onMainButtonClick()
{
	Omni_data += "onMainButtonClick()<br />";
	OmniDate_HideBanner();

	var clearStr = Omni_Server + "_clearrequest.php?dbid=" + dbid + "&user="+Omni_userid + "&jsonp=?";
	jQuery.getJSON(clearStr, 
	function(p)
	{
		OnClearComplete(p);
		Omni_data += clearStr + "<br />";
		jQuery("#containerX").html(Omni_data);
	}
	);
}
function OnClearComplete(_this)
{
	Omni_data += "OnClearComplete()<br />";
	Send();
}

/***************************************************************************************************************
************	Accept/Decline Dates
***************************************************************************************************************/
function acceptOrDecline(acceptdecline)
{
	if (acceptdecline == "false")
		OmniDate_HideBanner();
	else if (acceptdecline == "true")
	{
		Omni_Modal(true);
		InactiveAll();
	}

	var acceptdeclineStr = Omni_Server + "_acceptdate.php?dbid=" + dbid + "&user=" + Omni_userid + "&accept=" + acceptdecline + "&jsonp=?";

	jQuery.getJSON(acceptdeclineStr, 
	function(p)
	{
		if (acceptdecline == "true")
			OnAcceptComplete(p);
		else if (acceptdecline == "false")
			OnDeclineComplete(p);

		Omni_data += acceptdeclineStr + "<br />";
		jQuery("#containerX").html(Omni_data);
	}
	);
}
function OnAcceptComplete(_this)
{

	var valid = _this.valid;
	var inviter_id = _this.requestor;


	if (valid != undefined && valid == "true")
	{
		// Date is still valid!! Now take me to it!
		TakeMeOnTheDate();
	}
	else if (valid == "cancel")
	{
		// Date is no longer valid! They may have cancelled.
		BroadcastStatus("1", "7", "1", "1", "", YourDateName, YourDateId, You, YourDate, "", "");
	}
	else if (valid == "expired")
	{
		// Date is no longer valid! The date expired!
		BroadcastStatus("1", "8", "1", "1", "",	YourDateName, YourDateId, You, YourDate, "", "");
	}
	else 
	{
		// Woops, there was an error.
		BroadcastStatus("1", "6", "1", "1", "", "", "", "", "", "", "");
	}
}
function OnDeclineComplete(_this)
{
	BroadcastStatus("0", "", "1", "0", "", "", "", "", "", "", "")
	Send();
}




/***************************************************************************************************************
************	Go On The Date
***************************************************************************************************************/
function TakeMeOnTheDate()
{
	IgnorePingReturn = true;

	Omni_Modal(true);

	Omni_data += "TakeMeOnTheDate()<br />";

	var startStr = Omni_Server + "_startdate.php?dbid=" + dbid + "&user=" + Omni_userid + "&table=" + Omni_Table + "&jsonp=?";	
	Omni_data += startStr+"<br />";

	// Call register.php and parse the return xml using OnSendComplete.
	jQuery.getJSON(startStr, 
	function(data)
	{
		if (data.success != "true")
		{
			Omni_Modal(false);
		}
		TakeMeOnTheDateComplete(data);
		jQuery("#containerX").html(Omni_data);
	}
	);
}
function TakeMeOnTheDateComplete(_this) 
{
	Omni_data += "TakeMeOnTheDateComplete()<br />";

	//if (You == "") You = (gender.toLowerCase() == "male") ? "James" : "Jessi";

	var LocationString = "";

	if (!popup) 
	{
		//if (Omni_landing == "")
		//{
			var dateObj = new Object();
			dateObj.You = You;
			dateObj.YourDate = YourDate;
			dateObj.Table = Omni_Table;
			dateObj.YourId = YourId;
			dateObj.YourName = YourName;
			dateObj.YourDateName = YourDateName;
			dateObj.YourDateId = YourDateId;
			dateObj.StorylineFile = StorylineFile;
			dateObj.dbid = dbid;
			dateObj.DbId = dbid;
			dateObj.RedirectLink = top.location.href;
			GoToDate(dateObj);
		//}
		//else 
		//{
		//	LocationString = Omni_landing + "?You=" + You + "&YourDate=" + YourDate + "&Table=" + Omni_Table + "&YourId=" + YourId + "&YourName=" + YourName + "&YourDateName=" + YourDateName + "&YourDateId=" + YourDateId + "&IntegFolder=" + IntegFolder + "&StorylineFile=" + StorylineFile + "&dbid=" + dbid + "&RedirectLink=" + top.location.href;
		//	top.location.href = LocationString;
		//}
		
	}
	else 
	{
		// Popup code
	}

	IgnorePingReturn = false;
}
function GoToDate(OmniDate_variables)
{
	/*
	Omni_data += "GoToDate()<br />";
	for (OmniDate_i in OmniDate_variables) {
		document.date.innerHTML = document.date.innerHTML + "<input type=hidden name='" + OmniDate_i + "' value='" + OmniDate_variables[OmniDate_i] +"' />";
	};
	document.date.submit();
	*/
	dating = true;

	var target = document.getElementById('OmniFloatingLayerDate');
	var flashVars = ""; var firstVar = true;
	if (dbid == "omnitest")
	{
		flashVars = "Music=false"; firstVar = false;
	}

	for (OmniDate_i in OmniDate_variables) {
		flashVars += (firstVar) ? "" : "&";
		flashVars += OmniDate_i + "=" + OmniDate_variables[OmniDate_i];
		firstVar = false;
	};

	Omni_data += "<br />" + flashVars + "<br />";

	//grayOut(true, {'zindex':'50', 'bgcolor':'#666666', 'opacity':'80'});
	//Omni_Modal(true);

	var tag = new FlashTag("http://www.omnidate.com/Actual.swf", "820", "550", "8,0,0,0");
	tag.setFlashvars(flashVars);
	tag.setAllowScriptAccess("always");

	// Internet Explorer 6
	var IE6 = false /*@cc_on || @_jscript_version < 5.7 @*/;
	//var isMSIE = /*@cc_on!@*/false;
	//alert("isMSIE="+isMSIE);
	if (!IE6)
	{
		//tag.setWmode("transparent");
	}

	tag.setBgcolor("838383");
	tag.setId("OmniDateMovie1");
	Omni_Unique++;
	target.innerHTML = tag.toString();


	//if (BannerShowing == false)
	//{
		OmniDate_HideBanner();
		if(document.layers)	   //NN4+
		{
		   document.layers['OmniFloatingLayerInfo'].visibility = "hide";
		   document.layers['OmniFloatingLayerInfo'].display = "none";
		   document.layers['OmniFloatingLayerDate'].visibility = "show";
		   document.layers['OmniFloatingLayerDate'].display = "block";
		}
		else if(document.getElementById)	  //gecko(NN6) + IE 5+
		{
			var obj = document.getElementById('OmniFloatingLayerInfo');
			obj.style.visibility = "hidden";
			obj.style.display = "none";
			var obj = document.getElementById('OmniFloatingLayerDate');
			obj.style.visibility = "visible";
			obj.style.display = "block";
		}
		else if(document.all)	// IE 4
		{
			document.all['OmniFloatingLayerInfo'].style.visibility = "hidden";
			document.all['OmniFloatingLayerInfo'].style.display = "none";
			document.all['OmniFloatingLayerDate'].style.visibility = "visible";
			document.all['OmniFloatingLayerDate'].style.display = "block";
		}
	//}

}
function Omni_Modal(ShowOnScreen) {

	if(document.layers)	   //NN4+
	{
	   document.layers['OmniFloatingLayerModal'].visibility = ShowOnScreen ? "show" : "hide";
	   document.layers['OmniFloatingLayerModal'].display = ShowOnScreen ? "block" : "none";
	}
	else if(document.getElementById)	  //gecko(NN6) + IE 5+
	{
		var obj = document.getElementById('OmniFloatingLayerModal');
		obj.style.visibility = ShowOnScreen ? "visible" : "hidden";
		obj.style.display = ShowOnScreen ? "block" : "none";
	}
	else if(document.all)	// IE 4
	{
		document.all['OmniFloatingLayerModal'].style.visibility = ShowOnScreen ? "visible" : "hidden";
		document.all['OmniFloatingLayerModal'].style.display = ShowOnScreen ? "block" : "none";
	}
/*
		if(document.layers)	   //NN4+
		{
		   document.layers['OmniFloatingLayerInfo'].visibility = "show";
		   document.layers['OmniFloatingLayerInfo'].display = "block";
		}
		else if(document.getElementById)	  //gecko(NN6) + IE 5+
		{
			var obj = document.getElementById('OmniFloatingLayerInfo');
			obj.style.visibility = "visible";
			obj.style.display = "block";
		}
		else if(document.all)	// IE 4
		{
			document.all['OmniFloatingLayerInfo'].style.visibility = "visible";
			document.all['OmniFloatingLayerInfo'].style.display = "block";
		}
*/
}

function Quit()
{
	EndTheDate();
}
function EndTheDate()
{
	dating = "";

	if(document.layers)	   //NN4+
	{
	   document.layers['OmniFloatingLayerDate'].visibility = "hide";
	   document.layers['OmniFloatingLayerDate'].display = "none";
	}
	else if(document.getElementById)	  //gecko(NN6) + IE 5+
	{
		var obj = document.getElementById('OmniFloatingLayerDate');
		obj.style.visibility = "hidden";
		obj.style.display = "none";
	}
	else if(document.all)	// IE 4
	{
		document.all['OmniFloatingLayerDate'].style.visibility = "hidden";
		document.all['OmniFloatingLayerDate'].style.display = "none";
	}

	Omni_Modal(false);
	var target = document.getElementById('OmniFloatingLayerDate');
	target.innerHTML = "";

	Omni_data += "<br /><br />END THE DATE<br /><br />";

	Send();

	//top.location.href = '<?php echo $redirect; ?>';
}



function ClearDB()
{
	var clearStr = Omni_Server + "_clearall.php?dbid=" + dbid + "&jsonp=?";	
	jQuery.getJSON(clearStr, function(p){});
}




/***************************************************************************************************************
************	Ajax Solution Functions
***************************************************************************************************************/
function clearContainer(container) {
	document.getElementById(container).innerHTML = '';
}
function clearButtons() {
	Omni_ArStatus = new Array();
}
function refreshButtons() {
	if (dbid != "")
	{
		Send();
	}
}

/***************************************************************************************************************
************ Use to dynamically write Pop Divs
***************************************************************************************************************/

function OmniWriteDivs()
{
    var strPopUpElement = "<div id='OmniFloatingLayerOuter'><div id='OmniFloatingLayer' style='display: none;'></div></div>";
    var strPopUpWrapper = "<div id='OmniFloatingLayerOuter'></div>";
    if (jQuery("#OmniFloatingLayer").length > 0) // For existing customers who already includes this element. They should remove it though.
    {
        jQuery("#OmniFloatingLayer").wrap(strPopUpWrapper);   
    }
    else {
        jQuery("body").append(strPopUpElement);
    }

	var strPopUpElement2 = "<div id='OmniFloatingLayerInfoOuter'><div id='OmniFloatingLayerInfo' style='display: none;'></div></div>";
	jQuery("body").append(strPopUpElement2);

	var strPopUpElement3 = "<div id='OmniFloatingLayerDateOuter'><div id='OmniFloatingLayerDate' style='display: none;'></div></div>";
	jQuery("body").append(strPopUpElement3);

	var strPopUpElement4 = "<div id='OmniFloatingLayerModalOuter'><div id='OmniFloatingLayerModal' style='display: none;'></div></div>";
	jQuery("body").append(strPopUpElement4);

	if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)) {
        var ieversion = new Number(RegExp.$1) // capture x.x portion and store as a number
        if (ieversion < 7 || (ieversion >= 7 && document.compatMode == "BackCompat")) {
            var ele = document.getElementById("OmniFloatingLayer");
            if (ele) {
                ele.className = "OmniPopUpHack";
            }
            var ele2 = document.getElementById("OmniFloatingLayerInfo");
            if (ele2) {
                ele2.className = "OmniPopUpHack";
            }
            var ele3 = document.getElementById("OmniFloatingLayerDate");
            if (ele3) {
                ele3.className = "OmniPopUpHack";
            }
            var ele4 = document.getElementById("OmniFloatingLayerModal");
            if (ele4) {
                ele4.className = "OmniPopUpHack";
            }
        }

    }
}


/***************************************************************************************************************
************	Initialization
***************************************************************************************************************/
function Omni_Initialize()
{
	var argObj = new Object();

	for (var i=0; i < arguments.length; i=i+2)
	{
		var currArg = arguments[i].toLowerCase();

		switch (currArg){	
			case "user":
			case "userid":
				YourId = Omni_userid = arguments[i+1];
				break;
			case "name":
			case "username":
				YourName = username = arguments[i+1];
				break;
			case "gender":
			case "usergender":
				gender = arguments[i+1].toLowerCase();
				break;
			case "account":
				dbid = arguments[i+1];
				break;
			case "landing":
				Omni_landing = arguments[i+1];
				break;
			case "redirect":
				if (arguments[i+1] == "back")
					RedirectLink = top.location.href;
				else
					RedirectLink = arguments[i+1];
				break;
			case "dating":
				dating = arguments[i+1];
				break;
			case "profile":
				Omni_profile = arguments[i+1];
				break;
			case "style":
			case "banner":
				Omni_bannerStyle = arguments[i+1];
				break;
			default:
				argObj[arguments[i]] = arguments[i+1];
		}
	}

	BannerStyle(Omni_bannerStyle);

	OmniWriteDivs();



	Send();
}




/***************************************************************************************************************
************	Ajax Testing
***************************************************************************************************************/

// This is just sample data for lack of a database. 
// Just used JS Object and Multidementional Arrays to house sample data.
function AButton( btnUser, btnName, btnUI ) {
	this.btnUser = btnUser;
	this.btnName = btnName;
	this.btnUI = btnUI;
}

var myPages = new Array();
myPages[0] = new Array();
myPages[0][0] = new AButton ( 'jackie', 'Jackie', 'uiObj01' );
myPages[0][1] = new AButton ( 'jake', 'Jake', 'uiObj02' );
myPages[0][2] = new AButton ( 'james', 'James', 'uiObj02' );

myPages[1] = new Array();
myPages[1][0] = new AButton ( 'jamal', 'Jamal', 'uiObj02' );
myPages[1][1] = new AButton ( 'jenny', 'Jake', 'uiObj02' );
myPages[1][2] = new AButton ( 'jackie', 'Jackie', 'uiObj01' );

myPages[2] = new Array();
myPages[2][0] = new AButton ( 'james', 'James', 'uiObj01' );
myPages[2][1] = new AButton ( 'jackie', 'Jackie', 'uiObj01' );
myPages[2][2] = new AButton ( 'jamal', 'Jamal', 'uiObj01' );

// This code would be executed by the site. 
// I've created this function for quick pagination through the test arrays.
function ChangePage(page)
{
	//Clears the container HTML. This would typically be done by the site on their own
	clearContainer('refresh');
	// Reset the button array.
	clearButtons();

	for (i = 0; i < myPages[page].length; i++)
	{
		// Just for visual effect, print the username beside the button.
		document.getElementById('refresh').innerHTML += " " + myPages[page][i].btnName + ": ";
		// The site would recall the omnidateButton function with the usual parameters.
		// A new parameter "container", specifies where the buttons will be written to (appended).
		//Omni_Button('userid', myPages[page][i].btnUser, 'uiobj', myPages[page][i].btnUI, 'container', 'refresh');
		document.getElementById('refresh').innerHTML += Omni_Button('userid', myPages[page][i].btnUser, 'uiobj', myPages[page][i].btnUI, 'return', 'true');
	}

	// Calls the "Send()" funtion to update the buttons.
	refreshButtons();
}