
function submitUser()
{
	if($.trim($("#name").val()) != "" && isPhoneNumber($("#phone").val()) && validateEmail($("#email").val())){
		
		$.post("actions/storeUser.php", { name: $("#name").val(), phone: $("#phone").val(), email: $("#email").val() } );
		$("#consultation-succes").fadeIn("fast");
		$("#consultation-entry").hide();
		
		var google_conversion_id = 1039291982;
		var google_conversion_language = "en_US";
		var google_conversion_format = "3";
		var google_conversion_color = "ffffff";
		var google_conversion_label = "nq7ICOjziAEQzqzJ7wM";
		if (1.0) {
		  var google_conversion_value = 1.0;
		}

		IncludeJavaScript('http://www.googleadservices.com/pagead/conversion.js');

		
	}else{
		if($.trim($("#name").val()) == ""){ $("#name_label").css( "color", "red" ); }else{ $("#name_label").css( "color", "black" ); };
		if(!isPhoneNumber($("#phone").val())){ $("#phone_label").css("color","red"); }else{ $("#phone_label").css( "color", "black" ); };
		if(!validateEmail($("#email").val())){ $("#email_label").css("color","red"); }else{ $("#email_label").css( "color", "black" ); };
	}
}

function IncludeJavaScript(jsFile)
{
  $("#ppc").html('<img height="1" width="1" border="0" src="http://www.googleadservices.com/pagead/conversion/1039291982/?value=1.0&amp;label=nq7ICOjziAEQzqzJ7wM&amp;guid=ON&amp;script=0"/>'); 
  
}


function isPhoneNumber(str){
  var re = /^\(?[2-9]\d{2}[\)\.-]?\s?\d{3}[\s\.-]?\d{4}$/
  return re.test(str);
}

function validateEmail(str) {

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

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

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

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

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

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

	 return true; 				
}

var currentIndex = 1;

function openPopUp(index,total)
{
	$("#pop-up-overlay").height( $("#main-beforeandafter").height() );
	$("#pop-up-overlay").fadeIn("fast");
	$("#pop-up").fadeIn("slow");
	$("#close-button").fadeIn("slow");
	
	var scrollPosition = $(window).height() + $(window).scrollTop(); 
	$("#pop-up").css("top", scrollPosition - ($(window).height() / 2));
	show(index, total);
	 
	$("#close-button").css("top", (scrollPosition - ($(window).height() / 2))-200);
}

function show(index, total)
{
	currentIndex = index;
	for(var i = 1; i < total+1; i++){
		if(i == index) {
			$("#pop-up-picture"+i).css("display", "block");
			$("#content-before"+i).css("display", "block");
			$("#content-after"+i).css("display", "block");
			$("#link-off"+i).css("display", "inline");
			$("#link-on"+i).css("display", "none");
		}else{
			$("#pop-up-picture"+i).css("display", "none");
			$("#content-before"+i).css("display", "none");
			$("#content-after"+i).css("display", "none");
			$("#link-off"+i).css("display", "none");
			$("#link-on"+i).css("display", "inline");
		}
	}
	
	
}

function next(total)
{
	currentIndex++;
	if(currentIndex == total+1) currentIndex = 1;
	show(currentIndex, total);
}

function prev(total)
{
	currentIndex--;
	if(currentIndex == 0) currentIndex = total;
	show(currentIndex, total);
}

function closePopUp()
{
	$("#pop-up-overlay").fadeOut("slow");
	$("#pop-up").fadeOut("fast");
	$("#close-button").fadeOut("fast");
}

function animateHeader()
{
	
}

function openConsultationDescription()
{
	window.open('consultationdescription.php','Consultation', 'menubar=no,width=410,height=200,toolbar=no');	
}

function verifyAdmin()
{
	var verify = prompt("Please enter passcode", "");
	if(verify != "teethtoday2009") {
		window.location = "index.php"
	}else{
		$("#results-table").css("display", "block");
	}
}