function onError(error_message,_this)
    {
			alert(error_message);
			if (_this[0] && _this[0].type =='radio')
			    _this[0].focus()
			else if ( _this.focus )
			    _this.focus();

			if ( (_this.type == "text" || _this.type == "password" ) && _this.select )
				_this.select();
			return false;
    }
function hasValue(obj, obj_type)
    {
        if ( obj_type == "hidden" )
            return true;
    if (obj_type == "text" || obj_type == "password" || obj_type == "textarea")
			{
			trimmed = trim(obj.value)
			if (trimmed.length == 0)
						return false;
			else
						return true;
			}
	else if (obj_type == "select-one" || obj_type == "select-multiple")
			{
			if (
			obj.selectedIndex >= 0 &&
			obj.options[obj.selectedIndex].value != "0" &&
			obj.options[obj.selectedIndex].value != "" &&
			obj.options[obj.selectedIndex].value != "-1" &&
			obj.options[obj.selectedIndex].value != "Select One"
			) {return true;}
			else {return false;}
			}

    else if (obj_type == "radio"|| obj_type == "checkbox")
			{
			for (i=0; i < obj.length; i++)
			{
				if (obj[i].checked)
					return true;
				}
			return false;
			}

			}

function checkinteger(object_value)
{
	if (object_value.length == 0)
		return true;
	var check_char;
	check_char = object_value.indexOf(decimalSeperator);
	if (check_char > -1)
		return false;
	else
		return checknumber(object_value);
}

function checknumber(object_value)
{
	if (object_value.length == 0)
		return true;
	var start_format = decimalSeperator + groupingSeparator + "+-0123456789 ";
	var number_format = decimalSeperator + groupingSeparator + "0123456789 ";
	var check_char;
	var decimal = false;
	var trailing_blank = false;
	var digits = false;
	check_char = start_format.indexOf(object_value.charAt(0));
	if (check_char == 0)
		decimal = true;
	else if (check_char < 0)
		return false;
	for (var i = 1; i < object_value.length; i++)
	{
		check_char = number_format.indexOf(object_value.charAt(i));
		if (check_char < 0)
			return false;
		else if (check_char == 0)
		{
			if (decimal)
				return false;
			else
				decimal = true;
		}
		else if (check_char == 12)
		{
			if (decimal || digits)
				trailing_blank = true;
		}
		else if (trailing_blank)
			return false;
		else
			digits = true;
	}
	return true;
}

function checkfraction(input)
{
    var deci = convertFractionToDecimal(input);
    if ( deci != null )
        return true;
    return checknumber(input)
}
function checkcurrency(input)
{
    return formatToNumberFromMoney(input.value) > 0;
}

function convertFractionToDecimal(input)
{
    var fractionRegex = /^((\d*)( |\-))(\d+)\/(\d+)$/
	if (input != null )
	{
		var fracArr = input.match(fractionRegex)
		if ( fracArr != null )
		{
			var output = 0.0;
			var wholeNumber = fracArr[2];
			if ( wholeNumber != null && wholeNumber.length > 0 )
				output = parseFloat(wholeNumber);

			var numerator = parseInt(fracArr[4]);
			var denominator = parseInt(fracArr[5]);
			if ( denominator > numerator )
				return output + ( numerator / denominator );
		}
		else if ( checknumber(input) )
		{
		    return input;
		}

	}
	return null;
}

function checkcreditcard(obj_val) {
    var white_space = " -";
    var creditcard_string="";
    var check_char;
    if (obj_val.length == 0)
        return true;
    for (var i = 0; i < obj_val.length; i++) {
        check_char = white_space.indexOf(obj_val.charAt(i))
        if (check_char < 0)
            creditcard_string += obj_val.substring(i, (i + 1));
    }
    if (creditcard_string.length == 0)
        return false;
    if (creditcard_string.charAt(0) == "+")
        return false;
    if (!checkinteger(creditcard_string))
        return false;
    var doubledigit = creditcard_string.length % 2 != 1;
    var checkdigit = 0;
    var tempdigit;
    for (var i = 0; i < creditcard_string.length; i++) {
        tempdigit = eval(creditcard_string.charAt(i));
        if (doubledigit) {
            tempdigit *= 2;
            checkdigit += (tempdigit % 10);
            if ((tempdigit / 10) >= 1.0) {
                checkdigit++;
            }
            doubledigit = false;
        } else {
            checkdigit += tempdigit;
            doubledigit = true;
        }
    }
    return (checkdigit % 10) == 0;
}

function numberrange(obj_val, min_value, max_value) {
    if (min_value != null) {
        if (obj_val < min_value)
            return false;
    }
    if (max_value != null) {
        if (obj_val > max_value)
            return false;
    }
    return true;
}
function checkrange(obj_val, min_val, max_val) {
    obj_val = clearComma(obj_val)
    if (obj_val.length == 0)
        return true;
    if (!checknumber(obj_val)) {
        return false;
    } else {
        return numberrange(obj_val, min_val, max_val);
    }
    return true;
}

function checkfractionrange(obj_val, min_val, max_val)
{
    if (obj_val.length == 0)
        return true;
    var deci = convertFractionToDecimal(obj_val);
    if ( deci == null )
        return false;

    return numberrange(deci, min_val, max_val);

}


function checkdate(obj_val)
{
    if (obj_val.length == 0)
        return true;
	format = datePatternJS; // datepattern is defined in init.jsp, and comes from the DateFormat.getPattern( Locale )
    if (isDate(obj_val,format))
	    return true;
	else
	    return false;
}
function checkdaterange(obj_val, min_date, max_date)
{
    if (obj_val.length == 0)
        return true;
    var objDate = new Date(getDateFromFormat(obj_val,datePatternJS));
    if (min_date != null) {
        if (objDate < min_date)
            return false;
    }
    if (max_date != null) {
        if (objDate > max_date)
            return false;
    }
    return true;
}

/*
function checkdate(obj_val) {
    var splittype = '/';
	if (obj_val.length == 0)
        return true;
    isplit = obj_val.indexOf(splittype);
    if (isplit == -1 || isplit == obj_val.length)
       {
	    isplit = obj_val.indexOf('-');
		if (isplit == -1 || isplit == obj_val.length)
		  return false;
		else
		  splittype = '-';
		}
    sMonth = obj_val.substring(0, isplit);
    isplit = obj_val.indexOf(splittype, isplit + 1);
    if (isplit == -1 || (isplit + 1 ) == obj_val.length)
        return false;
    sDay = obj_val.substring((sMonth.length + 1), isplit);
    sYear = obj_val.substring(isplit + 1);
    if (!checkinteger(sMonth)) //check month
        return false;
    else if (!checkrange(sMonth, 1, 12)) //check month
        return false;
    else if (!checkinteger(sYear)) //check year
        return false;
    else if (!checkrange(sYear, 0, 9999)) //check year
        return false;
    else if (!checkinteger(sDay)) //check day
        return false;
    else if (!checkday(sYear, sMonth, sDay)) // check day
        return false;
    else
        return true;
}
function checkday(checkYear, checkMonth, checkDay) {
    maxDay = 31;
    if (checkMonth == 4 || checkMonth == 6 ||
        checkMonth == 9 || checkMonth == 11)
        maxDay = 30;
    else if (checkMonth == 2) {
        if (checkYear % 4 > 0)
            maxDay = 28;
        else if (checkYear % 100 == 0 && checkYear % 400 > 0)
            maxDay = 28;
        else
            maxDay = 29;
    }
    return checkrange(checkDay, 1, maxDay); //check day
}
function checkeurodate(obj_val) {
    var splittype = '/';
	if (obj_val.length == 0)
        return true;
    isplit = obj_val.indexOf(splittype);
    if (isplit == -1 || isplit == obj_val.length)
       {
	    isplit = obj_val.indexOf('-');
		if (isplit == -1 || isplit == obj_val.length)
		  return false;
		else
		  splittype = '-';
		}
    sDay = obj_val.substring(0, isplit);
    isplit = obj_val.indexOf(splittype, isplit + 1);
    if (isplit == -1 ||  (isplit + 1 )  == obj_val.length)
        return false;
    sMonth = obj_val.substring((sDay.length + 1), isplit);
    sYear = obj_val.substring(isplit + 1);
    if (!checkinteger(sMonth))
        return false;
    else if (!checkrange(sMonth, 1, 12))
        return false;
    else if (!checkinteger(sYear))
        return false;
    else if (!checkrange(sYear, 0, null))
        return false;
    else if (!checkinteger(sDay))
        return false;
    else if (!checkday(sYear, sMonth, sDay))
        return false;
    else
        return true;
}
*/
function checkphone(obj_val) {
    if (obj_val.length == 0)
        return true;
    if (obj_val.length != 12)
        return false;
    if (!checknumber(obj_val.substring(0,3)))
        return false;
    else if (!numberrange((eval(obj_val.substring(0,3))),100,1000))
        return false;
    if (obj_val.charAt(3) != "-" && obj_val.charAt(3) != " ")
        return false;
    if (!checknumber(obj_val.substring(4,7)))
        return false;
    else if (!numberrange((eval(obj_val.substring(4,7))), 100, 1000))
        return false;
    if (obj_val.charAt(7) != "-" && obj_val.charAt(7) != " ")
        return false;
    if (obj_val.charAt(8) == "-" || obj_val.charAt(8) == "+")
        return false;
    else {
        return (checkinteger(obj_val.substring(8,12)));
    }
}
function checkssc(obj_val) {
    var white_space = " -+.";
    var ssc_string="";
    var check_char;
    if (obj_val.length == 0)
        return true;
    if (obj_val.length != 11)
        return false;
    if (obj_val.charAt(3) != "-" && obj_val.charAt(3) != " ")
        return false;
    if (obj_val.charAt(6) != "-" && obj_val.charAt(6) != " ")
        return false;
    for (var i = 0; i < obj_val.length; i++) {
        check_char = white_space.indexOf(obj_val.charAt(i))
        if (check_char < 0)
            ssc_string += obj_val.substring(i, (i + 1));
    }
    if (ssc_string.length != 9)
        return false;
    if (!checkinteger(ssc_string))
        return false;
    return true;
}
function checktime(obj_val) {
    if (obj_val.length == 0)
        return true;
    isplit = obj_val.indexOf(':');
    if (isplit == -1 || isplit == obj_val.length)
        return false;
    sHour = obj_val.substring(0, isplit);
    iminute = obj_val.indexOf(':', isplit + 1);
    if (iminute == -1 || iminute == obj_val.length)
        sMin = obj_val.substring((sHour.length + 1));
    else
        sMin = obj_val.substring((sHour.length + 1), iminute);
    if (!checkinteger(sHour)) //check hour
        return false;
    else if (!checkrange(sHour, 0, 23)) //check hour
        return false;
    if (!checkinteger(sMin)) //check minutes
        return false;
    else if (!checkrange(sMin, 0, 59)) // check minutes
        return false;
    if (iminute != -1) {
        sSec = obj_val.substring(iminute + 1);
        if (!checkinteger(sSec)) //check seconds
            return false;
        else if (!checkrange(sSec, 0, 59)) //check seconds
            return false;
    }
    return true;
}
function checkzipcode(obj_val) {
    if (obj_val.length == 0)
        return true;
    if (obj_val.length != 5 && obj_val.length != 10)
        return false;
    if (obj_val.charAt(0) == "-" || obj_val.charAt(0) == "+")
        return false;
    if (!checkinteger(obj_val.substring(0,5)))
        return false;
    if (obj_val.length == 5)
        return true;
    if (obj_val.charAt(5) != "-" && obj_val.charAt(5) != " ")
        return false;
    if (obj_val.charAt(6) == "-" || obj_val.charAt(6) == "+")
        return false;
    return (checkinteger(obj_val.substring(6,10)));
}
function checkpassword(obj_val) {
    if (obj_val.length == 0)
        return true;
    return obj_val.match( /.*[A-Za-z]+.*/ ) && obj_val.match( /.*\d+.*/ ) && obj_val.length >= 6;
}

function trim ( s )
{
	return rtrim(ltrim(s));
}
function ltrim ( s )
{
	return s.replace( /^\s*/, "" )
}

function rtrim ( s )
{
	return s.replace( /\s*$/, "" );
}

function removeDecimals( val, parseWithLocale )
{
    if ( parseWithLocale == null )
        parseWithLocale = true
    deciInd = val.indexOf( parseWithLocale ? decimalSeperator : '.')
    if ( deciInd > -1 )
    {
        ret = val.substring( 0, deciInd )
    }
    else
        ret = val
    return ret
}

function removeCommas( object_value, parseWithLocale )
{
    if ( parseWithLocale == null )
        parseWithLocale = true
    object_value = removeDecimals( object_value, parseWithLocale )
	var cur=  ""
	for ( var i = 0; i < object_value.length; i++ )
	{
		if ( ( object_value.charAt( i ) >= "0" && object_value.charAt( i ) <= "9") )
			cur += object_value.charAt(i)
	}
	return cur;
}

function clearComma(strIn)
{
    var i;
    var strOut = new String('');
    for(i = 0; i < strIn.length; i++)
    {
        var s = new String(strIn.substr(i,1));
        if(s=='-' || ( !isNaN(s) && s != groupingSeparator ) || s == decimalSeperator)
        {
            strOut = strOut.concat(s);
        }
    }
    return strOut;
}

function addCommas( num )
{
    if ( typeof num == "string" )
        numstr = num;
    else if ( !isNaN(num) )
        numstr = new String(num);
    else
        numstr = num.value;
    if ( numstr == null || numstr.length == 0 )
        return "";
    var newcur = ""
	var fincur = ""
	var count = 0
	cur = removeCommas( numstr )

	for ( var i = cur.length-1; i >= 0; i-- ) {
		count++
		newcur += cur.charAt( i )
		if ( count == 3 && i != 0 )
		{
			count = 0
			newcur += groupingSeparator
		}
	}

	for ( var i = newcur.length-1; i >= 0; i-- ) {
		fincur+=newcur.charAt( i )
	}
    if ( num.value )
        num.value = fincur
    return fincur;
}

function outputMoney( number, allowNegatives, parseWithLocale, maximumFractionDigits )
{
    if ( parseWithLocale == null )
        parseWithLocale = true
	var sign = ''
	if ( allowNegatives && number.charAt(0) == '-' )
		sign = '-'
	if ( number == '' )
		number = '0'
    return sign + outputDollars( number + '', parseWithLocale ) + outputCents( number + '', parseWithLocale, maximumFractionDigits );
}

function outputDollars(number, parseWithLocale)
{
	number = removeCommas( number, parseWithLocale )
    if (number.length <= groupingDigits)
        return ( number == '' ? '0' : number );
    else
	{
        var mod = number.length % groupingDigits;
        var output = ( mod == 0 ? '' : ( number.substring( 0, mod ) ) );
        for ( var i = 0; i < Math.floor( number.length / groupingDigits ); i++ )
		{
            if ( ( mod == 0 ) && ( i == 0 ) )
                output += number.substring( mod + groupingDigits * i, mod + groupingDigits * i + groupingDigits );
            else
                output += groupingSeparator + number.substring( mod + groupingDigits * i, mod + groupingDigits * i + groupingDigits );
        }
        return ( output );
    }
}

function outputCents(amount, parseWithLocale, maximumFractionDigits)
{
    var fractionDigits = currencyMaximumFractionDigits;
    if ( maximumFractionDigits != null )
        fractionDigits = maximumFractionDigits;

    var decSeparator = parseWithLocale ? decimalSeperator : '.';
	if ( currencyMaximumFractionDigits <= 0 )
		return ''
	if ( amount.indexOf( decSeparator ) == -1 )
		amount = ''
	else
		amount = amount.substring( amount.indexOf( decSeparator ) + 1, amount.indexOf( decSeparator ) + fractionDigits + 1 )

	amount = removeCommas( amount, parseWithLocale )

	var zeroes = ''
	for ( var i = 0; i < fractionDigits - amount.length; i++ )
		zeroes += '0'
	return decimalSeperator + amount + zeroes

    return ( amount.length <= 1 ? decimalSeperator + '0' + amount : decimalSeperator + amount );

}

function formatMoney( number, parseWithLocale)
{
    if ( parseWithLocale == null )
        parseWithLocale = true
	var sign = ''
	if ( number == '' )
		number = '0'        
    number = Math.round(number*1000)/1000
    number = Math.round(number*100)/100
    strOut = new String(number);
    strOut = strOut.replace(".",decimalSeperator);

    if ( number < 0 )
        return negativeCurrencyPrefix + outputDollars( strOut + '', parseWithLocale ) + outputCents( strOut + '', parseWithLocale ) + negativeCurrencySuffix;
    else
        return sign + currencyPrefix + outputDollars( strOut + '', parseWithLocale ) + outputCents( strOut + '', parseWithLocale ) + currencySuffix;
}

function formatToNumberFromMoney( money)
{
    if ( !isNaN(money) )
        return parseFloat(money);
    strOut = new String(money);
    strOut = strOut.replace(new RegExp(groupingSeparator.replace(/\./g, "\\."), "g"), ""); // must convert separators to Regex compatible escaped strings first
    strOut = strOut.replace(new RegExp(decimalSeperator.replace(/\./g, "\\."), "g"), ".");
    strOut = strOut.replace('€', "&euro;"); // hack to fix euro symbol escaping from innerHTML call
    if ( strOut.indexOf( negativeCurrencyPrefix ) > -1 )
        strOut = strOut.replace(negativeCurrencyPrefix , "-");
    if ( strOut.indexOf( negativeCurrencySuffix ) > -1 )
        strOut = strOut.replace(negativeCurrencySuffix , "");
    strOut = strOut.replace(currencyPrefix , "");
    strOut = strOut.replace(currencySuffix , "");

    strOut = getRegexMatch( strOut, /\-?\d+\.?\d*/ ); // after some basic conversion and stripping is done, pull out the digits using this regex

    var val = parseFloat(strOut);
    if ( isNaN( val ) )
        val = 0.0;
    return val;
}

function getRegexMatch( str, pattern )
{
    var re = new RegExp(pattern);
    var m = re.exec(str);
    if ( m == null )
    {
        return str;
    }
    else
    {
        var s = "";
        for ( i = 0; i < m.length; i++ )
        {
            s += m[i];
        }
        return s;
    }
}

function calcTotal(objectTextField,columnId,boolTotal,strTotalId,theForm )
{
    objectTextFieldTotal =  "theForm."+strTotalId + columnId  ;
    var total=0;
    if( boolTotal )
    {
		var arrOfrows = getRowNames();
        var fieldVal = 0;
        for (var i=0; i < arrOfrows.length; i++)
            {
               var discount = false;
               if ( arrOfrows[i] == 'other1_price' && theForm.other1_cat[theForm.other1_cat.selectedIndex].value == 'DISCOUNT' )
               {
                  discount = true
               }
               if ( arrOfrows[i] == 'other2_price' && theForm.other2_cat[theForm.other2_cat.selectedIndex].value == 'DISCOUNT' )
               {
                  discount = true
               }

               strTextFieldNm = "theForm."+arrOfrows[i]+columnId;
               var obj = eval(strTextFieldNm)

               if (typeof obj != 'undefined')
               {
                  fieldVal = parseFloat(clearComma(outputMoney(obj.value)));
                  //alert( "obj.value = " + obj.value + "  outputMoney(obj.value) = " + outputMoney(obj.value) + "    clearComma(outputMoney(obj.value)) = " + clearComma(outputMoney(obj.value)) + "   fieldVal = " + fieldVal)
               }

               if ( fieldVal >= 0)
               {
                  if ( discount )
                     total -= fieldVal;
                  else
                     total += fieldVal;
               }
            }

        var objTotal = eval(objectTextFieldTotal)
        if (typeof objTotal != 'undefined')
        {
           finalTotal = outputMoney(total, false, false);
           //alert( " total = " + total + "   finalTotal = " + finalTotal)
           if ( total < 0 )
              finalTotal = "(" + finalTotal + ")"
           eval(objectTextFieldTotal).value = finalTotal;
        }
    }
    if (objectTextField.type != 'select-one' && objectTextField.type != 'select-multiple')
       objectTextField.value = outputMoney( objectTextField.value  );
}
/*
==================================================================
LTrim(string) : Returns a copy of a string without leading spaces.
==================================================================
*/
function LTrim(str)
/*
   PURPOSE: Remove leading blanks from our string.
   IN: str - the string we want to LTrim
*/
{
   var whitespace = new String(" \t\n\r");

   var s = new String(str);

   if (whitespace.indexOf(s.charAt(0)) != -1) {
      // We have a string with leading blank(s)...

      var j=0, i = s.length;

      // Iterate from the far left of string until we
      // don't have any more whitespace...
      while (j < i && whitespace.indexOf(s.charAt(j)) != -1)
         j++;

      // Get the substring from the first non-whitespace
      // character to the end of the string...
      s = s.substring(j, i);
   }
   return s;
}

function checkGTZero(object_value)
    {
	     var nCount = 0;
		 var checkCommaorDec;
		 if( LTrim(object_value).length == 0)
		   {
   		     return false;
		   }
		 else
		   if( LTrim(object_value).length == 1 && object_value == 0  )
	        return false;
		 else
		 {
			 object_value = LTrim( object_value );
			 for (var i= 0 ; i < object_value.length; i++)
			 {
               if( (object_value.charAt(i)== ",") || (object_value.charAt(i)== ".") )
			      {
					checkCommaorDec = true;
				  }
			   else
			      {checkCommaorDec = false;}

			   if ( (object_value.charAt(i) >= "0" && object_value.charAt(i) <= "9") || checkCommaorDec )
				     {
				       if(object_value.charAt(i) > "0" && object_value.charAt(i) <= "9")
					   nCount++;
					 }
			   else
				    {
					   return false;
				    }
		     }
			 if ( nCount == 0)
			  {
			   return false;
			  }
		  return true;
		}
   }

function countCharacters(maxchars,textBox,errorMsg)
{
    if(LTrim(textBox.value).length > maxchars)
    {
        errorMsg += " " + LTrim(textBox.value).length
        alert(errorMsg)
        textBox.select();
        textBox.focus();
        return false;
    }
    else
    {return true;}
}

function check(form, checked, formField)
{
    if ( checked == null )
        toggleval = form.toggle.checked;
    else
        toggleval = checked;
    if ( formField != null)
        field = formField;
    else
        field = form.actionkeys;
    if ( field == undefined)
        return;
    if (!field.length)
        field = new Array(field)

    if (toggleval == true)
    {
        for (i = 0; i < field.length; i++)
        {
            if (!field[i].disabled && field[i].offsetWidth > 0 )
                field[i].checked = true;
        }
    }
    else
    {
        for (i = 0; i < field.length; i++)
        {
            if (!field[i].disabled && field[i].offsetWidth > 0 )
                field[i].checked = false;
        }
    }
}

function email(to,from,subject,estimateNbr,versionNbr,orderNbr,bcc,userId,body,keepAttachments,projectNbr,cc,selectedRecipients)
{
    var param = "DataFlag=FirstTime";
    if (keepAttachments != null && keepAttachments == true )
        param = "DataFlag=FromFiles";
    if (to != null)
        param = param + "&to=" + to;
    if (from != null)
        param = param + "&from=" + from;
    if (subject != null && subject != "" && subject != "-1-1")
        param = param + "&subject=" + subject;
    if (body != null)
        param = param + "&body=" + body;
    if (orderNbr != null)
        param = param + "&orderNbr=" + orderNbr;
    if (estimateNbr != null && estimateNbr != "-1")
        param = param + "&estimateNbr=" + estimateNbr;
    if (versionNbr != null)
        param = param + "&versionNbr=" + versionNbr;
    if (bcc != null)
        param = param + "&bcc=" + bcc;
    if (cc != null)
        param = param + "&cc=" + cc;
    if (selectedRecipients != null)
        param = param + "&selectedRecipients=" + selectedRecipients;
    if (userId != null)
        param = param + "&userId=" + userId;
    if (projectNbr != null)
        param = param + "&projectNbr=" + projectNbr;
	window.open(calledjsp + param, "cirqit_" + new Date().getTime(), 'dependant=yes, width=650, height=550, location=no, menubar=no, status=yes, toolbar=no, scrollbars=yes, resizable=yes');
}

function attachNotification(theForm, url )
{
    var left = Math.floor( (screen.width - 575) / 2);
    var top = Math.floor( (screen.height - 550) / 2);
    var param = "DataFlag=FirstTime&"

    if ( theForm != null )
        param += "formName=" + theForm.name + "&";
    if ( url != null )
        param += "url=" + escape(url) + "&";

    window.open("attach_new_file_notification.jsp"+jsessionid +"?" + param, "cirqit_" + new Date().getTime(), 'dependant=yes, width=575, height=550, location=no, menubar=no, status=yes, toolbar=no, scrollbars=yes, resizable=yes, alwaysRaised=yes, top=' + top + ', left='+left);
}

function attachFiles(theForm, entityType, entityNbr,versionNbr, url, orgId, estimateNbr )
{
    var left = Math.floor( (screen.width - 550) / 2);
    var top = Math.floor( (screen.height - 625) / 2);
    var param = "DataFlag=FirstTime&"

    if ( theForm != null )
        param += "formName=" + theForm.name + "&";
    if ( entityType != null )
        param += "entityType=" + entityType + "&";
    if ( entityNbr != null )
        param += "entityNbr=" + entityNbr + "&";
    if ( estimateNbr != null )
        param += "estimateNbr=" + estimateNbr + "&";
    if ( versionNbr != null )
        param += "versionNbr=" + versionNbr + "&";
    if ( orgId != null )
        param += "orgId=" + orgId + "&";
    if ( url != null )
        param += "url=" + escape(url) + "&";
    window.open("DigitalFileUpload.jsp"+jsessionid +"?" + param, "cirqit_" + new Date().getTime(), 'dependant=yes, width=550, height=610, location=no, menubar=no, status=yes, toolbar=no, scrollbars=yes, resizable=yes, alwaysRaised=yes, top=' + top + ', left='+left);
}

var yesNoForm;
function yesNoCancel(theForm)
{
    yesNoForm = theForm;
    var left = Math.floor( (screen.width - 250) / 2);
    var top = Math.floor( (screen.height - 125) / 2);
    var formName;
    if ( theForm != null )
        formName = theForm.name
    if ( window.showModalDialog )
    {
        window.showModalDialog('confirm.jsp'+jsessionid +'?'+formName, window, "dialogHeight: 125px; dialogWidth: 250px; edge: Raised; center: Yes; help: No; resizable: No; status: No;");
    }
    else
        window.open('confirm.jsp'+jsessionid +'?'+formName, "cirqit_" + new Date().getTime(), 'dependant=yes, width=250, height=125, top=' + top + ', left='+left);
}

function emailList(theArray,from,subject,body,estimateNbr,versionNbr,orderNbr,cc)
{
        var msg, to = ""
    	var selected = false
        var count=0;
	    var actionKeys = theArray
        if (!actionKeys.length)
            actionKeys = new Array(actionKeys);

	    for ( i = 0; i < actionKeys.length; i++ )
        {
            var curVal = ""
            if ( actionKeys[i] != null && actionKeys[i].type == 'checkbox' && actionKeys[i].checked ) // if array of checkboxes
            {
                if( actionKeys[i].getAttribute("email") )
                    curVal = actionKeys[i].getAttribute("email")
                else
                    curVal = actionKeys[i].value;
                count++;
                selected = true;

            }
            else if ( actionKeys[i] != null && actionKeys[i].type != 'checkbox' ) // if array of strings (from estimate status page)
            {
                curVal = actionKeys[i];
                count++;
                selected = true;
            }

            if ( curVal != "" )
            {
                if (to.length == 0)
                    to = curVal;
                else
                    to += "," + curVal;
            }

  	    }
        if (selected == true)
        {
            if (count > 1)
                email(null,from,subject,estimateNbr,versionNbr,orderNbr,null,null,body,null,null,cc,to);
            else
                email(to,from,subject,estimateNbr,versionNbr,orderNbr,null,null,body,null,null,cc);
            return false;
        }
        if (selected == false)
        {
            alert(emailAlert);
            return false;
        }
}
function disableBackButton(theForm)
{
     var intEnd = theForm.elements
     for( i = 0; i < intEnd.length; i++ )
     {
          if(intEnd[i].type == "button" && intEnd[i].name == "Back")
          intEnd[i].disabled = true;
     }
}
function focusForm()
{
	// If there is a form in the doc...
	if (document.forms && document.forms[1] )
	{
		theElems = document.forms[1].elements
        var skippedCnt = 0
		// loop over the elements until finding a non-hidden one
		for (i = 0; i < theElems.length; i++)
		{
		    //if ( skippedCnt > 5 )
		    //    break;
			theElem = theElems[i];
			if (theElem.type && ( theElem.type == "hidden" || theElem.type == "button" || theElem.type == "submit" || theElem.type == "reset" || theElem.type == "button" || theElem.disabled == true ) )
			{
			    skippedCnt++;
			    continue;
			}
			// focus on the first non-hidden element
			if ( theElem.focus )
			    theElem.focus();
			if ( theElem.select )
			    theElem.select();
			break;
		}
	}
}
        function popupprint(itemNbr,specNbr,estimateNbr,versionNbr,revisionNbr)
        {
            var param = "itemNbr=" + itemNbr;
            if ((revisionNbr != null && revisionNbr.length > 0) )
                param = param + "&revisionNbr=" + revisionNbr;            
            if ((specNbr != null && specNbr.length > 0) )
                param = param + "&specNbr=" + specNbr;
            if ((estimateNbr != null && estimateNbr.length > 0) )
                param = param + "&estimateNbr=" + estimateNbr;
            if ((versionNbr != null && versionNbr.length > 0) )
                param = param + "&versionNbr=" + versionNbr;
            param = param + "&mode=readonly";
            jsppage = "PrintSpecDetail.jsp" + jsessionid + "?print=item&";
            window.open(jsppage + param, "cirqit_" + new Date().getTime(), 'dependant=yes, width=725, height=550, location=no, menubar=yes, status=yes, toolbar=no, scrollbars=yes, resizable=yes');
        }

function popupprintall(estimateNbr,versionNbr,orderNbr)
{
            var param = "estimateNbr=" + estimateNbr;
            param = param + "&versionNbr=" + versionNbr;
            if ((orderNbr != null && orderNbr.length > 0) )
                param = param + "&orderNbr=" + orderNbr;
            param = param + "&printall=true&mode=readonly";
            jsppage = "PrintSpecDetail.jsp" + jsessionid + "?";
            window.open(jsppage + param, "cirqit_" + new Date().getTime(), 'dependant=yes, width=725, height=550, location=no, menubar=yes, status=yes, toolbar=no, scrollbars=yes, resizable=yes');
}


function popupestimateupload()
{
            jsppage = "EstimateUpload.jsp" + jsessionid + "?";
            window.open(jsppage, "cirqit_" + new Date().getTime(), 'dependant=yes, width=725, height=550, location=no, menubar=yes, status=yes, toolbar=no, scrollbars=yes, resizable=yes');
}


function popuporderprint(isNewOrder,orderNbr)
{
    var sUrl = 'PrintOrderOverview.jsp' + jsessionid;
    if (orderNbr != null)
        sUrl = sUrl + '?print=true&orderNbr=' + orderNbr + '&newOrder=' + isNewOrder
    else
      sUrl = sUrl + '?print=true&newOrder=' + isNewOrder

    window.open(sUrl, "cirqit_" + new Date().getTime(), 'dependant=yes, width=725, height=550, location=no, menubar=yes, status=yes, toolbar=no, scrollbars=yes, resizable=yes');
}

function popupprintnew(isNew,itemNbr,specNbr)
{
    if (isNew)
    {
        var param = "itemNbr=" + itemNbr;
        if ((specNbr != null && specNbr.length > 0) )
            param = param + "&specNbr=" + specNbr;
        param = param + "&mode=readonly";
        jsppage = "PrintSpecDetail.jsp" + jsessionid + "?print=item&";
        window.open(jsppage + param, "cirqit_" + new Date().getTime(), 'dependant=yes, width=725, height=550, location=no, menubar=yes, status=yes, toolbar=no, scrollbars=yes, resizable=yes');
    }
    else
        popupprint(itemNbr,specNbr);
}
function popupprintallnew(isNew,estimateNbr,versionNbr)
{
    if (isNew)
    {
            var param = "estimateNbr=" + estimateNbr;
            param = param + "&versionNbr=" + versionNbr;
            param = param + "&printall=true&isnew=true&mode=readonly";
            jsppage = "PrintSpecDetail.jsp" + jsessionid + "?";
            window.open(jsppage + param, "cirqit_" + new Date().getTime(), 'dependant=yes, width=725, height=550, location=no, menubar=yes, status=yes, toolbar=no, scrollbars=yes, resizable=yes');
    }
    else
       popupprintall(estimateNbr,versionNbr);
}
function popupshipprint(estimateNbr,versionNbr,supplierid)
{
            jsppage = "PrintSpecDetail.jsp" + jsessionid + "?";
            var param = "print=ship";
            if ((estimateNbr != null && estimateNbr.length > 0) )
                param = param + "&estimateNbr=" + estimateNbr;
            if ((versionNbr != null && versionNbr.length > 0) )
                param = param + "&versionNbr=" + versionNbr;
            if ((supplierid != null && supplierid.length > 0) )
                param = param + "&supplierid=" + supplierid;
            window.open(jsppage + param, "cirqit_" + new Date().getTime(), 'dependant=yes, width=725, height=550, location=no, menubar=yes, status=yes, toolbar=no, scrollbars=yes, resizable=yes');
}

// xPer = 50 and yPer = 50 = CENTERED
var popupWindow = null;
function popup(name, url, width, height, xPer, yPer)
{
    if ( name == null )
        name = "cirqit_" + new Date().getTime();

     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;

    if ( xPer != null && yPer != null )
        var xOffset = (xMax - width) * (xPer / 100), yOffset = (yMax - height) * (yPer / 100);
    else
        var xOffset = (xMax - width)/2, yOffset = (yMax - height)/2;

    popupWindow = window.open(url, name, 'dependant=yes, width='+ width +', height='+ height +', location=no, menubar=yes, status=yes, toolbar=no, scrollbars=yes, resizable=yes,screenX='+xOffset+',screenY='+yOffset+',top='+yOffset+',left='+xOffset+'');
}

function showAlert(msg)
{
    if ( popupWindow != null && !popupWindow.closed )
        theWin = popupWindow.window;
    else
        theWin = window;
    theWin.alert( msg );
}

function disableAllButtons(theForm)
{
     var intEnd = theForm.elements
     for( i = 0; i < intEnd.length; i++ )
     {
          if(intEnd[i].type == "button" || intEnd[i].type == "submit" )
            intEnd[i].disabled = true;
     }
}
var isSubmit = true;

function checkProcess()
{
    if (isSubmit)
    {
        isSubmit = false;
        return true;
    }
    else
    {
        window.status= processWait;
        return false
    }
}

function revertSubmit()
{
    isSubmit = true;
}

function changeSelectImage( selectObj )
{
    if( !selectObj )
        return;
    if ( !eval( "_img_" + selectObj.name ) )
        return;
    var imageArray = eval( "_img_" + selectObj.name );
    var index = selectObj.selectedIndex;
    if( index < 0 || index >= imageArray.length )
        return;

    if (!document.images["img_" + selectObj.name])
        return;
    document.images["img_" + selectObj.name].src = imageArray[index].src;
}

function toggleEntitySelect( selectBox )
{
    var divs = document.getElementsByTagName('div');
    for ( var a = 0; a < divs.length; a++ )
    {
        // skip any <div> tags that aren't for pricing display
        if ( divs[a].getAttribute('group') == null )
            continue;

        if ( divs[a].id == ( selectBox.name + selectBox.options[selectBox.selectedIndex].value ) )
            divs[a].style.display = ''
        else if ( divs[a].getAttribute('group') == selectBox.name )
        {
            divs[a].style.display = 'none'
            clearFieldsRecusive( divs[a] )
        }
    }
}

function clearFieldsRecusive( obj )
{
    var children = obj.childNodes;
    for ( var b = 0; b < children.length; b++ )
    {
        if ( !children[b].type )
        {
            clearFieldsRecusive( children[b] )
        }
        else if ( children[b].type == "text" || children[b].type == "password" || children[b].type == "textarea" )
            children[b].value = '';
        else if ( children[b].type == "radio" || children[b].type == "checkbox" )
            children[b].checked = false;
        else if ( children[b].type == 'select-one')
        {
            children[b].selectedIndex = 0;
        }
        else if ( children[b].type == 'select-multiple' )
        {
            for (var k=0; k < children[b].options.length; k++)
            {
                children[b].options[k].selected = false;
            }
        }
    }

}

function setCookie(cookieName,cookieValue,nDays)
{
    var today = new Date();
    var expire = new Date();

    if ( nDays == null || nDays == 0 )
        nDays = 1;
    expire.setTime( today.getTime() + 3600000 * 24 * nDays );
    document.cookie = cookieName + "=" + escape( cookieValue ) + ";expires=" + expire.toGMTString();

}


function getCookie(cookieName)
{
    var theCookie = "" + document.cookie;
    var ind = theCookie.indexOf( cookieName );
    if (ind == -1 || cookieName == "")
        return "";
    var ind1 = theCookie.indexOf( ';' , ind );
    if (ind1 == -1 )
        ind1 = theCookie.length;
    return unescape( theCookie.substring( ind + cookieName.length + 1, ind1 ) );
}

function removeFormat( strOut)
{
    if ( strOut == null || strOut.length == 0 )
        return parseFloat(strOut);
    strOut = strOut.replace(new RegExp(groupingSeparator.replace(/\./g, "\\."), "g"), ""); // must convert separators to Regex compatible escaped strings first
    strOut = strOut.replace(new RegExp(decimalSeperator.replace(/\./g, "\\."), "g"), ".");
    return parseFloat(strOut);
}
function addFormat( number)
{
    var strOut = number + '';
    strOut = strOut.replace(".",decimalSeperator);
    return  outputWhole( strOut + '' ) + outputFraction( strOut + '');
}

function outputWhole(number)
{
	number = removeCommas( number )
    if (number.length <= groupingDigits)
        return ( number == '' ? '0' : number );
    else
	{
        var mod = number.length % groupingDigits;
        var output = ( mod == 0 ? '' : ( number.substring( 0, mod ) ) );
        for ( var i = 0; i < Math.floor( number.length / groupingDigits ); i++ )
		{
            if ( ( mod == 0 ) && ( i == 0 ) )
                output += number.substring( mod + groupingDigits * i, mod + groupingDigits * i + groupingDigits );
            else
                output += groupingSeparator + number.substring( mod + groupingDigits * i, mod + groupingDigits * i + groupingDigits );
        }
        return ( output );
    }
}

function outputFraction(amount)
{
	if ( currencyMaximumFractionDigits <= 0 )
		return ''
	if ( amount.indexOf( decimalSeperator ) == -1 )
		amount = ''
	else
		amount = amount.substring( amount.indexOf( decimalSeperator ) + 1, amount.indexOf( decimalSeperator ) + currencyMaximumFractionDigits + 1 )

	amount = removeCommas( amount )

	var zeroes = ''
	for ( var i = 0; i < currencyMaximumFractionDigits - amount.length; i++ )
		zeroes += '0'
    if (amount == 0 )
  		return ''

	return decimalSeperator + amount + zeroes

    return ( amount.length <= 1 ? decimalSeperator + '0' + amount : decimalSeperator + amount );

}

function checkEmail( email )
{
	var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	return filter.test( trim(email) );
}

var IFrameObj; // our IFrame object
function callToServer(URL) {
  if (!document.createElement) {return true};
  var IFrameDoc;
  if (!IFrameObj && document.createElement) {
    // create the IFrame and assign a reference to the
    // object to our global variable IFrameObj.
    // this will only happen the first time
    // callToServer() is called
   try {
      var tempIFrame=document.createElement('iframe');
      tempIFrame.setAttribute('id','RSIFrame');
      tempIFrame.style.border='0px';
      tempIFrame.style.width='0px';
      tempIFrame.style.height='0px';
      IFrameObj = document.body.appendChild(tempIFrame);

      if (document.frames) {
        // this is for IE5 Mac, because it will only
        // allow access to the document object
        // of the IFrame if we access it through
        // the document.frames array
        IFrameObj = document.frames['RSIFrame'];
      }
    } catch(exception) {
      // This is for IE5 PC, which does not allow dynamic creation
      // and manipulation of an iframe object. Instead, we'll fake
      // it up by creating our own objects.
      iframeHTML='\<iframe id="RSIFrame" style="';
      iframeHTML+='border:0px;';
      iframeHTML+='width:0px;';
      iframeHTML+='height:0px;';
      iframeHTML+='"><\/iframe>';
      document.body.innerHTML+=iframeHTML;
      IFrameObj = new Object();
      IFrameObj.document = new Object();
      IFrameObj.document.location = new Object();
      IFrameObj.document.location.iframe = document.getElementById('RSIFrame');
      IFrameObj.document.location.replace = function(location) {
        this.iframe.src = location;
      }
    }
  }

  if (navigator.userAgent.indexOf('Gecko') !=-1 && !IFrameObj.contentDocument) {
    // we have to give NS6 a fraction of a second
    // to recognize the new IFrame
    setTimeout('callToServer()',10);
    return false;
  }

  if (IFrameObj.contentDocument) {
    // For NS6
    IFrameDoc = IFrameObj.contentDocument;
  } else if (IFrameObj.contentWindow) {
    // For IE5.5 and IE6
    IFrameDoc = IFrameObj.contentWindow.document;
  } else if (IFrameObj.document) {
    // For IE5
    IFrameDoc = IFrameObj.document;
  } else {
    return true;
  }

  IFrameDoc.location.replace(URL);
  return false;
}
/*
These functions could also (maybe better)
be put in an imported JS file
link to the site - http://groups.google.com/group/comp.lang.javascript/browse_thread/thread/a1a2033e0ed9e72d/6df58b515d6a75e1?lnk=st&q=javascript+escape+plus+sign&rnum=2&hl=en#6df58b515d6a75e1
*/

/*
JavaScript equivalent of java.net.URLEncoder.encode(String s)
(from Java Docs:-)
1.The ASCII characters 'a' through 'z', 'A' through 'Z', and '0'
  through '9' remain the same.
2.The space character ' ' is converted into a plus sign '+'.
3.All other characters are converted into the 3-character string
  "%xy", where xy is the two-digit hexadecimal representation of
  the lower 8-bits of the character.


usage: var coded = URLEncoder(string);


JavaScript equivalent of java.net.URLDecoder.decode(String s)
1.Exact reverse of java.net.URLEncoder.encode(String s)


usage: var decoded = URLDecoder(string);


Note: prior to JScrip 5.5 String.replace() will not accept a function
as it's second parameter so the function set-up will try to compensate.
*/
if('a'.replace(/a/, function(){return '';}).length == 0){
    window.URLDecoder = function(str){
        return str.replace(/%[0-9a-f]{2}|\+/gi, dec);
        function dec(cMatch){
            if(cMatch == '+')return ' ';
            var len = cMatch.length;
            var hex = cMatch.substring((len-2), len);
            return String.fromCharCode(parseInt(hex, 16));
        }
    }
    window.URLEncoder = function(str){
        return str.replace(/[^a-z0-9]/gi, enc);
        function enc(cMatch){
            if(cMatch == ' ')return '+';
            var hex = cMatch.charCodeAt(0).toString(16);
            var len = hex.length;
            switch(len){
                case 0:
                    hex = '00';
                    break;
                case 1:
                    hex = '0'+hex;
                case 2:
                    break;
                defalt:
                    hex = hex.substring((len-2), len);
                    break;
            }
            return '%'+hex;
        }
    }


}else{


    window.URLDecoder = function(str){
        var outSt = '';
        for(var c = 0;c < str.length;c++){
            var cTr = str.charAt(c);
            if((cTr == '%')&&((c + 2) <= str.length)){
                outSt += String.fromCharCode(
                         parseInt(str.substring((c+1),
                                    ((c+=2)+1)), 16));
            }else if(cTr == '+'){
                outSt += ' ';
            }else{
                outSt += cTr;
            }
        }
        return outSt;
    }
    window.URLEncoder = function(str){
        var outSt = '';
        for(var c = 0;c < str.length;c++){
            var cCode = str.charCodeAt(c);
            if(((cCode > 47)&&(cCode < 58))||
               ((cCode > 64)&&(cCode < 91))||
               ((cCode > 96)&&(cCode < 123))){
                outSt += str.charAt(c);
            }else if(cCode == 32){
                outSt += '+';
            }else{
                var hex = cCode.toString(16);
                var len = hex.length;
                switch(len){
                    case 0:
                        hex = '00';
                        break;
                    case 1:
                        hex = '0'+hex;
                    case 2:
                        break;
                    defalt:
                        hex = hex.substring((len-2), len);
                        break;
                }
                outSt += '%'+hex;
            }
        }
        return outSt;
    }

}

function checkAllCats(input, col, itemNbr)
{
	var theForm = input.form;
	for ( var x = 0; x < theForm.elements.length; x++ )
	{
		if ( theForm.elements[x].type == 'checkbox' )
		{
			if ( (theForm.elements[x].getAttribute('col') == col || (input.checked && col == 'req' && theForm.elements[x].getAttribute('col') != null) )&& (itemNbr == null || theForm.elements[x].getAttribute('itemNbr') == itemNbr) )
			{
				theForm.elements[x].checked = input.checked
				if ( itemNbr != null && !input.checked )
                    document.getElementById(col+"ColToggle").checked = false;
				if ( itemNbr == null && input.checked && col == 'req' )
                    document.getElementById("priceColToggle").checked = true;
				if ( itemNbr != null && input.checked && col == 'req' )
                    document.getElementById("price"+itemNbr+"Toggle").checked = true;
                if ( theForm.elements[x].checked && theForm.elements[x].name != '')
                    theForm.elements[theForm.elements[x].name.replace("req", "price")].checked = true;
            }
		}
	}
}
function validatePriceCats(theForm)
{
    var curItemNbr = null;
    var hasCat = false;
    for ( var x = 0; x < theForm.elements.length; x++ )
	{
        var input = theForm.elements[x]
        if ( input.type == 'checkbox' )
        {
            var itemNbr = input.getAttribute( 'itemNbr' );
            if ( input.getAttribute('col') == 'price' && itemNbr != null )
			{
                if ( curItemNbr != itemNbr )
                {
                    if ( !hasCat && curItemNbr != null )
                        return false;
                    curItemNbr = itemNbr;
                    hasCat = false;
                }
                if ( input.checked )
                    hasCat = true;
            }
		}
	}
    if ( !hasCat && curItemNbr != null )
        return false;
    return true;
}
function checkCat(input, col, itemNbr)
{
	var theForm = input.form;
	if ( !input.checked )
	{
		document.getElementById(col+"ColToggle").checked = false;
        if (itemNbr !=null)
            document.getElementById(col+itemNbr+"Toggle").checked = false;
	}
    else if ( col == 'req' )
        input.form.elements[input.name.replace("req", "price")].checked = true;
}
function toggleDisplay(elementName, on)
{
    if ( on == undefined )
    {
        if ( document.getElementById(elementName) )
        {
            if ( document.getElementById(elementName).style.display == '' )
                document.getElementById(elementName).style.display = 'none'
            else
                document.getElementById(elementName).style.display = ''
        }
    }
    else
    {
        if ( document.getElementById(elementName) )
        {
            if ( !on )
                document.getElementById(elementName).style.display = 'none'
            else
                document.getElementById(elementName).style.display = ''
        }
    }
}

/**
 * Returns true if 's' is contained in the array 'a'
 */
function contains(a, e) {
	for(j=0;j<a.length;j++)if(a[j]==e)return true;
	return false;
}

function validateQtys(field, prefix)
{
    if ( prefix == null )
        prefix = field.id.substring(0,field.id.length-1);
    var theForm = field.form;
    var qty = new Array();
    for ( var x = 0; x < 3; x++ )
    {
        if ( document.getElementById(prefix+(x+1)) )
        {
            var tmpQty = removeFormat(document.getElementById(prefix+(x+1)).value);
            if ( !contains(qty, tmpQty))
                qty[x] = tmpQty;
        }
    }
    qty.sort(function(a,b) {if (isNaN(b)) {return -1;}if (isNaN(a)) {return 1;} return a-b;});
    for ( var x = 0; x < 3; x++ )
    {
        if ( document.getElementById(prefix+(x+1)) )
            document.getElementById(prefix+(x+1)).value = (qty[x]) ? addCommas(qty[x]) : '';
    }
}

function getSelectionId( text, li )
{
    if ( li.id == '-1' )
        text.value = '';
    if ( $(li).hasClassName('clickNav') )
    {
        /*text.value = '';
        $(text.id+'_hidden').value = ''*/
        location.href='/admin/supplierAdmin.jsp?id='+li.id+'&backTo=/SupplierList.jsp'
    }
    else
    {
        $(text.id+'_hidden').value = li.id
        $(text).blur()
    }
}

function setFormDirty(theForm)
{
    theForm.setAttribute('dirty','true');
}
function isFormDirty(theForm)
{
	var el, opt, hasDefault, i = 0, j;
    if ( theForm.getAttribute('dirty') && theForm.getAttribute('dirty') == 'true' )
        return true;
	while (el = theForm.elements[i++]) {
		switch (el.type) {
			case 'text' :
                   	case 'textarea' :
                   	case 'hidden' :
                         	if (!/^\s*$/.test(el.value) && el.value != el.defaultValue) return true;
                         	break;
                   	case 'checkbox' :
                   	case 'radio' :
                         	if (el.checked != el.defaultChecked) return true;
                         	break;
                   	case 'select-one' :
                   	case 'select-multiple' :
                         	j = 0, hasDefault = false;
                         	while (opt = el.options[j++])
                                	if (opt.defaultSelected) hasDefault = true;
                         	j = hasDefault ? 0 : 1;
                         	while (opt = el.options[j++])
                                	if (opt.selected != opt.defaultSelected) return true;
                         	break;
		}
	}
	return false;
}

function isVisible(obj)
{
    if (obj == document) return true

    if (!obj) return false
    if (!obj.parentNode) return false
    if (obj.style) {
        if (obj.style.display == 'none') return false
        if (obj.style.visibility == 'hidden') return false
    }

    //Try the computed style in a standard way
    if (window.getComputedStyle) {
        var style = window.getComputedStyle(obj, "")
        if (style.display == 'none') return false
        if (style.visibility == 'hidden') return false
    }

    //Or get the computed style using IE's silly proprietary way
    var style = obj.currentStyle
    if (style) {
        if (style['display'] == 'none') return false
        if (style['visibility'] == 'hidden') return false
    }

    return isVisible(obj.parentNode)
}

function disableEnterKey(evt)
{
    var evt = (evt) ? evt : ((event) ? event : null);
    var node = (evt.target) ? evt.target : ((evt.srcElement) ? evt.srcElement : null);
    if ( (evt.keyCode == 13) && (node.type == "text" || node.type == "checkbox") )
    {
        return false;
    }
}