var actype=0;

function show(eid){
	document.getElementById(eid).style.visibility = 'visible';
}
function loadMenu(n,t,nalias){
	var url = '../qbuilder/submenu.aspx?node='+n;
	url=t==null?url:url+'&table='+t;
	url=nalias==null?url:url+'&n_alias='+nalias;
	setSubMenu(url);
}
function loadSigmaMenu(){
	setSubMenu('../qbuilder/submenu.aspx?sigma=true');
}
function loadKeyMenu(key){setSubMenu('../qbuilder/submenu.aspx?key='+key);}
function loadColMenu(alias,col,type){
	var url = '../qbuilder/submenu.aspx?alias='+alias+'&col='+col+'&ctype='+type;
	setSubMenu(url);
}
function loadAcColList(a1,a2){
	var oplist = document.getElementById('aoperator');
	var op = oplist.options[oplist.selectedIndex].text;
	var url = '../qbuilder/acColBuffer.aspx?a1='+a1+'&c1='+column()+'&op='+op+'&a2='+a2;
	document.getElementById('accollist').innerHTML = '<br>&nbsp;<img src="../img/loading.gif"></img>';
	window.parent.frames["actablebuf"].location = url;
}
function loadSAColList(alias){
	var url = '../qbuilder/acColBuffer.aspx?sa='+alias;
	document.getElementById('accollist').innerHTML = '<img src="../img/loading.gif"></img>';
	window.parent.frames["actablebuf"].location = url;
}
function setSubMenu(url){
	try{document.getElementById('menu').innerHTML = '<br>&nbsp;<img src="../img/loading.gif"></img>';}catch(ER){}
	window.parent.showMessage('');
	window.parent.frames['bbuffer'].location = url;
}
function showMenu(){
	document.getElementById('menu').innerHTML = top.frames['bbuffer'].document.body.innerHTML;
}
function showACColList(){
	document.getElementById('accollist').innerHTML = window.frames['actablebuf'].document.body.innerHTML;
}
function column(){
	var clist = document.getElementById('colddl');
	return clist.options[clist.selectedIndex].text.split(',')[0];
}
function op(){
	var oplist = document.getElementById('aoperator');
	var index = oplist.selectedIndex > -1?oplist.selectedIndex:0;
	return oplist.options[index].text;
}
function clearElement(ele){
	var e1 = document.getElementById(ele);
	e1.parentNode.removeChild(e1);
}
function fire(nalias){
	switch(actype){
		case 0:
			aselectcols(nalias);break;
		case 1:
			show('oplist');show('cchoice');break;
	} 
}
function setSigmas(nodes){
	n = nodes.split(',');
	var arg='';
	for(x=0;x<n.length;x++){
		if(n[x].length < 2)continue;
		if(arg.length>1)arg+=",";
		val = document.getElementById(n[x]+'_sigma').value;
		if(val.length > 0)
		arg+=n[x]+'_'+val;
	}
	window.parent.setBuild("?ssigmas="+arg);
}
function resetSigmas(){
	window.parent.setBuild("?resetsigmas=true");
}
function acconstant(node_alias){
	var val = document.getElementById('acvalue').value;
	window.parent.setBuild("?acconst="+node_alias+","+column()+","+op()+","+val);
}
function aselectcols(nalias){
	var list = document.getElementById('colddl').options;	
	if(list.selectedIndex == -1)alert('Please select at least one column');
	var arg = nalias+'.'+list[list.selectedIndex].text.split(',')[0];
	for(x=list.selectedIndex+1;x<list.length;x++)
		if(list[x].selected)
			arg+=','+nalias+'.'+list[x].text.split(',')[0];
	window.parent.setBuild("?aselectcols="+arg);
}
function aselectcolsall(){
	var list = document.getElementById('colddl').options;	
	if(list.selectedIndex == -1)alert('Please select at least one column');
	var arg = list[list.selectedIndex].text.split(',')[0];
	for(x=list.selectedIndex+1;x<list.length;x++)
		if(list[x].selected)
			arg+=','+list[x].text.split(',')[0];
	window.parent.setBuild("?aselectcolsall="+arg);
}
function aselectcolssome(){
	var list = document.getElementById('colddl').options;	
	if(list.selectedIndex == -1)alert('Please select at least one column');
	var arg = list[list.selectedIndex].text.split(',')[0];
	for(x=list.selectedIndex+1;x<list.length;x++)
		if(list[x].selected)
			arg+=','+list[x].text.split(',')[0];
	window.parent.setBuild("?aselectcolssome="+arg);
	
}
function atables(n){
	var list = document.getElementById('tableddl').options;
	if(list.selectedIndex == -1)alert('Please select at least one table');
	var arg = n+':'+list[list.selectedIndex].text;
	for(x=list.selectedIndex+1;x<list.length;x++)
		if(list[x].selected)
			arg+=','+n+':'+list[x].text;
	window.parent.setBuild("?atables="+arg);
}
function axnodes(n){
	if(n != null){
		window.parent.setBuild("?axnodes="+n);
		return;
	}
	var list = document.getElementById('nodeddl').options;
	if(list.selectedIndex == -1){alert('Please select at least one node');return;}
	var arg = list[list.selectedIndex].text;
	for(x=list.selectedIndex+1;x<list.length;x++)
		if(list[x].selected)
			arg+=','+list[x].text;
	window.parent.setBuild("?axnodes="+arg);
}
function awherecol(a1,c1,op,a2){
	var list = document.getElementById('colddl').options;	
	window.parent.setBuild("?awcol="+a1+","+c1+","+op+","+a2+","+list[list.selectedIndex].text.split(',')[0]);
	alert("?awcol="+a1+","+c1+","+op+","+a2+","+list[list.selectedIndex].text.Split(',')[0]);
}
function aregion(){window.parent.setBuild("?aregion=true");}
function asigmas(){window.parent.setBuild("?asigmas=true");}
function mregion(ra,dec,radius){window.parent.setBuild("?mregion="+ra+","+dec+","+radius);}
function rnode(n){window.parent.setBuild("?rnode="+n);}
function rregion(){window.parent.setBuild("?rregion=true");}
function rselectcol(a,c){window.parent.setBuild("?rscol="+a+","+c);}
function rselectcolall(c){window.parent.setBuild("?rscolall="+c);}
function rtable(n,table){window.parent.setBuild("?rtable="+n+","+table)}
function rnxnode(n,table){window.parent.setBuild("?rnxnode="+n+","+table);}
function rxnode(n,table){window.parent.setBuild("?rxnode="+n+","+table);}



