// JavaScript Document

var theTimer, flashCounter;

// AJAX INIT STUFF -- START
var xmlhttp=null;

try
{
	xmlhttp = new XMLHttpRequest();
}
catch (error)
{
	try
	{
		xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	}
	catch (error)
	{
		xmlhttp = null;
	}
}
//  END

function echeck(str){
 var filter=/^.+@.+\..{2,4}$/

 if (filter.test(str))
    result=true
 else {
    result=false
	}
 return (result) }

function trim(str){
	var	str = str.replace(/^\s\s*/, ''),
	ws = /\s/,
	i = str.length;
	while (ws.test(str.charAt(--i)));
	return str.slice(0, i + 1);
}

function clearValue(defaultValue, input){ //alert(defaultValue + '==' + input.value);
	if(defaultValue == input.value) input.value = '';
	document.getElementById(input.id).style.color = 'black';
}

function setDefault(defaultValue, input){
	var currentValue = trim(input.value);
	if(currentValue == '') input.value = defaultValue;
}

function backToTop(){
	$('a.back2top').click(function(){
		$('html, body').animate({
			scrollTop: $("#header").offset().top
		}, 650);
		return false;
	});
}

function checkShortForm(){
	var passedCheck = true;
	var name = document.getElementById('name').value;
	var email = document.getElementById('email').value;
	var phone = document.getElementById('phone').value;
	var tellUsMore = document.getElementById('tellUsMore').value;
	
	if(name == '' || name == 'Name'){
		document.getElementById('name').style.color = '#FF0000';
		passedCheck = false;
	}else{
		document.getElementById('name').style.color = '#000';
	}
	
	if(email == 'Email' || !echeck(email)){
		document.getElementById('email').style.color = '#FF0000';
		passedCheck = false;
	}else{
		document.getElementById('email').style.color = '#000';
	}
	
	if(phone == '' || phone == 'Phone'){
		document.getElementById('phone').style.color = '#FF0000';
		passedCheck = false;
	}else{
		document.getElementById('phone').style.color = '#000';
	}
	
	if(tellUsMore == '' || tellUsMore == 'Tell Us More'){
		document.getElementById('tellUsMore').style.color = '#FF0000';
		passedCheck = false;
	}else{
		document.getElementById('tellUsMore').style.color = '#000';
	}
	
	return passedCheck; }


function checkCaseReview(){
	var passedCheck = true;
	
	if(document.getElementById('firstName').value == ''){
		passedCheck = false;
		document.getElementById('firstNameField').style.color = 'red';
		document.getElementById('firstNameField').style.fontStyle = 'italic';
		document.getElementById('firstNameField').style.fontWeight = 'bold';
	}else{
		document.getElementById('firstNameField').style.color = 'black';
		document.getElementById('firstNameField').style.fontStyle = 'normal';
		document.getElementById('firstNameField').style.fontWeight = 'normal';
	}
	
	if(document.getElementById('lastName').value == ''){
		passedCheck = false;
		document.getElementById('lastNameField').style.color = 'red';
		document.getElementById('lastNameField').style.fontStyle = 'italic';
		document.getElementById('lastNameField').style.fontWeight = 'bold';
	}else{
		document.getElementById('lastNameField').style.color = 'black';
		document.getElementById('lastNameField').style.fontStyle = 'normal';
		document.getElementById('lastNameField').style.fontWeight = 'normal';
	}
	
	if(document.getElementById('street').value == ''){
		passedCheck = false;
		document.getElementById('streetField').style.color = 'red';
		document.getElementById('streetField').style.fontStyle = 'italic';
		document.getElementById('streetField').style.fontWeight = 'bold';
	}else{
		document.getElementById('streetField').style.color = 'black';
		document.getElementById('streetField').style.fontStyle = 'normal';
		document.getElementById('streetField').style.fontWeight = 'normal';
	}
	
	if(document.getElementById('city').value == ''){
		passedCheck = false;
		document.getElementById('cityField').style.color = 'red';
		document.getElementById('cityField').style.fontStyle = 'italic';
		document.getElementById('cityField').style.fontWeight = 'bold';
	}else{
		document.getElementById('cityField').style.color = 'black';
		document.getElementById('cityField').style.fontStyle = 'normal';
		document.getElementById('cityField').style.fontWeight = 'normal';
	}
	
	if(document.getElementById('state').value == ''){
		passedCheck = false;
		document.getElementById('stateField').style.color = 'red';
		document.getElementById('stateField').style.fontStyle = 'italic';
		document.getElementById('stateField').style.fontWeight = 'bold';
	}else{
		document.getElementById('stateField').style.color = 'black';
		document.getElementById('stateField').style.fontStyle = 'normal';
		document.getElementById('stateField').style.fontWeight = 'normal';
	}
	
	if(document.getElementById('zip').value == ''){
		passedCheck = false;
		document.getElementById('zipField').style.color = 'red';
		document.getElementById('zipField').style.fontStyle = 'italic';
		document.getElementById('zipField').style.fontWeight = 'bold';
	}else{
		document.getElementById('zipField').style.color = 'black';
		document.getElementById('zipField').style.fontStyle = 'normal';
		document.getElementById('zipField').style.fontWeight = 'normal';
	}
	
	if(document.getElementById('dayPhone').value == ''){
		passedCheck = false;
		document.getElementById('dayField').style.color = 'red';
		document.getElementById('dayField').style.fontStyle = 'italic';
		document.getElementById('dayField').style.fontWeight = 'bold';
	}else{
		document.getElementById('dayField').style.color = 'black';
		document.getElementById('dayField').style.fontStyle = 'normal';
		document.getElementById('dayField').style.fontWeight = 'normal';
	}
	
	if(document.getElementById('nightPhone').value == ''){
		passedCheck = false;
		document.getElementById('nightField').style.color = 'red';
		document.getElementById('nightField').style.fontStyle = 'italic';
		document.getElementById('nightField').style.fontWeight = 'bold';
	}else{
		document.getElementById('nightField').style.color = 'black';
		document.getElementById('nightField').style.fontStyle = 'normal';
		document.getElementById('nightField').style.fontWeight = 'normal';
	}
	
	if(document.getElementById('email').value == ''){
		passedCheck = false;
		document.getElementById('emailField').style.color = 'red';
		document.getElementById('emailField').style.fontStyle = 'italic';
		document.getElementById('emailField').style.fontWeight = 'bold';
	}else{
		document.getElementById('emailField').style.color = 'black';
		document.getElementById('emailField').style.fontStyle = 'normal';
		document.getElementById('emailField').style.fontWeight = 'normal';
	}
	
	if(document.getElementById('whyHelp').value == ''){
		passedCheck = false;
		document.getElementById('whyField').style.color = 'red';
		document.getElementById('whyField').style.fontStyle = 'italic';
		document.getElementById('whyField').style.fontWeight = 'bold';
	}else{
		document.getElementById('whyField').style.color = 'black';
		document.getElementById('whyField').style.fontStyle = 'normal';
		document.getElementById('whyField').style.fontWeight = 'normal';
	}
	
	return passedCheck; }


function h1Click(){
	$("h1").click(function () { 
		window.location = "/";
	});
}

function playVideo(){
	$('#flashcontent img').click( function (){
		stopSlide();
		var so = new SWFObject("/media/casper&casper.swf", "casper&casper", "448", "336", "8", "#515151");
		so.addParam("wmode", "transparent");
		so.write("flashcontent");
	});
}

$(document).ready(function() {  
	$('.h1').pngFix(); 
	h1Click();
	$("a.map").fancybox({
		'width'				: '75%',
		'height'			: '75%',
		'autoScale'			: false,
		'transitionIn'		: 'none',
		'transitionOut'		: 'none',
		'type'				: 'iframe'
	});
	playVideo()
});
