
//-----------------------------------------------------------------------------
// Generic DreamWeaver Functions
//-----------------------------------------------------------------------------

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

//-----------------------------------------------------------------------------
// Win Popup.
//-----------------------------------------------------------------------------

function popCustomerlogin() {
    launchWindow("","");
}

var popX = 750;
var popY = 414;

// MSIE window pop
function iePop(newURL, newName, popWidth, popHeight, toolBars, scrollBars) {
    var popX = window.document.body.clientWidth;
    var popY = window.document.body.clientHeight;
    var leftPos = (popX-popWidth)/2;
    var topPos = (popY-popHeight)/2;
    var theParameters = 'channelmode=0,dependent=0,directories=0,fullscreen=0,location=0,menubar=0,resizable=0,scrollbars='+scrollBars+',status=0,toolbar=' + toolBars + ',width='+popWidth+',height='+popHeight+',top='+topPos+',left='+leftPos;
    var remote = open(newURL, newName, theParameters);
}

// Netscape window pop
function nsPop(newURL, newName, popWidth, popHeight, toolBars, scrollBars) {
    popX = window.innerWidth;
    popY = window.innerHeight;

    var menuVar = 'no';
    var agent = navigator.userAgent.toLowerCase(); 
    var leftPos = (popX-popWidth)/2;
    var topPos = (popY-popHeight)/2;
    var theParameters = 'LEFT=' + leftPos + ',TOP=' + topPos + ',screenX=' + leftPos + ',screenY=' + topPos + ',' + 'OUTERWIDTH=' + popWidth + ',OUTERHEIGHT=' + popHeight + ',WIDTH=' + popWidth + ',HEIGHT=' + popHeight + ',TOOLBAR=' + toolBars + ',LOCATION=no,DIRECTORIES=no,STATUS=no,MENUBAR=no,SCROLLBARS=' + scrollBars + ',RESIZABLE=no';
    makePop = window.open(newURL, newName, theParameters);
};

// our new window constructor
function launchWindow(winURL, winName, popWidth, popHeight, toolBars, scrollBars) {
    if (nn) {
        newWin = nsPop(winURL, winName, popWidth, popHeight, toolBars, scrollBars);
    }
    else
    if (ie) {
        newWin = iePop(winURL, winName, popWidth, popHeight, toolBars, scrollBars);
    }
}

// browser check setup
version = navigator.appVersion;
name = navigator.appName;
var nn, ie

if (name == "Netscape") {
    nn = true;
}
else
if (name == "Microsoft Internet Explorer") {
    ie = true;
}

var isMinNS4 = document.layers
var ie=document.all&&navigator.userAgent.indexOf("Opera")==-1
var dom=document.getElementById&&!ie&&navigator.userAgent.indexOf("Opera")==-1

//-----------------------------------------------------------------------------
// Window Resize Check.
//-----------------------------------------------------------------------------

// These variables are used to determine if a resize event is a true one.
// Necessary due to a bug in older NS4 releases.

var origWidth;
var origHeight;

// Fix for resize bug.

if (isMinNS4) {
  origWidth  = window.innerWidth;
  origHeight = window.innerHeight;
}
window.onresize = pageReload;

function pageReload() {

  // Reload page in case of a browser resize. First make sure it's a true
  // resize, then reload if neccesary.

  if (isMinNS4 && origWidth == window.innerWidth && origHeight == window.innerHeight)
    return;
  window.location.href = window.location.href;
}



/* *********************************************
FORM VALIDATION
********************************************* */
function formValidator(){
	// Make quick references to our fields
	var name = document.getElementById('name');
	var company = document.getElementById('company');
	var address = document.getElementById('address');
	var city = document.getElementById('city');
	var state = document.getElementById('state');
	var zip = document.getElementById('zip');
	var email = document.getElementById('email');
	var phone = document.getElementById('phone');
	var sourceofcontact = document.getElementById('source_of_contact');

	// Check each input in the order that it appears in the form!
	if(notEmpty(name, "Please enter a valid Name.")){
		if(notEmpty(company, "Please enter a valid Company.")){
			if(notEmpty(address, "Please enter a valid Address.")){
				if(notEmpty(city, "Please enter a valid City.")){
					if(notEmpty(state, "Please enter a valid State.")){
						if(notEmpty(zip, "Please enter a valid Zip/Postal Code.")){
							if(emailValidator(email, "Please enter a valid Email Address.")){
								if(notEmpty(phone, "Please enter a valid Phone Number.")){
									if(notEmpty(sourceofcontact, "Please enter a reply for How Did You Learn About Us.")){
										return true;
									}
								}
							}
						}
					}
				}
			}
		}
	}

	return false;

}

/* *********************************************
CPE FORM VALIDATION
********************************************* */
function formValidatorCPE(){
	// Make quick references to our fields
	var name = document.getElementById('contactname');
	var company = document.getElementById('firmname');
	var address = document.getElementById('address');
	var city = document.getElementById('city');
	var state = document.getElementById('state');
	var zip = document.getElementById('zip');
	var email = document.getElementById('email');
	var phone = document.getElementById('phone');
	
	// Check each input in the order that it appears in the form!
	if(notEmpty(company, "Please enter a valid Firm Name.")){
		if(notEmpty(name, "Please enter a valid Contact Name.")){
			if(notEmpty(address, "Please enter a valid Address.")){
				if(notEmpty(city, "Please enter a valid City.")){
					if(notEmpty(state, "Please enter a valid State.")){
						if(notEmpty(zip, "Please enter a valid Zip/Postal Code.")){
							if(emailValidator(email, "Please enter a valid Email Address.")){
								if(notEmpty(phone, "Please enter a valid Phone Number.")){
									return true;
								}
							}
						}
					}
				}
			}
		}
	}

	return false;

}


/* *********************************************
SUBMIT RESUME VALIDATION
********************************************* */
function formValidatorSubmitResume(){
	// Make quick references to our fields
	var fullname = document.getElementById('fullname');
	var position = document.getElementById('position');
	var emailaddress = document.getElementById('emailaddress');

	var daytimephone = document.getElementById('daytimephone');
	var salaryrequirements = document.getElementById('salaryrequirements');

	
	// Check each input in the order that it appears in the form!
	if(notEmpty(fullname, "Please enter a valid Full Name.")){
		if(notEmpty(position, "Please enter a valid Position.")){
			if(emailValidator(emailaddress, "Please enter a valid Email Address.")){

				if(notEmpty(daytimephone, "Please enter a valid Day Time Number.")){
					if(notEmpty(salaryrequirements, "Please enter a valid Salary Requirements.")){

						return true;

					}
				}

			}
		}
	}
	return false;
}

/* *********************************************
SUBMIT RESUME VALIDATION
********************************************* */
function formValidatorSubmitFile(){
	// Make quick references to our fields
	var recipient = document.getElementById('recipient');
	var securitycode = document.getElementById('securitycode');
	var securitycodeincluded = document.getElementById('securitycodeincluded');
	var confirmationemail = document.getElementById('confirmationemail');

	// Check each input in the order that it appears in the form!
	if(notEmpty(recipient, "Please enter a valid Recipient.")){
		if(notEmpty(recipient, "Please enter a valid Recipient.")){
			if(emailValidatorAlliantgroup(recipient, "Please enter a valid Recipient.")){

if(securitycode.value.length > 0 && securitycode.value.length < 6) {
	alert('Please enter a Security Code of at least 6 characters.')
} else {
	if(securitycodeincluded.value == 'yes') {
		if(notEmpty(confirmationemail, "Please enter a Delivery Confirmation Email Address.")){
			if(emailValidator(confirmationemail, "Please enter a Delivery Confirmation Email Address.")){
						return true;
			}
		}
	} else {
		return true;
	}
}

			}
		}
	}
	return false;
}


function notEmpty(elem, helperMsg){
	if(elem.value.length == 0){
		alert(helperMsg);
		elem.focus(); // set the focus to this input
		return false;
	}
	return true;
}

function isNumeric(elem, helperMsg){
	var numericExpression = /^[0-9]+$/;
	if(elem.value.match(numericExpression)){
		return true;
	}else{
		alert(helperMsg);
		elem.focus();
		return false;
	}
}

function isAlphabet(elem, helperMsg){
	var alphaExp = /^[a-zA-Z]+$/;
	if(elem.value.match(alphaExp)){
		return true;
	}else{
		alert(helperMsg);
		elem.focus();
		return false;
	}
}

function isAlphanumeric(elem, helperMsg){
	var alphaExp = /^[0-9a-zA-Z]+$/;
	if(elem.value.match(alphaExp)){
		return true;
	}else{
		alert(helperMsg);
		elem.focus();
		return false;
	}
}

function lengthRestriction(elem, min, max){
	var uInput = elem.value;
	if(uInput.length >= min && uInput.length <= max){
		return true;
	}else{
		alert("Please enter between " +min+ " and " +max+ " characters");
		elem.focus();
		return false;
	}
}

function madeSelection(elem, helperMsg){
	if(elem.value == "Please Choose"){
		alert(helperMsg);
		elem.focus();
		return false;
	}else{
		return true;
	}
}

function emailValidator(elem, helperMsg){
	var emailExp = /^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,4}$/;
	if(elem.value.match(emailExp)){
		return true;
	}else{
		alert(helperMsg);
		elem.focus();
		return false;
	}
}

function emailValidatorAlliantgroup(elem, helperMsg){
//	var emailExp = '\@alliantgroup\.com';
	var emailExp = /^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,4}$/;
	if(elem.value.match(emailExp)){
		return true;
	}else{
		alert(helperMsg);
		elem.focus();
		return false;
	}
}

/* **********************************************
PRINTING 
*********************************************** */
function DoPrint(objPrintArea,strPrefix)
{
	var prtContent = document.getElementById(objPrintArea);

	var text;
 	text = prtContent.innerHTML;	

	// HEADER
	text = text.replace('<!--INQPRINT','');
	text = text.replace('INQPRINT-->','');

	// HIDE LINKS
	text = text.replace('<!--HLB-->','<!--');
	text = text.replace('<!--HLE-->','-->');
	
	// TABLE WIDTH
	text = text.replace('width=990','width=700');
	text = text.replace('width=990','width=700');
	text = text.replace('width=990','width=700');
	text = text.replace('width=990','width=700');

	var str;
	str = "";

	if (window.screen) {
		var ah = screen.availHeight - 30;
		var aw = screen.availWidth - 10;

		var xc = (aw - 800) / 2;
		var yc = (ah - 600) / 2;

		str += ",left=" + xc + ",screenX=" + xc;
		str += ",top=" + yc + ",screenY=" + yc;
	}

	var objPrintWindow = window.open('', 'PrintWindow', "width=780,height=660,center,toolbar=1,location=1,directories=0,status=1,menubar=1,scrollbars=1,resizable=1,copyhistory=0" + str);
		
	objPrintWindow.document.write("");
	objPrintWindow.document.write("<link href=\"" + strPrefix + "style_print.css\" rel=\"stylesheet\" type=\"text/css\" />");
	objPrintWindow.document.write(text);
	objPrintWindow.document.close();

	// CALL PRINT COMMAND FROM WINDOW
	objPrintWindow.focus();
	objPrintWindow.print();

	// CLOSE WINDOW :: 
	// objPrintWindow.close();

}

/* **********************************************
EMAIL PAGE LINK
*********************************************** */
/* This script and many more are available free online at
The JavaScript Source!! http://javascript.internet.com
Created by: CodeLifter.com | http://www.codelifter.com */
var good;
function checkEmailAddress(field) {
// the following expression must be all on one line...
var goodEmail = field.value.match(/\b(^(\S+@).+((\.com)|(\.net)|(\.edu)|(\.mil)|(\.gov)|(\.org)|(\..{2,2}))$)\b/gi);
  if (goodEmail) {
    good = true;
  } else {
    alert('Please enter a valid e-mail address.');
    field.focus();
    field.select();
    good = false;
  }
}

u = window.location;
m = "I thought this might interest you...";

function mailThisUrl() {
  good = false
  checkEmailAddress(document.eMailer.address);
  if (good) {
    // the following expression must be all on one line...
    window.location = "mailto:"+document.eMailer.address.value+"?subject="+m+"&body="+document.title+" "+u;
  }
}

// *****************************************************
// HIDE||SHOW DETAILS [div]
// *****************************************************
function ToggleSubDisplay(strDiv) 
{
	var elemA = document.getElementById(strDiv);
	if (elemA) {
		if(elemA.style.visibility == 'visible') {
			elemA.style.display = 'none';
			elemA.style.visibility = 'hidden';
		} else {
			elemA.style.display = 'block';
			elemA.style.visibility = 'visible';
		}
	}
}


/* **********************************************
PASS FORM VALUE
*********************************************** */
function fncPopulateTextBox(strTarget, strValue) {
	var objPosition = document.getElementById(strTarget);
	if(objPosition){
		objPosition.value = strValue;
	}
}
