function validRequired(formField,fieldLabel)
{
	var result = true;
	
	if (formField.value == "")
	{
		alert('Please enter a valid "' + fieldLabel +'" before submitting this form.');
		formField.focus();
		result = false;
	}
	
	return result;
}

function validateQA(theForm)
{
	// Customize these calls for your form

	// Start ------->
	if (!validRequired(theForm.email,"Email Address"))
		return false;
	if (!validRequired(theForm.q,"Question"))
		return false;
	// <--------- End
	
	return true;
}

function apply_coupon()
{
	window.document.forms.form_dave.stage.value=null;
	window.document.forms.form_dave.dave.value='C';
	window.document.forms.form_dave.submit();
}

function search_w()
{
	if (document.forms.auxilary.search_within.value.length > 0)
	{
		document.forms.search_form.search_string.value = document.forms.search_form.search_string.value + ' ' + document.forms.auxilary.search_within.value;
		//alert(document.forms.search_form.search_string.value);
		document.forms.search_form.submit();
	}
	else
	{
		alert('Please provide a search word to search within the results. Thank you.');
	}
	return false;
}

function insertBR()
{
		document.forms.dave_product.Body.focus();
		var selection = document.selection.createRange();
		selection.text = '<BR>';
		document.forms.dave_product.Body.focus();
		return;
}

function navigate(page)
{
	document.forms.change_page.pg.value=page;
	document.change_page.submit();
	return true;
}

function validate_search()
{
if (document.forms.search_forum.sPhrase.value.length == 0)
{
	alert('Please put a search phrase into the search box. Thank you.');
	return false;
}
else
{
	return true;
}
}

function validate_message_post()
{
	if (document.forms.add_msg.BBHomepageURL.value.length > 0)
		{
			if (document.forms.add_msg.BBHomepageName.value.length == 0)
				{
					alert('Please provide a Link Ttile for Internet Link. Both fields, Internet Link and Link Title, must be filled in for a link to appear.');
					return false;
				}
		}
	if (document.forms.add_msg.BBHomepageName.value.length > 0)
		{
			if (document.forms.add_msg.BBHomepageURL.value.length == 0)
				{
					alert('Please provide an Internet Link for Link Title. Both fields, Internet Link and Link Title, must be filled in for a link to appear.');
					return false;
				}
		}
	if (document.forms.add_msg.Subject.value.length == 0)
	{
		alert('"Subject" is a required field. Please fill it in.');
		return false;
	}

		if (document.forms.add_msg.BBName.value.length == 0)
	{
		alert('"Name" is a required field. Please fill it in.');
		return false;
	}

		if (document.forms.add_msg.BBEmail.value.length == 0)
	{
		alert('"Email" is a required field. Please fill it in.');
		return false;
	}

	return true;
}

function quick_find(pid)
{
		window.location=document.quick_finder.features[document.quick_finder.features.selectedIndex].value;
}

function openWindow(url, name, width, height) {
  popupWin = window.open(url, name, ',width=' + width + ',height=' + height +  ',status,resizable,scrollbars,left=25,right=25')
}


function ismax(name, max_val)
{
	var field = new String(document.forms.dave_product.elements(name).value);
	var replaceField = field.replace('"', '""');

	if (replaceField.length >= max_val)
		alert('Character limit(' + max_val + ') reached.');
}


function checkAll()
{
 for (var i=0;i<document.search_form.elements.length;i++)
{
  var e = document.search_form.elements[i];
  if ((e.name == 'Show_Only') && (e.type == 'checkbox'))
  {
  	e.checked = false;
  }
 }
}

function checkAll2()
{
 for (var i=0;i<document.search_form.elements.length;i++)
{
  var e = document.search_form.elements[i];
  if ((e.name == 'Limit_To') && (e.type == 'checkbox'))
  {
  	e.checked = false;
  }
 }
}

function uncheckSOI()
{
 for (var i=0;i<document.search_form.elements.length;i++)
{
  var e = document.search_form.elements[i];
  if ((e.name == 'Show_Only_Ind') && (e.type == 'checkbox'))
  {
  	e.checked = false;
  }
 }
}

function uncheckLTI()
{
 for (var i=0;i<document.search_form.elements.length;i++)
{
  var e = document.search_form.elements[i];
  if ((e.name == 'Limit_To_Ind') && (e.type == 'checkbox'))
  {
  	e.checked = false;
  }
 }
}

function checkCreditCard(object_value)
    {

	var white_space = " -";
	var creditcard_string="";
	var check_char;


    if (object_value.length = 0)
        return false;

	// squish out the white space
	for (var i = 0; i < object_value.length; i++)
	{
		check_char = white_space.indexOf(object_value.charAt(i))
		if (check_char < 0)
			creditcard_string += object_value.substring(i, (i + 1));
	}	

	// if all white space return error
    if (creditcard_string.length == 0 || creditcard_string.length < 13 || creditcard_string.length > 16)
        return false;
	 
	 	
	// make sure number is a valid integer
	if (creditcard_string.charAt(0) == "+")
        return false;

	if (!validInteger(creditcard_string))
		return false;

    // now check mod10

	var doubledigit = creditcard_string.length % 2 == 1 ? false : true;
	var checkdigit = 0;
	var tempdigit;

	for (var i = 0; i < creditcard_string.length; i++)
	{
		tempdigit = eval(creditcard_string.charAt(i))

		if (doubledigit)
		{
			tempdigit *= 2;
			checkdigit += (tempdigit % 10);

			if ((tempdigit / 10) >= 1.0)
			{
				checkdigit++;
			}

			doubledigit = false;
		}
		else
		{
			checkdigit += tempdigit;
			doubledigit = true;
		}
	}	
	return (checkdigit % 10) == 0 ? true : false;

    }

function validInteger(object_value)
    {
    //Returns true if value is a number or is NULL
    //otherwise returns false	

    if (object_value.length == 0)
        return true;

    //Returns true if value is an integer defined as
    //   having an optional leading + or -.
    //   otherwise containing only the characters 0-9.
	var decimal_format = ".";
	var check_char;

    //The first character can be + -  blank or a digit.
	check_char = object_value.indexOf(decimal_format)
    //Was it a decimal?
    if (check_char < 1)
	return validNumber(object_value);
    else
	return false;
    }


function validNumber(object_value)
    {
    //Returns true if value is a number or is NULL
    //otherwise returns false	

    if (object_value.length == 0)
        return true;

    //Returns true if value is a number defined as
    //   having an optional leading + or -.
    //   having at most 1 decimal point.
    //   otherwise containing only the characters 0-9.
	var start_format = " .+-0123456789";
	var number_format = " .0123456789";
	var check_char;
	var decimal = false;
	var trailing_blank = false;
	var digits = false;

    //The first character can be + - .  blank or a digit.
	check_char = start_format.indexOf(object_value.charAt(0))
    //Was it a decimal?
	if (check_char == 1)
	    decimal = true;
	else if (check_char < 1)
		return false;
        
	//Remaining characters can be only . or a digit, but only one decimal.
	for (var i = 1; i < object_value.length; i++)
	{
		check_char = number_format.indexOf(object_value.charAt(i))
		if (check_char < 0)
			return false;
		else if (check_char == 1)
		{
			if (decimal)		// Second decimal.
				return false;
			else
				decimal = true;
		}
		else if (check_char == 0)
		{
			if (decimal || digits)	
				trailing_blank = true;
        // ignore leading blanks

		}
	        else if (trailing_blank)
			return false;
		else
			digits = true;
	}	
    //All tests passed, so...
    return true
    }

function intParse(ivalue){
	if(isNaN(parseInt(ivalue, 10)))
		return true;
	if(parseInt(ivalue, 10) != ivalue)
			return true;
	return false;
}

function floatParse(fvalue){
	if(isNaN(parseInt(fvalue, 10)))
		return true;
	if(parseFloat(fvalue, 10) != fvalue)
		return true;
	return false;
}

function dateParse(dvalue){
	if(isNaN(Date.parse(dvalue))){
		alert('That is not a valid Date Format.');
		return true;
	}
	return false;
}

function openIT(querystring,W,H) {
	theURL=querystring
	wname ="CHROMELESSWIN"
	windowCERRARa 		= "images/close_a.gif"
	windowCERRARd 		= "images/close_d.gif"
	windowCERRARo 		= "images/close_o.gif"
	windowNONEgrf 		= "images/dot_clear.gif"
	windowCLOCK		= "images/clock.gif"
	windowREALtit		= " "
	windowTIT 	    	= "<font face=verdana size=1> </font>"
	windowBORDERCOLOR   	= "#006634"
	windowBORDERCOLORsel	= "#FFFFFF"
	windowTITBGCOLOR    	= "#006634"
	windowTITBGCOLORsel 	= "#006634"
	openchromeless(theURL, wname, W, H, windowCERRARa, windowCERRARd, windowCERRARo, windowNONEgrf, windowCLOCK, windowTIT, windowREALtit , windowBORDERCOLOR, windowBORDERCOLORsel, windowTITBGCOLOR, windowTITBGCOLORsel)
}

