//javascript buttons
var iName=""; 
var nav=navigator.appName.indexOf("Netscape"); 
var vers=parseInt(navigator.appVersion);
  if ( (nav != -1 && vers >= 3) || (vers == 4) ) {
	default1 = new Image(); default1.src = "images/button_drawing.jpg"
	changed1 = new Image(); changed1.src = "images/button_drawing_d.jpg"
	default2 = new Image(); default2.src = "images/button_photo.jpg"
	changed2 = new Image(); changed2.src = "images/button_photo_d.jpg"
	default3 = new Image(); default3.src = "images/button_sequence.jpg"
	changed3 = new Image(); changed3.src = "images/button_sequence_d.jpg"
  }
  function Ichange(p) {
    if ( (nav != -1 && vers >= 3) || (vers == 4) ) {
    var pSrc=eval(p+ ".src");
    document[iName].src = pSrc;
    }
  }

//popup window
function openpopup(file,w,h){
winpops=window.open(file,"","width="+ (w*1.2) +",height="+ (h*1.2) +",status,scrollbars,resizable,")
}
  
  // ** Form field Limiter Script ** 
var ns6=document.getElementById&&!document.all

function restrictinput(maxlength,e,placeholder){
	if (window.event&&event.srcElement.value.length>=maxlength)
		return false
	else if (e.target&&e.target==eval(placeholder)&&e.target.value.length>=maxlength){
		var pressedkey=/[a-zA-Z0-9\.\,\/]/ //detect alphanumeric keys
	if (pressedkey.test(String.fromCharCode(e.which)))
		e.stopPropagation()
	}
}

function countlimit(maxlength,e,placeholder){
	var theform=eval(placeholder)
	var lengthleft=maxlength-theform.value.length
	var placeholderobj=document.all? document.all[placeholder] : document.getElementById(placeholder)
	if (window.event||e.target&&e.target==eval(placeholder)){
		if (lengthleft<0)
			theform.value=theform.value.substring(0,maxlength)
			placeholderobj.innerHTML=lengthleft
		}
	}

function displaylimit(theform,thelimit){
	var limit_text='<b><span id="'+theform.toString()+'">'+thelimit+'</span></b> CHARACTERS REMAINING ON YOUR INPUT LIMIT!'
	if (document.all||ns6)
		document.write(limit_text)
		if (document.all){
			eval(theform).onkeypress=function(){ return restrictinput(thelimit,event,theform)}
			eval(theform).onkeyup=function(){ countlimit(thelimit,event,theform)}
		}
	else if (ns6){
		document.body.addEventListener('keypress', function(event) { restrictinput(thelimit,event,theform) }, true); 
		document.body.addEventListener('keyup', function(event) { countlimit(thelimit,event,theform) }, true); 
	}
}

// ** Function to toggle visibility of form elements ** elements start off hidden
function showme(element,trigger) {
	element.style.display = "none";
	if (trigger.value == "Y") {
		element.style.display = "block";
	}
	if (trigger.value == "Client Advertising") {
		element.style.display = "block";
	}		
}		

// ** Functions for Calendar Date Picker ** uses calendar.asp
function getDate(mydate) {
	var dt = showModalDialog("cgi-bin/calendar.asp", "", "dialogWidth:295px; dialogHeight:295px; status:no")
		if (dt != "" && dt != null) {
			mydate.value = dt;
		}
}

// ** Submit Once Code ** onclick disable the button and then force the submit
function submitonce() {
	if (isBlank(document.frmGeneralInquiry.fname.value))
	{
		alert("Please enter your First Name!");
		return false
	}
		if (isBlank(document.frmGeneralInquiry.lname.value))
	{
		alert("Please enter your Last Name!");
		return false
	}
	if (isBlank(document.frmGeneralInquiry.title.value))
	{
		alert("Please enter your Title!");
		return false
	}		
	if (isBlank(document.frmGeneralInquiry.coname.value))
	{
		alert("Please enter your Company Name!");
		return false
	}	
	if (isBlank(document.frmGeneralInquiry.addr1.value))
	{
		alert("Please enter your Address!");
		return false
	}	
	if (isBlank(document.frmGeneralInquiry.city.value))
	{
		alert("Please enter your City!");
		return false
	}	
	if (isBlank(document.frmGeneralInquiry.state.value))
	{
		alert("Please enter your State!");
		return false
	}	
	if (isBlank(document.frmGeneralInquiry.zip.value))
	{
		alert("Please enter your Zip Code!");
		return false
	}	
	if (isBlank(document.frmGeneralInquiry.phone.value))
	{
		alert("Please enter your Phone!");
		return false
	}	
	if (isBlank(document.frmGeneralInquiry.email.value))
	{
		alert("Please enter your Email address!");
		return false
	}		
	if (isBlank(document.frmGeneralInquiry.selIndustry.value))
	{
		alert("Please enter your Type of Industry!");
		return false
	}	
	if (document.frmGeneralInquiry.selIndustry.value == "Other")
	{
		if (document.frmGeneralInquiry.txtIndustry.value == "")
		{
			alert("Please enter your Type of Industry");
			return false
		}
	}	
	
	//check for selection of product
	var product = 0;
	if (document.frmGeneralInquiry.btnATL1.checked)
	{
		product = 1;
	}
	if (document.frmGeneralInquiry.btnATL2.checked)
	{
		product = 1;
	}
	if (document.frmGeneralInquiry.btnATL3.checked)
	{
		product = 1;
	}
	if (document.frmGeneralInquiry.btnLFE1.checked)
	{
		product = 1;
	}
	if (document.frmGeneralInquiry.btnLFE2.checked)
	{
		product = 1;
	}
	if (document.frmGeneralInquiry.btnLFE3.checked)
	{
		product = 1;
	}
	if (document.frmGeneralInquiry.btnLFE4.checked)
	{
		product = 1;
	}
	if (document.frmGeneralInquiry.btnLFE5.checked)
	{
		product = 1;
	}
	if (document.frmGeneralInquiry.btnLFE7.checked)
	{
		product = 1;
	}
	if (document.frmGeneralInquiry.btnPRC1.checked)
	{
		product = 1;
	}
	if (document.frmGeneralInquiry.btnPRC2.checked)
	{
		product = 1;
	}
	if (document.frmGeneralInquiry.btnPRC3.checked)
	{
		product = 1;
	}
	if (document.frmGeneralInquiry.btnPRC4.checked)
	{
		product = 1;
	}
	if (document.frmGeneralInquiry.btnPRC5.checked)
	{
		product = 1;
	}
	if (document.frmGeneralInquiry.btnPRC6.checked)
	{
		product = 1;
	}
	if (document.frmGeneralInquiry.btnPRC7.checked)
	{
		product = 1;
	}
	if (document.frmGeneralInquiry.btnWSS1.checked)
	{
		product = 1;
	}
	if (document.frmGeneralInquiry.btnWSS2.checked)
	{
		product = 1;
	}
	if (document.frmGeneralInquiry.btnWSS3.checked)
	{
		product = 1;
	}
	if (document.frmGeneralInquiry.btnSRS1.checked)
	{
		product = 1;
	}
	if (document.frmGeneralInquiry.btnSRS2.checked)
	{
		product = 1;
	}
	if (document.frmGeneralInquiry.btnCDS1.checked)
	{
		product = 1;
	}

	if (product == 0)
	{
			alert("Please select at least one Product of Interest!");
			return false
	}
	// end product of interest check		
		
		
		
	if (document.frmGeneralInquiry.selRequest.value == "Other")
	{
		if (document.frmGeneralInquiry.txtRequest.value == "")
		{
			alert("Please specify your Type of Request");
			return false
		}
	}	
	document.frmGeneralInquiry.SUBMIT.disabled = true;
	document.frmGeneralInquiry.submit();
}		


function valEmail(field)
	{
	if (!isBlank(field.value))
		{
		// validate Email field - begin by stripping blanks
	  	field.value = stripLeadingTrailingBlanks(field.value);
		field.value = stripCharsInBag(field.value,"'");
	  	if (!isEmail(field.value))
	    		{
	    		alert("Please enter a valid email address: ?????@?????.???");
				field.value = "";
				field.focus();
	    		}			
		}
	}
	
function valPhone(field)
	{
	if (!isBlank(field.value))
		{	
		field.value = stripCharsNotInBag (field.value, digits);
		if (field.value.length != 10)
			{
			alert("Please enter a 10 Digit Phone Number");
			field.value = "";
			field.focus();
			}
		else
			{						
			field.value = reformatString(field.value, "", 3, "-", 3, "-", 4);
			}
		}			
	}

// ** Reformat 9 Digit SSN string uses formval.js	
function formatSSN(field) {
	field.value = reformatString(stripCharsNotInBag (field.value, digits), "", 3, "-", 2, "-", 4);
}

// ** Reformat Date string uses formval.js		
function formatDate(field) {
	field.value = reformatString(stripCharsNotInBag (field.value, digits), "",2,"/",2,"/",4);
}

function m2ym(months,years)	{
	if (parseInt(months.value) > 11) {
		//alert("months = " + months.value);
		//alert("years = " + years.value);
		var Rmonths = months.value%12;
		//alert("Rmonths = " + Rmonths);
		var RYears = parseInt(years.value) + parseInt(months.value/12);
		//alert("RYears = " + RYears);
		months.value = Rmonths;
		years.value = RYears;
	}
}				

