var AgatWizard={wizardSteps:Array(),id:"agat_popup",name:"agat_wizard_option",scrollInd:false,showStep:function(StepIndex,enable){if(AgatWizard.wizardSteps[StepIndex].disabled!="false"&&!enable){return;}
var CurrStep=AgatEngine.getWindowProperty("glbCurrWizardStep");var CurrElem=document.getElementById(AgatWizard.wizardSteps[CurrStep].id);if(StepIndex>CurrStep){if(!AgatValidator.validateForm(AgatWizard.wizardSteps[CurrStep].id))return;if(!AgatEvents.userBeforeOnloadWizardStep(CurrStep))return;if(AgatWizard.wizardSteps[StepIndex].disabled=="true"){this.enableStep(StepIndex);}
AgatEvents.userOnLoadWizardStep(StepIndex);}
var TargetElem=document.getElementById(AgatWizard.wizardSteps[StepIndex].id);$(CurrElem).tfsHide();$(TargetElem).tfsShow();if(AgatWizard.wizardSteps[StepIndex].name!=AgatWizard.wizardSteps[CurrStep].name){var TargetTab=document.getElementById("WizardTab_"+AgatWizard.wizardSteps[StepIndex].mainStep);$(TargetTab).attr("className","WizardStepActive");var CurrTabElem=document.getElementById("WizardTab_"+AgatWizard.wizardSteps[CurrStep].mainStep);$(CurrTabElem).attr("className","WizardStepVisited");var scollRight=parseInt(AgatEngine.getWindowProperty("glbInitialScrollLeft"),10)-$(CurrTabElem).parent().parent().scrollLeft();$(CurrTabElem).parent().parent().animate({scrollLeft:'+='+scollRight+'px'},1);if(AgatWizard.wizardSteps[StepIndex].mainStep!=AgatEngine.getWindowProperty("glbFirstWizardStep")){$(CurrTabElem).parent().parent().animate({scrollLeft:'-='+AgatWizard.wizardSteps[StepIndex].scrollLeft+'px'},1);}}
if(StepIndex==AgatEngine.getWindowProperty("glbFirstWizardStep")||$(TargetElem).hasAttribute("tfsHideBack")){$("#WizardBackButton").css("visibility","hidden");}
else{$("#WizardBackButton").css("visibility","visible");}
if(StepIndex==AgatEngine.getWindowProperty("glbLastWizardStep")||$(TargetElem).hasAttribute("tfsHideNext")){$("#WizardNextButton").css("visibility","hidden");}
else{$("#WizardNextButton").css("visibility","visible");}
AgatEngine.setWindowProperty("glbCurrWizardStep",StepIndex);this.showWizardProgress(StepIndex);},focusInputField:function(elem){var res=$("#"+$(elem).attr("id")+" *");var i=0;while(i<res.length&&$(res[i]).attr("tagName").toLowerCase()!="input"&&$(res[i]).attr("tagName").toLowerCase()!="a"&&$(res[i]).attr("tagName").toLowerCase()!="textarea"&&$(res[i]).attr("tagName").toLowerCase()!="select"){i++;}
if(($(res[i]).attr("tagName").toLowerCase()=="input"&&$(res[i]).attr("type").toLowerCase()=="text")||$(res[i]).attr("tagName").toLowerCase()=="textarea"){$(res[i]).focus();}},setupWizard:function(){if(!AgatEngine.getWindowProperty("glbCurrWizardStep")){this.firstWizardSetup();}
else{this.ongoingWizardSetup();}},enableStep:function(StepIndex){var StepElem=document.getElementById(AgatWizard.wizardSteps[StepIndex].id);$(StepElem).attr("disabled",false);AgatWizard.setupWizard();var TabElem=document.getElementById("WizardTab_"+AgatWizard.wizardSteps[StepIndex].mainStep);if($(TabElem).attr("className").toLowerCase()=="wizardsteplink"){$(TabElem).attr("className","WizardStepVisited");}},disableStep:function(StepIndex){var StepElem=document.getElementById(AgatWizard.wizardSteps[StepIndex].id);$(StepElem).attr("disabled",true);AgatWizard.setupWizard();var TabElem=document.getElementById("WizardTab_"+AgatWizard.wizardSteps[StepIndex].mainStep);if(!($(TabElem).attr("disabled")))$(TabElem).tfsDisable();$(TabElem).attr("className","WizardStepLink");},nextStep:function(){var CurrStep=AgatEngine.getWindowProperty("glbCurrWizardStep");var i=CurrStep;var found=false;for(i++;i<AgatWizard.wizardSteps.length&&(!found);i++){if(AgatWizard.wizardSteps[i].disabled=="false"){found=true;break;}}
if(found){this.showStep(i);}
else{for(i=CurrStep+1;i<AgatWizard.wizardSteps.length;i++){if(AgatWizard.wizardSteps[i].id){this.showStep(i,true);break;}}}},prevStep:function(){var CurrStep=AgatEngine.getWindowProperty("glbCurrWizardStep");var i=CurrStep;var found=false;for(i--;i>=0&&(!found);i--){if(AgatWizard.wizardSteps[i].disabled!=null&&AgatWizard.wizardSteps[i].disabled=="false"){found=true;break;}}
if(found)this.showStep(i);},wizardShow:function(elem){elem.each(function(){$(this).show();if($(this).tfsDataType()=="date")
$(this).next().show();}).end();},firstWizardSetup:function(){if(AgatEngine.getGeneralAttribute("tfsUIMode")==""||AgatEngine.getGeneralAttribute("tfsUIMode").toLowerCase()!="wizard"){return;}
$("input[className='tfsInputText']").each(function(){$(this).attr("className","tfsWizardInputText");});$("[className='tfsTextHeader']").each(function(){$(this).attr("className","tfsWizardTextHeader");});$("[className='tfsInputRadioText']").each(function(){$(this).attr("className","tfsWizardInputRadioText");});$("[className='stripesTbl']").each(function(){$(this).attr("className","wizardstripesTbl");});var lastStep=0;var firstStep=0;$("div[tfsstepindex]").each(function(){if($(this).hasAttribute("id")){AgatWizard.wizardSteps[$(this).attr("tfsstepindex")]={id:$(this).attr("id"),name:$(this).attr("tfsstepname"),disabled:"true",subtitle:$(this).attr("tfsstepsubtitle")};$(this).attr("disabled",true);if(parseInt($(this).attr("tfsstepindex"),10)>parseInt(lastStep,10))lastStep=$(this).attr("tfsstepindex");}});var i=0;for(i=0;i<=lastStep;i++){if(!AgatWizard.wizardSteps[i])
AgatWizard.wizardSteps[i]={id:null,name:null,disabled:null,internalStep:null,totalInternalSteps:null,subtitle:null,mainStep:null,scrollLeft:null};}
var found=false;for(i=0;i<AgatWizard.wizardSteps.length&&(!found);i++){if(AgatWizard.wizardSteps[i].id){firstStep=i;found=true;AgatWizard.wizardSteps[i].disabled="false";$(document.getElementById(AgatWizard.wizardSteps[i].id)).attr("disabled",false);}}
AgatEngine.setWindowProperty("glbCurrWizardStep",firstStep);AgatEngine.setWindowProperty("glbFirstWizardStep",firstStep);AgatEngine.setWindowProperty("glbLastWizardStep",lastStep);var elem=document.getElementById("UIMode");if(elem){$(elem).attr("value","Wizard");}
var i=firstStep;var scrollValue=0;CurrentName=AgatWizard.wizardSteps[firstStep].name;InternalIndex=1;mainStep=1;AgatWizard.wizardSteps[firstStep].internalStep=InternalIndex;AgatWizard.wizardSteps[firstStep].mainStep=mainStep;AgatWizard.wizardSteps[firstStep].scrollLeft=scrollValue;AgatEngine.setWindowProperty("glbInitialScrollLeft",$(document.getElementById("WizardTab_"+mainStep)).parent().parent().scrollLeft());for(i++,InternalIndex++;i<AgatWizard.wizardSteps.length;i++){if(AgatWizard.wizardSteps[i].id){var elem=document.getElementById(AgatWizard.wizardSteps[i].id);$(elem).tfsHide();if(CurrentName!=AgatWizard.wizardSteps[i].name){var CurrTabElem=document.getElementById("WizardTab_"+mainStep);var currScrollValue=0;$("#"+$(CurrTabElem).attr("id")+" *").each(function(){currScrollValue+=parseInt($(this).attr("clientWidth"),10);});scrollValue+=currScrollValue;InternalIndex=1;mainStep++;CurrentName=AgatWizard.wizardSteps[i].name;}
AgatWizard.wizardSteps[i].internalStep=InternalIndex;AgatWizard.wizardSteps[i].mainStep=mainStep;AgatWizard.wizardSteps[i].scrollLeft=scrollValue;InternalIndex++;}}
$(document.getElementById("WizardTab_"+AgatWizard.wizardSteps[firstStep].mainStep)).attr("className","WizardStepActive");$("#WizardBackButton").css("visibility","hidden");$("body").css("scrollbar-3dlight-color","#CDDAE1");$("body").css("scrollbar-arrow-color","black");$("body").css("scrollbar-darkshadow-color","#CDDAE1");$("body").css("scrollbar-base-color","#CDDAE1");$("body").css("scrollbar-face-color","#CDDAE1");$("body").css("scrollbar-highlight-color","#7398AB");this.showWizardProgress(firstStep);if(document.getElementById){window.alert=function(txt){AgatWizard.createCustomAlert(txt);}}
if(AgatEngine.getGeneralAttribute("tfsOnScreenKeyboard").toLowerCase()=="yes"){var files={"*hebrew":"hebrew","*english":"english"};var file=files['*'+AgatEngine.getGeneralAttribute("tfsLanguage").toLowerCase()]||"hebrew";var html=AgatKeyboardString[file];$("#WizardNevigatorFooter").attr("innerHTML",html);$("#keyboard input").bind("click",function(){AgatOnScreenKeyboard.handleKeyboardChar(this);});AgatEngine.setWindowProperty("glbFocusedInput","initialValue");}},ongoingWizardSetup:function(StepElem){if(AgatEngine.getGeneralAttribute("tfsUIMode")==""||AgatEngine.getGeneralAttribute("tfsUIMode").toLowerCase()!="wizard"){return;}
$("div[tfsstepindex]").each(function(){if($(this).attr("disabled").toString().toLowerCase()=="true")
AgatWizard.wizardSteps[$(this).attr("tfsstepindex")].disabled="true";else
AgatWizard.wizardSteps[$(this).attr("tfsstepindex")].disabled="false";});},scrollWizardDiv:function(id,value,speed){if(AgatWizard.scrollInd){$('#'+id).animate({scrollLeft:'+='+value+'px'},speed,function(){AgatWizard.scrollWizardDiv(id,value,speed);});}},HandleWizardRadios:function(displayId,radioId,check){if(AgatEngine.getGeneralAttribute("tfsUIMode").toLowerCase()!="wizard"){return;}
if(!check){document.getElementById(radioId).checked=false;}
displayElem=document.getElementById(displayId);if($(displayElem).attr("className")=="WizardRadio"&&check){$(displayElem).attr("className","WizardRadioSelected");document.getElementById(radioId).checked=true;}
else if($(displayElem).attr("className")=="WizardCheckbox"&&check){$(displayElem).attr("className","WizardCheckboxSelected");document.getElementById(radioId).checked=true;}
else if(document.getElementById(radioId).type.toLowerCase()=="checkbox"&&check){$(displayElem).attr("className","WizardCheckbox");document.getElementById(radioId).checked=false;}
if(document.getElementById(radioId).type.toLowerCase()=="radio"){options=document.getElementsByName(document.getElementById(radioId).name);var i=0;for(i=0;i<options.length;i++){if(!options[i].checked)
$(options[i]).next().attr("className","WizardRadio");}}
if(document.getElementById(radioId).type.toLowerCase()=="checkbox"&&document.getElementById(radioId).checked==false){$(displayElem).attr("className","WizardCheckbox");}
if($(document.getElementById(radioId)).attr('onclick')&&check){var clickCommandStr=$(document.getElementById(radioId)).attr('onclick').toString();clickCommandStr=clickCommandStr.substring(clickCommandStr.indexOf('{')+1,clickCommandStr.indexOf('}'));eval(clickCommandStr);}},updateLookupOption:function(evt,elem,input,WizardOptions){$("#WizardSelectBoxMessage").attr("innerHTML","");var i=0;var foundNewChoice=false;var foundOldChoice=false;for(i=0;i<WizardOptions.length&&(!foundNewChoice||!foundOldChoice);i++)
{if($(WizardOptions[i]).attr("id")==$(elem).attr("id"))
{$(WizardOptions[i]).attr("className","WizardOptionSelected");$(input).attr("value",$(WizardOptions[i]).attr("text"));$(input).attr("tfsValue",$(WizardOptions[i]).attr("value"));$(input).attr("text",$(WizardOptions[i]).attr("value"));foundNewChoice=true;}
else
{if($(WizardOptions[i]).attr("className")=="WizardOptionSelected"){$(WizardOptions[i]).attr("className","WizardOption");foundOldChoice=true;}}}
$("#WizardSelectInputText").attr("value",$(input).attr("value"));},WizardLookupCloseHandler:function(evt,WizardOptions,input){var LookupButton=$(input).next();if($(LookupButton).css("direction").toLowerCase()=="ltr"||$(LookupButton).attr("dir").toLowerCase()=="ltr"){$(LookupButton).css("border-right","solid 1px #7F9DB9");$(LookupButton).css("border-left","0px");$(LookupButton).css("margin-right","0px");$(LookupButton).css("margin-left","-4px");}
if(!WizardOptions){$(input).attr("value","");$(input).attr("text","");$(input).attr("tfsValue",-1);AgatWizard.WizardPopupCloseHandler(evt);return;}
var found=false;var i=0;for(i=0;i<WizardOptions.length&&(!found);i++){if($(WizardOptions[i]).attr("className")=="WizardOptionSelected")
{$(input).attr("value",$(WizardOptions[i]).attr("text"));$(input).attr("tfsValue",$(WizardOptions[i]).attr("value"));$(input).attr("text",$(WizardOptions[i]).attr("value"));found=true;}}
if(found){AgatWizard.WizardPopupCloseHandler(evt);$(input).trigger('change');}
else{$("#WizardSelectBoxMessage").attr("innerHTML","יש לבחור באחת מהאפשרויות שברשימה");}},WizardPopupCloseHandler:function(evt){AgatUtils.setOpacity("mainDiv",100);AgatPopup.popupCloseHandler(evt);},showWizardSelectBoxFromKey:function(evt,input,WizardOptions){$("#WizardSelectBoxMessage").attr("innerHTML","");var keyCodeUp=38;var keyCodeDown=40;var keyCodeEnter=13;var keyCodeEsc=27;var keyCodeTab=9;switch(evt.keyCode){case keyCodeUp:case keyCodeDown:case keyCodeEnter:case keyCodeEsc:case keyCodeTab:break;default:var inputValue=$(input).attr("value");var i=0;var optionsCounter=0;var singleOptionIndex=0;for(i=0;i<WizardOptions.length;i++){$(WizardOptions[i]).attr("className","WizardOption");if($(WizardOptions[i]).attr("text").indexOf(inputValue)!=0){WizardOptions[i].style.display="none";}
else{WizardOptions[i].style.display="block";optionsCounter++;singleOptionIndex=i;}}
if(optionsCounter==1){$(WizardOptions[singleOptionIndex]).attr("className","WizardOptionSelected");}
break;}},showWizardProgress:function(StepIndex){ProgressElem=document.getElementById("WizardNevigatorProgress");var stepNumber;var subtitle;stepNumber=AgatWizard.wizardSteps[StepIndex].mainStep+"."+AgatWizard.wizardSteps[StepIndex].internalStep;if(AgatWizard.wizardSteps[StepIndex].subtitle){subtitle=AgatWizard.wizardSteps[StepIndex].subtitle;}
else{subtitle=AgatWizard.wizardSteps[StepIndex].name;}
if(ProgressElem){$(ProgressElem).attr("innerHTML"," "+stepNumber+"   "+subtitle);}},createCustomAlert:function(txt){if(document.getElementById(AgatWizard.id))return;AgatUtils.setOpacity("mainDiv",40);mObj=document.getElementsByTagName("body")[0].appendChild(document.createElement("div"));mObj.id=AgatWizard.id;$(mObj).attr("className","WizardAlertBoxContainer");mObj.style.height=document.documentElement.scrollHeight+"px";var alertObj=mObj.appendChild(document.createElement("div"));$(alertObj).attr("className","WizardAlertBox");var WizardPopupImage=alertObj.appendChild(document.createElement("span"));$(WizardPopupImage).attr("className","WizardPopupImage");var patt1=new RegExp("\n");if(patt1.test(txt)){var title=alertObj.appendChild(document.createElement("span"));$(title).attr("className","WizardPopupTitle");$(title).attr("innerHTML",txt.substring(0,txt.indexOf("\n")));txt=txt.substring(txt.indexOf("\n")+1);txt=txt.replace(/\n/g,"<br />");}
var msg=alertObj.appendChild(document.createElement("div"));$(msg).attr("className","WizardAlertBoxText");$(msg).attr("innerHTML",txt);var AlertBoxFooter=alertObj.appendChild(document.createElement("div"));$(AlertBoxFooter).attr("className","WizardPopupFooter");var btn=document.createElement("input");btn.type="button";btn.id="AlertBoxCloseBtn";btn.value="חזרה לתהליך";$(btn).attr("className","WizardPopupButton");$(btn).bind("click",function(event){AgatWizard.WizardAlertCloseHandler(event);});AlertBoxFooter.appendChild(btn);},WizardAlertCloseHandler:function(evt){AgatWizard.WizardPopupCloseHandler(evt);var id=AgatEngine.getWindowProperty("ElemToFocus");if(id){if(id!=""){$("#"+id).focus();}}},showWizardLookupBox:function(input,options,x,y,selectElem){if(document.getElementById(AgatWizard.id))return;var WizardOptions;AgatUtils.setOpacity("mainDiv",10);var WizardSelectBox=document.getElementById(AgatWizard.id);if(!WizardSelectBox){WizardSelectBox=document.createElement("div");$(WizardSelectBox).attr("className","WizardSelectBox");WizardSelectBox.id=AgatWizard.id;WizardSelectBox.style.display="none";WizardSelectBox.setAttribute("_agat_transient","1");document.body.appendChild(WizardSelectBox);}
WizardSelectBox.style.top="18%";WizardSelectBox.style.left="40%";var WizardSelectTitle=document.createElement("div");$(WizardSelectTitle).attr("className","WizardSelectTitle");if($(selectElem).hasAttribute("tfsLookupTitle")){$(WizardSelectTitle).attr("innerHTML",$(selectElem).attr("tfsLookupTitle"));}
WizardSelectBox.appendChild(WizardSelectTitle);var WizardSelectSubTitle=document.createElement("div");$(WizardSelectSubTitle).attr("className","WizardSelectSubTitle");$(WizardSelectSubTitle).id="WizardSelectSubTitle";$(WizardSelectSubTitle).attr("innerHTML",$(selectElem).attr("tfsLookupSubTitle"));WizardSelectSubTitle.align="right";WizardSelectBox.appendChild(WizardSelectSubTitle);var WizardSelectBoxMessage=document.createElement("div");$(WizardSelectBoxMessage).attr("className","WizardSelectBoxMessage");WizardSelectBoxMessage.id="WizardSelectBoxMessage";WizardSelectBoxMessage.align="right";WizardSelectBox.appendChild(WizardSelectBoxMessage);var WizardSelectContent=document.createElement("select");var WizardSelectInputText=document.createElement("input");$(WizardSelectInputText).attr("className","WizardSelectInputText");WizardSelectInputText.type="text";WizardSelectInputText.id="WizardSelectInputText";$(WizardSelectInputText).bind('keyup',function(event){AgatWizard.showWizardSelectBoxFromKey(event,this,WizardOptions);});$(WizardSelectInputText).bind('focus',function(){AgatOnScreenKeyboard.handleInputChange($(WizardSelectInputText).attr("id"));})
WizardSelectBox.appendChild(WizardSelectInputText);var WizardOptionsContainer=document.createElement("div");WizardOptionsContainer.id="WizardOptionsContainer"
$(WizardOptionsContainer).attr("className","WizardOptionsContainer");WizardSelectBox.appendChild(WizardOptionsContainer);for(var i=0;i<options.length;i++){var WizardOption=document.createElement("a");$(WizardOption).bind("click",function(event){AgatWizard.updateLookupOption(event,this,input,WizardOptions);});$(WizardOption).attr("className","WizardOption");$(WizardOption).attr("innerHTML",options[i].text);WizardOption.value=options[i].value;WizardOption.text=options[i].text;WizardOption.id=AgatWizard.name+i;WizardOption.name=AgatWizard.name;WizardOptionsContainer.appendChild(WizardOption);}
var WizardSelectBoxSpaceHolder=document.createElement("span");WizardSelectBoxSpaceHolder.style.display="block";WizardSelectBoxSpaceHolder.style.height="200px";WizardSelectBox.appendChild(WizardSelectBoxSpaceHolder);var WizardSelectBoxFooter=document.createElement("div");$(WizardSelectBoxFooter).attr("className","WizardPopupFooter");WizardSelectBox.appendChild(WizardSelectBoxFooter);var WizardSelectBoxCancelButton=document.createElement("input");$(WizardSelectBoxCancelButton).attr("className","WizardPopupButton");WizardSelectBoxCancelButton.value="ביטול";WizardSelectBoxCancelButton.id="WizardSelectBoxCancelButton";WizardSelectBoxCancelButton.type="button";$(WizardSelectBoxCancelButton).bind("click",function(event){AgatWizard.WizardLookupCloseHandler(event,null,input);});WizardSelectBoxFooter.appendChild(WizardSelectBoxCancelButton);var WizardSelectBoxApproveButton=document.createElement("input");$(WizardSelectBoxApproveButton).attr("className","WizardPopupButton");WizardSelectBoxApproveButton.value="אישור";WizardSelectBoxApproveButton.id="WizardSelectBoxApproveButton"
WizardSelectBoxApproveButton.type="button";$(WizardSelectBoxApproveButton).bind("click",function(event){AgatWizard.WizardLookupCloseHandler(event,WizardOptions,input);});WizardSelectBoxFooter.appendChild(WizardSelectBoxApproveButton);WizardOptions=$("a[name='"+AgatWizard.name+"']");WizardSelectBox.style.display="block";WizardSelectInputText.focus();}}