//get the browser version
V3 = 0; OP = 0; IE4  = 0; IE5 = 0; NS = 0; NS6 = 0; IsMac = 0;
if(document.images){
    if(navigator.userAgent.indexOf("Opera") != -1){
        OP = 1;
    } else {
    		IE=1;
	      //IE = (document.all && !document.getElementById);
        IE4 = (document.all && !document.getElementById);
        IE5 = (document.all && document.getElementById);
				NS = (navigator.appName=="Netscape" && navigator.appVersion >= "4" && navigator.appVersion < "5")
        NS6 = (document.getElementById && navigator.appName=="Netscape");
    }
} else {
    V3 = 1;    
}

if(navigator.userAgent.indexOf("Mac") != -1){
    IsMac = 1;
}

//!!!! needed for calendar popup styles, remove some day
document.write(CalendarPopup_getStyles());

function validateField(obj,datatype){

 if (datatype==DATATYPE_TEXT) {

 } else if (datatype==DATATYPE_TEXTNOSPACES) {

 }
}

//fixes focus when an MDI window is closed, relates to parent.bFixFocus which gets set when a window is closed.
function fixFocus(obj) {
	if (window.top.bFixFocus) {
		obj.select();
		window.top.bFixFocus=false;
	}
}


//search and replace string
function stringReplace(strFind,strReplace,strString) {
	var re = new RegExp (strFind, 'gi') ;
	return strString.replace(re, strReplace) ;
}

//////////////////////////////////////////////////////////////
//Query functions
//////////////////////////////////////////////////////////////

function selectAllQueryResults() {
 document.query.bSelectAllQueryResults.value="1";
 document.query.submit()
}

function addSelected() {
 document.query.bAddSelected.value="1";
 document.query.submit()
}

function removeSelected() {
 document.query.bRemoveSelected.value="1";
 document.query.submit()
}

function removeAll() {
 document.query.bRemoveAll.value="1";
 document.query.submit()
}

//selects all checkboxes in a form.
function selectAll(oForm) {
	for (var i = 0; i<oForm.elements.length; i++) {
			if (oForm.elements[i].type=='checkbox') {
					oForm.elements[i].checked=true;
			}
	}
}

//selects all checkboxes in a form.
function unselectAll(oForm) {
	for (var i = 0; i<oForm.elements.length; i++) {
			if (oForm.elements[i].type=='checkbox') {
					oForm.elements[i].checked=false;
			}
	}
}

//used to display tooltip and change background color of focused form item
function doFocus(obj,msg) {
	obj.className = obj.className.replace('_cold','_hot');

	//show tooltip
	if (msg.length>0) {
		posX = getX(obj.id)+obj.clientWidth+6;
		posY = getY(obj.id)+15;
		window.status=obj.msg;
		overlib(msg, FIXX, posX, FIXY, posY);
	}
}

//used to remove tooltip and change background color of form item that lost focus
function doBlur(obj,datatype) {

	obj.className = obj.className.replace('_hot','_cold');

	//remove status message
	window.status="";
	
	//remove tooltip
	nd();

	validateField(obj,datatype);
}

//on mouse hover
function doMouseOver(obj) {
	//obj.className = stringReplace('_cold','_hot',obj.className);
	obj.className = obj.className.replace('_cold','_hot');
}

//on mouse un-hover
function doMouseOut(obj) {
	//obj.className = stringReplace('_hot','_cold',obj.className);
	obj.className = obj.className.replace('_hot','_cold');
}

//creates a unique window name with a timestamp
function generateWindowName(strName) {

	return strName+new Date().getTime();
}


//returns the x and y coordinates of an object (used for tooltip locations)

function getX(imgID) {
  return getX_ex(imgID);
}

function getY(imgID) {
  return getY_ex(imgID);
}

function getX_ex(imgElem) {
	xPos = eval('document.all.' + imgElem + '.offsetLeft');
	tempEl = eval('document.all.' + imgElem + '.offsetParent');
  	while (tempEl != null) {
  		xPos += tempEl.offsetLeft;
  		tempEl = tempEl.offsetParent;
  	}
	return xPos;
}

function getY_ex(imgElem) {

	yPos = eval('document.all.' + imgElem + '.offsetTop');
	tempEl = eval('document.all.' + imgElem + '.offsetParent' );
	while (tempEl != null) {
  		yPos += tempEl.offsetTop;
  		tempEl = tempEl.offsetParent;
  	}
	return yPos;

}

function submitSavedQuery() {

	var strDescription;
	strDescription = prompt('Please enter a name for the saved Query:','');
	if (strDescription!=null) {
		document.getElementById('strQueryDescription').value = strDescription;
		document.getElementById('saveQueryForm').submit();
	}
}

function promptYesNo(strMessage) {

	if (strMessage.length==0) {
		strMessage="Are you sure?";
	}

	
	return confirm(strMessage);
}

function submitForm(strForm,bSave) {
	
	oForm=document.getElementById(strForm);

	//if bSave, set the bSave flag to true
	if (bSave) oForm.bSave.value=true;

	//set the cursor to hourglass
	document.body.style.cursor="wait";

	//select all option boxes
	for (var i = 0; i<oForm.elements.length; i++) {
			if (oForm.elements[i].type=='select-multiple') {
					selectAllOptions(oForm.elements[i]);
			}
	}
	
	//submit the form
	oForm.submit();

}

function voidBO(strForm) {

	oForm=document.getElementById(strForm);

	oForm.bVoid.value=true;

	//set the cursor to hourglass
	document.body.style.cursor="wait";
	
	//submit the form	
	oForm.submit();

}

function updateToAddress(strToName, strToCompanyName, strToPhone, strToEmail,strAssignedOrg, strToAddress1,strToAddress2,strToCity,strToState,strToZip,strToCountry) {
	if (document.getElementById('strToName')) document.getElementById('strToName').value=strToName;
	if (document.getElementById('strToCompanyName')) document.getElementById('strToCompanyName').value=strToCompanyName;
	if (document.getElementById('strToAddress1')) document.getElementById('strToAddress1').value=strToAddress1;
	if (document.getElementById('strToAddress2')) document.getElementById('strToAddress2').value=strToAddress2;
	if (document.getElementById('strToCity')) document.getElementById('strToCity').value=strToCity;
	if (document.getElementById('strToState')) document.getElementById('strToState').value=strToState;
	if (document.getElementById('strToZip')) document.getElementById('strToZip').value=strToZip;
	if (document.getElementById('strToCountry')) document.getElementById('strToCountry').value=strToCountry;
	if (document.getElementById('strToContactName')) document.getElementById('strToContactName').value=strToName;
	if (document.getElementById('strToContactPhone')) document.getElementById('strToContactPhone').value=strToPhone;
	if (document.getElementById('strToContactEmail')) document.getElementById('strToContactEmail').value=strToEmail;
}

function updateBillToAddress(strToName, strToCompanyName, strToPhone, strToEmail,strAssignedOrg, strToAddress1,strToAddress2,strToCity,strToState,strToZip,strToCountry) {
	if (document.getElementById('strBillToName')) document.getElementById('strBillToName').value=strToName;
	if (document.getElementById('strBillToCompanyName')) document.getElementById('strBillToCompanyName').value=strToCompanyName;
	if (document.getElementById('strBillToAddress1')) document.getElementById('strBillToAddress1').value=strToAddress1;
	if (document.getElementById('strBillToAddress2')) document.getElementById('strBillToAddress2').value=strToAddress2;
	if (document.getElementById('strBillToCity')) document.getElementById('strBillToCity').value=strToCity;
	if (document.getElementById('strBillToState')) document.getElementById('strBillToState').value=strToState;
	if (document.getElementById('strBillToZip')) document.getElementById('strBillToZip').value=strToZip;
	if (document.getElementById('strBillToCountry')) document.getElementById('strBillToCountry').value=strToCountry;
	if (document.getElementById('strBillToContactName')) document.getElementById('strBillToContactName').value=strToName;
	if (document.getElementById('strBillToContactPhone')) document.getElementById('strBillToContactPhone').value=strToPhone;
	if (document.getElementById('strBillToContactEmail')) document.getElementById('strBillToContactEmail').value=strToEmail;
}

function updateFromAddress(strFromName, strFromCompanyName, strFromPhone, strFromEmail,strAssignedOrg, strFromAddress1,strFromAddress2,strFromCity,strFromState,strFromZip,strFromCountry) {
	if (document.getElementById('strFromName')) document.getElementById('strFromName').value=strFromName;
	if (document.getElementById('strFromCompanyName')) document.getElementById('strFromCompanyName').value=strFromCompanyName;
	if (document.getElementById('strFromAddress1')) document.getElementById('strFromAddress1').value=strFromAddress1;
	if (document.getElementById('strFromAddress2')) document.getElementById('strFromAddress2').value=strFromAddress2;
	if (document.getElementById('strFromCity')) document.getElementById('strFromCity').value=strFromCity;
	if (document.getElementById('strFromState')) document.getElementById('strFromState').value=strFromState;
	if (document.getElementById('strFromZip')) document.getElementById('strFromZip').value=strFromZip;
	if (document.getElementById('strFromCountry')) document.getElementById('strFromCountry').value=strFromCountry;
	if (document.getElementById('strFromContactName')) document.getElementById('strFromContactName').value=strFromName;
	if (document.getElementById('strFromContactPhone')) document.getElementById('strFromContactPhone').value=strFromPhone;
	if (document.getElementById('strFromContactEmail')) document.getElementById('strFromContactEmail').value=strFromEmail;
}

//!!!!!notinuseanymore
function fillFromAddress(strFromName, strFromCompanyName, strFromPhone, strFromEmail,strAssignedOrg, strFromAddress1,strFromAddress2,strFromCity,strFromState,strFromZip,strFromCountry) {
	if (document.getElementById('strFromName')) document.getElementById('strFromName').value=strFromName;
	if (document.getElementById('strFromCompanyName')) document.getElementById('strFromCompanyName').value=strFromCompanyName;
	if (document.getElementById('strFromAddress1')) document.getElementById('strFromAddress1').value=strFromAddress1;
	if (document.getElementById('strFromAddress2')) document.getElementById('strFromAddress2').value=strFromAddress2;
	if (document.getElementById('strFromCity')) document.getElementById('strFromCity').value=strFromCity;
	if (document.getElementById('strFromState')) document.getElementById('strFromState').value=strFromState;
	if (document.getElementById('strFromZip')) document.getElementById('strFromZip').value=strFromZip;
	if (document.getElementById('strFromCountry')) document.getElementById('strFromCountry').value=strFromCountry;
	if (document.getElementById('strFromName')) document.getElementById('strFromName').value=strFromName;
	if (document.getElementById('strFromPhone')) document.getElementById('strPhone').value=strFromPhone;
	if (document.getElementById('strFromEmail')) document.getElementById('strEmail').value=strFromEmail;
	//window.top.document.getElementById('selectAddressBook').style.visibility='hidden';
}

function fillContactInfo(strToName, strToCompanyName, strToContactPhone, strToContactEmail,strAssignedOrg, strToAddress1,strToAddress2,strToCity,strToState,strToZip,strToCountry) {
	if (document.getElementById('strFromName')) document.getElementById('strFromName').value=addressBook[i][1];
	if (document.getElementById('strFromCompany')) document.getElementById('strPhone').value=addressBook[i][3];
	if (document.getElementById('strFromCompany')) document.getElementById('strEmail').value=addressBook[i][4];
	//window.top.document.getElementById('selectAddressBook').style.visibility='hidden';
}

function showDiv(strDivName) {

	myDiv=document.getElementById(strDivName);

	myDiv.style.left=document.body.scrollLeft;
	myDiv.style.top=document.body.scrollTop;

	myDiv.style.visibility='visible';

	//i = 1;
	//while (myDiv.style.width < realWidth)
	//{
	//	 setTimer(growDiv(myDiv), 1000);
	//	 i++;
	//}
}

function growDiv(myDiv) {
alert('go');
	myDiv.style.width=myDiv.style.width+10;
	myDiv.style.height=myDiv.style.height+10;
}

//opens a popup div for choosing items for the current form.
// sits on top of all windows except for windowing system.

function showPopupSelector(page,params,strPopupCallback) {

	//set the caller object and caller window in the app window
	window.top.myOpenerWindow=window;
	window.top.strPopupCallback=strPopupCallback;
		
	openMDIWin(page, params);
}

//smart alert box for IE only
function alertBox(msg, tit,icon,buttons, defs,mode){
    if(IE){
        // if its IE4+ call the VB Script 
        return makeMsgBox(mess,tit,icon,buts,defs,mode);
					// which button was pressed?
					//retVal == 1 Ok pressed
					//retVal == 2 Cancel pressed
    } else {
        // else use a simple alert
        alert(msg);
    }
}

// smart input box for IE only
function inputBox(msg, title, val){
    
    // only three args here
    // Question, Title, Default answer
    
    if(IE){
        retVal = makeInputBox(msg, title, val);
    } else {
        retVal = prompt(msg, val);
    }
    
    if(retVal){
        return retVal;
    }
}

function setMsg(strMsg) {

	tmp='<table width=450 class="tableForm"><tr><td>';
	if (strMsg.substring(0,5)=="error") {
			tmp+='<div class="msgError">'+strMsg+'</div>';
		//} else if (substr($_SESSION["msgs"][$i],0,6)=="hidden") {
		//	tmp+='<div style="visibility: hidden;" class="msgNotify">'+strMsg+'</div>';
	} else {
			tmp+='<div class="msgNotify">'+strMsg+'</div>';
	}
	tmp+="</td></tr></table>";

	oMsgTD = document.getElementById('messages');
	if (oMsgTD!=null){
		oMsgTD.innerHTML=tmp;
	}
}

//used on order invitem popup to add items to the order
function popupInvItemSubmit(strArgs) {
	nQty = window.top.inputBox("Please enter the order quantity:","Order Quantity","0");

	if (!isNaN(nQty)) {
		setMsg("Item was added with a quantity of "+nQty);
		callback(strArgs+','+nQty);
	}
}

//used for invoice item submissions
function popupInvoiceItemSubmit(strArgs) {
	nQty = window.top.inputBox("Please enter the quantity:","Quantity","0");

	if (!isNaN(nQty)) {
		setMsg("Item was added with a quantity of "+nQty);
		callback(strArgs+','+nQty);
	}
}

//used on receiving orders to add products to the order
function popupOrderItemDistReceivingSubmit(strArgs) {
	nQty = window.top.inputBox("Please enter the order quantity:","Order Quantity","0");
	if (!isNaN(nQty)) {
		setMsg("Item was added with a quantity of "+nQty);
		callback(strArgs+','+nQty);
	}
}

//used for packages to add items to the package
function popupOrderItemSubmit(strArgs) {
	nQty = window.top.inputBox("Please enter the quantity:","Quantity","0");

	if (!isNaN(nQty)) {
		setMsg("Item was added with a quantity of "+nQty);
		callback(strArgs+','+nQty);
	}
}

//!!!!need to expand to accept array
function callback(strArgs) {
//alert('window.top.myOpenerWindow.'+window.top.strPopupCallback+'('+strArgs+');');
	eval ('window.top.myOpenerWindow.'+window.top.strPopupCallback+'('+strArgs+');');
}


//sends the page to the print window
//the print window automatically sucks whatever is between printstart and printend tags in the original window
function printWin() {
	pwin=window.open("pPrintWindow.php","pwin","screenX=1,screenY=1,width=608,height=300,toolbar=no,scrollbars=no,status=no,menubar=yes");
	return false;
}

//open a window
function openWin(page, params, windowParams) {

	if (window.name==window.top.name) {
		strWin=oPages.getUrl(page)
		pwin=window.open(strWin+"?"+params,"nWin","left=1,top=1,screenX=1,screenY=1,width=700,height=500,toolbar=yes,scrollbars=yes,status=yes,menubar=yes,resizable=yes");
		//return true;
	} else { //window is not top, so call same function in parent window. loops until window.top is found
		window.parent.openWin(page,params,windowParams);
	}
}

//redirect page
function sendTo(link) {
	window.location=link;
	return true;
}

// foneMask functions
function chkNAN(char2chk)
{
   var validNum = "0123456789";
   if (validNum.indexOf(char2chk) == "-1")
      return(confirm("You have entered a non-numeric character.\nDo you want to turn off non-numeric character checking?"));
}

function maskIt(fld)
{
   fldVal = fld.value;

   var tmpStr = "(";
   keyCount = fldVal.length;
   keyEntered =fldVal.substring(keyCount-1,keyCount);

   if (keyCount < 2)   isNamedFone = false;
   if (!isNamedFone)   isNamedFone = chkNAN(keyEntered);

   keyCount++;
//   with (document.foneMask)
//   {
      switch (keyCount)
      {
         case 2:
            tmpStr +=  fldVal;
            fld.value = tmpStr;
            break;
         case 5:
            fld.value +=  ") ";
            break;
          case 10:
            fld.value += "-";
            break;
      }
//   }
}

//used to open the app window
function openApp(URL) {
   var availHeight = screen.availHeight;
   var availWidth = screen.availWidth;
   var x = 0; y = 15; 
   if (document.all) {
        x = window.screenTop; 
        y = window.screenLeft+15;
   }
   else if (document.layers) {  
        x = window.screenX;
        y = window.screenY+15;
   }
   
   var arguments = 'resizable=1,toolbar=0,location=0,fullscreen=no,directories=0,addressbar=0,scrollbars=1,status=1,menubar=0,top=0,left=0,screenX='+x+',screenY='+y+',width='+availWidth+',height='+availHeight;
   var newWindow = window.open(URL,'app',arguments);
}

//used for the date insert
function leadingZero(nr)
{
	if (nr < 10) nr = "0" + nr;
	return nr;
}


//used to put the current date and time in a field
function insertDate(fld, dtType) {
	dateVar = new Date();
	switch (dtType) {
		case DATETIME_TODAY:
			document.getElementById(fld).value = leadingZero(dateVar.getMonth()+1) + "/" + leadingZero(dateVar.getDate()) + "/" + dateVar.getYear();
			break;
		case DATETIME_NOW:
			document.getElementById(fld).value = leadingZero(dateVar.getMonth()+1) + "/" + leadingZero(dateVar.getDate()) + "/" + dateVar.getYear() + " " + leadingZero(dateVar.getHours()) + ":" + leadingZero(dateVar.getMinutes());
			break;
		default:
			document.getElementById(fld).value = leadingZero(dateVar.getMonth()+1) + "/" + leadingZero(dateVar.getDate()) + "/" + dateVar.getYear();
			break;
	}
}

//!!!! not used anymore: runs in order window, however called from iFrame.
function addNewOrderItem(nEntityDefID,nEntityPKID){
	document.getElementById('nNewEntityDefID').value=nEntityDefID;
	document.getElementById('nNewEntityPKID').value=nEntityPKID;
	document.getElementById('formOrderItems').submit();
}

//runs in order distribution window, however called from iFrame.
function addNewOrderInvItem(nEntityDefID,strInvHash,nQty){
	document.getElementById('nNewEntityDefID').value=nEntityDefID;
	document.getElementById('strNewInvHash').value=strInvHash;
	document.getElementById('nNewQty').value=nQty;
	document.getElementById('formOrderItems').submit();
}

//runs in invoice window, however called from iFrame.
function addNewInvoiceItem(nPriceItemID,nBillingCategoryID,nQty){
	document.getElementById('nNewPriceItemID').value=nPriceItemID;
	document.getElementById('nNewBillingCategoryID').value=nBillingCategoryID;
	document.getElementById('nNewQty').value=nQty;
	//set the orgID by the parent:
	document.getElementById('nNewOrgID').value=window.parent.document.getElementById("nCustomerID").value;
	document.getElementById('formInvoiceItems').submit();
}

//runs in package window, however called from iFrame.
function addNewPackageItem(nEntityDefID,nPKID,nQty){
	document.getElementById('nNewEntityDefID').value=nEntityDefID;
	document.getElementById('nNewEntityPKID').value=nPKID;
	document.getElementById('nNewQty').value=nQty;
	document.getElementById('formPackageItems').submit();
}

function addNewOrderItemDistReceiving(nEntityDefID,nPKID,strLot, strSerialNumber, nInvItemConditionDefID, dtExpirationDate, nQty){

	document.getElementById('nNewEntityDefID').value=nEntityDefID;
	document.getElementById('nNewEntityPKID').value=nPKID;
	document.getElementById('strNewLot').value=strLot;
	document.getElementById('strNewSerialNumber').value=strSerialNumber;
	document.getElementById('nNewInvItemConditionDefID').value=nInvItemConditionDefID;
	document.getElementById('dtNewExpirationDate').value=dtExpirationDate;
	document.getElementById('nNewQty').value=nQty;
	document.getElementById('formOrderItemsDistReceiving').submit();
}

//used in iFrameQueryOrg
function updateOrg(nOrgID) {
	document.all.nOrgID.value=nOrgID;
}

//used in iFrameQueryProduct
function updateCustomer(nCustomerID) {
	document.all.nCustomerID.value=nCustomerID;
}

//used in iFrameQueryProduct
function updateDistReceivingCustomer(nCustomerID) {
	document.all.nCustomerID.value=nCustomerID;
	submitForm('formOrder',false);
}

//used in iFrameQueryProduct
function updateAdjustCustomer(nOrgID) {
	document.all.nOrgID.value=nOrgID;
	submitForm('formModInvItem',false);
}

function updateAssignTo(nOrgID) {
	document.all.nEntityPKID.value=nOrgID;
	//window.top.document.getElementById('selectCustomer').style.visibility='hidden';
}

function saveOrderDistribution() {
	window.frames.orderItemsDistribution.document.getElementById('bSave').value="True";
	window.frames.orderItemsDistribution.document.getElementById('formOrderItems').submit();
}

function saveOrderDistReceiving() {
	window.frames.orderItemsDistReceiving.document.getElementById('bSave').value="True";
	window.frames.orderItemsDistReceiving.document.getElementById('formOrderItemsDistReceiving').submit();
}

function savePackage() {
	window.frames.packageItems.document.getElementById('bSave').value="True";
	window.frames.packageItems.document.getElementById('formPackageItems').submit();
}

function saveInvoice() {
	window.frames.invoiceItems.document.getElementById('bSave').value="True";
	window.frames.invoiceItems.document.getElementById('formInvoiceItems').submit();
}

//disable right clicking in the browser. works for all browsers
function disableRightClick() {
	if(document.layers) {
    window.captureEvents(Event.MOUSEDOWN);
    window.onmousedown = function(e){
        if(e.target==document) return false;
    }
	} else {
    document.onmousedown = function(){return false;}
	}
	return false;
}

//validate keyboard control inputs
function validateKey(e) {
 if (document.all){
  e = window.event;
 }
 var key;
 var skey;
 if (document.layers){
  key = e.which;
  skey = e.which;
 } else {
  key = e.keyCode;
  skey = e.keyCode;
 }
 
 var chr = String.fromCharCode(key);
// alert("Unicode value of Key down was " + key);
// alert("Character representation of key down is " + chr);

 if (e.ctrlLeft){
  if (key == 79){
	openMDIWin(2,"pModOrderStorage.php")
	e.keyCode = 0;
	return(false);
//	history.back();
  }
 } else {
  if (e.ctrlKey){
    if (key == 0x53){
      alert("No using that key either...");
      history.back();
	 	}
  }
  return (true);
 }
}

//page collection object
function PageCollection() {

	this.ID = new Array();
	this.url = new Array();
	this.strDesc = new Array();
	
	function PageCollection_add(ID,url,strDesc) {
		this.ID[this.ID.length]=ID;
		this.strDesc[this.strDesc.length]=strDesc;
		this.url[this.url.length]=url;
	}
	
	function PageCollection_getName(ID) {
	
		for (i=0;i<this.ID.length;++i) {
			if (this.ID[i]==ID) return this.strDesc[i];
		}
	}
	
	function PageCollection_getUrl(ID) {
	
		for (i=0;i<this.ID.length;++i) {
			if (this.ID[i]==ID) return this.url[i];
		}
	}
	
	PageCollection.prototype.add=PageCollection_add;
	PageCollection.prototype.getName=PageCollection_getName;
	PageCollection.prototype.getUrl=PageCollection_getUrl;
}

//used to retrieve a stylesheet value;
function getCSSRule(ruleName) {
	for (i=0; i<document.styleSheets.length;i++) {
		for(j=0; j<document.styleSheets[i].rules.length;j++) {
			if(document.styleSheets[i].rules[j].selectorText == "." + ruleName) {
alert(document.styleSheets[i].rules[j].selectorText);
				alert(document.styleSheets[i].rules[j].selectorText);
				return document.styleSheets[i].rules[j];
			}
		}
	}
 	return null;
}

//used to disable javascript errors. used with window.onerror=silentHandler;
function silentHandler()  {return true};

//used to move multiselect option groups around
function MoveOption(objSourceElement, objTargetElement)
{
		var aryTempSourceOptions = new Array();
		var x = 0;

		//looping through source element to find selected options
		for (var i = 0; i < objSourceElement.length; i++) {
				if (objSourceElement.options[i].selected) {
						//need to move this option to target element
						var intTargetLen = objTargetElement.length++;
						objTargetElement.options[intTargetLen].text = objSourceElement.options[i].text;
						objTargetElement.options[intTargetLen].value = objSourceElement.options[i].value;
				}
				else {
						//storing options that stay to recreate select element
						var objTempValues = new Object();
						objTempValues.text = objSourceElement.options[i].text;
						objTempValues.value = objSourceElement.options[i].value;
						aryTempSourceOptions[x] = objTempValues;
						x++;
				}
		}

		//resetting length of source
		objSourceElement.length = aryTempSourceOptions.length;
		//looping through temp array to recreate source select element
		for (var i = 0; i < aryTempSourceOptions.length; i++) {
				objSourceElement.options[i].text = aryTempSourceOptions[i].text;
				objSourceElement.options[i].value = aryTempSourceOptions[i].value;
				objSourceElement.options[i].selected = false;
		}
}

//selects all options in a multiselect box
function selectAllOptions(obj){
	for(var i=0;i<obj.options.length;i++){obj.options[i].selected = true;}
}

//recordset implementation in javascript

function Recordset(arrFieldNames,arrData) {
    this.Columns = arrFieldNames;
    this.Data = arrData;

    this.Fields = Recordset_Fields;
    this.Move = Recordset_Move;
    this.MoveFirst = Recordset_MoveFirst;
    this.MoveNext = Recordset_MoveNext;
    this.MovePrevious = Recordset_MovePrevious;
    this.MoveLast = Recordset_MoveLast;
    this.AddNew = Recordset_AddNew;
    this.Update = Recordset_Update;
    this.Delete = Recordset_Delete;
    this.CheckPosition = Recordset_CheckPosition;
    this.ImportData= Recordset_ImportData;
    this.Setup= Recordset_Setup;

		this.Setup();
}

		function Recordset_Setup() {

			this.Columns.Count = this.Columns.length;
			this.Record = 0;
			this.AbsolutePosition = 1;
			this.EOF = false;
			this.BOF = false;
			this.RecordCount = this.Data.length;

			this.CheckPosition();

	}

    function Recordset_Fields(x, debug) {
        this.Record = this.AbsolutePosition-1;
        if (isNaN(x*1)) {
            for (var i=0; i<this.Columns.length; i++) if (this.Columns[i].toUpperCase() == x.toUpperCase()) return (new Field(this.Columns[i], this.Data[this.Record][i]));
        } else if (x < this.Data[this.Record].length) {
            return (new Field(this.Columns[x], this.Data[this.Record][x]));
        }
        alert("JS Recordset error: Item (" + x + ") not found.");
        return (new Field(x, ""));
    }

    function Recordset_Move(i) {
        this.Record += i-1;
        this.AbsolutePosition += i;
        this.CheckPosition();
    }

    function Recordset_MoveFirst() {
        this.Record = 0;
        this.AbsolutePosition = 1;
        this.EOF = false;
        this.BOF = false;
    }

    function Recordset_MoveNext() {
        this.Record++;
        this.AbsolutePosition++;
        this.CheckPosition(0);
    }

    function Recordset_MovePrevious() {
        this.Record--;
        this.AbsolutePosition--;
        this.CheckPosition(1);
    }

    function Recordset_MoveLast() {
        this.Record = this.Data.length-1;
        this.AbsolutePosition = this.Data.length;
        this.EOF = false;
        this.BOF = false;
    }

    function Recordset_AddNew(xFields, xValues) {
        this.Record = this.Data.length;
        this.AbsolutePosition = this.Data.length+1;
        this.Data[this.Data.length] = new Array(this.Columns.length);
        this.RecordCount = this.Data.length;
        if (xFields) this.Update(xFields, xValues);
    }

    function Recordset_Update(xFields, xValues) {
        this.Record = this.AbsolutePosition-1;
        if (typeof(xFields) == "string") {
            for (var i=0; i<this.Columns.length; i++) {
                if (this.Columns[i].toUpperCase() == xFields.toUpperCase()) {
                    this.Data[this.Record][i] = xValues + "";
                    return true;
                }
            }
            throw "JS Recordset error: Item (" + xFields + ") not found.";
        } else {
            if (xFields.length) for (var i=0; i<xFields.length; i++) this.Update(xFields[i], xValues[i]);
            return true;
        }
    }

    function Recordset_Delete() {
        this.Data = this.Data.remove(this.Record);
        this.RecordCount = this.Data.length;
        this.Record--;
        this.AbsolutePosition--;
        this.CheckPosition();
    }

    function Field(strName, strValue) {
        this.Name = strName;
        this.Value = strValue;
    }

    function Recordset_CheckPosition(iDirection) {
        switch(iDirection) {
        case 0 : // forward - check EOF
            if (this.Record == this.Data.length) this.EOF = true;
            else this.EOF = false;
            break;

        case 1 : // backward - check BOF
            if (this.Record == -1) this.BOF = true;
            else this.BOF = false;
            break;

        default :
            if (this.Record == this.Data.length || this.Data.length == 0) this.EOF = true;
            else this.EOF = false;
            if (this.Record == -1 || this.Data.length == 0) this.BOF = true;
            else this.BOF = false;
        }
    }

	function Recordset_ImportData(strData) {

		var aTmp=strData.split("\n");

		//get the headings
		this.Columns = aTmp[0].split(",");

		this.Data= new Array(aTmp.length-1);

		//now get the data without the headings
		for (var i=1; i<aTmp.length; i++) {
			this.Data[i-1]=aTmp[i].split(",");
		}
		this.Setup();
	}

////////////////////////////////////////////////////////
//data transfer utilities
////////////////////////////////////////////////////////

	function dataXfer(strType, params, callback) {

			commDiv = document.getElementById("DivXfer");

			var _element = document.getElementById("xferScript"+strType);
			if ( _element != null ) { alert("removing!"+params);document.all.divXfer.removeNode ( _element ); }

			_element = document.createElement ( "script" );
			_element.id="xferScript"+strType;
			_element.src="pDataXfer.php?strType="+strType+"&"+params+"&callback="+callback;
			_element.type="text\/javascript";

			commDiv.appendChild ( _element );

	}

	function getFirst ( _result ) {
			alert(_result);
	}

	function getSecond( _result ) {
			alert("1"+_result);
	}

