
var http=CreateRequestObject();function CreateRequestObject()
{var ro;var browser=navigator.appName;if(browser=="Microsoft Internet Explorer")
ro=new ActiveXObject("Microsoft.XMLHTTP");else
ro=new XMLHttpRequest();return ro;}
function AjaxExecute(app_name,pagelet,type,command,params,node_to_serialize)
{var ndx1;var ndx2=0;var code;var result;var counter=0;var lastNdx1=-1;var post_object=new Object();while((ndx1=params.indexOf('^~'))!=-1)
{if((ndx2=params.indexOf('~^',ndx1))!=-1)
{field_id=params.substring(ndx1+2,ndx2);field_value=GetFieldValue(field_id);params=params.replace('^~'+field_id+'~^',field_value);}
if(lastNdx1==ndx1)
break;lastNdx1=ndx1;}
var arr_params=params.split('#');for(var i=0;i<arr_params.length;i++)
{var arr_temp=arr_params[i].split('=>');post_object[arr_temp[0]]=arr_temp[1];}
if(node_to_serialize)
post_object=SerializeForm(node_to_serialize,post_object);var post_string=encodeURIComponent(post_object.toJSONString());var query_string='app_name='+encodeURIComponent(app_name)+'&pagelet='+encodeURIComponent(pagelet)+'&type='+encodeURIComponent(type)+'&command='+encodeURIComponent(command)+'&params='+post_string;setTimeout('AjaxSendRequest( "'+query_string+'" );',15);}
function AjaxSendRequest(query_string)
{http.open('post',VIRTUAL_LIB_PHP_HTML+'AjaxMainContainer.php');http.onreadystatechange=HandleResponse;http.setRequestHeader('Content-Type','application/x-www-form-urlencoded');http.send(query_string);}
function HandleResponse()
{if(http.readyState==4)
{try
{eval(http.responseText);}
catch(err)
{SystemError('There was a server error');TRACE(err.toString()+' => '+err.description);}}}
function GetFieldValue(field_id)
{var field=document.getElementById(field_id);if(!field)
field=document.getElementById(field_id+'_container');if(!field)
return'';switch(field.tagName.toLowerCase())
{case'input':switch(field.type)
{case'text':case'hidden':case'password':return field.value;case'checkbox':case'radio':if(field.checked)
return field.value;else
return'';}
break;case'select':if(field.selectedIndex==-1)
return'';else
return field.options[field.selectedIndex].value;case'textarea':return field.value;case'table':case'div':var arr_inputs=field.getElementsByTagName('input');if(arr_inputs.length<=0)
return'';switch(arr_inputs[0].type)
{case'checkbox':var arr_selected=Array();for(var j=0;j<arr_inputs.length;j++)
{if(arr_inputs[j].checked)
arr_selected.push(arr_inputs[j].value);}
return arr_selected;case'radio':for(var j=0;j<arr_inputs.length;j++)
{if(arr_inputs[j].checked)
return arr_inputs[j].value;}
return'';}
return'';}
return'';}
function SerializeForm(node,post_object)
{if(!node||!node.tagName)
return post_object;var tag_name=node.tagName.toLowerCase();var form_elements=Array('input','select','textarea');if(form_elements.in_array(tag_name)&&(tag_name!='input'||node.type=='text'))
post_object[node.id]=GetFieldValue(node.id);if(node.id.substr(-10)=='_container')
post_object[node.id.replace(/_container/,'')]=GetFieldValue(node.id);else
{for(var i=0;i<node.childNodes.length;i++)
post_object=SerializeForm(node.childNodes[i],post_object);}
return post_object;}
function DDLHighlightSuggestion(oTarget)
{suggestions_ctrl=oTarget.parentNode;for(var i=0;i<suggestions_ctrl.childNodes.length;i++)
{if(suggestions_ctrl.childNodes[i].className=='current')
suggestions_ctrl.childNodes[i].className='';else if(suggestions_ctrl.childNodes[i]==oTarget)
{oTarget.className='current';selected_suggestion=i;}}}
function DDLIterateSuggestions(oEvent,change)
{suggestions_ctrl=document.getElementById(oEvent.target.id+'_suggestions');suggestions_ctrl.setAttribute('selected_suggestion',suggestions_ctrl.getAttribute('selected_suggestion')*1+change);if(suggestions_ctrl.getAttribute('selected_suggestion')>=0&&suggestions_ctrl.getAttribute('selected_suggestion')<suggestions_ctrl.childNodes.length)
DDLHighlightSuggestion(suggestions_ctrl.childNodes[suggestions_ctrl.getAttribute('selected_suggestion')]);else
suggestions_ctrl.setAttribute('selected_suggestion',suggestions_ctrl.getAttribute('selected_suggestion')*1-change);}
function DDLOnBlur(ctrl_id,wipe_styles)
{document.getElementById(ctrl_id+'_suggestions').style.display='none';var txt_box=document.getElementById(ctrl_id);/*if(typeof(wipe_styles)!='boolean'||wipe_styles==true)
txt_box.style.background=txt_box.style.borderColor=txt_box.style.borderWidth=txt_box.style.borderStyle='';*/}
function DDLOnKeyDown(oEvent)
{oEvent=getCommonEvent(oEvent);switch(oEvent.keyCode)
{case 38:DDLIterateSuggestions(oEvent,-1);break;case 40:DDLIterateSuggestions(oEvent,1);break;case 13:var suggestions_ctrl=document.getElementById(oEvent.target.id+'_suggestions');var suggested_node=suggestions_ctrl.childNodes[suggestions_ctrl.getAttribute('selected_suggestion')];if(!suggested_node)
suggested_node=suggestions_ctrl.childNodes[0];if(suggested_node)
oEvent.target.value=suggested_node.innerHTML;DDLOnBlur(oEvent.target.id);if(oEvent.target.onchange)
oEvent.target.onchange(oEvent);return false;}
return true;}
function DDLOnKeyUp(oEvent)
{oEvent=getCommonEvent(oEvent);if((oEvent.keyCode<32&&oEvent.keyCode!=8)||(oEvent.keyCode>=33&&oEvent.keyCode<=45)||(oEvent.keyCode>=112&&oEvent.keyCode<=123))
return;if(oEvent.target.getAttribute('InAjax')==1)
return;oEvent.target.setAttribute('InAjax',1);eval(oEvent.target.getAttribute('AjaxCallback'));}
function DDLSetup(ctrl_id)
{if(window_loaded!=true)
{setTimeout("DDLSetup( '"+ctrl_id+"' );",100);return;}
var txt_box=document.getElementById(ctrl_id);var txt_box_pos=Viewport.getElementBoundingRect(txt_box);var suggestions_ctrl=document.createElement('span');suggestions_ctrl.id=ctrl_id+'_suggestions';suggestions_ctrl.className='suggestions';suggestions_ctrl.style.display='none';suggestions_ctrl.style.zIndex=500;suggestions_ctrl.style.position='absolute';suggestions_ctrl.style.top=txt_box_pos.y+txt_box_pos.height+'px';suggestions_ctrl.style.left=txt_box_pos.x+'px';suggestions_ctrl.setAttribute('selected_suggestion',-1);document.body.appendChild(suggestions_ctrl);suggestions_ctrl.onmousedown=suggestions_ctrl.onmouseup=suggestions_ctrl.onmouseover=function(oEvent)
{oEvent=getCommonEvent(oEvent);if(oEvent.target.tagName.toLowerCase()=='span')
return;var suggestions_ctrl=oEvent.target.parentNode;var txt_box=document.getElementById(suggestions_ctrl.id.replace(/_suggestions/,''));if(oEvent.type=="mousedown")
{txt_box.value=oEvent.target.innerHTML;DDLOnBlur(txt_box.id);if(txt_box.onchange)
txt_box.onchange(oEvent);}
else if(oEvent.type=="mouseover")
{DDLHighlightSuggestion(oEvent.target);}
else
{txt_box.focus();}};}
function DDLShowSuggestions(ctrl_id,obj_selections,key)
{var txt_box=document.getElementById(ctrl_id);var txt_box_pos=Viewport.getElementBoundingRect(txt_box);var suggestions_ctrl=document.getElementById(ctrl_id+'_suggestions');var arr_suggestions=[];txt_box.removeAttribute('InAjax');for(prop in obj_selections)
{if(typeof(obj_selections[prop])=='function')
continue;if(obj_selections[prop][key].substring(0,obj_selections[prop][key].length)==obj_selections[prop][key])
arr_suggestions.push(obj_selections[prop][key]);}
selected_suggestion=-1;if(arr_suggestions.length<1)
{/*txt_box.style.border='1px solid #cc0000';txt_box.style.background='#CCAEAE';*/return DDLOnBlur(ctrl_id,false);}
else
{/*txt_box.style.border='1px solid #008B00';txt_box.style.background='#C3DFC3';*/}
suggestions_ctrl.innerHTML='';for(var i=0;i<arr_suggestions.length;i++)
{var div=document.createElement('div');div.innerHTML=arr_suggestions[i];suggestions_ctrl.appendChild(div);}
suggestions_ctrl.style.width='';if(txt_box_pos.width-10>=suggestions_ctrl.offsetWidth)
suggestions_ctrl.style.width=txt_box_pos.width+'px';suggestions_ctrl.style.display='inline';}
function IncludeJSScript(script_filename)
{var html_doc=document.getElementsByTagName('head').item(0);var js=document.createElement('script');js.setAttribute('language','javascript');js.setAttribute('type','text/javascript');js.setAttribute('src',script_filename);html_doc.appendChild(js);}
function Highlight(ctrl_id,start_hex,time)
{if(!start_hex)
start_hex='FFFD6C';if(!time)
time=2.5;num_steps=Math.floor(time*1000/50);arr_hex_codes=GetFadeColorArray(start_hex,'FFFFFF',num_steps);for(var i=0;i<arr_hex_codes.length;i++)
setTimeout("HighlightElementBackground( document.getElementById( '"+ctrl_id+"' ), '"+arr_hex_codes[i]+"' );",i*50);}
function HighlightElementBackground(node,hex_code)
{try
{node.style.background='#'+hex_code;}
catch(err)
{;}
var arr_tds=node.getElementsByTagName('td');for(var i=0;i<arr_tds.length;i++)
arr_tds[i].style.background='#'+hex_code;}
function GetFadeColorArray(start_hex,end_hex,num_steps)
{var arr_hex_colors=[];var he="0123456789abcdef";var c=he.split('');var c1=start_hex.toLowerCase().split('');var c2=end_hex.toLowerCase().split('');arr_hex_colors[0]=start_hex;for(n=1;n<num_steps;n++)
{var red=((he.indexOf(c1[0])*16)+he.indexOf(c1[1]))+(n*(((he.indexOf(c2[0])*16)+he.indexOf(c2[1]))-((he.indexOf(c1[0])*16)+he.indexOf(c1[1])))/num_steps);var green=((he.indexOf(c1[2])*16)+he.indexOf(c1[3]))+(n*(((he.indexOf(c2[2])*16)+he.indexOf(c2[3]))-((he.indexOf(c1[2])*16)+he.indexOf(c1[3])))/num_steps);var blue=((he.indexOf(c1[4])*16)+he.indexOf(c1[5]))+(n*(((he.indexOf(c2[4])*16)+he.indexOf(c2[5]))-((he.indexOf(c1[4])*16)+he.indexOf(c1[5])))/num_steps);arr_hex_colors[n]=String(c[parseInt(red/16)]+c[parseInt(red-(parseInt(red/16)*16))]+c[parseInt(green/16)]+c[parseInt(green-(parseInt(green/16)*16))]+c[parseInt(blue/16)]+c[parseInt(blue-(parseInt(blue/16)*16))]).toUpperCase();}
arr_hex_colors[arr_hex_colors.length]=end_hex;return arr_hex_colors;}
var REQUEST_TYPE_CLEAR=1;var REQUEST_TYPE_APPEND=2;function ClearSelectBox(source)
{var sel=null;if(typeof(source)=='string')
sel=document.getElementById(source);else if(typeof(source)=='object')
sel=source;for(var i=sel.options.length-1;i>=0;i--)
sel.options[i]=null;}
function PopulateSelectBox(source_id,value_field,text_field,arr_rows,include_dummy,request_type)
{if(!request_type)
request_type=REQUEST_TYPE_CLEAR;var source_ctrl=document.getElementById(source_id);if(!source_ctrl)
{TRACE('Could not find '+source_id);return;}
if(request_type!=REQUEST_TYPE_APPEND)
ClearSelectBox(source_ctrl);if(include_dummy)
{var dummy_row=new Array();dummy_row[text_field]=include_dummy;dummy_row[value_field]='';arr_rows=[dummy_row].concat(arr_rows);}
for(key_row in arr_rows)
{var row=arr_rows[key_row];if(typeof(row)=='function')
continue;if(typeof(row)!='array'&&typeof(row)!='object')
row=new Array(row);var first_value=null;source_ctrl.options[source_ctrl.options.length]=new Option(row[text_field],row[value_field]);}
try
{hide_progress(true);}
catch(x){}}
