var auto=0;

function email_prompt(id, category_id)
{
	 $.ajax({
	   type: "POST",
	   url: "/randomcode.html?_cache="+Math.random(),
	   data: "auto="+auto,
	   success: function(msg){
			var text="";
			
			text = '<div id="prompt">';
			text = text + 'Your email:<br /><input type="text" id="user_email'+auto+'" size=30 value=""/>';
			text = text +'<br />Send article link to email:<br />';
			text = text +'<input type="text" id="email'+auto+'" size=30 value=""/><br />Please type in the security code:<br>';
			text = text +'<img src="/includes/captcha.php?text='+msg+'&color_bg=111111&font_size=14" style="position:relative; top:1px;" border="0" />&nbsp;';
			text = text +'<input type=text size=8 id="captcha_value'+auto+'"><br />';
			text = text +'<input type="hidden" id="article" id="article" value="' +id+ '"/>';
			text = text +'<input type="button" id="send_email" value="Submit" onClick="submit_email(\''+auto+'\'); return false;" />&nbsp;<input type="button" value="Close" id="close_prompt" onClick="close_prompt(); return false;" />';
			text = text +'</div>';
			
			document.getElementById('emailstuff').innerHTML =text;
			$("#prompt").css({display:"block"});
			$("#prompt").dialog({
									modal: true, 
									resizable: false,
									overlay: { 
										opacity: 0.9, 
										background: "black" 
									} 
								});
			
			auto = auto + 1;
	   }
	 });
	
}

function close_prompt()
{	
	$("#prompt").dialog("close").remove();
}

function submit_email(auto_id)
{
	$.ajax({
	type: "POST",
	url: "/email.html",
	data:	"email"+auto_id+"=" + document.getElementById('email'+auto_id).value + "&article=" + $("#article").val() 
			+ "&captcha_value"+auto_id+"=" + document.getElementById('captcha_value'+auto_id).value + "&auto="+auto_id+"&user_email"+auto_id+"="+document.getElementById('user_email'+auto_id).value,
	success: function(msg)
	{	close_prompt();
		alert(msg);
		
		
   	}
 });	
}