// JavaScript Document
// Live image upload path
var imagePath='Uploads/187/';

function showdetail(detail) {
	//document.elements[detail].class
	document.getElementById(detail).className = "showme";
}

function hidedetail(detail) {
	//document.elements[detail].class
	document.getElementById(detail).className = "hideme";
}

var inputCounter=6;
function addQuickOrderItem() {
	var theTable = document.getElementById("QuickOrderTable");
	var theErrorRow = theTable.insertRow(theTable.rows.length);
	theErrorRow.id = theErrorRow.uniqueID;
	var theRow = theTable.insertRow(theTable.rows.length);
	theRow.id = theRow.uniqueID;
	
	var theErrorBox = theErrorRow.insertCell(0);
	theErrorBox.colspan=2;
	theErrorBox.innerHTML='<variable strVariableName="strErrorMsg'+inputCounter+'">';
	
	var theSKUBox = theRow.insertCell(0);
	theSKUBox.id = theSKUBox.uniqueID;
	theSKUBox.innerHTML='<input type="text" name="strTFPID'+inputCounter+'" id="strTFPID'+inputCounter+'" value="" size="25" />';
	
	var theQtyBox = theRow.insertCell(1);
	theQtyBox.id = theQtyBox.uniqueID;
	theQtyBox.innerHTML='<input type="text" name="Qty'+inputCounter+'" id="Qty'+inputCounter+'" value="" size="4" />';

	inputCounter++;
}

function addMoreTextFields(tableName,blnShowFileField,fileList) {
	fieldHeadLeft = document.getElementById('head_left').value;
	fieldTextLeft = document.getElementById('text_left').value;
	fieldHeadRight = document.getElementById('head_right').value;
	fieldTextRight = document.getElementById('text_right').value;

	if (tableName == 'LeftColTable') {
		var leftHeading='<br />Heading (Max of xx characters)<br /><textarea class="heading_txtarea" name="heading_txtarea_l'+fieldHeadLeft+'"></textarea>&nbsp;<a href="javascript:void(0)" onclick="deleteRow(\'LeftColTable\',\'header\',this.parentNode.id)" class="image_x"><img src="'+imagePath+'images/shared/x.jpg" alt="Remove" width="12" height="12" border="0" /></a><br />';
		
		if (blnShowFileField == 1) {
			leftHeading += 'File<br /><select name="heading_file_'+fieldHeadLeft+'"><option value="">---CHOOSE FILE---</option>'+fileList+'</select><br /><br />';
		}
		else {
			leftHeading += '<br />';
		}
		var leftTextBlock='Text Block<br /><textarea class="txtblock_txtarea" name="txtblock_txtarea_l'+fieldTextLeft+'""></textarea> <a href="javascript:void(0)" onclick="deleteRow(\'LeftColTable\',\'textblock\',this.parentNode.id)" class="image_x"><img src="'+imagePath+'images/shared/x.jpg" alt="Remove" width="12" height="12" border="0" /></a><br />';
		addHeading(tableName,leftHeading,leftTextBlock,"left");
		document.getElementById('head_left').value = parseInt(fieldHeadLeft) + 1;
		document.getElementById('text_left').value = parseInt(fieldTextLeft) + 1;
	}
	else {
		var rightHeading='<br />Heading (Max of xx characters)<br /><textarea class="heading_txtarea" name="heading_txtarea_r'+fieldHeadRight+'"></textarea>&nbsp;<a href="javascript:void(0)" onclick="deleteRow(\'RightColTable\',\'header\',this.parentNode.id)" class="image_x"><img src="'+imagePath+'images/shared/x.jpg" alt="Remove" width="12" height="12" border="0" /></a><br /><br />';
		var RightTextBlock='Text Block<br /><textarea class="txtblock_txtarea" name="txtblock_txtarea_r'+fieldTextRight+'"></textarea> <a href="javascript:void(0)" onclick="deleteRow(\'RightColTable\',\'textblock\',this.parentNode.id)" class="image_x"><img src="'+imagePath+'images/shared/x.jpg" alt="Remove" width="12" height="12" border="0" /></a><br />';
		addHeading(tableName,rightHeading,RightTextBlock,"right");
		document.getElementById('head_right').value = parseInt(fieldHeadRight) + 1;
		document.getElementById('text_right').value = parseInt(fieldTextRight) + 1;
	}
}

function addHeading(tableName,heading,textBlock,fieldHead) {
	var theTable = document.getElementById(tableName);
	var len = theTable.rows.length;
	var theRow = theTable.insertRow(theTable.rows.length);
	if (fieldHead == 'left') { theRow.setAttribute("id","tr_l" + fieldHeadLeft + "h"); } else { theRow.setAttribute("id","tr_r" + fieldHeadRight + "h"); }
	
	var theInput = theRow.insertCell(0);
	if (fieldHead == 'left') { theInput.setAttribute("id","tr_l" + fieldHeadLeft + "h_td1"); } else { theInput.setAttribute("id","tr_r" + fieldHeadRight + "t_td1"); }
	
	theInput.innerHTML=heading;
	
	addTextBlock(tableName,textBlock,fieldHead);
}

function addTextBlock(tableName,textBlock,fieldHead) {
	var theTable = document.getElementById(tableName);
	var theRow = theTable.insertRow(theTable.rows.length);
	if (fieldHead == 'left') { theRow.setAttribute("id","tr_l" + fieldTextLeft + "t"); } else { theRow.setAttribute("id","tr_r" + fieldTextRight + "t"); }
	
	var theInput = theRow.insertCell(0);
	if (fieldHead == 'left') { theInput.setAttribute("id","tr_l" + fieldTextLeft + "t_td1"); } else {theInput.setAttribute("id","tr_r" + fieldTextRight + "t_td1"); }
	
	theInput.innerHTML=textBlock;
}


function deleteRow(tableName,fieldType,theCell) {
  var theRow = document.getElementById(theCell).parentNode.rowIndex;
  document.getElementById(tableName).deleteRow(theRow);
//	if (tableName == 'LeftColTable') {
//		if (fieldType == 'header')
//			document.getElementById('head_left').value = parseInt(fieldHeadLeft) - 1;
//		else
//			document.getElementById('text_left').value = parseInt(fieldTextLeft) - 1;
//	}
//	else {
//		if (fieldType == 'header')
//			document.getElementById('head_right').value = parseInt(fieldHeadRight) - 1;
//		else
//			document.getElementById('text_right').value = parseInt(fieldTextRight) - 1;
//	}
}

function flip_arrow(theArrow){
	var source_check=document[theArrow].src;
	if (source_check.match('arrow_brown_side.gif')) {
		document[theArrow].src=imagePath+'images/shared/arrow_brown_down.gif';
		document.getElementById('sidebar_cart').innerHTML='<table width="145" cellpadding="0" cellspacing="0" border="0" class="table" id="SidebarCartTable"><tr><td></td></tr></table><table width="145" cellpadding="0" cellspacing="0" border="0" class="table"><tr><td align="right"><b>total '+SidebarCartTotal+'</b></td></tr></table>';
		printSidebarCart();
	}
	else {
		document[theArrow].src=imagePath+'images/shared/arrow_brown_side.gif';
		document.getElementById('sidebar_cart').innerHTML='<table width="145" cellpadding="0" cellspacing="0" border="0" class="table"><tr><td align="left"><a href="shoppingbasket.cfm">'+SidebarCartItemCount+' items</a></td><td align="right"><a href="shoppingbasket.cfm">total '+SidebarCartTotal+'</a></td></tr></table>';
		sidebarRowSeq=1;
	}
}

function flip_setup_arrow(theArrow){
	var source_check=document[theArrow].src;
	if (source_check.match('arrow_brown_side.gif')) {
		document[theArrow].src=imagePath+'images/shared/arrow_brown_down.gif';
		document.getElementById('sidebar_setup').innerHTML='<table width="145" cellpadding="0" cellspacing="0" border="0" class="table"><tr><td align="left"><a href="setupa.cfm">Wizard</a><br /><a href="setup_accent.cfm">Accent</a><br /><a href="setup_logoname.cfm">Logo / Name</a><br /><a href="setup_contactinfo.cfm">Contact Information</a><br /><a href="setup_contactus.cfm">Contact Us</a><br /><a href="setup_reminders.cfm">Marketing / Reminders</a><br /><a href="setup_aboutus.cfm">About Us</a><br /><a href="setup_template.cfm">Template</a></td></tr></table>';
		setCookie('sidebarSetup','yes',30)
	}
	else {
		document[theArrow].src=imagePath+'images/shared/arrow_brown_side.gif';
		document.getElementById('sidebar_setup').innerHTML='';
		setCookie('sidebarSetup','no',30)
	}
}

function writeSidebarLink(subsite,outputStr) {
	if (!(subsite=='No'))
		document.write(outputStr);
}

// Begin sidebar site setup collapse/expand cookie functions
function setCookie(c_name,value,expiredays) {
	var exdate=new Date()
	exdate.setDate(exdate.getDate()+expiredays)
	document.cookie=c_name+ "=" +escape(value)+
	((expiredays==null) ? "" : ";expires="+exdate.toGMTString())
}

function getCookie(c_name) {
	if (document.cookie.length>0) {
		c_start=document.cookie.indexOf(c_name + "=")
		if (c_start!=-1) { 
			c_start=c_start + c_name.length+1 
			c_end=document.cookie.indexOf(";",c_start)
			if (c_end==-1) c_end=document.cookie.length
				return unescape(document.cookie.substring(c_start,c_end))
		} 
	}
	return ""
}

function checkSetupCookie(theArrow) {
	if(document[theArrow]){	
		sidebarSetup=getCookie('sidebarSetup')
		if (sidebarSetup!=null && sidebarSetup!="") {
			if (sidebarSetup=='yes') {
				document[theArrow].src=imagePath+'images/shared/arrow_brown_down.gif';
				document.getElementById('sidebar_setup').innerHTML='<table width="145" cellpadding="0" cellspacing="0" border="0" class="table"><tr><td align="left"><a href="setupa.cfm">Wizard</a><br /><a href="setup_accent.cfm">Accent</a><br /><a href="setup_logoname.cfm">Logo / Name</a><br /><a href="setup_contactinfo.cfm">Contact Information</a><br /><a href="setup_contactus.cfm">Contact Us</a><br /><a href="setup_reminders.cfm">Marketing / Reminders</a><br /><a href="setup_aboutus.cfm">About Us</a><br /><a href="setup_template.cfm">Template</a></td></tr></table>';
			}
			else {
				document[theArrow].src=imagePath+'images/shared/arrow_brown_side.gif';
				document.getElementById('sidebar_setup').innerHTML='';
			}
		}
		else  {
			document[theArrow].src=imagePath+'images/shared/arrow_brown_side.gif';
			document.getElementById('sidebar_setup').innerHTML='';
			setCookie('sidebarSetup',sidebarSetup,30)
		}
	}
}
// End sidebar site setup collapse/expand cookie functions

function formatCurrency(num) {
	num = num.toString().replace(/\$|\,/g,"");
	if(isNaN(num))
		num = "0";
	var sign = (num == (num = Math.abs(num)));
	num = Math.floor(num*100+0.50000000001);
	var cents = num%100;
	num = Math.floor(num/100).toString();
	if(cents<10)
	cents = "0" + cents;
	for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
		num = num.substring(0,num.length-(4*i+3))+','+
		num.substring(num.length-(4*i+3));
	return (((sign)?"":'-') + '$' + num + '.' + cents);
}

var sidebarRowSeq = 1;

function newCell(row,html,cssclass,align){
  var cell = row.insertCell(-1);
  cell.innerHTML = html;
//  if (cell.className)
    cell.setAttribute("className", cssclass);
//  else
    cell.setAttribute("class",cssclass);
  if (align!=null && align.length > 0)
    cell.style.textAlign = align;
  return cell;
}

function printItemSidebar(item, seq){
	var row = document.getElementById('SidebarCartTable').insertRow(sidebarRowSeq);  
	sidebarRowSeq++;
	
	// Item Number
	//newCell(row,"<a href='/shoppingbasket.cfm?strAction=EDITITEM&intSequence=" + seq + "/'></div>" + item[0] + "</a>","","left");
	newCell(row,item[0],"sidebar_cart_item","left");

	var unitPrice = 0;
	var quantity = parseInt(item[2]);
	var extendedPrice = parseFloat(item[3]);
	
	if (quantity > 0 && extendedPrice >0)
	unitPrice = extendedPrice / quantity;
	
	// Unit Price
	newCell(row,formatCurrency(unitPrice),"sidebar_cart_item","right");  
}

function printSidebarCart(){
	if (arySC.length){
	  for(var i=0;i<arySC.length;i++){
		printItemSidebar(arySC[i], i+1);
	  }
	}
	else {
		var row = document.getElementById('SidebarCartTable').insertRow(0);
		newCell(row,"no items","sidebar_cart_item","left");
	}
}

function submit_quick_order(destination){
	if (destination=='checkout') {
		document.getElementById('strReturnToURL').value='shoppingbasket.cfm';
		document.quick_order_frm.submit();
	}
	else {
		document.getElementById('strReturnToURL').value='engine.cfm';
		document.quick_order_frm.submit();		
	}
}

function resizeImages(pics,title,description,messages){
	for (i=0; i<title.length; i++) {
		var newImg = new Image();
		newImg.src = pics[i];
		var theHeight = newImg.height;
		var theWidth = newImg.width;
		if((theHeight>100) || (theWidth||100)){
			if(theWidth>theHeight){
				var ratio=100/theWidth;
				theHeight=theHeight*ratio;
				theHeight=Math.round(theHeight);
				theWidth=100;
			}
			else if(theHeight>theWidth){
				var ratio=100/theHeight;
				theWidth=theWidth*ratio;
				theWidth=Math.round(theWidth);
				theHeight=100;
			}
			else{ //height=width
				theHeight=100;
				theWidth=100;
			}
		}
		var finalImage='<img class="product_image" src="'+pics[i]+'" width="'+theWidth+'" height="'+theHeight+'" alt="image" border="0" align="left" />';
		messages.push();
		messages[i] = new Array(title[i],finalImage+description[i]);
	}
}

// Begin Order History scripts
function check_order_history(objForm)
{
	var strReqMsg = "";
	var strValidationMsg = "";

	if(objForm.ldtDateBefore.value.length
		&& ! isDate(objForm.ldtDateBefore.value))
	{ strValidationMsg += "    - To Date must be a valid date\n"; }
					
	if(objForm.ldtDateAfter.value.length
		&& ! isDate(objForm.ldtDateAfter.value))
	{ strValidationMsg += "    - From Date must be a valid date\n"; }

	// Assemble all of the error messates together to display to the user
	if(strReqMsg.length || strValidationMsg.length)
	{
		var strDisplay = "";
		if(strReqMsg.length)
		{ strDisplay += "The following fields are required to be completed:\n\n" + strReqMsg; }

		if(strValidationMsg.length)
		{ strDisplay += "The following fields are not filled in correctly:\n\n" + strValidationMsg; }

		alert(strDisplay);
		return false;
	}
	else
	{
		return true;
	}
}
// End Order History scripts

function isNumeric(strValue)
{
	// sChar will hold the current character
	var strChar = "";
	// bNumeric is set to false when a bad character is encountered
	var blnNumeric = true;
	var intDecimalPointsFound = 0;

	// Loop through each of the characters in the string
	for(intIndex = 0; intIndex < strValue.length; intIndex++)
	{
		// Get the character at the current index
		strChar = strValue.charAt(intIndex);
		// If the first character is a '-' and it isn't the only character
		if((strChar == "-" && intIndex == 0 && strValue.length > 1))
		{
			blnNumeric = true;
		}
		// If the character is not a number and is not a '.', we can't allow it
		else if(isNaN(parseInt(strChar)) && strChar != ".")
		{
			blnNumeric = false;
			// Early exit
			intIndex = strValue.length;
		}
		else if(strChar == ".")
		{
			intDecimalPointsFound++;
		}
	}

	if(intDecimalPointsFound > 1 || intDecimalPointsFound == strValue.length)
	{
		blnNumeric = false;
	}

	return blnNumeric;
}
	
function isDate(dateStr) {
var datePat = /^(\d{1,2})(\/)(\d{1,2})(\/)(\d{4})$/;
var matchArray = dateStr.match(datePat); // is the format ok?

if (matchArray == null) {
return false;
}
else {
	month = matchArray[1]; // p@rse date into variables
	day = matchArray[3];
	year = matchArray[5];
	
	if (month < 1 || month > 12) { // check month range
	return false;
	}
	
	if (day < 1 || day > 31) {
	return false;
	}
	
	if ((month==4 || month==6 || month==9 || month==11) && day==31) {
	return false;
	}
	
	if (month == 2) { // check for february 29th
	var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
	if (day > 29 || (day==29 && !isleap)) {
	return false;
	}
	}
	
	if (year < 1900) {
	return false;
	}
	return true; // date is valid
  }
}

function isEmail(strValue) {
	return /^[-!#\$%\*\+\/\?\|\^&{}`~\w]+(\.[-!#\$%\*\+\/\?\|\^&{}`~\w]+)*@[-\w]+(\.[-\w]+)+$/.test(strValue);
} 

function ValidatePhone(objPhone) {
	var strPhoneTxt = objPhone.value.replace(/\s+/g, "");
	var intPhoneLen = strPhoneTxt.length;
	var strTemp = "";
	var intTempLen = 0;
	var strFormatted = "";
	for(var i = 0; i < intPhoneLen; i++) {
		idxChar = strPhoneTxt.charAt(i);
		if(!isNaN(idxChar)) {
			strTemp = strTemp + idxChar;
		}
	}
	if(strTemp.length > 10) {
		strTemp = strTemp.substring(0,10);
	}
	if(strTemp.length > 0) {
		strFormatted = strFormatted + '(';
		if(strTemp.length > 3) {
			strFormatted = strFormatted + strTemp.substring(0,3) + ') ';
			strTemp = strTemp.substring(3);
			if(strTemp.length > 3) {
				strFormatted = strFormatted + strTemp.substring(0,3) + '-' + strTemp.substring(3);
			}
			else {
				strFormatted = strFormatted + strTemp.substring(0);
				if(strFormatted.length == 9) {
					strFormatted = strFormatted + '-';
				}
			}
		}
		else {
			strFormatted = strFormatted + strTemp.substring(0);
			if(strFormatted.length == 4) {
				strFormatted = strFormatted + ') ';
			}
		}
	}
	objPhone.value = strFormatted;
}

function pauseThenValidate(objPhone) {
	this.phone=objPhone;
	self.setTimeout('ValidatePhone(this.phone)', 1500);
}

function isPhone(strPhone)
{
	var blnIsPhone = true;

	// if it is 12 chars it must be in the format xxx-xxx-xxxx
	if(strPhone.length == 12)
	{
		// loop over each char in the string
		for(i = 0; i < 12; i++)
		{
			// all positions other than 3 & 7 must be a number
			if(i != 3 && i != 7)
			{
				if(isNaN(strPhone.charAt(i)))
				{
					blnIsPhone = false;
				}
			}
			// positions 3 & 7 must be a '-'
			else if(strPhone.charAt(i) != "-")
			{
				blnIsPhone = false;
			}
		}

	}
	// else it must be in the format (xxx) xxx-xxxx
	else if(strPhone.length == 14)
	{
		// all other chars must be numbers
		for(i = 0; i < 14; i++)
		{
			c = strPhone.charAt(i);
			// Position zero must be a (
			if(i == 0 && c != "(")
			{
				blnIsPhone = false;
			}
			// Position four must be a )
			else if(i == 4 && c != ")")
			{
				blnIsPhone = false;
			}
			// Position five must be a space
			else if(i == 5 && c != " ")
			{
				blnIsPhone = false;
			}
			// Position nine must be a -
			else if(i == 9 && c != "-")
			{
				blnIsPhone = false;
			}
			// All other positions must be a number
			else if((i != 0 && i != 4 && i != 5 && i != 9)
				&& isNaN(c))
			{
				blnIsPhone = false;
			}
		}
	}
	// If the length of the phone number isn't 12 or 14, we automatically know it's not a phone number
	else
	{
		blnIsPhone = false;
	}

	return blnIsPhone;
}

function swap_radio_buttons(uncheck_it,set_it,set_value){
	document.frm.elements[uncheck_it].checked=false;
	document.frm.elements[set_it].value=set_value;
}

function check_become_a_dealer(objForm) {
	var strReqMsg = "";
	var strValidationMsg = "";
				
	if(objForm.bill_strCompany.value.replace(/\s+/g, "") == "")
	{ strReqMsg += "    - Billing - Company\n"; }

	if(objForm.bill_strContactPerson.value.replace(/\s+/g, "") == "")
	{ strReqMsg += "    - Billing - Contact Person\n"; }

	if(objForm.bill_strStreetAddr1.value.replace(/\s+/g, "") == "")
	{ strReqMsg += "    - Billing - Street Address 1\n"; }

	if(objForm.bill_strCity.value.replace(/\s+/g, "") == "")
	{ strReqMsg += "    - Billing - City\n"; }

	if(objForm.bill_strState.value.replace(/\s+/g, "") == "")
	{ strReqMsg += "    - Billing - State/Province\n"; }

	if(objForm.bill_strCountry.value.replace(/\s+/g, "") == "")
	{ strReqMsg += "    - Billing - Country\n"; }

	if(objForm.bill_strPostalCode.value.replace(/\s+/g, "") == "")
	{ strReqMsg += "    - Billing - Zip/Postal Code\n"; }

	if(objForm.bill_strEmailAddress.value.replace(/\s+/g, "") == "")
	{ strReqMsg += "    - Billing - Email Address\n"; }

	if(objForm.bill_strEmailAddress.value.length && !(isEmail(objForm.bill_strEmailAddress.value)))
	{ strValidationMsg += "    - Billing - Email Address must be a well-formed email address\n"; }
	
	if(objForm.bill_strPhoneNumber.value.replace(/\s+/g, "") == "")
	{ strReqMsg += "    - Billing - Phone Number\n"; }

	if(objForm.bill_strPhoneNumber.value.length && !(isPhone(objForm.bill_strPhoneNumber.value)))
	{ strValidationMsg += "    - Billing - Phone Number must be a valid phone number\n"; }
	
	if(objForm.bill_strSalesTaxID.value.replace(/\s+/g, "") == "")
	{ strReqMsg += "    - Billing - Sales Tax ID\n"; }

	if(objForm.gen_strBusinessType.value.replace(/\s+/g, "") == "")
	{ strReqMsg += "    - General - Business Type\n"; }

	if(objForm.gen_strStateOfIncorp.value.replace(/\s+/g, "") == "")
	{ strReqMsg += "    - General - State of Incorporation\n"; }

	if(objForm.gen_strPrincipal1.value.replace(/\s+/g, "") == "")
	{ strReqMsg += "    - General - Principal 1\n"; }

	if(objForm.gen_strTitle1.value.replace(/\s+/g, "") == "")
	{ strReqMsg += "    - General - Title 1\n"; }

	if(objForm.gen_strHomeOffice.value.replace(/\s+/g, "") == "")
	{ strReqMsg += "    - General - Home Office\n"; }

	if(objForm.gen_strAddress.value.replace(/\s+/g, "") == "")
	{ strReqMsg += "    - General - Address\n"; }

	if(objForm.gen_strAmtOfCreditRequested.value.replace(/\s+/g, "") == "")
	{ strReqMsg += "    - General - Amount of Credit Line Requested\n"; }

	if(objForm.ref_strBank1.value.replace(/\s+/g, "") == "")
	{ strReqMsg += "    - References - Bank 1\n"; }

	if(objForm.ref_strBank1Addr.value.replace(/\s+/g, "") == "")
	{ strReqMsg += "    - References - Bank 1 Address\n"; }

	if(objForm.ref_strBank1Phone.value.replace(/\s+/g, "") == "")
	{ strReqMsg += "    - References - Bank 1 Phone\n"; }

	if(objForm.ref_strBank1Phone.value.length && !(isPhone(objForm.ref_strBank1Phone.value)))
	{ strValidationMsg += "    - References - Bank 1 Phone must be a valid phone number\n"; }
	
	if(objForm.ref_strBank1Fax.value.length && !(isPhone(objForm.ref_strBank1Fax.value)))
	{ strValidationMsg += "    - References - Bank 1 Fax must be a valid phone number\n"; }
	
	if(objForm.ref_strBank2Phone.value.length && !(isPhone(objForm.ref_strBank2Phone.value)))
	{ strValidationMsg += "    - References - Bank 2 Phone must be a valid phone number\n"; }
	
	if(objForm.ref_strBank2Fax.value.length && !(isPhone(objForm.ref_strBank2Fax.value)))
	{ strValidationMsg += "    - References - Bank 2 Fax must be a valid phone number\n"; }
	
	if(objForm.ref_strSupplier1Phone.value.length && !(isPhone(objForm.ref_strSupplier1Phone.value)))
	{ strValidationMsg += "    - References - Supplier 1 Phone must be a valid phone number\n"; }
	
	if(objForm.ref_strSupplier1Fax.value.length && !(isPhone(objForm.ref_strSupplier1Fax.value)))
	{ strValidationMsg += "    - References - Supplier 1 Fax must be a valid phone number\n"; }
	
	if(objForm.ref_strSupplier2Phone.value.length && !(isPhone(objForm.ref_strSupplier2Phone.value)))
	{ strValidationMsg += "    - References - Supplier 2 Phone must be a valid phone number\n"; }
	
	if(objForm.ref_strSupplier2Fax.value.length && !(isPhone(objForm.ref_strSupplier2Fax.value)))
	{ strValidationMsg += "    - References - Supplier 2 Fax must be a valid phone number\n"; }
	
	if(objForm.ref_strSupplier3Phone.value.length && !(isPhone(objForm.ref_strSupplier1Phone.value)))
	{ strValidationMsg += "    - References - Supplier 3 Phone must be a valid phone number\n"; }
	
	if(objForm.ref_strSupplier3Fax.value.length && !(isPhone(objForm.ref_strSupplier3Fax.value)))
	{ strValidationMsg += "    - References - Supplier 3 Fax must be a valid phone number\n"; }
	
	if(objForm.cert_rdoIAgree.value.replace(/\s+/g, "") == "")
	{ strReqMsg += "    - Certification - You must agree to the certification and authorization to release information terms\n"; }
	
	if(objForm.cert_strCompany.value.replace(/\s+/g, "") == "")
	{ strReqMsg += "    - Certification - Company\n"; }
	
	if(objForm.cert_strContact.value.replace(/\s+/g, "") == "")
	{ strReqMsg += "    - Certification - Contact\n"; }
	
	if(objForm.cert_strTitle.value.replace(/\s+/g, "") == "")
	{ strReqMsg += "    - Certification - Title\n"; }

	if(objForm.cert_strDate.value.replace(/\s+/g, "") == "")
	{ strReqMsg += "    - Certification - Date\n"; }

	if(objForm.cert_strDate.value.length && !(isDate(objForm.cert_strDate.value)))
	{ strValidationMsg += "    - Certification - Date must be a valid date\n"; }

// Assemble all of the error messates together to display to the user
	if(strReqMsg.length || strValidationMsg.length)
	{
		var strDisplay = "";
		if(strReqMsg.length)
		{ strDisplay += "The following fields are required to be completed:\n\n" + strReqMsg +"\n\n"; }

		if(strValidationMsg.length)
		{ strDisplay += "The following fields are not filled in correctly:\n\n" + strValidationMsg; }

		alert(strDisplay);
		return false;
	}
	else
	{
		return true;
	}
}

// Begin Form Finder functions
function choose_formfinder_action() {
	var whereToGo=document.getElementById('step1').value;
	if(whereToGo=='TaxForms')
		document.frm.action="formfinder.cfm";
	else if(whereToGo=='HCFA')
		document.frm.action="engine.cfm?strTFPType=HCFA";
	else
		document.frm.action="engine.cfm?strTFPType=ImpExp";
	document.frm.submit();
}
// End Form Finder functions

function submitForm(formName) {
	document.getElementById(formName).submit();
}

function forgotPassword() {
	document.frmSignIn.strMembershipAction.value='ForgotPassword'; 
	document.frmSignIn.submit(); 
	return false;	
}

function confirmIt(){
	var x=window.confirm("Are you sure you would like to save and apply?")
	if (x)
		return true;
	else
		return false;
}

function clearFillSearch(clear,message){
	if (clear)
		document.getElementById('searchon').value='';
	else if (!(clear) && (document.getElementById('searchon').value==''))
		document.getElementById('searchon').value=message;
	else {} // Do Nothing
}

function popUp(page, w, h, sbars) {
	window.open(page, "PopUp","toolbar=no,location=no,directories=no,status=no,menubar=yes,scrollbars="+sbars+",resizable=yes,copyhistory=no,width="+w+",height="+h+",top=0,left=0");
}
