function rememberMe(elem)
{
	var isChecked = elem.attr('checked');

	if(isChecked == false){
		elem.attr('checked','checked');
	}
	else{
		elem.removeAttr('checked');
	}

	return false;
}

function popMessage(issue)
{
	switch(issue)
	{
		case "disabled_referrers":
			msg = "<div><label>Disabled Referrers</label><div class='spacer30'></div><p>This feature could be used for a traffic tracking purposes. If you trade traffic with websites that sell traffic to Traffic Place, we suggest you to enable this option. In this case you will be able to understand if clicks received from these websites directly or delivered by Traffic Place, because, if you enable this option, clicks from Traffic Place will be counted as blocked ref traffic at your traffic stats.</p></div>";
			break;
	}
	
	Boxy.alert(msg);
}

$(function(){
	$(".boxy").boxy();
});

function notifyPayment(uid,processor)
{
	var amount = $("#epassporte_amount").val();
	
	$.ajax({
		type:"POST",
		url:"/ajax/notifyPayment.php",
		data:"uid="+uid+"&processor="+processor+"&m="+amount,
		success:function(msg){
			if(msg == 'success'){
				Boxy.alert("Thanks. Your account will be update in 1-2 hours.");
			}else{
				Boxy.alert("System busy. Please try it later.");
			}
		}
		});
}

function submitTicket()
{
	Boxy.load('/ajax/boxy_ticket.php',{title:"Submit Trouble Ticket/Contact Customer Server", modal:true});
}

function clickSubmitAnswerTicket(ticket_id)
{
	var answer = jQuery.trim($("#ticket_answer_"+ticket_id).val());
	var sender_id = $('#sender_id').val();
	if(answer.length <=0){
		$(".close").click();
		return false;
	}
	
	$.ajax({
		type:"POST",
		url:"/ajax/boxy_ticket.php",
		data:"a=answer&tid="+ticket_id+"&answer="+answer+"&sid="+sender_id,
		success:function(msg){
			$(".close").click();
			if(msg == 'success'){
				Boxy.alert("Thanks. Already send your answer to user via email.");
			}else{
				Boxy.alert("System busy. Please try it later.");
			}
		}
	});
}

function clickSubmitTick()
{
	var uid    = $("#uid").val();
	var ticket = $("#ticket").val();
	
	$.ajax({
		type:"POST",
		url:"/ajax/boxy_ticket.php",
		data:"a=doSubmit&t="+ticket+"&u="+uid,
		success:function(msg){
			$(".close").click();
			switch(msg)
			{
				case 'success':
					Boxy.alert("Ticket has been sent.");
					break;
				case 'fail':
					Boxy.alert("Failed to submit ticket, please try it later.");
					break;
			}
		}
	});
}

function chars_left(target_id, max_length)
{ 
	var chars_left = max_length - $("#"+target_id+" textarea").val().length;

	if (chars_left < 0)
		chars_left = 0;
		
	$("#"+target_id+" .chars_left").html(chars_left + " Characters left.");
}

function validateInvoiceForm()
{   
	$("#invoiceBuilderForm").validate({
		errorElement: "em",
		errorPlacement: function(error, element) {
			error.appendTo( element.closest("td.check_field").next("td.info") );
		},
		rules:{
			invoice_campany_name:{
				required:true,
				maxlength:250
			},
			invoice_name:{
				maxlength:250
			},
			invoice_street:{
				maxlength:250
			},
			invoice_zip:{
				maxlength:16
			},
			invoice_city:{
				maxlength:64
			},
			invoice_country:{
				maxlength:64
			}			
		}

	});
}

function boxy_buildInvoice()
{
	Boxy.load('/ajax/boxy_invoice.php',
			  {title:"Build Invoice",
			   modal:true,
			   unloadOnHide:true,
			   afterShow:function(){
				   validateInvoiceForm();
			   }
			});
	
}

function boxy_affiliates()
{
	Boxy.load(
			  '/ajax/boxy_affiliates.php',
			  {title:"Affiliates Stats",
			   modal:true
			});
}


