// JavaScript Document


function displaySignup() {
	$("#signup").dialog({
		modal: true,
		buttons: {
			Cancel: function() {
				$(this).dialog('close');
			}
		},
		resizable: false,
		width: 1000,
		height: 400
	});
}

function showMessage(id, opts) {
	if ($('#' + id + ' .aaplayer').length > 0) {
		iFrameSrc = $('#' + id + ' .aaplayer').html();
		$('#' + id + ' .aaplayer').html('<iframe src="' + iFrameSrc + '" height="40" width="90" frameborder="0" scrolling="no"></iframe>');
	}
	
	$("#" + id).dialog({
		modal: true,
		buttons: {
			Close: function() {
				$(this).dialog('close');
				if ($('#' + id + ' .aaplayer').length > 0) {
					iFrameSrc = $('#' + id + ' .aaplayer iframe').attr('src');
					$('#' + id + ' .aaplayer').html(iFrameSrc);
				}
			}
		}
	});
	for (key in opts) {
		$("#" + id).dialog('option', key, opts[key]);
	}
	
}

function dialog(html, opts) {
	$("#message").html(html);
	$("#message").dialog({
		modal: true,
		buttons: {
			Close: function() {
				$(this).dialog('close');
			}
		}
	});
	for (key in opts) {
		$("#message").dialog('option', key, opts[key]);
	}
}

function findDoctors() {
	html  = '<div style="margin:10px auto; font-size:24px;">' +
						'Enter Your Zip:<br/>' +
						'<input type="text" id="ppo_zip" name="ppo_zip" maxlength="5" style="width:100%" />' +
						'<div style="text-align:center; padding-top:3px;"><button onclick="findDoctors_action(document.getElementById(\'ppo_zip\').value)">Find My Doctor</button></div>' +
					'</div>';
	dialog(html, {title: "Find Doctors"});
}

function findDoctors_action(zip) {
	html = '<div style="text-align:center; padding-top:10px;"><img src="images/ajax/medium-circle.gif" border="0" alt="" /></div>';
	dialog(html, {title: "Loading..."});
	
	$.ajax({
					async: true,
					data: {'zip': zip},
					dataType: 'json',
					type: 'POST',
					url: '/api.php?function=CarrierFromZip',
					success: findDoctors_success
				 });
}

function PPOWindow(url) {
	//alert(url);
	window.open(url, 'PPONetwork', 'width=800,height=800,resizable=yes,scrollbars=yes,status=no', true);
}


	
function isValidEmail(email) {
	return email.match(/\b[A-Z0-9._%-]+@(?:[A-Z0-9-]+\.)+[A-Z]{2,4}\b/i);
}

function isValidZip(zip) {
	var returnJson;
	var returnArray = $.ajax({
														async: false,
														data: {'zip': zip},
														dataType: 'json',
														type: 'POST',
														url: '/api.php?function=ValidateZip'
													 });
	
	eval('returnJson = ' + returnArray.responseText);
	
	if (returnJson == false) {
		return false;
	} else {
		return true;
	}
	
}

function zipHasProvider(zip) {
	var returnJson;
	var returnArray = $.ajax({
														async: false,
														data: {'zip': zip},
														dataType: 'json',
														type: 'POST',
														url: '/api.php?function=CarrierFromZip'
													 });
	
	eval('returnJson = ' + returnArray.responseText);
	
	if (returnJson == false) {
		return false;
	} else {
		return true;
	}
	
}

function findDoctors_success(data) {
	html = '<div style="text-align:center; padding-top:10px;">';
	if (data) {
		//PPOWindow(data['PPOSearchURL']);
		html += 'PPO Network Found!<br /><a href="javascript:;" onclick="PPOWindow(\'' + data['PPOSearchURL'] + '\')">Click Here</a> to search for a doctor.';
		doPopup = true;
	} else {
		html += 'We\'re sorry, but we currently do not offer a PPO Network in your state.';
		doPopup = true;
	}
	
	html += '</div>';
	
	if (doPopup) {
		dialog(html, {title: "Your PPO Provider"});
	} else {
		$("#message").dialog('close');
	}
}

function openChat() {
	window.open('https://www.accesshealthpartners.com/chat/', '', 'height=475,width=520');
}
