function select_3(qs){
	var pos = 'left=' + (screen.availWidth-10-625)/2 + ',top=' + (screen.availHeight-30-400)/2 
	win=open('/ml_tools/fckeditor/default.asp?'+qs,'editor',pos+'height=400,width=625,status=no,resizable=yes,menubar=no,scrollbars=no,location=no,directories=no, dependent=yes, modal=yes, dialog=yes, close=no ',false);
	win.focus();
}

function select_118(qs, form_name, c_name){
	link = '/ml_tools/color.asp?' + qs;
	c=eval('document.'+form_name+'.'+c_name+'.value');
	if(c < 0) c = 0;
	//alert('document.'+form_name+'.'+c_name+'.value');
	win=open(link + '&color=' + c,'color','menubar=no,toolbar=no,location=no,directories=no,status=no,scrollbars=1,resizable=1,width=200,height=282');
	win.focus();
}

function select_117(qs, form_name, c_name){
	link = '/ml_tools/character.asp?'+qs;
	c=eval('document.'+form_name+'.'+c_name+'.value');
	win=open(link + '&CharCode=' + c,'character','menubar=yes,toolbar=yes,location=yes,directories=no,status=yes,scrollbars=1,resizable=1,width=600,height=600');
	win.focus();
}

function select_114(qs){
	link = '/ml_tools/lexicon.asp?' + qs;
	win=open(link,'lexicon','menubar=no,toolbar=no,location=no,directories=no,status=no,scrollbars=1,resizable=1,width=500,height=500');
	win.focus();
}

function showWin() {
  win=open('','UserRef','menubar=no,toolbar=no,location=no,directories=no,status=no,scrollbars=1,resizable=0,width=750,height=550');
  win.focus();
}

function showImg() {
  win=open('','UserImg','menubar=no,toolbar=no,location=no,directories=no,status=no,scrollbars=1,resizable=0,width=750,height=550');
  win.focus();
}

function select_104(qs, form_name, date_name){
	link = '/ml_tools/calendar.asp?'+qs;
	d=eval('document.'+form_name+'.'+date_name+'.value');
	link = link + '&d=' + d
	//if (calendarWin == null || calculatorWin.closed) {
		//calendarWin=open(link,'calendar');
		calendarWin=open(link,'calendar','menubar=no,toolbar=no,location=no,directories=no,status=no,scrollbars=no,resizable=no,width=180,height=200');
	//else {
	//	calendarWin.location.href = link;
	//}
		calendarWin.focus();
}

/*
 * called by color selectors, obj is an array of form elements
 * that represent red green blue values
 */

function selectColor( obj ) {
	// calculate the center
	if (document.all) {
		var xMax = screen.width, yMax = screen.height;
	} else {
		if (document.layers) {
			var xMax = window.outerWidth, yMax = window.outerHeight;
		} else {
			var xMax = 640, yMax=480;
		}
	}
	
	var xOffset = (xMax - 330)/2, yOffset = (yMax - 250)/2;
	
	// check if window is open and give focus
	if (currentTool != null && !currentTool.closed) {
		currentTool.focus();
		return;
	} else {
		currentTool = null;
	}
	
	currentTarget = obj;
	
	//szRed = currentTarget[0].value;
	//szGreen = currentTarget[1].value;
	//szBlue = currentTarget[2].value;
	szColor = currentTarget[0].value;
	sParam = obj[2].value;
	sNullParam = obj[3].value;
	
	if (sNullParam != ''){
		sNullParam = '&null=' + sNullParam;
	} else {
		sNullParam = '';
	}
	
	//if (szRed == "" || szGreen == "" || szBlue == "")
	if (szColor == "") {
		colorSpec = "";
	} else {
		colorSpec = '&c=' + szColor + sParam + sNullParam;
	}
	
    currentTool = window.open('/ml_tools/color.asp?' + 'CallBackFunc=colorCallBack' + colorSpec, 'color', 'resizable=yes,width=200,height=282,screenX='+xOffset+',screenY='+yOffset+',top='+yOffset+',left='+xOffset+'');
	return;
}

/*
 * callback for color selectors
 */
function colorCallBack( actionId, wh ){
	// Clicked ok
	if (actionId == 0) {
		//red = wh.nRedColor;
		//green = wh.nGreenColor;
		//blue = wh.nBlueColor;
		szColor = wh.nColor;
		currentTarget[0].value = szColor;
		//currentTarget[1].value = green;
		//currentTarget[2].value = blue;
		sParam = currentTarget[2].value;
		
		//currentTarget[3].src = szURI + "/color.php?red="+red+"&green="+green+"&blue="+blue+"&x=30&y=20";
		currentTarget[1].src = "/ml_tools/color_img.asp?c=" + szColor + sParam;
		wh.close();
	//Clicked Apply
	} else if (actionId == 1) {
		//red = wh.nRedColor;
		//green = wh.nGreenColor;
		//blue = wh.nBlueColor;
		szColor = wh.nColor;
		//currentTarget[0].value = szColor;
		//currentTarget[1].value = green;
		//currentTarget[2].value = blue;
		sParam = currentTarget[2].value;
		//currentTarget[3].src = szURI + "/color.php?red="+red+"&green="+green+"&blue="+blue+"&x=30&y=20";
		currentTarget[1].src = "/ml_tools/color_img.asp?c=" + szColor + sParam;
		wh.focus();
	//window opened
	} else if (actionId == 3) {
		wh.focus();
	//canceled or unloaded window
	} else {
		currentTarget = null;
		currentTool = null;
		
		if (!wh.closed) {
			wh.close();
		}
	}
	
	return;
}

/*
 * update object to the defined colour
 */
 
function colorChanged( obj ){
	szColor = obj[0].value;
	sParam = obj[2].value;
    //red = obj[0].value;
    //green = obj[1].value;
    //blue = obj[2].value;
    //obj[3].src = szURI + "/color.php?red="+red+"&green="+green+"&blue="+blue+"&x=30&y=20";
    obj[1].src = "/ml_tools/color_img.asp?c=" + szColor + sParam;
    return;
}

/*
 * called by font selectors
 */
function selectFont( obj ) {
    // calculate the center
    if (document.all) {
        var xMax = screen.width, yMax = screen.height;
	} else {
		if (document.layers) {
			var xMax = window.outerWidth, yMax = window.outerHeight;
		} else {
			var xMax = 640, yMax=480;
		}
	}
	
	var xOffset = (xMax - 400)/2, yOffset = (yMax - 370)/2;
	
	if (currentTool != null && !currentTool.closed) {
		currentTool.focus();
		return;
	} else {
		currentTool = null;
	}
	
	szURL = "/ml_tools/font.asp?fontid=" + obj[0].value + "&size=" + obj[1].value + "&charset=" + obj[2].value + "&color=" + obj[3].value + "&outlinecolor=" + obj[4].value + "&bold=" + obj[5].value + "&italic=" + obj[6].value + "&outline=" + obj[7].value + "&underline=" + obj[8].value + "&null=" + obj[11].value + "&text=" + obj[12].value;
	currentTarget = obj;
	currentTool = window.open( szURL, 'browsewindow',
						'status=no,resizable=yes,width=400,height=370,screenX='+xOffset+',screenY='+yOffset+',top='+yOffset+',left='+xOffset+'');
	return;
}

/*
 * font picker callback function
 */
function fontCallBack( actionId, wh ){
	// Clicked ok or Apply
	if (actionId == 0 || actionId == 1)	{
		nFontID = wh.nFontID;
		currentTarget[0].value = nFontID;
		nSize = wh.nSize;
		currentTarget[1].value = nSize;
		nCharset = wh.nCharset;
		currentTarget[2].value = nCharset;
		nColor = wh.nColor;
		currentTarget[3].value = nColor;
		nOutlineColor = wh.nOutlineColor;
		currentTarget[4].value = nOutlineColor;
		nBold = wh.nBold;
		currentTarget[5].value = nBold;
		nItalic = wh.nItalic;
		currentTarget[6].value = nItalic;
		nOutline = wh.nOutline;
		currentTarget[7].value = nOutline;
		nUnderline = wh.nUnderline;
		currentTarget[8].value = nUnderline;
		//nText = wh.nText;
		//currentTarget[12].value = nText;
		
		//sParam = currentTarget[2].value;
		
		sParam = '';
		
		currentTarget[9].src = "/ml_tools/font_img.asp?fontid=" + nFontID + "&size=" + nSize + "&charset=" + nCharset + "&color=" + nColor + "&outlinecolor=" + nOutlineColor + "&bold=" + nBold + "&italic=" + nItalic + "&outline=" + nOutline + "&underline=" + nUnderline + "&text=" + currentTarget[12].value + sParam;
		
		// Clicked ok
		if (actionId == 0) {
			if (!wh.closed) {
				wh.close();
			}
		}
		//Clicked Apply 
		else if (actionId == 1) {
			wh.focus();
		}
	}
 	//window opened
	else if (actionId == 3)	{
		wh.focus();
	}
	//canceled or unloaded window
	else {
		currentTarget = null;
		currentTool = null;
		
		if (!wh.closed) {
			wh.close();
		}
	}
	
	return;
}

/*
 * function to commit a font change
 */
function fontChanged(obj) {
	//sParam = currentTarget[2].value;
	sParam = '';
	
	obj[9].src = "/ml_tools/font_img.asp?fontid=" + obj[0].value + "&size=" + obj[1].value + "&charset=" + obj[2].value + "&color=" + obj[3].value + "&outlinecolor=" + obj[4].value + "&bold=" + obj[5].value + "&italic=" + obj[6].value + "&outline=" + obj[7].value + "&underline=" + obj[8].value + "&text=" + obj[12].value + sParam;
	return;
}

/*
 * called by XY selectors
 */
function selectXY(FormName, Prefix) {
    // calculate the center
    if (document.all) {
        var xMax = screen.width, yMax = screen.height;
	} else {
		if (document.layers) {
			var xMax = window.outerWidth, yMax = window.outerHeight;
		} else {
			var xMax = 640, yMax=480;
		}
	}
	
	var xOffset = (xMax - 400)/2, yOffset = (yMax - 370)/2;
	
	if (currentTool != null && !currentTool.closed) {
		currentTool.close();
		currentTool = null;
		//currentTool.focus();
		//return;
	} else {
		currentTool = null;
	}
	
	currentTarget = new Array(3);
	var desc = eval('document.forms.'+FormName+'.'+Prefix+'XY_desc.value');
	currentTarget[0] = desc;
	currentTarget[1] = FormName;
	currentTarget[2] = Prefix;
	
	//obj = null;
		//var fp = currentTarget[3];
	//var qqq = document.getElementById(obj[3]+'XY_Div').innerHTML;
	var www = xGetElementById(Prefix+'XY_Div');
	//var www = currentTarget[0];
	//var qqq = eval(fp + 'XY_Div.innerHTML');
	//var qqq = obj[0].innerHTML
	var qqq = www.innerHTML;
	//alert(qqq);
	
	//szURL = "/ml_tools/coords.asp?" + fillCoordsSpecString(obj);
	//currentTool = window.open( szURL, 'coords', 'status=no,resizable=yes,width=400,height=370,screenX='+xOffset+',screenY='+yOffset+',top='+yOffset+',left='+xOffset+'');
	
	var cs = fillCoordsSpecString(currentTarget)
	currentTool = window.open('/ml_tools/coords.asp?' + cs, 'coords', 'status=no,resizable=yes,width=400,height=370,screenX='+xOffset+',screenY='+yOffset+',top='+yOffset+',left='+xOffset+'');
	
	//obj[1].QString.value = cs;
	//obj[1].action = '/ml_tools/coords.asp';
	//obj[1].target = 'coords';
	//obj[1].submit();
	
	document.CodeProperties.QString.value = cs;
	document.CodeProperties.action = '/ml_tools/coords.asp?' + cs;
	var t = document.CodeProperties.target;
	document.CodeProperties.target = 'coords';
	document.CodeProperties.submit();
	document.CodeProperties.target = t;
	currentTool.focus();
	return;
}

function fillCoordsSpecString( obj ) {
	var s = '';
	
	var as = obj[0].split(";")
	//alert(as.length);
	for (var i = 0; i < as.length; i++){
		if (as[i].indexOf('sign') >= 0) {
			//alert(as[i] + '.selectedIndex= ' + obj[i+5].selectedIndex);
			//combo.options[combo.selectedIndex].value
			//var t = obj[i+5].options[obj[i+5].selectedIndex].value;
			var to = 'document.forms.'+obj[1]+'.'+obj[2]+as[i];
			//alert(to);
			var t = eval(to + '.options[' + to + '.selectedIndex].value;');
			//alert(as[i] + '=' + t);
		} else {
			var t = eval('document.forms.'+obj[1]+'.'+obj[2]+as[i]+'.value');
			//var t = obj[i+5].value;
		}
		//alert('obj[' + (i+5) + ']= ' + t);
		//alert(as[i] + '=' + t);
		s += '&' + obj[2] + as[i] + '=' + t;
		//alert(s);
	}
	//alert('s= ' + s);
	var pr = eval('document.forms.'+obj[1]+'.'+obj[2]+'XY_param.value');
	var s1 = 'prefix=' + obj[2] + s;
	//alert(s1);
	var s2 = s1 + '&' + obj[2] + 'XY_param=' + pr + '&formName=' + obj[1];
	//alert('!!!   ' + s2 + '   !!!');
	return s2;
}

/*
 * font picker callback function
 */
function XYCallBack(actionId, wh, newParam){
	// Clicked ok or Apply
	if (actionId == 0 || actionId == 1)	{
		var newXY = wh.XY_DivHTML;
			
		//alert(newXY);
		var fp = currentTarget[2];
		currentTarget[0] = newParam;
		
		var www = xGetElementById(fp+'XY_Div');
		www.innerHTML = "";
		www.innerHTML = newXY;
		//document.getElementById(fp+'XY_Div').innerHTML = newXY;
		
		//var obj = wh.currentTarget;
		var obj = wh.currentTarget;
		var desc = obj[0];
		//alert(desc);
		//alert(wh.name);
		
		//var objValues = wh.currentTargetValues;
		var as = desc.split(";")
		
		for (var i = 0; i < as.length; i++){
			if (as[i].indexOf('sign') >= 0) {
				eval('document.forms.'+obj[1]+'.'+obj[2]+as[i]+'.selectedIndex = wh.document.forms.'+obj[1]+'.'+obj[2]+as[i]+'.selectedIndex');
			} else {
				eval('document.forms.'+obj[1]+'.'+obj[2]+as[i]+'.value = wh.document.forms.'+obj[1]+'.'+obj[2]+as[i]+'.value');
			}
			//alert(as[i]+'= document.forms.'+obj[1]+'.'+obj[2]+as[i]+'.value');
		}
		
		// Clicked ok
		if (actionId == 0) {
			if (!wh.closed) {
				wh.close();
			}
		}
		//Clicked Apply 
		else if (actionId == 1) {
			wh.focus();
		}
		currentTarget = null;
		currentTool = null;
	}
 	//window opened
	else if (actionId == 3)	{
		wh.focus();
	}
	//canceled or unloaded window
	else {
		currentTarget = null;
		currentTool = null;
		
		if (!wh.closed) {
			wh.close();
		}
	}
	
	return;
}

function xGetElementById(e) {
  if(typeof(e)!='string') return e;
  if(document.getElementById) e=document.getElementById(e);
  else if(document.all) e=document.all[e];
  else e=null;
  return e;
}
