
function launchPaxNameConfirmation(openURL) {
	popWin(openURL, "Viewer", "450","495","yes","yes");
}

function popWin(strURL, strWinName, intWidth, intHeight, blnScrollbars, strCustomParams){
	var intLeft = (screen.width-intWidth)/2;
	var intTop = (screen.height-intHeight)/2;
	var strSettings, intWin;

	strSettings = "height="+ intHeight + ",";
	strSettings += "width="+ intWidth + ",";
	strSettings += "top=" + intTop + ",";
	strSettings += "left=" + intLeft + ",";
	strSettings += "scrollbars=" + blnScrollbars;
	if (strCustomParams && strCustomParams.length) {
		strSettings += "," + strCustomParams;
  	}
  intWin = window.open(strURL, strWinName, strSettings);
  return intWin;
}


/*
	Insert any predefined pop up window functions here.
*/

var ord;
ord = 'asc';
function padToString(str) {
	if(str.length < 22) {
		return Math.pow(10,(21-str.length)).toString().replace('1','0') + str;
	}
	else {
		return str;
	}
}

function orderCols(colNum,tableId,stRow,offTop,diffAdj) {
	dspWorkingDiv();
	
	aLen = arguments.length;
	
	t = document.getElementById(tableId);
	var g = true;
	cnt = 0;

	/*window.status = 'start_org';
	cT = new Date();
	window.status = cT;*/
	/*   the fastest way!!!   */	
	
	rArr = new Array();
	for(i=stRow;i<t.rows.length;i++) {
		if(t.rows[i].id != 'submit' && t.rows[i].id != 'total' && t.rows[i].cells[colNum]) {
			v = t.rows[i].cells[colNum].innerText.replace('$','').replace('€','').replace('£','').replace(':','').replace('-','').replace('+','').replace('*','').replace('(','');
			v = (isNaN(v.charAt(0))) ? v : padToString(v);
			//alert(v);
			//alert(v.length);
			rArr[rArr.length] = v + '_~_' + t.rows[i].id;
		}
	}

	l = rArr.length;
	for (var i=0; i<(l-1); i++) {
        for (var j=i+1; j<l; j++) {
            if ((rArr[j] < rArr[i] && ord=='asc') || (rArr[j] > rArr[i] && ord=='desc')) {
                var dummy = rArr[i];
                rArr[i] = rArr[j];
                rArr[j] = dummy;
            }
		}
	}
		
	for (var i=0; i<l; i++) {
		//rObj = document.getElementById(rArr[i].split('_~_')[1]);
		// loop finding the row with the id we're looking for...
		for(r=stRow;r<t.rows.length;r++) {
			if(t.rows[r].id == rArr[i].split('_~_')[1])
				rObj = t.rows[r];
		}

		if(rObj.rowIndex != (i+stRow))
			rObj.swapNode(t.rows[(i+stRow)]);
	}


/*	this does the same as the loop after this, but I think it's a bit slower...
	while (g) {
		g = false;
		for(i=1;i<t.rows.length-1;i++) {
			v = t.rows[i].cells[colNum].innerText.replace('$','').replace('€','').replace('£','');
			vn = t.rows[i+1].cells[colNum].innerText.replace('$','').replace('€','').replace('£','');
			v = (isNaN(v.charAt(0))) ? v : padToString(v);
			vn = (isNaN(vn.charAt(0))) ? vn : padToString(vn);
			if((v>vn && ord=='asc') || (v<vn && ord=='desc')) {
				t.rows[i].swapNode(t.rows[i+1]);
				i--;
				g = true;
			}
		}
		cnt++;
		if(cnt > 10000)
			g = false;
	}
	*/
	
	/* this does the same as the loop before this, but I think it's a bit faster... 
	for(i=1;i<t.rows.length-1;i++) {
		for(j=i+1;j<t.rows.length;j++) {
			v = t.rows[j].cells[colNum].innerText.replace('$','').replace('€','').replace('£','');
			vn = t.rows[i].cells[colNum].innerText.replace('$','').replace('€','').replace('£','');
			v = (isNaN(v.charAt(0))) ? v : padToString(v);
			vn = (isNaN(vn.charAt(0))) ? vn : padToString(vn);
			if((v<vn && ord=='asc') || (v>vn && ord=='desc')) {
				t.rows[i].swapNode(t.rows[j]);
			}
		}
	}*/
	
		

	
	var bg=true;
	
	for(i=stRow;i<t.rows.length;i++) {
		if(aLen > 3) {
			d = document.getElementById('cont'+t.rows[i].id.split('_')[1]);
			if(d) {
				if(aLen > 4 && diffAdj != "booyah") {
					newTop = eval(25*i)+offTop-25;
					d.style.top = newTop;
				}
				else if(aLen > 4 && diffAdj == "booyah") {
					newTop = eval(-50*i)-25;
					alert(i + '~' + offTop);
					d.style.top = offTop;
				}
				else {
					d.style.top = eval(25*i)+offTop;
				
					if(d.style.position != 'relative') {
					
						for(j=0;j<d.children.length;j++) {
							d.children[j].style.top = eval(25*i)+offTop;
						}
					}
				}
			}
		}

		//if(t.rows[i].getAttribute("sameOps") == false) {
			if(bg) {
				bg=false;
				if(t.rows[i].getAttribute("sameOps") == "false" || !t.rows[i].getAttribute("sameOps"))
					t.rows[i].bgColor = 'ececec';
			}
			else {
				bg=true;
				if(t.rows[i].getAttribute("sameOps") == "false" || !t.rows[i].getAttribute("sameOps"))
					t.rows[i].bgColor = 'ffffff';
			}
//		}
//		else {
//			if(bg) {
//				bg=false;
//			}
//			else {
//				bg=true;
//			}
//		}
	}
	
/*	for(i=stRow;i<t.rows.length;i++) {
		if(t.rows[i].getAttribute("sameOps") == "true") {
			t.rows[i].bgColor = 'bbffbb';
				alert(t.rows[i].outerHTML);
				break;
		}
	}
*/

	ord=(ord=='asc') ? 'desc' : 'asc';
	
/*	
	cT = new Date();
	window.status = cT;
//	window.status = 'comp_org_1';



	//window.status = 'comp_org_2';
	cT = new Date();
	window.status = cT;
*/
	$('loadingDiv').style.display = 'none';
}

//To use with Ajax, this function will convert any form field into a string
// i.e. var queryString = "index.cfm?fuseaction=baseCont.chkExistName&" + formData2QueryString(f);
	function formData2QueryString(docForm, formatOpts) {
	  var opts = formatOpts || {};
	  var str = '';
	  var formElem;
	  var lastElemName = '';
	  
	  for (i = 0; i < docForm.elements.length; i++) {
	    formElem = docForm.elements[i];
	    
	    switch (formElem.type) {
	      // Text fields, hidden form elements
	      case 'text':
	      case 'hidden':
	      case 'password':
	      case 'textarea':
	      case 'select-one':
	        str += formElem.name + '=' + encodeURIComponent(formElem.value) + '&'
	        break;
	        
	      // Multi-option select
	      case 'select-multiple':
	        var isSet = false;
	        for(var j = 0; j < formElem.options.length; j++) {
	          var currOpt = formElem.options[j];
	          if(currOpt.selected) {
	            if (opts.collapseMulti) {
	              if (isSet) {
	                str += ',' + encodeURIComponent(currOpt.value);
	              }
	              else {
	                str += formElem.name + '=' + encodeURIComponent(currOpt.value);
	                isSet = true;
	              }
	            }
	            else {
	              str += formElem.name + '=' + encodeURIComponent(currOpt.value) + '&';
	            }
	          }
	        }
	        if (opts.collapseMulti) {
	          str += '&';
	        }
	        break;
	      
	      // Radio buttons
	      case 'radio':
	        if (formElem.checked) {
	          str += formElem.name + '=' + encodeURIComponent(formElem.value) + '&'
	        }
	        break;
	        
	      // Checkboxes
	      case 'checkbox':
	        if (formElem.checked) {
	          // Collapse multi-select into comma-separated list
	          if (opts.collapseMulti && (formElem.name == lastElemName)) {
	            // Strip of end ampersand if there is one
	            if (str.lastIndexOf('&') == str.length-1) {
	              str = str.substr(0, str.length - 1);
	            }
	            // Append value as comma-delimited string
	            str += ',' + encodeURI(formElem.value);
	          }
	          else {
	            str += formElem.name + '=' + encodeURIComponent(formElem.value);
	          }
	          str += '&';
	          lastElemName = formElem.name;
	        }
	        break;
	        
	    }
	  }
	  // Remove trailing separator
	  str = str.substr(0, str.length - 1);
	  return str;
	}
