function copyrightYear(){
	if(document.getElementById('insertYear')) document.getElementById('insertYear').innerHTML = new Date().getFullYear();
}


function externalLinks(){
	if (!document.getElementsByTagName) return;
	var anchors = document.getElementsByTagName("a");
	for (var i=0; i<anchors.length; i++) {
		if (anchors[i].getAttribute("href") && anchors[i].getAttribute("rel") == "external") anchors[i].target = "_blank";
	}
}

function siteOnLoad () {
	copyrightYear();
	externalLinks();
}

function addLoadEvent(func){
	var oldOnLoad = window.onload;
	if(typeof window.onload != 'function'){
		window.onload = func;
	}
	else{
		window.onload = function(){
			oldOnLoad();
			func();
		}
	}
}


addLoadEvent(siteOnLoad);

function checkRequired(checkform, requiredArray){
	var error = "";
	var emailInfo = document.getElementById('emailInfo');
	var errorInfo = document.getElementById('errorInfo');
	
	for(i=0;i<requiredArray.length;i++) {
		var element = checkform[requiredArray[i]];
		if(element.value==""){
			if(element) showError(element);
			error = true;
			if(errorInfo){
				errorInfo.innerHTML = "Fields marked red either have errors or are blank and are required.";
				errorInfo.style.display = "block";
			}
		}
		if(element.name=="email" && element.value != ""){
			if(!validateEmail(element.value)){
				if(emailInfo) emailInfo.innerHTML = "Format: yourname@domain.com";
				showError(element);
				error = true;
			}
			element.onblur = function(){document.getElementById('emailInfo').innerHTML = ""};
		}
	}
	if(error) return false; else checkform.submit();
}
function showError(element){
	element.style.backgroundColor = "rgb(251, 191, 191)";
	element.onfocus = clearError;
}
function clearError(){
	this.style.backgroundColor = "rgb(255, 255, 255)";
}
function validateEmail(src) {
  var emailReg = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*\.(\w{2}|(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum|ca))$/;
    var regex = new RegExp(emailReg);
    return regex.test(src);
 }


String.prototype.trim = function() {
	a = this.replace(/^\s+/, '');
};



function validateForm(field){
	var el = document.getElementById(field);
	var myNum=new Number(el.value);
                                
	if(el.value=="" || el.value.length < 5){
		showError(el);
		}
	else if ( isNaN(myNum.valueOf()) ) {
		showError(el);
	}
	else{
		document.getElementById('autoForm').submit();
		return true;
	}
}

function showError(el){
	el.style.background = "url(http://www.cheapautoinsurancequotes1.com/graphics/input_error.gif) no-repeat";
				el.onfocus = clearError;
				document.getElementById('error').innerHTML = "You must enter a valid ZIP code to continue.";
	}

function clearError(){
	this.style.background = "url(http://www.cheapautoinsurancequotes1.com/graphics/input.gif) no-repeat";
}
			
