
/********************************************************************
	Filename.......: general.js
	Purpose........: stores all common & reusable javascripts
*********************************************************************/

var xmlHttp=false; try { xmlHttp = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e){ try { xmlHttp = new ActiveXObject("Microsoft.XMLHTTP"); } catch (E){ xmlHttp = false; }} if (!xmlHttp && typeof XMLHttpRequest!='undefined'){ xmlHttp = new XMLHttpRequest(); } function xmlHttpSend(url, val, call_back_func, method){ data = eval(call_back_func+"(val);"); xmlHttp.open(method, url, false); xmlHttp.setRequestHeader('Content-Type', 'text/html'); xmlHttp.send(data); } function xmlHttpGet(call_back_func){ eval(call_back_func+"(xmlHttp.responseText);"); } var aSyncXml= false; var aSyncQueue= new Array(); function aSyncSend(url, val, get_callback, method, do_callback){ if (window.XMLHttpRequest){ aSyncXml = new XMLHttpRequest(); } else if (window.ActiveXObject){ aSyncXml = new ActiveXObject("Microsoft.XMLHTTP"); } if (aSyncXml){ data = false; if (get_callback != ''){ data = eval(get_callback+"(val);"); } else data = val; if (do_callback == null){} else if (do_callback != ''){ eval('aSyncXml.onreadystatechange = '+ do_callback +';'); } else aSyncXml.onreadystatechange = ret_callback; aSyncXml.open(method, url, true); aSyncXml.setRequestHeader('Content-Type', 'text/html'); if (data) aSyncXml.send(data); else aSyncXml.send(null); } } function autoShowHide(id){ toggle = document.getElementById(id).style.display; document.getElementById(id).style.display = ((toggle == 'none')?'':'none');} function autoShowProgTbl(str){ if (!document.getElementById('prog_tbl')) return; obj = document.getElementById('prog_tbl').style; tmp = obj.display; aux = aSyncQueue.length; dat = document.getElementById('prog_txt'); if (str.length){ obj.display = ''; dat.innerHTML = str;  autoShowAlertTbl(''); } else { obj.display = 'none'; dat.innerHTML = ''; } } function autoShowAlertTbl(str){ if (!document.getElementById('alert_tbl')) return; obj = document.getElementById('alert_tbl').style; if (str == ''){ obj.display = 'none'; } else { tmp = document.getElementById('alert_txt'); tmp.innerHTML = urldecode(str); obj.display = ''; }} function verifyIP(ip){ errorString = ''; var ipPattern = /^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/; var ipArray = ip.match(ipPattern); if ((ip == "0.0.0.0") || (ip == "255.255.255.255")){ alert(ip+' is a special IP address and cannot be used here.'); return false; } if (ipArray == null){ alert(ip+' is not a valid IP address.'); return false; } for (i=1; i<ipArray.length; i++){ if (ipArray[i] > 255){ alert(ip+' is not a valid IP address.'); return false; } if ((i == 0) && (ipArray[i] > 255)){ alert(ip+' is a special IP address and cannot be used here.'); return false; }}return true; } function openPopUp(url, name, features){ window.open(url, name, features); } function onEnter(func){  if ((event.which == 13) || (event.keyCode == 13)){ document.changes=false; eval('if (window.'+func+') '+func+'();'); } return; } function showStatus(str){ status = str; return true; } function preLoadArrow(up, down){ var stash = document; stash.myTool = new Array(); stash.myTool[0] = new Image(); stash.myTool[0].src = up; stash.myTool[1] = new Image(); stash.myTool[1].src = down; } function swapArrow(img){ pic = document.getElementById(img); pic.src = (pic.src == stash.myPic[0].src) ? stash.myPic[1].src : stash.myPic[0].src; } function swapOptions(fromID, toID){ if (!document.getElementById(fromID)) return; if (!document.getElementById(toID)) return; var fr = document.getElementById(fromID); var to = document.getElementById(toID); if (!fr.length){ alert('The list is empty.'); return; } for (var i=0; i<fr.options.length;){ if (fr.options[i].selected && fr.options[i].value){ newOption = new Option(fr.options[i].text, fr.options[i].value, false, false); to.options[to.options.length] = newOption; fr.remove(i); } else i++; }} function swapSortOptions(fromID, toID){ if (!document.getElementById(fromID)) return false; else fr = document.getElementById(fromID); if (!document.getElementById(toID)) return false; else to = document.getElementById(toID); if (!fr.length){ alert('The list is empty.'); return; } for (i=0; i<fr.length;){ if (fr.options[i].selected && fr.options[i].value){ newOption = new Option(fr.options[i].text, fr.options[i].value, false, false); to.options[to.options.length] = newOption; fr.remove(i); } else i++; } sortSelect(fr); sortSelect(to); } function copyOptions(fromID, toID){ if (!document.getElementById(fromID)) return false; else fr = document.getElementById(fromID); if (!document.getElementById(toID)) return false; else to = document.getElementById(toID); if (!fr.length){ alert('The list is empty.'); return; } for (i=0; i<fr.length; i++){ if (fr.options[i].selected && fr.options[i].value){ newOption = new Option(fr.options[i].text, fr.options[i].value, false, false); to.options[to.options.length] = newOption; }} } function removeOptions(fromID){ if (!document.getElementById(fromID)) return false; else fr = document.getElementById(fromID); for (i=0; i<fr.length; i++){ if (fr.options[i].selected){ fr.remove(i); }} }



	function setCookie(name, value, days){
	        if (days){ var date = new Date(); date.setTime(date.getTime()+(days*24*60*60*1000));
	        var expires = "; expires="+date.toGMTString(); } else expires = "";
	        document.cookie = name+"="+value+expires+"; path=/";
	}
	function getCookie(name){
	        var nameEQ = name + "="; var ca = document.cookie.split(';');
	        for (var i=0;i < ca.length;i++){ var c = ca[i];
	        while (c.charAt(0)==' ') c = c.substring(1,c.length); if (c.indexOf(nameEQ) == 0)
	        return c.substring(nameEQ.length,c.length); } return null;
	}
	function killCookie (name, path, domain){
	        if (getCookie(name)){ document.cookie = name + "=" + ((path) ? "; path=" + path : "/") +
	        ((domain) ? "; domain=" + domain : "") + "; expires=Thu, 01-Jan-70 00:00:01 GMT"; }
	}


	function trim(str){
	        tmp = str.replace(/^\s+|\s+$/, '');
	        return tmp;
	}
	function autoFinishLoad(){
		if (!document.getElementById('loading')) return;
		var obj = document.getElementById('loading');
		obj.style.display = 'none';
	}
	function autoResizeIfr(){
	        if (window.name != 'rightFrame') return; if (!document.getElementById('ifr')) return;
	        tmp = document.body.clientHeight; obj = document.getElementById('ifr');
	        obj.height = tmp - 173; }
	function autoResizePayload(id){
	        if (window.name != 'rightFrame') return; if (!document.getElementById(id)) return;
	        obj = document.getElementById(id); x = obj.parentElement.offsetWidth;
	        obj.style.width = x * .98;
	}

	/* - Public - check and uncheck a list of checkboxes
	Added on Sunday, January 09, 2005 5:16 PM
	Verified working on Sunday, January 09, 2005 5:16 PM
	*/
	function swapChecks(f, x){
	        for (i=0; i<f.elements.length; i++){ if (f.elements[i].type != "checkbox") continue;
	        f.elements[i].checked = (x.checked) ? true : false; }
	}
	function swapChecksQuick(n, x){
	        tmp = document.getElementsByName(n); for (i=0; i<tmp.length; i++){
	        if (tmp[i].type != "checkbox") continue; tmp[i].checked = (x.checked) ? true : false; }
	}


	/* - Public - move <option> up or down
	Added on Thursday, October 21, 2004 12:42 PM
	Verified working on Sunday, November 28, 2004 5:16 AM
	*/
	function moveOptions(movement, target){
	        if (!document.getElementById(target)) return false; else obj = document.getElementById(target);
	        if (obj.length < 1) return false; block = new Array(); for (i=0; i<obj.length; i++)
	        if (obj.options[i].selected) block.push(i); if (block.length <= 0) return false;
	        function flt(idx, size){ pull = new Option(obj.options[idx-1].text, obj.options[idx-1].value, false, false);
	        obj.remove(idx-1); obj.add(pull, idx+size-1); } function sink(idx, size){
	        pull = new Option(obj.options[idx+1].text, obj.options[idx+1].value, false, false);
	        obj.remove(idx+1); obj.add(pull, idx-size+1); } switch (movement){ case 'up' :
	        if (block[0] > 0) flt(block[0], block.length); break; case 'down' :
	        if (block[block.length-1] < obj.length-1) sink(block[block.length-1], block.length); break; }
	}


	/* - Public - convert text/value of <option> to <hidden> or <input text>
	Added on Thursday, October 21, 2004 1:08 PM
	Verified working on Sunday, November 28, 2004 5:16 AM
	*/
	function implodeOptions(fromID, toID, attribute){
	        if (!document.getElementById(fromID)) return false; else fr = document.getElementById(fromID);
	        if (!document.getElementById(toID)) return false; else to = document.getElementById(toID);
	        var tmp = new Array(); switch (attribute){ case 'text' :
	        for (i=0; i<fr.length; i++) tmp.push(fr.options[i].text); break; case 'value' :
	        for (i=0; i<fr.length; i++) tmp.push(fr.options[i].value); break; } to.value = tmp.join(",");
	        return true;
	}


	/* - Public - option array search
	Added on Thursday, December 23, 2004 10:25 AM
	Verified working on Thursday, December 23, 2004 10:25 AM
	*/
	function optionsLookUp(haystack, needle){
	        if (!document.getElementById(haystack)) return false;
	        else x = document.getElementById(haystack); for (q=0; q<x.length; q++)
	        if (x.options[q].value == needle) return true; return false;
	}
	function parseKeyCode(x){
	        if (x == 8) return false; if (x == 37) return false;
	        if (x == 39) return false; if (x == 16) return false; return true;
	}


	/* - Public - Highlight grid row when mouse hover over
	Added on Saturday, July 31, 2004 9:25 AM
	Verified working on Thursday, December 23, 2004 10:25 AM
	*/
	function setBGColor(theRow, thePointerColor){
	        if (typeof(document.getElementsByTagName) != 'undefined'){
	        theCells = theRow.getElementsByTagName('td'); } else if (typeof(theRow.cells) != 'undefined'){
	        theCells = theRow.cells; } else return; theCells = theRow.cells;
	        var rowCellsCnt = theCells.length; for (c = 0; c < rowCellsCnt; c++){
	        if (theCells[c].style.backgroundColor == thePointerColor){
	        theCells[c].style.backgroundColor = ''; } else
	        theCells[c].style.backgroundColor = thePointerColor; }
	}


	/* - Public - show and collapse field history span using aSyncSend
	Moved on Sunday, June 05, 2005 10:46 PM
	*/
	function showHistory(ranID, field, id, base, multi){
	        var tmp, url, obj; /*tmp = 'ss_'+ranID;
	        if (!document.getElementById(tmp)) return;
	        obj = document.getElementById(tmp);

	        if (obj.uid != field) obj.uid = field
	        else { obj.innerHTML = ''; obj.uid = ''; return; }*/

	        if (multi == "1"){
	                tmp = field.split('@');
	                id = document.getElementById(tmp[0]+"@ID").value;
	        }
	        url = base +'Scripts/reqFieldHistory.php?field='+
	              field +'&formRowID='+ id +'&ranID='+ ranID;
	        jax_send(url, '', 'POST', 'printHistory');
	}
	function printHistory(data){
	        data = data.split("##"); var x = data[1];//x = 'ss_'+data[1];
	        if (!document.getElementById(x)) return;
	        var obj = document.getElementById(x);

	        if (typeof(data[0]) == 'undefined'){ alert(x + 'not found'); return; }
	        if (obj.innerHTML == '') obj.innerHTML = '<br />'+urldecode(data[0])+'<br />';
	        else obj.innerHTML = ''; AllComboInit();
	}


	/* - Public - ssn display formatter (onKeyUp)
	Added on Sunday, January 09, 2004 10:43 AM
	*/
	function ssnDash(obj){
	        if (obj.value == '') return; var tmp = obj.value; re = /(\-)|( )/g;
	        tmp = tmp.replace(re, ''); aux = tmp.substring(0,3)+'-'+tmp.substring(3,5)+
	        '-'+tmp.substr(5, 9); obj.value = aux.substring(0, 11);
	}


	/* - Public - phoneNum display formatter (onKeyUp)
	Added on Sunday, January 09, 2004 10:43 AM
	*/
	function phoneDash(obj){
	        if (obj.value == '') return; var tmp = obj.value; re = /(\()|(\))|(\-)|( )|e|x|t|:|/gi;
	        tmp = tmp.replace(re, ''); if (tmp.substring(10,15) != "") obj.value = '('+tmp.substring(0,3)+
	        ') '+tmp.substring(3,6)+'-'+tmp.substring(6,10)+' Ext: '+tmp.substring(10,15);
	        else obj.value = '('+tmp.substring(0,3)+') '+tmp.substring(3,6)+'-'+tmp.substring(6,10);
	}


	/* - Public - zip display formatter (onKeyUp)
	Added on Sunday, January 09, 2004 10:43 AM
	*/
	function zipDash(obj){
	        if (obj.value == '') return; var tmp = obj.value; re = /(\-)|( )/g;
	        tmp = tmp.replace(re, ''); if(tmp.length > 5)
	        obj.value = tmp.substring(0,5)+'-'+tmp.substr(5, 4); else
	        obj.value = tmp.substring(0,5);
	}


	/* - Public - date display formatter (onKeyUp)
	Added on Sunday, January 09, 2004 10:43 AM
	*/
	function dateDash(obj){
	        var tmp = obj.value; re = /(\/)|( )/g; tmp = tmp.replace(re, '');
	        obj.value = tmp.substring(0,2)+'/'+tmp.substring(2,4)+'/'+tmp.substr(4);
	}
	function timeDash(obj){
	        if (parseKeyCode(event.keyCode)){ var tmp = obj.value; re = /(\:)|( )/g;
	        tmp = tmp.replace(re, ''); switch (tmp.length){
	        case 2: obj.value = tmp+':'; break;
	        case 3: obj.value = tmp.substring(0,2)+':'+tmp.substr(2); break;
	        case 4: obj.value = tmp.substring(0,2)+':'+tmp.substr(2)+' am'; break; }}
	}


	/* - datetime form function controller
	Added on Tuesday , Spetember 27, 2004 4:02 PM
	*/
	function upd_tick(obj, m, ampm, d){
		var h, n, y;
		m = m.split(':'); d = d.split('/');
                h = parseInt(m[0]); m = parseInt(m[1]);
                y = d[2]; n = d[0]; d = d[1];

                if ((ampm == 'PM') && (h < 12)) h += 12;
                if ((ampm == 'AM') && (h >= 12)) h -= 12;
                if (h < 10) h = '0'+h.toString();
                if (m < 10) m = '0'+m.toString();

                obj.value = (isNaN(y)) ? '0000-00-00 00:00:00' :
                y+'-'+n+'-'+d+' '+h+':'+m+':00';
	}
	function upd_date(obj){
		var id=obj.uid, tar, rdn, h, m;
		if (!document.getElementById(id)) return;
		rdn = obj.id.split('_'); rdn = rdn[1];
		tar = document.getElementById(id);
		var ampm = document.getElementById('ampm_'+rdn);
		var time = document.getElementById('time_'+rdn);
		upd_tick(tar, time.value, ampm.value, obj.value);
		tar.onchange();
	}
	function upd_time(obj){
		var id=obj.uid, tar, rdn, h, m;
		if (!document.getElementById(id)) return;
		rdn = obj.id.split('_'); rdn = rdn[1];
		tar = document.getElementById(id);
                var ampm = document.getElementById('ampm_'+rdn);
                var day = document.getElementById('date_'+rdn);
                upd_tick(tar, obj.value, ampm.value, day.value);
	}
	function upd_ampm(obj){
		var id=obj.uid, tar, rdn, h, m;
		if (!document.getElementById(id)) return;
		rdn = obj.id.split('_'); rdn = rdn[1];
		tar = document.getElementById(id);
		var time = document.getElementById('time_'+rdn);
		var day = document.getElementById('date_'+rdn);
                upd_tick(tar, time.value, obj.value, day.value);
	}




function changeUnsave(){ changes = true; }
function changeFlag(){ changes = false; }

function gridCntOver(obj){obj.className = 'gridCnt-over'; }
function gridCntOut(obj){obj.className = 'gridCnt-default'; }
function gridHdrOver(obj, str){ obj.className = 'hdr_over'; if (str!=undefined) { window.status = str; }}
function gridHdrOut(obj){ obj.className = window.status = ''; }
function gridCntClick(obj){ tmp = obj.className; obj.className = (tmp == 'clik_row') ? '' : 'clik_row'; }
function contactDisplayOut(obj){obj.className = 'contactDisplayOut'; }
function contactDisplayOver(obj){obj.className = 'contactDisplayOver'; }


	function alert_focus(obj){
	        obj.focus(); if(document.all || document.getElementByID){
	        obj.style.background = "#E5F3FC"; } return false;
	}
	function chkUnique(){
	        url = baseURL+ 'Scripts/reqUnique.php';
	        xmlHttpSend(url, '', 'validate', 'POST');

	        if (xmlHttp.responseText){
	                data = xmlHttp.responseText;
	                data = data.split('##');
	                alert_focus(document.getElementById(data[1]));
	        alert(data[0]); return true; }
	        else return false;
	}
	function validate(){
	        obj= new Array();
	        elems= new Array();
	        elems= document.forms[0].elements;
	        for(i=0;i<elems.length;i++){
	        obj[i]= elems[i].name + " = "+ elems[i].value; }
	        words= obj.join(","); return words;
	}
	function chkDuplicateLoanNumber(base){
	        url = base+"Scripts/reqLoanNumberDuplicate.php";
	        xmlHttpSend(url, '', 'validateLoanNumberDuplicate' , 'POST');
	        if (xmlHttp.responseText){
	        alert(xmlHttp.responseText); return true; }
	        else return false;
	}
	function validateLoanNumberDuplicate(){
	        value = document.getElementById("loan@number").value;
	        data = "loan@number="+value;
	        return data;
	}
	function newInboxEmail(num){
		if (!parent.menuFrame) return; var obj = parent.menuFrame;
		if (!obj.document.getElementById('newInboxemail')) return;
		obj = obj.document.getElementById('newInboxemail');
		obj.innerHTML = (num > 0) ? '('+num+')' : '';
	}



	/* - Public - Validator to ensure all required fields have been filled in.
	Added on Friday, August 19 by Cindy Lai
	*/
	function chkAllRequired(action){
	        // If there are no required fields, just execute the action
	        if (!reqFeil) eval(action);

	        // If there are, check to make sure all required fields are completed
	        else
	        {
	                ret = false;
	                // Split the list of required fields into an array
	                tmp = reqFeil.split(',');

	                // Loop through the array
	                for (i=0; i<tmp.length; i++){

	                        // If the field is empty, alert the user
	                        if (!document.getElementById(tmp[i]).value && !document.getElementById(tmp[i]).alt)
	                        {
	                                ret = true;
	                                alert_focus(document.getElementById(tmp[i]));
	                        }

	                        // If it's a pre-filled field, we reset the 'ret' variable false so that it doesn't display the alert
	                        //if (document.getElementById(tmp[i]).innerText != '')
	                        //{
	                        //      ret = false;
	                        //      document.getElementById(tmp[i]).style.background = "white";
	                        //}
	                }

	                if (ret)
	                {
	                        alert('Please fill in values for the highlighted areas.');
	                }

	                // Now, we can execute the action since all required fields have been filled in.
	                else
	                {
	                        eval(action);
	                }
	        }
	}



function setValue( objName, newValue ) {
obj = document.getElementById( objName );
if (typeof(obj) != 'undefined') {
obj.value = newValue;
}
}


function checkUncheckAll(formName, className, objId) {
 //for frame with label
 if (objId == undefined) {
 op = "uncheck";
 for (i=0,n=formName.elements.length;i<n;i++) {
 if (formName.elements[i].className.indexOf(className) !=-1)
 if (formName.elements[i].checked == false) {
 formName.elements[i].checked = true;
 op = "check";
 }
 }
 if(op == "uncheck"){
 for (i=0,n=formName.elements.length;i<n;i++)
 if (formName.elements[i].className.indexOf(className) !=-1)
 formName.elements[i].checked = false;
 }
 }
 // for frame with checkbox
 else {
 if (objId.checked != true) {
 for (i=0,n=formName.elements.length;i<n;i++) {
 if (formName.elements[i].className.indexOf(className) !=-1)
 formName.elements[i].checked = false;
 }
 }
 else {
 for (i=0,n=formName.elements.length;i<n;i++) {
 if (formName.elements[i].className.indexOf(className) !=-1)
 formName.elements[i].checked = true;
 }
 }
 }
}



function chkEnumCheck(chk, val){
ID = chk.id;
str = ID.substring(3,ID.length);
objName = "hdn" + str;
obj = document.getElementById(objName);
if(obj.value ==''){
obj.value = val;
} else {
obj.value = '';
}

}

function chkCheck(obj, to){
myObj = document.getElementById(to);
myObj.value = (obj.checked) ? obj.value : 0;
}

function checkSave(){
if (changes){
event.returnValue = "Any unsaved changes will be lost."; }
}


function chkRequired(element) {
if (element.value == "") {
 alert('Please fill in value for the *required field.');
 //element.focus();
 //element.selectedIndex();
 element.style.backgroundColor = "#E5F3FC";
return false;
} else {
element.style.backgroundColor = "";
return true;
}
}

function sortSelect(obj) {
var ob = new Array();

for (var i=0; i<obj.options.length; i++) {
ob[ob.length] = new Option( obj.options[i].text, obj.options[i].value, obj.options[i].defaultSelected, obj.options[i].selected) ;
}
if (ob.length==0) { return; }
ob = ob.sort(
function(a,b) {
if ((a.text+"") < (b.text+"")) { return -1; }
if ((a.text+"") > (b.text+"")) { return 1; }
return 0;
}
);

for (var i=0; i<ob.length; i++) {
obj.options[i] = new Option(ob[i].text, ob[i].value, ob[i].defaultSelected, ob[i].selected);
}
}

function chkUserSync(base,type) { if(type == 'employee') url = base + 'Scripts/employeeSync.php'; else if(type == 'contact') url = base + 'Scripts/contactSync.php'; xmlHttpSend(url, '', 'validate', 'POST'); }

function chkUser(base) { url = base + 'Scripts/userExist.php'; xmlHttpSend(url, '', 'validate', 'POST'); if (xmlHttp.responseText){ return confirm('Warning: Sync with user account information has been unchecked. Are you sure you want to remove the user account of this employee/contact?'+ ' Removing user account will not delete this employee/contact from the system.'+ ' This employee/contact will not be able to login into the system after this action.'); } else return true; }


//Create an array
var allPageTags = new Array();
function onFormSubmit() {
//Populate the array with all the page tags
var allPageTags=document.getElementsByTagName("*");

//Cycle through the tags using a for loop
for (i=0; i<allPageTags.length; i++) {

//Pick out the tags with our class name
if (allPageTags[i].className=="chkbox") {
if (allPageTags[i].checked ){
allPageTags[i].value = "y";
} else {
// change to checked and value = "n"
// unchecked will NOT POST !!!
allPageTags[i].value = "n";
allPageTags[i].checked = true;
} // checked
} // chkbox

if (allPageTags[i].className=="list") {
//Manipulate this in whatever way you want
if( allPageTags[i].disabled ) {
// set listbox value = "" if listbox been disabled
allPageTags[i].disabled = false;
allPageTags[i].selectedIndex = 0;
allPageTags[i].options.length = 1;
allPageTags[i].options[0].value = "";
} else {
// set listbox value = array to string if listbox been enabled
obj = allPageTags[i];
var plist1 = "";
for( j=0; j<obj.options.length; j++ ) {
if(obj.options[j].selected)
plist1 += "," + obj.options[j].value;
}
plist1 = plist1.substr(1); // remove the 1st ","
allPageTags[i].selectedIndex = 0;
allPageTags[i].options.length = 1;
allPageTags[i].options[0].value = plist1;
} // disabled
} // list

} // for
}







	/* --------------------------------- Experimental Async JS implementation ---------------------------- */

	var jax_obj = new Array();

	function jax_send(url, val, post_get, do_callback){
	        var idx = jax_obj.length;

	        if (window.XMLHttpRequest){ jax_obj[idx] = new XMLHttpRequest(); } else
	        if (window.ActiveXObject){ jax_obj[idx] = new ActiveXObject("Microsoft.XMLHTTP"); }
	        else { alert('Your browser does not supports xmlhttp.'); return; }

	        var data = false; data = val;
	        var str = "jax_obj[idx].onreadystatechange = function(){ "+
	              "idx = "+idx+"; "+
	              "if (jax_obj[idx].readyState != 4) return; "+
	              "if (jax_obj[idx].status == 2){ alert('jax error. No connection to server.'); return; } "+
	              "if (jax_obj[idx].status >= 600){ /* internet cannot connect - suspressing */ return; } "+
	              "if (jax_obj[idx].status != 200){ alert('jax error. "+
	              "('+jax_obj[idx].status+')'); return; } "+
	              "data = jax_obj[idx].responseText; "+
	              ((do_callback != '') ? do_callback+"(data); " : '')+ "}";

	        if (do_callback == null){} else eval(str);
	        jax_obj[idx].open(post_get, url, true);
	        jax_obj[idx].setRequestHeader('Content-Type', 'text/html');
	        try { if (data) jax_obj[idx].send(data); else jax_obj[idx].send(null); }
	        catch (e){ /* suppress */ }
	}
	function jax_func(func, pid, code){
		var sad, tmp, prt, uid; func = urldecode(func);

                // if function invalid, return silently
                try { sad = new String(func); sad = sad.replace(/[;]/g, '');
		sad = sad.replace(/[\(].*[\)]$/g, ''); tmp = eval('(!window.'+sad+')');
		if (tmp) return; } catch (e){ alert(e.description); }

		tmp = jax_func.arguments;
		prt = (tmp[3]) ? new String(tmp[3]) : '';
		uid = (tmp[4]) ? new String(tmp[4]) : '';


                // if no prt and uid parameter passed-in, do normal
                if (prt+uid == ''){ chkAllRequired(func); return; }

                // request onxx in server
	        if (window.XMLHttpRequest){ jax = new XMLHttpRequest(); } else
	        if (window.ActiveXObject){ jax = new ActiveXObject("Microsoft.XMLHTTP"); }
	        else { alert('Your browser does not supports xmlhttp.');
	        chkAllRequired(func); return; }

                var url, val;
                val = 'pid => '+pid+' ## prt => '+prt+' ## UID => '+uid+' ## code => '+code;
                url = baseURL+ 'Scripts/reqSystem.php?ops=onxx_stop';
                if (document.form2) val = val+' ## '+implode_formElement(document.form2);

	        var str = "jax.onreadystatechange = function(){ if "+
	        	"(jax.readyState != 4) return; if (jax.status == 2){ alert('jax error. "+
	        	"No connection to server.'); return; } if (jax.status >= 600){ /* "+
	        	"internet cannot connect - suspressing */ return; } if (jax.status != 200){ "+
	        	"alert('jax error. ('+jax_obj[idx].status+')'); return; } "+
	                "autoShowProgTbl(''); if (jax_act(jax.responseText)) chkAllRequired('"+func+"'); }";

	        eval(str); jax.open('POST', url, true);
	        jax.setRequestHeader('Content-Type', 'text/html');
	        try { autoShowProgTbl('Checking...'); jax.send(val); } catch (e){ /* suppress */ }
	}
	function implode_formElement(obj){
	        var data = new Array(); for (var i=0; i<obj.elements.length; i++){
	        var tmp = obj.elements[i]; if (tmp.disabled) continue; switch (tmp.type){
	        case 'checkbox': if (tmp.checked && tmp.name){ data.push(tmp.name + ' => '+
	        urlencode(tmp.value)); } break;
	        default: if (tmp.name){ data.push(tmp.name + ' => ' + urlencode(tmp.value)); }
	        }} if (data.length) return data.join(' ## '); else return '';
	}
	function implode_listElement(obj){
	        var data = new Array(); for (var i=0; i<obj.elements.length; i++){
	        if (obj.elements[i].checked) data.push(obj.elements[i].value); }
	        if (data.length) return data.join(', '); else return '';
	}
	function choose_more(name){
	        alert('Please select one or more '+ name +'s.');
	}
	function urlencode(str){
		var sad = new String( escape(str) );
		return sad.replace(/[+]/g, '%2B');
	}
	function urldecode(str){
	        var sad = new String( unescape(str) );
	        return sad.replace(/[+]/g, ' ');
	}
	function jax_answer(){ // obsolete Nov 16, 2005
	        var data = aSyncXml.responseText;
	        if (data.length) return data; else return '';
	}
	function jax_ready(){ // obsolete Nov 16, 2005
	        if (aSyncXml.readyState != 4) return false;
	        if (jax_obj[idx].status == 2){ alert('jax error. No connection to server.'); return false; }
	        if (aSyncXml.status != 200){ alert('jax error. ('+aSyncXml.status +')');
	        return false; } return true;
	}
	function jax_act(data){
		if (data.length < 1) return true; data = data.split(' ## ');
        	for (var i=0; i<data.length; i++){ var tmp = data[i].split(' => '); switch (tmp[0]){
                case 'alert':
                     alert(urldecode(tmp[1])); break;

                case 'function':
                     try { eval(urldecode(tmp[1])); } catch (e){
                     var aux = 'There was an error in the system listener. \nPlease '+
                     'contact your system administrator immediately. \n\n Reason: '+
                     e.description; alert(aux); } break;

                     default: alert(data);
                }}
	}
	function jax_delete(name, url, post_func){
	        if (!window.ifr.document.iframe) return;
	        if (url == '') return;

	        var data = implode_listElement(window.ifr.document.iframe);
	        if (!data){ choose_more(name); return; }
	        var sure = 'Are you sure you want to delete?';

	        if (confirm(sure)){ autoShowProgTbl('Deleting...');
	        jax_send(url, data, 'POST', post_func); } return;
	}
	function jax_enable(name, url, post_func){
	        if (!window.ifr.document.iframe) return;
	        if (url == '') return;

	        var data = implode_listElement(window.ifr.document.iframe);
	        if (!data){ choose_more(name); return; }
	        if (data.indexOf(',') > 0) plural = 's'; else plural = '';
	        var sure = 'Enable the '+ name + plural +'?';

	        if (confirm(sure)){ autoShowProgTbl('Enabling...');
	        jax_send(url, data, 'POST', post_func); } return;
	}
	function jax_disable(name, url, post_func){
	        if (!window.ifr.document.iframe) return;
	        if (url == '') return;

	        var data = implode_listElement(window.ifr.document.iframe);
	        if (!data){ choose_more(name); return; }
	        if (data.indexOf(',') > 0) plural = 's'; else plural = '';
	        var sure = 'Disable the '+ name + plural +'?';

	        if (confirm(sure)){ autoShowProgTbl('Disabling...');
	        jax_send(url, data, 'POST', post_func); } return;
	}
	function jax_duplicate(name, url, post_func){
	        if (!window.ifr.document.iframe) return;
	        if (url == '') return;

	        var data = implode_listElement(window.ifr.document.iframe);
	        if (!data){ choose_more(name); return; }
	        if (data.indexOf(',') > 0) plural = 's'; else plural = '';
	        var sure = 'Duplicate the '+ name + plural +'?';

	        if (confirm(sure)){ autoShowProgTbl('Duplicating...');
	        jax_send(url, data, 'POST', post_func); } return;
	}





/* -------------------------------------- See kit's Calculation -------------------------------*/
// NOTE: calculation using "xmlhttp"... small letter h. For other general usage, we use xmlHttp.

var xmlhttp=false; try { xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e){ try { xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); } catch (E){ xmlhttp = false; }} if (!xmlhttp && typeof XMLHttpRequest!='undefined'){ xmlhttp = new XMLHttpRequest(); }

var calcQ = new Array();
var doneQ =new Array();

function bgProcess(element_id, form, window){
	//element.value = 'Calculating ...';
	//var postMsg = bgData(form);

	if(calcQ.length> 0) {
		calcQ.push(element_id);
		return;
	}

	calcQ.push(element_id);

	if (element_id.search('#') != 1){
		temp= element_id.split('#');
		element_id= temp[0];
		var custom_id;
		custom_id= temp[1];
	}

	xmlhttp.open("POST", window.location.protocol+"//"+window.location.hostname+"/Scripts/calculation.php?field="+element_id, true);
	xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	xmlhttp.onreadystatechange = function() {
		if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
			//alert(xmlhttp.responseText);
			if(xmlhttp.responseText != "") {
				//alert(xmlhttp.responseText);
				processField(xmlhttp.responseText, window, form, element_id, custom_id);
			}
		}
	}
	xmlhttp.send();
}

function checkQueue(element_id) {
	if (element_id.search('#') != 1){
		temp= element_id.split('#');
		element_id= temp[0];
	}

	for(i=0; i < doneQ.length; i++) {
		if(doneQ[i] == element_id) {
			return false;
		}
	}
	return true;
}

function clearingHouse(form, window) {

	var found = false;

	calcQ.shift(); // take away the previous

	//alert('Queue = '+calcQ+' DoneQ = '+doneQ);

	while(calcQ.length > 0 && found == false) {
		element_id = calcQ.shift();
		//found = checkQueue(element_id);
		if(element_id != undefined)
			found = true;
	}

	// reset doneQ
	while(doneQ.length > 0)
		doneQ.pop();

	if(found == false) {
		aSyncQueue.pop();
		autoShowProgTbl('');
		return;
	}

	//alert(calcQ.length+' next ='+element_id);

	if (element_id.search('#') != 1){
		temp= element_id.split('#');
		element_id= temp[0];
		var custom_id;
		custom_id= temp[1];
	}

	xmlhttp.open("POST", window.location.protocol+"//"+window.location.hostname+"/Scripts/calculation.php?field="+element_id, true);
	xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	xmlhttp.onreadystatechange = function() {
		if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
			//alert(xmlhttp.responseText);
			if(xmlhttp.responseText != "") {
				//alert(xmlhttp.responseText);
				processField(xmlhttp.responseText, window, form, element_id, custom_id);
			}
			//else {
			//	clearingHouse(form, window);
			//}
		}
	}
	xmlhttp.send();
}

function processField(responseText, window, form, element_id, custom_id){
	var responseString = responseText.toString();
	var response = responseString.split('%%');
	var i, j;
	var qs = new Array();
	var post = '';
	var field = '';

	theForm = document.getElementById(form);

	for(i=0;i < response.length; i++) {
		//field = theForm.elements[response[i]];
		if(typeof(theForm.elements[response[i]]) == "object"){
			var responseString = response[i].toString();
			var tblField = responseString.split('@');
			var tbl = tblField[0];
			var total = 0;
			var multArray = new Array();

			// for callock
			if(typeof(theForm.elements[tbl+'@ID']) == "object" && theForm.elements[tbl+'@ID'].value)
				qs.push(tbl+'@ID='+theForm.elements[tbl+'@ID'].value);

			//alert(tblField[0]+' '+lib_map[tbl]);
			if(typeof(lib_map) == 'object' && lib_map[tbl]) { // multiple

				// locate field location
				for(j=0; j<lib_field[lib_map[tbl]].length; j++) {
					if(lib_field[lib_map[tbl]][j] == response[i]) {
						index = j;
						break;
					}
				}

				ctrlID = lib_map[tbl];

				// loop thru lib_indx to get current values
				for(k=0; k<lib_indx[ctrlID].length; k++) {
					indx = lib_indx[ctrlID][k];
					//if(lib_ops[ctrlID][k] != 'DELETE') {
						//alert(lib_ops[ctrlID]);
						total = total + Number(lib_data[ctrlID][indx][index]);
						multArray.push(lib_data[ctrlID][indx][index]);
					//}
				}

				qs.push(response[i]+'='+total);

				// in case we need a single item we can get it w/ id-current
				qs.push(theForm.elements[response[i]].id+'-current='+theForm.elements[response[i]].value);

				// in case we need the # of items
				qs.push(theForm.elements[response[i]].id+'-count='+k);

				// in case we need all the items
				qs.push(theForm.elements[response[i]].id+'-array='+multArray);

			}
			else
				qs.push(theForm.elements[response[i]].id+'='+theForm.elements[response[i]].value);
		}
		else { // if we can't find the fields... try w/ custom_id
			if (custom_id) {
				var temp1;
				temp1 = response[i] + '#' + custom_id;
				if(typeof(theForm.elements[temp1]) == "object"){
					qs.push(response[i]+'='+theForm.elements[temp1].value);
				}
			}
		}
	}
	if(custom_id) {
		qs.push('customID='+custom_id);
	}
	qs.push('operation=process');

	post = qs.join("&");
	//alert(post);
	xmlhttp.open("POST", window.location.protocol+"//"+window.location.hostname+"/Scripts/calculation.php?field="+element_id, true);
	xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	xmlhttp.onreadystatechange = function() {
		if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
			//alert(xmlhttp.responseText);
			//if(xmlhttp.responseText != "") {
				//alert(xmlhttp.responseText);
				doneQ.push(element_id);
				processResult(xmlhttp.responseText, window, form, custom_id);
				aSyncQueue.pop();
				autoShowProgTbl('');
			//}
		}
	}
	aSyncQueue.push(1);
	autoShowProgTbl('Calculating...');
	xmlhttp.send(post);
}

function processResult(responseText, window, form, custom_id){
	var responseString = responseText.toString();
	var response = responseString.split('%%');
	var i;
	for(i=0;i < response.length; i++) {
		var field = response[i].split('=');

		field_element = document.getElementById(field[0]);

		if(field_element) {
			prefix = field_element.alt.substr(0, 3);

			if(prefix == 'lbl') // have to do this becoz innerHTML is causing problem
				field_element.innerHTML = field[1];
			else
				field_element.value = field[1];

			var tbl = field[0].split('@');

			if(typeof(lib_map) == 'object' && lib_map[tbl[0]]) {
				//alert(tbl[0]+' '+lib_map[tbl[0]]+' '+field_element.id);
				shadowSnap(field_element, lib_map[tbl[0]]);
			}
			else {
				if(prefix == 'lbl') { // lable is not an input
					hidden = document.createElement("INPUT");
					hidden.type = "hidden";
					hidden.name = field[0];
					hidden.value = field[1];
					document.forms[0].appendChild(hidden);
				}
			}
		}
		else if(custom_id && field[0].indexOf("gfe") != -1 && field[0] != 'gfeMisc' ) {
			field[0] = field[0] + '#' + custom_id;

			field_element = document.getElementById(field[0]);

			if(field_element) {
				prefix = field_element.alt.substr(0, 3);
				if(prefix == 'lbl') // have to do this becoz innerHTML is causing problem
					field_element.innerHTML = field[1];
				else
					field_element.value = field[1];
			}
			else {
				hidden = document.createElement("INPUT");
				hidden.type = "hidden";
				hidden.name = field[0];
				hidden.value = field[1];
				document.forms[0].appendChild(hidden);
			}
		}
		else {
			hidden = document.createElement("INPUT");
			hidden.type = "hidden";
			hidden.name = field[0];
			hidden.value = field[1];
			document.forms[0].appendChild(hidden);
		}

		//if(response[i+1] == 'QUEUE' && custom_id)
		//	calcQ.push(field[0]);
	}
	// so we are done displaying results.. now we need process the calcQ
	clearingHouse(form, window);
}