/**
 * this script fill will implement the isiportal declarative ajax framework that will base itself on the YUI toolkit
 * and will make certain parts of a page dynamic based on the tags (personalizzed attributes placed on different div's)
 * inside of the html markup that is generated.
 **/
 
 var isipAjaxVersion = "alpha";
 
 var PROGRESSIVE_FUNCTIONS_TO_EXEC = new Array();
 var PROGRESSIVE_FUNCTIONS_TO_EXEC_LEN = 0; 
 
 //add an array of variables to functions that should always be executed after a progressive function
 //has completed. so you can add further elaboration to isipAjax hot loaded code, and you have a hook to add custom
 //functionality or alfa functionality.
 var PROGRESSIVE_FUNCTION_HOOKS = new Array();
 
 function isipAjaxAddHook(functionHook) {
	 //check if this hook already exists
	 var hasFunction = false;
	 for(var i = 0; i < PROGRESSIVE_FUNCTION_HOOKS.length; i++) {
		 if(PROGRESSIVE_FUNCTION_HOOKS[i] == functionHook) {
			 hasFunction = true;
			 break;
		 }
	 }
	 if(!hasFunction) {
		 PROGRESSIVE_FUNCTION_HOOKS[PROGRESSIVE_FUNCTION_HOOKS.length] = functionHook;
	 }
 }
 
 /**
  * this function will execute all of the function hooks, this
	* method should be called by the progressive function
	**/
 function isipAjaxExecHooks(dvContainer) {
	 for(var i = 0; i < PROGRESSIVE_FUNCTION_HOOKS.length; i++) {
		 var func = PROGRESSIVE_FUNCTION_HOOKS[i];
		 func(dvContainer); //execute the function reference
	 }
 }
 
 //define the incompatible safari version
 var SAFARI_43_MAC = "SAFARI_43_MAC";
 var SAFARI = "SAFARI";
 
 var ISIPAJAX = function() {}
 
 //we should popup a dialog that will make the user wait until the library is fully initialized.
 var waitPanel = null;
 var waitPanelCheckInterval = 10;
 if(getSafariVersion() == SAFARI_43_MAC) {
	 waitPanelCheckInterval = 1000;
 }
 var waitPanelInterval = window.setInterval(function() {
		 if(!waitPanel) {
			 if(document.body) {
					waitPanel = document.createElement("div");
					var docwidth = 0;
					var docheight = 0;
					if(!document.all){ 
						docwidth = window.innerWidth; 
						docheight = window.innerHeight; 
						waitPanel.style.opacity = ".5";
					} else {  
						docwidth = document.body.clientWidth;
						if(getInternetExplorerVersion() >= 8.0) {
							docwidth = docwidth-19;
						}
						docheight = screen.availHeight;
						waitPanel.style.filter = "alpha(opacity = 50)";
					} 
					waitPanel.style.width = docwidth+"px";
					waitPanel.style.height = docheight+"px";
					waitPanel.style.backgroundColor = "#000000";					
					waitPanel.style.position = "absolute";
					waitPanel.style.zIndex = 999;
					waitPanel.style.top = "0px";
					waitPanel.style.left = "0px";
					document.body.appendChild(waitPanel);
			 }
		 } else {
			 clearInterval(waitPanelInterval);
		 }
 },waitPanelCheckInterval);
 
 var isWindowLoaded = false;
 window.onload = function() {
	 isWindowLoaded = true;
 }
 
 //load YUI resources that will be needed for our ajax implementation
 var moduleList = ["connection","dragdrop","container","isipajaxonclick","isipajaxshowonclick","isipajaxshowondrop","isipajaxexecuteondrop",
							 "isipajaxtargettodialog","isipajaxsortable","isipajaxliveplayer","isipajaxvideoplayer","animation","event","dom",
							 "button","menu","isipajaxexecuteaftertimeperiod","carousel","isipajaxcarousel","editor","calendar","imageloader",
 							 "isipajaxnumberfield","isipajaxhtmlfield"];
 if(getSafariVersion() == SAFARI_43_MAC) {	 
	 moduleList = ["connection","dragdrop","isipajaxonclick","isipajaxshowonclick","isipajaxshowondrop","isipajaxexecuteondrop",
							 "isipajaxtargettodialog","isipajaxsortable","isipajaxliveplayer","isipajaxvideoplayer","animation","event","dom",
							 "button","menu","isipajaxexecuteaftertimeperiod","carousel","isipajaxcarousel","isipajaxnumberfield",
	 						 "editor","isipajaxhtmlfield"];
 }
 var yuiLoader = new YAHOO.util.YUILoader({
		 base: "http://ajax.isiportal.com/yui/build/",
		 combine: false,
		 loadOptional: true,
		 require: moduleList,
		 force: moduleList,
		 onSuccess: initISIPAjax,
		 onFailure: function(o) {
			 alert("Attenzione, si e verificato un errore nell caricamento delle librerie YUI, e necessario ri-caricare la pagina");
		 },
		 onTimeout: function(o) {
			 alert("The Loading the YUI library timed out");
		 },
		 onProgress: function(o) {
		 },
		 timeout: 30000
 });
 
 //add the isipajaxshowondrop module
 yuiLoader.addModule({
		 name: "isipajaxshowondrop",
		 type: "js",
		 fullpath: "http://ajax.isiportal.com/../../"+isipAjaxVersion+"/js/isipAjaxShowOnDrop.js",
		 varName: "ISIPAJAXSHOWONDROP"
 });
 
 //add the isipajaxexecuteondrop module
 yuiLoader.addModule({
		 name: "isipajaxexecuteondrop",
		 type: "js",
		 fullpath: "http://ajax.isiportal.com/../../"+isipAjaxVersion+"/js/isipAjaxExecuteOnDrop.js",
		 varName: "ISIPAJAXEXECUTEONDROP"
 });
 
 //add the isipAjaxShowOnClick module
 yuiLoader.addModule({
		 name: "isipajaxshowonclick",
		 type: "js",
		 fullpath: "http://ajax.isiportal.com/../../"+isipAjaxVersion+"/js/isipAjaxShowOnClick.js",
		 varName: "ISIPAJAXSHOWONCLICK"
 });
 
 //add the isipAjaxOnClick module so that it will be loaded dynamically
 yuiLoader.addModule({
		 name: "isipajaxonclick",
		 type: "js",
		 fullpath: "http://ajax.isiportal.com/../../"+isipAjaxVersion+"/js/isipAjaxOnClick.js",
		 varName: "ISIPAJAXONCLICK"
 });
 
 
 
 yuiLoader.addModule({
		 name: "isipajaxtargettodialog",
		 type: "js",
		 fullpath: "http://ajax.isiportal.com/../../"+isipAjaxVersion+"/js/isipAjaxTargetToDialog.js",
		 varName: "ISIPAJAXTARGETTODIALOG"
 });
 
 yuiLoader.addModule({
		 name: "isipajaxsortable",
		 type: "js",
		 fullpath: "http://ajax.isiportal.com/../../"+isipAjaxVersion+"/js/isipAjaxSortable.js",
		 varName: "ISIPAJAXSORTABLE"
 });
 
 yuiLoader.addModule({
		 name: "isipajaxliveplayer",
		 type: "js",
		 fullpath: "http://ajax.isiportal.com/../../"+isipAjaxVersion+"/js/isipAjaxLivePlayer.js",
		 varName: "ISIPAJAXLIVEPLAYER"
 });
 
 
 //add the module for video on demand flash player
 yuiLoader.addModule({
		 name: "isipajaxvideoplayer",
		 type: "js",
		 fullpath: "http://ajax.isiportal.com/../../"+isipAjaxVersion+"/js/isipAjaxVideoPlayer.js",
		 varName: "ISIPAJAXVIDEOPLAYER"
 });
 
 yuiLoader.addModule({
		 name: "isipajaxexecuteaftertimeperiod",
		 type: "js",
		 fullpath: "http://ajax.isiportal.com/../../"+isipAjaxVersion+"/js/isipAjaxExecuteAfterTimePeriod.js",
		 varName: "ISIPAJAXEXECUTEAFTERTIMEPERIOD"
 });
 
 yuiLoader.addModule({
		 name: "isipajaxcarousel",
		 type: "js",
		 fullpath: "http://ajax.isiportal.com/../../"+isipAjaxVersion+"/js/isipAjaxCarousel.js",
		 varName: "ISIPAJAXCAROUSEL"
 });
 
 yuiLoader.addModule({
		 name: "isipajaxnumberfield",
		 type: "js",
		 fullpath: "http://ajax.isiportal.com/../../"+isipAjaxVersion+"/js/isipAjaxNumberField.js",
		 varName: "ISIPAJAXNUMBERFIELD"
 });
 
 yuiLoader.addModule({
		 name: "isipajaxhtmlfield",
		 type: "js",
		 fullpath: "http://ajax.isiportal.com/../../"+isipAjaxVersion+"/js/isipAjaxHTMLField.js",
		 varName: "ISIPAJAXNUMBERFIELD"
 });

 yuiLoader.insert(); 
 
 if(getSafariVersion() == SAFARI_43_MAC) {
	 alert("Questa funzione non \u00e8 supportata da Safari/PPC, si prega di uscire dall'applicazione e rientrare utilizzando Firefox.");
 }
 
 function initISIPAjax() {
	 //this function will be called once the yui is loaded so we can proceed with
	 //any needed object initialization.	 
	 YAHOO.util.DDM.mode = YAHOO.util.DDM.INTERSECT;
	 if(isWindowLoaded) {
		 initISIPAjaxProgressive(document.body);
	 } else {	 
		 window.onload = function() {
			 initISIPAjaxProgressive(document.body);
		 }		 
	 }	 
	 document.body.removeChild(waitPanel);	 
}
 
 function initISIPAjaxProgressive(baseElm) {
	 if(!document.all){
		 getSafariVersion();
		 initISIPAjaxTarget(baseElm);
		 new ISIPAJAXSHOWONDROP().initISIPAjaxShowOnDrop(baseElm);
		 initISIPAjaxDropTarget(baseElm);
		 initISIPAjaxLoad(baseElm);
		 new ISIPAJAXEXECUTEONDROP().initISIPAjaxExecuteOnDrop(baseElm);
		 new ISIPAJAXSHOWONCLICK().initISIPAjaxShowOnClick(baseElm);
		 new ISIPAJAXONCLICK().initISIPAjaxOnClick(baseElm);
		 new ISIPAJAXTARGETTODIALOG().initISIPAjaxTargetToDialog(baseElm);
		 new ISIPAJAXSORTABLE().initISIPAjaxSortable(baseElm);
		 new ISIPAJAXLIVEPLAYER().initISIPAjaxLivePlayer(baseElm);
		 new ISIPAJAXVIDEOPLAYER().initISIPAjaxVideoPlayer(baseElm);
		 new ISIPAJAXEXECUTEAFTERTIMEPERIOD().init(baseElm);
		 new ISIPAJAXCAROUSEL().init(baseElm);
		 new ISIPAJAXNUMBERFIELD().init(baseElm);
		 new ISIPAJAXHTMLFIELD().init(baseElm);
		 if(PROGRESSIVE_FUNCTIONS_TO_EXEC) {
			 for(var i = 0; i < PROGRESSIVE_FUNCTIONS_TO_EXEC_LEN; i++) {
				 eval(PROGRESSIVE_FUNCTIONS_TO_EXEC[i]);
			 }
		 }
		 PROGRESSIVE_FUNCTIONS_TO_EXEC = new Array();
		 PROGRESSIVE_FUNCTIONS_TO_EXEC_LEN = 0;
		 isipAjaxExecHooks(baseElm);
	 }else{
		 //IE SUCKS!!!		 
		 initISIPAjaxTarget(baseElm);
		 ISIPAJAXSHOWONDROP.initISIPAjaxShowOnDrop(baseElm);
		 initISIPAjaxDropTarget(baseElm);
		 initISIPAjaxLoad(baseElm);
		 ISIPAJAXEXECUTEONDROP.initISIPAjaxExecuteOnDrop(baseElm);
		 ISIPAJAXSHOWONCLICK.initISIPAjaxShowOnClick(baseElm);
		 ISIPAJAXONCLICK.initISIPAjaxOnClick(baseElm);
		 //this does not work under ie and needs to be ported.		 
		 //ISIPAJAXTARGETTODIALOG.initISIPAjaxTargetToDialog(baseElm);
		 ISIPAJAXSORTABLE.initISIPAjaxSortable(baseElm);
		 ISIPAJAXLIVEPLAYER.initISIPAjaxLivePlayer(baseElm);
		 ISIPAJAXVIDEOPLAYER.initISIPAjaxVideoPlayer(baseElm);	
		 new ISIPAJAXEXECUTEAFTERTIMEPERIOD().init(baseElm);
		 //new ISIPAJAXCAROUSEL().init(baseElm); not tested with IE
		 new ISIPAJAXNUMBERFIELD().init(baseElm);
		 new ISIPAJAXHTMLFIELD().init(baseElm);
		 if(PROGRESSIVE_FUNCTIONS_TO_EXEC) {
			 for(var i = 0; i < PROGRESSIVE_FUNCTIONS_TO_EXEC_LEN; i++) {
				 eval(PROGRESSIVE_FUNCTIONS_TO_EXEC[i]);
			 }
		 }
		 PROGRESSIVE_FUNCTIONS_TO_EXEC = new Array();
		 PROGRESSIVE_FUNCTIONS_TO_EXEC_LEN = 0;
		 isipAjaxExecHooks(baseElm);
	 }
 }  
 
 function getFirstParentElementForTag(tagName,node) {
	 var elm = node;
	 do {
		 elm = elm.parentNode;
		 if(elm == null) {
			 return null; 
		 }
	 }while(elm.nodeName.toUpperCase() != tagName.toUpperCase());
	 return elm;
 }
 
 function ieAjaxTarget(newInput,formElm) {
	 this.newInput = newInput;
	 this.formElm = formElm;
 }
 
 /**
  * this function will actually execute the execute after procedures for internet explorer
  **/
 function _exec_isipAjaxExecuteAfter(objRef) {
 	 if(objRef.getAttribute("isipAjaxExecuteAfter") && objRef.getAttribute("isipAjaxExecuteAfter").length != 0) {
		 if(document.all) {
			 eval(objRef.getAttribute("isipAjaxExecuteAfter"));
		 } else {
			 window.setTimeout(objRef.getAttribute("isipAjaxExecuteAfter"),10);
		 }
	 }
 }
 /**
  * this function will recode the ajax target tag isipAjaxTarget this specific action
	* will check for the form that encloses the input field that has this tag and adjust the html
	* such that the target of the form will be executed and loaded dynamically into the div id identified
	* by the value of this attribute.
	**/	
 function initISIPAjaxTarget(baseElm) {
	 //we will look for any input targets inside of this form.
	 var inputList = baseElm.getElementsByTagName("input");
	 var ieInputListToAppend = new Array();
	 for(var i = 0; i < inputList.length; i++) {
		 var input = inputList[i];
		 if(input.getAttribute("isipAjaxTarget")) {
			 //we need to get the first parent element form
			 var parentForm = getFirstParentElementForTag("form",input);		 
			 if(parentForm) {
				 if(document.all){
					 //exploer can't handle a setattribute... it's too difficult...
					 var inputHtml = input.outerHTML;
					 var modHtml = inputHtml.replace("submit", "button");
					 var newEl = document.createElement("div");
					 newEl.innerHTML = modHtml;
					 ieInputListToAppend[ieInputListToAppend.length] = new ieAjaxTarget(newEl,parentForm);					 
					 input.style.visibility = "hidden";
					 input = newEl.getElementsByTagName("input")[0];
				 } else {
					 input.setAttribute("type","button");
				 }
				 input.onclick = function() {
					 if(hasAttribute(this,"isipAjaxValidateDataFunction")) {
						 try {
							 if(!eval(this.getAttribute("isipAjaxValidateDataFunction"))) {
								 return false;
							 }
						 }catch(e) {
							 alert("I was unable to execute the validation function "+this.getAttribute("isipAjaxValidateDataFunction"));
							 return false;
						 }
					 }
					 var form = getFirstParentElementForTag("form",this);
					 var btnPressed = document.createElement("input");
					 btnPressed.setAttribute("type","hidden");
					 btnPressed.setAttribute("name",this.getAttribute("name"));
					 btnPressed.setAttribute("value",this.getAttribute("value"));
					 form.appendChild(btnPressed);
					 
					 if(form.getAttribute("enctype") && form.getAttribute("enctype") == "multipart/form-data") {
						 YAHOO.util.Connect.setForm(form,true);
					 } else {
						 YAHOO.util.Connect.setForm(form);
					 }
					 var successFunction = function(o) {						 
						 var targetDiv = document.getElementById(o.argument.ajaxTarget);
						 if(targetDiv) {
							 targetDiv.innerHTML = ""; //remove any data inside of the target
							 if(targetDiv.getAttribute("isipAjaxLoadAfterTarget")) {								 
								 YAHOO.util.Connect.asyncRequest("GET",targetDiv.getAttribute("isipAjaxLoadAfterTarget"),{
										 success: function(o) {
											 o.argument.ajaxTarget.innerHTML = o.responseText;
											 _exec_isipAjaxExecuteAfter(o.argument.objRef);
											 initISIPAjaxProgressive(o.argument.ajaxTarget);
										 },
										 upload: function(o) {
											 o.argument.ajaxTarget.innerHTML = o.responseText;
											 _exec_isipAjaxExecuteAfter(o.argument.objRef);
											 initISIPAjaxProgressive(o.argument.ajaxTarget);
										 },
										 failure: function(o) {
										 	 _exec_isipAjaxExecuteAfter(o.argument.objRef);
											 alert(o.responseText);
										 },
										 argument: { ajaxTarget: targetDiv, objRef: o.argument.objRef }
								 });
							 } else {
								 targetDiv.innerHTML = o.responseText;
								 _exec_isipAjaxExecuteAfter(o.argument.objRef);
								 initISIPAjaxProgressive(targetDiv);
							 }
						 }						 
					 }; 
					 var callback = {
						 success: successFunction,
						 upload: successFunction,
						 failure: function(o) {
							 var targetDiv = document.getElementById(o.argument.ajaxTarget);
							 if(targetDiv) {
								 targetDiv.innerHTML = "";
								 targetDiv.innerHTML = o.responseText;
							 }
						 },
						 argument: { ajaxTarget: this.getAttribute("isipAjaxTarget"), objRef: this }
					 };
					 
					 //if the user executes an exec before action we should run the function specified. (in another thread) ... set timeout
					 if(this.getAttribute("isipAjaxExecuteBefore") && this.getAttribute("isipAjaxExecuteBefore").length != 0) {
						 window.setTimeout(this.getAttribute("isipAjaxExecuteBefore"),10);
					 }
					 					
					 var formMethod = form.getAttribute("method");
					 if(!formMethod) {
					 	 formMethod = "GET";
					 }
					 var execAction = YAHOO.util.Connect.asyncRequest(formMethod, form.getAttribute("action"), callback);
				 }
			 }
		 }
	 }
	 if(document.all) {
		 for(var i = 0; i < ieInputListToAppend.length; i++) {
			 var ieTarget =  ieInputListToAppend[i];
			 ieTarget.formElm.appendChild(ieTarget.newInput);
		 }
	 }
 }
 
 function initISIPAjaxDropTarget(baseElm) {
	 var dvList = baseElm.getElementsByTagName("div");
	 for(var i = 0; i < dvList.length; i++) {
		 var dv = dvList[i];
		 if(dv.getAttribute("isipAjaxDropTarget")) {
			 var ddTarget = new YAHOO.util.DDTarget(dv);
		 }
	 }
 }
 
 /**
  * internet explorer is unable to pass variables in the setTimeout function
	* therfore we need to execute the setTimeout with a key that will then get it's
	* values from the request pool
	**/
 IE_AJAX_REQUEST_POOL = new Array();
 IE_AJAX_REQUEST_POOL_CTR = 0;
 
 var IE_AJAX_DEBUG = null;
 
 function logIE(message) {
	 if(!IE_AJAX_DEBUG) {
		 IE_AJAX_DEBUG = document.createElement("div");
		 IE_AJAX_DEBUG.style.position="absolute";
		 IE_AJAX_DEBUG.style.left="1px";
		 IE_AJAX_DEBUG.style.top="1px";
		 IE_AJAX_DEBUG.style.zIndex=99;
		 IE_AJAX_DEBUG.style.width="250px";
		 IE_AJAX_DEBUG.style.height="300px";
		 IE_AJAX_DEBUG.style.backgroundColor="#eeeeee";
		 IE_AJAX_DEBUG.style.overflow="auto";
		 document.body.appendChild(IE_AJAX_DEBUG);
	 }
	 var mesg = document.createElement("div");
	 mesg.innerHTML = message;
	 IE_AJAX_DEBUG.appendChild(mesg);
 }
 
 function ieRequestPoolItem(id,method,targetUrl,callback) {
	 this.id = id;
	 this.method = method;
	 this.targetUrl = targetUrl;
	 this.callback = callback;
 }
 
 function runAjaxIEPoolRequest(id) {	 
	 for(var i = 0; i < IE_AJAX_REQUEST_POOL.length; i++) {
		 if(IE_AJAX_REQUEST_POOL[i].id == id) {
			 var ieReq = new window.XMLHttpRequest();
			 ieReq.open(IE_AJAX_REQUEST_POOL[i].method,IE_AJAX_REQUEST_POOL[i].targetUrl,false);
			 ieReq.send(null);
			 IE_AJAX_REQUEST_POOL[i].callback.argument.isipTarget.innerHTML = "";
			 IE_AJAX_REQUEST_POOL[i].callback.argument.isipTarget.innerHTML = ieReq.responseText;
			 initISIPAjaxProgressive(IE_AJAX_REQUEST_POOL[i].callback.argument.isipTarget);			 
		 }
	 }
 }
 
 /**
  * this function will wait for microsoft internet explorer to free a YUI asyncRequest slot.
	**/
 function runAjaxRequest(method,targetUrl,callback) {
	 if(document.all) {		 			 			 
		 var poolItem = new ieRequestPoolItem(IE_AJAX_REQUEST_POOL_CTR,method,targetUrl,callback);
		 IE_AJAX_REQUEST_POOL[IE_AJAX_REQUEST_POOL_CTR] = poolItem;		 
		 IE_AJAX_REQUEST_POOL_CTR++;
		 var waitInterval = 100*IE_AJAX_REQUEST_POOL_CTR;
		 setTimeout('runAjaxIEPoolRequest('+poolItem.id+')',waitInterval);
	 } else {
		 YAHOO.util.Connect.asyncRequest(method,targetUrl,callback);
	 }
 }
 
 /**
  * this function will dynamically implement dynamic loading of 
	**/
 function initISIPAjaxLoad(baseElm) {
	 //check if there are anythings that need to be loaded because the have the load tag.
	 var dvList = baseElm.getElementsByTagName("div");
	 for(var i = 0; i < dvList.length; i++) {
		 var dv = dvList[i];
		 if(dv.getAttribute("isipAjaxLoad")) {
			 //we need to load this url
			 runAjaxRequest("GET",dv.getAttribute("isipAjaxLoad"),{
					 success: function(o) {
						 o.argument.isipTarget.innerHTML = "";
						 o.argument.isipTarget.innerHTML = o.responseText;						 
						 initISIPAjaxProgressive(o.argument.isipTarget);
					 },
					 failure: function(o) {
					 	 if(o.status == 502) {
					 	 	 o.argument.isipTarget.innerHTML = "Proxy Error - server message: "+o.statusText;
					 	 }
					 },
					 argument: { isipTarget : dv }
			 });
		 }
	 } 
}

/**
 * this function will detect firefox 3.5
 **/
function isFFX35() {
	return (document.body.childElementCount && !document.all);
}

function getInternetExplorerVersion() {

    var rv = -1; // Return value assumes failure.

    if (navigator.appName == 'Microsoft Internet Explorer') {

        var ua = navigator.userAgent;

        var re = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");

        if (re.exec(ua) != null)

            rv = parseFloat(RegExp.$1);

    }

    return rv;

}

function getSafariVersion() {
	var navId = navigator.userAgent.indexOf("Macintosh");
	if(navId != -1) {
		var navVers = navigator.userAgent.indexOf("Safari/531.9");
		if(navVers != -1) {
			//check if we are using a PPC
			var isPPC = (navigator.userAgent.indexOf("PPC") != -1);
			if(isPPC) {				
				return SAFARI_43_MAC;
			}
		}
	}
	
	return SAFARI;
}

function execCommandChain(commandChain) {
	var clickTargets = commandChain.split(",");
	for(var i = 0; i < clickTargets.length; i++) {
		var clickTarget = clickTargets[i].substring(1,clickTargets[i].length-1);
		var targetConfig = clickTarget.split("#");
		var playerdivName = targetConfig[0];
		var targetUrl = targetConfig[1];
		var targetDiv = document.getElementById(playerdivName);
		if(targetUrl.indexOf("isiptube:") == 0) {
			//we need to tell the isiptube player to reload this url as a video.
			var isipTubePlayer = getFlashMovie(playerdivName);
			if(isipTubePlayer) {
				if(isipTubePlayer.changeMovie) {
					isipTubePlayer.changeMovie(targetUrl.substring(9));
				}
			}
		} else if(targetUrl.indexOf("javascript:") == 0) {
			var jsSource = targetUrl.substring(11);
			PROGRESSIVE_FUNCTIONS_TO_EXEC[PROGRESSIVE_FUNCTIONS_TO_EXEC_LEN] = jsSource;
			PROGRESSIVE_FUNCTIONS_TO_EXEC_LEN++;
		} else if(targetUrl.indexOf("isipAjaxTimelineNext:") == 0) {
			var timelineName = targetUrl.substring(targetUrl.indexOf(":")+1);
			var timelineRef = ISIPAjaxTimeline_getByName(timelineName);
			if(timelineRef) {
				//move to the next position in the timeline
				timelineRef.next();
			}
		} else {						
			if(targetDiv) {
				YAHOO.util.Connect.asyncRequest("GET",targetUrl,{
						success: function(o) {
							o.argument.targetDiv.innerHTML = "";
							o.argument.targetDiv.innerHTML = o.responseText;
							initISIPAjaxProgressive(o.argument.targetDiv);
						},
						failure: function(o) {
							alert("Attenzione, non e stato possibile caricare l'url: "+o.argument.targetUrl+" a cause di un errore: "+o.status+" con messaggio: "+o.statusText);
						},
						argument: { targetDiv: targetDiv, targetUrl: targetUrl }
				});
			}
		}
	}
}

/**
 * create a function that will allow us to introduce a wait vail such that while things are being executed we get the feel
 * that the server is actually doing something
 **/
function isipAjaxShowWaitDialog(dv,x,y) {
	//calculate the side of the container element.
	var rect = null;
	var left = 100;
	var top = 100;
	var width = 100;
	var height = 100;
	if(dv.getBoundingClientRect) {
		rect = dv.getBoundingClientRect();
		left = rect.left;
		top = rect.top;
		width = rect.right-rect.left;
		height = rect.bottom-rect.top;
	}
	var waitVail = document.createElement("div");
	waitVail.style.position="absolute";	
	if(x) {
		left = x;
	}
	if(y) {
		top = y;
	}	
	waitVail.style.left = left+"px";
	waitVail.style.top = top+"px";	
	waitVail.style.width = width+"px";
	waitVail.style.height = height+"px";
	waitVail.style.backgroundColor = "#333333";
	if(!document.all){ 		 
		waitVail.style.opacity = ".5";
	} else {  		
		waitVail.style.filter = "alpha(opacity = 50)";
	}
	var waitIcon = document.createElement("img");
	waitIcon.setAttribute("src","http://ajax.isiportal.com/"+isipAjaxVersion+"/images/loader.gif");
	waitIcon.style.position = "absolute";
	waitIcon.style.top = ((height/2)-10)+"px";
	waitIcon.style.left = ((width/2)-10)+"px";
	waitIcon.style.width="20px";
	waitIcon.style.zIndex = 999;
	waitVail.style.zIndex = 999;
	waitVail.appendChild(waitIcon);	
	dv.appendChild(waitVail);
	
	return waitVail;
}

function isipAjaxHideWaitDialog(waitVail) {
	var parentNode = waitVail.parentNode;
	parentNode.removeChild(waitVail);
}

/**
 * this function will check if the attribute specified exists on the dom element that is passed in
 *
 * @param elm a reference to the element where we should check if the attribute exists or not.
 * @param attrName the name of the attribute to check for.
 * @return true if the attribute exists on the element passed and false if it does not. 
 **/
function hasAttribute(elm,attrName) {
	if(elm.hasAttribute) {
		return elm.hasAttribute(attrName);
	} else {
		for(var i = 0; i < elm.attributes.length; i++) {
			var attr = elm.attributes[i];			
			if(attr.name.toUpperCase() == attrName.toUpperCase()) {
				return true;
			}
		}
		
		return false;
	}
}

/**
 * this function will return a list of the nodes with the name specified
 * that have the attribute name passed implemented on the node with the name specified.
 * this is an isipAjax utility function that avoids having to repeat code throught different implementations.
 *
 * @param baseElm the base parent element to search for nodes in
 * @param nodeName the name of the nodes to search for
 * @param attrName the attribute that must be implemented on those nodes.
 **/
function getElementList(baseElm,nodeName,attrName) {
	var result = new Array();
	var nodeList = baseElm.getElementsByTagName(nodeName);	
	for(var i = 0; i < nodeList.length; i++) {
		var nodeRef = nodeList[i];
		if(hasAttribute(nodeRef,attrName)) {
			result[result.length] = nodeRef;
		}
	}
	
	return result;
}

/**
 * this function will combine two element lists in a single element list.  
 **/
function combineElementLists(listArray) {
	var result = new Array();
	for(var i = 0; i < listArray.length; i++) {
		var listRef = listArray[i];
		for(var j = 0; j < listRef.length; j++) {
			result[result.length] = listRef[j];
		}
	}
	
	return result;
}

function getFirstParentElementForTagWithAttribute(tagName,node,attrName) {
	 var elm = node;
	 do {
		 elm = elm.parentNode;
		 if(elm == null) {
			 return null; 
		 }
	 }while(elm.nodeName.toUpperCase() != tagName.toUpperCase() && !hasAttribute(elm,attrName));
	 return elm;
}
