
// ===================================================================
// Author: SkyMark Corporation Development Team
// WWW: http://www.skymark.com/
// Common routines used by all project developed by SkyMark Corporation
// ===================================================================

// Global variables

// Store the row selected into array, so when clearing rows, get the value from the array
var aRowSelected = new Array();

// Adjustment of width of tools
var nToolWidthAdjust = 0.95;

// Offset of height of tools
var nToolHeightOffset = 0;

// Offset of height of tools
var sAreaName = "workingArea";

// Offset of height of tools(2)
// add by linliming, 07/13/2005, bug id 4650.
var sAreaName2 = "scrollArea";

// add by lianying 04/28/2005. bug id 3846.
var bDebug2	= true;

// add lianying 01/18/2005. bug 281. New Feature.
var img = null;
var myForm = null;
var nImgSize = 0;

var nHeight  = 0;
var nWidth   = 0;
var nGridWidthOffset = -6;
var nGridHeightOffset = 0;

// browsers
var bOpera = false;
var bIE = false;
var bFirefox = false;
var bSafari = false;

var nBrowserWidth = 1020;
var nBrowserHeight = 600;
var nGridWidthRatio = 0;
var bAdjustWidth = true;

//---------------String Section--------------------

// Check if the string is empty
// Param: value		the parameter to be evaluated
function isEmpty(value)
{
	var bEmpty = false;
	if (trimString(value) == "")
		bEmpty = true;

	return bEmpty;
}

function Trim(sValue)
{
	if(sValue.length < 1)
	{
		return"";
	}

	sValue = RTrim(sValue);
	sValue = LTrim(sValue);

	return sValue;
} //End Function

function RTrim(sValue)
{
	var w_space = String.fromCharCode(32);
	var v_length = sValue.length;
	var strTemp = "";
	if(v_length < 0)
	{
		return"";
	}

	var iTemp = v_length -1;
	while(iTemp > -1)
	{
		if(sValue.charAt(iTemp) == w_space)
		{
		}
		else
		{
			strTemp = sValue.substring(0,iTemp +1);
			break;
		}

		iTemp = iTemp-1;

	} //End While

	return strTemp;
} //End Function

function LTrim(sValue)
{
	var w_space = String.fromCharCode(32);
	if(v_length < 1)
	{
		return"";
	}

	var v_length = sValue.length;
	var strTemp = "";

	var iTemp = 0;

	while(iTemp < v_length)
	{
		if(sValue.charAt(iTemp) == w_space)
		{
		}
		else
		{
			strTemp = sValue.substring(iTemp,v_length);
			break;
		}

		iTemp = iTemp + 1;
	} //End While

	return strTemp;
} //End Function

// This function is used to trim String
// Param: 	str		the string to trim
function trimString (str)
{
	return Trim(str);
/* 	str = this != window? this : str;
  	return str.replace(/^\s+/g, '').replace(/\s+$/g, '');
*/
}

// Return text with the specified length
// Param: 	s			the text
//			maxlimit	the max limit
function truncate(s, maxlimit)
{
	if (s.value.length > maxlimit)
	{
		s.value = s.value.substring(0, maxlimit);
	}
}

// In String str, replace all the oldStrs with newStrs
// Param: str		the string
// 		  oldStr	the string to be replaced
// 		  newStr	the string to replace
function replaceString(str, oldStr, newStr)
{
	var sRetVal = "";
	var index = str.indexOf(oldStr);

	while(index != -1)
	{
		sRetVal = sRetVal + str.substring(0, index) + newStr;
		str = str.substring(index + oldStr.length);
		index = str.indexOf(oldStr);
	}

	sRetVal = sRetVal + str;

	return sRetVal;
}

//---------------Conversion Section--------------------//

// Convert string to an int
// Param: vStr	string to be converted
function strToInt(vStr)
{
	if (vStr == "")
		return 0;
	else
		return parseInt(vStr, 10);
}

// Convert string to a float
// Param: vStr	string to be converted
function strToFloat(vStr)
{
	if (vStr == "")
		return 0;
	else
		return parseFloat(vStr);
}

// Convert string to an array
// Param: vStr	string to be converted
function strToArray(vStr, vDelimiter)
{
	var aRet = new Array();
	var nPos = vStr.indexOf(vDelimiter);

	while (nPos != -1)
	{
		if (nPos != 0)
			aRet[aRet.length] = vStr.substring(0, nPos);
		else
			aRet[aRet.length] = "";

		if (vStr.length > nPos+1)
		{
			vStr = vStr.substring(nPos+1);
			nPos = vStr.indexOf(vDelimiter);
		}
		else
		{
			vStr = "";
			nPos = -1;
		}

	}

	if (vStr.length > 0)
		aRet[aRet.length] = vStr;

	return aRet;
}


// Convert int to a fix length string
// Param: vInt			The int value
//		  vLen			The length of result string
//		  vFillChar		The char that will be filled into string
function intToStr(vInt, vLen, vFillChar)
{
	var vRetVal = "" + vInt;

	if (vLen > 0)
	{
		while (vRetVal.length < vLen)
		{
			vRetVal = vFillChar + vRetVal;
		}
	}

	return vRetVal;
}



//-----------------Validation Section------------------------

// Validate if the given parameter is valid number
// Param: s		the number
function isValidNumber(s)
{
	var i;
	var hasDecimalPoint = false;

	if (isEmpty(s) || s=="." || s=="-")
	{
		return false;
	}

	for (i = 0; i < s.length; i++)
	{
	  var c = s.charAt(i);

	  if(!isDigit(c) && !(c=="." && !hasDecimalPoint) && !(i==0 && c=="-"))
	  	return false;

	  if (c==".")
	  	hasDecimalPoint = true;
	}

	return true;
}

// Add by haifeng 07/09/2004,bug id 5242,for "Valid Integer"
// Validate if the given parameter is valid Integer
// Param: s		the number
function isValidInteger(s)
{
	var i;

	if (isEmpty(s) || s.indexOf(".") != -1 || s=="-")
	{
		return false;
	}

	for (i = 0; i < s.length; i++)
	{
	  var c = s.charAt(i);

	  if(!isDigit(c) &&  !(i==0 && c=="-"))
	  	return false;

	}

	return true;
}

// Add by haifeng 07/12/2004,bug id 5242,for "Valid Integer"
// Validate if the given parameter is valid Integer
// Param: s		the number
function isInAreaNumber(s,minNum,maxNum)
{
	if (!isValidNumber(s))
	{
		return false;
	}

	if((strToFloat(s)>maxNum) || (strToFloat(s)<minNum))
	{
	    return false;
	}

	return true;
}

// Add by haifeng 03/24/05, bug id 945
// Validate if the given parameter is valid Integer
// Param: s		the input parameter to be validated
// Param: minInt		the min Integer
// Param: maxInt	the max Integer
function isAreaInteger(s,minInt,maxInt)
{
	if (!isValidInteger(s))
	{
		return false;
	}

	if((strToInt(s)>maxInt) || (strToInt(s)<minInt))
	{
	    return false;
	}

	return true;
}

// Validate Quote given the string
// Param: s		the input parameter to be validated
function validateQuotes(s)
{
	if (s.value.indexOf('"') != -1 || s.value.indexOf("'") != -1)
	{
		alert("Invalid entry! Double quote and single quote characters are not allowed.");
		s.disabled = false;

		while (s.value.indexOf("'") != -1)
		{
			s.value = s.value.replace("'", "");
		}

		while (s.value.indexOf('"') != -1)
		{
			s.value = s.value.replace('"', "");
		}

		s.focus();
	}
}

// Validate if The User ID has valid format or not. Valid User ID has A-Z, a-z, 0-9, "-", "_" and "." only.
// Param: 	s		the input parameter to be validated
function validateUserIdFormat(s)
{
	var ok = true;
	var c;
	for (var i=0; i<s.value.length; i++)
	{
		c = "" + s.value.substring(i, i+1);
		if(!isLetter(c) && !isDigit(c) && (c != "-") && (c != "_") && (c != "."))
		{
			ok = false;
			break;
		}
	}

	if (!ok)
	{
		alert("Invalid entry! Only letters, digits, and special characters '-', '_' and '.' are allowed.");

		var temp = "";
		for (var i=0; i<s.value.length; i++)
		{
			c = "" + s.value.substring(i, i+1);
			if(isLetter(c) || isDigit(c) || (c == "-") || (c == "_") || (c == "."))
			{
				temp = temp + c;
			}
		}
		s.value = temp;

		s.focus();
	}
}

// Validate if The Brainstorm Idea has valid format or not. Valid Brainstorm Idea has A-Z, a-z, 0-9, "-", "_" and "." only.
// Param: 	s		the input parameter to be validated
/*
function validateIdeaFormat(s)
{
	var ok = true;
	var c;
	for (var i=0; i<s.value.length; i++)
	{
		c = "" + s.value.substring(i, i+1);
		if(!isLetter(c) && !isDigit(c) && (c != "-") && (c != "_") && (c != ".")&& (c != " "))
		{
			ok = false;
			break;
		}
	}

	if (!ok)
	{
		alert("Invalid entry! Only letters, digits, and special characters '-', '_', ' ' and '.' are allowed.");

		var temp = "";
		for (var i=0; i<s.value.length; i++)
		{
			c = "" + s.value.substring(i, i+1);
			if(isLetter(c) || isDigit(c) || (c == "-") || (c == "_") || (c == "."))
			{
				temp = temp + c;
			}
		}
		s.value = temp;

		s.focus();
	}
}
*/

function validateIdeaFormat(s)
{	
	var ok = true;
	var c;
	for (var i=0; i<s.value.length; i++)
	{
		c = "" + s.value.substring(i, i+1);
		if((c == "#")|| (c == "%"))
		{
			ok = false;
			break;
		}
	}

	if (!ok)
	{
		alert("Invalid entry! '#' and '%' are not allowed.");

		var temp = "";
		for (var i=0; i<s.value.length; i++)
		{
			c = "" + s.value.substring(i, i+1);
			if((c != "#")&& (c != "%"))
			{
				temp = temp + c;
			}
		}
		s.value = temp;

		s.focus();
	}
}

// Validate if input is valid or not. Valid input has 0-9 only.


// Param: s		the input parameter to be validated
function validateDigitFormat(s)
{
	if(isEmpty(s))
	{
		return false;
	}

	var i;
	for (i = 0; i < s.length; i++)
	{
	  var c = s.charAt(i);

	  if(!isDigit(c))
	  	return false;
	}
	return true;
}

// Returns true if character c is an English letter (A .. Z, a..z).
// Param: c		the input parameter to be evaluated
function isLetter (c)
{
	return ( ((c >= "a") && (c <= "z")) || ((c >= "A") && (c <= "Z")) );
}

// Returns true if character c is a digit between 0 to 9.
// Param: c		the input parameter to be evaluated
function isDigit (c)
{
	return ((c >= "0") && (c <= "9"));
}

// Validate if the given parameter is positive number
// Param: c		the input parameter to be evaluated
function isPositiveNumber(c)
{
	var num = parseFloat(c);

	return (num != null && num > 0);
}

// Validate if the given parameter is a positive integer
// Param: s		the input parameter to be evaluated
function isPositiveInteger(s)
{
	var i;

	if (!isPositiveNumber(s))
	{
		return false;
	}

	for (i = 0; i < s.length; i++)
	{
	  var c = s.charAt(i);

	  if(!isDigit(c))
	  	return false;
	}

	return true;
}

// Validate if the given parameter is number
// Param: c		the input parameter to be evaluated
function isNumber(c)
{
	var num = parseFloat(c);

	return (num != null);
}

// Validate the double quotes
// Param: s		the input parameter to be validated
function validateDoubleQuote(s)
{
	if (s.value.indexOf('"') != -1)
	{
		alert("Invalid entry! Double quotes are not allowed.");
		s.disabled = false;

		while (s.value.indexOf('"') != -1)
		{
			s.value = s.value.replace('"', "");
		}

		s.focus();
	}
}

// Valid if the given string is in a valid email format
// Param: str		the input parameter to be evaluated
function isValidEmail(str)
{
	// are regular expressions supported?
	var supported = 0;
	if (window.RegExp)
	{
		var tempStr = "a";
		var tempReg = new RegExp(tempStr);
		if (tempReg.test(tempStr))
			supported = 1;
	}

	if (!supported)
		return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);

	var r1 = new RegExp("(@.*@)|(\\.\\.)|(@\\.)|(^\\.)");
	var r2 = new RegExp("^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$");

	return (!r1.test(str) && r2.test(str));
}
// add lianying 01/26/2005. bug id 2547.
// Valid if the given string is in a valid email format
// Param: str		the input parameter to be evaluated
function isValidEmails(str)
{
    var aEmail = new Array();
    var bValidEmail = true;
    var sEmail = replaceString((str),";",",");
    aEmail = sEmail.split(",");
    for (var i=0;i<aEmail.length;i++)
    {
        if (!isEmpty(aEmail[i]))
        {
            if (!isValidEmail(aEmail[i]))
            {
                bValidEmail = false;
                break;
            }
        }
    }
    return bValidEmail;
}

//---------------Tables Related Section-----------------//

// Get table body
// Param: vArea 		the area of table body
function getTableBody(vArea)
{
    // add by lianying 04/28/2005. bug id 3846.
    // Modify by linliming, 03/15/2005, support in more browses.
    var vSpecObj;
    try
    {
        var updDiv = document.getElementById(vArea);
        
        if(updDiv.childNodes.length>0){
			      for(i=updDiv.childNodes.length-1 ; i>=0 ;i--)		
				    {
						if((updDiv.childNodes[i].nodeName.toUpperCase()!="#TEXT"))
						{
							vSpecObj = updDiv.childNodes[i] ;
							break ;			
						}
				    }
		    
				    for(i=vSpecObj.childNodes.length-1 ; i>=0; i--)
				    {
				    	 if((vSpecObj.childNodes[i].nodeName.toUpperCase() != "#TEXT"))
				    	 {
				    	 	 vSpecObj = vSpecObj.childNodes[i];
				    	 	 break;
				    	 }
				    }
	      } 
	      else 
	      {
					vSpecObj=updDiv;
	      } 
        //				Table		 TableBody
       // return updDiv.childNodes[0].childNodes[0];
       return vSpecObj;
    }
    catch(ex)
    {
        if (bDebug2)
        {
            throw ex;
        }
        else
        {
            ;
        }
    }
}

// Get first <td> in the table area defined
// Param: 	vArea 		the area of table body
//			vRow		the row selected
function getFirstTD(vArea, vRow)
{
    var updDiv = document.getElementById(vArea);
	//				TableBody			Row
	//return getTableBody(vArea).childNodes[vRow].childNodes[0];
	var vObj = getSpecialObject(vRow,"TR",getTableBody(vArea)) ;
	vObj = getSpecialObject(0,"TD",vObj) ; 
	return vObj ;

}

// Get textarea
// Param: 	vArea 		the area of table body
//			vRow		the row selected
//			vCol		the column selected
//			vOffset		the offset of textarea position
function getTextArea(vArea, vRow, vCol, vOffset)
{
	var updDiv = document.getElementById(vArea);
	var vObj = getSpecialObject(vRow,"TR",getTableBody(vArea)) ;
	vObj = getSpecialObject(vCol-1,"TD",vObj) ;	
	vObj = getObjectWithoutComment(vOffset,vObj) ;	
	return vObj ;
//	vObj = getTableBody(vArea).childNodes[vRow].childNodes[vCol-1].childNodes[vOffset] ;
    //				TableBody			Row					Cell		TextArea
//  return getTableBody(vArea).childNodes[vRow].childNodes[vCol-1].childNodes[vOffset];
}

// Validate if it is the last row
// Param: 	vArea 		the area of table body
//			vRow		the row selected
function isLastRow(vArea, vRow)
{
	return (getTableBody(vArea).childNodes.length == (vRow+1));  // one header row
}

// Deselect row
// Param: 	vArea 		the area of table body
//			vRow		the row selected
function deselectRow(vArea, vRow)
{
//oText.value = "PMTBox line 601 deselectRow() \n" + oText.value ;
	if (prvSelectRow(vArea, vRow+nRowOffset, ""))
		nSelectedRow = 0;
}

//Select row
//Param: 	vArea 		the area of table body
//			vRow		the row selected
function selectRow(vArea, vRow)
{
	if (nSelectedCol > 0)
		deselectCol(vArea, nSelectedCol);
//oText.value = "PMTBox line 613 selectRow() \n" + oText.value ;
	if (prvSelectRow(vArea, vRow+nRowOffset, COLOR_SELECTED)){
		nSelectedRow = vRow;
	}
}

// Select row (muliple)
// Param: 	vArea 		the area of table body
//			vRow		the row selected
function selectRowMultiple(vArea, vRow)
{
	var ctrlPressed=false;
	var shiftPressed=false;
	
	if (window.event)
	{
		shiftPressed=window.event.shiftKey;
		ctrlPressed =window.event.ctrlKey;
	}

	if (ctrlPressed)
	{
		if (aRows[vRow-1] > 0)
		{
//oText.value = "PMTBox line 756 selectRowMultiple() \n" + oText.value ;
			deselectRow(vArea, vRow);
		}
		else
		{
    	selectRow(vArea, vRow);
    	aRowSelected[aRowSelected.length] = vRow;
		}
	}
  else if (shiftPressed)
  {
  	clearRows(vArea);

		if (nSelectedRow < 1)
			nSelectedRow = 1;

  	if (nSelectedRow < vRow)
  	{
    	for (i=nSelectedRow; i<=vRow; i++)
    	{
		    selectRow(vArea, i);
	    	aRowSelected[aRowSelected.length] = i;
	    }
		}
		else
		{
			for (i=vRow; i<=nSelectedRow; i++)
    	{
		    selectRow(vArea, i);
	    	aRowSelected[aRowSelected.length] = i;
	    }
		}
	}
  else
  {
  	clearRows(vArea);
  	selectRow(vArea, vRow);
  	aRowSelected[aRowSelected.length] = vRow;
  }

  nSelectedRow = vRow;
}

// Highlight the selected row with the given color - 'vValue'
// Param: 	vArea 		the area of table body
//			vRow		the row selected
//			vValue		the color to used for highlight the row
function prvSelectRow(vArea, vRow, vValue)
{
	var myTableBody = getTableBody(vArea);
	var nRowLen = getObjectCountWithoutComment(myTableBody);
	
	if ((vRow == 0) || (vRow >= nRowLen))
	{
		return false;
	}
	else
	{
		//var myRow = myTableBody.childNodes[vRow];
		var myRow = getSpecialObject(vRow,"TR",myTableBody) ;		
	//oText.value = "PMTBox line 691 vRow =" + vRow + ", myRow =" +myRow + "\n" + oText.value ;
		myRow.bgColor = vValue;
		return true;
	}
}

// Select whole col.
// When user clicks on a column header cell, the whole column will be selected and
// displayed in different color.
// Param: 	vArea 		the area of table body
//			vCol		the column selected
function selectCol(vArea, vCol)
{
	if (nSelectedRow > 0)
	{
//oText.value = "PMTBox line 707 selectCol() \n" + oText.value ;
		deselectRow(vArea, nSelectedRow);
	}

	if (prvSelectCol(vArea, vCol+nColOffset, COLOR_SELECTED))
		nSelectedCol = vCol;
}

// Deselect column
// Param: 	vArea 		the area of table body
//			vCol		the column selected
function deselectCol(vArea, vCol)
{
	if (prvSelectCol(vArea, vCol+nColOffset, ""))
		nSelectedCol = 0;
}

// Highlight selected column with the give color - vValue
// Param: 	vArea 		the area of table body
// 			vCol		the column selected
//			vValue		the color to used for highlight the column
function prvSelectCol(vArea, vCol, vValue)
{   
	var myTableBody = getTableBody(vArea);
	var nRowsLen = getObjectCountWithoutComment(myTableBody);
	if (nRowsLen == 0)
		return false;
    var vTempObj = getObjectWithoutComment(1, myTableBody);	
    
    var nTempLen = getObjectCountWithoutComment(vTempObj);
    
	if ((vCol == 0) || (vCol >= nTempLen))	
	//if ((vCol == 0) || (vCol >= vTempObj.childNodes.length))
		return false;	
	//for(i=1; i<myTableBody.childNodes.length; i++)
	for(var a = 1; a < nRowsLen; a++)	
	{
		  //var myRow = myTableBody.childNodes[i];		
		var myRow = getObjectWithoutComment(a, myTableBody);
		var nMyRowLen = getObjectCountWithoutComment(myRow);

		//for (j=0; j < myRow.childNodes.length; j++)
		for (var j=0; j < nMyRowLen; j++)	
		{
			//myRow.childNodes[vCol].bgColor = vValue;
			getObjectWithoutComment(vCol, myRow).bgColor = vValue;
		}
	}
	return true;
}

// Change select row
// Param: 	vArea		the area of table body
//			vNewRow		the new row selected
//			vOldRow		the previous selected row
function changeSelectRow(vArea, vNewRow, vOldRow)
{
//oText.value = "PMTBox line 755 changeSelectRow() \n" + oText.value ;
	//If vOldRow == -1, clear all rows(mulitply selection)
	if(strToInt(vOldRow) == -1)
		clearRows(vArea);
	else if(strToInt(vOldRow) > 0)
	{
//oText.value = "PMTBox line 756 changeSelectRow() \n" + oText.value ;
		deselectRow(vArea, vOldRow);
	}
	selectRow(vArea, vNewRow);
	nSelectedRow = vNewRow;

	//If changeSelectRow() is called, store nSelectedRow to the row selected array
	aRowSelected[aRowSelected.length] = nSelectedRow;
}

// Clear selected row
// Param:	vAreaName	Working area name
function clearRows(vAreaName)
{
	var myTableBody = getTableBody(vAreaName);
	var nRowsLen = getObjectCountWithoutComment(myTableBody);
	
	for (var k=1; k < nRowsLen-1; k++)
	{
//oText.value = "PMTBox line 777 clearRows() vAreaName = " + vAreaName + ", i=" + i + "\n" + oText.value ;
    deselectRow(vAreaName, k);
  }
 	aRowSelected = new Array();
}

// Delete a row
// Param:	vSelected	The row number
//			vAreaName	Working area name
function deleteRow(vSelected, vAreaName)
{
	if (vSelected == 0)
		return 0;

    var myTableBody = getTableBody(vAreaName);

    // remove the row from Table body
    var vTempObj = getObjectWithoutComment(vSelected, myTableBody);
	myTableBody.removeChild(vTempObj);
	var nRowsLen = getObjectCountWithoutComment(myTableBody);

	if (vSelected > -1)
		if (nRowsLen == 0)
			vSelected = 0;
		else
			vSelected = nRowsLen - 1;   
						
	adjustCellNameByRow(myTableBody, vSelected, -1, vAreaName);

	return vSelected;
}

//---------------NEW CELLS CREATION SECTION-----------------//
// Create a new text area cell.
// Param:	vRowColStr			The row/col string name
//			vHeight				The height of the textarea
//			vWidth				The width of the textarea
//			vTitle				Is it title cell?
function newTextArea(vRowColStr, vHeight, vWidth, vTitle)
{
	// Create a new cell
	var myCell = document.createElement("TD");

	// Create a new input field
	var myText = document.createElement("TEXTAREA");

	// Set input field attributes.
	if (vTitle)
	{
		// Title Row
		//myText.setAttribute("className", "header");
		myText.className = "header" ;
	}
	else
	{
		// Cell Rows
		//myText.setAttribute("className", "cell");
		myText.className = "cell" ;
	}

	myText.setAttribute("name", "IT" + vRowColStr);
	myText.setAttribute("id", "IT" + vRowColStr);
	myText.setAttribute("wrap", "virtual");
	myText.setAttribute("cols", vWidth);
	myText.setAttribute("rows", vHeight);

	// appends the Text Node we created into the cell TD
	myCell.appendChild(myText);

	// Set cell attributes.
	myCell.setAttribute("name", "IC" + vRowColStr);
	myCell.setAttribute("id", "DROP" + vRowColStr);

	return myCell;
}

// Create a new text area (with calendar button) cell.
// Param:	vRowColStr			The row/col string name
//			vHeight				The height of the row
//			vWidth				The width of the row
//			vTitle				Is it title cell?
function newTextAreaWithCalendar(vRowColStr, vHeight, vWidth, vTitle)
{
	// Create a new cell
	var myCell = document.createElement("TD");

	// Create a new input field
	var myText = document.createElement("TEXTAREA");

	// Set input field attributes.
	if (vTitle)
	{
		// Title Row
		//myText.setAttribute("className", "header");
		myText.className = "header";
	}
	else
	{
		// Cell Rows
		//myText.setAttribute("className", "cell2");
		myText.className = "cell2";
	}
	myText.setAttribute("name", "IT" + vRowColStr);
	myText.setAttribute("id", "IT" + vRowColStr);
	myText.setAttribute("wrap", "virtual");
	myText.setAttribute("cols", vWidth);
	myText.setAttribute("rows", vHeight);

	if (!vTitle)
		myCell.setAttribute("id", "cell");

	// Create a new input field
	var myImage = document.createElement("IMG");

	// Set input field attributes.
	myImage.setAttribute("name", "IT" + vRowColStr);
	myImage.setAttribute("id", "IT" + vRowColStr);
	myImage.setAttribute("align", "middle");
	myImage.setAttribute("src", "image/Calendar.gif");

	// appends the Text Node we created into the cell TD
	myCell.appendChild(myText);

	// appends the Text Node we created into the cell TD
	myCell.appendChild(myImage);

	// Set cell attributes.
	myCell.setAttribute("name", "IC" + vRowColStr);
	myCell.setAttribute("id", "DROP" + vRowColStr);
	return myCell;
}

// Create a new combobox cell which contain by span.
// Param: vRowColStr			The row/col string name
//		  vMultiple				Is user allowed multiple selection? (true of false)
//		  v_aOptionItemIDs   	The array of option items' value in select box
//		  v_aOptionItemTexts		The array of option items' text in select box
// add by xiahaobo ,01/27/2005 ,bug id 760
function nenewComboBoxWithSpan(vRowColStr, vMultiple, v_aOptionItemIDs, v_aOptionItemTexts)
{
	// Create a new cell
	var myCell = document.createElement("TD");
	// Create a new Span container
	var mySpanContain = document.createElement("SPAN") ;
	mySpanContain.setAttribute("name", "TD" + vRowColStr + "spn");
	mySpanContain.setAttribute("id", "TD" + vRowColStr + "spn");
	//mySpanContain.setAttribute("className", "spanwithselect");
	mySpanContain.className = "spanwithselect" ;
	// create a new combox
	var myComboBox = document.createElement("SELECT");
	myComboBox.setAttribute("name", "IT" + vRowColStr);
	myComboBox.multiple = false ;
	//myComboBox.setAttribute("multiple", false);
	for(var i=0; i < v_aOptionItemIDs.length; i++){
		var myOption = new Option();
		myComboBox.appendChild(myOption);
		myComboBox.options[i].value = v_aOptionItemIDs[i];
		//This prevents the long text for select option
		if(v_aOptionItemTexts[i].length > 15)
			myComboBox.options[i].text = v_aOptionItemTexts[i].substring(0,15);
		else
			myComboBox.options[i].text = v_aOptionItemTexts[i];
	}
	myComboBox.options[0].selected = true ;
	myComboBox.setAttribute("class", "smallselect");
	myComboBox.setAttribute("className", "smallselect");

	// appends the Text Node we created into the cell TD
	mySpanContain.appendChild(myComboBox) ;

	var mySpanDisplay = document.createElement("SPAN") ;
	mySpanDisplay.setAttribute("name", "TD" + vRowColStr + "spndsp");
	mySpanDisplay.setAttribute("id", "TD" + vRowColStr + "spndsp");
	mySpanDisplay.setAttribute("className", "spannoselect");
	mySpanDisplay.setAttribute("innerHtml", "Unassigned");
	mySpanContain.style.display = "none" ;
	mySpanDisplay.style.display = "" ;
	myCell.appendChild(mySpanContain);
	myCell.appendChild(mySpanDisplay) ;
	// Set cell attributes.
	myCell.setAttribute("name", "IC" + vRowColStr);
	myCell.setAttribute("id", "DROP" + vRowColStr);
	return myCell;
}

// Create a new combobox cell.
// Param: vRowColStr			The row/col string name
//		  vMultiple				Is user allowed multiple selection? (true of false)
//		  v_aOptionItemIDs   	The array of option items' value in select box
//		  v_aOptionItemTexts		The array of option items' text in select box
//			vSize						the size of the combobox
function newComboBox(vRowColStr, vMultiple, v_aOptionItemIDs, v_aOptionItemTexts, vSize)
{
	// Create a new cell
	var myCell = document.createElement("TD");

	// Create a new input field
	var myComboBox = document.createElement("SELECT");
	myComboBox.setAttribute("name", "IT" + vRowColStr);
	myComboBox.setAttribute("id", "IT" + vRowColStr);
	myComboBox.multiple = vMultiple;	//works in IE and Firefox
	myComboBox.size = vSize;

	for(var i=0; i < v_aOptionItemIDs.length; i++)
	{
		var myOption = new Option();
		myComboBox.appendChild(myOption);
		myComboBox.options[i].value = v_aOptionItemIDs[i];
		//This prevents the long text for select option
		if(v_aOptionItemTexts[i].length > 15)
			myComboBox.options[i].text = v_aOptionItemTexts[i].substring(0,15);
		else
			myComboBox.options[i].text = v_aOptionItemTexts[i];
	}
	myComboBox.setAttribute("class", "smallselect");
	myComboBox.setAttribute("className", "smallselect");

	// appends the Text Node we created into the cell TD
	myCell.appendChild(myComboBox);

	// Set cell attributes.
	myCell.setAttribute("name", "IC" + vRowColStr);
	myCell.setAttribute("id", "IC" + vRowColStr);

	return myCell;
}

// This method creates a new checkbox cell
// Param: vRowColStr		The row/col string name
//		  vChecked			Is the checkboxed default as checked? (true or false)
function newCheckBox(vRowColStr, vChecked)
{
	// Create a new cell
	var myCell = document.createElement("TD");

	// Create a new input field
	var myCheckBox = document.createElement("INPUT");
	myCheckBox.setAttribute("type", "CHECKBOX");
	myCheckBox.setAttribute("name", "IT" + vRowColStr);
	myCheckBox.setAttribute("id", "IT" + vRowColStr);
	//myCheckBox.setAttribute("checked", vChecked);	
	myCheckBox.checked = vChecked;
	
	// appends the Text Node we created into the cell TD
	myCell.appendChild(myCheckBox);

	// Set cell attributes.
	myCell.setAttribute("name", "IC" + vRowColStr);
	myCell.setAttribute("id", "IC" + vRowColStr);

	return myCell;
}

// This method creates a new checkbox cell
// Param: vRowColStr		The row/col string name
//		  vChecked			Is the checkboxed default as checked? (true or false)
function newTextBoxForCheckBox(vRowColStr, vChecked)
{
	// Create a new cell
	var myCell = document.createElement("TD");

	// Create a new input field
	var myCheckBox = document.createElement("INPUT");
	myCheckBox.setAttribute("name", "IT" + vRowColStr);
	myCheckBox.setAttribute("id", "IT" + vRowColStr);
	myCheckBox.setAttribute("value", vChecked);
	myCheckBox.setAttribute("type", "textbox");
	myCheckBox.setAttribute("readOnly","true");
	//myCheckBox.setAttribute("classname","textboxforcheck") ; oddly, Input's attribute havn't classname

	// appends the Text Node we created into the cell TD
	myCell.appendChild(myCheckBox);

	// Set cell attributes.
	myCell.setAttribute("name", "IC" + vRowColStr);
	myCell.setAttribute("id", "DROP" + vRowColStr);
	return myCell;
}

// Create a new image link.
// Param:	vRowColStr			The row/col string name
function newImageLink(vRowColStr, vWidth)
{
	// Create a new cell
	var myCell = document.createElement("TD");

	// Create a new input field
	var myA = document.createElement("A");

	// Create a new input field
	var myImage = document.createElement("IMG");

	// Set input field attributes.
	myImage.setAttribute("name", "IT" + vRowColStr);
	myImage.setAttribute("id", "IT" + vRowColStr);
	// appends the Text Node we created into the cell TD
	myA.appendChild(myImage);

	myCell.appendChild(myA);

	// Set cell attributes.
	myCell.setAttribute("name", "IC" + vRowColStr);
	myCell.setAttribute("id", "DROP" + vRowColStr);

	myCell.setAttribute("width", vWidth);
	return myCell;
}

// Creates a new image cell
// Param:	vRowColStr			The row/col string name
// 				vWidth					The width of the cell
function newImage(vRowColStr, vWidth)
{
	// Create a new cell
	var myCell = document.createElement("TD");

	// Create a new input field
	var myImage = document.createElement("IMG");

	// Set input field attributes.
	myImage.setAttribute("name", "IT" + vRowColStr);
	myImage.setAttribute("id", "IT" + vRowColStr);

	myCell.appendChild(myImage);

	// Set cell attributes.
	myCell.setAttribute("name", "IC" + vRowColStr);
	myCell.setAttribute("id", "DROP" + vRowColStr);

	myCell.setAttribute("width", vWidth);

	return myCell;
}


// Creates a new empty cell
// Param: vRowColStr	The row/col string name
//		  vWidth		The width of the cell
function newEmptyCell(vRowColStr, vWidth)
{
	// Create a new cell
	var myCell = document.createElement("TD");

	// Set cell attributes.
	myCell.setAttribute("name", "IC" + vRowColStr);
	myCell.setAttribute("id", "DROP" + vRowColStr);
	myCell.setAttribute("width", vWidth);
	
	// modified by zhanghuajie 060328 ,for supporting FireFox
	myCell.setAttribute("innerHTML", "");

	return myCell;
}

// Create Row Header Cell
// Param: vName		The name of the cell
//	      vText		The text that will be displayed in the cell.
function newRowHeaderCell(vName, vTo){
	var myCell = document.createElement("TD");
	// Create a new input field
	var sText = "";

	if(vTo > 0)
		sText = ""+vTo;
	
	myCell.innerHTML = sText ;
	myCell.id = vName ;
	myCell.className = "rowheader";
	myCell.setAttribute("class", "rowheader"); //for firefox
	//myCell.setAttribute("innerText", sText);
	//myCell.setAttribute("name", vName);
	//myCell.setAttribute("className", "rowheader");

	return myCell;
}

// Create Column Header Cell
// Param: vName		The name of the cell
//		  vText		The text that will be displayed in the cell.
function newColumnHeaderCell(vName, vText)
{
	var myCell = document.createElement("TD");

// modified by zhanghuajie 060328 ,for supporting FireFox
     myCell.innerHTML = vText;
     myCell.id = vName;
     myCell.setAttribute("class", "colHeader");
     myCell.className = "colHeader";     
     
	//myCell.setAttribute("innerHTML", vText);
	//myCell.setAttribute("name", vName);
	//myCell.setAttribute("className", "colHeader");

	return myCell;
}

// Create an input cell. An input cell is a table cell that has an input text area field.
// Param: vRowColStr		A string that has Row/Column data that will be used to
//						    generate cell name. The format of the string is: CCRRR
//		  vTextAreaHeight	The row number of text area
//	   	  vTextAreaWidth	The col number of text area
//		  vWidth			The width of the cell (in pixel)
//		  vTitle			a boolean value that indicates if this cell is a title cell.
function newInputCell(vRowColStr, vTextAreaHeight, vTextAreaWidth, vWidth, vTitle, vValue)
{
	// Create a new cell
	var myCell = document.createElement("TD");

	// Set cell attributes.
	myCell.setAttribute("name", "IC" + vRowColStr);
	myCell.setAttribute("id", "DROP" + vRowColStr);

	if (vWidth > 0)
		myCell.setAttribute("width", vWidth);

	// Create a new input field
	var myText = document.createElement("TEXTAREA");

	// Set input field attributes.
	if (vTitle)
	{
		// Title Row
		//myText.setAttribute("className", "header");
		myText.setAttribute("class", "header");
		myText.className = "header" ;
	}
	else
	{
		// Cell Rows
		//myText.setAttribute("className", "cell");
		myText.setAttribute("class", "cell");
		myText.className = "cell" ;
	}
	myText.setAttribute("name", "IT" + vRowColStr);
	myText.setAttribute("id", "IT" + vRowColStr);
	myText.setAttribute("value", vValue);
	myText.setAttribute("wrap", "virtual");

	if (vTextAreaWidth > 0)
		myText.setAttribute("cols", vTextAreaWidth);

	if (vTextAreaHeight > 0)
		myText.setAttribute("rows", vTextAreaHeight);

	// appends the Text Node we created into the cell TD
	myCell.appendChild(myText);


	return myCell;
}

// Hide the row
// Param: 	vArea		the area of table body
//			nRow		the new row
//			nRowOffset	the row offset
function hideRow(vArea, nRow, nRowOffset)
{
	var myTableBody = getTableBody(vArea);

	if (nRow+nRowOffset < getObjectCountWithoutComment(myTableBody))
	{
	    var vTempObj = getObjectWithoutComment(nRow+nRowOffset, myTableBody);
		vTempObj.style.display="none";
	}
}

// Show the row
// Param: 	vArea		the area of table body
//			nRow		the new row
//			nRowOffset	the row offset
function showRow(vArea, nRow, nRowOffset)
{
	var myTableBody = getTableBody(vArea);
	var vTempObj = getObjectWithoutComment(nRow+nRowOffset-1, myTableBody);
	vTempObj.style.display="";
}

// Alert the given text if it is not empty
// Param: vTxt		the text to display in 'Alert' message box
function displayText(vTxt)
{
	if(!isEmpty(vTxt))
			alert(vTxt);
}

// Reset the given field
// Param: vField	the field to be reset
function resetField(vField)
{
	vField.value = "";
	vField.focus();
}

// Adjust the row height of the given two or three textarea
// Param: vItemArea1			the first textarea
//		  vItemArea2			the second textarea
//		  vItemArea3			the third textarea
function adjustRowHeight(vTextArea1, vTextArea2, vTextArea3)
{
	//If there are three textarea to compare
	if(vTextArea3 != "")
	{
		var hHeight = calTextAreaHeight(vTextArea1);
		var tempHeight1 = calTextAreaHeight(vTextArea2);
		var tempHeight2 = calTextAreaHeight(vTextArea3);

		if (tempHeight1 > hHeight)
			hHeight = tempHeight1;

		if (tempHeight2 > hHeight)
			hHeight = tempHeight2;

		vTextArea1.rows = hHeight;
		vTextArea2.rows = hHeight;
		vTextArea3.rows = hHeight;
	}
	//If there are only two textarea to compare
	else
	{
		var hHeight = calTextAreaHeight(vTextArea1);
		var tempHeight = calTextAreaHeight(vTextArea2);

		if (tempHeight > hHeight)
			hHeight = tempHeight;

		vTextArea1.rows = hHeight;
		vTextArea2.rows = hHeight;
	}
}

// Select a cell by clicking
function onCellClick(e)
{
	var current = getDragDropObject(e);
	
	if(current.nodeName == "TEXTAREA")
	    current = current.parentNode;
	
	if(current.nodeName == "TD")
	{
		//var ta = current.childNodes[0];
		var ta = getFirstObjectWithoutComment(current);
		if((ta.nodeName == "TEXTAREA") && !ta.disabled)
		{
			ta.focus();
			setCaretToEnd(ta);
		}
	}
}

// Set the cursor to the end the the textarea
function setCaretToEnd(vTextArea)
{
  if (vTextArea.createTextRange)
  {
    var r = vTextArea.createTextRange();
    r.moveStart('character', vTextArea.value.length);
    r.select();
  }
}


/* add by lianying 04/27/2005.  bug id 629.
 * add showEmailToWhom() and doModalLocation() method.
 * intent :     in the MyAI and MyCal send email.
 * Display email page when we know the user ID
 * Param:	vTo		The user ID
 */
function showEmailToWhom(vTo)
{
    var emailWindow = null;
    if (emailWindow == null || emailWindow.closed)
        emailWindow = doModal("Email.jsp?ToUser=" + vTo, this, EMAIL_DIALOG_WIDTH, EMAIL_DIALOG_HEIGHT);
    else
        emailWindow.focus();
}
function doModalLocation(url,MyWindow,mwidth,mheight,mLeft,mTop)
{
	var newWindow;
	if (document.all&&window.print){ //if ie5
		newWindow = window.showModelessDialog(url,MyWindow,"help:0;resizable:1;dialogWidth:"+mwidth+"px;dialogHeight:"+mheight+"px;dialogLeft:"+mLeft+"px;dialogTop:"+mTop+"px;status:no;scroll:no");
	}
	else{
		newWindow = window.open(url,MyWindow,"width="+mwidth+"px,height="+mheight+"px,resizable=1,scrollbars=1,left="+mLeft+"px,top="+mTop+"px");
	}

	newWindow.name = "NewWindow";

	return newWindow;
}
//---------------Miscellaneous Section--------------------

// Display a new window dialog
// Param: 	url			the url
//			MyWindow	the window object
//			mwidth		the width of window
//			mheight 	the height of window
function doModal(url,MyWindow,mwidth,mheight)
{
	var newWindow;

	if (document.all&&window.print) //if ie5
		newWindow = window.showModelessDialog(url,MyWindow,"help:0;resizable:1;dialogWidth:"+mwidth+"px;dialogHeight:"+mheight+"px;status:no");
    else
		newWindow = window.open(url,"","width="+mwidth+"px,height="+mheight+"px,resizable=1,scrollbars=1");

	newWindow.name = "NewWindow";

	return newWindow;
}

// Display a new window dialog
// Param: 	url			the url
//			MyWindow	the window object
//			mwidth		the width of window
//			mheight 	the height of window
//			mLeft		the position of window from left
//			mTop		the position of window from top
function showModalLocation(url,MyWindow,mwidth,mheight,mLeft,mTop)
{
	var newWindow;

	if (document.all&&window.print) //if ie5
		newWindow = window.showModelessDialog(url,MyWindow,"help:0;resizable:1;dialogWidth:"+mwidth+"px;dialogHeight:"+mheight+"px;dialogLeft:"+mLeft+"px;dialogTop:"+mTop+"px;status:no");
	else
		newWindow = window.open(url,MyWindow,"width="+mwidth+"px,height="+mheight+"px,resizable=1,scrollbars=1,left="+mLeft+"px,top="+mTop+"px");
	newWindow.name = "NewWindow";

	return newWindow;
}

// Return false if ctrl key and shiftkey is pressed
function doSelectStart()
{
	var oEvent = window.event;
	if (oEvent.ctrlKey || oEvent.shiftKey)
	    return false;
    else
    	return true;
}

// Use this function instead of "location.reload()"
// The reload() function causes problems when using Java 1.4.1
function reloadPage()
{
	window.top.Working.location.href= ""+window.top.Working.location;
}

// Abstract function. Should be existed in separate js file (e.g. ForceField.js)
function onSelectCell()
{
    
}

// Disable the right-click menu
function disableRightClickMenu()
{
	document.oncontextmenu=new Function("return false");
}

// As its name says
function doNothing()
{
}

// Check if the browser is Netscape
function isNetscape()
{
	if(window.navigator.appName == "Netscape")
		return true;
	else
		return false;
}
function getCompOffsetWin(comp)
{
   var off=0;
	 var o=comp;   
	 while(o.offsetParent){
	 	 off+=o.offsetParent.offsetTop;
	 	 //alert(o.offsetParent.nodeName);
	 	 o=o.offsetParent;
	 }
	 return off;
}
// Adjust area's width and height
function onAdjustArea()
{	
	var acomp = document.getElementById(sAreaName);
	onAdjustPageArea(acomp);
}

// Adjust area's width and height
function onAdjustArea2()
{
   var acomp = document.getElementById(sAreaName2);
	onAdjustPageArea(acomp);
}

// Adjust the height of a text area according to the length of the its text
// Param: 	current 	the text area to adjust
function adjustHeight(current)
{
	var width = current.cols;
	var textHeight = calculateTextAreaHeight(current, width);

	if(textHeight <= 1)
		current.rows = 1;
	else
		current.rows = textHeight;
}

// Adjust the height of a text area according to the length of the its text
// Param: 	current  	the text area to adjust
//			width 		the width to adjust
function adjustHeightWithWidth(current, width)
{
	var textHeight = calculateTextAreaHeight(current, width);

	if(textHeight <= 1)
		current.rows = 1;
	else
		current.rows = textHeight;
}

// Return the height of a text area according to the length of the its text
// Param: 	current 	the text area to adjust
function calTextAreaHeight(current)
{
	var width = current.cols;
	var textHeight = calculateTextAreaHeight(current, width);

	if(textHeight < 1)
		textHeight = 1;

	return textHeight;
}

// Calculate the height of a text area according to the length of the its text
// Param: 	current  	the text area
//			width 		the width
function calculateTextAreaHeight(current, width)
{
	var text = current.value;
	var textArray = new Array();
	var breakPoint = 0;
	var portionCount = 1;
	var textHeight = 0;

	for (var i = 0; i < text.length; i++)
	{
		if (text.charAt(i)=="\n")
		{
			textArray[portionCount-1] = text.substring(breakPoint, i);
			portionCount = portionCount + 1;
			breakPoint = i + 1;
		}
	}

	textArray[portionCount-1] = text.substring(breakPoint);

	for (var j = 0; j < portionCount; j++)
	{
		textHeight = textHeight + Math.floor(textArray[j].length/width) + 1;
	}

	return textHeight;
}

// Adjust column width
// Param: vArea 		the area of table body
//		  vWidth		the new width
//		  vColSize		the width size added to the current width; if it is zero use the vWidth variable
//						if less than zero, narrow column by that size, if more than zero, wider column for that size(vColSize)
/*
function adjustColumnWidth(vArea, vWidth, vColSize)
{
    var vTBBody = getTableBody(vArea);

	var bEnd = false;		//Check to see if column reach minimum size

	//Scan through row
	for(var i = 0; i < vTBBody.childNodes.length; i++)
	{
		//If column exist
		if(vTBBody.childNodes[i].childNodes[nSelectedCol] != null)
		{
			//If selected column contains <TD> tag
			if(vTBBody.childNodes[i].childNodes[nSelectedCol].tagName == "TD")
			{
				if((strToInt(vColSize) < 0 && vTBBody.childNodes[i].childNodes[nSelectedCol].width > (strToInt(vColSize)*(-1))) || (strToInt(vColSize) >= 0))
					vTBBody.childNodes[i].childNodes[nSelectedCol].width = strToInt(vWidth);

				//Check to see if column reach minimum size
				if(strToInt(vColSize) < 0 && vTBBody.childNodes[i].childNodes[nSelectedCol].width <= (strToInt(vColSize)*(-1)))
					bEnd = true;

			}
			//If selected column contains <TEXTAREA> tag
			if(vTBBody.childNodes[i].childNodes[nSelectedCol].childNodes[0].tagName == "TEXTAREA")
			{
				vTBBody.childNodes[i].childNodes[nSelectedCol].childNodes[0].style.width = strToInt(vWidth);

				if(strToInt(vColSize) < 0 && vTBBody.childNodes[i].childNodes[nSelectedCol].childNodes[0].style.width <= (strToInt(vColSize)*(-1)))
					bEnd = true;
			}
			//If selected column contains <INPUT> tag
			if(vTBBody.childNodes[i].childNodes[nSelectedCol].childNodes[0].tagName == "INPUT")
			{
				if(strToInt(vColSize) == 0)
				{
					vTBBody.childNodes[i].childNodes[nSelectedCol].childNodes[0].size = strToInt(vWidth)/5;
				}
				else
				{
					if((strToInt(vColSize) < 0 && vTBBody.childNodes[i].childNodes[nSelectedCol].childNodes[0].size > (strToInt(vColSize/5)*(-1))) || (strToInt(vColSize) > 0))
					{
						var nSize = vTBBody.childNodes[i].childNodes[nSelectedCol].childNodes[0].size;
						vTBBody.childNodes[i].childNodes[nSelectedCol].childNodes[0].size = strToInt(nSize) + (strToInt(vColSize)/5);
					}
				}

				if(strToInt(vColSize) < 0 && vTBBody.childNodes[i].childNodes[nSelectedCol].childNodes[0].size <= (strToInt(vColSize/5)*(-1)))
					bEnd = true;
			}
		}
	}
	//only use the return value in narrowing column
	return bEnd;
}
*/

function adjustColumnWidth(vArea, vWidth, vColSize)
{
    var vTBBody = getTableBody(vArea);

	var bEnd = false;		//Check to see if column reach minimum size

	//Scan through row
	var vTBBodyLen = getObjectCountWithoutComment(vTBBody);
	var k;
	for(var k = 0; k < vTBBodyLen; k++)
	{
		//If column exist
		var vTempObj = getObjectWithoutComment(k, vTBBody);
		var vTempObj1 = getObjectWithoutComment(nSelectedCol, vTempObj);
		if( vTempObj1 != null)
		{
			//If selected column contains <TD> tag
			if(vTempObj1.tagName == "TD")
			{
				if((strToInt(vColSize) < 0 && vTempObj1.width > (strToInt(vColSize)*(-1))) || (strToInt(vColSize) >= 0))
					vTempObj1.width = strToInt(vWidth);

				//Check to see if column reach minimum size
				if(strToInt(vColSize) < 0 && vTempObj1.width <= (strToInt(vColSize)*(-1)))
					bEnd = true;

			}
			//If selected column contains <TEXTAREA> tag
			

			//var vTempObj2 = getFirstObjectWithoutComment(vTempObj1);
			var vTempObj2 = vTempObj1.childNodes[0];
			if(vTempObj2.nodeName.toUpperCase() == "#TEXT")
			{
			}
			
			if(vTempObj2.tagName == "TEXTAREA")
			{
				vTempObj2.style.width = strToInt(vWidth);

				if(strToInt(vColSize) < 0 && vTempObj2.style.width <= (strToInt(vColSize)*(-1)))
					bEnd = true;
			}
			//If selected column contains <INPUT> tag
			if(vTempObj2.tagName == "INPUT")
			{
				if(strToInt(vColSize) == 0)
				{
					vTempObj2.size = strToInt(vWidth)/5;
				}
				else
				{
					if((strToInt(vColSize) < 0 && vTempObj2.size > (strToInt(vColSize/5)*(-1))) || (strToInt(vColSize) > 0))
					{
						var nSize = vTempObj2.size;
						vTempObj2.size = strToInt(nSize) + (strToInt(vColSize)/5);
					}
				}

				if(strToInt(vColSize) < 0 && vTempObj2.size <= (strToInt(vColSize/5)*(-1)))
					bEnd = true;
			}
		}
	}
	//only use the return value in narrowing column
	return bEnd;
}



// Get current column width
// Param: vArea 		the area of table body
//		  vColSize		the width size added to the current width; if it is zero use the vWidth variable
//						if less than zero, narrow column by that size, if more than zero, wider column for that size(vColSize)
function getCurrentColWidth(vArea, vColSize)
{
    var vTBBody = getTableBody(vArea);
	var nWidth = 0;
	var bEnd = false;		//Check to see if column reach minimum size

	//Scan through row
	var vTempLen = getObjectCountWithoutComment(vTBBody);
	var a;
	for(var a = 0; a < vTempLen; a++)
	{
		//If column exist
		var vTempObj = getObjectWithoutComment(a, vTBBody);
		var vTempObj1 = getObjectWithoutComment(nSelectedCol, vTempObj);
		
		
		//if(vTBBody.childNodes[i].childNodes[nSelectedCol] != null)
		if(vTempObj1 != null)
		{
			//If selected column contains <TD> tag
			if(vTempObj1.nodeName == "TD")
				nWidth = strToInt(vTempObj1.width) + strToInt(vColSize);
		}
	}
	return nWidth;
}

// Get an Alphabet String from a number. If the number is larger than 26,
// it will return more than one characters, eg. "AA" or "AAA".
function getLetter(vNum)
{
	var sLetter = "";
	if(vNum >= 0)
	{
	     var sAlphabet  ="ABCDEFGHIJKLMNOPQRSTUVWXYZ";

	   	 var nPos = vNum%26;
	   	 var sTemp = "";

	   	 if (nPos == 0)
	   	 	sTemp = "Z";
	   	 else
		   	 sTemp=sAlphabet.substr(nPos-1,1);

		 var nRound = parseInt(vNum/27)+1;

	   	 for (var i=0;i<nRound;i++)
	   	 	sLetter = sLetter+sTemp;
   	 }
     return sLetter;
}

// Used by new created cells only. Handles key pressed event.
/*
function onNewCellKeyPressed()
{
	var current = event.srcElement;
	return onKeyPressed(current,event);
}
*/

// Print out

function doPrint()
{
	var controller = document.getElementById("controller");

	if(controller)
		controller.style.display = "none";

	if(document.toolbar)
		document.toolbar.style.display = "none";

	doPrintDivOverflow();

	if(document.toolbar)
		document.toolbar.style.display = "";

	if(controller)
		controller.style.display = "";
}

// modified by zhanghuajie 060327 ,for supporting FireFox
// validate Image,
// param thisForm         page form.
// param value            file name.
// param nSize            file size.
function validateImage(thisForm, value, nSize, vWidth, vHeight)
{
    myForm = thisForm;
    nImgSize = nSize;
    nHeight = vHeight;
    nWidth = vWidth;
    
    var bodyRef = document.getElementsByTagName("body").item(0);
    
    //alert(document.implementation.hasFeature("Events","2.0"));
    
    if(value == "")
		alert("Please specify the file location of the image.");
    else
    {
    	  
        if(img)  bodyRef.removeChild(img);
        img = document.createElement("img");
        img.id = "upImg";
        img.style.position = "absolute";
        img.style.visibility = "hidden";
		    //addEvent(img,"onreadystatechange",onCheckImgSize,false)
		    addEvent(img,"onerror",isImage,false) ;

        bodyRef.appendChild(img);
        img.src = "file:///"+value;
        
        if(onCheckImgSize(img)){
           myForm.submit();
        }
    }
}
function isImage()
{
    alert("Please specify the file location of the image.");
}

// modified by zhanghuajie 060327 ,for supporting FireFox

function onCheckImgSize(upImg)
{   
	  var img =upImg;

    if (img.offsetWidth > nWidth || img.offsetHeight > nHeight)
    {
        alert("Please use image no larger than "+nWidth+"x"+nHeight+" pixels.");
        return false;
    }
    
    
    return true;
}

// add by lianying 01/22/2005. bug id 2843.
// Send command to server to update and check the length of the input data; truncating String if needed
// Param: 	vLength 	maximum length allowed for input data. Don't check the length if vLength is 0.

function onEndEditingTextAreaLength(current,vLength)
{
//	var current = event.srcElement;
	var s	= current.value;
	if(vLength != 0){
		if (s.length > vLength)
		{
			alert("The maximum length of the field is " + vLength + " characters. The data will be truncated.");
			s = s.substr(0, vLength);
			current.value=s;
		}
	}
}

// modified by zhanghuajie 060327 ,for supporting FireFox
// add by lianying 04/22/2005. upload img browse.
function change_path(nPage)
{
    var myForm = "";
    if (nPage == "ConsultantLogo_New")
        myForm = document.LogoForm;
    if (nPage == "UG_AE_Image")
        myForm = document.UGForm;
    if (nPage == "User_Edit_Image")
        myForm = document.AddForm; 
        
    if (!isEmpty(myForm.sImageName.value))
    {
        document.getElementById("image1").style.display = "";
        
        // add by zhanghuajie 03/25/2006. support firefox.
        
        var obj=document.getElementById("image1");
        obj.src="file:///"+myForm.sImageName.value;
    }
    else
        document.getElementById("image1").style.display = "none";
}
// modified by zhanghuajie 060328 ,for supporting FireFox
// add by linliming 04/28/2005, task id 955.
// When a user opens an input page, put the cursor in the first input-field.
function setCursorInFirstField()
{
        // use "document.getElementsByTagName(*)" to get the all tags
    //var all_tags = document.all    
		var all_tags = document.getElementsByTagName("*");
		
        // Loop through the all tags
       for (var counter = 0; counter < all_tags.length; counter++)
	   {
			 if ((all_tags[counter].tagName == "INPUT") && (all_tags[counter].type == "text") && (all_tags[counter].id != "controller") && !all_tags[counter].disabled)
			 {
				     var input_tags = all_tags[counter];
				     input_tags.focus();
				     break;
			  }
			 else if(all_tags[counter].tagName == "TEXTAREA" && !all_tags[counter].disabled)
			  {
					 var textarea_tags = all_tags[counter];
					 textarea_tags.focus();
				     break;
			  }		
       }      
}      

// for print
// add by linliming, 12/19/2005, bug id 7147.
function doPrintDivOverflow()
{
	if(typeof(document.getElementById("workingArea")) != "undefined")
	    document.getElementById("workingArea").style.overflow = "visible";
	    
	window.print();
	
	if(typeof(document.getElementById("workingArea")) != "undefined")
	    document.getElementById("workingArea").style.overflow = "auto";
}

//get special object for firefox
function getSpecialObject(nSerial ,vTagName ,parentBody)
{
	var vSpecObj ;
	var nNO = 0 ;
	for(i=0 ; i<parentBody.childNodes.length ;i++)		
	{
		if((parentBody.childNodes[i].nodeName.toUpperCase()==vTagName))
		{
			if(nNO==nSerial)
			{
				vSpecObj = parentBody.childNodes[i] ;
				break ;			
			}
			nNO++ ;
		}
	}
	return vSpecObj ;
}

//get object for firefox without {#text}
function getObjectWithoutComment(nSerial ,parentBody)
{
	var vSpecObj ;
	var nNO = 0 ;
	for(var i=0 ; i<parentBody.childNodes.length ;i++)		
	{
		if((parentBody.childNodes[i].nodeName.toUpperCase()!="#TEXT"))
		{
			if(nNO==nSerial)
			{
				vSpecObj = parentBody.childNodes[i] ;
				break ;			
			}
			nNO++ ;
		}
	}
	return vSpecObj ;
}

// get special object by tagname of parent
function getSpecialParentObject(vParentTagName ,vObj)
{
	var vParentObj = vObj.parentNode ;
	if(vParentObj.nodeName == vParentTagName)
	{
		return vParentObj ;
	}
	else if(vParentObj.nodeName == "BODY")
	{
		return null ;
	}
	else
	{
		return getSpecialParentObject(vParentTagName,vParentObj) ;
	}
}

// modified by zhanghuajie 060327 ,for supporting FireFox

function addEvent(obj,eventName,refer,capture)
{

	if(document.uniqueID)
	{
		obj.attachEvent(eventName,refer);
	}
	else
	{
		var sTemp = eventName.substr(2,eventName.length-1) ;
		obj.addEventListener(sTemp,refer,capture) ;
	}
}

function getLastObjectWithoutComment(parentBody)
{
	var vSpecObj ;
	var nNO = 0 ;
	if(parentBody.childNodes > 0)
	{
		for(i=parentBody.childNodes.length-1 ; i>=0 ;i--)		
		{
			if((parentBody.childNodes[i].nodeName.toUpperCase()!="#TEXT"))
			{
				vSpecObj = parentBody.childNodes[i] ;
				break ;			
			}
		}
   }
   else
   	  vSpecObj = parentBody;
   return vSpecObj ;
}

function getFirstObjectWithoutComment(parentBody)
{
	var vSpecObj ;
	var nNO = 0 ;
	for(i=0 ; i<=parentBody.childNodes.length-1 ;i++)		
	{
		if((parentBody.childNodes[i].nodeName.toUpperCase()!="#TEXT"))
		{
			vSpecObj = parentBody.childNodes[i] ;
			break ;			
		}
	}
	return vSpecObj ;
}

function getObjectCountWithoutComment(parentBody)
{
	var nCount = 0 ;
	    
	for(i=0 ; i<parentBody.childNodes.length ;i++)		
	{
		if((parentBody.childNodes[i].nodeName.toUpperCase()!="#TEXT"))
		{
			nCount++ ;
		}
	}
   
	return nCount ;
}

// add by linliming, 03/17/2006.
// vNum              the special number.
// vElement          the element that special type.
// vParentBody       the element's parent node.
function getObjectBySpecialElement(vNum, vElement, vParentBody)
{
	var vSpecObj ;
	var nNO = 0 ;
	for(i=0 ; i<=vParentBody.childNodes.length-1 ;i++)		
	{
		if((vParentBody.childNodes[i].nodeName.toUpperCase() != "#TEXT") &&
		   (vParentBody.childNodes[i].nodeName.toUpperCase() == vElement))
		{	
			if(vNum == nNO)
			{
				vSpecObj = vParentBody.childNodes[i] ;	
				break ;
		    }
		    nNO++;		
		}		
	}
	return vSpecObj ;
}

// vTempObj      the object
// vType         the types of previous(:1) and next(:0).
// author        linliming by 07/11/2006.
function getObjectWithoutMoreComment(vTempObj, vType)
{
    var vSpecObj;
    if(vType == "0")
    {
      vTempObj = vTempObj.nextSibling;
      while(vTempObj.nodeName.toUpperCase() == "#TEXT")
         vTempObj = vTempObj.nextSibling;
    }
    else
    {
       vTempObj = vTempObj.previousSibling;
       while(vTempObj.nodeName.toUpperCase() == "#TEXT")
         vTempObj = vTempObj.previousSibling;
    }
    vSpecObj = vTempObj;
    
    return vSpecObj;   
}

function textLength(s, maxlimit)
{	
	  var result = true;
	  if (s.value.length > maxlimit)
	  {
	  	//alert("The maximum length is " + maxlimit);
	  	s.value = s.value.substring(0, maxlimit);
	    result = false;
	  }
	
	  if (window.event)
	   window.event.returnValue = result;
	    
	  return result;
}

function onAdjustGridArea(oArea)
{
	onAdjustPageArea(oArea);
}	

function onAdjustPageArea(oArea)
{	   	  
	getBrowserInfo();
   var nScreenHeight = window.screen.availHeight;        
 	var nDiffH = nScreenHeight - nBrowserHeight; 	
 	 	
 	var nDiffOffset = 1.1;
 	   
   var nTempHeight = nScreenHeight - (150 + (nDiffH * nDiffOffset)) + nGridHeightOffset;
  
   if(nTempHeight < 100)
   	nTempHeight = 100;
          	   
   oArea.style.height=Math.round(nTempHeight);
   
   if(bAdjustWidth)
   {
   		var nScreenWidth = window.screen.availWidth; 
   		var nDiffW = nScreenWidth - nBrowserWidth;
	   //nGridWidthOffset -= 6;
	   var nTempWidth = nScreenWidth + nGridWidthOffset; 
	   if(nDiffW > 0)
	   	nTempWidth -= nDiffW;
	   	
	   if(nGridWidthRatio > 0)
	   		nTempWidth = nTempWidth * nGridWidthRatio;
	   		
	   if(nToolWidthAdjust > 0)
	   	   	nTempWidth = nTempWidth * nToolWidthAdjust;	
	   		
	   oArea.style.width=Math.round(nTempWidth); 
	   		// alert(oArea.style.Width);
   }
             
//alert("Grid: oArea.style.height="+oArea.style.height+"; nDiffH="+nDiffH+"; nBrowserHeight="+nBrowserHeight+"; nTempHeight="+nTempHeight);   
     
}	

function adjustGridArea()
{	   
	//checkBrowser();
	//if(bFirefox)
	//	nGridHeightOffset = -60;
		
	var acomp = document.getElementById("workingArea");
   onAdjustGridArea(acomp);       
}

function onResizeGrid()
{		
	adjustGridArea();	
}	

function adjustArea()
{	   
	var acomp = document.getElementById("workingArea");
   onAdjustGridArea(acomp);       
}

function onResize()
{
	adjustArea();
}	

function checkBrowser()
{
	var agt = navigator.userAgent.toLowerCase(); 
	//alert(agt);
	bOpera = (agt.indexOf("opera") != -1);
	bIE = !bOpera && (agt.indexOf("msie") > -1); 
	bFirefox = !bIE && (agt.indexOf("firefox") > -1); 
	bSafari = !bFirefox && (agt.indexOf("safari") > -1);	
}

function onTimeOut(vMilisec)
{
	window.setTimeout("doNothing()", vMilisec, "JAVASCRIPT" );	
}

function checkSelection(vCheckboxName)
{
	var bSelected = false;
	var aCheckbox = document.getElementsByName(vCheckboxName);		
	var nLength = aCheckbox.length;
	for (var i=0; i<nLength; i++)
	{
		if (aCheckbox[i].checked)
		{
		   	bSelected = true;
		   	break;
		}
	}
	return bSelected;
}	

function getBrowserInfo() 
{  
  if( typeof( window.top.innerWidth ) == 'number' ) {
    //Non-IE
    nBrowserWidth = window.top.innerWidth;
    nBrowserHeight = window.top.innerHeight;
  } else if( window.top.document.documentElement &&
      ( window.top.document.documentElement.clientWidth || window.top.document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    nBrowserWidth = window.top.document.documentElement.clientWidth;
    nBrowserHeight = window.top.document.documentElement.clientHeight;
  } else if( window.top.document.body && ( window.top.document.body.clientWidth || window.top.document.body.clientHeight ) ) {
    //IE 4 compatible
    nBrowserWidth = window.top.document.body.clientWidth;
    nBrowserHeight = window.top.document.body.clientHeight;
  }
  //window.alert( 'Width = ' + nBrowserWidth );
 // window.alert( 'Height = ' + nBrowserHeight );
}