// popup window
var win = null;


// popup window

function popup(mypage,myname,w,h,scroll)
{
	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 = yes'
	win = window.open(mypage,myname,settings)
}

function popupLarge(mypage,myname,w,h,scroll,resize)
{
	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='+resize
	win = window.open(mypage,myname,settings)
}


function isNumeric(str)
{
    var numeric = true;
    str = str.replace(/[0-9]/g,'');
    if(str.length != 0)
        numeric = false;
    return numeric;
}

// Check for INTEGER
function isInteger(obj) 
 {
	value=obj.value;
  if(isNaN(value)) 
  {
   alert("Please enter Integer value for "+obj.id)
   obj.select();
   return false;
  }

  if(value.split('.').length > 1) 
  { 
   alert("Please enter Integer value for "+obj.id)
   obj.select();
   return false;
  }
  return true;
 }
 
function doSelectAll(source, destination){

  if(destination.length == null){
	  destination.checked = source.checked;
  }
  else{
	for(var i=0; i< destination.length; i++)
		destination[i].checked = source.checked;
  }

}


function changeBtnClass()
{
	var form = document.forms[0];
	var obj;
	for(i=0; i<form.length; i++)
	{
		obj = form.elements[i];
		if((obj.type=='button')&&(obj.disabled==true))
		{
			obj.className='disabledPageActionButton'
		}
		if((obj.type=='button')&&(obj.disabled==false))
		{
			obj.className='pageActionButton'
		}
	}
}

function validateEmailAddr(x)
{
	
	var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	if (filter.test(x)) return true;
	else {
		alert("Please enter valid Email Address");
		return false;
	}
}

function addRowToTable(){	
 	
	var tbl = document.getElementById('dynamictab');
	var lastRow = tbl.rows.length;
	  // if there's no header row in the table, then iteration = lastRow + 1
	var iteration = lastRow;
	var row = tbl.insertRow(lastRow);

	var cellh1 = row.insertCell(0);
	var hl = document.createElement('input');
	hl.type = 'hidden';
	hl.name = 'hid1' + iteration;
	hl.id = 'hid1' + iteration;
	//h1.size=5;
	cellh1.appendChild(hl);
	
	// Check Box cell
	var cellLeft = row.insertCell(1);
	var chkbox = document.createElement('input');
	chkbox.type='checkbox';
	chkbox.name='adcheck'+iteration;
	chkbox.value='1';
	chkbox.size = 5;					
	cellLeft.appendChild(chkbox);
					
    var cellh2 = row.insertCell(2);
	var h2 = document.createElement('input');
  	h2.type = 'hidden';
  	h2.name = 'hid2' + iteration;
  	h2.id = 'hid2' + iteration;
  	//h2.size=5;
	cellh2.appendChild(h2);
 
	 // Tool Name cell
	 var cellToolName = row.insertCell(3);
	 var el = document.createElement('input');
	 el.type = 'text';
	 el.name = 'adtoolName'+iteration;
	 el.id = 'adtoolName';
	 el.size = 25;
	 cellToolName.appendChild(el);
				 
	  // Tool Quantity cell
	 var cellQuantity = row.insertCell(4);
	 var e2 = document.createElement('input');
	 e2.type = 'text';
	 e2.name = 'adquantity'+iteration;
	 e2.id = 'adquantity';
	 e2.size = 10;
	  cellQuantity.appendChild(e2);
 
	 // Tool Notes Cell
	 var cellNotes = row.insertCell(5);
	 var e3 = document.createElement('input');
	 e3.type = 'text';
	 e3.name = 'adnotes'+iteration;
	 e3.id = 'adnotes';
	 e3.size = 40;					 
	 cellNotes.appendChild(e3);
}
				