// THIS PAGE HAS MANY FUNCTIONS FOR VALIDATION

// password validation function
function validatepwrd(pwrd,pwrd2)
{
// set variable for valid characters for password
var pwrdvalid = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"

// check for special characters in password
for (var i=0; i < pwrd.length; i++) 
{
if (pwrdvalid.indexOf(pwrd.charAt(i)) < 0) 
{
alert("You must not use any special characters or spaces in your password.");
return false;
}
}

// verify password match
if ((pwrd) != (pwrd2))
{
alert("Your password verification failed. Please try again.");
return false;
}

// verify that password is longer than six characters
if (pwrd.length < 6)
{
alert("Your password must be at least six characters long.");
return false;
}

else
{
return true;
}

}
// end validate function


// start billing to shipping address function
function billtoship(boxchecked,theForm)
{

if (boxchecked)
{
theForm.Ship_Fname.value=theForm.Bill_fname.value;
theForm.Ship_Lname.value=theForm.Bill_lname.value;
theForm.Ship_Address.value=theForm.Address.value;
theForm.Ship_Address2.value=theForm.Address2.value;
theForm.Ship_City.value=theForm.City.value;
theForm.Ship_State.value=theForm.State.value;
theForm.Ship_Zip.value=theForm.Zip.value;
theForm.Ship_Country.value=theForm.Country.value;
theForm.Ship_Phone.value=theForm.Phone.value;
theForm.Ship_Phone2.value=theForm.Phone2.value;
}


else
{
theForm.Ship_Fname.value="";
theForm.Ship_Lname.value="";
theForm.Ship_Address.value="";
theForm.Ship_Address2.value=" ";
theForm.Ship_City.value="";
theForm.Ship_State.selectedIndex=0;
theForm.Ship_Zip.value="";
theForm.Ship_Country.value="US";
theForm.Ship_Phone.value="";
theForm.Ship_Phone2.value="";
}

}
// end billing to shipping address function




// check phone numbers

function checkphones(phone,shipphone)
{

// set variable for valid characters for phone
var phonevalid = "0123456789-+ .()"

// check for special characters in bill phone
for (var i=0; i < phone.length; i++) 
{
if (phonevalid.indexOf(phone.charAt(i)) < 0) 
{
alert("You must not use any special characters in your billing phone.");
return false;
}
}

// check for special characters in ship phone
for (var i=0; i < shipphone.length; i++) 
{
if (phonevalid.indexOf(shipphone.charAt(i)) < 0) 
{
alert("You must not use any special characters in your shipping phone.");
return false;
}
}


}


// end check phone numbers



// check zips

function checkzips(zip,shipzip)
{

// set variable for valid characters for zip
var zipvalid = "0123456789- abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"


// check for special characters in bill zip
for (var i=0; i < zip.length; i++) 
{
if (zipvalid.indexOf(zip.charAt(i)) < 0) 
{
alert("You must not use any special characters in your billing zip.");
return false;
}
}

// check for special characters in ship zip
for (var i=0; i < shipzip.length; i++) 
{
if (zipvalid.indexOf(shipzip.charAt(i)) < 0) 
{
alert("You must not use any special characters in your shipping zip.");
return false;
}
}

}

// end check zips



// start email verification function
function validateemail(email)
{

var emailvalid = "_-.~`@0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
var filter = /^.+@.+\..{2,3}$/ 

// check for special characters in email
for (var i=0; i < email.length; i++) 
{
if (emailvalid.indexOf(email.charAt(i)) < 0) 
{
alert("You must not have any spaces or special characters in your email address.");
return false;
}
}

if (filter.test(email)) 
{
return true;
}
else
{ 
alert("Please enter a valid email address!");
return false;
} 

}
// end email verification function


// start checking country for state
// if country is US then a state must be chosen

function statecountry(billstate,billcountry,shipstate,shipcountry)
{

if ((billstate == 'XX') && (billcountry == 'US'))
{
alert("If you live in the US, you must choose a state for billing!");
return false ;
}

else if ((shipstate == 'XX') && (shipcountry == 'US'))
{
alert("If you live in the US, you must choose a state for shipping!");
return false ;
}

else
{
return true ;
}

}
// end country/state verification



// check checkboxes
function isChecked(msg){
 if (msg == 1){
 var message='All Shipping Orders must be approved before closing order';
   }
  else 
  {var message='All Vendor and Warehouse Purchase Order must be approved before submitting form';
  } 

 for (i=0; i<myform.elements.length; i++) 
{
    if (myform.elements[i].type == 'checkbox' && myform.elements[i].checked == false)
	{ 
	alert(message);
	return false;
	}
  }
}
// end check checkboxes

// limit textfield size

// THIS FUNCTION DOESN'T QUITE WORK 
// FOR SOME REASON IT WAS LIMITING MY "LIMIT" 
// FOR TEXT FIELDS TO 28...?????
function limittextfield(thefield,limit)
{
alert(thefield);
if (thefield.length > limit )
    {
	alert("Only "  + limit +  " characters allowed in text boxes!");
	return false;
	}
	
else
    {
	  return true;
	}
 }
// open new window

function MM_openBrWindow(theURL,winName,features) { 
  window.open(theURL,winName,features);
}
//end open window 

// *******************************************//

function ShowCalendar(FormName, FieldName)
{
	window.open("CFDateSelectPopupWindow.cfm?FormName=" + FormName + "&FieldName=" + FieldName, "CalendarWindow", "width=200,height=240");
}

// update using checkbox

function UpdateIt(message,oid) {
location.href("_approval.cfm?updated=" + message + "&id=" + oid )}


// Preventing from viewing source 
 
if (window.Event)
  document.captureEvents(Event.MOUSEUP);

function nocontextmenu() {
  event.cancelBubble = true, event.returnValue = false;

  return false;
} 

function norightclick(e) {
  if (window.Event) {
    if (e.which == 2 || e.which == 3) return false;
  }
  else if (event.button == 2 || event.button == 3) {
    event.cancelBubble = true, event.returnValue = false;
    return false;
  }
}

if (document.layers)
  document.captureEvents(Event.MOUSEDOWN);

document.oncontextmenu = nocontextmenu;
document.onmousedown = norightclick;
document.onmouseup = norightclick;

