var myDate = new Date();
var myConnectionTime = myDate.getTime(); // Used by Flash receiver / sender

function getConnectionId() {
	return myConnectionTime;
}


// Call this function to retrieve remote information
// Requires that the Flash receiver has been added to the web page that is to receive the data (See client_side.html).
function requestRemoteInfo(recordId) {
	//addHiddenIframe(document.body, "https://yourdomain.com/getRemoteInfo.php?connectionID=" + getConnectionId() + "&recordId=" + recordId);
	addHiddenIframe(document.body, "http://yourdomain.com/getRemoteInfo.php?connectionID=" + getConnectionId() + "&recordId=" + recordId);
}


// This function is called by cross_domain_receiver.swf upon receiving data from the "cross_domain_sender.swf" sender.
function processRemoteInfo(userData) {
	//alert("userData = " + userData);
	var parsedUserDataArray = userData.split(" ,");
	
	// Replace "\," with "," in the values of the name / value pairs
	// now that they have been split into an array.
	for (var indexNV = 0; indexNV < parsedUserDataArray.length; indexNV++) {
		myNextNV = parsedUserDataArray[indexNV].split("=");
		myUnescapedValue = myNextNV[1].replace(/\\,/g, ",");
		
		// Use each name / value pair as needed.
		// Below is an example:
		/*
		if (myNextNV[0] == "ecpName") {
			document.getElementById('selectedEcpName').innerHTML = myUnescapedValue;
		}
		else if (myNextNV[0] == "ecpPhone") {
			document.getElementById('selectedEcpPhone').innerHTML = myUnescapedValue;
		}
		*/
	}
	
	removeHiddenIframe();
}


var lastIframeParentEl = document.body;
var lastIframe = null;
var newIframe = null;
function addHiddenIframe(iframeParentEl, iframeSource) {
	//alert("addHiddenIframe: " + iframeSource);
	lastIframeParentEl = iframeParentEl;
	newIframe = null;
	
	// First ensure that another iframe does not exist for same purpose.
	removeHiddenIframe();
	
	newIframe = document.createElement('iframe');
	newIframe.setAttribute('id','myHiddenIframe');
	newIframe.setAttribute('name','myHiddenIframe');
	newIframe.setAttribute('allowTransparency','true');
	newIframe.setAttribute('frameborder','0');
	newIframe.setAttribute('scrolling','no');
	newIframe.setAttribute('width','350');
	newIframe.setAttribute('height','50');
	newIframe.setAttribute('title','');
	newIframe.setAttribute('src',iframeSource);
	//newIframe.setAttribute('style','top:0px;');
	//newIframe.setAttribute('onload','removeHiddenIframe();');
	
	iframeParentEl.appendChild(newIframe);
	
	lastIframe = document.getElementById('myHiddenIframe');
}


// This function is called by addHiddenIframe() and processRemoteInfo()
function removeHiddenIframe() {
	if (lastIframe) {
		lastIframeParentEl.removeChild(lastIframe);
		lastIframe = null;
	}
}


function FP_preloadImgs() {//v1.0
 var d=document,a=arguments; if(!d.FP_imgs) d.FP_imgs=new Array();
 for(var i=0; i<a.length; i++) { d.FP_imgs[i]=new Image; d.FP_imgs[i].src=a[i]; }
}

function FP_swapImgRestore() {//v1.0
 var doc=document,i; if(doc.$imgSwaps) { for(i=0;i<doc.$imgSwaps.length;i++) {
  var elm=doc.$imgSwaps[i]; if(elm) { elm.src=elm.$src; elm.$src=null; } } 
  doc.$imgSwaps=null; }
}

function FP_swapImg() {//v1.0
 var doc=document,args=arguments,elm,n; doc.$imgSwaps=new Array(); for(n=2; n<args.length;
 n+=2) { elm=FP_getObjectByID(args[n]); if(elm) { doc.$imgSwaps[doc.$imgSwaps.length]=elm;
 elm.$src=elm.src; elm.src=args[n+1]; } }
}

function FP_getObjectByID(id,o) {//v1.0
 var c,el,els,f,m,n; if(!o)o=document; if(o.getElementById) el=o.getElementById(id);
 else if(o.layers) c=o.layers; else if(o.all) el=o.all[id]; if(el) return el;
 if(o.id==id || o.name==id) return o; if(o.childNodes) c=o.childNodes; if(c)
 for(n=0; n<c.length; n++) { el=FP_getObjectByID(id,c[n]); if(el) return el; }
 f=o.forms; if(f) for(n=0; n<f.length; n++) { els=f[n].elements;
 for(m=0; m<els.length; m++){ el=FP_getObjectByID(id,els[n]); if(el) return el; } }
 return null;
}

function FP_openNewWindow(w,h,nav,loc,sts,menu,scroll,resize,name,url) {//v1.0
 var windowProperties=''; if(nav==false) windowProperties+='toolbar=no,'; else
  windowProperties+='toolbar=yes,'; if(loc==false) windowProperties+='location=no,'; 
 else windowProperties+='location=yes,'; if(sts==false) windowProperties+='status=no,';
 else windowProperties+='status=yes,'; if(menu==false) windowProperties+='menubar=no,';
 else windowProperties+='menubar=yes,'; if(scroll==false) windowProperties+='scrollbars=no,';
 else windowProperties+='scrollbars=yes,'; if(resize==false) windowProperties+='resizable=no,';
 else windowProperties+='resizable=yes,'; if(w!="") windowProperties+='width='+w+',';
 if(h!="") windowProperties+='height='+h; if(windowProperties!="") { 
  if( windowProperties.charAt(windowProperties.length-1)==',') 
   windowProperties=windowProperties.substring(0,windowProperties.length-1); } 
 window.open(url,name,windowProperties);
}

function P7_JumpMenu(selObj,restore){
	var theFullString = selObj.options[selObj.selectedIndex].value;
	if (restore) selObj.selectedIndex=0;
	var theLength = theFullString.length;
	var endPos = theFullString.lastIndexOf("~");
	var theUrl, theTarget, theParent;
	if (endPos > 0) {
		theUrl = theFullString.substring(0,endPos);
	}
	else {theUrl = theFullString;}
	endPos++
	if (endPos < theLength) {
		theTarget = theFullString.substring(endPos,theLength)
	}
	else {theTarget = "window:Main";}
	if (theTarget == "window:New") {
		window.open(theUrl);
	}
	else if (theTarget == "window:Main") {
		eval("parent.location='"+theUrl+"'");
	}
	else {
		eval("parent.frames[\'"+theTarget+"\'].location='"+theUrl+"'");
	}
}