// JavaScript Document

function deleteUser(catID)
{
	check = confirm("Are you sure you wish to delete this user?");
	if(check)
	{
		$.post("/bundles/users/ajax/ajax_data.php",   
		  { deleteUserID : catID } , function(data) {  
		  		alert(data);	
				if(data=="User has been successfully deleted!")
				{
					window.location.reload();
				}
			}, "html" 
		);
	}
}

function deleteTeam(catID)
{
	check = confirm("Are you sure you wish to delete this team?");
	if(check)
	{
		$.post("/bundles/users/ajax/ajax_data.php",   
		  { deleteTeamID : catID } , function(data) {  
		  		alert(data);	
				if(data=="Team has been successfully deleted!")
				{
					window.location.reload();
				}
			}, "html" 
		);
	}
}

function getParent(level, parentID)
{
	if(level==4)
	{
		$.post("/bundles/users/ajax/ajax_data.php",   
		  { getParentID : parentID } , function(data) {  $("#getParent").html(data); }, "html" 
		);
	}
	else if(level==3)
	{
		$("#getParent").html("<td><p>Proprietors discount %</p><input name='discount' id='discount' type='text' value='' /></td>");
		$("#rewardsScheme").html("<td style='background-color:#efefef; padding-top:20px;'><p style='font-size:1em;'>Rewards Scheme:</p>"
								 +"<select name=\"pointsFlag\" onchange=\"getPoints(this.value)\">"
                            	 +"<option value=\"0\">No</option><option value=\"1\">Yes</option></select></td>");
	}
	else
	{
		$("#getParent").html("");
		$("#pointsReview").html("");
		$("#rewardsScheme").html("");
		$("#pointsValue").html("");
	}
}

function showRows(className)
{
	var display;
	if($("."+className).css("display")=="none")
	{
		$("."+className).css("display", "block");
		display	=	"block";
	}
	else
	{
		$("."+className).css("display", "none");
		display	=	"none";
	}
	$.post("/bundles/users/ajax/ajax_data.php",   
	  { className : className, display : display} , function(data) {  }, "html" 
	);
}

function getPoints(level)
{
	if(level==1)
	{
		$("#pointsValue").html("<td><p>Balance:</p><input type='text' value='' name='points' id='points' /></td>");
		$("#pointsReview").html("<td><p>Review Date:</p><input type='Text' id='reviewDate' maxlength='25' size='25' name='reviewDate' value='' onClick='javascript:NewCssCal(\"reviewDate\",\"yyyymmdd\",\"dropdown\",true,24,false)' readonly /></td>");
	}
	else
	{
		$("#pointsValue").html("");
		$("#pointsReview").html("");
	}
}

function addToProgramme(pro, user)
{
	$.post("/bundles/users/ajax/ajax_data.php",   
	  { pro : pro, user : user } , function(data) {  
	  	if(data=="1")
		{
			window.location.reload();
		}
		else
		{
			alert(data);	
		}
	  }, "html" 
	);	
}

function removeFromProgramme(pro, user)
{
	$.post("/bundles/users/ajax/ajax_data.php",   
	  { delpro : pro, deluser : user } , function(data) {  
	  	if(data=="1")
		{
			window.location.reload();
		}
		else
		{
			alert(data);	
		}
	  }, "html" 
	);
}

function displayCompany(type)
{
	if(type==1)
	{
		$("#comptitle").html("<td class='notReq'>Company:</td>");
		$("#compform").html("<td class='noPad'><input name=\"company\" type=\"text\" value=\"\" /></td>");
	}
	else
	{
		$("#comptitle").html("");
		$("#compform").html("");
	}
}