function CheckParameters() {
  var success = false;

  if (document.getElementById("action_type").value == "clear") {
  	return(true);
  }

  success = (
    (document.getElementById("cat_keywords").value != "") ||
		(document.getElementById("cat_vendorcode").value != "_NULL_") ||
		(document.getElementById("cat_node_code").value != "") ||
		((document.getElementById("cat_estcat_code").value != "_NULL_") &
		 (document.getElementById("cat_estcat_page").value > 1)
		)
  );
  
  if (!success) {
		alert(document.getElementById("label_req").value);
		return(false);
	}
  return(true);
}

function SetActionPrices() {
	var el = document.getElementById("cat_showprices");
	if (el != null) {
	  var el2 = document.getElementById("cat_actprices");
	  if (el2 != null) {
		  if ((el2.checked) & (!el.checked)) {
		    el2.checked = false;
			  alert(document.getElementById("cat_actprices_error").value);
		  }
	  }
	 }
}

function ClearActPrices() {
  var el=document.getElementById("cat_actprices");
	if (el != null) {
		el.checked = false;
	}
}

function DoSubmit(action) {
	var el;
  el = document.getElementById("action_type");
  el.value = action;
	if (CheckParameters()) {
	  document.f_cat_criteria.submit();
	}
}
  
  
  
  
function CheckElement(el) {
  var i;

  for (i=0;i<el.length;i++) {
    if (el[i].getAttribute("cne") != null) {
      if (el[i].value == "")  {
        alert(document.getElementById("cne_label").value);
        el[i].focus();
        return (false);
      }
    }

    if (el[i].getAttribute("mlen") != null) {
      var l;
      l = el[i].getAttribute("mlen");
      if (el[i].value.length < l) {
        alert(document.getElementById("mlen_label").value + " " + l);
        el[i].focus();
        return(false);
      }
    }

    if (el[i].getAttribute("nneg") != null) {
      var isinteger, ispositive;
      isinteger = ((el[i].value % 1) == 0);
      if (isinteger) {
        ispositive = (el[i].value >= 0);
      }
      if (!ispositive) {
        alert(document.getElementById("nneg_label").value);
        el[i].focus();
        return(false);
      }
    }

    if (el[i].getAttribute("gtzero") != null) {
      var isinteger, ispositive;
      isinteger = ((el[i].value % 1) == 0);
      if (isinteger) {
        ispositive = (el[i].value > 0);
      }
      if (!ispositive) {
        alert(document.getElementById("gtzero_label").value);
        el[i].focus();
        return(false);
      }
    }
  }
  return (true);
}

function GoToBackPage(form_obj, page_addr) {
  form_obj.action = page_addr;
  form_obj.submit();
}

function InsertElement(strTagName, strElementID, strElementValue, strAttributes, objParent) {

	var objElement;
	if (strTagName.toLowerCase() == "option") {
		objElement = new Option();
		objElement.id = strElementID;
		objElement.value = strElementValue;
		objElement.text = strAttributes;

    objParent.options.add(objElement);
	  return true;
	}	else {
		objElement = document.createElement(strTagName);
	}

	objElement.id = strElementID;
	objElement.name = strElementID;
	objElement.value = strElementValue;

	var arrAttributes=strAttributes.split(",");
	for (var i=0; i<arrAttributes.length; i++) {
		var curAttribute=arrAttributes[i];
		if (curAttribute.length > 0) {
			var arrAttParts=curAttribute.split("=");
			if (arrAttParts.length < 2)
				arrAttParts[arrAttParts.length]="1";
			objElement.attributes.setNamedItem(MakeAttribute(arrAttParts[0], arrAttParts[1]));
		}
	}

	objParent.appendChild(objElement);

	return true;
}

function MakeAttribute(attName, attValue) {
	var objAttribute=document.createAttribute(attName);
	objAttribute.value = attValue;
	return objAttribute;
}


function Check_Password(el) {
  if (!CheckElement(el)) {
    return (false);
  }
  if (el.chgpswd_value2.value != el.chgpswd_value1.value) {
    alert(el.mismatch.value);
    return (false);
  }
  return (true);
}

