function openPopoutDialog() {
	jQuery(function($) {
		$('#overlay').fadeIn('fast', function() {
			$('#box').css('display', 'block');
			// default 30%
				$('#box').animate( {
					'left' : '28%'
				}, 500);
			});
	});
}

function closePopoutDialog(prospectElementID) {
	jQuery(function($) {
		$(document).ready(function() {
			$('#' + prospectElementID).animate( {
				'left' : '-100%'
			}, 500, function() {
				$('#' + prospectElementID).css('left', '100%');
				$('#overlay').fadeOut('fast');
			});
		});
	});
}

function popoutCallback(event, Mobile, screenName, progressBarID, defaultProgressHTML, type) {
	jQuery(function($) {
		if (event == null || event.keyCode == null || event.keyCode == 13) {
			var term = $('#' + Mobile).val();
			var urls = document.URL;
			var regex = /^((\+)?(\d{2}[-])?(\d{10}){1})?(\d{11}){0,1}?$/; // Checking
			var regex2 = /^([0-9])\1*$/; // Checking for Similar digit
			var regex3 = 1234567890;
			var regex4 = 0123456789;

			if (term == '') {
				$('#' + progressBarID).html('Please enter your Name');
				$('#' + progressBarID).addClass('error');
				$('#' + Name).addClass('error');
				return;
			} else if (isNaN(term) || term.length < 10) {
				$('#' + progressBarID).html(
						'Please enter a valid 10 digit mobile number');
				$('#' + progressBarID).addClass('error');
				$('#' + Mobile).addClass('error');
				return;
			} else if (!term.match(regex)) {
				$('#' + progressBarID).html(
						'Please enter a valid mobile number');
				$('#' + progressBarID).addClass('error');
				$('#' + Mobile).addClass('error');
				return;
			} else if (term.match(regex2)) {
				$('#' + progressBarID).html(
						'Please enter a valid mobile number');
				$('#' + progressBarID).addClass('error');
				$('#' + Mobile).addClass('error');
				return;
			} else if (term.match(regex3)) {
				$('#' + progressBarID).html(
						'Please enter a valid mobile number');
				$('#' + progressBarID).addClass('error');
				$('#' + Mobile).addClass('error');
				return;
			} else if (term.match(regex4)) {
				$('#' + progressBarID).html(
						'Please enter a valid mobile number');
				$('#' + progressBarID).addClass('error');
				$('#' + Mobile).addClass('error');
				return;
			} else {
				$('#' + progressBarID).html('');
				$('#' + progressBarID).html(defaultProgressHTML);
				$('#' + progressBarID).removeClass('error');
				$('#' + Mobile).removeClass('error');
				$('#' + progressBarID)
						.html(
								'<p><img src="/ajax-loader.gif" /></p><p><span class="txtsmall">Contacting Property Experts now.  .  .  .</span></p>');
				$
						.ajax( {
							url : "popupEmail.php",
							data : {
								"MobileNo" : term,
								"ScreenName" : screenName
							},
							success : function(data) {
								window
										.setTimeout(
												function() {
													$('#' + progressBarID)
															.html(
																	'<p><span class="txtsmall">Processing Your Call Back Request on High Priority</span></p>');
												}, 2000);

								// window.setTimeout(function() {
								// $("#progressbar_mail").html(data);
								// }, 4000);
								window.setTimeout(function() {
									rrLead('',term,'', screenName, urls);
									$('#' + progressBarID).fadeIn(0).html(
											defaultProgressHTML);
								}, 6000);
								window.setTimeout(function() {
									closePopoutDialog('box');
									ppcconversion('googleTrackingHome');
									APCTracking(type, screenName);
								}, 8000);
							}
						});
			}
		}
	});
}

function validateEmail(email) {
	var re = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	return email.match(re);
}
/** ************Default text hide for imput types ************* */
jQuery(function($) {
	$(document).ready(function() {
		$('.default-value').each(function() {
			var default_value = this.value;
			$(this).focus(function() {
				if (this.value == default_value) {
					this.value = '';
				}
			});
			$(this).blur(function() {
				if (this.value == '') {
					this.value = default_value;
				}
			});
		});
		//check for popup cookie if set don't open the dialog.
		if (!Get_Cookie('popout')) {
			// possible parameters for Set_Cookie: name, value, expires, path, domain, secure
			Set_Cookie('popout', 'it works', '', '/', '', '');
			openPopoutDialog();
		}
	});
});


function APCTracking(type, title){
	jQuery(function($) {
		var MbNumber = $('#mobile').val();
		var callbackName = $('#callbackName').val();
		var callbackMobile = $('#callbackMobile').val();
		var callbackEmail = $('#callbackEmail').val();
		
		var pathname = window.location.pathname;
		
		if(callbackMobile != 'Mobile')
		{
			
			var data = pathname + ';' + callbackName + ';' + callbackMobile + ';' + callbackEmail;
		}
		else{
			var data = pathname + ';' + MbNumber;
		}
		var _gaq = _gaq || [];
		_gaq.push(['_trackEvent', type, title, data]);
	});
}

