function isElArray(oEl) { return ( !isNaN(parseInt(oEl.length)) ); }

function doFavorite( strVar, iFunction, oLink ) {
	sURL = "/databuffet/shared/xt_action.asp?cmd=" + iFunction + "&s=" + unescape(strVar) ;
	//alert(unescape(strVar));
	//var oXmlHttp = document.all ? new ActiveXObject("Microsoft.XMLHTTP") : new XMLHttpRequest();
	var oXmlHttp = new XMLHttpObj();
	if (oXmlHttp){
		oXmlHttp.open("GET", sURL, true);
		oXmlHttp.send(null);
	}

	
	var oParent = oLink.parentNode;
	oParent.style.color = '#BFBFBF';
	oParent.style.textDecoration = 'underline';	
	oParent.removeChild(oLink);
	oParent.innerHTML = 'Favorites';

	//window.frames["action_frame"].location=strURL ;
}

function doCmd( iCmd ) {
	var oFrm = document.frmMain ;
	oFrm.cmd.value = iCmd ;
	oFrm.submit() ;
}

function goSort( iSort ) {
	var oFrm = document.frmMain ;
	oFrm.sort.value = iSort ;
	oFrm.submit() ;
}

function CheckAll( sObjName, blnChecked ) {
	var oFrm = document.frmMain ;
	var oObj = eval("oFrm." + sObjName );

	if ( isNaN(parseInt(oObj.length)) ) {
		oObj.checked = blnChecked;
	} else {
		if ( window.location.href.indexOf("oc_basket_edit") != -1) {
			for (i=0; i<oObj.length; i++) 
				oObj[i].checked = ( ( blnChecked ) && ( eval('oFrm.mnemonic_' + i + '.value') != "" ) ) ? true : false;
		} else {
			for (i=0; i<oObj.length; i++) oObj[i].checked = blnChecked;
		}
	}
}

function goTab( sTab ) {
	var oFrm = document.frmMain ;
	var oDiv = document.all.tags("DIV") ;
	var sField = "" ;
	var sForm = "" ;

	for (i=0; i<oDiv.length; i++) {
		sField = oDiv[i].id ;

		if (sField.indexOf("tab_") > -1) {
			if (sField == sTab) {
				oDiv[i].style.display = '' ;
				sForm = "document.all.b_" + sField + ".className = 'tabActive'" ;
				oFrm.active_div.value = sField ;
			} else {
				oDiv[i].style.display = 'none' ;
				sForm = "document.all.b_" + sField + ".className = 'tabInActive'" ;
			}
			eval(sForm) ;
		}
	}
}

function goCancel() { this.close() ; }

function doWindow (oWindow, strName, strURL, strFeatures) {
	if ( oWindow == null )	 {
		oWindow = window.open(strURL,strName,strFeatures) ;
		if ( !oWindow.opener ) oWindow.Opener = window ;
	} else if ( oWindow.closed ) {
		oWindow = window.open(strURL,strName,strFeatures) ;
		if ( !oWindow.opener ) oWindow.Opener = window	;	
	} else {
		oWindow.location = strURL ; 
	}
	oWindow.focus() ;
}

var wndExecute = null ;
function doTask( sTask, sBid, intApp ) {	
	intApp = ( isNaN(parseInt(intApp)) ) ? "1" : intApp;
	var strURL = "/databuffet/shared/wb_execute_task.asp?task=" + sTask + "&bid=" + sBid + "&app=" + intApp;
	var strFeatures = "resizable,height=225,width=400" ;
	doWindow(wndExecute, "download", strURL, strFeatures);
}


function checkFreq( iAction ) {
	var oFrm = document.frmMain ;
	var oObj ;
	var sFreq = "" ;
	var sFreq_cur = "" ;
	var aryFreq ;

	if (oFrm.active_div.value == "tab_dat") {
		oObj = oFrm.freq_cht ;

		if ( isElArray( oFrm.freq_tbl ) ) {
			for (i=0; i<oFrm.freq_tbl.length; i++) {
				try {
					oFrm.trans_cht[i].options.selectedIndex = oFrm.trans_tbl[i].options.selectedIndex ;
					oFrm.freq_cht[i].options.selectedIndex = oFrm.freq_tbl[i].options.selectedIndex ;
				} catch(er) {
					oFrm.trans_cht[0].options.selectedIndex = oFrm.trans_tbl.options.selectedIndex ;
					oFrm.freq_cht[0].options.selectedIndex = oFrm.freq_tbl.options.selectedIndex ;
				}
			}
		} else {
			oFrm.trans_cht[i].options.selectedIndex = oFrm.trans_tbl.options.selectedIndex ;
			oFrm.freq_cht[i].options.selectedIndex = oFrm.freq_tbl.options.selectedIndex ;
		} 
	} else if (oFrm.active_div.value == "tab_cht") {
		oObj = oFrm.freq_cht ;

		if ( isElArray(oFrm.freq_cht) ) {
			for (i=0; i<oFrm.freq_cht.length; i++) {
				try {
					oFrm.trans_tbl[i].options.selectedIndex = oFrm.trans_cht[i].options.selectedIndex ;
					oFrm.freq_tbl[i].options.selectedIndex = oFrm.freq_cht[i].options.selectedIndex ;					
				} catch (er) {
					if ( oFrm.txt_var[i].value.length > 3 ) {
						try {
							oFrm.trans_tbl.options.selectedIndex = oFrm.trans_cht[i].options.selectedIndex ;
							oFrm.freq_tbl.options.selectedIndex = oFrm.freq_cht[i].options.selectedIndex ;							
						} catch (er) {}
					}
				} 
			}
		}
	} else {
		oObj = oFrm.freq ;
	}

	for (i=0; i<oObj.length; i++) sFreq += oObj[i].options.selectedIndex + "," ;

	aryFreq = sFreq.split(",") ;

	for (i=0; i<oFrm.chkVar.length; i++) {
		if (oFrm.chkVar[i].checked) {
			if (sFreq_cur == "") sFreq_cur = aryFreq[i] ;

			if (sFreq_cur != aryFreq[i]) {
				if (iAction == 0) {
					alert("You can only graph series of the same frequency.") ;
					return false;
				} else { oFrm.chkVar[i].checked = false ; }
			}
		}
	}
	return true ;
}

function viewSeries( sVar, sCmd, blnWnd, iOutFmt ) {
	var oFrm = document.frmMain;

	
	if (sVar.indexOf(".") == -1 && sVar.indexOf("%2E") == -1 ) { alert("You must enter a full mnemonic") ;	return false;	}

	if (sVar.indexOf("^") > -1 || sVar.indexOf("?") > -1) {
		alert("Wildcard characters '^' and '?' cannot be used in this context.") ;
		return false;
	}
	
	var intApp = ( oFrm.app ) ? parseInt(oFrm.app.value) : 1;
	var sURL = "";
	var sQString = "?mnemonic=" + doWBEscape(sVar) + "&cmd=" + sCmd + "&out_fmt=" + iOutFmt + "&app=" + intApp;
	
	// Force login by first going to gateway page.  
	// Gateway then redirects to xt_quickView.asp to launch order
	//var sURL = "/databuffet/shared/xt_quickView.asp?mnemonic=" + escape(sVar) + "&cmd=" + sCmd + "&out_fmt=" + iOutFmt + "&app=" + intApp;
	switch ( intApp ) {
		case 1:
			sURL = "/databuffet/pro/gateway_viewData.asp" + sQString;
			break;
		case 2:
		case 3:
			sURL = "/store/sp/gateway_viewData.asp" + sQString;
			break;
		default:
			sURL = "/databuffet/pro/gateway_viewData.asp" + sQString;
			break;
	}
	
	if (blnWnd) {
		var wnd = window.open( sURL, "quickView", "status,height=640,width=520,scrollbars,resizable" ) ;
		wnd.moveTo(480, 0);
		wnd.focus() ;
	} 	else {
		window.location = sURL ;
	}
}

function getInt( oObj ) {
	var iInt = parseInt( oObj.value ) ;
	
	if ( isNaN(iInt) ) {
		alert("You must enter an integer value.") ;
		oObj.value = 1 ;
		oObj.focus();
	} else {
		oObj.value = iInt ;
	}
}
