// JavaScript Document
function check_validate() {
	if (document.form_one.validate.checked == true) {
		return true;
	}
	else {
		alert("Please read section: \"Read Carefully Before Submitting\" and accept the terms!");
		document.form_one.validate.focus();
		return false;
	}
}
function externalLinks() {
 if (!document.getElementsByTagName) return;
 var anchors = document.getElementsByTagName("a");
 for (var i=0; i<anchors.length; i++) {
   var anchor = anchors[i];
   if (anchor.getAttribute("href") &&
       anchor.getAttribute("rel") == "external")
     anchor.target = "_blank";
 }
}

function initialize() {
    //externalLinks();	
	focus();	
}
window.onload = initialize;

function focus(){
	if(document.forms[0]){
		document.forms[0].focus.focus();
	}
}

function textCounter(field, maxlimit) {
	if (field.value.length > maxlimit) // if too long...trim it!
	field.value = field.value.substring(0, maxlimit);	
}

function acc_close() {
	document.getElementById('accolade_more').style.display = 'none';
}
function acc_open() {
	document.getElementById('accolade_more').style.display = 'block';
}
/*
function textCounter(field, maxlimit) {
	if (field.value.length > maxlimit) // if too long...trim it!
	field.value = field.value.substring(0, maxlimit);	
}
*/
//email validate
function echeck(str) {

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   alert("Invalid E-mail")
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert("Invalid E-mail")
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    alert("Invalid E-mail")
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    alert("Invalid E-mail")
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    alert("Invalid E-mail")
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    alert("Invalid E-mail")
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    alert("Invalid E-mail")
		    return false
		 }

 		 return true					
	}

function validate_contact(){
	var email=document.forms['contact'].email	
	if ((email.value==null)||(email.value=="")){
		alert("Please Enter your Email")
		email.focus()
		return false
	}
	if (echeck(email.value)==false){
		email.value=""
		email.focus()
		return false
	}
	return true
 }
 
function validate_join_mailing(){
	var email=document.forms['join_mailing_list'].email	
	if ((email.value==null)||(email.value=="")){
		alert("Please Enter your Email")
		email.focus()
		return false
	}
	if (echeck(email.value)==false){
		email.value=""
		email.focus()
		return false
	}
	return true
}

function validate_unsubscribe_mailing(){
	var email=document.forms['unsubscribe_mailing_list'].email	
	if ((email.value==null)||(email.value=="")){
		alert("Please Enter your Email")
		email.focus()
		return false
	}
	if (echeck(email.value)==false){
		email.value=""
		email.focus()
		return false
	}
	return true
}
 //end email validate

