function popUp(strURL,strType,strHeight,strWidth) {
var strOptions="";
if (strType=="console") strOptions="resizable,height="+strHeight+",width="+strWidth;
if (strType=="fixed") strOptions="status,height="+strHeight+",width="+strWidth;
if (strType=="elastic") strOptions="toolbar,menubar,scrollbars,resizable,location,height="+strHeight+",width="+strWidth;
window.open(strURL, 'newWin', strOptions);
}

function iPop(id,w,h,n)
{
	iPopURL = 'popup-pic.php' // set as location of ipop
	url = iPopURL + '?' + 'item=' + id + '&' + 'n=' + n
	//l = (screen.width-w)/4
	//t = (screen.height-h)/4
	attribs = 'width='+w+',height='+h+',left=40,top=40'
	open(url,'imgWin',attribs)
	return false;
}

function Dollar (val) 	// force to valid dollar amount
{  
var str,pos,rnd=0;
  if (val < .995) rnd = 1;  // for old Netscape browsers
  str = escape (val*1.0 + 0.005001 + rnd);  // float, round, escape
  pos = str.indexOf (".");
  if (pos > 0) str = str.substring (rnd, pos + 3);
  return str;
}

function ReadForm (obj1) 		// process un-named selects
{ 
var i,amt,des,obj,pos,val,num="";
  amt = obj1.baseamt.value*1.0;       // base amount
  des = obj1.basedes.value;           // base description
  for (i=0; i<obj1.length; i++) {     // run entire form
    obj = obj1.elements[i];           // a form element
    if (obj.type == "select-one" &&   // just get selects
        obj.name == "") {             // must be un-named
      pos = obj.selectedIndex;        // which option selected
      val = obj.options[pos].value;   // selected value
      pos  = val.indexOf ("@");       // price set?
      if (pos >= 0) amt = val.substring (pos + 1)*1.0;
      pos  = val.indexOf ("+");       // price increment?
      if (pos >= 0) amt = amt + val.substring (pos + 1)*1.0;
      pos  = val.indexOf ("%");       // percent change?
      if (pos >= 0) amt = amt + (amt * val.substring (pos + 1)/100.0);
      pos  = val.indexOf ("#");       // item number?
      if (pos > 0) {                  //  yes
        num = val.substring (pos + 1);// get number, and rest of line
        val = val.substring (0, pos); // lop off some stuff
        pos = num.indexOf (" ");      // end it with space
        if (pos > 0) num = num.substring (0, pos);
      }
      if (des.length == 0) des = val;
      else des = des + ", " + val;    // accumulate value
    }
  }
  if (obj1.item_number && num.length > 0) obj1.item_number.value = num;
  obj1.item_name.value = des;
  obj1.amount.value = Dollar (amt);
  if (obj1.tot) obj1.tot.value = "$" + Dollar (amt);
}


var submitcount=0;
function checkSubmit() {

   if (submitcount == 0)
   {
   submitcount++;
   document.Surv.submit();
   }
}


function wordCounter(field, countfield, maxlimit) {
wordcounter=0;
for (x=0;x<field.value.length;x++) {
      if (field.value.charAt(x) == " " && field.value.charAt(x-1) != " ")  {wordcounter++}  
	// Counts the spaces while ignoring double spaces, usually one in between each word.
	      	if (wordcounter > 50000) {
				field.value = field.value.substring(0, x);
		  	} else {
			  	//countfield.value = maxlimit - wordcounter;
				countfield.value = wordcounter;
			}
      }
}

// this only really works with table rows right now, but you could make one for divs
// based on http://www.dustindiaz.com/dhtml-expand-and-collapse-div-menu/
function switchTableRow(obj) {
	var el = document.getElementById(obj);

	if ( el.style.display == 'table-row' ) {
		el.style.display = 'none';
	}
	else {
		el.style.display = 'table-row';
	}
}

