// JavaScript Document
var $j = jQuery.noConflict();
var tea_Global_timeout = new Array();
var tea_Stat = true;
var tea_Fullpat = '';
$j(document).ready(function(){tea_Loader();});

function tea_Loader(){
	tea_sched_app_front_pre();
	
	
	
	
	/*
	
	
	
	if(document.getElementById('tsfFrontEnabler')){
		clearTimeout(tsfGlobal_timeout);
		if($j('#tsfFrontEnabler').attr('title') == 'free_site_analysis'){
			tsfLoadFront();			
		}else if($j('#tsfFrontEnabler').attr('title') == 'contact'){
			tsf_contact_page();	
		}
	
		$j('.tsf_validator').each(function(){
			var tsf_v = $j(this);
			tsf_v.focus(function(){
				if($j(this).val() == $j(this).attr('title')){
					$j(this).val('');		
				}
			});
			tsf_v.blur(function(){
				if($j(this).val() == ''){
					$j(this).val($j(this).attr('title'));
				}else if($j(this).val() == $j(this).attr('title')){
					$j(this).val($j(this).attr('title'));
				}
			});
			
		});
		(document.getElementById('tsfdialog'))?'':$j('body').prepend('<div id="tsfdialog"></div>');
		
	}else{
		tsfGlobal_timeout = setTimeout("tsfLoader()", 500);
	}
	*/
	$j('link').each(function(){
		if($j(this).attr('rel') == 'index')tsfFullpat = $j(this).attr('href');						 
	});
}

function tea_sched_app_front_pre(){
	if(document.getElementById('schedule_mini_enabler')){
		if(tea_Global_timeout[1])clearTimeout(tea_Global_timeout[1]);
		tea_sched_app_front();
	}else{
		tea_Global_timeout[1] = setTimeout("tea_sched_app_front_pre()", 1000);
	}
}

function tea_sched_app_front(){
	tea_load_defaults();
	$j('.samplecalendar').datepicker();
	$j('#schedule_mini input[name=wedding_date]').datepicker({ 
		dateFormat: 'DD, MM dd, yy',
		minDate: 1,
		showOn: "both",
		buttonImage: document.getElementById('schedule_mini_enabler').value+'images/iconCalendar.gif',
		buttonImageOnly: true,
		//numberOfMonths: 2,
		//showButtonPanel: true,
		changeMonth: true,
		changeYear: true,
		onSelect: function(dateText, inst) {				
			//tep_logsheetfield_directsave(document.getElementById('searchAble').value+'/229/1/1', dateText);//
		}
	});
	
	$j('#schedule_mini').submit(function(){
		var dform = $j(this);
		tea_Stat = true;
		
		$j('#schedule_mini input[name=fname], #schedule_mini input[name=femail], #schedule_mini input[name=wedding_date]').css('color', '#969696');
		$j('#schedule_mini input[name=fname], #schedule_mini input[name=femail], #schedule_mini input[name=wedding_date]').css('background-color', '#ffffff')
		$j('#schedule_mini input[name=fname], #schedule_mini input[name=femail], #schedule_mini input[name=wedding_date]').css('border', '#c5c5c5 1px solid');
		
		tsfEmptyStat($j('#schedule_mini input[name=fname]'));
		tsfEmptyStat($j('#schedule_mini input[name=femail]'));
		tsfEmptyStat($j('#schedule_mini input[name=wedding_date]'));
		tsfEmailStat($j('#schedule_mini input[name=femail]'));
		if(tea_Stat == true){
			$j('#schedule_mini .preloader').css('visibility','visible');
			/*
			query='appaction=scheduleApp&name='+$j('#schedule_mini input[name=fname]').val()+'&email='+$j('#schedule_mini input[name=femail]').val()+'&wedding_date='+$j('#schedule_mini input[name=wedding_date]').val();		
			$j.get(tsfFullpat+'schedule-an-appointment/', query, function(data){
				alert(data);
			});*/
			urlu=tsfFullpat+'/schedule-an-appointment.html/?appaction=scheduleApp';	
			
			//alert(urlu);
			$j.ajax({
			  type: 'POST',
			  url: urlu,
 		  	  cache: false,
			  data: dform.serialize(),
			  success: function(data){
				/*
				$j('.tegminiform').css('opacity', 0);
				$j('.tegminiform').html(data);
				$j('.tegminiform').animate({
					opacity:1
				}, "slow");
				
				$j('#teaminireSubmit').click(function(){
					$j.get(document.getElementById('schedule_mini_enabler').value+'schedule_mini.php', 'action=default_disp&tempdir='+tempdir+'&schedule_mini_enabler='+document.getElementById('schedule_mini_enabler').value, function(data){	
						$j('.tegminiform').css('opacity', 0);
						$j('.tegminiform').html(data);
						$j('.tegminiform').animate({
							opacity:1
						}, "slow", function(){
							tea_sched_app_front();	
						});
						
					});
				});
				*/
				window.location.href= tsfFullpat+'/schedule-an-appointment.html';
			  }
			});	
			/*
			urlu=tsfFullpat+'schedule-an-appointment/';
			dform.attr('action', urlu);
			dform.attr('method', 'post');
			dform.submit();
			*/
		}
		return false;
	});
	
	
};

function tea_load_defaults(){
	$j('.teg_validator').each(function(){
		var v = $j(this);
		v.focus(function(){
			if(v.val() == v.attr('title')){
				v.val('');		
			}
		});
		v.blur(function(){
			if(v.val() == ''){
				v.val(v.attr('title'));
			}else if(v.val() == v.attr('title')){
				v.val(v.attr('title'));
			}
		});
	});
	(document.getElementById('teadialog'))?'':$j('body').prepend('<div id="teadialog"></div>');	
}


function tea_default_error_box(obj){
	$j(obj).css('color', '#8b0b0b');
	$j(obj).css('background-color', '#f0d8d8')
	$j(obj).css('border', '#f89695 1px solid');
	tea_Stat = false;
}





function tsfEmptyStat(o, thebgError){
	if(o.val() == '' || o.val() == o.attr('title')){
		tea_default_error_box(o);
	}
}

function tsfURLStat(o, thebgError){
	var theURLs = o.val();
	var v = new RegExp();
	if(theURLs.length>0 && theURLs !=o.attr('title')){
		
		if(theURLs.substring(0,7) == 'http://')theURLs = theURLs.substring(7);
		//v.compile("^[A-Za-z]+://[A-Za-z0-9-_]+\\.[A-Za-z0-9-_%&\?\/.=]+$");
		v.compile("^[A-Za-z0-9-_]+\\.[A-Za-z0-9-_%&\?\/.=]+$");
		if (!v.test(theURLs)) {
			tea_default_error_box(o);
		}
	}
}

function tsfEmailStat(o, thebgError){
	
	var email = o.val();
	var passed;
	var blnRetval, intAtSign, intDot, intComma, intSpace, intLastDot, intDomain, intStrLen;
	intAtSign=email.indexOf("@");
	intDot=email.indexOf(".",intAtSign);
	intComma=email.indexOf(",");
	intSpace=email.indexOf(" ");
	intLastDot=email.lastIndexOf(".");
	intDomain=intDot-intAtSign;
	intStrLen=email.length;
	// *** CHECK FOR BLANK EMAIL VALUE
	
	if (intAtSign == -1){
		tea_default_error_box(o);
	}else if (intComma != -1){
		tea_default_error_box(o);
	}else if (intSpace != -1){
		tea_default_error_box(o);
	}else if ((intDot <= 2) || (intDomain <= 1)  || (intStrLen-(intLastDot+1) < 2)){
		tea_default_error_box(o);
		tsfStat = false;
	}
};

function tsfNumberKey(evt){
	var charCode = (evt.which) ? evt.which : event.keyCode
	if (charCode > 31 && (charCode < 48 || charCode > 57))return false;
	return true;
}

function tsfdialog(text){
	$j.fx.speeds._default =1500;
	$j("#tsfdialog").html(text);
	$j("#tsfdialog:ui-dialog").dialog( "destroy" );
	$j("#tsfdialog").attr('title', 'Notification');
/*
	$j( "#tsfdialog" ).dialog({
		resizable: false,
		width:350,
		modal: true,
		buttons: {
			"Okay" : function() {
				$j( this ).dialog( "close" );
			}
		}
	});
*/
	$j( "#tsfdialog" ).dialog({
		resizable: false,
		width:800,
		height:600,
		show: "fade",
		hide: "fade",
		modal: true
	});
}
