jQuery.fn.autotab=function(){jQuery(this).keyup(function(e){switch(e.keyCode){case 9:return false;case 16:return false;case 20:return false;default:var maxlength=jQuery(this).attr('maxlength');var inputlength=jQuery(this).val().length;if(inputlength>=maxlength){jQuery(this).next('input[type="text"]').focus();}}});}

jQuery.cookie=function(name,value,options){
if(typeof value !='undefined'){
options=options ||{}
if(value===null){
value=''
options=$.extend({},options)
options.expires=-1}
var expires=''
if(options.expires&&(typeof options.expires=='number' || options.expires.toUTCString)){
var date
if(typeof options.expires=='number'){
date=new Date()
date.setTime(date.getTime()+(options.expires*24*60*60*1000))
}else{
date=options.expires}
expires='; expires='+date.toUTCString()}
var path=options.path ? '; path='+(options.path): ''
var domain=options.domain ? '; domain='+(options.domain): ''
var secure=options.secure ? '; secure' : ''
document.cookie=[name,'=',encodeURIComponent(value),expires,path,domain,secure].join('')
}else{
var cookieValue=null
if(document.cookie&&document.cookie !=''){
var cookies=document.cookie.split(';')
for(var i=0;i<cookies.length;i++){
var cookie=jQuery.trim(cookies[i])
if(cookie.substring(0,name.length+1)==(name+'=')){
cookieValue=decodeURIComponent(cookie.substring(name.length+1))
break}}}
return cookieValue}}
// JavaScript Document
//SETTING UP OUR POPUP
//0 means disabled; 1 means enabled;
var popupStatus = 0;
//loading popup with jQuery magic!
function loadPopup(){
	//loads popup only if it is disabled
	if(popupStatus==0){
		$("#backgroundPopup").css({
			"opacity": "0.7"
			});
	
	$("#popUp").load("step3.php", function(){
						$("#popUp").fadeIn("slow");
						 });
/*
	$("#popUp").hide().load("step3.php", function(){
						$("#popUp").fadeIn("slow");
						 });

*/
	$("#backgroundPopup").fadeIn("fast");

		popupStatus = 1;

	}
}

//disabling popup with jQuery magic!
function disablePopup(){
	//disables popup only if it is enabled
	if(popupStatus==1){
		$("#backgroundPopup").fadeOut("fast");
		$("#popUp").fadeOut("fast");
		popupStatus = 0;
	}
}


//centering popup
function centerPopup(){
	//request data for centering
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var popupHeight = $("#popUp").height();
	var popupWidth = $("#popUp").width();
	//centering
/*	$("#popUp").css({
	"position": "absolute",
	"top": windowHeight/2-popupHeight/2,
	"left": windowWidth/2-popupWidth/2
	});
*/
	$("#popUp").css({
	"position": "absolute",
	"left": windowWidth/2-popupWidth/2
	});

	
	//only need force for IE6
	
	$("#backgroundPopup").css({
		"height": windowHeight
	});

}

function testcheck(email_c){
	var args=testcheck.arguments; 
	var email_c=args[0]; 
		$.ajax({url: './email_check.php',  
            type: 'GET',  
			data: 'email_c=' + email_c,
            dataType: 'html',
            timeout: 20000, 
            error: function(){
			return true;
            },  
            success: function(html){  
				if (html != "ok")
				{
					$("label#errEmail").show();
					$("input#email").css('background-color', '#d7e3ba');
					$("input#email").css('border', '1px solid #8dab4a');
					$("input#email").focus();
					return false;
				}
				else
				{
					return true;
				}				
            }  
        });
}

<!-- when the page loads...->
$(document).ready(function(){
			jQuery('input.autotab').autotab();
			//initialize the first selected tab
			$("#navigation ul #tab1 a").addClass("selected");
			//hide the sub-nav for start
			$("#sub-nav").hide();
			
			//setup the tab click functions
			//TAB 1
			$("#navigation ul #tab1").click(function()
				{
					//add the selected tab
					$("#navigation ul #tab1 a").addClass("selected");
					//remove it from everythinge else
					$("#navigation ul #tab2 a").removeClass("selected");
					$("#navigation ul #tab3 a").removeClass("selected");
					$("#navigation ul #tab4 a").removeClass("selected");
					$("#navigation ul #tab5 a").removeClass("selected");
					
					//hide sub-nav : no need for it
					$("#sub-nav").hide();
					
					//reposition the column-r image
					$("#content-r").css("margin-top","40px");
					
					//load the specific content
					$("#content-l").empty();
					$("#content-l").hide();
					$("#loading").fadeIn("slow");
					$("#content-l").load("./index.html #content-l:first", function(){
						$("#content-l").fadeIn("slow");
						$("#homesecond").fadeIn("slow");
						$("#loading").fadeOut("fast");
					});
					return false;
				});
			
			//TAB 2
			$("#navigation ul #tab2").click(function()
				{
					//add the selected tab
					$("#navigation ul #tab2 a").addClass("selected");
					//remove it from everythinge else
					$("#navigation ul #tab1 a").removeClass("selected");
					$("#navigation ul #tab3 a").removeClass("selected");
					$("#navigation ul #tab4 a").removeClass("selected");
					$("#navigation ul #tab5 a").removeClass("selected");
					
					//fade in sub-nav
					$("#sub-nav").fadeIn("slow");
					
					//reposition the column-r image
					$("#content-r").css("margin-top","0px");
					
					//load the specific content
					$("#content-l").empty();
					$("#content-l").hide();
					$("#homesecond").hide();
					$("#loading").fadeIn("slow");
					$("#content-l").load("./plans.html #content-l:first", function(){
						$("#content-l").fadeIn("slow");
						$("#loading").fadeOut("fast");
					   
					});
 				 
					return false;
				});
			
			//TAB 3
			$("#navigation ul #tab3").click(function()
				{
					//add the selected tab
					$("#navigation ul #tab3 a").addClass("selected");
					//remove it from everythinge else
					$("#navigation ul #tab1 a").removeClass("selected");
					$("#navigation ul #tab2 a").removeClass("selected");
					$("#navigation ul #tab4 a").removeClass("selected");
					$("#navigation ul #tab5 a").removeClass("selected");
					
					//hide sub-nav : no need for it
					$("#sub-nav").hide();
					
					//reposition the column-r image
					$("#content-r").css("margin-top","40px");
					
					//load the specific content
					$("#content-l").empty();
					$("#content-l").hide();
					$("#homesecond").hide();
					$("#loading").fadeIn("slow");
					$("#content-l").load("./faq.html #content-l:first", function(){
						$("#content-l").fadeIn("slow");
						$("#loading").fadeOut("fast");
					});
					return false;
				});
			
			//TAB 4
			$("#navigation ul #tab4").click(function()
				{
					//add the selected tab
					$("#navigation ul #tab4 a").addClass("selected");
					//remove it from everythinge else
					$("#navigation ul #tab1 a").removeClass("selected");
					$("#navigation ul #tab2 a").removeClass("selected");
					$("#navigation ul #tab3 a").removeClass("selected");
					$("#navigation ul #tab5 a").removeClass("selected");
					
					//hide sub-nav : no need for it
					$("#sub-nav").hide();
					
					//reposition the column-r image
					$("#content-r").css("margin-top","40px");
					
					//load the specific content
					$("#content-l").empty();
					$("#content-l").hide();
					$("#homesecond").hide();
					$("#loading").fadeIn("slow");
					$("#content-l").load("./studies.html #content-l:first", function(){
						$("#content-l").fadeIn("slow");
						$("#loading").fadeOut("fast");
					});
					return false;
				});
			
			//TAB 5
			$("#navigation ul #tab5").click(function()
				{
					//add the selected tab
					$("#navigation ul #tab5 a").addClass("selected");
					//remove it from everythinge else
					$("#navigation ul #tab1 a").removeClass("selected");
					$("#navigation ul #tab2 a").removeClass("selected");
					$("#navigation ul #tab3 a").removeClass("selected");
					$("#navigation ul #tab4 a").removeClass("selected");
					
					//hide sub-nav : no need for it
					$("#sub-nav").hide();
					
					//reposition the column-r image
					$("#content-r").css("margin-top","40px");
					
						//load the specific content
					$("#content-l").empty();
					$("#content-l").hide();
					$("#homesecond").hide();
					$("#loading").fadeIn("slow");
					$("#content-l").load("./finder.html #content-l:first", function(){
						$("#content-l").fadeIn("slow");
						$("#loading").fadeOut("fast");
					});
					return false;
				});
			
			/** Sub Navigation **/
			
			//setup the sub-tab click functions
			//Sub TAB 1
			$("#sub-nav ul #sub1").click(function()
				{
					//load the specific content
					$("#content-l").empty();
					$("#content-l").hide();
					$("#homesecond").hide();
					$("#loading").fadeIn("slow");
					$("#content-l").load("./plans.html #content-l:first", function(){
						$("#content-l").fadeIn("slow");
						$("#loading").fadeOut("fast");
					});
					return false;
				});
			
			//Sub TAB 2
			$("#sub-nav ul #sub2").click(function()
				{
					//load the specific content
					$("#content-l").empty();
					$("#content-l").hide();
					$("#homesecond").hide();
					$("#loading").fadeIn("slow");
					$("#content-l").load("./healthcareMediation.html #content-l:first", function(){
						$("#content-l").fadeIn("slow");
						$("#loading").fadeOut("fast");
					});
					return false;
				});
			
			//Sub TAB 3
			$("#sub-nav ul #sub3").click(function()
				{
					
					//load the specific content
					$("#content-l").empty();
					$("#content-l").hide();
					$("#homesecond").hide();
					$("#loading").fadeIn("slow");
					$("#content-l").load("./dentalCare.html #content-l:first", function(){
						$("#content-l").fadeIn("slow");
						$("#loading").fadeOut("fast");
					});
					return false;
				});
			
			//Sub TAB 4
			$("#sub-nav ul #sub4").click(function()
				{
					/*add the selected tab
					$("#navigation ul #sub1 a").addClass("selected");
					//remove it from everythinge else
					$("#navigation ul #sub2 a").removeClass("selected");
					$("#navigation ul #sub3 a").removeClass("selected");
					$("#navigation ul #sub4 a").removeClass("selected");
					$("#navigation ul #sub5 a").removeClass("selected");
					
					//hide sub-nav : no need for it
					$("#sub-nav").hide();*/
					
					//reposition the column-r image
					//$("#content-r").css("margin-top","40px");
					
					//load the specific content
					$("#content-l").empty();
					$("#content-l").hide();
					$("#homesecond").hide();
					$("#loading").fadeIn("slow");
					$("#content-l").load("./prescriptionDrugs.html #content-l:first", function(){
						$("#content-l").fadeIn("slow");
						$("#loading").fadeOut("fast");
					});
					return false;
				});
			
			//Sub TAB 5
			$("#sub-nav ul #sub5").click(function()
				{
					//load the specific content
					$("#content-l").empty();
					$("#content-l").hide();
					$("#homesecond").hide();
					$("#loading").fadeIn("slow");
					$("#content-l").load("./vision.html #content-l:first", function(){
						$("#content-l").fadeIn("slow");
						$("#loading").fadeOut("fast");
					});
					return false;
				});
			
			//Sub TAB 6
			$("#sub-nav ul #sub6").click(function()
				{					
					//load the specific content
					$("#content-l").empty();
					$("#content-l").hide();
					$("#homesecond").hide();
					$("#loading").fadeIn("slow");
					$("#content-l").load("./chiropractic.html #content-l:first", function(){
						$("#content-l").fadeIn("slow");
						$("#loading").fadeOut("fast");
					});
					return false;
				});
			
			//Sub TAB 6
			$("#sub-nav ul #sub7").click(function()
				{
					//load the specific content
					$("#content-l").empty();
					$("#content-l").hide();
					$("#homesecond").hide();
					$("#loading").fadeIn("slow");
					$("#content-l").load("./hotline.html #content-l:first", function(){
						$("#content-l").fadeIn("slow");
						$("#loading").fadeOut("fast");
					});
					return false;
				});
			
	/** Sign Up Form **/
	//append dob sel
	var i;
	for (i=1; i<=12; i++)
	{
		$("<option value='"+i+"'>"+i+"</option>").appendTo("#dobmonth")
	}
	for (i=1; i<=31; i++)
	{
		$("<option value='"+i+"'>"+i+"</option>").appendTo("#dobday")
	}
	var age = 18;
	$("span#agelimit").html(age);
	var currdate = new Date();
	for (i=currdate.getFullYear()-1; i>=1900; i--)
	{
		$("<option value='"+i+"'>"+i+"</option>").appendTo("#dobyear")
	}
	
	//If the submit button is clicked...
	$("#submit-btn").click(function()
	{
		var fname = $("input#fname").val();
		var lname = $("input#lname").val();
		var email = $("input#email").val();
  		var postal = $("input#postal").val();
	
  		if (fname == "")
		{
        	$("label#errFname").show();
			$("input#fname").css('background-color', '#d7e3ba');
			$("input#fname").css('border', '1px solid #8dab4a');
        	$("input#fname").focus();
       		return false;
     	}		
		$("label#errFname").hide();		
  		if (lname == "")
		{
        	$("label#errLname").show();
			$("input#lname").css('background-color', '#d7e3ba');
			$("input#lname").css('border', '1px solid #8dab4a');
        	$("input#lname").focus();
       		return false;
     	}
		$("label#errLname").hide();
		
		var re = /^[^\s()<>@,;:\/]+@\w[\w\.-]+\.[a-z]{2,}$/i;  		
  		if (email == "" || !(re.test(email))) 
		{
			$("label#errEmail").show();
			$("input#email").css('background-color', '#d7e3ba');
			$("input#email").css('border', '1px solid #8dab4a');
			$("input#email").focus();
			return false;
        }	
		$("label#errEmail").hide();		
  	

	   // for DOB checking
		var dobm= $("select#dobmonth").val();
		var dobd= $("select#dobday").val();
		var doby= $("select#dobyear").val();	
		var age = 18;
		var mydate = new Date();
		mydate.setFullYear(doby, dobm-1, dobd);
		var currdate = new Date();
		currdate.setFullYear(currdate.getFullYear() - age);		
		if ((currdate - mydate) < 0){
			$("label#errDOB").show();
			$("select#dobyear").css('background-color', '#d7e3ba');
			$("select#dobyear").css('border', '1px solid #8dab4a');
			$("select#dobyear").focus();
			return false;
		}
		$("label#errDOB").hide();

		//for phone checking
		var phone1 = $("input#phone1").val();
  		if (phone1== "" || isNaN(phone1))
		{
			$("label#errPhone").show();
      		$("input#phone1").css('background-color', '#d7e3ba');
			$("input#phone1").css('border', '1px solid #8dab4a');
        	$("input#phone1").focus();
       		return false;
     	}	
		var phone2 = $("input#phone2").val();
  		if (phone2== "" || isNaN(phone2))
		{
			$("label#errPhone").show();
      		$("input#phone2").css('background-color', '#d7e3ba');
			$("input#phone2").css('border', '1px solid #8dab4a');
        	$("input#phone2").focus();
       		return false;
     	}	
		var phone3 = $("input#phone3").val();
  		if (phone3== "" || isNaN(phone3))
		{
			$("label#errPhone").show();
      		$("input#phone3").css('background-color', '#d7e3ba');
			$("input#phone3").css('border', '1px solid #8dab4a');
        	$("input#phone3").focus();
       		return false;
     	}	
		$("label#errPhone").hide();

		var gender	= $("select#gender").val();

		//zipcode checking
		if (postal == "" || isNaN(postal))
		{
			$("label#errPostal").show();
			$("input#postal").css('background-color', '#d7e3ba');
			$("input#postal").css('border', '1px solid #8dab4a');
			$("input#postal").focus();
			return false;
       }
	   $("label#errPostal").hide();

	  //save to cookies
	  $.cookie('fn', fname);
	  $.cookie('ln', lname);
	  $.cookie('em', email);	
	  $.cookie('po', postal);

	  $.cookie('hac', phone1);
	  $.cookie('hpre', phone2);
	  $.cookie('hln', phone3);
	  
	  $.cookie('dobm',dobm);
	  $.cookie('dobd',dobd);
	  $.cookie('doby',doby);
	  
	  $.cookie('ge',gender);	

	  //start the AJAX process
	  var dataString = 'fn='+ fname + '&ln' + lname + '&em=' + email + '&po=' + postal ;
	  
	  $.ajax({url: './write_stp1.php',  
            type: 'GET',  
            dataType: 'html',
            timeout: 20000, 
            error: function(){
			alert('Database Problem! Please Contact Admin.');
			return false;
            },  
            success: function(html){  

                //$('#htmlTarget').html(html);
				var re2 = /^[\d]+$/i;  		
				if (html == "" || !(re2.test(html)))
				{
					alert('Database Problem! Please Contact Admin.');
					return false;
				}
				else
				{
					//alert(html);
					$.cookie('regid', html);
				}
            }  
        });

	  $("#loading").fadeIn("slow");
			centerPopup();
			//load popup
			loadPopup();
			$("#loading").fadeOut("slow");  
			//alert($("#popUp").html());
		  return false;
	
	});	

	$("#retun-btn").click(function()
		{
		//disable the pop-up and return the user to the main page
		disablePopup()
		});
			
});
