var cur=-1;var selectsToHide=new Array();var suggestValues=new Array();var lookupValues=new Array();var masterDetails={flag:"",counter:0,show:false};var isLookupError=false;var isSetFocus=false;var isMouseOnDiv=false;var RollDetailsLink={timeout:null,showPopup:function(a,b){clearTimeout(this.timeout);if($("#master_details").css("visibility")=="hidden"||(b!=undefined&&b!=masterDetails.flag)){this.timeout=setTimeout(function(){masterDetails.flag=b;masterDetails.show=true;masterDetails.counter++;$.get(b,{counter:masterDetails.counter,rndVal:(new Date().getTime())},function(c){var d=c.split("counterSeparator");if(masterDetails.counter==d[1]){$("#master_details").html(d[0]);setLyr(a,"master_details");if($.browser.mozilla&&($("#master_details").get(0).offsetTop>window.innerHeight/2+document.body.scrollTop)){$("#master_details").css("top",($("#master_details").get(0).offsetTop-$("#master_details").get(0).offsetHeight)+"px")}else{if($.browser.msie&&($("#master_details").get(0).offsetTop>document.body.clientHeight/2+document.body.scrollTop)){$("#master_details").css("top",($("#master_details").get(0).offsetTop-$("#master_details").get(0).offsetHeight)+"px")}}if(masterDetails.show){$("#master_details").css("visibility","visible")}}})},50)}},hidePopup:function(){masterDetails.show=false;if($("#master_details").css("visibility")=="hidden"){clearTimeout(this.timeout)}else{this.timeout=setTimeout(function(){$("#master_details").css("visibility","hidden");$("#master_details").html("")},100)}}};$(document).ready(function(){$("#search_suggest").mouseover(function(){isMouseOnDiv=true});$("#search_suggest").mouseout(function(){isMouseOnDiv=false});$("#ctlSearchFor").blur(function(){if(!isMouseOnDiv){DestroySuggestDiv()}});$("input[@name*=value_]").blur(function(){if(!isMouseOnDiv){DestroySuggestDiv()}})});$(document).click(function(){DestroySuggestDiv()});function myEncode(a){if(a){a=a.replace(/:/g,"%3A");a=a.replace(/=/g,"%3D");a=a.replace(/&/g,"%26");a=a.replace(/\//g,"%2F");a=a.replace(/\?/g,"%3F");a=a.replace(/\s/g,"%20")}return a}Array.prototype.inArray=function(c,a){var b;for(b=0;b<this.length;b++){if(a){if(this[b]==c){return true}}else{if(this[b].toLowerCase()==c.toLowerCase()){return true}}}return false};function DestroySuggestDiv(){cur=-1;isMouseOnDiv=false;$("#search_suggest").html("");$("#search_suggest").css({visibility:"hidden"});$.each(selectsToHide,function(a,b){b.style.visibility="visible"});selectsToHide.splice(0,selectsToHide.length)}function PtInBox(c){var b=false;var e=$("#search_suggest")[0];var g=findPos(c)[0];var f=findPos(c)[1];var d=findPos(c)[2];var a=findPos(c)[3];if(g>=e.offsetLeft&&g<=(e.offsetLeft+e.offsetWidth)&&f>=e.offsetTop&&f<=(e.offsetTop+e.offsetHeight)){b=true}if((g+d)>=e.offsetLeft&&(g+d)<=(e.offsetLeft+e.offsetWidth)&&f>=e.offsetTop&&f<=(e.offsetTop+e.offsetHeight)){b=true}if(g>=e.offsetLeft&&g<=(e.offsetLeft+e.offsetWidth)&&(f+a)>=e.offsetTop&&(f+a)<=(e.offsetTop+e.offsetHeight)){b=true}if((g+d)>=e.offsetLeft&&(g+d)<=(e.offsetLeft+e.offsetWidth)&&(f+a)>=e.offsetTop&&(f+a)<=(e.offsetTop+e.offsetHeight)){b=true}if((g<=e.offsetLeft&&(g+d)>=(e.offsetLeft+e.offsetWidth))&&((e.offsetTop+e.offsetHeight)>=f&&e.offsetTop<=(f+a))){b=true}if(b){return true}return false}function setLyr(c,a){var b=findPos(c);if(a=="master_details"){b[0]+=(b[2]+5)}if(a=="search_suggest"){b[1]+=b[3]}$("#"+a).css("top",b[1]+"px");$("#"+a).css("left",b[0]+"px")}function findPos(a){var b=curtop=0;if(a.offsetParent){b=a.offsetLeft;curtop=a.offsetTop;curwidth=a.offsetWidth;curheight=a.offsetHeight;while(a=a.offsetParent){b+=a.offsetLeft;curtop+=a.offsetTop}}return[b,curtop,curwidth,curheight]}function moveUp(c,a){if($("#search_suggest").children().length>0&&cur>=-1){cur--;if(cur==-2){cur=$("#search_suggest").children().length-1;c.focus()}for(var b=0;b<$("#search_suggest").children().length;b++){if(b==cur){$("#search_suggest").children().get(b).className="suggest_link_over";c.value=suggestValues[cur].replace(/\<(\/b|b)\>/gi,"");if(a=="lookup"){isLookupError=false;$(c).removeClass("highlight");var d=$("#"+c.id.substring(8))[0];if($(d).val()!=lookupValues[cur]){$(d).val(lookupValues[cur]);$(d).change()}}}else{$("#search_suggest").children().get(b).className="suggest_link"}}}}function moveDown(c,a){if($("#search_suggest").children().length>0&&cur<($("#search_suggest").children().length)){cur++;for(var b=0;b<$("#search_suggest").children().length;b++){if(b==cur){$("#search_suggest").children().get(b).className="suggest_link_over";c.value=suggestValues[cur].replace(/\<(\/b|b)\>/gi,"");if(a=="lookup"){isLookupError=false;var d=$("#"+c.id.substring(8))[0];$(c).removeClass("highlight");if($(d).val()!=lookupValues[cur]){$(d).val(lookupValues[cur]);$(d).change()}}}else{$("#search_suggest").children().get(b).className="suggest_link"}}if(cur==($("#search_suggest").children().length)){cur=-1;c.focus()}}}function suggestOver(a){$("div.suggest_link_over").each(function(){this.className="suggest_link"});a.className="suggest_link_over";cur=a.id.substring(10)}function suggestOut(a){a.className="suggest_link"}function setSearch(a,b){if(setSearch.arguments[2]=="lookup"){isLookupError=false;var c=$("#"+a.substring(8)+setSearch.arguments[4])[0];$("#"+a+setSearch.arguments[4]).removeClass("highlight");$("#"+a+setSearch.arguments[4]).val(b);if($(c).val()!=setSearch.arguments[3]){$(c).val(setSearch.arguments[3]);$(c).change()}}else{$("input[@type=text][@name="+a+"]").val(b)}DestroySuggestDiv()}function listenEvent(a,c,b){a=window.event||a;iKeyCode=a.keyCode;switch(iKeyCode){case 38:moveUp(c,b);break;case 40:moveDown(c,b);break;case 13:DestroySuggestDiv();if(b=="ordinary"){RunSearch();return false}if(b=="advanced"||b=="advanced1"){document.forms[0].submit();return false}if(b=="lookup"){return false}break;case 9:DestroySuggestDiv();break}return true}function searchSuggest(a,c,b){a=window.event||a;var e=a.keyCode;var d=[8,32,46,191,192,222];switch(b){case"ordinary":fieldForSearch=$("select#ctlSearchField").val();break;case"advanced":fieldForSearch=c.name.substring(6);break;case"advanced1":fieldForSearch=c.name.substring(7);break}if(((e>=65)&&(e<=90))||((e>=48)&&(e<=57))||((e>=96)&&(e<=111))||d.inArray(e,true)){cur=-1;$.get(SUGGEST_TABLE,{searchFor:myEncode(c.value),searchField:myEncode(fieldForSearch),rndVal:(new Date().getTime())},function(f){$("#search_suggest").html("");var h=f.split("\n");for(i=0,j=0;i<h.length-1;i++,j++){var g='<div id="suggestDiv'+i+'" style="cursor:pointer;" onmouseover="suggestOver(this);" ';g+='onmouseout="suggestOut(this);" ';g+="onclick=\"setSearch('"+c.name+"',suggestValues["+j+"].replace(/\\<(\\/b|b)\\>/gi,''));\" ";g+='class="suggest_link">'+h[i]+"</div>";$(g).appendTo("#search_suggest");suggestValues[j]=h[i]}if(f){$("select").each(function(){if(PtInBox(this)){selectsToHide[selectsToHide.length]=this;this.style.visibility="hidden"}});$("#search_suggest").css({visibility:"visible"})}else{DestroySuggestDiv()}})}setLyr(c,"search_suggest")}function showHideLookupError(a){if(isLookupError){$(a).addClass("highlight")}else{$(a).removeClass("highlight")}}function lookupSuggest(b,d,a,c){if(c!=""){c="_"+c}b=window.event||b;iKeyCode=b.keyCode;var f=$("#"+d.name.substring(8)+c)[0];if(((iKeyCode>=65)&&(iKeyCode<=90))||((iKeyCode>=48)&&(iKeyCode<=57))||((iKeyCode>=96)&&(iKeyCode<=105))||(iKeyCode==8)||(iKeyCode==46)||(iKeyCode==32)||(iKeyCode==222)){cur=-1;if(d.value==""){DestroySuggestDiv();isLookupError=false;$(d).removeClass("highlight");$(f).val("");$(f).change();return}var g="";if($(d).attr("categoryId")!=undefined){var e=$("#value_"+$(d).attr("categoryId"));if($(e).length){g=$(e).val()}}$.get(SUGGEST_LOOKUP_TABLE,{searchFor:myEncode(d.value),searchField:myEncode(d.name.substring(14)),lookupValue:myEncode(a),category:g,rndVal:(new Date().getTime())},function(h){$("#search_suggest").html("");var l=h.split("\n");$.each(l,function(m,o){l[m]=unescape(o)});if(l.inArray(d.value,false)){isLookupError=false;$(d).removeClass("highlight");$.each(l,function(m,o){if((o.toLowerCase()==d.value.toLowerCase())&&($(f).val()!=l[m-1])){$(f).val(l[m-1]);$(f).change()}})}else{isLookupError=true;if(!isSetFocus){$(d).addClass("highlight")}}for(i=0,j=0;i<l.length-1;i=i+2,j++){var k='<div id="suggestDiv'+i+'" style="cursor:pointer;" onmouseover="javascript:suggestOver(this);" ';k+='onmouseout="javascript:suggestOut(this);" ';k+="onclick=\"javascript:setSearch('"+d.name+"',suggestValues["+j+"],'lookup','"+l[i]+"','"+c+"');\" ";k+='class="suggest_link">'+l[i+1]+"</div>";$(k).appendTo("#search_suggest");suggestValues[j]=l[i+1];lookupValues[j]=l[i]}if(h){$("select").each(function(){if(PtInBox(this)){selectsToHide[selectsToHide.length]=this;this.style.visibility="hidden"}});if(isSetFocus){$("#search_suggest").css({visibility:"visible"})}}else{DestroySuggestDiv()}})}setLyr(d,"search_suggest")}function preloadSelectContent(a,e,d,c){if(c!=""){c="_"+c}if($("#"+e+c)[0].tagName=="SELECT"){$("#"+e+c).get(0).options[0]=new Option(TEXT_PLEASE_SELECT,"");var f=a.split("\n");var b=0;for(i=0,j=0;i<f.length-1;i=i+2,j++){$("#"+e+c).get(0).options[j+1]=new Option(unescape(f[i+1]),unescape(f[i]));if(unescape(f[i])==d){b=j+1}}$("#"+e+c).get(0).selectedIndex=b;if(j==1){$("#"+e+c).get(0).selectedIndex=1}}else{if(a.length){var f=a.split("\n");if(f.length==3){$("#"+e+c).val(unescape(f[0]));$("#display_"+e+c).val(unescape(f[1]))}}}}function loadSelectContent(b,a,c){if(c!=""){c="_"+c}$.get(AUTOCOMPLETE_TABLE,{field:myEncode(a),value:myEncode($("#value_"+b+c).val()),type:$("#value_"+a+c)[0].tagName},function(d){if($("#value_"+a+c)[0].tagName=="SELECT"){$("#value_"+a+c).html('<option value="">'+TEXT_PLEASE_SELECT+"</option>");var e=d.split("\n");for(i=0,j=0;i<e.length-1;i=i+2,j++){$("#value_"+a+c).get(0).options[j+1]=new Option(unescape(e[i+1]),unescape(e[i]))}$("#value_"+a+c).get(0).selectedIndex=0;if(j==1){$("#value_"+a+c).get(0).selectedIndex=1}$("#value_"+a+c)[0].onchange()}else{$("#value_"+a+c).val("");$("#display_value_"+a+c).val("");if(d.length){var e=d.split("\n");if(e.length==3){$("#value_"+a+c).val(unescape(e[0]));$("#display_value_"+a+c).val(unescape(e[1]))}}}})};
