
// Check Validity of the Order Quantity

function chkqty_ord(form)
{
if	(!(form.qty_ord.value > 0) )
	{

	alert('Invalid Order Quantity - Please Re-Enter');
	form.qty_ord.value = 1
	return false;
	}
else if (form.ord_avail.value == 'N')
	{
	alert('This Product Is Not Available - Please Select An Alternative');
	return false;
	}
else if ((form.qty_ord.value > 10) && (form.qty_type.checked || form.qty_type[0].checked))
	{
	if (confirm('Case quantity is greater than 10 - Please confirm that you wish to order this amount'))
		{
		var win = window.open("","baskwin","width=525,height=150,status=no,resizeable=no,top=10,left=10");
		win.focus();
		form.target = "baskwin";
		return true;
		}
	else
		{
		form.qty_ord.value = 1
		return false;
		}
	}
else if ((form.qty_ord.value > 0) && (form.qty_type[1]) && (form.qty_type[1].checked) && (form.con_split_ind.value == 'N'))
	{
	alert('You Cannot Purchase Units Of This Product');
	return false;
	}
else
	{
	var win = window.open("","baskwin","width=525,height=150,status=no,resizeable=no,top=10,left=10");
	win.focus();
	form.target = "baskwin";
	return true;
	}
}

// Get Information


function getinfo(form)
{

var		msgtext = '';
var     i = 0;

for (i=0;i<form.elements.length;i++)

	{
	msgtext +=  "\n" + i + "(" + form.elements[i].type + ")" + form.elements[i].name + "=" + form.elements[i].value;
	}

alert (msgtext);

return false;
}


// Check validity of the Amended Order Quantity

function chkqty_new(form)
{
if (form.c_qty_ord.value > 0)
	if	(!(form.c_qty_new.value >= 0) )
		{
		alert('Invalid Order Quantity - Please Re-Enter');
		form.c_qty_new.value = form.c_qty_new.defaultValue
		return false;
		}
	else if (form.c_qty_new.value > 10)
		{
		if (confirm('Case quantity is greater than 10 - Please confirm that you wish to order this amount'))
			{
			return true;
			}
		else
			{
			form.c_qty_new.value = form.c_qty_new.defaultValue
			return false;
			}
		}
	else 
		{
		return true;
		}
else
	if	(!(form.u_qty_new.value >= 0) )
		{
		alert('Invalid Order Quantity - Please Re-Enter');
		form.u_qty_new.value = form.u_qty_new.defaultValue
		return false;
		}
	else 
		{
		return true;
		}
}

// Check validity of the entered search words

function chksearch_words(form)
{
if (form.search_words.value == '') 
	{
	alert('Search is all spaces');
	return false;
	}
else if (form.search_words.value.length <= 2)
	{
	alert('Invalid search - enter more than 2 characters');
	return false;
	}
else
	{
	return true;
	}
}

// Check validity of the entered key word

function chkart_key(form)
{
if (form.art_key.value == '') 
	{
	alert('Product Code is all spaces');
	return false;
	}
else
	{
	return true;
	}
}


// Check validity of the entered key word

function chkart_search(form)
{
if (form.art_search.value == '') 
	{
	alert('Entered Code  is all spaces');
	return false;
	}
else
	{
	return true;
	}
}

// Check Validity of the Account Number

function chkcuf_appl_no(form)
{
if	(!(form.cuf_appl_no.value > 0) )
	{
	alert("Invalid Account Number - Please Re-Enter");
	return false;
	}
else 
	{
	return true;
	}
}

// Check Validity of the Customer Id

function chkcuf_id(form)
{
if	(form.cuf_id.value.length <= 6)
	{
	alert('Login Name must be greater than 6 characters');
	return false;
	}


pattarr = form.cuf_id.value.match (/\D/);

if (pattarr == null)
	{
	alert('Login Id must contain at least 1 alpha character')
	return false;
	} 

	return true;

}

// Check Validity of the Customer Password

function chkcuf_passwd(form)
{
if	(form.cuf_passwd.value.length <= 6)
	{
	alert('Customer Password must be greater than 6 characters');
	return false;
	}

if (form.cuf_passwd.value == form.cuf_id.value)
	{
	alert('Customer Password must be not the same as the Login Name');
	return false;
	}

pattarr = form.cuf_passwd.value.match (/\D/);

if (pattarr == null)
	{
	alert('Password must contain at least 1 alpha character')
	return false;
	} 

pattarr = form.cuf_passwd.value.match (/\d/);

if (pattarr == null)
	{
	alert('Password must contain at least 1 numeric character')
	return false;
	} 

return true;

}

// Check Second Entry of the Customer Password

function chkcuf_passwd_2(form)
{
if	(form.cuf_passwd.value != form.cuf_passwd_2.value)
	{
	alert('The two entries for Password do not match - Please Re-Enter');
	return false;
	}
else
	{
	return true;
	}
}

function closedet() 
{
	// Close the popup window. 
	// 1st line stops crash in IE3 if the user has already closed the window themselves. 
    detWindow=window.open('','windet','width=500,height=300,scrollbars,top=80,left=80');
	detWindow.close();
}

function closealt() 
{
	// Close the popup window. 
	// 1st line stops crash in IE3 if the user has already closed the window themselves. 
	altWindow=window.open('','winalt','width=800,height=500,scrollbars,top=1,left=1');
	altWindow.close();
}

// Check Basket Empty

function chkempty_basket(form)
{
if (confirm('Please Confirm That You Wish To Empty The Basket'))
	{
	return true;
	}
else
	{
	return false;
	}
}

// Check Validity of the Order Quantity On Temporary Repeat Order

function chkqty_temp(form)
{
if	(!(form.qty_ord.value >= 0) )
	{

	alert('Invalid Order Quantity - Please Re-Enter');
	{
	if (form.qty_type.checked || form.qty_type[0].checked)
		{
		form.qty_ord.value = form.c_qty_ord.value
		}
	else
		{
		form.qty_ord.value = form.u_qty_ord.value
		}
	}
	return false;
	}
else if ((form.qty_ord.value > 10) && (form.qty_type.checked || form.qty_type[0].checked))
	{
	if (confirm('Case quantity is greater than 10 - Please confirm that you wish to order this amount'))
		{
		return true;
		}
	else
		{
		form.qty_ord.value = form.c_qty_ord.value
		return false;
		}
	}
else if (form.ord_avail.value == 'N')
	{
	alert('This Product Is Not Available - Please Select An Alternative');
	{
	if (form.qty_type.checked || form.qty_type[0].checked)
		{
		form.qty_ord.value = form.c_qty_ord.value
		}
	else
		{
		form.qty_ord.value = form.u_qty_ord.value
		}
	}
	return false;
	}
else if ((form.qty_ord.value > 0) && (form.qty_type[1]) && (form.qty_type[1].checked) && (form.con_split_ind.value == 'N'))
	{
	alert('You Cannot Purchase Units Of This Product');
	return false;
	}
else 
	{
	return true;
	}
}
function conf_reg()
{
termwin = window.open ('//ultra1/dbc/design/terms.htm','makeNewWindow','height=300,width=900,resizable=yes,top=1,left=1');
termwin.focus;
var msg = "Please Indicate your acceptance of these terms by clicking the OK button";
if (termwin.confirm(msg))
    {
	termwin.close();
	return true;
	}
else
	{
	termwin.close();
	return false;
	}
}
// Check for product alread in basket

function ChkInBasket(form)
{
if  (form.ib_flag.value == 'Y') 
	{
	alert ('This product is already in your basket.');
	return false;
	}
else
	{
	return true;
	}
}
// Check customer reference

function ChkOrdRef(form)
{
if ((form.ord_ref_ind.value > 0) && (form.cu_ord_no.value == '')) 
	{
	alert('Order reference required');
	return false;
	}
else
	{
	return true;
	}
}
// Check validity of the Query contact

function chkqry_contact(form)
{
if (form.qry_contact.value == '') 
	{
	alert('Please provide a contact name');
	return false;
	}
else
	{
	return true;
	}
}

// Check for contract item out of stock

function ChkContract(form)
{
if (form.ord_avail.value == 'C' && form.qty_ord.value > 0)
	{
	alert('Contract Item Out Of Stock');
	if (confirm('Please Confirm If You Require DBC To Supply An Approved Alternative'))
		{
		return true;
		}
	else
		{
		return false;
		}
	}
else
	{
	return true;
	}
}

// Resets null images on the order form

function reset_null(form)
{
for (i=0;i<document.images.length;i++)
	{
	var iname = document.images[i].name;
	if (iname.substr(0,7) == 'warning')
		{
		document.images[i].src = '../design/images/null.gif';
		}
	}
	return true;
}

// Check for contract item out of stock when Submit is clicked

function ChkSubmit(OrdAvail)
{
if (OrdAvail == 'C')
	{
	alert('Contract Item(s) Out Of Stock');
	if (confirm('Please Confirm If You Require DBC To Supply Approved Alternative(s)'))
		{
		return true;
		}
	else
		{
		return false;
		}
	}
else
	{
	return true;
	}
}

// Show non-availability reason

function AvailDesc(OrdAvail)
{
if	(OrdAvail == 'N')
	{
	alert("This product is generally not available.");
	}
else if	(OrdAvail == 'R')
	{
	alert("The product is not within the range of products which you can purchase.");
	}
else if	(OrdAvail == 'T')
	{
	alert("This type of product cannot be included in this order.");
	}
else if	(OrdAvail == 'B')
	{
	alert("This is a branded product. You are unable to purchase products of this brand.");
	}
else if	(OrdAvail == 'P')
	{
	alert("This is a price marked product. You have indicated you will not accept price marked products.");
	}
else if	(OrdAvail == 'F')
	{
	alert("This is a frozen item. Frozen items cannot be included in this order.");
	}
else 
	{
	alert("The reason you cannot purchase this product has not been identified.");
	}
}

// Check for frozen hub-supplied item 

function ChkFHS(form)
{
if (form.fhs_ind.value > 0)
	{
	if (confirm('This item is on a 48 hour lead time. If you press OK it will be added to your basket and you will be offered a later delivery date for the whole order. If you press Cancel, it will not be added to your basket for this order, but you can raise it on a separate order for a later date.'))
		{
		return true;
		}
	else
		{
		return false;
		}
	}
else
	{
	return true;
	}
}

