var digits = "0123456789";
var lowercaseLetters = "abcdefghijklmnopqrstuvwxyz";
var uppercaseLetters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
var whitespace = " \t\n\r";
var decimalPointDelimiter = ".";
var phoneNumberDelimiters = "()- ";
var validUSPhoneChars = digits + phoneNumberDelimiters;
var validWorldPhoneChars = digits + phoneNumberDelimiters + "+";
var SSNDelimiters = "- ";
var validSSNChars = digits + SSNDelimiters;
var digitsInSocialSecurityNumber = 9;
var digitsInUSPhoneNumber = 10;
var ZIPCodeDelimiters = "-";
var ZIPCodeDelimeter = "-";
var validZIPCodeChars = digits + ZIPCodeDelimiters;
var digitsInZIPCode1 = 5;
var digitsInZIPCode2 = 9;
var creditCardDelimiters = " ";
var mPrefix = "You did not enter a value into the ";
var mSuffix = " field. This is a required field. Please enter it now.";
var sUSLastName = "Last Name";
var sUSFirstName = "First Name";
var sWorldLastName = "Family Name";
var sWorldFirstName = "Given Name";
var sTitle = "Title";
var sCompanyName = "Company Name";
var sUSAddress = "Street Address";
var sWorldAddress = "Address";
var sCity = "City";
var sStateCode = "State Code";
var sWorldState = "State, Province, or Prefecture";
var sCountry = "Country";
var sZIPCode = "ZIP Code";
var sWorldPostalCode = "Postal Code";
var sPhone = "Phone Number";
var sFax = "Fax Number";
var sDateOfBirth = "Date of Birth";
var sExpirationDate = "Expiration Date";
var sEmail = "Email";
var sSSN = "Social Security Number";
var sCreditCardNumber = "Credit Card Number";
var sOtherInfo = "Other Information";
var iStateCode = "This field must be a valid two character U.S. state abbreviation (like CA for California). Please reenter it now.";
var iZIPCode = "This field must be a 5 or 9 digit U.S. ZIP Code (like 94043). Please reenter it now.";
var iUSPhone = "This field must be a 10 digit U.S. phone number (like 415 555 1212). Please reenter it now.";
var iWorldPhone = "This field must be a valid international phone number. Please reenter it now.";
var iSSN = "This field must be a 9 digit U.S. social security number (like 123 45 6789). Please reenter it now.";
var iEmail = "This field must be a valid email address (like myname@mydomain.com). Please reenter it now.";
var iCreditCardPrefix = "This is not a valid ";
var iCreditCardSuffix = " credit card number. (Please enter numbers only.) Please reenter it now.";
var iDay = "This field must be a day number between 1 and 31.  Please reenter it now.";
var iMonth = "This field must be a month number between 1 and 12.  Please reenter it now.";
var iYear = "This field must be a 2 or 4 digit year number.  Please reenter it now.";
var iDatePrefix = "The Day, Month, and Year for ";
var iDateSuffix = " do not form a valid date.  Please reenter them now.";
var pEntryPrompt = "Please enter a ";
var pStateCode = "2 character code (like CA).";
var pZIPCode = "5 or 9 digit U.S. ZIP Code (like 94043).";
var pUSPhone = "10 digit U.S. phone number (like 415 555 1212).";
var pWorldPhone = "international phone number.";
var pSSN = "9 digit U.S. social security number (like 123 45 6789).";
var pEmail = "valid email address (like foo@bar.com).";
var pCreditCard = "valid credit card number.";
var pDay = "day number between 1 and 31.";
var pMonth = "month number between 1 and 12.";
var pYear = "2 or 4 digit year number.";
var defaultEmptyOK = false

function whereonsite(){
	document.all['ponotes'].value = prompt('Where were the materials left onsite?', '');
}

function calcBudget(){
	var retperc;
	var billperc;
	var totret;
	var baldue;
	var prevbill;
	var hidprevbill;
	var soldamt;
	
	retperc = '.' + document.all['retainperc'].value;
	billperc = '.' + document.all['billedperc'].value;
	if(retperc == '.0.0'){retperc = 0};
	if(retperc == '.1'){retperc = .01};
	if(retperc == '.2'){retperc = .02};
	if(retperc == '.3'){retperc = .03};
	if(retperc == '.4'){retperc = .04};
	if(retperc == '.5'){retperc = .05};
	if(retperc == '.6'){retperc = .06};
	if(retperc == '.7'){retperc = .07};
	if(retperc == '.8'){retperc = .08};
	if(retperc == '.9'){retperc = .09};
	if(retperc == '.100'){retperc = 1};
	
	if(billperc == '.0.0'){billperc = 0};
	if(billperc == '.1'){billperc = .01};
	if(billperc == '.2'){billperc = .02};
	if(billperc == '.3'){billperc = .03};
	if(billperc == '.4'){billperc = .04};
	if(billperc == '.5'){billperc = .05};
	if(billperc == '.6'){billperc = .06};
	if(billperc == '.7'){billperc = .07};
	if(billperc == '.8'){billperc = .08};
	if(billperc == '.9'){billperc = .09};
	if(billperc == '.100'){billperc = 1};
	
	//prevbill = document.all['prevbill'].value;
	//hidprevbill = document.all['hidprevbill'].value;
	
        formatCurrency(document.all['saleprice'], 0);
	soldamt = document.all['saleprice'].value;
	formatCurrency(document.all['saleprice'], 1);
	
	soldamt = soldamt.replace(',','');
	
	//alert('retperc:' + retperc + '\nbillperc:' + billperc + '\nprevbill:' + prevbill + '\nhidprevbill:' + hidprevbill + '\nsoldamt:' + soldamt);

	//update balance due by billed percentage...
	if(isNaN(billperc)){
		billperc = 0;
		document.all['billedperc'].value = '0.0';
	}
	//alert(soldamt + ' - ' + billperc);
	baldue = soldamt * billperc;
	//alert(baldue);
	document.all['balance'].value = baldue; 
	document.all['amt'].value = baldue;
	formatCurrency(document.all['balance'], 1);
	formatCurrency(document.all['amt'], 1);

	//update total retainer amt
	if(isNaN(retperc)){
		retperc = 0;
		document.all['retainperc'].value = '0.0';
	}
	totret = baldue * retperc;
	document.all['totretain'].value = totret;
	formatCurrency(document.all['totretain'] , 1);
	
	//update hidden value field...
	//if(hidprevbill == ''){
	//	document.all['hidprevbill'].value = '0.00';
	//}else{
	//	document.all['prevbill'].value = hidprevbill;
	//	formatCurrency(document.all['prevbill'], 1);
	//}
}

function setFieldDate(fld){
    var currentTime = new Date();
    var month = currentTime.getMonth() + 1
    var day = currentTime.getDate()
    var year = currentTime.getFullYear()
    document.all[fld].value = month + "/" + day + "/" + year;
}

function formatPercent(fld){
    document.all[fld].value = document.all[fld].value / 100;
}

function calcBillPerc(){
   formatCurrency(document.all['amt'], 0);
   formatCurrency(document.all['saleprice'], 0);
   document.all['amt'].value = document.all['amt'].value.replace(',','');
   document.all['saleprice'].value = document.all['saleprice'].value.replace(',','');

   document.all['billedperc'].value = document.all['amt'].value / document.all['saleprice'].value;
   
   formatCurrency(document.all['amt'], 1);
   formatCurrency(document.all['saleprice'], 1);
}

function makeArray(n) {
   for (var i = 1; i <= n; i++) {
      this[i] = 0
   } 
   return this
}


var daysInMonth = makeArray(12);
daysInMonth[1] = 31;
daysInMonth[2] = 29;   // must programmatically check this
daysInMonth[3] = 31;
daysInMonth[4] = 30;
daysInMonth[5] = 31;
daysInMonth[6] = 30;
daysInMonth[7] = 31;
daysInMonth[8] = 31;
daysInMonth[9] = 30;
daysInMonth[10] = 31;
daysInMonth[11] = 30;
daysInMonth[12] = 31;


var USStateCodeDelimiter = "|";
var USStateCodes = "AL|AK|AS|AZ|AR|CA|CO|CT|DE|DC|FM|FL|GA|GU|HI|ID|IL|IN|IA|KS|KY|LA|ME|MH|MD|MA|MI|MN|MS|MO|MT|NE|NV|NH|NJ|NM|NY|NC|ND|MP|OH|OK|OR|PW|PA|PR|RI|SC|SD|TN|TX|UT|VT|VI|VA|WA|WV|WI|WY|AE|AA|AE|AE|AP"

function isEmpty(s)
{   return ((s == null) || (s.length == 0))
}

function isWhitespace (s)
{   var i;
    if (isEmpty(s)) return true;
    for (i = 0; i < s.length; i++)
    {   
        var c = s.charAt(i);
        if (whitespace.indexOf(c) == -1) return false;
    }
    return true;
}

function stripCharsInBag (s, bag)
{   var i;
    var returnString = "";
    for (i = 0; i < s.length; i++)
    {   
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function stripCharsNotInBag (s, bag)
{   var i;
    var returnString = "";
	for (i = 0; i < s.length; i++)
    {
        var c = s.charAt(i);
        if (bag.indexOf(c) != -1) returnString += c;
    }
    return returnString;
}

function stripWhitespace (s)
{   return stripCharsInBag (s, whitespace)
}

function charInString (c, s)
{   for (i = 0; i < s.length; i++)
    {   if (s.charAt(i) == c) return true;
    }
    return false
}

function stripInitialWhitespace (s)

{   var i = 0;

    while ((i < s.length) && charInString (s.charAt(i), whitespace))
       i++;
    
    return s.substring (i, s.length);
}

function isLetter (c)
{   return ( ((c >= "a") && (c <= "z")) || ((c >= "A") && (c <= "Z")) )
}

function isDigit (c)
{   return ((c >= "0") && (c <= "9"))
}

function isLetterOrDigit (c)
{   return (isLetter(c) || isDigit(c))
}

function isInteger (s)

{   var i;

    if (isEmpty(s)) 
       if (isInteger.arguments.length == 1) return defaultEmptyOK;
       else return (isInteger.arguments[1] == true);

	for (i = 0; i < s.length; i++)
    {   
        var c = s.charAt(i);
        if (!isDigit(c)) return false;
    }
    return true;
}

function isSignedInteger (s)
{   if (isEmpty(s)) 
       if (isSignedInteger.arguments.length == 1) return defaultEmptyOK;
       else return (isSignedInteger.arguments[1] == true);
    else {
        var startPos = 0;
        var secondArg = defaultEmptyOK;

        if (isSignedInteger.arguments.length > 1)
            secondArg = isSignedInteger.arguments[1];
        if ( (s.charAt(0) == "-") || (s.charAt(0) == "+") )
           startPos = 1;    
        return (isInteger(s.substring(startPos, s.length), secondArg))
    }
}

function isPositiveInteger (s)
{   var secondArg = defaultEmptyOK;

    if (isPositiveInteger.arguments.length > 1)
        secondArg = isPositiveInteger.arguments[1];
    return (isSignedInteger(s, secondArg)
         && ( (isEmpty(s) && secondArg)  || (parseInt (s) > 0) ) );
}

function isNonnegativeInteger (s)
{   var secondArg = defaultEmptyOK;

    if (isNonnegativeInteger.arguments.length > 1)
        secondArg = isNonnegativeInteger.arguments[1];
    return (isSignedInteger(s, secondArg)
         && ( (isEmpty(s) && secondArg)  || (parseInt (s) >= 0) ) );
}

function isNegativeInteger (s)
{   var secondArg = defaultEmptyOK;

    if (isNegativeInteger.arguments.length > 1)
        secondArg = isNegativeInteger.arguments[1];
    return (isSignedInteger(s, secondArg)
         && ( (isEmpty(s) && secondArg)  || (parseInt (s) < 0) ) );
}

function isNonpositiveInteger (s)
{   var secondArg = defaultEmptyOK;

    if (isNonpositiveInteger.arguments.length > 1)
        secondArg = isNonpositiveInteger.arguments[1];
    return (isSignedInteger(s, secondArg)
         && ( (isEmpty(s) && secondArg)  || (parseInt (s) <= 0) ) );
}

function isFloat (s)

{   var i;
    var seenDecimalPoint = false;

    if (isEmpty(s)) 
       if (isFloat.arguments.length == 1) return defaultEmptyOK;
       else return (isFloat.arguments[1] == true);

    if (s == decimalPointDelimiter) return false;
    for (i = 0; i < s.length; i++)
    {   
        var c = s.charAt(i);
        if ((c == decimalPointDelimiter) && !seenDecimalPoint) seenDecimalPoint = true;
        else if (!isDigit(c)) return false;
    }
    return true;
}

function isSignedFloat (s)
{   if (isEmpty(s)) 
       if (isSignedFloat.arguments.length == 1) return defaultEmptyOK;
       else return (isSignedFloat.arguments[1] == true);

    else {
        var startPos = 0;
        var secondArg = defaultEmptyOK;

        if (isSignedFloat.arguments.length > 1)
            secondArg = isSignedFloat.arguments[1];
        if ( (s.charAt(0) == "-") || (s.charAt(0) == "+") )
           startPos = 1;    
        return (isFloat(s.substring(startPos, s.length), secondArg))
    }
}

function isAlphabetic (s)
{   var i;
    if (isEmpty(s)) 
       if (isAlphabetic.arguments.length == 1) return defaultEmptyOK;
       else return (isAlphabetic.arguments[1] == true);
    for (i = 0; i < s.length; i++)
    {   
        var c = s.charAt(i);

        if (!isLetter(c))
        return false;
    }
    return true;
}

function isAlphanumeric (s)

{   var i;

    if (isEmpty(s)) 
       if (isAlphanumeric.arguments.length == 1) return defaultEmptyOK;
       else return (isAlphanumeric.arguments[1] == true);
    for (i = 0; i < s.length; i++)
    {   
        var c = s.charAt(i);
        if (! (isLetter(c) || isDigit(c) ) )
        return false;
    }
    return true;
}

function reformat (s)
{   var arg;
    var sPos = 0;
    var resultString = "";
    for (var i = 1; i < reformat.arguments.length; i++) {
       arg = reformat.arguments[i];
       if (i % 2 == 1) resultString += arg;
       else {
           resultString += s.substring(sPos, sPos + arg);
           sPos += arg;
       }
    }
    return resultString;
}

function isSSN (s)
{   if (isEmpty(s)) 
       if (isSSN.arguments.length == 1) return defaultEmptyOK;
       else return (isSSN.arguments[1] == true);
    return (isInteger(s) && s.length == digitsInSocialSecurityNumber)
}

function isUSPhoneNumber (s)
{   if (isEmpty(s)) 
       if (isUSPhoneNumber.arguments.length == 1) return defaultEmptyOK;
       else return (isUSPhoneNumber.arguments[1] == true);
    return (isInteger(s) && s.length == digitsInUSPhoneNumber)
}

function isInternationalPhoneNumber (s)
{   if (isEmpty(s)) 
       if (isInternationalPhoneNumber.arguments.length == 1) return defaultEmptyOK;
       else return (isInternationalPhoneNumber.arguments[1] == true);
    return (isPositiveInteger(s))
}

function isZIPCode (s)
{  if (isEmpty(s)) 
       if (isZIPCode.arguments.length == 1) return defaultEmptyOK;
       else return (isZIPCode.arguments[1] == true);
   return (isInteger(s) && 
            ((s.length == digitsInZIPCode1) ||
             (s.length == digitsInZIPCode2)))
}

function isStateCode(s)
{   if (isEmpty(s)) 
       if (isStateCode.arguments.length == 1) return defaultEmptyOK;
       else return (isStateCode.arguments[1] == true);
    return ( (USStateCodes.indexOf(s) != -1) &&
             (s.indexOf(USStateCodeDelimiter) == -1) )
}

function isEmail (s)
{   if (isEmpty(s)) 
       if (isEmail.arguments.length == 1) return defaultEmptyOK;
       else return (isEmail.arguments[1] == true);
    if (isWhitespace(s)) return false;
    var i = 1;
    var sLength = s.length;
    while ((i < sLength) && (s.charAt(i) != "@"))
    { i++
    }

    if ((i >= sLength) || (s.charAt(i) != "@")) return false;
    else i += 2;
    while ((i < sLength) && (s.charAt(i) != "."))
    { i++
    }
    if ((i >= sLength - 1) || (s.charAt(i) != ".")) return false;
    else return true;
}

function isTime (s)
{   if (isEmpty(s)) 
       if (isTime.arguments.length == 1) return defaultEmptyOK;
       else return (isTime.arguments[1] == true);
   if (isWhitespace(s)) return false;
    var i = 1;
    var sLength = s.length;
    while ((i < sLength) && (s.charAt(i) != ":"))
    { i++
    }
    if ((i >= sLength) || (s.charAt(i) != ":")) return false;
    else i += 2;
    if ((i >= sLength - 2) || (s.charAt(i) != ":")) return false;
    else return true;
}

function isYear (s)
{   if (isEmpty(s)) 
       if (isYear.arguments.length == 1) return defaultEmptyOK;
       else return (isYear.arguments[1] == true);
    if (!isNonnegativeInteger(s)) return false;
    return ((s.length == 2) || (s.length == 4));
}

function isIntegerInRange (s, a, b)
{   if (isEmpty(s)) 
       if (isIntegerInRange.arguments.length == 1) return defaultEmptyOK;
       else return (isIntegerInRange.arguments[1] == true);
    if (!isInteger(s, false)) return false;
    var num = parseInt (s);
    return ((num >= a) && (num <= b));
}

function isMonth (s)
{   if (isEmpty(s)) 
       if (isMonth.arguments.length == 1) return defaultEmptyOK;
       else return (isMonth.arguments[1] == true);
    return isIntegerInRange (s, 1, 12);
}

function isDay (s)
{   if (isEmpty(s)) 
       if (isDay.arguments.length == 1) return defaultEmptyOK;
       else return (isDay.arguments[1] == true);   
    return isIntegerInRange (s, 1, 31);
}

function daysInFebruary (year)
{   
    return (  ((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0) ) ) ? 29 : 28 );
}

function isDate (year, month, day)
{   
    if (! (isYear(year, false) && isMonth(month, false) && isDay(day, false))) return false;
    var intYear = parseInt(year);
    var intMonth = parseInt(month);
    var intDay = parseInt(day);
    if (intDay > daysInMonth[intMonth]) return false; 
    if ((intMonth == 2) && (intDay > daysInFebruary(intYear))) return false;
    return true;
}

function prompt (s)
{   window.status = s
}

function promptEntry (s)
{   window.status = pEntryPrompt + s
}

function warnEmpty (theField, s)
{   theField.focus()
    alert(mPrefix + s + mSuffix)
    return false
}

function warnInvalid (theField, s){ 
    theField.value = ""
    theField.select()
    alert(s)
    return false
}

function checkString (theField, s, emptyOK)
{   
    if (checkString.arguments.length == 2) emptyOK = defaultEmptyOK;
    if ((emptyOK == true) && (isEmpty(theField.value))) return true;
    if (isWhitespace(theField.value)) 
       return warnEmpty (theField, s);
    else return true;
}

function checkStateCode (theField, emptyOK)
{   if (checkStateCode.arguments.length == 1) emptyOK = defaultEmptyOK;
    if ((emptyOK == true) && (isEmpty(theField.value))) return true;
    else
    {  theField.value = theField.value.toUpperCase();
       if (!isStateCode(theField.value, false)) 
          return warnInvalid (theField, iStateCode);
       else return true;
    }
}

function reformatZIPCode (ZIPString)
{   if (ZIPString.length == 5) return ZIPString;
    else return (reformat (ZIPString, "", 5, "-", 4));
}

function checkZIPCode (theField, emptyOK)
{   if (checkZIPCode.arguments.length == 1) emptyOK = defaultEmptyOK;
    if ((emptyOK == true) && (isEmpty(theField.value))) return true;
    else
    { var normalizedZIP = stripCharsInBag(theField.value, ZIPCodeDelimiters)
      if (!isZIPCode(normalizedZIP, false)) 
         return warnInvalid (theField, iZIPCode);
      else 
      { 
         theField.value = reformatZIPCode(normalizedZIP)
         return true;
      }
    }
}

function reformatUSPhone (USPhone)
{   return (reformat (USPhone, "(", 3, ") ", 3, "-", 4))
//return (reformat (USPhone, "", 3, "-", 3, "-", 4))
}

function checkUSPhone (theField, emptyOK)
{   if (checkUSPhone.arguments.length == 1) emptyOK = defaultEmptyOK;
    if ((emptyOK == true) && (isEmpty(theField.value))) return true;
    else
    {  var normalizedPhone = stripCharsInBag(theField.value, phoneNumberDelimiters)
       if (!isUSPhoneNumber(normalizedPhone, false)) 
          return warnInvalid (theField, iUSPhone);
       else 
       {  
          theField.value = reformatUSPhone(normalizedPhone)
          return true;
       }
    }
}

function checkPassword (pwdfield, cpwdfield){
	if (pwdfield.value != '' && cpwdfield.value != ''){
		if (pwdfield.value != cpwdfield.value){
			pwdfield.value = '';
			cpwdfield.value = '';
			alert('Your confirmation Password does not match.  Please try again.');
		}
	}
}

function checkEmailAddr (emfield, cemfield){
	if (emfield.value != '' && cemfield.value != ''){
		if (emfield.value != cemfield.value){
			emfield.value = '';
			cemfield.value = '';
			alert('Your confirmation E-Mail Address does not match.  Please try again.');
		}
	}
}

function shareinfo(fld, oid, otid, ca, aoid, headerotid){
    //top.opener.top.frames['procframe'].location = 'redir.aspx?cmd=shareinfo&ca=' + ca + '&aoid=' + aoid + '&fld=' + fld + '&oid=' + oid + '&otid=' + otid;
    window.open('redir.aspx?cmd=shareinfo&ca=' + ca + '&aoid=' + aoid + '&fld=' + fld + '&oid=' + oid + '&otid=' + otid + '&hd=' + headerotid, '_parent'); 
}

function checkSignup(){
	var noerr = true; 
	var errmsg = '';

	if(document.all['selplan'].value == ''){
		errmsg = errmsg + '\nStep 1: What would you like to do?'; 
		noerr = false; 
	}
	if(document.all['fname'].value == ''){
		errmsg = errmsg + '\nFirst Name'; 
		noerr = false; 
	}
	if(document.all['lname'].value == ''){
		errmsg = errmsg + '\nLast Name'; 
		noerr = false; 
	}
	if(document.all['comp'].value == ''){
		errmsg = errmsg + '\nCompany'; 
		noerr = false; 
	}
	if(document.all['email'].value == ''){
		errmsg = errmsg + '\nE-Mail'; 
		noerr = false; 
	}
	if(document.all['confemail'].value == ''){
		errmsg = errmsg + '\nConfirmation Email'; 
		noerr = false; 
	}
	if(document.all['pwd'].value == ''){
		errmsg = errmsg + '\nPassword'; 
		noerr = false; 
	}
	if(document.all['confpwd'].value == ''){
		errmsg = errmsg + '\nConfirmation Password'; 
		noerr = false; 
	}

	if(noerr){
		document.all['signupfrm'].submit();
	}else{
		errmsg = 'The following field(s) are required:\n' + errmsg
		alert(errmsg);
		return false;
	}
}

function checkNumeric (theField, emptyOK)
{   if (checkNumeric.arguments.length == 1) emptyOK = defaultEmptyOK;
    if ((emptyOK == true) && (isEmpty(theField.value))) return true;
    else
    { 
       if (!isFloat(theField.value))
          return warnInvalid (theField, "This field requires a numeric value.");
       else 
       {
          return true;
       }
    }
}

function formatDate(theField) {

	if (theField.value != ''){

		var datePat = /^(\d{1,2})(\/|-)(\d{1,2})(\/|-)(\d{4})$/;
		var matchArray = theField.value.match(datePat); // is format OK?

		if (matchArray == null && theField.value != '') {
			theField.value = '';
			alert("Please enter date as mm/dd/yyyy.");
		}else{

			// parse date into variables
			month = matchArray[1];
			day = matchArray[3];
			year = matchArray[5];

			if (month < 1 || month > 12 && theField.value != '') { // check month range
				theField.value = '';
				alert("Month must be between 1 and 12.");
			}

			if (day < 1 || day > 31 && theField.value != '') {
				theField.value = '';
				alert("Day must be between 1 and 31.");
			}

			if ((month==4 || month==6 || month==9 || month==11) && day==31 && theField.value != '') {
				theField.value = '';
				alert("Month " + month + " doesn't have 31 days!");
			}

			if (month == 2 && theField.value != '') { // check for february 29th
				var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0) && theField.value != '');
				if (day > 29 || (day==29 && !isleap)) {
				theField.value = '';
				alert("February " + year + " doesn't have " + day + " days!");
				}
			}
			return true;  // date is valid
		}
	}
}

function checkInternationalPhone (theField, emptyOK)
{   if (checkInternationalPhone.arguments.length == 1) emptyOK = defaultEmptyOK;
    if ((emptyOK == true) && (isEmpty(theField.value))) return true;
    else
    {  if (!isInternationalPhoneNumber(theField.value, false)) 
          return warnInvalid (theField, iWorldPhone);
       else return true;
    }
}

function checkEmail (theField, emptyOK)
{   if (checkEmail.arguments.length == 1) emptyOK = defaultEmptyOK;
    if ((emptyOK == true) && (isEmpty(theField.value))) return true;
    else if (!isEmail(theField.value, false)) 
       return warnInvalid (theField, iEmail);
    else return true;
}

function reformatSSN (SSN)
{   return (reformat (SSN, "", 3, "-", 2, "-", 4))
}

function checkSSN (theField, emptyOK)
{   if (checkSSN.arguments.length == 1) emptyOK = defaultEmptyOK;
    if ((emptyOK == true) && (isEmpty(theField.value))) return true;
    else
    {  var normalizedSSN = stripCharsInBag(theField.value, SSNDelimiters)
       if (!isSSN(normalizedSSN, false)) 
          return warnInvalid (theField, iSSN);
       else 
       {  
          theField.value = reformatSSN(normalizedSSN)
          return true;
       }
    }
}

function checkYear (theField, emptyOK)
{   if (checkYear.arguments.length == 1) emptyOK = defaultEmptyOK;
    if ((emptyOK == true) && (isEmpty(theField.value))) return true;
    if (!isYear(theField.value, false)) 
       return warnInvalid (theField, iYear);
    else return true;
}

function checkMonth (theField, emptyOK)
{   if (checkMonth.arguments.length == 1) emptyOK = defaultEmptyOK;
    if ((emptyOK == true) && (isEmpty(theField.value))) return true;
    if (!isMonth(theField.value, false)) 
       return warnInvalid (theField, iMonth);
    else return true;
}

function checkDay (theField, emptyOK)
{   if (checkDay.arguments.length == 1) emptyOK = defaultEmptyOK;
    if ((emptyOK == true) && (isEmpty(theField.value))) return true;
    if (!isDay(theField.value, false)) 
       return warnInvalid (theField, iDay);
    else return true;
}


//0000000000000000000000000000000000000000000000000000000000000000000000000000000000

var dtCh= "/";
var minYear=1900;
var maxYear=2100;

function DaysArray(n) {
	for (var i = 1; i <= n; i++) {
		this[i] = 31
		if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
		if (i==2) {this[i] = 29}
   } 
   return this
}

function checkValidDate(dtStr, fld){
	var daysInMonth = DaysArray(12)
	var pos1=dtStr.indexOf(dtCh)
	var pos2=dtStr.indexOf(dtCh,pos1+1)
	var strMonth=dtStr.substring(0,pos1)
	var strDay=dtStr.substring(pos1+1,pos2)
	var strYear=dtStr.substring(pos2+1)
	strYr=strYear
	if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
	if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
	for (var i = 1; i <= 3; i++) {
		if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1);
	}
	month=parseInt(strMonth)
	day=parseInt(strDay)
	year=parseInt(strYr)
	if (pos1==-1 || pos2==-1){
		alert("The date format should be : mm/dd/yyyy");
		document.getElementById(fld).value = '';
		return false
	}
	if (strMonth.length<1 || month<1 || month>12){
		alert("Please enter a valid month");
		document.getElementById(fld).value = '';
		return false
	}
	if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
		alert("Please enter a valid day");
		document.getElementById(fld).value = '';
		return false
	}
	if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
		alert("Please enter a valid 4 digit year between "+minYear+" and "+maxYear);
		document.getElementById(fld).value = '';
		return false
	}
	if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
		alert("Please enter a valid date");
		document.getElementById(fld).value = '';
		return false
	}
return true
}

//0000000000000000000000000000000000000000000000000000000000000000000000000000000000


function checkDate (yearField, monthField, dayField, labelString, OKtoOmitDay)
{   
    if (checkDate.arguments.length == 4) OKtoOmitDay = false;
    if (!isYear(yearField.value)) return warnInvalid (yearField, iYear);
    if (!isMonth(monthField.value)) return warnInvalid (monthField, iMonth);
    if ( (OKtoOmitDay == true) && isEmpty(dayField.value) ) return true;
    else if (!isDay(dayField.value)) 
       return warnInvalid (dayField, iDay);
    if (isDate (yearField.value, monthField.value, dayField.value))
       return true;
    alert (iDatePrefix + labelString + iDateSuffix)
    return false
}

function getRadioButtonValue (radio)
{   for (var i = 0; i < radio.length; i++)
    {   if (radio[i].checked) { break }
    }
    return radio[i].value
}

function checkCreditCard (radio, theField){   
    var cardType = document.all[radio].options[document.all[radio].selectedIndex].value;   //getRadioButtonValue (radio)
    var normalizedCCN = stripCharsInBag(theField.value, creditCardDelimiters)
       
    if (!isCardMatch(cardType, normalizedCCN)) 
        if (theField.value != '') {
            if (cardType == '1'){cardType = 'unspecified';};   
            if (cardType == '2'){cardType = 'Visa';}; 
            if (cardType == '3'){cardType = 'MasterCard';};
            if (cardType == '4'){cardType = 'American Express';};
            if (cardType == '5'){cardType = 'Discover';};   
            return warnInvalid (theField, iCreditCardPrefix + cardType + iCreditCardSuffix);
        }
    else 
    {  theField.value = normalizedCCN
       return true
    }
}

function isCreditCard(st) {
  if (st.length > 19)
    return (false);

  sum = 0; mul = 1; l = st.length;
  for (i = 0; i < l; i++) {
    digit = st.substring(l-i-1,l-i);
    tproduct = parseInt(digit ,10)*mul;
    if (tproduct >= 10)
      sum += (tproduct % 10) + 1;
    else
      sum += tproduct;
    if (mul == 1)
      mul++;
    else
      mul--;
  }
  if ((sum % 10) == 0)
    return (true);
  else
    return (false);

} 

function isVisa(cc)
{
  if (((cc.length == 16) || (cc.length == 13)) &&
      (cc.substring(0,1) == 4))
    return isCreditCard(cc);
  return false;
} 

function isMasterCard(cc)
{
  firstdig = cc.substring(0,1);
  seconddig = cc.substring(1,2);
  if ((cc.length == 16) && (firstdig == 5) &&
      ((seconddig >= 1) && (seconddig <= 5)))
    return isCreditCard(cc);
  return false;

} 

function isAmericanExpress(cc)
{
  firstdig = cc.substring(0,1);
  seconddig = cc.substring(1,2);
  if ((cc.length == 15) && (firstdig == 3) &&
      ((seconddig == 4) || (seconddig == 7)))
    return isCreditCard(cc);
  return false;

} 

function isDinersClub(cc)
{
  firstdig = cc.substring(0,1);
  seconddig = cc.substring(1,2);
  if ((cc.length == 14) && (firstdig == 3) &&
      ((seconddig == 0) || (seconddig == 6) || (seconddig == 8)))
    return isCreditCard(cc);
  return false;
}

function isCarteBlanche(cc)
{
  return isDinersClub(cc);
}

function isDiscover(cc)
{
  first4digs = cc.substring(0,4);
  if ((cc.length == 16) && (first4digs == "6011"))
    return isCreditCard(cc);
  return false;

} 

function isEnRoute(cc)
{
  first4digs = cc.substring(0,4);
  if ((cc.length == 15) &&
      ((first4digs == "2014") ||
       (first4digs == "2149")))
    return isCreditCard(cc);
  return false;
}

function isJCB(cc)
{
  first4digs = cc.substring(0,4);
  if ((cc.length == 16) &&
      ((first4digs == "3088") ||
       (first4digs == "3096") ||
       (first4digs == "3112") ||
       (first4digs == "3158") ||
       (first4digs == "3337") ||
       (first4digs == "3528")))
    return isCreditCard(cc);
  return false;

} 

function isAnyCard(cc)
{
  if (!isCreditCard(cc))
    return false;
  if (!isMasterCard(cc) && !isVisa(cc) && !isAmericanExpress(cc) && !isDinersClub(cc) &&
      !isDiscover(cc) && !isEnRoute(cc) && !isJCB(cc)) {
    return false;
  }
  return true;

} 

//function isCardMatch (cardType, cardNumber)
//{

//	cardType = cardType.toUpperCase();
//	var doesMatch = true;

//	if ((cardType == "VISA") && (!isVisa(cardNumber)))
//		doesMatch = false;
//	if ((cardType == "MASTERCARD") && (!isMasterCard(cardNumber)))
//		doesMatch = false;
//	if ( ( (cardType == "AMERICANEXPRESS") || (cardType == "AMEX") )
//                && (!isAmericanExpress(cardNumber))) doesMatch = false;
//	if ((cardType == "DISCOVER") && (!isDiscover(cardNumber)))
//		doesMatch = false;
//	if ((cardType == "JCB") && (!isJCB(cardNumber)))
//		doesMatch = false;
//	if ((cardType == "DINERS") && (!isDinersClub(cardNumber)))
//		doesMatch = false;
//	if ((cardType == "CARTEBLANCHE") && (!isCarteBlanche(cardNumber)))
//		doesMatch = false;
//	if ((cardType == "ENROUTE") && (!isEnRoute(cardNumber)))
//		doesMatch = false;
//	return doesMatch;

//}  

function isCardMatch (cardType, cardNumber)
{

	cardType = cardType.toUpperCase();
	var doesMatch = true;
    
	if ((cardType == "2") && (!isVisa(cardNumber)))
		doesMatch = false;
	if ((cardType == "3") && (!isMasterCard(cardNumber)))
		doesMatch = false;
	if ( ( (cardType == "4") || (cardType == "AMEX") )
                && (!isAmericanExpress(cardNumber))) doesMatch = false;
	if ((cardType == "5") && (!isDiscover(cardNumber)))
		doesMatch = false;
	return doesMatch;

}  

function dateIsBefore(date1, date2){
	var d1 = new Date(date1);
	var d2 = new Date(date2);
	return (d1<d2);
}

function checkEventDate(date1,date2){
	if (dateIsBefore(date1,date2)){
		alert("True");
	}else{
		alert("False");
	}
}

function IsCC (st) {
    return isCreditCard(st);
}

function IsVisa (cc)  {
  return isVisa(cc);
}

function IsVISA (cc)  {
  return isVisa(cc);
}

function IsMasterCard (cc)  {
  return isMasterCard(cc);
}

function IsMastercard (cc)  {
  return isMasterCard(cc);
}

function IsMC (cc)  {
  return isMasterCard(cc);
}

function IsAmericanExpress (cc)  {
  return isAmericanExpress(cc);
}

function IsAmEx (cc)  {
  return isAmericanExpress(cc);
}

function IsDinersClub (cc)  {
  return isDinersClub(cc);
}

function IsDC (cc)  {
  return isDinersClub(cc);
}

function IsDiners (cc)  {
  return isDinersClub(cc);
}

function IsCarteBlanche (cc)  {
  return isCarteBlanche(cc);
}

function IsCB (cc)  {
  return isCarteBlanche(cc);
}

function IsDiscover (cc)  {
  return isDiscover(cc);
}

function IsEnRoute (cc)  {
  return isEnRoute(cc);
}

function IsenRoute (cc)  {
  return isEnRoute(cc);
}

function IsJCB (cc)  {
  return isJCB(cc);
}

function IsAnyCard(cc)  {
  return isAnyCard(cc);
}

function IsCardMatch (cardType, cardNumber)  {
  return isCardMatch (cardType, cardNumber);
}

// @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

function rollover(td){
	td.className = "mbon";
	td.style.cursor = "hand";
}

function rollout(td){
	td.className = "mboff";
	td.style.cursor = "default";
}

function rollover_link(td, rep){
	if(rep == 1){
		td.className = "frmbtnlinkrepon";
	}else{
		td.className = "frmbtnlinkon";
	}
	td.style.cursor = "hand";
}

function rollout_link(td, rep){
	if(rep == 1){
		td.className = "frmbtnlink";
	}else{
		td.className = "frmbtnlinkrep";
	}
	td.style.cursor = "default";
}

//currently not used
function sortlinkresults(ca, otid, col, aoid, revsort){
	window.open('woform.aspx?ca=' + ca + '&cmd=sort&otid=' + otid + '&col=' + col + '&aoid=' + aoid + '&revsort=' + revsort,'workframe');
}

function searchsortresults(ca, otid, col, aoid, revsort, rpp, pagenum, cmd){
	//var norev = document.all['norev'].value;
	//window.open('wodataset.aspx?ca=' + ca + '&norev=' + norev + '&rpp=' + rpp + '&pagenum=' + pagenum + '&cmd=sort&otid=' + otid + '&col=' + col + '&aoid=' + aoid + '&revsort=' + revsort,'workframe');
	window.open('wodataset.aspx?ca=' + ca + '&rpp=' + rpp + '&pagenum=' + pagenum + '&cmd=sort&otid=' + otid + '&col=' + col + '&aoid=' + aoid + '&revsort=' + revsort + '&cmd2=' + cmd,'workframe');
}

function formsortresults(ca, otid, col, aoid, revsort){
	window.open('woform.aspx?cmd2=linkonly&ca=' + ca + '&cmd=sort&otid=' + otid + '&col=' + col + '&aoid=' + aoid + '&revsort=' + revsort,'procframe');
}

function viewhelpwin(ca, otid, fld, aoid){
	//loadhelpwin('helptip.aspx?ca=' + ca + '&aoid=' + aoid + '&otid=' + otid + '&fld=' + fld);
	window.open('helptip.aspx?ca=' + ca + '&aoid=' + aoid + '&otid=' + otid + '&fld=' + fld, 'helpwin','height=300,width=400,top=' + event.clientY + 'left=' + event.clientX);
}

function getMouseXY(e) {
if (IE) { 
	tempX = event.clientX + document.body.scrollLeft
	tempY = event.clientY + document.body.scrollTop
} else {  
	tempX = e.pageX
	tempY = e.pageY
}  
if (tempX < 0){tempX = 0}
if (tempY < 0){tempY = 0}  
document.Show.MouseX.value = tempX
document.Show.MouseY.value = tempY
return true
}

var icurrentrec = 0;
var irectrans = 0;

function changerow(layerorder, transitem){
	if(icurrentrec == 0){
		if(transitem == 1){
			document.all['rec' + layerorder].className = 'trans_on';
			//document.all['rec' + layerorder].fontSize = '9pt';
			//document.all['rec' + layerorder].fontFamily = 'verdana';
			//document.all['rec' + layerorder].color = 'green';
			//document.all['rec' + layerorder].fontWeight = 'bold';
			//document.all['rec' + layerorder].backgroundColor = 'white';
		}else{
			document.all['rec' + layerorder].className = 'row_on';
		}
	}else{
		if(irectrans == 1){
			document.all['rec' + icurrentrec].className = 'trans_off';
		}else{
			document.all['rec' + icurrentrec].className = 'row_off';
		}
		if(transitem == 1){
			document.all['rec' + layerorder].className = 'trans_on';
		}else{
			document.all['rec' + layerorder].className = 'row_on';
		}
	}

	icurrentrec = layerorder;
	irectrans = transitem;
}

function resetrows(){
	if(icurrentrec != 0){
		if(irectrans == 1){
			document.all['rec' + icurrentrec].className = 'trans_off';
		}else{
			document.all['rec' + icurrentrec].className = 'row_off';
		}
		icurrentrec = 0;
	}
}

function loadwp(wp){
	window.open('http://www.casewide.com/wp.aspx?wp=' + wp, '_parent');
}

//currently not used
function closewin(){
	if(checksave(cmd)){
		document.all['pgfrm'].style.visibility = 'hidden';
		document.frmNew.action = "woform.aspx?cmd=" + cmd;
		document.frmNew.submit();
	}
}	

function lblHL(lbl, fld){
	document.all[lbl].className = 'labelfocus';
	document.all[fld].className = 'fieldfocus';
}
function lblUHL(lbl, fld){
	document.all[lbl].className = 'formlabels';
	document.all[fld].className = 'formfields';
}
function btnHL(btn){
	document.all[btn].className = 'logon';
}
function btnUHL(btn){
	document.all[btn].className = 'logoff';
}
function header_rollover(td){
	document.all[td].className = 'mainmenuover';
}

function header_rollout(td){
	document.all[td].className = 'mainmenu';
}

function modelesswin(url,properties){
	if (document.all&&window.print) //if ie5
		eval('window.showModelessDialog(url,"","help:0;resizable:1;dialogWidth:'+mwidth+'px;dialogHeight:'+mheight+'px")')
	else
		eval('window.open(url,"","width='+mwidth+'px,height='+mheight+'px,resizable=1,scrollbars=1")')
}

function targetopener(mylink, closeme, closeonly){
	if (! (window.focus && window.opener)){return true;window.opener.focus();}
	if (! closeonly){window.opener.location.href=mylink.href;}
	if (closeme){window.close();return false;}
}

function postwarn(){
	if(document.all['post'].checked){
		if(!confirm('Clicking "Post to Account" will lock this record and any\ncorresponding records/items that meet the specified criteria.\n\n                                Are you sure?')){
			document.all['post'].checked = false;
		}
	}
}

function postemailblast(){
	if(document.all['post'].checked){
		if(!confirm('Clicking "Send This Email" will lock this record and process all emails to be sent.\n\n                                Are you sure?')){
			document.all['post'].checked = false;
		}
	}
}

function submitformobjcheck(ca, cmd){
	if (confirm('The object or object property you are about to delete currently has data.\n\n                  This action cannot be undone. Are you sure!')){
		document.frmNew.action = "woform.aspx?ca=" + ca + "&cmd=" + cmd;
		document.frmNew.submit();
	}
}

function submitformobjchecklink(ca, cmd){
	if (confirm('The object or object property you are about to delete currently has data.\n\n                  This action cannot be undone. Are you sure!')){
		document.frmNew.action = "woform.aspx?cmd2=linkonly&ca=" + ca + "&cmd=" + cmd;
		document.frmNew.submit();
	}
}
	




function fwddataobj(ca, otid, cmd, oid, potid){
	document.frmNew.action = "woform.aspx?ca=" + ca + "&cmd=" + cmd + "&otid=" + otid + "&oid=" + oid + "&potid=" + potid;
	document.frmNew.submit();
}		

function getTemplates(ca, aoid, tbl, fld){
	loadsubwin('wodataset.aspx?ca=' + ca + '&cmd=template&aoid=' + aoid + '&tbl=' + tbl + '&fld=' + fld);
}

function resetfield(fldname){
	document.all[fldname].value = ''
}


function 	advSearch(frm){
	document.all['srchtype'].value = 2;
	if(document.all['txtCriteria1'].value != '' && document.all['ddlCategory'].value != ''){
		document.all['frmSearch'].submit();
	}else{
		alert('Please make a selection and enter your search criteria.');
		//document.all['srchfrm'].style.visible = 'visible';
	}
}

function loadhelpwin(loc){
	window.history.forward();
	document.all['subwinhelp'].style.width = 400;
	document.all['subwinhelp'].style.height = 300;
	document.all['subwinhelp'].style.visibility = 'visible';
	document.all['subwinhelp'].style.pixelTop = event.clientY + document.body.scrollTop;
	document.all['subwinhelp'].style.pixelLeft = event.clientX + document.body.scrollLeft;
	
	//document.frames['subframehelp'].location = loc;
}

function updateCheckbox(ca, otid, oid, chk, dispname, aoid){
	var chkval;
    if(chk){chkval=1}else{chkval=0};
	window.open('woform.aspx?ca=' + ca + '&aoid=' + aoid + '&otid=' + otid + '&oid=' + oid + '&chk=' + chkval + '&dispname=' + dispname + '&cmd=updatechkbx', 'procframe');
}

function updateNumericField(ca, theField, otid, oid, val, dispname, aoid){
	if(checkNumeric(theField,1)){
	    if(theField.value != ""){
		   window.open('woform.aspx?ca=' + ca + '&aoid=' + aoid + '&otid=' + otid + '&oid=' + oid + '&val=' + theField.value + '&dispname=' + dispname + '&cmd=updsrchfld&isnum=1', 'procframe');
		}
	}
}

function updateDecimalField(ca, theField, otid, oid, val, dispname, aoid){
	formatCurrency(thefield,1);
	window.open('woform.aspx?ca=' + ca + '&aoid=' + aoid + '&otid=' + otid + '&oid=' + oid + '&val=' + theField.value + '&dispname=' + dispname + '&cmd=updsrchfld&isnum=1', 'procframe');
}

function updateDecimalField2(ca, theField, otid, oid, val, dispname, aoid){
	formatCurrency(thefield,1);
	window.open('woform.aspx?ca=' + ca + '&aoid=' + aoid + '&otid=' + otid + '&oid=' + oid + '&val=' + theField + '&dispname=' + dispname + '&cmd=updsrchfld&isnum=1', 'procframe');
}

function getQuickSrch(ca, aoid, otid){
	window.open('wodataset.aspx?ca=' + ca + '&cmd=new&aoid=' + aoid + '&ddlcategory=o_' + otid + '&txtcriteria=all', 'workframe');
}

function closesubwin(ca){
	window.open('woform.aspx?cmd2=linkonly&ca=' + ca + '&cmd=view&fwoid=' + document.all['fwoid'].value + '&xvt=' + document.all['xvt'].value + '&xpotid=' + document.all['xpotid'].value + '&xpoid=' + document.all['xpoid'].value + '&aoid=' + document.all['aoid'].value,'workframe');
	window.close();
}

function closewiz(ca, aoid, title){
	if(confirm("Closing this wizard will load the regular Form Category View.  You may return \nto this " + title + " by clicking on Search from the main menu above. \n\n                                         Are you sure?")){
		window.open('woform.aspx?ca=' + ca + '&cmd=view&aoid=' + aoid,'workframe');
	}
}

//currently not used
function closetsksubwin(ca){
	window.open('woform.aspx?ca=' + ca + '&cmd=timeline&aoid=' + document.all['aoid'].value,'workframe');
}

//currently not used
function gototimeline(ca, otid, oid){
	window.open('woform.aspx?ca=' + ca + '&cmd=timeline&aoid=' + document.all['aoid'].value + '&otid=' + otid + '&oid=' + oid,'workframe');
}

function ppdcalc(){
	if(document.all['quantity'].value != '' && isInteger(document.all['quantity'].value) && document.all['acqunitcost'].value != '' && isFloat(document.all['acqunitcost'].value)){
		var ttl = parseFloat(document.all['quantity'].value) * parseFloat(document.all['acqunitcost'].value);
		document.all['acqtotcost'].value = ttl;
		formatCurrency(document.all['acqtotcost'],0);
		formatCurrency(document.all['acqunitcost'],0);
	}else{
		document.all['acqtotcost'].value = '';
		document.all['acqunitcost'].value = '';
	}
}

function checkFieldCalc(fld1, fld2, totfld){
	if(document.all[fld1].value != '' && isInteger(document.all[fld1].value) && document.all[fld2].value != '' && isFloat(document.all[fld2].value)){
		var ttl = parseFloat(document.all[fld1].value) * parseFloat(document.all[fld2].value);
		document.all[totfld].value = ttl;
		formatCurrency(document.all[fld2],0);
		formatCurrency(document.all[totfld],0);
	}
}

function fieldCalcDiv(fld1, fld2, totfld){
	var nostr = /[$,]/ig;
	if ((document.all[fld1].value != '$0.00') && (document.all[fld1].value != '') && document.all[fld2].value != '' && isInteger(document.all[fld2].value)){
		var fld1val = document.all[fld1].value;
		fld1val = fld1val.replace("$","");
		fld1val = fld1val.replace(",","");
		var ttl = fld1val / document.all[fld2].value;
		
		//alert(fld1val + '/' + document.all[fld2].value + ' = ' + ttl);
		document.all[totfld].value = ttl;
		formatCurrency(document.all[totfld],1);
	}
}

//qty multiqty multiremain      
function fieldCalcMinus(fld1, fld2, totfld){
	if ((document.all[fld1].value != '') && isInteger(document.all[fld1].value) && (document.all[fld2].value != '') && isInteger(document.all[fld2].value)){
		if (document.all[fld2].value > document.all[fld1].value){
			alert('The "Multi-Release Qty." you entered cannot be more than the "Qty".');
		}else{
			document.all[totfld].value = parseFloat(document.all[fld1].value) - parseFloat(document.all[fld2].value);
		}
	}
}

function openfile(filename){
	var buffer = (iswhat.ns406 || iswhat.ns407 || iswhat.ns408) ? 30 : 48;
	var window_width = screen.width-12;
	var window_height = screen.height-buffer;
	var x = (window_width / 2) - 350;
	var y = (window_height / 2) - 200;
	window.open(filename,'filewin','left=' + x + ',top=' + y + ', width=700,height=400,toolbar=no,resizable=yes,location=no,scrollbars=yes,menubar=yes,status=no,title=filewin');
}

function iswhat(){
	var agent = navigator.userAgent.toLowerCase();
	this.major = parseInt(navigator.appVersion);
	this.minor = parseFloat(navigator.appVersion);
	this.ns  = ((agent.indexOf('mozilla')!=-1) && ((agent.indexOf('spoofer')==-1) && (agent.indexOf('compatible') == -1)));
	this.ns2 = (this.ns && (this.major == 3));
	this.ns3 = (this.ns && (this.major == 3));
	this.ns4 = (this.ns && (this.major >= 4));
	this.ns406 = (this.ns && (this.minor == 4.06));
	this.ns407 = (this.ns && (this.minor == 4.07));
	this.ns408 = (this.ns && (this.minor == 4.08));
	this.ns45 = (this.ns && (this.minor == 4.5));
	this.ie   = (agent.indexOf('msie') != -1);
	this.ie3  = (this.ie && (this.major == 2));
	this.ie4  = (this.ie && (this.major >= 4));
	this.op3 = (agent.indexOf('opera') != -1);
}

function SetSecurity(level){
	if(level == 6 && document.all['fullcontrol'].checked == true){
		document.all['modify'].checked = true;
		document.all['search'].checked = true;
		document.all['_read'].checked = true;
		document.all['_write'].checked = true;
		document.all['readexecute'].checked = true;
		document.all['del'].checked = true;
	}
	if(level == 5 && document.all['modify'].checked == true){
		document.all['search'].checked = true;
		document.all['_read'].checked = true;
	}
	if(level == 4 && document.all['readexecute'].checked == true){
		document.all['search'].checked = true;
		document.all['_read'].checked = true;
	}
}

function updateSched(dt){
	if(document.all['installcal'].value == 'woyes'){
		window.open('woform.aspx?cmd=schedcal&aoid=' + document.all['aoid'].value + '&oid=' + document.all['installoid'].value + '&dt=' + dt,'workframe');
	}
}

function resetSched(oid){
    if(document.all['ss' + oid].checked){
		if(document.all['installoid'].value != '' && document.all['installoid'].value != oid){
			document.all['ss' + document.all['installoid'].value].checked = false;
		}
		document.all['installoid'].value = oid;
    }else if(!document.all['ss' + oid].checked){
		document.all['installoid'].value = ''
    }
}

function rep_rollover(td){
	td.style.backgroundColor = "#A0AEC0";
	td.style.cursor = "hand";
}

function rep_rollout(td){
	td.style.backgroundColor = "ffffcc";
	td.style.cursor = "default";
}

//currently not used
function NewScheduleSwitch(ca, dotid, fullname, oid, dt, aoid){
    fullname = fullname.split("'").join("\'\'");
	if(document.all['installoid'].value != '') {
	alert('woform.aspx?ca=' + ca + '&cmd=newlinkschedday&aoid=' + aoid + '&ddlCategory=o_' + dotid + '&inst=' + fullname + '&instoid=' + oid + '&dt=' + dt);
		window.open('woform.aspx?ca=' + ca + '&cmd=schedcal&aoid=' + aoid + '&inst=' + fullname + '&instoid=' + oid + '&dt=' + dt + '&doid=' + document.all['installoid'].value,'workframe');
	}else{
	alert('woform.aspx?ca=' + ca + '&cmd=newlinkschedday&aoid=' + aoid + '&ddlCategory=o_' + dotid + '&inst=' + fullname + '&instoid=' + oid + '&dt=' + dt);
		window.open('woform.aspx?ca=' + ca + '&cmd=newlinkschedday&aoid=' + aoid + '&ddlCategory=o_' + dotid + '&inst=' + fullname + '&instoid=' + oid + '&dt=' + dt,'workframe');
	}
}

function SetTaskType(){
	if (document.frmNew.tt_id.options[document.frmNew.tt_id.selectedIndex].value == 2){
		document.frmNew.subject.value = "Submittals Package - Sent By"
	}else if (document.frmNew.tt_id.options[document.frmNew.tt_id.selectedIndex].value == 3){
		document.frmNew.subject.value = "Submittals - Approved By"
	}else if (document.frmNew.tt_id.options[document.frmNew.tt_id.selectedIndex].value == 4){
		document.frmNew.subject.value = "Shop Drawings - Sent By"
	}else if (document.frmNew.tt_id.options[document.frmNew.tt_id.selectedIndex].value == 5){
		document.frmNew.subject.value = "Shop Drawings - Approved By"
	}else if (document.frmNew.tt_id.options[document.frmNew.tt_id.selectedIndex].value == 6){
		document.frmNew.subject.value = "Measure By"
	}else if (document.frmNew.tt_id.options[document.frmNew.tt_id.selectedIndex].value == 7){
		document.frmNew.subject.value = "Order Materials By"
	}else if (document.frmNew.tt_id.options[document.frmNew.tt_id.selectedIndex].value == 8){
		document.frmNew.subject.value = "Receive Materials By"
	}else if (document.frmNew.tt_id.options[document.frmNew.tt_id.selectedIndex].value == 9){
		document.frmNew.subject.value = "Begin Installation By"
	}
}

function SetAppointmentType(){
	if (document.frmNew.apptype_id.options[document.frmNew.apptype_id.selectedIndex].value == 2){
		document.frmNew.subject.value = "Shampoo & Style"
	}else if (document.frmNew.apptype_id.options[document.frmNew.apptype_id.selectedIndex].value == 3){
		document.frmNew.subject.value = "Full Relaxer"
	}else if (document.frmNew.apptype_id.options[document.frmNew.apptype_id.selectedIndex].value == 4){
		document.frmNew.subject.value = "Retouch Relaxer"
	}else if (document.frmNew.apptype_id.options[document.frmNew.apptype_id.selectedIndex].value == 5){
		document.frmNew.subject.value = "Hair Coloring"
	}else if (document.frmNew.apptype_id.options[document.frmNew.apptype_id.selectedIndex].value == 6){
		document.frmNew.subject.value = "Straw / Spiral Set"
	}else if (document.frmNew.apptype_id.options[document.frmNew.apptype_id.selectedIndex].value == 7){
		document.frmNew.subject.value = "Weave"
	}else if (document.frmNew.apptype_id.options[document.frmNew.apptype_id.selectedIndex].value == 8){
		document.frmNew.subject.value = "Natural Style"
	}
}

var fixedX = -1;var fixedY = -1;var startAt = 1;var showWeekNumber = 1;	var showToday = 1;var imgDir = "images/cal/";
var gotoString = "Go To Current Month";var todayString = "Today is";var weekString = "Wk";var scrollLeftMessage = "Click to scroll to previous month. Hold mouse button to scroll automatically.";var scrollRightMessage = "Click to scroll to next month. Hold mouse button to scroll automatically.";var selectMonthMessage = "Click to select a month.";var selectYearMessage = "Click to select a year.";var selectDateMessage = "Select [date] as date.";
var crossobj, crossMonthObj, crossYearObj, monthSelected, yearSelected, dateSelected, omonthSelected, oyearSelected, odateSelected, monthConstructed, yearConstructed, intervalID1, intervalID2, timeoutID1, timeoutID2, ctlToPlaceValue, ctlNow, dateFormat, nStartingYear; var bPageLoaded=false; var ie=document.all; var dom=document.getElementById; var ns4=document.layers; var today = new	Date(); var dateNow	 = today.getDate(); var monthNow = today.getMonth(); var yearNow	 = today.getYear(); var imgsrc = new Array("drop1.gif","drop2.gif","left1.gif","left2.gif","right1.gif","right2.gif"); var img	= new Array(); var bShow = false;
function hideElement( elmID, overDiv ){if( ie ){for( i = 0; i < document.all.tags( elmID ).length; i++ ){obj = document.all.tags( elmID )[i];if( !obj || !obj.offsetParent ){continue;}; objLeft   = obj.offsetLeft; objTop    = obj.offsetTop; objParent = obj.offsetParent; while( objParent.tagName.toUpperCase() != "BODY" ){objLeft  += objParent.offsetLeft;objTop   += objParent.offsetTop;objParent = objParent.offsetParent;};objHeight = obj.offsetHeight;objWidth = obj.offsetWidth;if(( overDiv.offsetLeft + overDiv.offsetWidth ) <= objLeft );else if(( overDiv.offsetTop + overDiv.offsetHeight ) <= objTop ); else if( overDiv.offsetTop >= ( objTop + objHeight )); else if( overDiv.offsetLeft >= ( objLeft + objWidth ));else{obj.style.visibility = "hidden";};};};};
function showElement( elmID ){if( ie ){for( i = 0; i < document.all.tags( elmID ).length; i++ ){obj = document.all.tags( elmID )[i];if( !obj || !obj.offsetParent ){continue;};obj.style.visibility = "";};};};
function HolidayRec (d, m, y, desc){this.d = d;this.m = m;this.y = y;	this.desc = desc;};
var HolidaysCounter = 0;var Holidays = new Array();
function addHoliday (d, m, y, desc){Holidays[HolidaysCounter++] = new HolidayRec ( d, m, y, desc );};if (dom){for	(i=0;i<imgsrc.length;i++){img[i] = new Image;	img[i].src = imgDir + imgsrc[i];};	document.write ("<div onclick='bShow=true' id='calendar'	style='z-index:+999;position:absolute;visibility:hidden;'><table	width="+((showWeekNumber==1)?250:220)+" style='font-family:arial;font-size:9pt;border-width:1;border-style:solid;border-color:#a0a0a0;font-family:arial; font-size:9pt}' bgcolor='#ffffff'><tr bgcolor='#0000aa'><td><table width='"+((showWeekNumber==1)?248:218)+"'><tr><td style='padding:2px;font-family:arial; font-size:9pt;'><font color='#ffffff'><B><span id='caption'></span></B></font></td><td align=right><a href='javascript:hideCalendar()'><IMG SRC='"+imgDir+"close.gif' WIDTH='15' HEIGHT='13' BORDER='0' ALT='Close the Calendar'></a></td></tr></table></td></tr><tr><td style='padding:5px' bgcolor=#ffffff><span id='content'></span></td></tr>");	if (showToday==1){document.write ("<tr bgcolor=#f0f0f0><td style='padding:5px' align=center><span id='lblToday'></span></td></tr>");};document.write ("</table></div><div id='selectMonth' style='z-index:+999;position:absolute;visibility:hidden;'></div><div id='selectYear' style='z-index:+999;position:absolute;visibility:hidden;'></div>");};var monthName =	new	Array("January","February","March","April","May","June","July","August","September","October","November","December");if (startAt==0){dayName = new Array	("Sun","Mon","Tue","Wed","Thu","Fri","Sat");}else{dayName = new Array	("Mon","Tue","Wed","Thu","Fri","Sat","Sun");};
var styleAnchor="text-decoration:none;color:black;";
var styleLightBorder="border-style:solid;border-width:1px;border-color:#a0a0a0;";
function swapImage(srcImg, destImg){if (ie)	{ document.getElementById(srcImg).setAttribute("src",imgDir + destImg) };};
function initcal()	{if (!ns4){if (!ie) { yearNow += 1900 } crossobj=(dom)?document.getElementById("calendar").style : ie? document.all.calendar : document.calendar; hideCalendar(); crossMonthObj=(dom)?document.getElementById("selectMonth").style : ie? document.all.selectMonth	: document.selectMonth; crossYearObj=(dom)?document.getElementById("selectYear").style : ie? document.all.selectYear : document.selectYear; monthConstructed=false; yearConstructed=false; if (showToday==1){document.getElementById("lblToday").innerHTML =	todayString + " <a onmousemove='window.status=\""+gotoString+"\"' onmouseout='window.status=\"\"' title='"+gotoString+"' style='"+styleAnchor+"' href='javascript:monthSelected=monthNow;yearSelected=yearNow;constructCalendar();'>"+dayName[(today.getDay()-startAt==-1)?6:(today.getDay()-startAt)]+", " + dateNow + " " + monthName[monthNow].substring(0,3)	+ "	" +	yearNow	+ "</a>";};	sHTML1="<span id='spanLeft'	style='border-style:solid;border-width:1;border-color:#3366FF;cursor:pointer' onmouseover='swapImage(\"changeLeft\",\"left2.gif\");this.style.borderColor=\"#88AAFF\";window.status=\""+scrollLeftMessage+"\"' onclick='javascript:decMonth()' onmouseout='clearInterval(intervalID1);swapImage(\"changeLeft\",\"left1.gif\");this.style.borderColor=\"#3366FF\";window.status=\"\"' onmousedown='clearTimeout(timeoutID1);timeoutID1=setTimeout(\"StartDecMonth()\",500)'	onmouseup='clearTimeout(timeoutID1);clearInterval(intervalID1)'>&nbsp<IMG id='changeLeft' SRC='"+imgDir+"left1.gif' width=10 height=11 BORDER=0>&nbsp</span>&nbsp;";	sHTML1+="<span id='spanRight' style='border-style:solid;border-width:1;border-color:#3366FF;cursor:pointer'	onmouseover='swapImage(\"changeRight\",\"right2.gif\");this.style.borderColor=\"#88AAFF\";window.status=\""+scrollRightMessage+"\"' onmouseout='clearInterval(intervalID1);swapImage(\"changeRight\",\"right1.gif\");this.style.borderColor=\"#3366FF\";window.status=\"\"' onclick='incMonth()' onmousedown='clearTimeout(timeoutID1);timeoutID1=setTimeout(\"StartIncMonth()\",500)'	onmouseup='clearTimeout(timeoutID1);clearInterval(intervalID1)'>&nbsp<IMG id='changeRight' SRC='"+imgDir+"right1.gif'	width=10 height=11 BORDER=0>&nbsp</span>&nbsp";sHTML1+="<span id='spanMonth' style='border-style:solid;border-width:1;border-color:#3366FF;cursor:pointer'	onmouseover='swapImage(\"changeMonth\",\"drop2.gif\");this.style.borderColor=\"#88AAFF\";window.status=\""+selectMonthMessage+"\"' onmouseout='swapImage(\"changeMonth\",\"drop1.gif\");this.style.borderColor=\"#3366FF\";window.status=\"\"' onclick='popUpMonth()'></span>&nbsp;";sHTML1+="<span id='spanYear' style='border-style:solid;border-width:1;border-color:#3366FF;cursor:pointer' onmouseover='swapImage(\"changeYear\",\"drop2.gif\");this.style.borderColor=\"#88AAFF\";window.status=\""+selectYearMessage+"\"'	onmouseout='swapImage(\"changeYear\",\"drop1.gif\");this.style.borderColor=\"#3366FF\";window.status=\"\"'	onclick='popUpYear()'></span>&nbsp;";document.getElementById("caption").innerHTML  =	sHTML1;	bPageLoaded=true;};};
function hideCalendar()	{try{crossobj.visibility="hidden";if (crossMonthObj != null){crossMonthObj.visibility="hidden"};	if (crossYearObj !=	null){crossYearObj.visibility="hidden"};	showElement( 'SELECT' );	showElement( 'APPLET' ); }catch(e){}; };
function padZero(num) { return (num < 10)? '0' + num : num ;};
function constructDate(d,m,y){ sTmp = dateFormat;sTmp = sTmp.replace	("dd","<e>");sTmp = sTmp.replace	("d","<d>");	sTmp = sTmp.replace	("<e>",padZero(d));sTmp = sTmp.replace	("<d>",d); sTmp = sTmp.replace	("mmm","<o>");sTmp = sTmp.replace	("mm","<n>");sTmp = sTmp.replace	("m","<m>");sTmp = sTmp.replace	("<m>",m+1);sTmp = sTmp.replace	("<n>",padZero(m+1));sTmp = sTmp.replace	("<o>",monthName[m]);	return sTmp.replace ("yyyy",y);};
function closeCalendar() {	var sTmp; hideCalendar();	ctlToPlaceValue.value =	constructDate(dateSelected,monthSelected,yearSelected); updateSched(ctlToPlaceValue.value);if(document.all['copyfld'].value != ''){document.all[document.all['copyfld'].value].value = ctlToPlaceValue.value;};};
function StartDecMonth(){intervalID1=setInterval("decMonth()",80);};
function StartIncMonth(){intervalID1=setInterval("incMonth()",80);};
function incMonth () { monthSelected++; if (monthSelected>11) { monthSelected=0; yearSelected++;	};	constructCalendar();};
function decMonth () {monthSelected--; if (monthSelected<0) {monthSelected=11;yearSelected--;};constructCalendar();};
function constructMonth() { popDownYear(); if (!monthConstructed) {sHTML = "";	for	(i=0; i<12;	i++) {sName =	monthName[i];	if (i==monthSelected){sName =	"<B>" +	sName +	"</B>";}; sHTML += "<tr><td id='m" + i + "' onmouseover='this.style.backgroundColor=\"#FFCC99\"' onmouseout='this.style.backgroundColor=\"\"' style='cursor:pointer' onclick='monthConstructed=false;monthSelected=" + i + ";constructCalendar();popDownMonth();event.cancelBubble=true'>&nbsp;" + sName + "&nbsp;</td></tr>";};	document.getElementById("selectMonth").innerHTML = "<table width=70	style='font-family:arial; font-size:9pt; border-width:1; border-style:solid; border-color:#a0a0a0;' bgcolor='#FFFFDD' cellspacing=0 onmouseover='clearTimeout(timeoutID1)'	onmouseout='clearTimeout(timeoutID1);timeoutID1=setTimeout(\"popDownMonth()\",100);event.cancelBubble=true'>" +	sHTML +	"</table>";	monthConstructed=true;};};
function popUpMonth() {constructMonth();crossMonthObj.visibility = (dom||ie)? "visible"	: "show";crossMonthObj.left = parseInt(crossobj.left) + 50;	crossMonthObj.top =	parseInt(crossobj.top) + 26;};
function popDownMonth()	{crossMonthObj.visibility= "hidden";};
function incYear() {for	(i=0; i<7; i++){newYear	= (i+nStartingYear)+1;if (newYear==yearSelected){ txtYear =	"&nbsp;<B>"	+ newYear +	"</B>&nbsp;" }else{ txtYear =	"&nbsp;" + newYear + "&nbsp;" };document.getElementById("y"+i).innerHTML = txtYear;};nStartingYear ++;bShow=true;};
function decYear() {	for	(i=0; i<7; i++){newYear = (i+nStartingYear)-1;if (newYear==yearSelected){ txtYear =	"&nbsp;<B>"	+ newYear +	"</B>&nbsp;"; }else{ txtYear =	"&nbsp;" + newYear + "&nbsp;" };document.getElementById("y"+i).innerHTML = txtYear;};	nStartingYear --;	bShow=true;};
function selectYear(nYear) {yearSelected=parseInt(nYear+nStartingYear); yearConstructed=false; constructCalendar();	popDownYear();};
function constructYear() {	popDownMonth(); sHTML = ""; if (!yearConstructed) {sHTML =	"<tr><td align='center'	onmouseover='this.style.backgroundColor=\"#FFCC99\"' onmouseout='clearInterval(intervalID1);this.style.backgroundColor=\"\"' style='cursor:pointer'	onmousedown='clearInterval(intervalID1);intervalID1=setInterval(\"decYear()\",30)' onmouseup='clearInterval(intervalID1)'>-</td></tr>"; j =	0;	nStartingYear = yearSelected-3; for (i=(yearSelected-3); i<=(yearSelected+3); i++) { sName =	i; if (i==yearSelected){ sName =	"<B>" +	sName +	"</B>"; }; sHTML += "<tr><td id='y" + j + "' onmouseover='this.style.backgroundColor=\"#FFCC99\"' onmouseout='this.style.backgroundColor=\"\"' style='cursor:pointer' onclick='selectYear("+j+");event.cancelBubble=true'>&nbsp;" + sName + "&nbsp;</td></tr>"; j ++;}; sHTML += "<tr><td align='center' onmouseover='this.style.backgroundColor=\"#FFCC99\"' onmouseout='clearInterval(intervalID2);this.style.backgroundColor=\"\"' style='cursor:pointer' onmousedown='clearInterval(intervalID2);intervalID2=setInterval(\"incYear()\",30)'	onmouseup='clearInterval(intervalID2)'>+</td></tr>";	document.getElementById("selectYear").innerHTML	= "<table width=44 style='font-family:arial; font-size:9pt; border-width:1; border-style:solid; border-color:#a0a0a0;'	bgcolor='#FFFFDD' onmouseover='clearTimeout(timeoutID2)' onmouseout='clearTimeout(timeoutID2);timeoutID2=setTimeout(\"popDownYear()\",100)' cellspacing=0>"	+ sHTML	+ "</table>";yearConstructed	= true;}};
function popDownYear() {	clearInterval(intervalID1);	clearTimeout(timeoutID1);	clearInterval(intervalID2);	clearTimeout(timeoutID2);	crossYearObj.visibility= "hidden";};
function popUpYear() {var leftOffset;constructYear();crossYearObj.visibility	= (dom||ie)? "visible" : "show";leftOffset = parseInt(crossobj.left) + document.getElementById("spanYear").offsetLeft;if (ie)	{leftOffset += 6;};crossYearObj.left =	leftOffset;crossYearObj.top = parseInt(crossobj.top) +	26;};
function WeekNbr(n) {year = n.getFullYear();month = n.getMonth() + 1; if (startAt == 0) {day = n.getDate() + 1;} else {day = n.getDate();}; a = Math.floor((14-month) / 12); y = year + 4800 - a; m = month + 12 * a - 3; b = Math.floor(y/4) - Math.floor(y/100) + Math.floor(y/400); J = day + Math.floor((153 * m + 2) / 5) + 365 * y + b - 32045; d4 = (((J + 31741 - (J % 7)) % 146097) % 36524) % 1461; L = Math.floor(d4 / 1460); d1 = ((d4 - L) % 365) + L; week = Math.floor(d1/7) + 1; return week;};
function constructCalendar () {var aNumDays = Array (31,0,31,30,31,30,31,31,30,31,30,31);var dateMessage; var startDate =	new Date (yearSelected,monthSelected,1); var endDate;if (monthSelected==1){endDate	= new Date (yearSelected,monthSelected+1,1);endDate	= new Date (endDate	- (24*60*60*1000));numDaysInMonth = endDate.getDate();}else{numDaysInMonth = aNumDays[monthSelected];};datePointer	= 0;dayPointer = startDate.getDay() - startAt;if (dayPointer<0){dayPointer = 6;};sHTML =	"<table	 border=0 style='font-family:verdana;font-size:10px;'><tr>";if (showWeekNumber==1){sHTML += "<td width=27><b>" + weekString + "</b></td><td width=1 rowspan=7 bgcolor='#d0d0d0' style='padding:0px'><img src='"+imgDir+"divider.gif' width=1></td>";};for	(i=0; i<7; i++)	{sHTML += "<td width='27' align='right'><B>"+ dayName[i]+"</B></td>";};sHTML +="</tr><tr>";if (showWeekNumber==1){ sHTML += "<td align=right>" + WeekNbr(startDate) + "&nbsp;</td>"; };	for	( var i=1; i<=dayPointer;i++ )	{ sHTML += "<td>&nbsp;</td>"; };	for	( datePointer=1; datePointer<=numDaysInMonth; datePointer++ )	{ dayPointer++;	sHTML += "<td align=right>";	sStyle=styleAnchor;	if ((datePointer==odateSelected) &&	(monthSelected==omonthSelected)	&& (yearSelected==oyearSelected)){ sStyle+=styleLightBorder };	sHint = "";for (k=0;k<HolidaysCounter;k++){if ((parseInt(Holidays[k].d)==datePointer)&&(parseInt(Holidays[k].m)==(monthSelected+1))){if ((parseInt(Holidays[k].y)==0)||((parseInt(Holidays[k].y)==yearSelected)&&(parseInt(Holidays[k].y)!=0)))	{sStyle+="background-color:#FFDDDD;";sHint+=sHint==""?Holidays[k].desc:"\n"+Holidays[k].desc;};};}; var regexp= /\"/g; sHint=sHint.replace(regexp,"&quot;"); dateMessage = "onmousemove='window.status=\""+selectDateMessage.replace("[date]",constructDate(datePointer,monthSelected,yearSelected))+"\"' onmouseout='window.status=\"\"' "; if ((datePointer==dateNow)&&(monthSelected==monthNow)&&(yearSelected==yearNow))	{ sHTML += "<b><a "+dateMessage+" title=\"" + sHint + "\" style='"+sStyle+"' href='javascript:dateSelected="+datePointer+";closeCalendar();'><font color=#ff0000>&nbsp;" + datePointer + "</font>&nbsp;</a></b>"} else if (dayPointer % 7 == (startAt * -1)+1){ sHTML += "<a "+dateMessage+" title=\"" + sHint + "\" style='"+sStyle+"' href='javascript:dateSelected="+datePointer + ";closeCalendar();'>&nbsp;<font color=#909090>" + datePointer + "</font>&nbsp;</a>" } else { sHTML += "<a "+dateMessage+" title=\"" + sHint + "\" style='"+sStyle+"' href='javascript:dateSelected="+datePointer + ";closeCalendar();'>&nbsp;" + datePointer + "&nbsp;</a>" };sHTML += "";if ((dayPointer+startAt) % 7 == startAt) {sHTML += "</tr><tr>";if ((showWeekNumber==1)&&(datePointer<numDaysInMonth)){sHTML += "<td align=right>" + (WeekNbr(new Date(yearSelected,monthSelected,datePointer+1))) + "&nbsp;</td>";};};};document.getElementById("content").innerHTML   = sHTML;	document.getElementById("spanMonth").innerHTML = "&nbsp;" +	monthName[monthSelected] + "&nbsp;<IMG id='changeMonth' SRC='"+imgDir+"drop1.gif' WIDTH='12' HEIGHT='10' BORDER=0>"; document.getElementById("spanYear").innerHTML =	"&nbsp;" + yearSelected	+ "&nbsp;<IMG id='changeYear' SRC='"+imgDir+"drop1.gif' WIDTH='12' HEIGHT='10' BORDER=0>";};
function popUpCalendar(ctl, ctl2, format) {var	leftpos=0;var	toppos=0;if (bPageLoaded){if ( crossobj.visibility ==	"hidden" ) {ctlToPlaceValue	= ctl2;dateFormat=format;formatChar = " ";aFormat	= dateFormat.split(formatChar);if (aFormat.length<3){formatChar = "/";aFormat	= dateFormat.split(formatChar);if (aFormat.length<3){formatChar = ".";aFormat	= dateFormat.split(formatChar);if (aFormat.length<3){formatChar = "-";aFormat	= dateFormat.split(formatChar);if (aFormat.length<3){formatChar="";};};};};tokensChanged =	0;if ( formatChar	!= "" ){aData =	ctl2.value.split(formatChar);for	(i=0;i<3;i++){if ((aFormat[i]=="d") || (aFormat[i]=="dd")){dateSelected = parseInt(aData[i], 10);tokensChanged ++;}else if	((aFormat[i]=="m") || (aFormat[i]=="mm")){monthSelected =	parseInt(aData[i], 10) - 1;	tokensChanged ++;}else if	(aFormat[i]=="yyyy"){yearSelected = parseInt(aData[i], 10);	tokensChanged ++;}else if	(aFormat[i]=="mmm"){for	(j=0; j<12;	j++){if (aData[i]==monthName[j]){monthSelected=j;	tokensChanged ++;};};};};};if ((tokensChanged!=3)||isNaN(dateSelected)||isNaN(monthSelected)||isNaN(yearSelected)){dateSelected = dateNow;monthSelected =	monthNow;	yearSelected = yearNow;};odateSelected=dateSelected;	omonthSelected=monthSelected;oyearSelected=yearSelected;	aTag = ctl;	do {aTag = aTag.offsetParent;	leftpos	+= aTag.offsetLeft;toppos += aTag.offsetTop;} while(aTag.tagName!="BODY");crossobj.left =	fixedX==-1 ? ctl.offsetLeft	+ leftpos :	fixedX;crossobj.top = fixedY==-1 ?	ctl.offsetTop +	toppos + ctl.offsetHeight +	2 :	fixedY;constructCalendar (1, monthSelected, yearSelected);	crossobj.visibility=(dom||ie)? "visible" : "show";hideElement( 'SELECT', document.getElementById("calendar") );hideElement( 'APPLET', document.getElementById("calendar") );bShow = true;	}else{hideCalendar();if (ctlNow!=ctl) {popUpCalendar(ctl, ctl2, format)};};	ctlNow = ctl;};};
document.onkeypress = function hidecal1 () { if (event.keyCode==27) {hideCalendar()}}
document.onclick = function hidecal2 () { if (!bShow){hideCalendar()}	bShow = false}
window.onload = initcal;

function schedadd(ca, aoid, fullname, oid, currdt, schedotid){
	if(document.all['installoid'].value != '') {
		window.open('woform.aspx?ca=' + ca + '&cmd=schedcal&aoid=' + aoid + '&inst=' + fullname + '&instoid=' + oid + '&dt=' + currdt + '&doid=' + document.all['installoid'].value,'workframe');
	}else{
		window.open('woform.aspx?ca=' + ca + '&cmd=newlinkschedday&aoid=' + aoid + '&ddlCategory=o_' + schedotid + '&inst=' + fullname + '&instoid=' + oid + '&dt=' + currdt,'workframe');
	}
}

function getCal(fld1, fld2, setfld){
    popUpCalendar(document.getElementById(fld1), document.getElementById(fld1), 'mm/dd/yyyy');
}

//Sub Window Functions @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
//function moveOver()  
//{
//var boxLength = document.choiceForm.choiceBox.length;
//var selectedItem = document.choiceForm.available.selectedIndex;
//var selectedText = document.choiceForm.available.options[selectedItem].text;
//var selectedValue = document.choiceForm.available.options[selectedItem].value;
//var i;
//var isNew = true;
//if (boxLength != 0) {
//for (i = 0; i < boxLength; i++) {
//thisitem = document.choiceForm.choiceBox.options[i].text;
//if (thisitem == selectedText) {
//isNew = false;
//break;
//      }
//   }
//} 
//if (isNew) {
//newoption = new Option(selectedText, selectedValue, false, false);
//document.choiceForm.choiceBox.options[boxLength] = newoption;
//}
//document.choiceForm.available.selectedIndex=-1;
//}

var checkflag = "false";
function checkall(field) {
    if (checkflag == "false") {
        for (i = 0; i < field.length; i++) {
            field[i].checked = true;
        }
        checkflag = "true";
    } else {
        for (i = 0; i < field.length; i++) {
            field[i].checked = false; 
        }
        checkflag = "false";
    }
}










//var countDownInterval=150;
//var countDownTime=countDownInterval+1;
//function countDown(milsec, proc){
//	countDownTime--;
//	if (countDownTime <=0){
//		countDownTime=countDownInterval;	
//		clearTimeout(counter);	
//		eval(proc);
//		return;	
//	}	
//	counter=setTimeout("countDown()", milsec);	
//}	
       
function loadsubwin(loc){
	var w = (window.screen.availWidth - 50) * .80;
	var h = (window.screen.availHeight - 100) * .80;
	var rn = Math.floor(Math.random()*100000);
	var top = ((window.screen.availHeight - h) / 2);
	var left = ((window.screen.availWidth - w) / 2);
	
	var currsw = 'subwin' + rn;
	window.open(loc,currsw,'menubar=no,resizable=yes,status=yes,width=' + w + ',height=' + h + ',top=' + top + ',left=' + left);
}

function loaddebugwin(loc){
	var w = 400;
	var h = window.screen.availHeight - 400;
	var rn = Math.floor(Math.random()*100000);
	
	var currsw = 'subwin' + rn;
	window.open(loc,currsw,'scrollbars=yes,menubar=no,resizable=yes,status=yes,width=' + w + ',height=' + h + ',top=100,left=100');
}

function loadsubwinsm(loc){
	var w = window.screen.availWidth - 50;
	var h = window.screen.availHeight - 50;
	var rn = Math.floor(Math.random()*100000);
	
	var currsw = 'subwin' + rn;
	window.open(loc,currsw,'menubar=no,resizable=yes,status=yes,width=' + w + ',height=' + h + ',top=25,left=25');
}

function fieldpurpose(aoid, otid, fldname){
    var w = 500;
	var h = 200;
	var leftVal = (screen.width / 2)  - 250;
    var topVal = (screen.height / 2)  - 100;
    
	if (window.showModalDialog) { 
	    window.showModalDialog('purpose.aspx?aoid=' + aoid + '&otid=' + otid + '&fn=' + fldname, 'purpose', 'dialogHeight:' + h + 'px;dialogWidth:' + w + 'px;help:no;scroll:auto;status:no;'); 
	} else { 
	    window.open('purpose.aspx?aoid=' + aoid + '&otid=' + otid + '&fn=' + fldname,'purpose','scrollbars=auto,menubar=no,resizable=yes,status=yes,width=' + w + ',height=' + h + ',top=' + topVal + ',left=' + leftVal);
	}
}

function showinfo(msg){
    var w = 500;
	var h = 200;
	var leftVal = (screen.width / 2)  - 250;
    var topVal = (screen.height / 2)  - 100;
    window.showModalDialog('info.aspx?msg=' + msg, 'info', 'dialogHeight:' + h + 'px;dialogWidth:' + w + 'px;help:no;scroll:auto;status:no;'); 
}





function setTimeFld(fromfld, tofld){
    try{
	    document.all[tofld].selectedIndex=document.all[fromfld].selectedIndex + 4;
	} catch(e) {
	    document.all[tofld].selectedIndex=document.all[fromfld].selectedIndex;
	}
}




function refresh_sample(ca, cmd){
    document.all['frmNew'].action = "woform.aspx?cmd2=linkonly&ca=" + ca + "&cmd=" + cmd;
    document.all['frmNew'].submit();
}

function uploadfile(){
	document.all['frm'].submit();
	document.location.href = 'proc.htm'
}

function getreport(filename, formname){
	document.all[formname].action = filename;
	document.all[formname].method = 'post';
	document.all[formname].submit();
}

function getSearchVal(ca, aoid, searchotid, searchfld, linkingtable, islink, col1, col2, linkingfld){
	document.all[searchfld].blur();
	document.all['dupsrchfld'].value = searchfld;
	var linkingfldvalue = 0;
	var scv = '';
	var wwidth = screen.availWidth * .8;
	var wheight = screen.availHeight * .65;

	if(linkingfld != ''){
		linkingfldvalue = document.all[linkingfld].value; 
	}
	if(islink == 1 && linkingfldvalue == 0){
		alert('This field is dependant on another search on the form\nPlease search on required fields first before selecting this field');
	}else{
		if(islink == 0){
			if(document.frmNew.all[searchfld].value == ''){
				scv = 'all'; //users are allowed to search without placing any search values in the field.  If nothing is put in the field
			}else{             //we must search with stars to bring back nothing and open the field
				scv = 'all'; //document.frmNew.all[searchfld].value;
			}
			//alert('wodataset.aspx?ca=' + ca + '&aoid=' + aoid + '&cmd=objsrch&searchotid=' + searchotid + '&searchfld=' + searchfld + '&linkingfld=' + linkingfld + '&linkingfldvalue=' + linkingfldvalue + '&sc=' + document.frmNew.all[searchfld].value + '&linkingtable=' + linkingtable + '&islink=' + islink + '&col1=' + col1 + '&col2=' + col2);
			loadsubwin('wodataset.aspx?ca=' + ca + '&aoid=' + aoid + '&cmd=objsrch&searchotid=' + searchotid + '&searchfld=' + searchfld + '&linkingfld=' + linkingfld + '&linkingfldvalue=' + linkingfldvalue + '&sc=' + scv + '&linkingtable=' + linkingtable + '&islink=' + islink + '&col1=' + col1 + '&col2=' + col2);
		}else if(islink == 1){
			document.all[searchfld].value = ''
			loadsubwin('wodataset.aspx?ca=' + ca + '&aoid=' + aoid + '&cmd=objsrch&searchotid=' + searchotid + '&searchfld=' + searchfld+ '&linkingfld=' + linkingfld + '&linkingfldvalue=' + linkingfldvalue + '&sc=' + document.frmNew.all[searchfld].value + '&linkingtable=' + linkingtable + '&islink=' + islink + '&col1=' + col1 + '&col2=' + col2)
		}else{
			alert('Please enter your search criteria.');
		}
	}
}

function objsrchlinkchecked(val, fld){
    var txt = top.opener.document.all[fld].value
    if (txt.lastIndexOf(";") == txt.length - 1 || txt.lastIndexOf(";") == txt.length - 2){
        top.opener.document.all[fld].value = top.opener.document.all[fld].value + val;
    }else{
        if (txt.length > 0){top.opener.document.all[fld].value = top.opener.document.all[fld].value + "; "}
        top.opener.document.all[fld].value = top.opener.document.all[fld].value + val;
    }
    top.opener.document.all[fld + '_oid'].value = 0;
    top.close(); 
}

function closesubwindyn(){
	if(confirm('The current report may not be up to date.  Would you like to refresh the screen?')){
		window.open(top.opener.document.all['dynurl'].value,'workframe');
	}
	top.close();
}

function setCheckForm(){
    try{
        document.all['formchanged'].value = 1;     
    }catch(e){
        //do nothing... 
    }  
    
}

function checkhidesubwin(){
//    if (document.all['formchanged'].value == 1){
//		if(confirm('The changes on the current form have not been saved.  Are you sure?')){
//			top.close();
//		}
//	}else{
	    top.close();
//	}
}

function hidesubwin(){
	top.close();
}

function hidehelpwin(){
    try{
	    document.all['subwinhelp'].style.visibility = 'hidden';
	    document.frames['subwin'].location = '_blank.htm';
	} catch(e) {
	    //do nothing;
	}
}


function setTemplateFld(fld, fldvalue){
	top.opener.document.all[fld].value = fldvalue;
	try{
	    top.opener.editor_setmode(fld, "textedit");
	    top.opener.document.all['_' + fld + '_editor'].value = fldvalue;
	    top.opener.editor_setmode(fld, "wysiwyg");
	} catch(e) {
	   //alert(e);
	}
	top.close();
}

function setObjSearchFldDup(oid, fld, fldvalue){
alert(top.opener.document.all['dupsrchfld'].value);
	top.opener.document.all[top.opener.document.all['dupsrchfld'].value].value = fldvalue;
	top.opener.document.all[top.opener.document.all['dupsrchfld'].value+ '_oid'].value = oid;
	top.close();
}

//main search information @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
function displayform(ca, oid, otid, cmd, targ){
	document.frmSearch.oid.value = oid;
	document.frmSearch.otid.value = otid;
	
	document.frmSearch.target = targ;
	document.frmSearch.action = "woform.aspx?ca=" + ca + "&cmd=" + cmd + "&rt=1";
	document.frmSearch.method = "post";
	document.frmSearch.submit();
}	

function displayformlink(ca, oid, otid, cmd, targ){
	document.frmSearch.oid.value = oid;
	document.frmSearch.otid.value = otid;
	
	document.frmSearch.xoid.value = oid;
	document.frmSearch.xotid.value = otid;
	
	document.frmSearch.target = targ;
	document.frmSearch.action = "woform.aspx?cmd2=linkonly&ca=" + ca + "&cmd=" + cmd + "&rt=1";
	document.frmSearch.method = "post";
	document.frmSearch.submit();
}	

function displayformdt(ca, oid, otid){
	document.frmSearch.target = "workframe";
	document.frmSearch.action = "woform.aspx?ca=" + ca + "&cmd=dupview&otid=" + otid + "&oid=" + oid + "&sct=yes&rt=1";
	document.frmSearch.method = "post";
	document.frmSearch.submit();
}	

function fillSelectFromArray(selectCtrl, itemArray, goodPrompt, badPrompt, defaultItem) {
	var i, j;
	var prompt;
	// empty existing items
	for (i = selectCtrl.options.length; i >= 0; i--) {
		selectCtrl.options[i] = null; 
	}
	prompt = (eval(itemArray) != null) ? goodPrompt : badPrompt;
	if (prompt == null) {
		j = 0;
	}else{
		selectCtrl.options[0] = new Option(prompt);
		j = 1;
	}
	if (eval(itemArray) != null) { // add new items
		for (i = 0; i < eval(itemArray).length; i++) {
			selectCtrl.options[j] = new Option(eval(itemArray)[i][0]);
			if (eval(itemArray)[i][1] != null) {
				selectCtrl.options[j].value = eval(itemArray)[i][1]; 
			}
			j++;
		}
		selectCtrl.options[0].selected = true; // select first item (prompt) for sub list
	}
}

function movedata(fld1, fld2){
    document.all[fld2].value = document.all[fld1].value;
}

function sv(obj, val, otid){
	resetCrit();
	document.all['ddlCategory'].value = val;
	fillSelectFromArray(document.all['col1'], 'ao_' + otid);
	fillSelectFromArray(document.all['col2'], 'ao_' + otid);
	fillSelectFromArray(document.all['col3'], 'ao_' + otid);
	if(document.all['butobj'].value == ""){
		document.all['butobj'].value = obj;
		document.all[obj].className = 'newb_s';
	}else{
		document.all[document.all['butobj'].value].className = 'newb_off';
		document.all['butobj'].value = obj;
		document.all[obj].className = 'newb_s';
	}
	document.all['ddl'].options[0].selected = true;
}
function svd(){
	resetCrit();
	var ddl = document.all['ddl']
	if(ddl.options[ddl.selectedIndex].value!=0 && ddl.options[ddl.selectedIndex].value!='s'){
		document.all['ddlCategory'].value = ddl.options[ddl.selectedIndex].value;
		fillSelectFromArray(document.all['col1'], 'a' + document.all['ddlCategory'].value);
		fillSelectFromArray(document.all['col2'], 'a' + document.all['ddlCategory'].value);
		fillSelectFromArray(document.all['col3'], 'a' + document.all['ddlCategory'].value);
		if(document.all['butobj'].value != ""){
			document.all[document.all['butobj'].value].className = 'newb_off';
			document.all['butobj'].value = '';
		}
	}
}
function sro(obj,clsname){
	if(document.all['butobj'].value != obj){
		document.all[obj].className = clsname;
	}
}
function resetCrit(){
	document.all['crit1'].options[0].selected = true;
	document.all['crit2'].options[0].selected = true;
	document.all['crit3'].options[0].selected = true;
}

function resetForm(){
	resetCrit();
	document.all['txtCriteria'].value = '';
	document.all['txtCriteria1'].value = '';
	document.all['txtCriteria2'].value = '';
	document.all['txtCriteria3'].value = '';
	document.all['txtCriteria'].value = '';
	if(document.all['butobj'].value != ""){
		document.all[document.all['butobj'].value].className = 'newb_off';
		document.all['butobj'].value = '';
	}
	document.all['ddl'].options[0].selected = true;
	for (i = document.all['col1'].options.length; i >= 0; i--) {
		document.all['col1'].options[i] = null; 
	}
	for (i = document.all['col2'].options.length; i >= 0; i--) {
		document.all['col2'].options[i] = null; 
	}
	for (i = document.all['col3'].options.length; i >= 0; i--) {
		document.all['col3'].options[i] = null; 
	}
}

function desklinksrch(ca, aoid, cat){
	var sc = prompt('Please enter your search criteria...', '');
	if(sc == ''){
		alert('You must enter search criteria in order to search.');
	}else{
		window.open('wodataset.aspx?ca=' + ca + '&cmd=new&aoid=' + aoid + '&ddlCategory=' + cat + '&txtCriteria=' + sc,'workframe');
	}
}

function desklinkext(lnk){
  window.open(lnk,'workframe','scrollbars=yes,menubar=no,resizable=yes,status=yes,top=0,left=0,width=window.screen.availWidth,height=window.screen.availHeight');
}
//Main Search Information @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

//Button Features @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
function ro(obj, clsname){
	document.all[obj].className = clsname;
}

function gotodataview(ca, otid, oid){
	window.open('woform.aspx?ca=' + ca + '&cmd=dataview&aoid=' + document.all['aoid'].value + '&otid=' + otid + '&oid=' + oid,'workframe');
	top.close();
}

function removelink(ca, poid, potid, oid, otid, aoid){
	try{
		if(confirm("You are about to unlink/remove the current record from the list. \nThis action will NOT delete the record. \nAre you sure?")){
		    document.frmNew.target = 'procframe';
			document.frmNew.action = 'woform.aspx?cmd2=linkonly&ca=' + ca + '&cmd=unlink&poid=' + poid + '&potid=' + potid + '&oid=' + oid + '&otid=' + otid;
			document.frmNew.method = "post";
			document.frmNew.submit();
		}
	} catch(e) {
		//alert('This page is currently loading.  Please Wait...');
	}
}

//currently not used
function removelinkdt(ca, oid, otid, aoid){
	try{
		if(confirm("You are about to unlink/remove the current record from your desktop. \nThis action will NOT delete the record. Are you sure?")){
			document.frmNew.action = 'woform.aspx?cmd2=linkonly&ca=' + ca + '&cmd=unlink&oid=' + oid + '&otid=' + otid + '&aoid=' + aoid;
			document.frmNew.method = "post";
			document.frmNew.submit();
		}
	} catch(e) {
		//alert('This page is currently loading.  Please Wait...');
	}
}

//Button Features End @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

//WorkObjects 5.0 Default Configuration @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
function autofill_bidder(){
	if(document.all['allbidders'].checked){
		document.all['contact'].value = 'All Bidders';
		document.all['contact_oid'].value = '1';
		alert('The contact field has been automatically updated.');
	}
}

function calcMarkupBudget(){
	var qty = document.all['qty'].value;
	if(qty == ''){document.all['qty'].value = 1; qty = 1};

	formatCurrency(document.all['itemcost'], 0); 
	var totitemcost = document.all['itemcost'].value;
	totitemcost = totitemcost.replace(',','');
	totitemcost = parseFloat(totitemcost) * qty;
	document.all['totitemcost'].value = totitemcost;
	formatCurrency(document.all['itemcost'], 1); 
	formatCurrency(document.all['totitemcost'], 1);

	var markup = document.all['markup'].value;
	var markupamt = document.all['markupamt'].value;

	if(markup != ''){
		markupamt = parseFloat(markup) * parseFloat(totitemcost);
		document.all['markupamt'].value = markupamt;
		formatCurrency(document.all['markupamt'], 1);

		var subtotal = parseFloat(totitemcost) + parseFloat(markupamt);
		if(!taxExemptCheck()){
			var salestax = document.all['salestax'].value;
			if(salestax == ''){salestax = 0.0;document.all['salestax'].value = '0.0';}
			var salestaxamt = parseFloat(subtotal) * (parseFloat(salestax) * .01);
			subtotal = parseFloat(subtotal) + parseFloat(salestaxamt);
			document.all['salestaxamt'].value = salestaxamt;
			formatCurrency(document.all['salestaxamt'], 1);
		}else{
			document.all['salestaxamt'].value = '$0.00';
		}
		document.all['subtotal'].value = subtotal;
		formatCurrency(document.all['subtotal'], 1);

		calcSalePrice(subtotal);
	}	
}

function taxExemptCheck(){
	if(document.all['taxexempt'].checked){return true;}else{return false;	}
}

function qtyCheck(){
	var qty = document.all['qty'].value;
	if(isNaN(qty) || parseFloat(qty) < 0){
		alert('The quantity field must have a numeric value greater that zero.');
		document.all['itemcost'].value = '$0.00';
		document.all['totitemcost'].value = '$0.00';
		document.all['subtotal'].value = '$0.00';
		document.all['markup'].value = '';
		document.all['markupamt'].value = '$0.00';
		document.all['qty'].value = '';
	}else{
		calcMarkupBudget();
	}
}

function calc_cc(){
    if(isNaN(document.getElementById("itemquant").value) || document.getElementById("itemquant").value == ''){
        alert('This field requires a numeric value.');
        document.getElementById("itemquant").value = '1';
        document.getElementById("iqtot").value = '$8.00';
    }else if(document.getElementById("itemquant").value > 10){
        alert('Quantities of greater than 10 requires special pricing \nPlease contact us at members@inquirestyle.com');
        document.getElementById("itemquant").value = '1';
        document.getElementById("iqtot").value = '$8.00';
    }else{ 
        document.getElementById("iqtot").value = parseFloat(document.getElementById("itemquant").value) * 8;
        formatCurrency(document.getElementById("iqtot"), 1); 
    } 
}

function formatCurrency(thefield, showsign) {
	if (formatCurrency.arguments.length == 1) showsign = 1;
	thefield.value = thefield.value.toString().replace(/\$|\,/g,'');
	if(isNaN(thefield.value)) thefield.value = "0";
	sign = (thefield.value == (thefield.value = Math.abs(thefield.value)));
	thefield.value = Math.round(thefield.value*100);
	cents = thefield.value%100;
	thefield.value = Math.floor(thefield.value/100).toString();
	
	if(cents<10){
//	    cents = "00" + cents;
//	}else if(cents<100){
	    cents = "0" + cents;
	} 

	for (var i = 0; i < Math.floor((thefield.value.length-(1+i))/3); i++)
	    thefield.value = thefield.value.substring(0,thefield.value.length-(4*i+3))+ ',' + thefield.value.substring(thefield.value.length-(4*i+3));

	if (showsign == 1){
	    thefield.value = (((sign)?'':'-') + '$' + thefield.value + '.' + cents);
	}else{
	    thefield.value = (((sign)?'':'-') + thefield.value + '.' + cents);
    }
}

function totalMoney(qty, unitcost, total){
    var varqty = document.all[qty].value;
    
    formatCurrency(document.all[unitcost], 0); 
    var varunitcost = document.all[unitcost].value;
    varunitcost = varunitcost.replace(',','');

    if(!isNaN(varqty) && !isNaN(varunitcost)){
        var vartotal = parseFloat(varunitcost) * varqty;
        document.all[total].value = vartotal;
        formatCurrency(document.all[total], 1);
    } 
    formatCurrency(document.all[unitcost], 1); 
}

function calcMarkup(){
	formatCurrency(document.all['totitemcost'], 0);
	var totitemcost = document.all['totitemcost'].value;
	totitemcost = totitemcost.replace(',','');

	formatCurrency(document.all['subtotal'], 0);
	var subtotal = document.all['subtotal'].value;
	subtotal = subtotal.replace(',','');

	str = new String(document.all['markup'].value);
	var markup = formatFloat(str);

	if(isNaN(markup) || markup == 0){markup = '0.0'; document.all['markup'].value = '0.0';}
	document.all['markup'].value = markup;

	var markupamt = parseFloat(totitemcost) * parseFloat(markup);
	document.all['markupamt'].value = markupamt;
	formatCurrency(document.all['markupamt'], 1);

	subtotal = parseFloat(totitemcost) + parseFloat(markupamt)
	if(!taxExemptCheck()){
		var salestax = document.all['salestax'].value;
		if(salestax == ''){salestax = 0.0;document.all['salestax'].value = '0.0';}
		var salestaxamt = parseFloat(subtotal) * (parseFloat(salestax) * .01);
		subtotal = parseFloat(subtotal) + parseFloat(salestaxamt);
		document.all['salestaxamt'].value = salestaxamt;
		formatCurrency(document.all['salestaxamt'], 1);
	}else{
		document.all['salestaxamt'].value = '$0.00';
	}

	document.all['subtotal'].value = subtotal;
	formatCurrency(document.all['subtotal'], 1);
	formatCurrency(document.all['totitemcost'], 1);

	calcSalePrice(subtotal);
}

function calcMarkupAmt(){
	formatCurrency(document.all['totitemcost'], 0);
	var totitemcost = document.all['totitemcost'].value;
	totitemcost = totitemcost.replace(',','');

	formatCurrency(document.all['markupamt'], 0);
	var markupamt = document.all['markupamt'].value;
	markupamt = markupamt.replace(',','');

	var markup = (parseFloat(markupamt) / parseFloat(totitemcost));
	markup = Math.round(markup * 100) / 100;
	if(markup == 0 || isNaN(markup) || !isFinite(markup)){markup = '0.0'};

	document.all['markup'].value = markup;
	formatCurrency(document.all['markupamt'], 1);

	subtotal = parseFloat(totitemcost) + parseFloat(markupamt)
	if(!taxExemptCheck()){
		var salestax = document.all['salestax'].value;
		if(salestax == ''){salestax = 0.0;document.all['salestax'].value = '0.0';}
		var salestaxamt = parseFloat(subtotal) * (parseFloat(salestax) * .01);
		subtotal = parseFloat(subtotal) + parseFloat(salestaxamt);
		document.all['salestaxamt'].value = salestaxamt;
		formatCurrency(document.all['salestaxamt'], 1);
	}else{
		document.all['salestaxamt'].value = '$0.00';
	}

	document.all['subtotal'].value = subtotal;
	formatCurrency(document.all['subtotal'], 1);

	formatCurrency(document.all['totitemcost'], 1);

	calcSalePrice(subtotal);
}

function NoEdit(fld, flddesc){
	fld.style.border = "solid 1px #F1F4FA";
	fld.style.backgroundColor = "#F1F4FA";
	fld.blur();
	//alert('The "' + flddesc + '" field cannot be edited');
}

function setStateTax(){
	var statefld = document.all['state_id'];
	var stateid = statefld.options[statefld.selectedIndex].value;
	if(stateid > 1){
		document.all['salestax'].value = eval('st_' + stateid);
	}
}

function calcSalePrice(bidprice){
	formatCurrency(document.all['freightcost'], 0);
	var freight = document.all['freightcost'].value;
	var saleprice = parseFloat(freight) + parseFloat(bidprice);
	document.all['finalsaleprice'].value = saleprice;
	formatCurrency(document.all['freightcost'], 1);
	formatCurrency(document.all['finalsaleprice'], 1);
}

function formatFloat(s){
	if(isNaN(parseFloat(s))){
		return 0.0;
	}else{
		if(s.charAt(0) == '.' || (str.charAt(0) == '0' && str.charAt(1) == '.')){           
			return s;
		}else{
			return (parseFloat(s) / 100);
		}
	}
}



//OLD @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@2
function _ro(objn, onOff){
	if(onOff){
		document.all['mmb_' + objn].className = 'mmboron';
		document.all['mmt_' + objn].className = 'mmtxton';
	}else{
		document.all['mmb_' + objn].className = 'mmboroff';
		document.all['mmt_' + objn].className = 'mmtxtoff';
	}
}
function _ros(objn, onOff){
	if(onOff){
		document.all['smb_' + objn].className = 'smboron';
		document.all['smt_' + objn].className = 'smtxton';
	}else{
		document.all['smb_' + objn].className = 'smboroff';
		document.all['smt_' + objn].className = 'smtxtoff';
	}
}

function stopwin(){
	try {
		window.stop();
	} catch (e) {
		//do nothing
	}
}

function _rsm(objn, tcls, bcls){
	document.all['smb_' + objn].className = bcls;
	document.all['smt_' + objn].className = tcls;
}

function smro(obj, clsname){
	alert(obj);
	alert(clsname);
	//document.all[obj].className = clsname;
}

function header_gotourl(page){
	window.open(page,'workframe','title=Casewide WorkObjects 5.0');
}

function panel_gotourl(page,frame){
	window.open(page,frame,'title=Casewide WorkObjects 5.0');
}

//currently not used
function panel_logoff(){
	window.open('splitview_vertical.aspx?ca=' + ca + '&cmd=logoff&aoid=1','workframe','title=Casewide WorkObjects 5.0');
}

function setaction(filename){
	document.frm.action = filename; 
}

function AutoCenterWin(mypage,myname,w,h,scroll){
var win = null;
LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
TopPosition = (screen.height) ? (screen.height-h)/2 : 0;
settings =
'height='+h+',width='+w+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',resizable'
win = window.open(mypage,myname,settings)
}

function openhelpwin(){
	window.open('helpwin.aspx','wohelpwin','menubar=no,toolbar=yes,resizable=yes,status=no,width=800,height=600,top=50,left=50');
}

function MWJ_findObj( oName, oFrame, oDoc ) {
	if( !oDoc ) { if( oFrame ) { oDoc = oFrame.document; } else { oDoc = window.document; } }
	if( oDoc[oName] ) { return oDoc[oName]; } if( oDoc.all && oDoc.all[oName] ) { return oDoc.all[oName]; }
	if( oDoc.getElementById && oDoc.getElementById(oName) ) { return oDoc.getElementById(oName); }
	for( var x = 0; x < oDoc.forms.length; x++ ) { if( oDoc.forms[x][oName] ) { return oDoc.forms[x][oName]; } }
	for( var x = 0; x < oDoc.anchors.length; x++ ) { if( oDoc.anchors[x].name == oName ) { return oDoc.anchors[x]; } }
	for( var x = 0; document.layers && x < oDoc.layers.length; x++ ) {
		var theOb = MWJ_findObj( oName, null, oDoc.layers[x].document ); if( theOb ) { return theOb; } }
	if( !oFrame && window[oName] ) { return window[oName]; } if( oFrame && oFrame[oName] ) { return oFrame[oName]; }
	for( var x = 0; oFrame && oFrame.frames && x < oFrame.frames.length; x++ ) {
		var theOb = MWJ_findObj( oName, oFrame.frames[x], oFrame.frames[x].document ); if( theOb ) { return theOb; } }
	return null;
}

function setObjSearchFld(oid, fld, fldvalue){
	top.parent.document.all[fld].value = fldvalue;top.parent.document.all[fld + '_oid'].value = oid;
}

function getpage(ca, otid, col, aoid){
	var pn = document.all['pagenum'].value;
	var revsort = document.all['revsort'].value;
	var rpp = document.all['rpp'].value;
	var norev = document.all['norev'].value;
	
	window.open('wodataset.aspx?ca=' + ca + '&norev=' + norev + '&cmd=sort&setpager=true&rpp=' + rpp + '&pagenum=' + pn + '&otid=' + otid + '&col=' + col + '&aoid=' + aoid + '&revsort=' + revsort,'workframe');
}

function checkSealedBid(){
	if(document.all['sealedbid'].checked){
		alert('Please allow 24-48 hours on the bid due date field for processing!');
	}
}

//totQtyCost('lab_tot','lab_qty','lab_cost');
//function totQtyCost(tot, qty, cost) {
//	var quantity = document.all[qty].value;
//	
//	formatCurrency(document.all[cost], 0);
//	var costing = document.all[cost].value;
//	costing = costing.replace(',','');

//	//alert(quantity + ' - ' + costing + ' - ' + tot);

//	if(quantity > 0 && costing > 0){
//		document.all[tot].value = quantity * costing;
//		formatCurrency(document.all[tot], 1);
//	}else{
//		document.all[tot].value = '$0.00';
//	}

//	formatCurrency(document.all[cost], 1);
//	setMatLabCost();
//	calcGA();
//	calcGPM();
//	calcSalesTax();
//}



function totQtyCost(cost) {
    
//	var quantity = document.all[qty].value;
//	
//	formatCurrency(document.all[cost], 0);
//	var costing = document.all[cost].value;
//	costing = costing.replace(',','');

//	if(quantity > 0 && costing > 0){
//		document.all[tot].value = quantity * costing;
//		formatCurrency(document.all[tot], 1);
//	}else{
//		document.all[tot].value = '$0.00';
//	}

    formatCurrency(document.all[cost], 1);
 //setMatLabCost();
	calcGA();
	calcGPM();
	calcSalesTax();
}



//totQtyCostMarkup('misc1_tot', 'misc1_qty', 'misc1_cost', 'misc1_perc');    
function totQtyCostMarkup(tot, qty, cost, markupval) {
	var quantity = document.all[qty].value;
	
	formatCurrency(document.all[cost], 0);
	var costing = document.all[cost].value;
	costing = costing.replace(',','');

	if(quantity > 0 && costing > 0){
		if(document.all[markupval].value == ''){
			document.all[markupval].value = '0.0';
		}else{
			str = new String(document.all[markupval].value);
			var markup = formatFloat(str) * 100 / 100;

			if(isNaN(markup) || markup == 0){markup = '0.0';}
			document.all[markupval].value = markup;
		}
		document.all[tot].value = quantity * costing;
		var markupamt = parseFloat(document.all[tot].value) * parseFloat(markup);
		if(parseFloat(markupamt) > 0){
			var totamt = document.all[tot].value; 
			document.all[tot].value = parseFloat(totamt) + parseFloat(markupamt);
		}
		formatCurrency(document.all[tot], 1);
	}else{
		document.all[tot].value = '$0.00';
		document.all[markupval].value = '';
	}
	formatCurrency(document.all[cost], 1);
	setMatLabCost();
	calcGA();
	calcGPM();
	calcSalesTax();
}

function setMatLabCost(){
	formatCurrency(document.all['lab_tot'], 0);
	formatCurrency(document.all['meas_tot'], 0);
	formatCurrency(document.all['instl_tot'], 0);
	formatCurrency(document.all['instd_tot'], 0);

	formatCurrency(document.all['fre_tot'], 0);
	formatCurrency(document.all['shop_tot'], 0);

	var lab_tot = document.all['lab_tot'].value;
	lab_tot = lab_tot.replace(',','');

	var meas_tot = document.all['meas_tot'].value;
	meas_tot = meas_tot.replace(',','');

	var instl_tot = document.all['instl_tot'].value;
	instl_tot = instl_tot.replace(',','');

	var instd_tot = document.all['instd_tot'].value;
	instd_tot = instd_tot.replace(',','');

	var fre_tot = document.all['fre_tot'].value;
	fre_tot = fre_tot.replace(',','');

	var shop_tot = document.all['shop_tot'].value;
	shop_tot = shop_tot.replace(',','');	

	var lab_total = parseFloat(lab_tot) + parseFloat(meas_tot) + parseFloat(instl_tot) + parseFloat(instd_tot);

	var mat_total  = parseFloat(fre_tot) + parseFloat(shop_tot);

	document.all['totmatcost'].value = mat_total;
	document.all['totlabcost'].value = lab_total;

	formatCurrency(document.all['lab_tot'], 1);
	formatCurrency(document.all['meas_tot'], 1);
	formatCurrency(document.all['instl_tot'], 1);
	formatCurrency(document.all['instd_tot'], 1);

	formatCurrency(document.all['fre_tot'], 1);
	formatCurrency(document.all['shop_tot'], 1);

	formatCurrency(document.all['totmatcost'], 1);
	formatCurrency(document.all['totlabcost'], 1);
}

function AdditionalCost(){
    formatCurrency(document.all['bondamt'], 0);
    var _bondamt = document.all['bondamt'].value;
    _bondamt = _bondamt.replace(',',''); 
    formatCurrency(document.all['bondamt'], 1); 
   
    formatCurrency(document.all['ocipamt'], 0);
    var _ocipamt = document.all['ocipamt'].value;
    _ocipamt = _ocipamt.replace(',','');  
    formatCurrency(document.all['ocipamt'], 1); 
   
    formatCurrency(document.all['freight'], 0);
    var _freight = document.all['freight'].value;
    _freight = _freight.replace(',','');  
    formatCurrency(document.all['freight'], 1); 
   
    formatCurrency(document.all['travel'], 0);
    var _travel = document.all['travel'].value;
    _travel = _travel.replace(',','');  
    formatCurrency(document.all['travel'], 1); 
    
    formatCurrency(document.all['miscamt'], 0);
    var _miscamt = document.all['miscamt'].value;
    _miscamt = _miscamt.replace(',','');  
    formatCurrency(document.all['miscamt'], 1); 
   
    var tot = parseFloat(_bondamt) + parseFloat(_ocipamt) + parseFloat(_freight) + parseFloat(_travel) + parseFloat(_miscamt); 
    return tot; 
}

function calcGA(){
    var addcost = AdditionalCost();
	formatCurrency(document.all['totmatcost'], 0);
	formatCurrency(document.all['totlabcost'], 0);
	
	var mat_total = document.all['totmatcost'].value
	mat_total = mat_total.replace(',','');

	var lab_total = document.all['totlabcost'].value
	lab_total = lab_total.replace(',','');

	var totamt = parseFloat(mat_total) + parseFloat(lab_total);
	var gacost = parseFloat(totamt) * document.all['gap'].value;
	if(parseFloat(gacost) < document.all['gac'].value){gacost = document.all['gac'].value}
	document.all['ga'].value = gacost;

	formatCurrency(document.all['totlabcost'], 1);
	formatCurrency(document.all['totmatcost'], 1);
	formatCurrency(document.all['ga'], 1);

	//var netcost = parseFloat(totamt) + parseFloat(gacost);
	var netcost = parseFloat(totamt) + parseFloat(gacost) + parseFloat(AdditionalCost());
	document.all['netcosttot'].value = netcost;
	formatCurrency(document.all['netcosttot'], 1);
	document.all['subtotal'].value = document.all['netcosttot'].value;
}

function calcGPM(){
	if(document.all['markup'].value != '' && document.all['markup'].value != '0.00' && document.all['netcosttot'].value != '' && document.all['netcosttot'].value != '0.00'){
		formatCurrency(document.all['netcosttot'], 0);
		var netcost = document.all['netcosttot'].value;
		netcost = netcost.replace(',','');
		
		str = new String(document.all['markup'].value);
		var mu = formatFloat(str) * 100 / 100;
		if(isNaN(mu) || mu == 0){mu = '0.0';}
		document.all['markup'].value = mu;

		var subtot = parseFloat(netcost) / (1 - parseFloat(mu));
		document.all['subtotal'].value = subtot;
		document.all['gpm'].value = parseFloat(subtot) - parseFloat(netcost);
		
		formatCurrency(document.all['netcosttot'], 1);
		formatCurrency(document.all['gpm'], 1);
		formatCurrency(document.all['subtotal'], 1);
		calcSalesTax();
	}
}

function calcSalesTax(){
	if(document.all['subtotal'].value != '' && document.all['subtotal'].value != '0.00'){
		formatCurrency(document.all['subtotal'], 0);
		var subtot = document.all['subtotal'].value;
		subtot = subtot.replace(',','');
		
		str = new String(document.all['salestaxperc'].value);
		var taxperc = formatFloat(str) * 100 / 100;
		if(isNaN(taxperc) || taxperc == 0){taxperc = '0.0';}
		document.all['salestaxperc'].value = taxperc;

		var taxamt = parseFloat(subtot) * (parseFloat(taxperc));
		document.all['salestaxamt'].value = taxamt;
		document.all['finalsaleprice'].value = parseFloat(subtot) + parseFloat(taxamt);
		
		formatCurrency(document.all['subtotal'], 1);
		formatCurrency(document.all['salestaxamt'], 1);
		formatCurrency(document.all['finalsaleprice'], 1);
	}
}

function setTaxExempt(){
	if(document.all['taxexemptyn'].checked){
		document.all['salestaxperc'].value = '0.0';
		calcSalesTax();
	}
}

function calcMiscMarkup(){
	//setMatLabCost();
	calcGA();
	calcGPM();

	if(document.all['miscmarkupperc'].value != '' && document.all['miscmarkupperc'].value != '0.00'){
		formatCurrency(document.all['subtotal'], 0);
		var subtot = document.all['subtotal'].value;
		subtot = subtot.replace(',','');
		
		str = new String(document.all['miscmarkupperc'].value);
		var markupperc = formatFloat(str) * 100 / 100;
		if(isNaN(markupperc) || markupperc == 0){markupperc = '0.0';}
		document.all['miscmarkupperc'].value = markupperc;

		var markupamt = parseFloat(subtot) * (parseFloat(markupperc));
		document.all['subtotal'].value = parseFloat(subtot) + parseFloat(markupamt);
		
		formatCurrency(document.all['subtotal'], 1);
		calcSalesTax();
	}else{
		document.all['miscmarkupperc'].value = '0.00';
		calcSalesTax();
	}
}

function updtObjSearchFld(fld1, fld2){
	document.all[fld2].value = document.all[fld1].value;
	document.all[fld2 + '_oid'].value = document.all[fld1 + '_oid'].value;
}

function updtField(fld1, fld2){
	document.all[fld2].value = document.all[fld1].value;
}

function copya(){
    if(document.all['copyaddr'].checked){
       document.all['ship_addr1'].value = document.all['bill_addr1'].value;
       document.all['ship_addr2'].value = document.all['bill_addr2'].value;
       document.all['ship_city'].value = document.all['bill_city'].value;
       document.all['stateII_id'].value = document.all['state_id'].value;
       document.all['ship_province'].value = document.all['bill_province'].value;
       document.all['ship_zip'].value = document.all['bill_zip'].value;
       document.all['countryII_id'].value = document.all['country_id'].value;
       document.all['ship_contact'].value = document.all['bill_contact'].value;
       document.all['ship_phone'].value = document.all['bill_phone'].value;
    }
}

function _copya(){
    if(document.all['copyaddr'].checked){
       document.all['_addline1'].value = document.all['addline1'].value;
       document.all['_addline2'].value = document.all['addline2'].value;
       document.all['_addline3'].value = document.all['addline3'].value;
       document.all['stateII_id'].value = document.all['state_id'].value;
       document.all['_province'].value = document.all['province'].value;
       document.all['_postalcode'].value = document.all['postalcode'].value;
       document.all['countryII_id'].value = document.all['country_id'].value;
       document.all['_city'].value = document.all['city'].value;
    }
}

function updatePrice(val){
    var qty = document.all['qty'].value;
    if(qty == '' || isNaN(qty)) qty = 1;
    document.all['qty'].value = qty;
    
    formatCurrency(document.all['unitprice'], 0); 
    var cp = document.all['unitprice'].value;
    cp = cp.replace(',','');
    cp = Number(val);
    
    document.all['unitprice'].value = cp;
    formatCurrency(document.all['unitprice'], 1);
   
    cp = qty * parseFloat(cp);
    document.all['totprice'].value = cp; 
    formatCurrency(document.all['totprice'], 1);   
}

function setPrice(){
   var a = document.all['prt_id'].value;
   var b = document.all['os_id'].value;
   var c = document.all['pattern_id'].value;
   var d = document.all['bs_id'].value;
   var e = document.all['fabwidth_id'].value;
   var mv = "m" + a + '_' + b + '_' + c + '_' + d + '_' + e
   try{
        updatePrice(eval(mv)); 
   }catch (e){
        //alert("m" + mv);
   } 
}

function setSizes(){
    if(document.all['bs_id'].value == 9){
        document.all['width'].value = 76;
        document.all['length'].value = 110;
        document.all['dropsize'].value = 21;
    }   
    if(document.all['bs_id'].value == 10){
        document.all['width'].value = 81;
        document.all['length'].value = 115;
        document.all['dropsize'].value = 21;
    } 
   if(document.all['bs_id'].value == 11){
        document.all['width'].value = 96;
        document.all['length'].value = 115;
        document.all['dropsize'].value = 21;
    } 
   if(document.all['bs_id'].value == 12){
        document.all['width'].value = 101;
        document.all['length'].value = 115;
        document.all['dropsize'].value = 21;
    } 
   if(document.all['bs_id'].value == 13){
        document.all['width'].value = 120;
        document.all['length'].value = 115;
        document.all['dropsize'].value = 21;
    }    
}

function convToYards(meterfield, yardfield){
    var m = document.all[meterfield].value;
    var y; 
    if(!isNaN(m)){
        y = m * 1.0936133;
        y = Math.round(y); 
        document.all[yardfield].value = y;
    } 
}   

function convToMeters(meterfield, yardfield){
    var m; 
    var y = document.all[yardfield].value;
    if(!isNaN(y)){
        m = y * 0.9144;
        m = Math.round(m); 
        document.all[meterfield].value = m;
    }
}   

function convToYardCost(meterfield, yardfield, mcost, ycost){
    formatCurrency(document.all[mcost],0);
    var mc = document.all[mcost].value; 
    var y; 
    if(!(isNaN(mc) && isNaN(document.all[meterfield].value) && isNaN(document.all[yardfield].value))){
        var totmc = mc * document.all[meterfield].value; 
        var totyc = totmc / document.all[yardfield].value;
        document.all[ycost].value = totyc;
        formatCurrency(document.all[mcost],1);
        formatCurrency(document.all[ycost],1); 
    } 
}   

function convToMeterCost(meterfield, yardfield, mcost, ycost){
    formatCurrency(document.all[ycost],0);
    var yc = document.all[ycost].value; 
    var m; 
    if(!(isNaN(yc) && isNaN(document.all[meterfield].value) && isNaN(document.all[yardfield].value))){
        var totyc = yc * document.all[yardfield].value; 
        var totmc = totyc / document.all[meterfield].value;
        document.all[mcost].value = totmc;
        formatCurrency(document.all[mcost],1);
        formatCurrency(document.all[ycost],1); 
    } 
}   

//ajax #######################################################################

function submitformobj(ca, cmd){
	//try {
	    document.all['xcmd'].value = cmd;
	
		if(cmd != 'cancel' && cmd != 'view' && cmd != 'delete'){
			if(checksave(cmd)){
			    document.all['frmNew'].target = "procframe";
				document.all['frmNew'].action = "woform.aspx?ca=" + ca + "&cmd=" + cmd;
				document.all['frmNew'].submit();
			}
		}else{
		    document.all['frmNew'].target = "procframe";
			document.all['frmNew'].action = "woform.aspx?ca=" + ca + "&cmd=" + cmd;
			document.all['frmNew'].submit();
		}
	//} catch(e) {
		//alert('This page is currently loading.  Please Wait...');
	//}
}	


function submitformobjreg(ca, cmd){
	//try {
	    document.all['xcmd'].value = cmd;
	
		if(cmd != 'cancel' && cmd != 'view' && cmd != 'delete'){
			if(checksave(cmd)){
			    document.all['frmNew'].target = "workframe";
				document.all['frmNew'].action = "woform.aspx?ca=" + ca + "&cmd=" + cmd;
				document.all['frmNew'].submit();
			}
		}else{
		    document.all['frmNew'].target = "workframe";
			document.all['frmNew'].action = "woform.aspx?ca=" + ca + "&cmd=" + cmd;
			document.all['frmNew'].submit();
		}
	//} catch(e) {
		//alert('This page is currently loading.  Please Wait...');
	//}
}	

function checkformchange(loc, win){
//	if (document.all['formchanged'].value == 1 && document.all['disablecheck'].value == 0){
//		if(confirm('The changes on the current form have not been saved.  Are you sure?')){
//			window.open(loc,win);
//		}
//	}else{
	    window.open(loc, win);
//	}
}

function checkformchangesubmit(loc, win){
//	if (document.all['formchanged'].value == 1 && document.all['disablecheck'].value == 0){
//		if(confirm('The changes on the current form have not been saved.  Are you sure?')){
//			document.all['frmNew'].target = win;
//			document.all['frmNew'].action = loc;
//			document.all['frmNew'].submit();
//		}
//	}else{
	    document.all['frmNew'].target = win;
		document.all['frmNew'].action = loc;
		document.all['frmNew'].submit();
//	}
}

function submitformdepcheck(aoid, ca, cmd, msg){
	if(msg != ''){
		if(confirm(msg)){
			window.open('woform.aspx?ca=' + ca + '&cmd=' + cmd + '&aoid=' + aoid, 'workframe');
		}
	}else{
		window.open('woform.aspx?ca=' + ca + '&cmd=' + cmd + '&aoid=' + aoid, 'workframe');
	}
}

function submitformdepchecklink(aoid, ca, cmd, msg){
	if(msg != ''){
		if(confirm(msg)){
			document.frmNew.action = "woform.aspx?cmd2=linkonly&ca=" + ca + "&cmd=" + cmd;
			document.frmNew.submit();
		}
	}else{
		document.frmNew.action = "woform.aspx?cmd2=linkonly&ca=" + ca + "&cmd=" + cmd;
		document.frmNew.submit();
	}
}

function switchtab(ca, aoid, tab){
    var tab = "_" & document.all['currtab'].value;
    document.all['tab'].style.className = ''; 
//woform.aspx?ca=" & ClientAccount & "&aoid=" & AOID & "&cmd=viewtab&cmd2=" & extra & "&tabotid=" & TabOTID & "
}

function submitformobjlink(ca, cmd){
	if(cmd != 'cancel' && cmd != 'view' && cmd != 'delete'){
		if(checksave(cmd)){
			document.all['frmNew'].action = "woform.aspx?cmd2=linkonly&ca=" + ca + "&cmd=" + cmd;
			document.all['frmNew'].submit();
		}
	}else{
		document.all['frmNew'].action = "woform.aspx?cmd2=linkonly&ca=" + ca + "&cmd=" + cmd;
		document.all['frmNew'].submit();
	}
}

function loadsubwinctm(loc){
	var w = 600;
	var h = 400;
	var leftVal = (screen.width / 2)  - 300;
    var topVal = (screen.height / 2)  - 200;

	var rn = Math.floor(Math.random()*100000);
	
	var currsw = 'subwin' + rn;
	window.open(loc,currsw,'menubar=no,resizable=yes,status=yes,width=' + w + ',height=' + h + ',top=' + topVal + ',left=' + leftVal);
	
//	if (window.showModalDialog) { 
//	    window.showModalDialog(loc, window, 'dialogHeight:' + h + 'px;dialogWidth:' + w + 'px;help:no;scroll:no;status:no;'); 
//	} else { 
//	    alert('This method is only supported by Internet Explorer 4 and above.') 
//	}
}

function deleteObjSrchDD(fldname, fldvalue){
    window.opener.delOption(fldname, fldvalue);
    window.close(); 
}

function updateObjSrchDD(fldname, fldtext, fldvalue, AOID, CA, OTID){
   window.opener.addOption(fldname, fldtext, fldvalue);
   window.close(); 
}

function delOption(fldname, fldvalue){
    var dd = document.getElementById(fldname);
   //alert(dd.length); 
    for (i=0; i < dd.length; i++){
   //alert(dd.options[i].value + ' = ' + fldvalue); 
        if (dd.options[i].value == fldvalue){
       //alert('got here'); 
            dd.options[i] = null;
            i = dd.length;
        } 
    }
}

function addOption(theField, theText, theValue)
{
	var theSel = document.getElementById(theField);
	var newOpt = new Option(theText, theValue);
	var selLength = theSel.length;
	theSel.options[selLength] = newOpt;
}

function capamt(_remamt, _amt){
    formatCurrency(document.all[_remamt], 0); 
    var remamt = document.all[_remamt].value;
    remamt = remamt.replace(',','');
   
    formatCurrency(document.all[_amt], 0); 
    var amt = document.all[_amt].value;
    amt = amt.replace(',','');
   
    if(amt > remamt){
        alert('The amount you entered is greater than what is available.  Please try again.');
        document.all[_amt].value = '0.000'; 
    }
   
    formatCurrency(document.all[_remamt], 1); 
    formatCurrency(document.all[_amt], 1);  
}

function cfld(fld){
    document.all[fld].value = '';
}

//blazarus start
function setremamt(){
    formatCurrency(document.all['depositamt'], 0); 
    var depamt = document.all['depositamt'].value;
    depamt = depamt.replace(',','');
   
    formatCurrency(document.all['amtapp'], 0); 
    var amtapp = document.all['amtapp'].value;
    amtapp = amtapp.replace(',','');
   
    var amtrem = depamt - amtapp;
    document.all['amtrem'].value = amtrem;
    formatCurrency(document.all['amtrem'], 1);   
   
    formatCurrency(document.all['depositamt'], 1);
    formatCurrency(document.all['amtapp'], 1); 
}

function verifyamt(){
    formatCurrency(document.all['amtrem'], 0); 
    var amtrem = document.all['amtrem'].value;
    amtrem = amtrem.replace(',','');
   
    formatCurrency(document.all['amt'], 0); 
    var amt = document.all['amt'].value;
    amt = amt.replace(',','');
   //alert(amt + " -- " + amtrem);
    if(parseFloat(amt) > parseFloat(amtrem)){
        alert('The amount you entered is greater than what is available.  Please try again.');
        document.all['amt'].value = '0.000'; 
    }
   
    formatCurrency(document.all['amtrem'], 1); 
    formatCurrency(document.all['amt'], 1);  
}

function verifyamtcap(capfld, fld){
    formatCurrency(document.all[capfld], 0); 
    var amtrem = document.all[capfld].value;
    amtrem = amtrem.replace(',','');
   
    formatCurrency(document.all[fld], 0); 
    var amt = document.all[fld].value;
    amt = amt.replace(',','');

    if(parseFloat(amt) > parseFloat(amtrem)){
        alert('The amount you entered is greater than what is available.  Please try again.');
        document.all[fld].value = '0.000'; 
    }
   
    formatCurrency(document.all[capfld], 1); 
    formatCurrency(document.all[fld], 1);  
}
