function thisYear() {

	var d = new Date();
	var thisYear = d.getYear() + 1900;
	document.write(thisYear);
}


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){
		highlightError();
	   return false
	}

	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		highlightError();
	   return false
	}


	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		highlightError();
		return false
	}


	 if (str.indexOf(at,(lat+1))!=-1){
		highlightError();
		return false
	 }


	 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		highlightError();
		return false
	 }


	 if (str.indexOf(dot,(lat+2))==-1){
		highlightError();
		return false
	 }
	

	 if (str.indexOf(" ")!=-1){
		highlightError();
		return false

	 }


	function highlightError(){
		$('#form_contact_email').css({'border': '1px solid #FF0000'});
		$('#emailRequired').css({'display': 'inline'});
	}
	return true					

}


function ValidateForm(e){

	var emailID=document.form_contact.form_contact_email
	

	if ((emailID.value==null)||(emailID.value=="")){
		$('#form_contact_email').css({'border': '1px solid #FF0000'});
		$('#emailRequired').css({'display': 'inline'});
		emailID.focus();
		return false
	}else{
		document.getElementById('form_contact_email').style.border = "";
		document.getElementById('emailRequired').style.display = "none";
	}
	
	if (echeck(emailID.value)==false){
		emailID.focus();
		return false
	}

	if(document.getElementById('form_contact_math').value == '3'){
		document.form_contact.submit();
		document.form_contact.style.display = "none";
		$('#form_contact_thanks').css({'display': ''});
	} else {
		$('#mathRequired').css({'display': ''});
		$('#form_contact_math').css({'border': '1px solid #FF0000'});
	}
	return true

}

$.popUps = {
	active : false,				//Pop up status
	myPopUp : '',	windowWidth : function(){		return $(window).width();	},	windowHeight : function(){		return $(window).height();	},	documentHeight : function(){		return $(document).width();	},	documentWidth : function(){		return $(document).height();	},
	parameters : {				//Parameters to be set from JSON call
		'id' : '',
		'width' : '480',
		'padding' : 25,
		'closable' : true, //Save this for later as an idea
		'closeLink' : true, //Display the close like in the top right
		'type' : '' //a property to reference if pop up is static/dyanmic for ifs
	},
	
	popUpStyle : function(){
		return {
			'position' : 'absolute',
			'z-index' : '102',
			'width' : Math.min($.popUps.parameters.width, $.popUps.windowWidth()-50),
			'background-color' : "#fff",
			'padding' : $.popUps.parameters.padding
		}
	},
	
	
	
	createObscure : function(){ //Build obscure layer and append it to the body
		$('<div id="popUp_obscure" />')
			.css({
				'position' : 'fixed',
				'top' : 0,
				'left' : 0,
				'width' : '100%',
				'background-color' : "#000",
				'opacity' : .75,
				'display' : 'none',
				'z-index' : '101'
			}).appendTo('body');		
	},
	
	doTrafficControl : function(manualCheck, popUpInfo){//Start appropriate function based on type of pop up
		if(manualCheck == false){
			//console.log($(popUpInfo).attr('href').replace('#',''));
			var keyPairs;
			var path = function(){
				if($(popUpInfo).attr('href').indexOf("?") >= 0){
					return $(popUpInfo).attr('href').replace('#','').split('?')[0];
				}else{
					return $(popUpInfo).attr('href').replace('#','');
				}
			}
				
			if($(popUpInfo).attr('href').indexOf("?") >= 0){//make sure their are parameters defined in the path
				keyPairs = $(popUpInfo).attr('href').replace('#','').split('?')[1].split('&');
			}
			
			if(keyPairs){//if keypairs exist, assign them to the parameters object
				for(i=0; i<keyPairs.length; i++){//loop through pairs and set parameters properties and values
					var parameters = keyPairs[i].split('=');
					$.popUps.parameters[parameters[0]] = parseInt(parameters[1]);
				}
			}
				
			if(path().indexOf("div-") >= 0){//if path contains "div-", content should exist on page
				$.popUps.parameters['type'] = 'static';
				$.popUps.buildStaticPopUp(path()); //Create static popup
			}else{
				$.popUps.parameters['type'] = 'dynamic';
				$.popUps.buildDynamicPopUp(path());
			};
			
		}else{
			//Do the manual stuff here
		}
	},
	
	buildStaticPopUp : function(path){
		var div = path.split('-');
		$.popUps.myPopUp = $('#' + div[1]).css($.popUps.popUpStyle());
		
		if($.popUps.parameters['closeLink'] == true && $.popUps.myPopUp.children('.popUp_close').length == 0){//add close link to pop up
			$.popUps.myPopUp.prepend('<a href="javascript:;" class="popUp_close" onclick="$.popUps.toggleElements();">Close</a>')
		}
		$.popUps.positionElements();
		$.popUps.toggleElements();
	},
	
	buildDynamicPopUp : function(path){
		//get json data then build the div
	},
	
	positionElements : function(){ //Position obscure and pop up
		var popUpHeight = $.popUps.myPopUp.height();
		var popUpWidth = $.popUps.myPopUp.width();

		var popUpPosX = function(){
			return Math.max($.popUps.windowWidth()/2 - popUpWidth/2 - $.popUps.parameters.padding, 0)
		}
		var popUpPosY = function(){
			return Math.max($.popUps.windowHeight()/2  - popUpHeight/2 - $.popUps.parameters.padding, 0) + $(window).scrollTop()
		}

		$('#popUp_obscure')
			.css({
				'height' : $.popUps.documentHeight()
			});
		
		$.popUps.myPopUp
			.css({				'width' : Math.min($.popUps.parameters.width, $.popUps.windowWidth()-50),
				'top' : popUpPosY(),
				'left' : popUpPosX()
			});
	},
	
	toggleElements : function(){ //Toggle elements based on active status
		if($.popUps.active == false){
			$('#popUp_obscure').fadeIn(250);
			if($.popUps.parameters['type'] == 'dynamic'){$(body).append($.popUps.myPopUp)}; //add it to the page
			$.popUps.myPopUp.fadeIn(250);
			$.popUps.active = true;
		}else{
			$('#popUp_obscure').fadeOut(250);
			$.popUps.myPopUp.fadeOut(250);
			if($.popUps.parameters['type'] == 'dynamic'){$.popUps.myPopUp.remove()}; //remove it from the page
			$.popUps.active = false;
		}
	},
	
	init : function(){
		$.popUps.createObscure(); //Create obscure div on page load
	
		$('.link_popUp').click(function(event){
			event.preventDefault();
			$.popUps.doTrafficControl(false, this);
		});
		
		$('#popUp_obscure').click(function(event){//Hide the pop up assets
			$.popUps.toggleElements();
		});
		
		$('.popUp_close').click(function(event){//Hide the pop up assets
			event.preventDefault();
			$.popUps.toggleElements();
		});
		
		$(window).resize(function(){
			if($.popUps.active == true){
				$.popUps.positionElements();
			}
		});	
	}
}

$(document).ready(function(event){
	if($('.popUp')){$.popUps.init()}
});









