
// just some minor bot prevention
function submitForm(theForm, theAction) {
	if (theForm) {
		theForm.action = theAction;
		theForm.validationKey.value = "submitted";
		theForm.submit();
	}
}	

function scrubNonDigits(theElement, forceZero, allowDecimal) {
	if (allowDecimal) {
		theElement.value = theElement.value.replace(/[^\d.]/g, '');
	}
	else {
		theElement.value = theElement.value.replace(/[^\d]/g, '');
	}
	
	if (forceZero && (theElement.value == '' || theElement.value == null)) {
		theElement.value = '0';
	}
}

/************** Popup Functions *******************/
function popupLoanCalculator(amount) {
	var loanURL = "loan_calculator.php?amount="+amount;
	var newWindow = open(loanURL, "LoanPopup", "width=350,height=300,scrollbars=no,resizable=yes,toolbar=no,menubar=no,titlebar=no,status=no,screenX=0,screenY=0");
}

function popupPricing(url) {
	var pricingURL = "pricing_popup.php?d_url="+url;
	var newWindow = open(pricingURL, "PricingPopup", "width=800,height=700,scrollbars=yes,resizable=yes,toolbar=no,menubar=no,titlebar=no,status=no,screenX=0,screenY=0");
}

function popupScheduleMaster() {
	//var schedMasterURL = "http://www.schedulemaster.com/smlogin.htm";
	//var schedMasterURL = "http://209.181.6.59/";
	//var schedMasterURL = 'http://209.181.6.59:13161/fcms1.aspx';
	var schedMasterURL = 'http://s08.myfbo.com/link.asp?fbo=sumt';
	var newWindow = open(schedMasterURL, "SchedMasterPopup", "width=850,height=600,scrollbars=yes,resizable=yes,toolbar=no,menubar=no,titlebar=no,status=no,screenX=0,screenY=0");
}

function hover(who, baseClass, what) { 
	var current; 
	eval('current = who.className.match(/(Sel)?'+baseClass+'(Hover)?/);'); 
	current = current[0]; 
	if(what && current && current.search(/Hover$/) == -1) {
		eval('who.className = who.className.replace(/'+current+'/, "'+current+'Hover");'); 
	} else if(!what && current && current.search(/Hover$/) != -1) {
		eval('who.className = who.className.replace(/'+current+'/, "'+current.replace(/Hover$/, '')+'");'); 
	}
}

/************** Printing functions *******************/
function copyPrintableContents(fromElementID, toElementID) {
	// transfer the stuff we want to print into the printable area
	var printContents = document.getElementById(fromElementID);
	var printableArea = document.getElementById(toElementID);
	if (printContents && printableArea) {
		// copy it over
		var theInnerHTML = printContents.innerHTML;
		printableArea.innerHTML = theInnerHTML;
	}
}

function fixPNG(who) {
	var isIE = (navigator.appName == "Microsoft Internet Explorer" && navigator.userAgent.indexOf('Opera') == -1);
	if(isIE) {
		// filter for MSIE 6.x and 5.5
		var ie6xFilter = /^.*MSIE [6]\.[0-9].*$/;
		var ie55Filter = /^.*MSIE [5].*$/;
		
		if(ie6xFilter.test(navigator.userAgent) || ie55Filter.test(navigator.userAgent)) {
			who.onload = function(){}
			who.style.filter = 'progid:DXImageTransform.Microsoft.AlphaImageLoader(src='+who.src+')';
			who.src = 'images/pixel.gif';
		}
	}
}

/************* PNG for IE **************************/
function outputPNG(imgSource, width, height, title) {	
	var isIE = (navigator.appName == "Microsoft Internet Explorer" && navigator.userAgent.indexOf('Opera') == -1);
	if(isIE) {
		// filter for MSIE 6.x and 5.5
		var ie6xFilter = /^.*MSIE [6]\.[0-9].*$/;
		var ie55Filter = /^.*MSIE [5].*$/;
		if (ie6xFilter.test(navigator.userAgent) || ie55Filter.test(navigator.userAgent)) {
			document.write('<img src="images/pixel.gif" style="filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src='+imgSource+');" width="'+width+'" height="'+height+'" alt="'+title+'" title="'+title+'">');
		}
		else {
			document.write('<img src="'+imgSource+'"  width="'+width+'" height="'+height+'" alt="'+title+'" title="'+title+'">');	 
		}
	}
	else {
		document.write('<img src="'+imgSource+'"  width="'+width+'" height="'+height+'" alt="'+title+'" title="'+title+'">');	 
	}
}

function toggleJTechComments() {
	var jtechComments = document.getElementById('jtechCommentsContainer');
	
	if(jtechComments) {	
		jtechComments.style.display = jtechComments.style.display == 'block' ? 'none' : 'block';
	}
}

function updateHowFoundDisplay(selectElement) {
	// see what value was selected
	var selectedValue = selectElement.value;
	var howFoundOtherDisplay = document.getElementById('howFoundOtherDisplay');
	if (howFoundOtherDisplay) {
		if (selectedValue == 'Other') {
			// show it
			howFoundOtherDisplay.style.display = 'block';
		}
		else {
			// hide it
			howFoundOtherDisplay.style.display = 'none';
			// and clear out the value
			var howFoundOther = document.getElementById('howFoundOther');
			if (howFoundOther) {
				howFoundOther.value = "";
			}
		}
	}
}

/* adwords */
document.jtAdConversion = function(conversionId) {
	var iframeHtml = '<html><head></head>';
	iframeHtml += '<body onload="if(window.parent.document.jtAdConversionEnd) {window.parent.document.jtAdConversionEnd();}">';
		iframeHtml += '<script language="JavaScript" type="text/javascript">';
			iframeHtml += 'var google_conversion_id = '+conversionId+';';
			iframeHtml += 'var google_conversion_language = "en_US";';
			iframeHtml += 'var google_conversion_format = "1";';
			iframeHtml += 'var google_conversion_color = "666666";';
			iframeHtml += 'var google_conversion_value = 1;';
			iframeHtml += 'var google_conversion_label = "LEAD";';
		iframeHtml += '</script>';
		iframeHtml += '<script language="JavaScript" src="http://www.googleadservices.com/pagead/conversion.js"></script>';
	iframeHtml += '</body>';
	iframeHtml += '</html>';
	
	document.jtAdConversionIframe = document.createElement('iframe');
	document.jtAdConversionIframe.style.width = '0px';
	document.jtAdConversionIframe.style.height = '0px';
	document.jtAdConversionIframe.style.visibility = 'hidden';
	
	document.body.appendChild(document.jtAdConversionIframe);
	
	var doc = document.jtAdConversionIframe.contentWindow.document;
	
	doc.open();
	doc.write(iframeHtml);
	doc.close();
}

document.jtAdConversionEnd = function() {
	if(document.jtAdConversionIframe) {
		document.jtAdConversionIframe.parentNode.removeChild(document.jtAdConversionIframe);
		document.jtAdConversionIframe = null;
	}
}
/* end adwords */
