/* *********************************************
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');

	// 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(phone, "Please enter a valid Phone Number.")){
										return true;
									}
								}
							}
						}
					}
				}
			}
		}
	}

	return false;

}

/* *********************************************
FORM VALIDATION ::: CONTACT US
********************************************* */
function formValidatorContactUs(){
	// Make quick references to our fields
	var name = document.getElementById('name');
	var email = document.getElementById('email');

	// Check each input in the order that it appears in the form!
	if(notEmpty(name, "Please enter a valid Name.")){
		if(emailValidator(email, "Please enter a valid Email.")){
			return true;
		}
	}
	return false;
}

/* *********************************************
FORM VALIDATION
********************************************* */
function formValidatorLookingForArt(){
	// Make quick references to our fields
	var typeofart = document.getElementById('typeofart');
	var firstname = document.getElementById('firstname');
	var lastname = document.getElementById('lastname');
	var title = document.getElementById('title');
	var email = document.getElementById('email');
	var firmname = document.getElementById('firmname');
	var address = document.getElementById('address');
	var city = document.getElementById('city');
	var state = document.getElementById('state');
	var country = document.getElementById('country');
	var postalcode = document.getElementById('postalcode');

	// Check each input in the order that it appears in the form!
	if(notEmpty(typeofart, "Please enter a valid Type Of Art.")){
		if(notEmpty(firstname, "Please enter a valid First Name.")){
			if(notEmpty(lastname, "Please enter a valid Last Name.")){
				if(notEmpty(title, "Please enter a valid Title.")){
					if(emailValidator(email, "Please enter a valid Email Address.")){
						if(notEmpty(firmname, "Please enter a valid Firm 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(country, "Please enter a valid Country.")){
											if(notEmpty(postalcode, "Please enter a valid Postal Code.")){
												return true;
											}
										}
									}
								}
							}
						}
					}
				}
			}
		}
	}

	return false;

}

/* *************************************************************
BASE FUNCTIONS ::: DO NOT EDIT BELOW
************************************************************* */
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;
	}
}
