﻿// Javascript Document

function CheckCallToQuote() {
	var form = document.QuoteForm;
	var details = document.getElementById("productDetails");
	if (form && details) {
		if (form.cbCallToQuote.checked) {
			details.style.display = 'none';
		} else {
			details.style.display = '';
		}
	}
}

function ValidatePrimaryPhone(source, args) {
	var form = document.QuoteForm;
	if (form && form.txtPriPhoneAreaCode && form.txtPriPhonePrefix) {
		if (form.txtPriPhoneAreaCode.value.length > 0 && form.txtPriPhonePrefix.value.length > 0 && args.Value.length > 0) {
			if (form.txtPriPhoneAreaCode.value.match(/^[0-9]{3}$/) && form.txtPriPhonePrefix.value.match(/^[0-9]{3}$/) && args.Value.match(/^[0-9]{4}$/)) args.IsValid = true;
			else args.IsValid = false;
		} else args.IsValid = false;
	}
	return;
}

function ValidateTemplate(source, args) {
	var form = document.QuoteForm;
	if (form && form.cbCallToQuote.checked) args.IsValid = true;
	else if (form && form.lbCategory && form.lbProduct) {
		if (form.lbCategory.selectedIndex > -1 && form.lbProduct.selectedIndex > -1) args.IsValid = true;
		else args.IsValid = false;
	} else args.IsValid = false;
	return;
}

function ValidateQuantity(source, args) {
	var form = document.QuoteForm;
	if (form && form.cbCallToQuote) {
		if (form.cbCallToQuote.checked) args.IsValid = true;
		else if (form.txtQuantity.value.match(/^\d+$/)) args.IsValid = true;
		else args.IsValid = false;
	} else args.IsValid = false;
}

function ValidateQuantityAmount(source, args) {
	var form = document.QuoteForm;
	if (form && form.cbCallToQuote) {
		if (form.cbCallToQuote.checked) args.IsValid = true;
		else if (parseInt(form.txtQuantity.value) < 2000) args.IsValid = false;
		else args.IsValid = true;
	} else args.IsValid = false;
}

function ValidatePaperStock(source, args) {
	var form = document.QuoteForm;
	if (form && form.cbCallToQuote) {
		if (form.cbCallToQuote.checked) args.IsValid = true;
		else if (args.Value.length == 0) args.IsValid = false;
		else args.IsValid = true;
	} else args.IsValid = false;
}

function ValidateCoating(source, args) {
	var form = document.QuoteForm;
	if (form && form.cbCallToQuote) {
		if (form.cbCallToQuote.checked) args.IsValid = true;
		else if (args.Value.length == 0) args.IsValid = false;
		else args.IsValid = true;
	} else args.IsValid = false;
}

// Automatically tab to the specified field when the current field reaches a certain length
function autotab(original,destination){
	if (original.getAttribute&&original.value.length==original.getAttribute("maxlength")) {
		// Added next two lines to make autotab less "glitchy" when back-tabbing/correcting
		original.onkeyup = '';  // Required for IE (ignores removeAttribute)
		original.removeAttribute('onkeyup');
		destination.focus();
	}
}

window.onload = CheckCallToQuote;