//<!-- Begin

function jsredir(r,w) {
        var warning = w;
        if (warning != "ok") {
                window.alert(warning);
                }
                window.location.href= r;
	}

var startList;
startList = function() {
if (document.all&&document.getElementById) {
navRoot = document.getElementById("topnavigation");
for (i=0; i<navRoot.childNodes.length; i++) {
node = navRoot.childNodes[i];
if (node.nodeName=="LI") {
node.onmouseover=function() {
this.className+=" over";
  }
  node.onmouseout=function() {
  this.className=this.className.replace(" over", "");
   }
   }
  }
 }
}
window.onload=startList;


function checkscript()
{
	for (i=1;i<7;i++)
	{
		box = document.posthandling.elements[i];
		if (!box.value)
		{
			alert('You haven\'t filled in ' + box.name + '!');
			box.focus()
			return false;
		}
	}
	return true;
}

// start validate add delivery
function validate() {
	var ddd, dmm, dyyyy, rdd, rmm, ryyyy, lot, pcode1, qty1, weight1,p1weight,packweight, isoc1;
	var l, p1, q1, w1, i1;
	var depot, refdate;
	var myboolean;
	var msg;
	var myfocus;
	msg = "";
	myboolean = true;
	myfocus = "title";
	rdd = document.posthandling.refnr_dd.value;
	rmm = document.posthandling.refnr_mm.value;
	ryyyy = document.posthandling.refnr_yyyy.value;
	ddd = document.posthandling.depot_dd.value;
	dmm = document.posthandling.depot_mm.value;
	dyyyy = document.posthandling.depot_yyyy.value;
	lot = document.posthandling.lotnr.value;
	packweight = document.posthandling.packweight.value;
	p1weight = document.posthandling.productweight_1.value;

	refdate = ryyyy + "/" + rmm +"/" + rdd;
	refdate = Date.parse(refdate);
	//alert(refdate);
	depot = dyyyy + "/" + dmm +"/" + ddd;
	depot = Date.parse(depot);
	//alert("ref.date: "+ refdate + "\n dep. date: "+ depot);
	if ((depot - refdate) > 0 == 0) {
		msg += "Depot date should be later than ref. date.";
	}

	l = document.posthandling.lotnr.value.length;
	p1 = document.posthandling.productcode_1.value.length;
	q1 = document.posthandling.qty_1.value.length;
	w1 = document.posthandling.productweight_1.value.length;
	isoc1 = document.posthandling.country_1.value.length;
	//window.alert('rdd: '+rdd+'\nrmm: '+rmm+'\nryyyy: '+ryyyy+'\nddd: '+ddd+'\ndmm'+dmm+'\ndyyyy: '+dyyyy+'\nlot: '+lot+'['+l+']'+'\np1: '+p1+'\nq1: '+q1+'\nw1: '+w1+'\nisoc1: '+isoc1);
	//alert("l: "+ rdd.length);
	

	if (ddd.length < 1) { msg = msg + "\nDepot date is required.";}
	if (rdd.length < 1) { msg = msg + "\nReference date is required.";}
	if (l < 6) { msg = msg + "\nLot number must contain 6 digits.";}
	if (p1 < 1) { msg = msg + "\nOne product code is required.";}
	if (q1 < 1) {msg = msg + "\nQuantity is required.";}
	if (w1 < 1) {msg = msg + "\nProvide poids unitaire.";}
	if (validateNumeric(p1weight) == false) {msg = msg + "\nPoids unitaire must be numeric.";}
	if (isoc1 < 2) {msg = msg + "\nPlease provide a country.";}
	if (validateNumeric(packweight) == false ) { 
		msg += "\n Packweight must be numeric."
	}

	if (validateNumeric(packweight) == false ) {
		document.posthandling.packweight.value = '';
		document.posthandling.packweight.style.background = '#FFFF33';
		document.posthandling.packweight.focus(); 
		}
	if (l < 1) {document.posthandling.lotnr.focus();}
	if (p1 < 1) {document.posthandling.productcode_1.focus();} 	
	if (q1 < 1) {document.posthandling.qty_1.focus();} 	
	if (w1 < 1) {document.posthandling.productweight_1.focus();}
	if (validateNumeric(p1weight) == false ) {
		document.posthandling.productweight_1.value = '';
		document.posthandling.productweight_1.style.background = '#FFFF33';
		document.posthandling.productweight_1.focus(); 
		}
	
	if (isoc1 < 1) {document.posthandling.country_1.focus();}
	
	if (msg != "") {
		myboolean = false;
		window.alert(msg);
	}
 	return myboolean;	
}	
//  end  validate add delivery


//  start add product validation
var validateproduct;
validateproduct = function() {
	var lname, weight,pcode,stockqty,pname,brand;
	var myboolean;
	var msg;
	var myfocus;
	var regex;
	regex = /^\d+$/;
	regex = /^\d+$/;
	msg = "";
	myboolean = true;
	myfocus = "lname";
	lname = document.addproduct.lname.value;
	weight = document.addproduct.weight.value;
	pcode = document.addproduct.pcode.value;
	stockqty = document.addproduct.stockqty.value;
	pname = document.addproduct.pname.value;
	brand = document.addproduct.brand.value;

	if (pcode.length < 1) { msg = msg + "\nA product code is required.";}
	if (weight.length < 1) { msg = msg + "\nWeight is required.";}
	if (lname.length < 1) { document.addproduct.lname.value=pcode;}
	if (pname.length < 1) { document.addproduct.pname.value=pcode;}
	if (stockqty.length < 1) { document.addproduct.stockqty.value=0;}

	if (regex.test(stockqty) == 0) {
		msg += "\nStock quantity should be a number";
	} 
	if (validateNumeric(weight) == 0) {
		msg += "\nWeight should be numeric.";
	} 	
	if (pcode.length < 1) {document.addproduct.pcode.focus();} 	
	if (weight.length < 1) {document.addproduct.weight.focus();}
	
	if (msg != "") {
		myboolean = false;
		window.alert(msg);
	}
 	return myboolean;	
}	
// end add product validation

function  validateNumeric( strValue ) {
/*****************************************************************
DESCRIPTION: Validates that a string contains only valid numbers.

PARAMETERS:
   strValue - String to be tested for validity

RETURNS:
   True if valid, otherwise false.
******************************************************************/
  var objRegExp  =  /(^-?\d\d*\.\d*$)|(^-?\d\d*$)|(^-?\.\d\d*$)/;

  //check for numeric characters
  return objRegExp.test(strValue);
}

function requireValue(fld)
{ // disallow a blank field
  if(fld.disabled) return true;
  if(!fld.value.length)
  { status= 'The '+fieldname(fld)+' field cannot be left blank.'; return false; }
  return true;
}
var deselectallboxes;
deselectallboxes = function ()
{
var i;
var j;
	for(i = 0; i < document.forms.length; i++)
	{
		for (j = 0; j < document.forms[i].elements.length; j++)
		{
			if(document.forms[i].elements[j].type == "checkbox")
			{
				document.forms[i].elements[j].checked = false;
			}
		}
	}
}

var selectallboxes;
selectallboxes = function ()
{
var i;
var j;
	for(i = 0; i < document.forms.length; i++)
	{
		for (j = 0; j < document.forms[i].elements.length; j++)
		{
			if(document.forms[i].elements[j].type == "checkbox")
			{
				document.forms[i].elements[j].checked = true;
			}
		}
	}
}

var userfunc;
userfunc = function ()
{
var i;
var j;
var msg;
msg = ""
	for(i = 0; i < document.forms.length; i++)
	{
		for (j = 0; j < document.forms[i].elements.length; j++)
		{
			if (document.forms[i].elements[j].name ) {
				msg += "\n" + document.forms[i].elements[j].name + ": "+ document.forms[i].elements[j].value;
				if ( document.forms[i].elements[j].value.indexOf('script') >= 0 ) {
					jsredir('page.asp?content=login','acces denied');
				}
			}
		}
	}
	//alert(msg);
}

//  End -->
