function openWin(url, title, width, height, scroll) {
	var load=window.open(url, title, 'width=' + width +', height=' + height + ', resizable=1, scrollbars=' + scroll + ', left=50, top=50');
}
function chckSnt() {
var qryStr = window.location.search;
var send = qryStr.split("=")[1];
	if (send == "yes") {
	  document.write("Thank you for your feedback!");
	}
}
function chckChg() {
var qryStr = window.location.search;
var send = qryStr.split("=")[1];
	if (send == "yes") {
	  document.write("Thank you for your request. We will respond to your request as quickly as possible");
	}
}

function validate(frm) {
	if((document.certFrm.sendEmail.checked == false) && (document.certFrm.sendFax.checked  == false) && (document.certFrm.sendMail.checked  == false)) {
		 	alert("Please select how you want the certificate to be sent to you!");
		 	document.certFrm.sendEmail.focus();
		 	return false;
		 }
	if((document.certFrm.recEmail.checked == false) && (document.certFrm.recFax.checked  == false) && (document.certFrm.recMail.checked  == false)) {
		 	alert("Please select how you want to receive the receipt of delivery for the certificate!");
		 	document.certFrm.recEmail.focus();
		 	return false;
		 }
	if(document.certFrm.sendEmail.checked == true) {
		if(checkEmail(document.certFrm.compEmail) == false) {
			alert("Please enter a valid email address for the insured company!");
			document.certFrm.compEmail.focus();
			return false;
		}
		if(checkEmail(document.certFrm.certEmail) == false) {
			alert("Please enter a valid email address for the certificate holder!");
			document.certFrm.certEmail.focus();
			return false;
		}
	}
	if(document.certFrm.recEmail.checked == true) {
		if(checkEmail(document.certFrm.compEmail) == false) {
			alert("Please enter a valid email address for the insured company!");
			document.certFrm.compEmail.focus();
			return false;
		}
		if(checkEmail(document.certFrm.certEmail) == false) {
			alert("Please enter a valid email address for the certificate holder!");
			document.certFrm.certEmail.focus();
			return false;
		}
	}
	if(document.certFrm.sendFax.checked == true) {
		if(checkFax(document.certFrm.compFax1.value, document.certFrm.compFax2.value, document.certFrm.compFax3.value) == false) {
			alert("Please enter a valid fax number for the insured company!");
			document.certFrm.compFax1.focus();
			return false;
		}
		if(checkFax(document.certFrm.certFax1.value, document.certFrm.certFax2.value, document.certFrm.certFax3.value) == false) {
			alert("Please enter a valid fax number for the certificate holder!");
			document.certFrm.certFax1.focus();
			return false;
		}
	}
	if(document.certFrm.recFax.checked == true) {
		if(checkFax(document.certFrm.compFax1.value, document.certFrm.compFax2.value, document.certFrm.compFax3.value) == false) {
			alert("Please enter a valid fax number for the insured company!");
			document.certFrm.compFax1.focus();
			return false;
		}
		if(checkFax(document.certFrm.certFax1.value, document.certFrm.certFax2.value, document.certFrm.certFax3.value) == false) {
			alert("Please enter a valid fax number for the certificate holder!");
			document.certFrm.certFax1.focus();
			return false;
		}
	}	
	if((document.certFrm.sendMail.checked == true) || (document.certFrm.recMail.checked == true)) {
		if(document.certFrm.compAddr.value == '') {
			alert("Please enter an address for the insured company!");
			document.certFrm.compAddr.focus();
			return false;
		}
		if(document.certFrm.compCity.value == '') {
			alert("Please enter a city for the insured company!");
			document.certFrm.compCity.focus();
			return false;
		}
		if(document.certFrm.compState.value == '') {
			alert("Please enter a state for the insured company!");
			document.certFrm.compState.focus();
			return false;
		}
		if(document.certFrm.compZip.value == '') {
			alert("Please enter a zip code for the insured company!");
			document.certFrm.compZip.focus();
			return false;
		}
		if(document.certFrm.certAddr.value == '') {
			alert("Please enter an address for the certificate holder!");
			document.certFrm.certAddr.focus();
			return false;
		}
		if(document.certFrm.certCity.value == '') {
			alert("Please enter a city for the certificate holder!");
			document.certFrm.certCity.focus();
			return false;
		}
		if(document.certFrm.certState.value == '') {
			alert("Please enter a state for the certificate holder!");
			document.certFrm.certState.focus();
			return false;
		}
		if(document.certFrm.certZip.value == '') {
			alert("Please enter a zip code for the certificate holder!");
			document.certFrm.certZip.focus();
			return false;
		}
	}			
	if(document.certFrm.type.value == "default") {
		alert("Please select type of certificate");
		return false;
	}
	if(document.certFrm.rel.value == "default") {
		alert("Please select type of relationship");
		return false;
	}

	frm.submit();
}

function checkEmail(frmEmail) {
if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(frmEmail.value)){
	return true;
	}
return false;
}

function checkFax(fax1, fax2, fax3) {
	if((isInteger(fax1)) && (fax1.length == 3)) {
		if((isInteger(fax2)) && (fax2.length == 3)) {
			if((isInteger(fax3)) && (fax3.length == 4)) {
				return true;
			}
			return false;
		}
		return false;
	}
	return false;
}

	
//-------------------------------------------------------------------
// isBlank(value)
//   Returns true if value only contains spaces
//-------------------------------------------------------------------
function isBlank(val){
	if(val==null){return true;}
	for(var i=0;i<val.length;i++) {
		if ((val.charAt(i)!=' ')&&(val.charAt(i)!="\t")&&(val.charAt(i)!="\n")&&(val.charAt(i)!="\r")){return false;}
		}
	return true;
	}
//-------------------------------------------------------------------
// isDigit(value)
//   Returns true if value is a 1-character digit
//-------------------------------------------------------------------
function isDigit(num) {
	if (num.length>1){return false;}
	var string="1234567890";
	if (string.indexOf(num)!=-1){return true;}
	return false;
	}
	
//-------------------------------------------------------------------
// isInteger(value)
//   Returns true if value contains all digits
//-------------------------------------------------------------------
function isInteger(val){
	if (isBlank(val)){return false;}
	for(var i=0;i<val.length;i++){
		if(!isDigit(val.charAt(i))){return false;}
		}
	return true;
	}