function openProdList(DivID) {
	document.getElementById('productlist_'+DivID).style.display='block';
	document.getElementById('openlist_'+DivID).style.display='none';
	document.getElementById('closelist_'+DivID).style.display='block';
}

function closeProdList(DivID) {
	document.getElementById('productlist_'+DivID).style.display='none';
	document.getElementById('openlist_'+DivID).style.display='block';
	document.getElementById('closelist_'+DivID).style.display='none';
}

//checks to see if US or Canada selected - if selected sets StateProvince field label to required status
function checkCountry() {
 if(document.form1.Country.value=='US' || document.form1.Country.value=='CA') {
 document.getElementById('stateprov_reqd').style.display='inline';
 }
 else {
 document.getElementById('stateprov_reqd').style.display='none';
 }
}
//end


//selects the specified Product Area checkbox when user selects a product checkbox
function selectAreaCheckbox (AreaCheckboxID,ProdCheckboxID) {
	document.getElementById(AreaCheckboxID).checked = 'checked';
	for(i=0; i<ProductAreas.length; i++){
	document.getElementById('checkbox_'+ProductAreas[i]+'_1').style.background = '';
	document.getElementById('hdg_'+ProductAreas[i]).style.color = '#666666';
	}
}
//end

//selects the specified Product Area checkbox when user selects a product description
function textselectAreaCheckbox (AreaCheckboxID,ProdCheckboxID) {
	checkedStatus=document.getElementById(ProdCheckboxID).checked;
	if(checkedStatus==false){
	document.getElementById(AreaCheckboxID).checked = 'checked';
	}
	for(i=0; i<ProductAreas.length; i++){
	document.getElementById('checkbox_'+ProductAreas[i]+'_1').style.background = '';
	document.getElementById('hdg_'+ProductAreas[i]).style.color = '#666666';
	}
}
//end

//toggles the specified checkbox on/off when user selects related text label
function toggleCheckbox (CheckboxID) {
	checkedStatus=document.getElementById(CheckboxID).checked;
	if (checkedStatus==false) {
	document.getElementById(CheckboxID).checked = 'checked';
	}
	else {
	document.getElementById(CheckboxID).checked = '';
	}
	for(i=0; i<ProductAreas.length; i++){
	document.getElementById('checkbox_'+ProductAreas[i]+'_1').style.background = '';
	document.getElementById('hdg_'+ProductAreas[i]).style.color = '#666666';
	}
}
//end



//functions for Form validation
var defaultEmptyOK = false;
var mPrefix = "You did not enter a value into the ";
var mSuffix = " field. This is a required field. Please enter it now.";
var whitespace = " \t\n\r";
var iEmail = "This field must contain a valid e-mail address (eg. myname@yourcompany.com). Please re-enter it now."


function checkString (theField, s, emptyOK) {   
			// Next line is needed on NN3 to avoid "undefined is not a number" error
   // in equality comparison below.
   if (checkString.arguments.length == 2) emptyOK = defaultEmptyOK;
   if ((emptyOK == true) && (isEmpty(theField.value))) return true;
   if (isWhitespace(theField.value)) return warnEmpty (theField, s);
   else return true;
}


function isWhitespace (s) {   
var i;

    // Is s empty?
    if (isEmpty(s)) return true;

    // Search through string's characters one by one
    // until we find a non-whitespace character.
    // When we do, return false; if we don't, return true.

    for (i = 0; i < s.length; i++)
    {   
        // Check that current character isn't whitespace.
        var c = s.charAt(i);

        if (whitespace.indexOf(c) == -1) return false;
    }

    // All characters are whitespace.
    return true;
}


function isEmpty(s) {   
return ((s == null) || (s.length == 0));
}


// checkEmail (TEXTFIELD theField [, BOOLEAN emptyOK==false])
//
// Check that string theField.value is a valid Email.
//
// For explanation of optional argument emptyOK, see comments of function isInteger.
function IsValidEmail(elElement) {
	var strReturnValue	=	"";
	var strValue	= elElement.value;
	var emailExp = /[a-z0-9_\-\.]+@[a-z0-9_\-\.]+\.[a-z]{2,6}$/i;
	var emailExp1 = /@/i;
		
	if (strValue.search(emailExp1) == 0)
		strReturnValue = "The field email address can only contain alphanumeric characters, @ and period(.) and should be of the form myname@mycompany.com";

	if (strValue.search(emailExp) < 0)
		strReturnValue	=	"The field email address can only contain alphanumeric characters, @ and period(.) and should be of the form myname@mycompany.com";
		
	return strReturnValue;
}


function checkEmail (theField, emptyOK) {   
  if (checkEmail.arguments.length == 1) emptyOK = defaultEmptyOK;
  if ((emptyOK == true) && (isEmpty(theField.value))) return true;
  //!isEmail(theField.value, false)) 
  else if (IsValidEmail(theField) != "") return warnInvalid (theField, iEmail);
  else return true;
}


function warnEmpty (theField, s) {   
		theField.focus();
  alert(mPrefix + s + mSuffix);
  return false;
}


function warnInvalid (theField, s) {   
		theField.focus();
  theField.select();
  alert(s);
  return false;
}


function reviewCheckboxSelection() {
		for(i=0; i<ProductAreas.length; i++) {
			checkedStatus=document.getElementById('checkbox_'+ProductAreas[i]+'_1').checked;
			if (checkedStatus==true) break;
		}
		if(checkedStatus==true) return true;
		else return false;
}


function selectField (FieldID,FieldName) {
		document.getElementById('label_'+FieldID).style.color = '#cc0000';
		document.getElementById(FieldID).style.background = '#FAC8C9';
		document.getElementById(FieldID).style.color = '#cc0000';
		setTimeout("FieldName.focus()",100);
}


function deselectField (FieldID) {
		document.getElementById('label_'+FieldID).style.color = '#666666';
		document.getElementById(FieldID).style.background = '#eeeeee';
		document.getElementById(FieldID).style.color = '#666666';
}
//end