/**
 * 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.
 * * update
 **/

 var isipAjaxVersion = "STABLE_0008";

 var tmpvhost = window.location.href.substring(window.location.href.indexOf("://") + 3, window.location.href.length);
 var vhost = window.location.href.substring(0, window.location.href.indexOf("://") + 3 + tmpvhost.indexOf("/"));

 var scriptLocation = null;
 var scriptList = document.getElementsByTagName("script");
 for(var i = 0; i < scriptList.length; i++) {
     if(scriptList[i].getAttribute("src").length != 0 && scriptList[i].getAttribute("src").indexOf("isipajax.js") != -1
         && scriptList[i].getAttribute("src").indexOf("http") == 0) {
         var remoteSrc = scriptList[i].getAttribute("src");
         var startIdx = remoteSrc.indexOf("://")+3;
         vhost = remoteSrc.substring(0,remoteSrc.indexOf("/",startIdx));
         break;
     }
 }
 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();

 var COMMAND_CHAIN_CUSTOM_PROTOCOLS = new Array();

 function isipAjaxCommandChainHander(protocol,commandChainHook) {
 	 this.protocol = protocol;
 	 this.commandChainHook = commandChainHook;

 	 this.execute = function(commandString) {
 	 	 this.commandChainHook(commandString);
 	 }
 }

 function isipAjaxAddCommandChainHandler(protocol,commandChainHook) {
 	 //check if this hook already exists
	 var hasFunction = false;
	 for(var i = 0; i < COMMAND_CHAIN_CUSTOM_PROTOCOLS.length; i++) {
		 if(COMMAND_CHAIN_CUSTOM_PROTOCOLS[i].protocol == protocol) {
			 hasFunction = true;
			 break;
		 }
	 }
	 if(!hasFunction) {
		 COMMAND_CHAIN_CUSTOM_PROTOCOLS[COMMAND_CHAIN_CUSTOM_PROTOCOLS.length] = new isipAjaxCommandChainHander(protocol,commandChainHook);
	 }
 }

 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) {
					isipAjax_FullScreenWait();
			 }
		 } else {
			 clearInterval(waitPanelInterval);
		 }
 },waitPanelCheckInterval);

 function isipAjax_FullScreenWait() {
 	 isipAjax_FullScreenWait(null);
 }

function isipAjax_FullScreenWait(message) {
 	 waitPanel = document.createElement("div");
		var docwidth = 0;
		var docheight = 0;
		var waitVail = document.createElement("div");
		var waitMessage = document.createElement("div");
		if(!document.all){
			docwidth = window.innerWidth;
			docheight = window.innerHeight;
			waitVail.style.opacity = ".5";
		} else {
			docwidth = document.body.clientWidth;
			if(getInternetExplorerVersion() >= 8.0) {
				docwidth = docwidth-19;
			}
			docheight = screen.availHeight;
			waitVail.style.filter = "alpha(opacity = 50)";
		}
		waitPanel.style.width = docwidth+"px";
		waitPanel.style.height = docheight+"px";
		waitPanel.style.position = "absolute";
		waitPanel.style.zIndex = 999;
		waitPanel.style.top = "0px";
		waitPanel.style.left = "0px";
		waitVail.style.width = docwidth+"px";
		waitVail.style.height = docheight+"px";
		waitVail.style.backgroundColor = "#000000";
		waitVail.style.position = "absolute";
		waitVail.style.top = "0px";
		waitVail.style.left = "0px";
		waitPanel.appendChild(waitVail);
		var waitIcon = document.createElement("img");
		waitIcon.setAttribute("src",vhost+"/isipajax/"+isipAjaxVersion+"/images/loader.gif");
		waitIcon.style.position = "absolute";
		waitIcon.style.top = ((docheight/2)-10)+"px";
		waitIcon.style.left = ((docwidth/2)-10)+"px";
		waitIcon.style.width="20px";
		waitIcon.style.zIndex = 998;
		waitPanel.appendChild(waitIcon);
		if(message) {
			waitMessage.style.backgroundColor = "#fff";
			waitMessage.style.borderWidth = "1px";
			waitMessage.style.borderColor = "#333";
			waitMessage.style.width = "250px";
			waitMessage.style.paddingLeft = "5px";
			waitMessage.style.paddingRight = "5px";
			waitMessage.style.paddingTop = "50px";
			waitMessage.style.paddingBottom = "50px";
			waitMessage.style.fontWeight = "bold";
			waitMessage.innerHTML = message;
			waitMessage.style.position = "absolute";
			waitMessage.style.top = ((docheight/2)-25)+"px";
			waitMessage.style.left = ((docwidth/2)-125)+"px";
			waitMessage.style.zIndex = 999;
			waitPanel.appendChild(waitMessage);
		}
		document.body.appendChild(waitPanel);
 }

 function isipAjax_clearFullScreenWait() {
 	 document.body.removeChild(waitPanel);
 }

 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","autocomplete",
 							 "isipajaxnumberfield","isipajaxhtmlfield","isipajaxtabs", "isipajaxcalendar", "isipajaxvalidateformat", "isipajaxvalidateeunumberformat",
                                                         "isipajaxvalidateusnumberformat", "isipajaxvalidateintnumberformat", "isipajaxvalidateeustrictnumberformat", "isipajaxvalidateusstrictnumberformat",
                                                         "isipajaxnumbernovalidate", "isipajaxnumberdecposnotnullnovalidate","isipajaxautocomplete"];
 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", "isipajaxcalendar","isipajaxvalidateformat", "isipajaxvalidateeunumberformat",
                                                         "isipajaxvalidateusnumberformat", "isipajaxvalidateintnumberformat", "isipajaxvalidateeustrictnumberformat", "isipajaxvalidateusstrictnumberformat",
                                                         "isipajaxnumbernovalidate", "isipajaxnumberdecposnotnullnovalidate"];
 }
 var yuiLoader = new YAHOO.util.YUILoader({
		 base: vhost+"/isipajax/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: vhost+"/isipajax/"+isipAjaxVersion+"/js/isipAjaxShowOnDrop.js",
		 varName: "ISIPAJAXSHOWONDROP"
 });

 //add the isipajaxexecuteondrop module
 yuiLoader.addModule({
		 name: "isipajaxexecuteondrop",
		 type: "js",
		 fullpath: vhost+"/isipajax/"+isipAjaxVersion+"/js/isipAjaxExecuteOnDrop.js",
		 varName: "ISIPAJAXEXECUTEONDROP"
 });

 //add the isipAjaxShowOnClick module
 yuiLoader.addModule({
		 name: "isipajaxshowonclick",
		 type: "js",
		 fullpath: vhost+"/isipajax/"+isipAjaxVersion+"/js/isipAjaxShowOnClick.js",
		 varName: "ISIPAJAXSHOWONCLICK"
 });

 //add the isipAjaxOnClick module so that it will be loaded dynamically
 yuiLoader.addModule({
		 name: "isipajaxonclick",
		 type: "js",
		 fullpath: vhost+"/isipajax/"+isipAjaxVersion+"/js/isipAjaxOnClick.js",
		 varName: "ISIPAJAXONCLICK"
 });



 yuiLoader.addModule({
		 name: "isipajaxtargettodialog",
		 type: "js",
		 fullpath: vhost+"/isipajax/"+isipAjaxVersion+"/js/isipAjaxTargetToDialog.js",
		 varName: "ISIPAJAXTARGETTODIALOG"
 });

 yuiLoader.addModule({
		 name: "isipajaxsortable",
		 type: "js",
		 fullpath: vhost+"/isipajax/"+isipAjaxVersion+"/js/isipAjaxSortable.js",
		 varName: "ISIPAJAXSORTABLE"
 });

 yuiLoader.addModule({
		 name: "isipajaxliveplayer",
		 type: "js",
		 fullpath: vhost+"/isipajax/"+isipAjaxVersion+"/js/isipAjaxLivePlayer.js",
		 varName: "ISIPAJAXLIVEPLAYER"
 });


 //add the module for video on demand flash player
 yuiLoader.addModule({
		 name: "isipajaxvideoplayer",
		 type: "js",
		 fullpath: vhost+"/isipajax/"+isipAjaxVersion+"/js/isipAjaxVideoPlayer.js",
		 varName: "ISIPAJAXVIDEOPLAYER"
 });

 yuiLoader.addModule({
		 name: "isipajaxexecuteaftertimeperiod",
		 type: "js",
		 fullpath: vhost+"/isipajax/"+isipAjaxVersion+"/js/isipAjaxExecuteAfterTimePeriod.js",
		 varName: "ISIPAJAXEXECUTEAFTERTIMEPERIOD"
 });

 yuiLoader.addModule({
		 name: "isipajaxcarousel",
		 type: "js",
		 fullpath: vhost+"/isipajax/"+isipAjaxVersion+"/js/isipAjaxCarousel.js",
		 varName: "ISIPAJAXCAROUSEL"
 });

 yuiLoader.addModule({
		 name: "isipajaxnumberfield",
		 type: "js",
		 fullpath: vhost+"/isipajax/"+isipAjaxVersion+"/js/isipAjaxNumberField.js",
		 varName: "ISIPAJAXNUMBERFIELD"
 });

 yuiLoader.addModule({
		 name: "isipajaxhtmlfield",
		 type: "js",
		 fullpath: vhost+"/isipajax/"+isipAjaxVersion+"/js/isipAjaxHTMLField.js",
		 varName: "ISIPAJAXNUMBERFIELD"
 });

 yuiLoader.addModule({
		 name: "isipajaxtabs",
		 type: "js",
		 fullpath: vhost+"/isipajax/"+isipAjaxVersion+"/js/isipAjaxTabs.js",
		 varName: "ISIPAJAXTABS"
 });

  yuiLoader.addModule({
		 name: "isipajaxcalendar",
		 type: "js",
		 fullpath: vhost+"/isipajax/"+isipAjaxVersion+"/js/isipAjaxCalendar.js",
		 varName: "ISIPAJAXCALENDAR"
 });

 yuiLoader.addModule({
		 name: "isipajaxvalidateformat",
		 type: "js",
		 fullpath: vhost+"/isipajax/"+isipAjaxVersion+"/js/isipAjaxValidateFormat.js",
		 varName: "ISIPAJAXVALIDATENUMBERFORMAT"
 });

 yuiLoader.addModule({
		 name: "isipajaxvalidateeunumberformat",
		 type: "js",
		 fullpath: vhost+"/isipajax/"+isipAjaxVersion+"/js/isipAjaxValidateEuNumberFormat.js",
		 varName: "ISIPAJAXVALIDATEEUNUMBERFORMAT"
 });
 yuiLoader.addModule({
		 name: "isipajaxvalidateusnumberformat",
		 type: "js",
		 fullpath: vhost+"/isipajax/"+isipAjaxVersion+"/js/isipAjaxValidateUsNumberFormat.js",
		 varName: "ISIPAJAXVALIDATEUSNUMBERFORMAT"
 });
 yuiLoader.addModule({
		 name: "isipajaxvalidateintnumberformat",
		 type: "js",
		 fullpath: vhost+"/isipajax/"+isipAjaxVersion+"/js/isipAjaxValidateIntNumberFormat.js",
		 varName: "ISIPAJAXVALIDATEINTNUMBERFORMAT"
 });
 yuiLoader.addModule({
		 name: "isipajaxvalidateeustrictnumberformat",
		 type: "js",
		 fullpath: vhost+"/isipajax/"+isipAjaxVersion+"/js/isipAjaxValidateEuStrictNumberFormat.js",
		 varName: "ISIPAJAXVALIDATEEUSTRICTNUMBERFORMAT"
 });
 yuiLoader.addModule({
		 name: "isipajaxvalidateusstrictnumberformat",
		 type: "js",
		 fullpath: vhost+"/isipajax/"+isipAjaxVersion+"/js/isipAjaxValidateUsStrictNumberFormat.js",
		 varName: "ISIPAJAXVALIDATEUSSTRICTNUMBERFORMAT"
 });
 yuiLoader.addModule({
		 name: "isipajaxnumbernovalidate",
		 type: "js",
		 fullpath: vhost+"/isipajax/"+isipAjaxVersion+"/js/isipAjaxNumberNoValidate.js",
		 varName: "ISIPAJAXNUMBERNOVALIDATE"
 });
 yuiLoader.addModule({
		 name: "isipajaxnumberdecposnotnullnovalidate",
		 type: "js",
		 fullpath: vhost+"/isipajax/"+isipAjaxVersion+"/js/isipAjaxNumberDecPosNotNullNoValidate.js",
		 varName: "ISIPAJAXNUMBERDECPOSNOTNULLNOVALIDATE"
 });
 yuiLoader.addModule({
		 name: "isipajaxautocomplete",
		 type: "js",
		 fullpath: vhost+"/isipajax/"+isipAjaxVersion+"/js/isipAjaxAutoComplete.js",
		 varName: "ISIPAJAXAUTOCOMPLETE"
 });
 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);
		 new ISIPAJAXTABS().init(baseElm);
		 new ISIPAJAXCALENDAR().init(baseElm);
		 new ISIPAJAXVALIDATEEUNUMBERFORMAT().init(baseElm);
		 new ISIPAJAXVALIDATEUSNUMBERFORMAT().init(baseElm);
                 new ISIPAJAXVALIDATEINTNUMBERFORMAT().init(baseElm);
                 new ISIPAJAXVALIDATEEUSTRICTNUMBERFORMAT().init(baseElm);
                 new ISIPAJAXVALIDATEUSSTRICTNUMBERFORMAT().init(baseElm);
                 new ISIPAJAXNUMBERNOVALIDATE().init(baseElm);
                 new ISIPAJAXNUMBERDECPOSNOTNULLNOVALIDATE().init(baseElm);
		 initISIPAjaxAutoComplete(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);
		 new ISIPAJAXTABS().init(baseElm);
		 new ISIPAJAXCALENDAR().init(baseElm);
		 new ISIPAJAXVALIDATEEUNUMBERFORMAT().init(baseElm);
		 new ISIPAJAXVALIDATEUSNUMBERFORMAT().init(baseElm);
                 new ISIPAJAXVALIDATEINTNUMBERFORMAT().init(baseElm);
                 new ISIPAJAXVALIDATEEUSTRICTNUMBERFORMAT().init(baseElm);
                 new ISIPAJAXVALIDATEUSSTRICTNUMBERFORMAT().init(baseElm);
                 new ISIPAJAXNUMBERNOVALIDATE().init(baseElm);
                 new ISIPAJAXNUMBERDECPOSNOTNULLNOVALIDATE().init(baseElm);
		 initISIPAjaxAutoComplete(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() {
					 SYNC_ISIPAJAXEDITORS(); //internet explorer is not fast.
					 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);

					 // Controllo presenza campi validazione number.

					 if( !validateInputWithEuropeanFormat(form)
                                             || !validateInputWithAmericanFormat(form)
                                             || !validateInputWithIntegerFormat(form)
                                             || !validateInputWithEuropeanStrictFormat(form)
                                             || !validateInputWithAmericanStrictFormat(form)) return ;


					 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")) {
								 runAjaxRequest("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 = getAjaxData(IE_AJAX_REQUEST_POOL[i].method,IE_AJAX_REQUEST_POOL[i].targetUrl);
			 /*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.success({
			 		 responseText: ieReq.responseText,
			 		 responseXML: ieReq.responseXML,
			 		 argument: IE_AJAX_REQUEST_POOL[i].callback.argument
			 });
		 }
	 }
 }

 function getAjaxData(method,url) {
 	 var ieReq = new window.XMLHttpRequest();
	 ieReq.open(method,url,false);
	 ieReq.send(null);

	 return ieReq;
 }

 /**
  * this function will wait for microsoft internet explorer to free a YUI asyncRequest slot.
	**/
 function runAjaxRequest(method,targetUrl,callback) {
	 if(document.all) {
		 if(targetUrl.indexOf("?") != -1) {
			 targetUrl += "&";
		 } else {
			 targetUrl += "?";
		 }
		 targetUrl += "ISIPAJAXTIMESTAMPFORCEIEREFRESH="+(new Date().getTime());
		 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 isIE() {
	if(document.all) {
		return true;
	}

	return false;
}

function isIE8() {
	return (document.all && getInternetExplorerVersion() >= 8.0);
}

function isIE7() {
	return (_ie7_getInternetExplorerVersion() >= 7.0 && _ie7_getInternetExplorerVersion() < 8.0);
}

function _ie7_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 {
			//check if somebody added custom protocol handlers to our click target and call their implementation functions
			//with the data placed after the protocol specification.
			var protocolSpec = targetUrl.substring(0,targetUrl.indexOf(":"));
			var hasExecCustom = false;

			for(var j = 0; j < COMMAND_CHAIN_CUSTOM_PROTOCOLS.length; j++) {
				var handler = COMMAND_CHAIN_CUSTOM_PROTOCOLS[j];
				if(handler.protocol == playerdivName) {
					handler.execute(targetUrl);
					hasExecCustom = true;
					break;
				}
			}
			if(!hasExecCustom) {
				if(targetDiv) {
					runAjaxRequest("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",vhost+"/isipajax/"+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;
}

function isipAjax_loadDataIntoElement(elm,url) {
	runAjaxRequest("GET",url,{
		 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 : elm}
 });
}

var EXECUTE_ARGS = new Array();

function threadExec(name,func,params) {
	this.name = name;
	this.func = func;
	this.params = params;
}

function executeInThread(name,func,params,delay) {
	EXECUTE_ARGS[EXECUTE_ARGS.length] = new threadExec(name,func,params);
	setTimeout("__executeInThread('"+name+"')",delay);
}

function __executeInThread(name) {
	var N_EXECUTE_ARGS = new Array();
	var threadToExec = null;
	for(var i = 0; i < EXECUTE_ARGS.length; i++) {
		if(EXECUTE_ARGS[i].name == name) {
			threadToExec = EXECUTE_ARGS[i];
		} else {
			N_EXECUTE_ARGS[N_EXECUTE_ARGS.length] = EXECUTE_ARGS[i];
		}
	}
	EXECUTE_ARGS = N_EXECUTE_ARGS;
	threadToExec.func(threadToExec.params);
}

