function dumfunc (form)
{
alert("Hi there");
return true;
}
//*****************************************************
//*****************************************************
function getCookie (name) 
{
var dc = document.cookie;
var cname = name + "=";
var clen = dc.length;
var cbegin = 0;

while (cbegin < clen) { 
var vbegin = cbegin + cname.length;

if (dc.substring(cbegin, vbegin) == cname) { 
var vend = dc.indexOf (";", vbegin);
if (vend == -1) vend = clen;

return unescape(dc.substring(vbegin, vend));
}

cbegin = dc.indexOf(" ", cbegin) + 1;

if (cbegin== 0) break;
}
return null;
}

//*****************************************************
//*****************************************************

function setCookie(cname, cvalue)
{
var expires = new Date(); 
expires.setTime(expires.getTime() + (1000 * 60 * 60 *24));    

 var mycookie = cname + "=" + escape(cvalue)
         + ((expires == null) ? "" : ("; expires=" + expires.toGMTString()));
    document.cookie = mycookie;    //set the cookie
// For the example - write out the value of the cookie we just set
 //   document.write("A cookie was set with value: ", mycookie, "<br />");

}

//***************************************************
//***************************************************

//***************************************************
//***************************************************

var ShipFirst = "";
var ShipCompany = "";
var ShipAddress1 = "";
var ShipAddress2 = "";
var ShipCity = "";
var ShipState = "";
var ShipStateIndex = 0;
var ShipZip = "";
var ShipPhone = "";
var ShipPhoneExt= "";


//***************************************************
//***************************************************

function InitSaveVariables(form) 
{

ShipFirst = form.txtName.value;
ShipCompany = form.txtCompany.value;
ShipAddress1 = form.txtAddress1.value;
ShipAddress2 = form.txtAddress2.value;
ShipCity = form.txtCity.value;
ShipZip = form.txtZip.value;
ShipStateIndex = form.txtState.selectedIndex;
ShipState = form.txtState[ShipStateIndex].value;
ShipPhone = form.txtPhone.value;
ShipPhoneExt = form.txtPhoneExt.value;

}



//***************************************************
//***************************************************

function ShipToBillPerson(form) 
{
	if (form.chkSameShipping.checked) 
	{
		InitSaveVariables(form);
		form.txtShipToName.value = form.txtName.value;
		form.txtShipToCompany.value = form.txtCompany.value;
		form.txtShipToAddress1.value = form.txtAddress1.value;
		form.txtShipToAddress2.value = form.txtAddress2.value;
		form.txtShipToCity.value = form.txtCity.value;
		form.txtShipToZip.value = form.txtZip.value;
		form.txtShipToState.selectedIndex = form.txtState.selectedIndex;
		form.txtShipToPhone.value = form.txtPhone.value;
		form.txtShipToPhoneExt.value = form.txtPhoneExt.value;
	}
	else 
	{
		form.txtShipToName.value = ShipFirst;
		form.txtShipToCompany.value = ShipCompany;
		form.txtShipToAddress1.value = ShipAddress1;
		form.txtShipToAddress2.value = ShipAddress2;
		form.txtShipToCity.value = ShipCity;
		form.txtShipToZip.value = ShipZip;       
		form.txtShipToState.selectedIndex = ShipStateIndex;
		form.txtShipToPhone.value = ShipPhone;
		form.txtShipToPhoneExt.value = ShipPhoneExt;

   	}
}


//***************************************************
//***************************************************

function handleParent(parentId)
{
	myParent = document.getElementById("collapse" + parentId)

	if (myParent.style.display=="none") {
		myParent.style.display="block";
		document.all("txtExpCol" + parentId).innerText = "-";
	} else {
		myParent.style.display="none";
		document.all("txtExpCol" + parentId).innerText ="+";
	}
}

//***************************************************
//***************************************************

function checkLogin (form) 
{
if (form.loginEmail.value == "") 
	{ alert("Please enter your Email Address."); form.loginEmail.focus(); return false;}
if (form.loginPassword.value == "") 
	{ alert("Please enter your Password."); form.loginPassword.focus(); return false;} 
return true;}

//***************************************************
//***************************************************

function checkEmail (form) 
{ 
	if (form.txtEmail.value == "") 
	{ alert("Please enter your Email Address."); 
	  form.txtEmail.focus(); 
	  return false;} 
	return true;}

//***************************************************
//***************************************************

function validRequired(formField,fieldLabel)
{
	var result = true;
	
	if (formField.value == "")
	{
		alert('Please enter a value for the "' + fieldLabel +'" field.');
		formField.focus();
		result = false;
	}
	
	return result;
}

//***************************************************
//***************************************************

function isInteger(theField, frmIndex)
{
   if (theField.value == "")
   {
	return(true);
   }

   var i;
   var sString = theField.value;

   for (i = 0; i < sString.length; i++)
   {
   	var c = sString.charAt(i);
     	if (!((c <= "9") || (c == "0")))
        {
		alert('Please enter an integer for the quantity.');
		theField.focus();
		theField.select();
            	return (false);
        }
   }

}
//***************************************************
//***************************************************


function allDigits(theField)
{
	return inValidCharSet(theField,"0123456789");
}

function inValidCharSet(theField,charset)
{
	var result = true;
	var str = theField.value

	for (var i=0;i<str.length;i++)
		if (charset.indexOf(str.substr(i,1))<0)
		{
			alert('Please enter an integer for the quantity.');
			theField.focus();
			theField.select();
			result = false;
			break;
		}
	
	return result;
}
//***************************************************
//***************************************************


function allDigitsUM(theField, frmIndex)
{

	return inValidCharSetUM(theField,"0123456789", frmIndex);
}

function inValidCharSetUM(theField,charset,frmIndex)
{
	var result = true;
	var str;
	var index;

	if (theField.name == "Add"){
		
		if ( (document.forms[0].name == "frmLogin") && (document.forms[1].name == "frmCart") ){
			index = 2;
		}
		else if ( (document.forms[0].name == "frmCart") || (document.forms[0].name == "frmLogin") ){
			index = 1;
		}
		else{
			index = 0;
		}

		if (document.forms[index].name == "frmCatalog"){
			str = document.frmCatalog.elements[frmIndex+1].value;
			if (document.frmCatalog.elements[frmIndex].selectedIndex == 0){
				alert('Please select a unit of measure.');
				document.frmCatalog.elements[frmIndex].focus();
				result = false;
			}
		}
		if (document.forms[index].name == "frmResults"){
			str = document.frmResults.elements[frmIndex+1].value;
			if (document.frmResults.elements[frmIndex].selectedIndex == 0){
				alert('Please select a unit of measure.');
				document.frmResults.elements[frmIndex].focus();
				result = false;
			}
		}
		if (document.forms[index].name == "frmContract"){
			str = document.frmContract.elements[frmIndex+1].value;
			if (document.frmContract.elements[frmIndex].selectedIndex == 0){
				alert('Please select a unit of measure.');
				document.frmContract.elements[frmIndex].focus();
				result = false;
			}
		}
		if (document.forms[index].name == "frmDetails"){
			str = document.frmDetails.elements[frmIndex+1].value;
			if (document.frmDetails.elements[frmIndex].selectedIndex == 0){
				alert('Please select a unit of measure.');
				document.frmDetails.elements[frmIndex].focus();
				result = false;
			}
		}
	}

	for (var i=0;i<str.length;i++)
		if (charset.indexOf(str.substr(i,1))<0)
		{
			result = false;
			break;
		}
	
	return result;
}
//***************************************************
//***************************************************

function validCC(formField,fieldLabel,required)
{
	var result = true;

	if (required && !validRequired(formField,fieldLabel)) 
		result = false;
  
 	if (result)
 	{
 		if ((!allDigits(formField.value)) || (formField.value.length<16))
 		{
 			alert('Please enter a 16 digit number for the "' + fieldLabel +'" field. \n Omit dashes and spaces.');
			formField.focus();		
			result = false;
		}
	} 
	
	return result;
}

//********************************************************
//********************************************************

function isEmailAddr(email)
{
  var result = false;
  var theStr = new String(email);
  var index = theStr.indexOf("@");
  if (index > 0)
  {
    var pindex = theStr.indexOf(".",index);
    if ((pindex > index+1) && (theStr.length > pindex+1))
	result = true;
  }
  return result;
}
//********************************************************
//********************************************************

function validEmail(formField,fieldLabel,required)
{
	var result = true;
	
	if (required && !validRequired(formField,fieldLabel))
		result = false;

	if (result && ((formField.value.length < 3) || !isEmailAddr(formField.value)) )
	{
		alert("Please enter a complete email address in the form: yourname@yourdomain.com");
		formField.focus();
		result = false;
	}
  return result;
}
//********************************************************
//********************************************************


function validNum(formField,fieldLabel,required)
{
	var result = true;

	if (required && !validRequired(formField,fieldLabel))
		result = false;
  
 	if (result)
 	{
 		if (!allDigits(formField.value))
 		{
 			alert('Please enter a number for the "' + fieldLabel +'" field.');
			formField.focus();		
			result = false;
		}
	} 
	
	return result;
}
//********************************************************
//********************************************************

function validZip(formField,fieldLabel,required)
{
	var result = true;

	if (required && !validRequired(formField,fieldLabel)) 
		result = false;
  
 	if (result)
 	{
 		if ((!allDigits(formField.value)) || (formField.value.length < 5) ||(formField.value.length > 5))
 		{
 			alert('Please enter a 5 digit number for the "' + fieldLabel +'" field.');
			formField.focus();		
			result = false;
		}
	} 
	
	return result;
}
//********************************************************
//********************************************************

function validPhone(formField,fieldLabel,required) 
{
	var result=true;
	re = /^\(?(\d{3})\)?[\.\-\/ ]?(\d{3})[\.\-\/ ]?(\d{4})$/;
	
	if (required && !validRequired(formField,fieldLabel)) 
		result = false;
		
	if(result)
	{
			validPhone = re.exec(formField.value)
			if (validPhone) 
			{
				formField.value = "(" + validPhone[1] + ") " + validPhone[2] + "-" + validPhone[3];
			}
			else 
			{
				alert(formField.value + " isn't a valid phone number");
				formField.focus();
				formField.select();
				result=false;
			}
	}
	return result;
}
//********************************************************
//********************************************************


function validInt(formField,fieldLabel,required)
{
	var result = true;

	if (required && !validRequired(formField,fieldLabel))
		result = false;
  
 	if (result)
 	{
 		var num = parseInt(formField.value);
 		if (isNaN(num))
 		{
 			alert('Please enter a number for the "' + fieldLabel +'" field.');
			formField.focus();		
			result = false;
		}
	} 
	
	return result;
}

//********************************************************
//********************************************************


function isValidCreditCard(type, ccnum) 
{


   if (type == "Visa") 
     {
      // Visa: length 16, prefix 4, dashes optional.
      var re = /^4\d{3}-?\d{4}-?\d{4}-?\d{4}$/;
     } 
    else if (type == "Mastercard") 
     {
      // Mastercard: length 16, prefix 51-55, dashes optional.
      var re = /^5[1-5]\d{2}-?\d{4}-?\d{4}-?\d{4}$/;
     } 
    else if (type == "Discover") 
     {
      // Discover: length 16, prefix 6011, dashes optional.
      var re = /^6011-?\d{4}-?\d{4}-?\d{4}$/;
     } 
    else if (type == "American Express") 
     {
      // American Express: length 15, prefix 34 or 37.
      var re = /^3[4,7]\d{13}$/;
     } 

   if (!re.test(ccnum)) return false;

   // Checksum ("Mod 10")
   // Add even digits in even length strings or odd digits in odd length strings.

   var checksum = 0;
   for (var i=(2-(ccnum.length % 2)); i<=ccnum.length; i+=2) 
   {
      checksum += parseInt(ccnum.charAt(i-1));
   }

   // Analyze odd digits in even length strings or even digits in odd length strings.

   for (var i=(ccnum.length % 2) + 1; i<ccnum.length; i+=2) 
   {
      var digit = parseInt(ccnum.charAt(i-1)) * 2;
      if (digit < 10) { checksum += digit; } else { checksum += (digit-9); }
   }

   if ((checksum % 10) == 0) return true; else return false;
}

//********************************************************
//********************************************************


function Checkout ( form )
{

if (form.txtName.value == "")
	{
		alert("Name must be filled in.");  
		form.txtName.focus();  
		return false;
	}


if (form.txtPassword.value == "")
	{
		alert("Password must be filled in.");  
		form.txtPassword.focus();  
		return false;
	}

if (form.txtPassword2.value == "")
	{
		alert("Password Confirmation must be filled in.");  
		form.txtPassword2.focus();  
		return false;
	}


if (form.txtPassword.value !== form.txtPassword2.value)
	{
		alert("Passwords Don\'t Match.");  
		form.txtPassword2.focus();  
		return false;
	}

if (form.txtEmail.value == "") 
	{ 
		alert("Please enter your Email Address."); 
	  	form.txtEmail.focus(); 
	  	return false;
	} 


if (form.txtAddress1.value == "")
	{
		alert("Address must be filled in.");  
		form.txtAddress1.focus();  
		return false;
	}

if (form.txtCity.value == "")
	{
		alert("City must be filled in.");  
		form.txtCity.focus();  
		return false;
	}

if (form.txtState.value == "")
	{
		alert("State must be filled in.");  
		form.txtState.focus();  
		return false;
	}


if (form.txtZip.value == "")
	{
		alert("Zip Code must be filled in.");  
		form.txtZip.focus();  
		return false;
	}


if (form.txtPhone.value == "")
	{
		alert("Phone Number must be filled in.");  
		form.txtPhone.focus();  
		return false;
	}

//if (!validZip(theForm.txtZip,"Zip Code",true)) 
	//{return false;}


//if (!validPhone(form.txtPhone,"Phone Number",true)) 
	//{return false;}

if (form.txtShipToName.value == "")
	{
		alert("Ship to Name must be filled in.");  
		form.txtShipToName.focus();  
		return false;
	}

if (form.txtShipToAddress1.value == "")
	{
		alert("Ship to Address must be filled in.");  
		form.txtShipToAddress1.focus();  
		return false;
	}

if (form.txtShipToCity.value == "")
	{
		alert("Ship to City must be filled in.");  
		form.txtShipToCity.focus();  
		return false;
	}

if (form.txtShipToState.value == "")
	{
		alert("Ship to State must be filled in.");  
		form.txtShipToState.focus();  
		return false;
	}

if (form.txtShipToZip.value == "")
	{
		alert("Ship To Zip Code must be filled in.");  
		form.txtShipToZip.focus();  
		return false;
	}


if (form.txtShipToPhone.value == "")
	{
		alert("Shipping Contact Phone Number must be filled in.");  
		form.txtShipToPhone.focus();  
		return false;
	}


if (form.txtCCnumber.value != "")
{

	if (!isValidCreditCard(form.txtCCType.value, form.txtCCnumber.value))
	{
		alert("Please enter a valid number for the credit card, omitting spaces and dashes."); 
		form.txtCCnumber.focus();  
		return false;
	}
}


if (form.recurrOrdName)
{
	if (form.recurrOrdName.value == "")
	{
		alert("Recurring Order Name must be filled in.");  
		form.recurrOrdName.focus();  
		return false;
	}
}

return true;}

//********************************************************
//*******************************************************

function Checkout2 ( form )
{

if (form.txtName.value == "")
	{
		alert("Name must be filled in.");  
		form.txtName.focus();  
		return false;
	}


if (form.txtPassword.value == "")
	{
		alert("Password must be filled in.");  
		form.txtPassword.focus();  
		return false;
	}


if (form.txtEmail.value == "") 
	{ 
		alert("Please enter your Email Address."); 
	  	form.txtEmail.focus(); 
	  	return false;
	} 


if (form.txtAddress1.value == "")
	{
		alert("Address must be filled in.");  
		form.txtAddress1.focus();  
		return false;
	}

if (form.txtCity.value == "")
	{
		alert("City must be filled in.");  
		form.txtCity.focus();  
		return false;
	}

if (form.txtState.value == "")
	{
		alert("State must be filled in.");  
		form.txtState.focus();  
		return false;
	}


if (form.txtZip.value == "")
	{
		alert("Zip Code must be filled in.");  
		form.txtZip.focus();  
		return false;
	}


if (form.txtPhone.value == "")
	{
		alert("Phone Number must be filled in.");  
		form.txtPhone.focus();  
		return false;
	}


if (form.txtShipToName.value == "")
	{
		alert("Ship to Name must be filled in.");  
		form.txtShipToName.focus();  
		return false;
	}

if (form.txtShipToAddress1.value == "")
	{
		alert("Ship to Address must be filled in.");  
		form.txtShipToAddress1.focus();  
		return false;
	}

if (form.txtShipToCity.value == "")
	{
		alert("Ship to City must be filled in.");  
		form.txtShipToCity.focus();  
		return false;
	}

if (form.txtShipToState.value == "")
	{
		alert("Ship to State must be filled in.");  
		form.txtShipToState.focus();  
		return false;
	}

if (form.txtShipToZip.value == "")
	{
		alert("Ship To Zip Code must be filled in.");  
		form.txtShipToZip.focus();  
		return false;
	}


if (form.txtShipToPhone.value == "")
	{
		alert("Shipping Contact Phone Number must be filled in.");  
		form.txtShipToPhone.focus();  
		return false;
	}



if (form.txtCCnumber.value != "")
{

	if (!isValidCreditCard(form.txtCCType.value, form.txtCCnumber.value))
	{
		alert("Please enter a valid number for the credit card, omitting spaces and dashes."); 
		form.txtCCnumber.focus();  
		return false;
	}
}


if (form.recurrOrdName)
{
	if (form.recurrOrdName.value == "")
	{
		alert("Recurring Order Name must be filled in.");  
		form.recurrOrdName.focus();  
		return false;
	}
}

return true;}

//********************************************************
//*******************************************************
//********************************************************
//*******************************************************

function CheckoutPO ( form )
{

if (form.txtName.value == "")
	{
		alert("Name must be filled in.");  
		form.txtName.focus();  
		return false;
	}


if (form.txtPassword.value == "")
	{
		alert("Password must be filled in.");  
		form.txtPassword.focus();  
		return false;
	}


if (form.txtEmail.value == "") 
	{ 
		alert("Please enter your Email Address."); 
	  	form.txtEmail.focus(); 
	  	return false;
	} 


if (form.txtAddress1.value == "")
	{
		alert("Address must be filled in.");  
		form.txtAddress1.focus();  
		return false;
	}

if (form.txtCity.value == "")
	{
		alert("City must be filled in.");  
		form.txtCity.focus();  
		return false;
	}

if (form.txtState.value == "")
	{
		alert("State must be filled in.");  
		form.txtState.focus();  
		return false;
	}


if (form.txtZip.value == "")
	{
		alert("Zip Code must be filled in.");  
		form.txtZip.focus();  
		return false;
	}


if (form.txtPhone.value == "")
	{
		alert("Phone Number must be filled in.");  
		form.txtPhone.focus();  
		return false;
	}
if (form.txtPO.value == "")
	{
		alert("PO Number is required to order.");  
		form.txtPO.focus();  
		return false;
	}


if (form.txtShipToName.value == "")
	{
		alert("Ship to Name must be filled in.");  
		form.txtShipToName.focus();  
		return false;
	}

if (form.txtShipToAddress1.value == "")
	{
		alert("Ship to Address must be filled in.");  
		form.txtShipToAddress1.focus();  
		return false;
	}

if (form.txtShipToCity.value == "")
	{
		alert("Ship to City must be filled in.");  
		form.txtShipToCity.focus();  
		return false;
	}

if (form.txtShipToState.value == "")
	{
		alert("Ship to State must be filled in.");  
		form.txtShipToState.focus();  
		return false;
	}

if (form.txtShipToZip.value == "")
	{
		alert("Ship To Zip Code must be filled in.");  
		form.txtShipToZip.focus();  
		return false;
	}


if (form.txtShipToPhone.value == "")
	{
		alert("Shipping Contact Phone Number must be filled in.");  
		form.txtShipToPhone.focus();  
		return false;
	}



if (form.txtCCnumber.value != "")
{

	if (!isValidCreditCard(form.txtCCType.value, form.txtCCnumber.value))
	{
		alert("Please enter a valid number for the credit card, omitting spaces and dashes."); 
		form.txtCCnumber.focus();  
		return false;
	}
}


if (form.recurrOrdName)
{
	if (form.recurrOrdName.value == "")
	{
		alert("Recurring Order Name must be filled in.");  
		form.recurrOrdName.focus();  
		return false;
	}
}

return true;}

//********************************************************
//*******************************************************


//*********** Based on the payment type it will display *************//
//*********  the proper payment method fields if needed  ***********//

	
function viewPaymentFields(PaymentType)
{

	if ( PaymentType == "creditcard" )
	{
		document.getElementById("stYearDiv").style.left = 0;
		document.getElementById("stYearDiv").style.pixelLeft -= 100;
		document.getElementById("endYearDiv").style.left = 0;
		document.getElementById("endYearDiv").style.pixelLeft -= 100;
		document.getElementById("stMonDiv").style.visibility = "hidden";
		document.getElementById("endMonDiv").style.visibility = "hidden";
		document.getElementById("stDayDiv").style.visibility = "hidden";
		document.getElementById("endDayDiv").style.visibility = "hidden";
		if ( document.getElementById("rptCust").checked == true || document.getElementById("rptProd").checked == true )
		{
			document.getElementById("endYearDiv").style.visibility = "hidden";
			document.getElementById("toDateDiv").style.visibility = "hidden";
		}
	}
	if ( PaymentType == "openaccount" )
	{
		document.getElementById("stYearDiv").style.left = 0;
		document.getElementById("stYearDiv").style.pixelLeft -= 45;
		document.getElementById("endYearDiv").style.left = 0;
		document.getElementById("endYearDiv").style.pixelLeft -= 45;
		document.getElementById("stMonDiv").style.visibility = "visible";
		document.getElementById("endMonDiv").style.visibility = "visible";
		document.getElementById("stDayDiv").style.visibility = "hidden";
		document.getElementById("endDayDiv").style.visibility = "hidden";
		if ( document.getElementById("rptCust").checked == true || document.getElementById("rptProd").checked == true )
		{
			document.getElementById("endYearDiv").style.visibility = "hidden";
			document.getElementById("endMonDiv").style.visibility = "hidden";
			document.getElementById("toDateDiv").style.visibility = "hidden";
		}
	}
return true;
}

//******* Get the correct shipTo info ********//
//******* based on selected location  ********//


function loadShipToInfo(){
	btnShip();
	document.frmCheckout.action = "checkout.asp";
	document.frmCheckout.submit();
}

function btnShip(){
	document.getElementById("btnPush").value = "ship";
}

function btnAdd(){
	document.getElementById("btnPush").value = "add";
}

function btnDelete(){
	document.getElementById("btnPush").value = "delete";
}

function btnSave(){
	document.getElementById("btnPush").value = "save";
}


function CheckShipInfo(form){
	if (form.txtShipToName.value == "")
		{
			alert("Ship to Name must be filled in.");  
			form.txtShipToName.focus();  
			return false;
		}

	if (form.txtShipToAddress1.value == "")
		{
			alert("Ship to Address must be filled in.");  
			form.txtShipToAddress1.focus();  
			return false;
		}

	if (form.txtShipToCity.value == "")
		{
			alert("Ship to City must be filled in.");  
			form.txtShipToCity.focus();  
			return false;
		}

	if (form.txtShipToState.value == "")
		{
			alert("Ship to State must be filled in.");  
			form.txtShipToState.focus();  
			return false;
		}

	if (form.txtShipToState.value.length > 2)
		{
			alert("Please Use State Abbreviations!");
			form.txtShipToState.focus();
			return false;
		}

	if (form.txtShipToZip.value == "")
		{
			alert("Ship To Zip Code must be filled in.");  
			form.txtShipToZip.focus();  
			return false;
		}


	if (form.txtShipToPhone.value == "")
		{
			alert("Shipping Contact Phone Number must be filled in.");  
			form.txtShipToPhone.focus();  
			return false;
		}
	return true;
}

function addShip(userNo, custID){
	
	btnAdd();
	
	var leftPos = screen.width / 1.5;
	var topPos = screen.height / 3;
	var winURL = "editShipping.asp?userNo=" + userNo + "&custID=" + custID;
	var winName = "EditShipWin";
	var winAttr = "title=0,toolbar=0,status=0,location=0,directories=0,scrollbars=0,resizable=0,menubar=0,width=280,height=300,top=" + topPos + ",left=" + leftPos;

	window.open(winURL, winName, winAttr);

}

function saveShip(userNo, custID){
	
	if ( CheckShipInfo(document.frmEditShip) ){
		btnSave();
		document.frmEditShip.action = "editShipping.asp?userNo=" + userNo + "&custID=" + custID;
		document.frmEditShip.submit();
		window.opener.location.href = unescape(window.opener.location.pathname)+ "?loadNewShip=true";
	}
}

//********** Functions for FTM Approval or Rejection **********//

function openFTMApproval(FTM_Response, FTM_OrderID, FTM_Originator, FTM_Approver){	
	
	var wdt = 700;
	var hgt = 500;
	var leftPos = (screen.width - wdt)/2;
	var topPos = (screen.height - hgt)/2;
	
	if ( leftPos < 0 ) leftPos = 0;
	if ( topPos < 0 ) topPos = 0;

	if ( FTM_Response == "rejected" )
		var winURL = "http://www.ocsaccess.com/uscoffeedev/ftmApproval.asp?ftm_response=rejected&ftm_orderID=" + FTM_OrderID +  "&ftm_originator=" + FTM_Originator + "&ftm_approver=" + FTM_Approver;
	if ( FTM_Response == "approved" )
		var winURL = "http://www.ocsaccess.com/uscoffeedev/ftmApproval.asp?ftm_response=approved&ftm_orderID=" + FTM_OrderID + "&ftm_originator=" + FTM_Originator + "&ftm_approver=" + FTM_Approver;

	var winName = "FTMApproval";
	var winAttr = "title=0,toolbar=0,status=0,location=0,directories=0,scrollbars=0,resizable=0,menubar=0,width=360,height=362,top=" + topPos + ",left=" + leftPos;

	window.open(winURL, winName, winAttr);

}


//************ Functions in FTM Audit **********//

function collapseAudit(parentId)
{
	myParent = document.getElementById("collapse" + parentId)

	if (myParent.style.display=="none") {
		myParent.style.display="block";
		document.all("btnAudit" + parentId).innerText = "-";
	} else {
		myParent.style.display="none";
		document.all("btnAudit" + parentId).innerText ="+";
	}
}


//********** Function in verify.asp **********//

function forwardFTMOrd(btn){
	
	btn.disabled = true;
	document.getElementById("chngOrder").disabled = true;
	
	document.frmVerify.action = "ftmConfirm.asp";
	document.frmVerify.submit();
	setTimeout('alert("Your order has been forwarded for approval.")',2000);
}

function completeOrder(btn){

	btn.disabled = true;
	document.getElementById("chngOrder").disabled = true;

	document.frmVerify.action = "Confirm.asp";
	document.frmVerify.submit();
	setTimeout('alert("Your order has been submitted.")', 2000);
}

function submitOnce(theform) {

	if (document.all || document.getElementById) {

		for (i = 0; i < theform.length; i++) {
			var tempobj = theform.elements[i];
			if (tempobj.type.toLowerCase() == "submit" || tempobj.type.toLowerCase() == "reset")
				tempobj.disabled = true;
		}

		setTimeout('alert("Your order has been submitted.")', 2000);
		return true;
	}
	else {

		alert("The order has been submitted.");
		return false;
   	}
}

//********** FTM Approval Code for images *********//

function newImage(arg) {
	if (document.images) {
		rslt = new Image();
		rslt.src = arg;
		return rslt;
	}
}

function changeImages() {
	if (document.images && (preloadFlag == true)) {
		for (var i=0; i<changeImages.arguments.length; i+=2) {
			//document[changeImages.arguments[i]].src = changeImages.arguments[i+1];
			document.getElementById(changeImages.arguments[i]).src = changeImages.arguments[i+1];
		}
	}
}

function changeImages2() {
	//if (document.images && (preloadFlag == true)) {
		for (var i=0; i<changeImages2.arguments.length; i+=2) {
			document[changeImages2.arguments[i]].src = changeImages2.arguments[i+1];
		}
	//}
}

var preloadFlag = false;

function preloadImages() {
	if (document.images) {
		Submit1_over = newImage("images/ftm_rejected/Submit1-over.gif");
		preloadFlag = true;
	}
}

function btnFtmSub(){

	document.getElementById("FtmSubmit").disabled = true;

	var RejReason = escape(document.getElementById("FtmRejected").value);

	document.getElementById("btnPushed").value = "FtmSubmit";
	document.getElementById("txtRejection").value = RejReason;
	document.frmFtmRejected.submit();
}

//********** function within newUser.asp **********//

function existCust(){
	document.getElementById("nonExistCust").checked = false;
	if (document.getElementById("colExist").style.display == "none"){
		document.getElementById("colExist").style.display = "block";
		document.getElementById("colNonExist").style.display = "none"
	}
	else
		document.getElementById("colExist").style.display = "none";

}

function nonExistCust(){
	document.getElementById("existCust").checked = false;
	if (document.getElementById("colNonExist").style.display == "none"){
		document.getElementById("colNonExist").style.display = "block";
		document.getElementById("colExist").style.display = "none";
	}
	else
		document.getElementById("colNonExist").style.display = "none";
}

function fillShipInfo(){

	var shipInfo;
	shipInfo = document.frmNonExistCust;
	
	if (shipInfo.chkShipInfo.checked == true){	
		shipInfo.txtShipToName.value = shipInfo.txtName.value;
		shipInfo.txtShipToCompany.value = shipInfo.txtCompany.value;
		shipInfo.txtShipToAddress1.value = shipInfo.txtAddress1.value;
		shipInfo.txtShipToAddress2.value = shipInfo.txtAddress2.value;
		shipInfo.txtShipToCity.value = shipInfo.txtCity.value;
		shipInfo.txtShipToState.value = shipInfo.txtState.value;
		shipInfo.txtShipToZip.value = shipInfo.txtZip.value;
		shipInfo.txtShipToPhone.value = shipInfo.txtPhone.value;
		shipInfo.txtShipToPhoneExt.value = shipInfo.txtPhoneExt.value;
	}
	else{
		shipInfo.txtShipToName.value = "";
		shipInfo.txtShipToCompany.value = "";
		shipInfo.txtShipToAddress1.value = "";
		shipInfo.txtShipToAddress2.value = "";
		shipInfo.txtShipToCity.value = "";
		shipInfo.txtShipToState.value = "";
		shipInfo.txtShipToZip.value = "";
		shipInfo.txtShipToPhone.value = "";
		shipInfo.txtShipToPhoneExt.value = "";
	}
}

function chkExistFrm(){

	var existFrm;
	existFrm = document.frmExistCust;
	
	if ( existFrm.txtName.value.length <= 2 ){
		alert("Please enter your name!");
		existFrm.txtName.focus();
		return false;
	}
	if ( existFrm.txtCompany.value.length <= 2 ){
		alert("Please enter company name!");
		existFrm.txtCompany.focus();
		return false;
	}
	if ( existFrm.txtAccountNumber.value.length < 2 ){
		alert("Please enter your account number!");
		existFrm.txtAccountNumber.focus();
		return false;
	}
	if ( !isEmailAddr(existFrm.txtEmail.value) ){
		alert("Please enter a valid email address!");
		existFrm.txtEmail.focus();
		return false;
	}
	if ( existFrm.txtPassword1.value.length < 1 ){
		alert("Please enter a password!");
		existFrm.txtPassword1.focus();
		return false;
	}
	if ( existFrm.txtPassword1.value != existFrm.txtPassword2.value ){
		alert("The password do not match!");
		existFrm.txtPassword2.focus();
		return false;
	}
	
	return true;
}

function chkNonExistFrm(){
	
	var result;
	var nonExistFrm;
	var d = new Date();
	var curr_year = d.getYear();
	var curr_month = d.getMonth();
	
	result = false;
	nonExistFrm = document.frmNonExistCust;
	
	result = Checkout(nonExistFrm);
	

	if (nonExistFrm.txtPassword.value == "")
	{
		alert("Password must be filled in.");  
		nonExistFrm.txtPassword.focus();  
		return false;
	}
	
	if (nonExistFrm.txtPassword2.value == "")
	{
		alert("Password Confirmation must be filled in.");  
		nonExistFrm.txtPassword2.focus();  
		return false;
	}


	if (nonExistFrm.txtPassword.value !== form.txtPassword2.value)
	{
		alert("Passwords Don\'t Match.");  
		nonExistFrm.txtPassword2.focus();  
		return false;
	}


	if (nonExistFrm.txtEmail.value == "") 
	{ 
		alert("Please enter your Email Address."); 
	  	nonExistFrm.txtEmail.focus(); 
	  	return false;
	} 


	if (nonExistFrm.txtAddress1.value == "")
	{
		alert("Address must be filled in.");  
		nonExistFrm.txtAddress1.focus();  
		return false;
	}

	if (nonExistFrm.txtCity.value == "")
	{
		alert("City must be filled in.");  
		nonExistFrm.txtCity.focus();  
		return false;
	}

	if (nonExistFrm.txtState.value == "")
	{
		alert("State must be filled in.");  
		nonExistFrm.txtState.focus();  
		return false;
	}


	if (nonExistFrm.txtZip.value == "")
	{
		alert("Zip Code must be filled in.");  
		nonExistFrm.txtZip.focus();  
		return false;
	}


	if (nonExistFrm.txtPhone.value == "")
	{
		alert("Phone Number must be filled in.");  
		nonExistFrm.txtPhone.focus();  
		return false;
	}


	if (nonExistFrm.txtShipToName.value == "")
	{
		alert("Ship to Name must be filled in.");  
		nonExistFrm.txtShipToName.focus();  
		return false;
	}

	if (nonExistFrm.txtShipToAddress1.value == "")
	{
		alert("Ship to Address must be filled in.");  
		nonExistFrm.txtShipToAddress1.focus();  
		return false;
	}

	if (nonExistFrm.txtShipToCity.value == "")
	{
		alert("Ship to City must be filled in.");  
		nonExistFrm.txtShipToCity.focus();  
		return false;
	}

	if (nonExistFrm.txtShipToState.value == "")
	{
		alert("Ship to State must be filled in.");  
		nonExistFrm.txtShipToState.focus();  
		return false;
	}

	if (nonExistFrm.txtShipToZip.value == "")
	{
		alert("Ship To Zip Code must be filled in.");  
		nonExistFrm.txtShipToZip.focus();  
		return false;
	}


	if (nonExistFrm.txtShipToPhone.value == "")
	{
		alert("Shipping Contact Phone Number must be filled in.");  
		nonExistFrm.txtShipToPhone.focus();  
		return false;
	}


		
		
	return result;
}

