function OnLoadForm()
{
	window.resizeTo(450,220);
	
	var objCboChoiceID=document.getElementById("cboCOrder");
	
	if(objCboChoiceID){
		window.resizeBy(0,30);
	}
	
	var objTxtColor=document.getElementById("txtColor");
	
	if(objTxtColor){
		//window.resizeBy(0,155);
	}
	
	var objCboType=document.getElementById("cboType");
	
	if(objCboType){
		//window.resizeBy(0,50);
	}
	
	var objDepValCaption=document.getElementById("DepValCaption");
	if(objDepValCaption){
		objDepValCaption.innerHTML=mstrDepValFldCaption;
	}
	
	var objDepValList=document.getElementById("DepValList");
	if(objDepValList){
		objDepValList.innerHTML="<select name='cboDepVal' id='cboDepVal' class='AdminComboBoxWidth'>" +
									mstrDepValOptions + "<option id='-1'></option></select>";
	}
				
	SetColor();
	
	SetFocus();
}

function Pressed(e)
{
    if(e.keyCode == 13){
		AddRow();
	}else{
		if(e.keyCode == 27){
			opener.CloseChildWindow(WIN_ADD_ROW);
		}
	}
}

function SetColor()
{
	var objColorSample=document.getElementById("ColorSample");
	var objTxtColor=document.getElementById("txtColor");
	var objType=document.getElementById("cboType");
	
	if(objColorSample){
		if(objTxtColor){
			if(objType){
				try{
					objColorSample.style.background=objTxtColor.value;
					
				}catch(e){
					alert(MSG_INVALID_COLOR);
					objTxtColor.focus();
					return false;
				}
				var lngType=objType.options[objType.selectedIndex].value;
					
				if(lngType=="1"){
					objColorSample.innerHTML="<img src='../../../theme/images/images/flag.gif'>";
					objColorSample.style.border="1px solid #000000";
					objColorSample.style.width="20px";
					objColorSample.style.height="16px";
					
				}else{
					objColorSample.innerHTML="Text";
					objColorSample.style.background="transparent";
					objColorSample.style.color=objTxtColor.value;
					objColorSample.style.border="none";
				}
			}
		}
	}
}

function SetFocus()
{ 
    var objTxtInput=document.getElementById("txtAddRow");
	
	if(objTxtInput){
		objTxtInput.focus();
	}
}


function AddRow(){
	var objTxtAddRow=document.getElementById("txtAddRow");
	if(objTxtAddRow){
		var strValue=objTxtAddRow.value;
		if (strValue === ""){
		    window.alert(MSG_ENTER_CHOICE);
		    SetFocus();
		}else{
			var lngCOID = "";
			var objRequest=opener.mobjHTTPrequest;
			var strProj = opener.GetProject();
			var strTableToAddRow = opener.GetTable();
			var strNewRow = g_MqRef.MqStr.MqEncodeURIComponent(strValue);
			var strColor="";
			var lngType=0;
			var lngDepVal=0;
			
			var objCboCOrder=document.getElementById("cboCOrder");
			if (objCboCOrder){
				lngCOID = objCboCOrder.options[objCboCOrder.selectedIndex].value;
			}
			
			var objTxtColor=document.getElementById("txtColor");
			if(objTxtColor){
				strColor=g_MqRef.MqStr.MqEncodeURIComponent(objTxtColor.value);
			}
			
			var objCboType=document.getElementById("cboType");
			if(objCboType){
				lngType=objCboType.options[objCboType.selectedIndex].value;
			}
			
			var objCboDepVal=document.getElementById("cboDepVal");
			if(objCboDepVal){
				lngDepVal=objCboDepVal.options[objCboDepVal.selectedIndex].value;
			}
			
			var strCurrentLocation=opener.mstrCurrentLocation;
			
			var strMessage=objRequest.Get(strCurrentLocation + "WCMQeDict.ASP?WCI=eDictAddRow&Proj=" 
						+ strProj + "&TableToAddRow=" + strTableToAddRow + "&NewRow=" + strNewRow + 
						"&NewCOID=" + lngCOID + "&Color=" + strColor + "&Type=" + lngType + "&DepVal=" + lngDepVal);
						
			if (strMessage==VALUE_ADDED_MSG){
				opener.GetFieldListByTable();
				if(!objCboCOrder){
					objTxtAddRow.value="";
					SetFocus();
				}else{
					window.location.reload();
				}
			}else{
				if(strMessage!=HTTP_REQ_CANCEL_PROCESS){
					alert(strMessage);
				}
			}
		}
	}
}