Object.prototype.hasFunction=function(name){
	return this[name] && this[name] instanceof Function;
}
Object.prototype.hasProperty=function(name){
	return (this[name]) && (!( this[name] instanceof Function) );
}

Array.prototype.append=function(value) {
	this[this.length]=value;
}
Function.prototype.bind = function(object) {
  var method = this;
  return function() {
    method.apply(object, arguments);
  }
}
Function.prototype.bindAsEventListener = function(object) {
  var method = this;
  return function(event) {
    method.call(object, event || window.event);
  }
}
var net=new Object();

net.READY_STATE_UNINITIALIZED=0;
net.READY_STATE_LOADING=1;
net.READY_STATE_LOADED=2;
net.READY_STATE_INTERACTIVE=3;
net.READY_STATE_COMPLETE=4;

var com=new Object();
com.fps=new Object();
com.fps.ajax=new Object();

com.fps.ajax.CommandProxy=function(){
	this.queue=new Array();
}

	com.fps.ajax.CommandProxy.prototype
	.resultReturned=function(){
		window.alert('Default command Callback method. testing');
	}
	
	com.fps.ajax.CommandProxy.prototype
	.isCommand=function(command){
		if(command.hasProperty("id")
			&& command.hasFunction("getToURL")
			&& command.hasFunction("getXML")
			&& command.hasFunction("callbackFunc")
			&& command.hasFunction("errorFunc")){
			return true;
		} else {
			return false;
		}
	}

	com.fps.ajax.CommandProxy.prototype
	.sendRequest=function(command){
		if(this.isCommand(command)){
			this.queue.append(command);
		}
	}

	com.fps.ajax.CommandProxy.prototype
	.fireRequest=function(){
		if(this.queue.length==0)
			return;
		for(var i=0;i<this.queue.length;i++){
			var cmd=this.queue[i];
			if(this.isCommand(cmd)){
				this.loader=new com.fps.ajax.ContentLoader(cmd);
			}
		}
		this.queue=new Array();
	}

com.fps.ajax.ContentLoader=function(cmd) {
	this.command=cmd;
	this.request=null;
	this.loadXMLDoc();
}

	com.fps.ajax.ContentLoader.prototype
	.loadXMLDoc=function(){
		try{
			if(window.XMLHttpRequest) {
				this.request=new XMLHttpRequest();
			}else if(window.ActiveXObject){
				this.request=new ActiveXObject("Microsoft.XMLHTTP");
			}
			
			if(this.request) {
				var loader=this;
				this.request.onreadystatechange=function(){
					loader.onReadyState.call(loader);
				}
				this.request.open(this.command.reqMethod,this.command.getToURL(),true);
				this.request.setRequestHeader('Content-Type', this.command.reqContentType);

				var tmpString="requestXml="+escape(this.command.getXML());
				this.request.send(""+tmpString+"");
			}
		} catch(errMsg) {
			window.alert(errMsg);
			this.command.errorFunc.call(this);
		}
	}
	
	com.fps.ajax.ContentLoader.prototype
	.onReadyState=function(){
		try{
			var ready=this.request.readyState;
			
			if( ready == net.READY_STATE_COMPLETE ) {

				if (this.request.status==200 || this.request.status==0){
					this.command.callbackFunc.call(this.command,this.request);
				}else{
					this.command.errorFunc.call(this.command,this.request);
				}
			}
			
			this.command.onReadyCount=this.command.onReadyCount+1;
		}catch(errMsg){
			window.alert(errMsg);
		}
	}
	com.fps.ajax.ContentLoader.prototype
	.defaultError=function(){
		try {
			window.alert("error fetching data!"
				+"\n\nreadyState:"+this.request.readyState
				+"\nstatus: "+this.request.status
				+"\nheaders: "+this.request.getAllResponseHeaders());
		}catch(error) {
			//nothing
		}
 }

com.fps.ajax.Command=function(cmdName,toUrl,paramNameArray,paramValueArray){
	this.onReadyCount=0;
	this.id=(new Date()).getTime();
	this.reqMethod="post";
	this.reqContentType="application/x-www-form-urlencoded";
	this.toUrl=toUrl;
	this.cmdName=cmdName;
	this.paramNameArray=paramNameArray;
	this.paramValueArray=paramValueArray;
}
	com.fps.ajax.Command.prototype
	.getXML=function(){
		var xml="<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<"+this.cmdName+">";
		for( var i=0;i<this.paramNameArray.length;i++){
			xml=xml+"<"+this.paramNameArray[i]+">"+
				escape(this.paramValueArray[i])+"</"+this.paramNameArray[i]+">";
		}
		xml=xml+"</"+this.cmdName+">";
		return xml;
	}

	com.fps.ajax.Command.prototype
	.getToURL=function(){
		if(!this.toUrl) {
			return "";
		}else {
			return this.toUrl;
		}
	}
	com.fps.ajax.Command.prototype
	.callbackFunc=function(request){
		window.alert("Callback, came back:"+request);
	}

	com.fps.ajax.Command.prototype
	.errorFunc=function(request){
		window.alert("error Callback, come back:"+request);
	}


function getCommandProxy(){
	if(!(com.fps.ajax.CommandProxyInstance)) {
		if(!com) com=new Object();
		if(!com.fps) com.fps=new Object();
		if(!com.fps.ajax) com.fps.ajax=new Object();

		com.fps.ajax.CommandProxyInstance=new com.fps.ajax.CommandProxy();
	}
	return com.fps.ajax.CommandProxyInstance;
}

function parseXML(xmlString) {
	if (typeof DOMParser == "undefined") {
		if (typeof ActiveXObject != "undefined") {
			var d = new ActiveXObject("Microsoft.XMLDOM");
			d.loadXML(xmlString);
			return d;
		}
	}else {
		var parser = new DOMParser();
		var doc = null;			
		try {
			doc = parser.parseFromString(xmlString,"text/xml");
		} catch (e) {
		}
		return doc;
	}
}

function findPosX(obj) {
	var curleft = 0;
	if (obj.offsetParent) {
		while (obj.offsetParent) {
			curleft += obj.offsetLeft;
			obj = obj.offsetParent;
		}
	} else if (obj.x) {
		curleft += obj.x;
	}
	return curleft;
}

function findPosY(obj) {
	var curtop = 0;
	if (obj.offsetParent) {
		while (obj.offsetParent) {
			curtop += obj.offsetTop;
			obj = obj.offsetParent;
		}
	} else if (obj.y) {
		curtop += obj.y;
	}
	return curtop;
}

function rmObjFromRegistry(nameId){
	if(window.tempRegistry){
		window.tempRegistry[nameId]=null;
	}
}

function hideNode(node) {
	node.style.visibility = 'hidden';
}
function showNode(node) {
	node.style.visibility = 'visible';
}

com.fps.ajax
.fpsDependExecute=function dependExecute(objectID, functionCall) {
    var entries=null;
    if (objectID.indexOf(',') == -1) {
        entries = new Array(objectID);
    } else {
		entries = objectID.split(/, ?/);
    }

    var check;
    for (var i=0; i<entries.length; i++) {

        check = entries[i].substring(3,entries[i].length);
        if (entries[i].indexOf('fl:') != -1) {
            if ( (typeof(loaded_scripts) != "object") || (loaded_scripts[check] != true) ) {
                setTimeout("fpsDdependExecute('" + objectID + "', '" + functionCall + "')", 100);
                return;
            }
        } else if (entries[i].indexOf('js:') != -1) {
			try{
	        	tempVar=eval(check);
	            if ( typeof(tempVar) == "undefined" || tempVar==null ) {
	                setTimeout("fpsDependExecute('" + objectID + "', '" + functionCall + "')", 100);
	                return;
	            }
            }catch(errInfo) {}
        } else if (entries[i].indexOf('id:') != -1) {
            if (!document.getElementById(check)) {
                setTimeout("fpsDependExecute('" + objectID + "', '" + functionCall + "')", 100);
                return;
            }
        }
    }
	//real work
    try{
		if(typeof functionCall =="function") {
	   		functionCall.call();
	   	}else {
			eval(functionCall);
	    }
	}catch(errInfo) {
		setTimeout("fpsDependExecute('" + objectID + "', '" + functionCall + "')", 1000);
	}
    return true;
}

function getTextContentValue(element) {
	var ret="";
	ret=element.textContent?element.textContent : element.text;
	if(!ret || ret=="") {
		if(element && element.firstChild && element.firstChild.nodeName=="#text") {
			ret=element.firstChild.data;				
		}else if(element && element.firstChild && element.firstChild.nodeName=="#cdata-section") {
			ret=element.firstChild.nodeValue;
		}
	}
	return ret;
}

function createCookie(name,value,days,path,domain)
{
	if (days)
	{
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value +
			expires+
			((path == null)    ? "path=/" : "; path=" + path) +
			((domain == null)  ? "" : "; domain=" + domain);
}

function readCookie(name)
{
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++)
	{
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name)
{
	createCookie(name,"",-1);
}

function spyObj(f){
	var a=""+f;
	for(i in f) {
		a+="["+i+":"+f[i]+"]";
	}
	window.alert(a);
}

function fade(theDiv,inOut,inter) {
	try{
		if(theDiv.fadingEnd==null) {
			theDiv.fadingEnd=true;
		}
		if(theDiv.fadingEnd != true) {
			return;
		}
	}catch(e) {}
	theDiv.fadingEnd=false;
	theDiv.fadingInOut=inOut;
	theDiv.style.width=theDiv.offsetWidth;
	theDiv.fadeFun=fadeFun;
	if(theDiv.fadingInOut) {
		theDiv.fadingOpa=0;
	}else {
		theDiv.fadingOpa=100;
	}
	var os=inter;
	for(var x=0;x < 10;x++) {
		setTimeout(function(){fadeFun.call(theDiv,theDiv);},os);
		os+=inter;
	}
}
function fadeFun(theDiv){	
	var v=theDiv;
	//window.alert("1"+opa);
	if(	v.fadingInOut){
		// +10;
		v.fadingOpa+=10
	}else {
		v.fadingOpa-=10
	}

	//window.alert(v.offsetHeight+":"+v.offsetWidth);
	v.style.filter="alpha(opacity="+v.fadingOpa+")";
	v.style.opacity=""+v.fadingOpa/100;
	v.style.MozOpacity=""+v.fadingOpa/100;

	//window.alert("2"+opa);
	if(	v.fadingInOut && v.fadingOpa>=100){
		//done
		theDiv.fadingEnd=true;
	}else if(v.fadingOpa<=0){
		//done
		theDiv.fadingEnd=true;
	}
}

//add a bookmark
function addToFavorites() { 
	if(window.external!=null){
    	//window ie
    	window.external.AddFavorite(document.location.href,document.title );
    }else {
    	if (window.sidebar!=null){ //mozilla like
    		window.sidebar.addPanel(document.title, document.location.href,"");
	    }else {
			window.alert("Your browser is not supported yet, please add it manually.");
		}
	}
}

function emailFriend(mediaName) {
	w=580;
	h=370;
	LeftPosition=(screen.width)?(screen.width-w)/2:100;
	TopPosition=(screen.height)?(screen.height-h)/2:100;	
	window.open('/emailFriend.html?mediaName='+mediaName, 
		'Email_to_Friends', 'top='+TopPosition+',left='+LeftPosition+',location=false,status=false,width='+w+',height='+h+',toolbar=false,menubar=false,scrollbars=0');
}

if (typeof loaded_scripts != 'object') loaded_scripts = new Object();
loaded_scripts["com.fps.ajax.js"] = true;
