function returnEmail(username, domain) {
					var formattedEmail = username+"@"+domain;
					window.location.href = "mailto:"+formattedEmail+"?subject=";
				}
// ~~~~~~~EXAMPLE~~~~~~~<a href="javascript:returnEmail('name', 'domain.com');" title="Click to email">


function setupRollovers() {
if (!document.getElementsByTagName)
return;
var all_links = document.getElementsByTagName('a');
for (var i = 0; i < all_links.length; i++) {
var link = all_links[i];
if (link.className &&
(' ' + link.className + ' ').indexOf(' rollover ') != -1)
{
if (link.childNodes &&
link.childNodes.length == 1 &&
link.childNodes[0].nodeName.toLowerCase() == 'img') {
link.onmouseover = mouseover;
link.onmouseout = mouseout;
}
}
}
}
function findTarget(e)
{
/* Begin the DOM events part, which you */
/* can ignore for now if it's confusing */
var target;
if (window.event && window.event.srcElement)
target = window.event.srcElement;
else if (e && e.target)
target = e.target;
if (!target)
return null;
while (target != document.body &&
target.nodeName.toLowerCase() != 'a')
target = target.parentNode;
if (target.nodeName.toLowerCase() != 'a')
return null;
return target;
}
function mouseover(e) {
var target = findTarget(e);
if (!target) return;
// the only child node of the a-tag in target will be an img-tag
var img_tag = target.childNodes[0];
// Take the "src", which names an image called "something.ext",
// Make it point to "something-over.ext"
// This is done with a regular expression
img_tag.src = img_tag.src.replace(/(\.[^.]+)$/, '-over$1');
}
function mouseout(e) {
var target = findTarget(e);
if (!target) return;
// the only child node of the a-tag in target will be an img-tag
var img_tag = target.childNodes[0];
// Take the "src", which names an image as "something-over.ext",
// Make it point to "something.ext"
// This is done with a regular expression
img_tag.src = img_tag.src.replace(/-over(\.[^.]+)$/, '$1');
}
// When the page loads, set up the rollovers
window.onload = setupRollovers;


// attach to resource center links

jQuery(document).ready(function(){

	if(typeof CmsEditor == 'undefined')
	{
		var securePath = new RegExp("small_business_resource_center/professional_and_legal_materials","gim");

		jQuery('.content_body a').each(function(){
			var tag = jQuery(this);
			if(tag.attr('href').match(securePath))
			{
				tag.click(showTerms);
			}
		});


		if(window.location.toString().match(securePath) && !window.location.toString().match(/valid=1/))
		{
			showTerms();
		}
	}
});


function isblank(s) {
    for(var i = 0; i < s.length; i++) {
        var c = s.charAt(i);
        if ((c != ' ') && (c != '\n') && (c != '\t')) return false;
    }
    return true;
}

function echeck(str) {
	var at="@"
	var dot="."
	var lat=str.indexOf(at)
	var lstr=str.length
	var ldot=str.indexOf(dot)
	var flag="true"
	if (str.indexOf(at)==-1){
		flag="false"
	}
	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		flag="false"
	}
	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		flag="false"
	}
	if (str.indexOf(at,(lat+1))!=-1){
		flag="false"
	}
	if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		flag="false"
	}
	if (str.indexOf(dot,(lat+2))==-1){
		flag="false"
	}
	if (str.indexOf(" ")!=-1){
		flag="false"
	}
	if(flag=="false"){
		return false;
	}
	return true;
}


function validate() {
	f=document.getElementById('disclaimerForm');
	document.getElementById('firstname').required = true;
	document.getElementById('lastname').required = true;
	document.getElementById('email').required = true;
	var msg;
	var empty_fields="";
	var bad_email="";
    
	for(var i = 0; i < f.length; i++) {
		var e = f.elements[i];
		if ((e.type == "text") && e.required) {
			if ((e.value == null) || (e.value == "") || isblank(e.value)) {
				empty_fields += "\n          " + e.title;
				continue;
			}
			if (e.name=="email"){
				if (!echeck(e.value)) {
					bad_email="\n          Email Address Invalid";
				}
			}

		}
	}
	if ((e.type=="submit")&&(e.name=="")) {
		e.name=e.type;
	}

	if (!empty_fields && !bad_email){
		document.getElementById('disclaimerForm').submit();
	} else {
		msg = "PLEASE COMPLETE THE FOLLOWING:\n"
		msg +=         empty_fields + bad_email +"\n";
		alert(msg);
		return false;
	}
}




// shows terms and conditions
var showTerms = function(e)
{	
	var terms = '<h2>I ACKNOWLEDGE THAT I HAVE READ AND UNDERSTAND THE FOLLOWING DISCLAIMER:</h2>';
	terms += '<p style="font-size:13px;">I fully understand that SEIA&#0174; does not provide legal or other professional advice. ';
	terms += 'Documents and other materials available in the SEIA&#0174; Small Business Resource Center do not constitute legal or ';
	terms += 'other professional advice, and are not a substitute for such legal or other professional advice.';
	terms += 'I recognize I should consult my own legal counsel or other professionals for advice regarding my or my company\'s specific ';
	terms += 'situation, and not rely solely on any of the materials contained in the SEIA&#0174; Small Business Resource Center.</p>';

	terms += '<br><form action="/cmsForms/submit.ww" method="POST" id="disclaimerForm" name="infoForm" enctype="multipart/form-data">';
	terms += '<input type="hidden" name="table" value="disclaimer"/><input type="hidden" name="formName" value="Disclaimer"/><input type="hidden" name="secure" value=""/>';
	terms += '<table><tbody>';
	terms += '<tr><td>First Name:</td><td><input title="firstname" name="firstname" id="firstname"/></td></tr>';
	terms += '<tr><td>Last Name:</td><td><input title="lastname" name="lastname" id="lastname" /></td></tr>';
	terms += '<tr><td>Email Address:</td><td><input title="email" name="email" id="email" /></td></tr>';
	terms += '</tbody></table>';
	terms += '</form>';

	var agree = '';
	agree += '<div class="buttons"><button onclick="closeTerms()">I DON\'T AGREE</button>';
	agree += '<button onclick="validate()">I AGREE</button></div>';
//	agree += '<button onclick="window.location=\'/cs/members_only/installer_resource_center\'">I AGREE</button></div>';
	
	var cnt = jQuery('<div id="terms-and-conditions"><blockquote style="width:700px;height:280px"><div style="padding:20px">'+terms+'</div></blockquote>'+agree+'</div>');	
//	var cnt = jQuery('<div id="terms-and-conditions">testing</div>');	
	var left = jQuery(window).width()/2 - 400;
	var top = (jQuery(window).height()/2 - 140) + jQuery(window).scrollTop();	
	
	cnt.css({top:top,left:left,opacity:.9,width:'700px',height:'330px'});
	
	var overlay = jQuery('<div>').attr('id','overlay').css({opacity:.5,width:jQuery(window).width(),height:jQuery(window).height() + jQuery(window).scrollTop() });
	
	jQuery('body').css({overflow:'hidden'}).append(overlay);
	jQuery('body').append(cnt);
	
	if(e)
	{
		e.stopPropagation();
		e.preventDefault();
	}
	return false;
			
}

// closes terms and conditions
var closeTerms = function()
{
	jQuery('#overlay').remove();	
	jQuery('#terms-and-conditions').remove();
	jQuery('body').css({overflow:'auto'});
	
	if(document.referrer == '')
	{
		window.location.replace('/cs/small_business_resource_center');
	}
}

