// find out what DOM to use

if (document.getElementById)
{
	DOMtype = "std";
}
else if (document.all)
{
	DOMtype = "ie4";
}
else if (document.layers)
{
	DOMtype = "ns4";
}


function grabobj(objname) // v1.0
{
var ret = null;
	switch (DOMtype)
	{
		case "std":
		{
			ret = document.getElementById(objname);
		}
		break;

		case "ie4":
		{
			ret = document.all[objname];
		}
		break;
		case "ns4":
		{
			ret = document.layers[objname];
		}
		break;
	}
return ret;
}

function addrows ()
{
var currentrows=grabobj("totalnum").value;

for (i=1;i<8;i++)
{
	currentrows++;
  var tbl = grabobj("tableform");
  var lastRow = tbl.rows.length;
  var iteration = lastRow;
  var row2 = tbl.insertRow(lastRow);
  var row = tbl.insertRow(lastRow+1);
  
  
if (i==1)
{
  var cellRight = row.insertCell(0);
  cellRight.setAttribute("id", "firstb"+currentrows);
  cellRight.setAttribute("class", "blacksmall viewordbordright");
  cellRight.setAttribute("className", "blacksmall viewordbordright");
  cellRight = row.insertCell(1);
  cellRight.setAttribute("id", "desc"+currentrows);
  cellRight.setAttribute("class", "blacksmall viewordbordright");
  cellRight.setAttribute("className", "blacksmall viewordbordright");
  var cellRight = row.insertCell(2);
  cellRight.setAttribute("id", "siz"+currentrows);
  cellRight.setAttribute("class", "blacksmall viewordbordright");
  cellRight.setAttribute("className", "blacksmall viewordbordright");
  var cellRight = row.insertCell(3);
  cellRight.setAttribute("id", "col"+currentrows);
  cellRight.setAttribute("class", "blacksmall viewordbordright");
  cellRight.setAttribute("className", "blacksmall viewordbordright");
  var cellRight = row.insertCell(4);
  cellRight.setAttribute("id", "qty"+currentrows);
  cellRight.setAttribute("class", "blacksmall");
  cellRight.setAttribute("className", "blacksmall");
  var cellRight = row.insertCell(5); 
} else {
 if (i==8)
 {
  var cellRight = row.insertCell(0);
  cellRight.setAttribute("id", "firstb"+currentrows);
  cellRight.setAttribute("class", "blacksmall viewordbordtop viewordbordbot viewordbordright");
  cellRight.setAttribute("className", "blacksmall viewordbordtop viewordbordbot viewordbordright");
  cellRight = row.insertCell(1);
  cellRight.setAttribute("id", "desc"+currentrows);
  cellRight.setAttribute("class", "blacksmall viewordbordtop viewordbordbot viewordbordright");
  cellRight.setAttribute("className", "blacksmall viewordbordtop viewordbordbot viewordbordright");
  var cellRight = row.insertCell(2);
  cellRight.setAttribute("id", "siz"+currentrows);
  cellRight.setAttribute("class", "blacksmall viewordbordtop viewordbordbot viewordbordright");
  cellRight.setAttribute("className", "blacksmall viewordbordtop viewordbordbot viewordbordright");
  var cellRight = row.insertCell(3);
  cellRight.setAttribute("id", "col"+currentrows);
  cellRight.setAttribute("class", "blacksmall viewordbordtop viewordbordbot viewordbordright");
  cellRight.setAttribute("className", "blacksmall viewordbordtop viewordbordbot viewordbordright");
  var cellRight = row.insertCell(4);
  cellRight.setAttribute("id", "qty"+currentrows);
  cellRight.setAttribute("class", "blacksmall viewordbordtop viewordbordbot");
  cellRight.setAttribute("className", "blacksmall viewordbordtop viewordbordbot");
  var cellRight = row.insertCell(5);
 } else {
  var cellRight = row.insertCell(0);
  cellRight.setAttribute("id", "firstb"+currentrows);
  cellRight.setAttribute("class", "blacksmall viewordbordtop viewordbordright");
  cellRight.setAttribute("className", "blacksmall viewordbordtop viewordbordright");
  cellRight = row.insertCell(1);
  cellRight.setAttribute("id", "desc"+currentrows);
  cellRight.setAttribute("class", "blacksmall viewordbordtop viewordbordright");
  cellRight.setAttribute("className", "blacksmall viewordbordtop viewordbordright");
  var cellRight = row.insertCell(2);
  cellRight.setAttribute("id", "siz"+currentrows);
  cellRight.setAttribute("class", "blacksmall viewordbordtop viewordbordright");
  cellRight.setAttribute("className", "blacksmall viewordbordtop viewordbordright");
  var cellRight = row.insertCell(3);
  cellRight.setAttribute("id", "col"+currentrows);
  cellRight.setAttribute("class", "blacksmall viewordbordtop viewordbordright");
  cellRight.setAttribute("className", "blacksmall viewordbordtop viewordbordright");
  var cellRight = row.insertCell(4);
  cellRight.setAttribute("id", "qty"+currentrows);
  cellRight.setAttribute("class", "blacksmall viewordbordtop");
  cellRight.setAttribute("className", "blacksmall viewordbordtop");
  var cellRight = row.insertCell(5);
 }
}

  grabobj("firstb"+currentrows).innerHTML = "<input type=\"text\" name=\"pno"+currentrows+"\" class=\"lightformbox\" autoComplete=\"off\" onChange=\"MM_goToURL('topFrame','/csp/smp/'+appname+'/quickprocess.csp?Action=GetSize&OrderNo="+currentrows+"&ProdNo=' + this.value)\" onKeyPress=\"return handleEnter(this, event)\" size=\"15\"> <input type=\"button\" name=\"Go"+currentrows+"\" value=\"GO\" class=\"go\" onClick=\"return handleEnter(this, event)\">";
  grabobj("desc"+currentrows).innerHTML = "<div id=\"desc"+currentrows+"\">&nbsp;</div>";
  grabobj("siz"+currentrows).innerHTML = "<div id=\"size"+currentrows+"\">&nbsp;</div>";  
  grabobj("col"+currentrows).innerHTML = "<div id=\"col"+currentrows+"\">&nbsp;</div>";
  grabobj("qty"+currentrows).innerHTML = "<input type=\"text\" class=\"lightformbox\" name='Stno"+currentrows+"' size=\"3\" value=\"0\" onChange=\"MM_goToURL('topFrame','/csp/smp/'+appname+'/quickprocess.csp?Action=ChangeQty&OrderNo="+currentrows+"&ProdNo=' + this.value)\" onKeyPress=\"return handleEnter(this, event)\">";
}
grabobj("totalnum").value = currentrows;
}

function init()
{ var derr = '#($G(%session.Data("FormError")))#';
  if (derr !== "") alert(derr);
}
  if (document.getElementsByTagName) {
    var inputElements = document.getElementsByTagName("input");
    for (i=0; inputElements[i]; i++) {
      if (inputElements[i].className && (inputElements[i].className.indexOf("disableAutoComplete") != -1)) {
        inputElements[i].setAttribute("autocomplete","off");
      }//if current input element has the disableAutoComplete class set.
    }//loop thru input elements
  }//basic DOM-happiness-check

var lastColObj='';
function checkAvail(obj){
 lastColObj=obj;
 var tval=obj.options[obj.selectedIndex].value;
 if (tval.substr(0,1)=="*")
 {
	 //	03-07-09; LJB; Attempt to get around issue with BT browser
	if (validajax==true)
	{
		outofstock(tval.split(":")[1],tval.split(":")[2]);
		obj.blur();
		
	} else {
		MM_goToURL('topFrame', '/stockmessage/?STNO='+tval.split(":")[1]+'&type='+tval.split(":")[2]+'&fastorder='+fastorder);
		update = window.setTimeout('displayBox("stock",unescape(self.window[1].document.body.innerHTML)); ',200);
	}
 }
}

function handleEnter (field, event){
	var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
	if (keyCode == 13) {
		var i;
		for (i = 0; i < field.form.elements.length; i++)
			if (field == field.form.elements[i])
				break;
		i = (i + 1) % field.form.elements.length;
		field.form.elements[i].focus();
		return false;
	}
	else
	return true;
}

function MM_findObj(n, d) { //v4.0
  var p,i,x;
  if(!d) d=document;
  if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document;
	n=n.substring(0,p);
  }
  if(!(x=d[n])&&d.all) {
    x=d.all[n];
  }
  for (i=0;!x&&i<d.forms.length;i++) {
    x=d.forms[i][n];
  }
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) {
    x=MM_findObj(n,d.layers[i].document);
  }
  if(!x && document.getElementById) {
    x=document.getElementById(n);
  }
  return x;
}

function MM_validateForm() { //v4.0
  var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
  for (i=0; i<(args.length-2); i+=3) {
    test=args[i+2];
	val=MM_findObj(args[i]);
    if (val) {
	  nm=val.name;
	  if ((val=val.value)!="") {
        if (test.indexOf('isNum')!=-1) {
          if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
	    }
	  }
	  else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n';
	}
  }
  
  if (document.form1.size1 != null) {
    if (document.form1.size1.options[document.form1.size1.selectedIndex].value==""){
	  errors += '- Size selection for ' + document.form1.pno1.value + ' is required.\n';
	}
  }
  if (document.form1.col1 != null) {
    if (document.form1.col1.options[document.form1.col1.selectedIndex].value==""){
	  errors += '- Colour selection for ' + document.form1.pno1.value + ' is required.\n';
	}
  }
  if (document.form1.size2 != null) {
    if (document.form1.size2.options[document.form1.size2.selectedIndex].value==""){
	  errors += '- Size selection for ' + document.form1.pno2.value + ' is required.\n';
	}
  }
  if (document.form1.col2 != null) {
    if (document.form1.col2.options[document.form1.col2.selectedIndex].value==""){
	  errors += '- Colour selection for ' + document.form1.pno2.value + ' is required.\n';
	}
  }
  if (document.form1.size3 != null) {
    if (document.form1.size3.options[document.form1.size3.selectedIndex].value==""){
	  errors += '- Size selection for ' + document.form1.pno3.value + ' is required.\n';
	}
  }
  if (document.form1.col3 != null) {
    if (document.form1.col3.options[document.form1.col3.selectedIndex].value==""){
	  errors += '- Colour selection for ' + document.form1.pno3.value + ' is required.\n';
	}
  }
  if (document.form1.size4 != null) {
    if (document.form1.size4.options[document.form1.size4.selectedIndex].value==""){
	  errors += '- Size selection for ' + document.form1.pno4.value + ' is required.\n';
	}
  }
  if (document.form1.col4 != null) {
    if (document.form1.col4.options[document.form1.col4.selectedIndex].value==""){
	  errors += '- Colour selection for ' + document.form1.pno4.value + ' is required.\n';
	}
  }
  if (document.form1.size5 != null) {
    if (document.form1.size5.options[document.form1.size5.selectedIndex].value==""){
	  errors += '- Size selection for ' + document.form1.pno5.value + ' is required.\n';
	}
  }
  if (document.form1.col5 != null) {
    if (document.form1.col5.options[document.form1.col5.selectedIndex].value==""){
	  errors += '- Colour selection for ' + document.form1.pno5.value + ' is required.\n';
	}
  }
  if (document.form1.size6 != null) {
    if (document.form1.size6.options[document.form1.size6.selectedIndex].value==""){
	  errors += '- Size selection for ' + document.form1.pno6.value + ' is required.\n';
	}
  }
  if (document.form1.col6 != null) {
    if (document.form1.col6.options[document.form1.col6.selectedIndex].value==""){
	  errors += '- Colour selection for ' + document.form1.pno6.value + ' is required.\n';
	}
  }
  if (document.form1.size7 != null) {
    if (document.form1.size7.options[document.form1.size7.selectedIndex].value==""){
	  errors += '- Size selection for ' + document.form1.pno7.value + ' is required.\n';
	}
  }
  if (document.form1.col7 != null) {
    if (document.form1.col7.options[document.form1.col7.selectedIndex].value==""){
	  errors += '- Colour selection for ' + document.form1.pno7.value + ' is required.\n';
	}
  }
  if (document.form1.size8 != null) {
    if (document.form1.size8.options[document.form1.size8.selectedIndex].value==""){
	  errors += '- Size selection for ' + document.form1.pno8.value + ' is required.\n';
	}
  }
  if (document.form1.col8 != null) {
    if (document.form1.col8.options[document.form1.col8.selectedIndex].value==""){
	  errors += '- Colour selection for ' + document.form1.pno8.value + ' is required.\n';
	}
  }
  
  //for (i=1; i<11; i+=1) {
   // checkSelect(i);
  //}

  if (errors)
  {alert('The following error(s) occurred:\n'+errors);
  document.MM_returnValue = (errors == '');}
  else{
  document.form1.action='/csp/smp/'+appname+'/quickadd.csp?checked=3';
  document.form1.target='';
  document.form1.submit();}
}

function MM_goToURL() { //v3.0
  var i, args=MM_goToURL.arguments; document.MM_returnValue = false;
  for (i=0; i<(args.length-1); i+=2) eval(args[i]+".location='"+args[i+1]+"'");
}

//function checkSelect(no) {
  //eval('if (document.form1.size' + no + ' != null) { if (document.form1.size' + no + '.options[document.form1.size' + no + '.selectedIndex].value=="") { errors += \'- Size ' + no + ' is required.\n\'; } }');
//}