// 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 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 echeck(str){
 var filter=/^.+@.+\..{2,4}$/

 if (filter.test(str))
    result=true
 else {
    result=false
	}
 return (result) }

function clearValue(defaultValue, input){ //alert(defaultValue + '==' + input.value);
	if(defaultValue == input.value) input.value = '';
}

function setDefault(defaultValue, input){
	var currentValue = trim(input.value);
	if(currentValue == '') input.value = defaultValue;
}

function checkContactForm(){
	var passedCheck = true;
	var name = document.getElementById('name').value;
	var email = document.getElementById('email').value;
	var phone = document.getElementById('phone').value;
	
	if(name == ''){
		$('label.name').css({'color':'red','font-style':'italic'});
		passedCheck = false;
	}else{
		$('label.name').css({'color':'#7F8173','font-style':'normal'});
	}
	
	if(!echeck(email)){
		$('label.email').css({'color':'red','font-style':'italic'});
		passedCheck = false;
	}else{
		$('label.email').css({'color':'#7F8173','font-style':'normal'});
	}
	
	if(phone == ''){
		$('label.phone').css({'color':'red','font-style':'italic'});
		passedCheck = false;
	}else{
		$('label.phone').css({'color':'#7F8173','font-style':'normal'});
	}
	
	return passedCheck; }

function sendcontact(){	
	if(checkContactForm()){
		var querystring = $('#generalContact').serialize(); //alert(querystring);
		xmlhttp.open("GET", "/ajaxHandler.php?action=contact&" + querystring + "&time=" + new  Date().getTime());
		xmlhttp.onreadystatechange = function(){
			if (xmlhttp.readyState == 4 && xmlhttp.status == 200){
				var response = xmlhttp.responseText; //alert(response);
				document.getElementById('generalContact').innerHTML = '<p style="width:560px"><br /><br /><em>Thank you for contacting Jim Marker Consulting. We will call or email you within the next business day and look forward to working with you on a future full of change and changed lives.</em></p>';
			}
		}
		xmlhttp.send(null);
	}
	
	return false; }

function checkleadgen(){
	var passedCheck = true;
	
	var passcode = document.getElementById('passcode').value;
	
	var name = document.getElementById('name').value;
	var email = document.getElementById('email').value;
	var phone = document.getElementById('phone').value;
	
	if(passcode.length > 0){
		if(passcode == '781HD83a'){
			$('label.passcode').css({'color':'#7F8173','font-style':'normal'});
			var whichPodcast = document.getElementById('podcast').value;
			redirectPodcast(whichPodcast);
		}else{
			$('label.passcode').css({'color':'red','font-style':'italic'});
			passedCheck = false;
		}
	}else{
		if(name == ''){
			$('label.name').css({'color':'red','font-style':'italic'});
			passedCheck = false;
		}else{
			$('label.name').css({'color':'#7F8173','font-style':'normal'});
		}
		
		if(!echeck(email)){
			$('label.email').css({'color':'red','font-style':'italic'});
			passedCheck = false;
		}else{
			$('label.email').css({'color':'#7F8173','font-style':'normal'});
		}
		
		if(phone == ''){
			$('label.phone').css({'color':'red','font-style':'italic'});
			passedCheck = false;
		}else{
			$('label.phone').css({'color':'#7F8173','font-style':'normal'});
		}
	}
	
	return passedCheck; }

function sendleadgen(){	
	if(checkleadgen()){
		var whichPodcast = document.getElementById('podcast').value;
		var querystring = $('#leadGeneration').serialize(); //alert(querystring);
		xmlhttp.open("GET", "/ajaxHandler.php?action=leadgen&" + querystring + "&time=" + new  Date().getTime());
		xmlhttp.onreadystatechange = function(){
			if (xmlhttp.readyState == 4 && xmlhttp.status == 200){
				var response = xmlhttp.responseText; //alert(response);
				redirectPodcast(whichPodcast);
			}
		}
		xmlhttp.send(null);
	}
	
	return false; }

function redirectPodcast(whichPodcast){
	switch(whichPodcast){
		case '1':
			window.location = 'http://www.onecardexpert.com/products/free-podcast/podcast1/';
			break;
		case '2':
			window.location = 'http://www.onecardexpert.com/products/free-podcast/podcast2/';
			break;
		case '4':
			window.location = 'http://www.onecardexpert.com/products/free-podcast/podcast4/';
			break;
		case '5':
			window.location = 'http://www.onecardexpert.com/products/free-podcast/podcast5/';
			break;
		case '6':
			window.location = 'http://www.onecardexpert.com/products/free-podcast/podcast6/';
			break;
		case '7':
			window.location = 'http://www.onecardexpert.com/products/free-podcast/podcast7/';
			break;
		case '8':
			window.location = 'http://www.onecardexpert.com/products/free-podcast/insights-on-the-art-of-client-building/';
			break;	
		case '9':
			window.location = 'http://www.onecardexpert.com/products/free-podcast/mastering-the-science-of-client-building-video/';
			break;
		default:
			window.location = 'http://www.onecardexpert.com/products/free-podcast/podcast3/';
			break;
	}
}

function checkshortform(){
	var passedCheck = true;
	var name = document.getElementById('name').value;
	var email = document.getElementById('email').value;
	var phone = document.getElementById('phone').value;
	
	if(name == ''){
		$('label.name').css({'color':'red','font-style':'italic'});
		passedCheck = false;
	}else{
		$('label.name').css({'color':'#7F8173','font-style':'normal'});
	}
	
	if(!echeck(email)){
		$('label.email').css({'color':'red','font-style':'italic'});
		passedCheck = false;
	}else{
		$('label.email').css({'color':'#7F8173','font-style':'normal'});
	}
	
	if(phone == ''){
		$('label.phone').css({'color':'red','font-style':'italic'});
		passedCheck = false;
	}else{
		$('label.phone').css({'color':'#7F8173','font-style':'normal'});
	}
	
	return passedCheck; }

function sendshortform(){	
	if(checkshortform()){
		var querystring = $('#coachingForm').serialize(); //alert(querystring);
		xmlhttp.open("GET", "/ajaxHandler.php?action=shortform&" + querystring + "&time=" + new  Date().getTime());
		xmlhttp.onreadystatechange = function(){
			if (xmlhttp.readyState == 4 && xmlhttp.status == 200){
				var response = xmlhttp.responseText; //alert(response);
				document.getElementById('coachingForm').innerHTML = '<p style="width:560px"><br /><br /><em>Thank you for contacting Jim Marker Consulting about Personal Planning and Consulting. We\'re ready to help you build  your business, and look forward to talking with you soon.</em></p>';
			}
		}
		xmlhttp.send(null);
	}
	
	return false; }

function h1Click(){
	$("h1").click(function () { 
		window.location = "/";
	});
}

$(document).ready(function() {  
	 h1Click();
	 //$(document).pngFix(); 
});

