function check_carrier(){
	var carrier_object = document.getElementById('mobile_carrier');
	var notification_type_object = document.getElementById('notification');
	
	if(notification_type_object.value == 'email'){
		carrier_object.style.display = "none";
	}
	if(notification_type_object.value == 'mobile'){
		carrier_object.style.display = "inline";
	}
}

function check_donation()
{
	var select_element = document.getElementById('donation_select');
	var form_element = document.getElementById('membership_form_donation');
	if(select_element.value == "")
	{
		alert("Please choose the youth organization that will benefit from your purchase.");
		select_element.focus();
	}
	else
	{
		form_element.submit();
	}
}

function check_donation_middle()
{
	var select_element = document.getElementById('donation_select_middle');
	var form_element = document.getElementById('membership_form_donation_middle');
	if(select_element.value == "")
	{
		alert("Please choose the youth organization that will benefit from your purchase.");
		select_element.focus();
	}
	else
	{
		form_element.submit();
	}
}

function toUnicode(elmnt,content,next)
{
    if (content.length==elmnt.maxLength)
    {
    	if(next != 4)
    	{
    		document.getElementById("code-"+next).focus();
    	}
    	if(next == 4)
    	{
    		document.getElementById("sign-in").focus();
    	}
    }
}
var xmlHttp = false;
try {
  xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
  try {
    xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
  } catch (e2) {
    xmlHttp = false;
  }
}

if (!xmlHttp && typeof XMLHttpRequest != 'undefined') {
  xmlHttp = new XMLHttpRequest();
}

function conf_del(action,type,id,user_id)
{
	if(action == "delete")
	{
		if(type == "listing")
		{
			if(confirm("Are you sure you want to delete this listing?"))
			{
				window.location = "../action.php?id="+id+"&action=delete&type=listing";
			}
		}
		if(type == "file")
		{
			if(confirm("Are you sure you want to delete this file?"))
			{
				window.location = "../action.php?id="+id+"&action=delete&type=file";
			}
		}
		if(type == "favorites")
		{
			if(confirm("Are you sure you want to delete this listing from your favorites?"))
			{
				window.location = "../action.php?user_id="+user_id+"&id="+id+"&action=delete&type=favorites";
			}
		}
	}
}

function admin_conf_del(action,type,id,user_id)
{
	if(action == "delete")
	{
		if(type == "listing")
		{
			if(confirm("Are you sure you want to delete this listing?"))
			{
				window.location = "../admin_action.php?id="+id+"&action=delete&type=listing";
			}
		}
		if(type == "business")
		{
			if(confirm("Are you sure you want to delete this business?"))
			{
				window.location = "../admin_action.php?id="+id+"&action=delete&type=business";
			}
		}
		if(type == "file")
		{
			if(confirm("Are you sure you want to delete this file?"))
			{
				window.location = "../admin_action.php?id="+id+"&action=delete&type=file";
			}
		}
		if(type == "subscriber")
		{
			if(confirm("Are you sure you want to delete this subscriber?"))
			{
				window.location = "../admin_action.php?id="+id+"&action=delete&type=subscriber";
			}
		}
	}
}

function add_to_favorites_checkout()
{
	if(xmlHttp.readyState == 4 && xmlHttp.status == 200)
	{
		confirmation = xmlHttp.responseText;
		if(confirmation == "true")
		{
			alert("The listing has been added to your favorites list");
		}
		else
		{
			alert("Error: The listing has not been added to your favorites list\n\nPlease try again later.");
		}
	}
}
function send_promotion_checkout()
{
	if(xmlHttp.readyState == 4 && xmlHttp.status == 200)
	{
		confirmation = xmlHttp.responseText;
//		alert(confirmation);
		if(confirmation == "true")
		{
			alert("This promotion has been sent to you.");
		}
		else
		{
			alert("Error: This promotion can't be sent to you.\n\nPlease try again later.");
		}
	}
}

function add_to_favorites(user_id,listing_id)
{
	if(confirm("Add Listing As Favorite\n\nBy adding this business as a favorite, I understand and agree that I am opting-in to receive alerts, notifications, advertisments and discounts from this business while they use Key To Omaha. I further understand that the business does not have access to my personal information directly and cannot contact me specifically or directly without my membership with Key To Omaha as well."))
	{	
		var url = "ajax_actions.php?action=add_to_favorites&user_id=" + escape(user_id) + "&listing_id=" + escape(listing_id);
//		prompt("",url);
		xmlHttp.open("GET", url, true);
		xmlHttp.onreadystatechange = add_to_favorites_checkout;
		xmlHttp.send(null);
	}
}
function send_promotion(user_id,listing_id)
{
	var url = "ajax_actions.php?action=send_promotion&user_id=" + escape(user_id) + "&listing_id=" + escape(listing_id);
//	prompt("",url);
	xmlHttp.open("GET", url, true);
	xmlHttp.onreadystatechange = send_promotion_checkout;
	xmlHttp.send(null);
}
function refer_to_a_friend(listing_id)
{
/*	
	var url = "ajax_actions.php?action=send_promotion&user_id=" + escape(user_id) + "&listing_id=" + escape(listing_id);
//	prompt("",url);
	xmlHttp.open("GET", url, true);
	xmlHttp.onreadystatechange = send_promotion_checkout;
	xmlHttp.send(null);
*/
}

function documentScrollTop() {
    return (document.documentElement.scrollTop + document.body.scrollTop
    == document.documentElement.scrollTop) ?
    document.documentElement.scrollTop : document.body.scrollTop;
}

function show_promotion_pop_up(id)
{
	var body = document.getElementById('body');
	var width = document.documentElement.clientWidth;
	var height = document.documentElement.clientHeight;

	var content = document.getElementById('promo_content_'+id).value;

	var modal_div = document.getElementById('modal_div');
	var inner_div = document.getElementById('inner_pop_up_div');
	
	var promo_div = document.getElementById("promotion-inner");
	
	promo_div.innerHTML = "";	
	promo_div.innerHTML = content;
	
	modal_div.style.width = width+"px";
	modal_div.style.height = body.offsetHeight+"px";
	
	scr_top = documentScrollTop();
	inner_div.style.top = (height/2 - 95)+scr_top+"px";
	inner_div.style.left = (width/2 - 150)+document.documentElement.scrollLeft+"px";
	
	modal_div.style.display = "inline";
	inner_div.style.display = "inline";
}

function hide_promotion_pop_up(id)
{
	var modal_div = document.getElementById('modal_div');
	var inner_div = document.getElementById('inner_pop_up_div');
	
	modal_div.style.display = "none";
	inner_div.style.display = "none";
}

function table_header_scroll()
{
	var body = document.getElementById('body');
	var width = document.documentElement.clientWidth;
	var height = document.documentElement.clientHeight;

	var table_header = document.getElementById('moved_header');
	
	var top_scroll = document.documentElement.scrollTop-height/2+58;
	if(top_scroll > 100)
	{
		table_header.style.display = "inline";
		table_header.style.top = top_scroll+"px";
	}
	if(top_scroll < 100)
	{
		table_header.style.display = "none";
		table_header.style.top = top_scroll+"px";
	}
}
