// Declare Global Variables
	var formAlertMessage='There were Errors!';
	var formSubmit=1;

/*
	throwError gets called each time there is an error in the
	validation routines.
*/
function throwError (theField,theMessage) {
	formAlertMessage=formAlertMessage + "\n - " + theMessage;
	formSubmit=0;
	switchStyle(theField);
}
function switchStyle (theField) {
	theSwitch=new Function("this.style.backgroundColor='FFFFFF';this.style.color='000000';if(this.type=='text') this.select();")
	theField.style.backgroundColor='FF0000';
	theField.style.color='White';
	theField.onfocus=theSwitch;
}

/*
	formAlert displays the alert message and clears necessary variables to start
	the validation over.
*/

function formAlert() {
	alert(formAlertMessage);
	formAlertMessage='There were Errors!';
	formSubmit=1;
}

// form field must be composed only of numbers and letters.
function formIsNumeric(theField,theMessage) {
	theField.value = theField.value.replace(/\s+$|^\s*/gi, "");
	isNum = new RegExp ("[^0-9 \(\)\-\.\/]");
	if (isNum.test(theField.value)) {
		throwError(theField,theMessage);
	}
}
/*
	formRequired makes sure a field has been completed by the user.   In order
	for this function to work with select boxes the empty value must be set to 0
	in the form.
*/

function formRequired(theField,theMessage) {
	theField.value = theField.value.replace(/\s+$|^\s*/gi, "");
	if(theField.value == '' || theField.value == '-1' || theField.value == '0') {
		throwError(theField,theMessage);
	}
}

// form field must be composed only of numbers and letters.
function formIsAlphaNumeric(theField,theMessage) {
	theField.value = theField.value.replace(/\s+$|^\s*/gi, "");
	isAlphaNum = new RegExp ("[^0-9a-zA-Z \(\)\-\.\/]");
	if (isAlphaNum.test(theField.value)) {
		throwError(theField,theMessage);
	}
}

// form field must be composed only of numbers and letters.
function formIsSame(field1,field2,theMessage) {

	if(field1.value != field2.value) {
		throwError(field2,theMessage);
		switchStyle(field1);
	}
}

function formIsEmail (theField,theMessage) {
	var email = /^[a-zA-Z0-9._-]+@([a-zA-Z0-9.-]+\.)+[a-zA-Z0-9.-]{2,4}$/;
 	if(!email.test(theField.value)) {
		throwError(theField,theMessage);
	}
 }

// This is the javascript file for qbb
// Description	: This function resets the mouse pointer to "default"
// Used for		:Showing default mouse pointer after delayed display of pages. 
// Used in		:Extensively in qbb_ordercart.cfm and qbb_catalogue.cfm.
function resetPointer() 
{ 
if (document.all) 
for (var i=0;i < 10; i++) 
document.all(i).style.cursor = 'default'; 
} 


// Description	:This function resets the mouse pointer to "wait"
// Used for		:Showing busy mouse pointer for delayed display of pages. 
// Used in		:Extensively in qbb_ordercart.cfm and qbb_catalogue.cfm.
function setPointer() 
{ 
if (document.all) 
for (var i=0;i < 2; i++) 
document.all(i).style.cursor = 'wait'; 
} 

// Description	:This function checks if the string is numeric.
// Used for		:Numeric validations for quantity fields.
// Used in		:Extensively in qbb_ordercart.cfm and qbb_catalogue.cfm.
function IsNumeric(InStr)
{
  if (InStr.search(/^[0-9]*$/) != -1) {
    return true; }
  else {
    return false; }
}


// Description	:This function converts & with a ~ sign
// Used for		:Converting the & in URL into ~ sign
// Used in		:Extensively in qbb_ordercart.cfm and qbb_catalogue.cfm.
function convertSpaces(str)
{
var out = "", flag = 0;
for (i = 0; i < str.length; i++) 
{
if (str.charAt(i) != "&") 
{
out += str.charAt(i);
flag = 0;
}
else 
{
if(flag == 0) 
	{
		out += "~";
		flag = 1;
    }
 }
}
return out;
}

String.prototype.lrtrim = function() {
				 // skip leading and trailing whitespace and return everything in between
				  var x=this;
				  x=x.replace(/^\s*/, "");
				  x=x.replace(/\s*$/, "");
				  return x;
				}	

function trim(str) { 
   str.replace(/^\s*/, '').replace(/\s*$/, ''); 
   return str;
} 

function isDefined(v){
    return typeof(v) != 'undefined';
}

function focusQty(frmname, index) {
	//if (document.all.frmCart.qty.length==1) {
	//alert("document.all.frmCart.qty.length is "+document.all.frmCart.qty.length+" and "+typeof document.all.frmCart.qty+ " and e is "+e);
	if (typeof frmname.qty.length == 'undefined'){
		frmname.qty.focus();
		frmname.qty.select();
	}
	else { 
		frmname.qty[index-1].focus();
		frmname.qty[index-1].select(); 
	}
}

function moveFocus(frmname,c, i, m) {
	if (c == 38) {
		if (i > 1)
			i = i - 1;
	}
	else if (c == 40) {
		if (i < m)
			i = i + 1;
	}
	else if (c == 13) {
		if (i < m)
			i = i + 1;
	}
	else
		return false;
	focusQty(frmname,i);
}
/*focusQty(frmname, e-1)*/

function checkArrows(frmname,e,emax) {
	var keyCode = window.event.keyCode;
	// DOWN arrow key pressed
	if (keyCode == 40) {
		// if cursor is in the first qty box
		if (e == 0) {
			focusQty(frmname, e-1)
		}
		else {
			focusQty(frmname, e);
		}
	}
		// UP arrow key pressed
	else if (keyCode == 38) {
		// if cursor is in the last qty box
		if (e == emax) {
			focusQty(frmname, e-1);
		}
		else {
			focusQty(frmname, e-2);
		}
	}
}

function MM_findObj(n, d) { //v3.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document); return x;
}

function MM_nbGroup(event, grpName) { //v3.0
  var i,img,nbArr,args=MM_nbGroup.arguments;
  if (event == "init" && args.length > 2) {
    if ((img = MM_findObj(args[2])) != null && !img.MM_init) {
      img.MM_init = true; img.MM_up = args[3]; img.MM_dn = img.src;
      if ((nbArr = document[grpName]) == null) nbArr = document[grpName] = new Array();
      nbArr[nbArr.length] = img;
      for (i=4; i < args.length-1; i+=2) if ((img = MM_findObj(args[i])) != null) {
        if (!img.MM_up) img.MM_up = img.src;
        img.src = img.MM_dn = args[i+1];
        nbArr[nbArr.length] = img;
    } }
  } else if (event == "over") {
    document.MM_nbOver = nbArr = new Array();
    for (i=1; i < args.length-1; i+=3) if ((img = MM_findObj(args[i])) != null) {
      if (!img.MM_up) img.MM_up = img.src;
      img.src = (img.MM_dn && args[i+2]) ? args[i+2] : args[i+1];
      nbArr[nbArr.length] = img;
    }
  } else if (event == "out" ) {
    for (i=0; i < document.MM_nbOver.length; i++) {
      img = document.MM_nbOver[i]; img.src = (img.MM_dn) ? img.MM_dn : img.MM_up; }
  } else if (event == "down") {
    if ((nbArr = document[grpName]) != null)
      for (i=0; i < nbArr.length; i++) { img=nbArr[i]; img.src = img.MM_up; img.MM_dn = 0; }
    document[grpName] = nbArr = new Array();
    for (i=2; i < args.length-1; i+=2) if ((img = MM_findObj(args[i])) != null) {
      if (!img.MM_up) img.MM_up = img.src;
      img.src = img.MM_dn = args[i+1];
      nbArr[nbArr.length] = img;
  } }
}
