/* Advertise */
function updatepack(){
	specialid = $("#spackformlist").val();
	specialtext = $("#spackformlist option[value="+specialid+"]").text();
	var packlist = "<strong>"+specialtext+"</strong>";
	packlist += '<ul>';
	for (var k in specialitemsList.specialitems){
		if(specialitemsList.specialitems[k].specialpack == specialid){
			packlist += "<li>"+specialitemsList.specialitems[k].amount+" "+specialitemsList.specialitems[k].title+"</li>";
		}
	}
	packlist += '<ul>';
	$("#specialpackdescr").html(packlist);
}
function prepare_payment(formid){
	selectorid = $("#"+formid+"list").val();
	itemdetails = $("#"+formid+"list").children("[value='"+selectorid+"']").text();
	var productname = $("#"+formid+"product").val();
	//return false;
	$("#itemname").html(itemdetails);
	$("#productname").html(productname);
	$("#ads_list").hide();
	var payment_details = '';
	$.each($('#'+formid).serializeArray(), function(i, field) {
   		payment_details += '<input type="hidden" name="'+field.name+'" id="'+field.name+'" value="'+field.value+'" />';
	});
	$("#payment_details").html(payment_details);
	$("#payment_form").show();
	return false;
}
function cancel_payad(){
	$("#payment_form").hide();
	$("#ads_list").show();
}
function submitpayment(){
	hideerror('errorbox');
	$("#checkoutform").l2block("#ffffff","35");
	var jqxhr = $.post("index.php?view=account&page=buy&",$("#checkoutform").serialize(), function(data) {
	if(data.status == 0){
		showerror('errorbox', data.msg);
		$("#checkoutform").l2unblock();
	}else{
		location.href='index.php?view=account&page=thankyou&order='+data.msg+'';
	}

   }, "json")
return false;
}
/* End Advertise */

function showerror(id, msg){
	$("#"+id).html(msg);
	$("#"+id).fadeIn('slow');
}
function hideerror(id){
	$("#"+id).fadeOut('slow');
}
/* Login */
function loginform() {
	hideerror('errorbox');
	$("#loginform").l2block("#ffffff",35);
	var jqxhr = $.post("index.php?view=login&a=submit",$("#loginform").serialize(), function(data) {
	if(data.status == 0){
		showerror('errorbox', data.msg);
		$("#loginform").l2unblock();
	}else{
		location.href='index.php?view=login&a=y';
	}
   }, "json")
return false;
}
/* Register */
function registerform() {
	hideerror('errorbox');
	$("#registerform").l2block("#ffffff", 35);	
	var jqxhr = $.post("index.php?view=register&a=submit&",$("#registerform").serialize(), function(data) {
	if(data.status == 0){
		captchareload();
		showerror('errorbox', data.msg);
		$("#registerform").l2unblock();
	}else{
		$("#registerform").remove();
		$("#message_sent").show();
	}

   }, "json")
return false;
}
/* Activation */
function activationform() {
	hideerror('errorbox');
	var jqxhr = $.post("index.php?view=activation&a=submit&",$("#activationform").serialize(), function(data) {
	if(data.status == 0){
		showerror('errorbox', data.msg);
	}else{
		$("#activationform").remove();
		$("#message_sent").show();
	}
   }, "json")
return false;
}
/* Recovery */
function recovery(classe){
	hideerror('errorbox');
	var jqxhr = $.post("index.php?view=recovery&class="+classe+"&a=submit&",$("#recoveryform").serialize(), function(data) {
	if(data.status == 0){
		showerror('errorbox', data.msg);
	}else{
		$("#recoveryform").remove();
		$("#message_sent").show();
	}
   }, "json")
	return false;
}
/* HelpDesk */

function OpenSupportTicket(){
	hideerror('errorbox');
	name = $("#hdname").val();
	email = $("#hdemail").val();
	subject = $("#hdsubject").val();
	message = $("#hdmessage").val();
	department = $("#departmentshd").val();
	if(logged != 'yes'){
		if(name == ''){
			showerror('errorbox', name_error);
			$('html, body').animate({scrollTop:0}, 'slow');
			return false;
		}else
		if(email == ''){
			showerror('errorbox', email_error);
			$('html, body').animate({scrollTop:0}, 'slow');
			return false;
		}else
		if(!/^[0-9a-zA-Z_\-\.]+@[0-9a-zA-Z\-\.]+\.[a-z]{2,4}$/.test(email)){
			showerror('errorbox', email_error);
			$('html, body').animate({scrollTop:0}, 'slow');
			return false;
		}
		
	}
	if(subject == ''){
		showerror('errorbox', subject_error);
		$('html, body').animate({scrollTop:0}, 'slow');		
	}else
	if(department == ''){
		showerror('errorbox', department_error);
		$('html, body').animate({scrollTop:0}, 'slow');		
	}else
	if(message == ''){
		showerror('errorbox', message_error);
		$('html, body').animate({scrollTop:0}, 'slow');			
	}else{
		$("#helpdeskform").l2block("#ffffff", 35);
		var jqxhr = $.post("index.php?view=contact&t=new&",$("#helpdeskform").serialize(), function(data) {
		if(data.status == 0){
			showerror('errorbox', data.msg);
			$('html, body').animate({scrollTop:0}, 'slow');		
			$("#helpdeskform").l2unblock();
		}else{
			$("#helpdeskform").remove();
			$("#ticketmsgid").html(data.msg);
			$("#message_sent").show();
		}
	
	   }, "json")
		captchareload();
		return false;
	}
	return false;	
}
function checkticket(){
	hideerror('errorbox');
	var ticketid = $("#ticketid").val();
	$('html, body').animate({scrollTop:0}, 'slow');
	if(ticketid == ''){
		showerror('errorbox', message_error);
	}else{
		location.href='index.php?view=contact&t=view&id='+ticketid;
	}
	return false;
}
function addTicketReply(){
	hideerror('errorbox');
	var ticketid = $("#ticketid").val();
	var message = $("#hdmessage").val();
	if(message == ''){
		showerror('errorbox', message_error);
		$('html, body').animate({scrollTop:0}, 'slow');
		return false;
	}	
}
/* Virtual Keyboard */
function loginkeyboard(){
	$("input").focus(function(){
		$('input').removeClass('input-focus');
		$(this).addClass('input-focus');
	});
	$('#keyboard li').each(function(){
		$(this).addClass('keyboard-buton');
	}).hover(function(){
		$(this).addClass('keyboard-buton-hover');
	}, function(){
		$(this).removeClass('keyboard-buton-hover')}).click(function(){
			kb( $('input.input-focus'), $(this) );
		});;function kb(ok,ob){var $write = ok,shift = false,capslock = false;var $this = ob,character = $this.html();if ($this.hasClass('left-shift') || $this.hasClass('right-shift')){$('.letter').toggleClass('uppercase');$('.symbol span').toggle();shift = (shift === true) ? false : true;capslock = false;return false;}if ($this.hasClass('capslock')){$('.letter').toggleClass('uppercase');capslock = true;return false;}if ($this.hasClass('delete')){var html = $write.val();$write.val(html.substr(0, html.length - 1));return false;}if ($this.hasClass('symbol')) character = $('span:visible', $this).html();if ($this.hasClass('space')) character = ' ';if ($this.hasClass('tab')) character = "\t";if ($this.hasClass('return')) character = "\n";if ($this.hasClass('uppercase')) character = character.toUpperCase();if (shift === true){$('.symbol span').toggle();if (capslock === false) $('.letter').toggleClass('uppercase');shift = false;}$write.val($write.val() + character);}
}
/* LoginOut Process */
function loginoutprocess(actionloginout){

	$("#progressbar").link2progress(10, function(){
	 	if(actionloginout == 'login'){
			location.href = 'index.php?view=account';
		}else{
			location.href = 'index.php';
		}
	});

	//	$("#progressbar").link2progress(10);
}

/* Timer */
function dateTimer(){
	var hours=mydate.getHours();
	var minutes=mydate.getMinutes();
	var seconds=mydate.getSeconds();
	if(hours<10){ hours='0'+hours;}
	if(minutes<10){minutes='0'+minutes; }
	if(seconds<10){ seconds='0'+seconds; }
	fech=hours+":"+minutes+":"+seconds;
	$("#timenow").html(fech);
	mydate.setSeconds(mydate.getSeconds()+1);
	setTimeout("dateTimer()",1000);
}

/* Request Payment */
function requestpayment(id){
	hideerror('errorbox');
	$("#withdrawform-"+id).l2block("#ffffff", 35);	
	var jqxhr = $.post("index.php?view=account&page=withdraw&",$("#withdrawform-"+id).serialize(), function(data) {
	if(data.status == 0){
		$("#withdrawform-"+id).l2unblock();	
		showerror('errorbox', data.msg);
	}else{
		$("#withdrawform-"+id).remove();
		$("#message_sent").show();
	}
   }, "json")
	return false;

}
/* Delete referral */
function directrefaction(){
	hideerror('errorbox');
	$("#referral_list").l2block("#ffffff", 35);	
	var jqxhr = $.post("index.php?view=account&page=referrals",$("#reflist").serialize(), function(data) {
	if(data.status == 0){
		$("#referral_list").l2unblock();	
		showerror('errorbox', data.msg);
	}else{
		location.href='index.php?view=account&page=referrals';
	}
   }, "json")
	return false;																										
}
function sowdeletionbar(){
	var referrals=$("input:checked[name^='ref']");
	var refslist=referrals.length;
	var raction = $("#descr").val();
	$("#priceref").hide();
	$("#priceref2").hide();
	$("#paybutton").hide();
	$("#addfunds").hide();
	if(refslist>0){
		$("#rentedbar").show();	
		if(raction == "delete"){
			var price = deletion_price*refslist;
			price = price.toFixed(3);
			var step1 = 'done';
		}
		if(step1 == 'done'){
			if(rental_balance >= price){
				$("#priceref").html(totaltopay+": $"+price);
				$("#priceref").show();
				$("#paybutton").show();
			}else{
				$("#priceref2").html(noenoughfunds);
				$("#priceref2").show();
			}
		}
	}else{
		$("#rentedbar").hide();	
	}
}
/* Rent Referrals Options */
function rentedaction(){
	hideerror('errorbox');
	$("#referral_list").l2block("#ffffff", 35);	
	var jqxhr = $.post("index.php?view=account&page=rented_referrals",$("#reflist").serialize(), function(data) {
	if(data.status == 0){
		$("#referral_list").l2unblock();	
		showerror('errorbox', data.msg);
	}else{
		location.href='index.php?view=account&page=rented_referrals';
	}
   }, "json")
	return false;
}
function sowrentedbar(){
	var rented=$("input:checked[name^='ref']");
	var rentedlist=rented.length;
	var raction = $("#descr").val();
	$("#priceref").hide();
	$("#priceref2").hide();
	$("#paybutton").hide();
	$("#addfunds").hide();
	if(rentedlist>0){
		$("#rentedbar").show();	
		if(raction == 1){
			var price = recycle_price*rentedlist;
			price = price.toFixed(3)
		}
		if(raction == 2){
			var price = renew_price*rentedlist;
			price = price.toFixed(3)
		}
			if(rental_balance >= price){
				$("#priceref").html(totaltopay+": $"+price);
				$("#priceref").show();
				$("#paybutton").show();
			}else{
				if(price != null){
				$("#priceref2").html(noenoughfunds);
				}
				$("#priceref2").show();
				$("#addfunds").show();
			}

	}else{
		$("#rentedbar").hide();	
	}
}
/* Submit PTSU Request */
function submitptsu(id){
	hideerror('errorbox');
	$("#submitptsu").l2block("#ffffff", 35);	
	var jqxhr = $.post("index.php?view=account&page=ptsu&id="+id,$("#submitptsu").serialize(), function(data) {
	if(data.status == 0){
		$("#submitptsu").l2unblock();	
		showerror('errorbox', data.msg);
	}else{
		$("#submitptsu").remove();
		$("#message_sent").show();
	}
   }, "json")
	return false;
}

/* Message Center Action */
function message_action(){
	hideerror('errorbox');
	$("#msglist").l2block("#ffffff", 35);	
	var jqxhr = $.post("index.php?view=account&page=messages",$("#msglist").serialize(), function(data) {
	if(data.status == 0){
		$("#msglist").l2unblock();	
		showerror('errorbox', data.msg);
	}else{
		location.href='index.php?view=account&page=messages';
	}
   }, "json")
	return false;
}

function message_send(){
	hideerror('errorbox');
	$("#massage_form").l2block("#ffffff", 35);	
	var jqxhr = $.post("index.php?view=account&page=messages&do=compose",$("#massage_form").serialize(), function(data) {
	if(data.status == 0){
		$("#massage_form").l2unblock();	
		showerror('errorbox', data.msg);
	}else{
		$("#massage_form").remove();
		$("#message_sent").fadeIn();;
	}
   }, "json")
	return false;
}

function forum_preview(){
	hideerror('errorbox');
	$('#preview').hide();
	$("#massage_form").l2block("#ffffff", 35);	
	datatosend = $("#massage_form").serialize();
	datatosend += "&preview=1";
	var jqxhr = $.post("includes/bbcode.php",datatosend, function(data) {
	if(data.status == 0){
		$("#massage_form").l2unblock();	
		showerror('errorbox', data.msg);
	}else{
		$("#preview_msg").html(data.msg);
		$("#massage_form").l2unblock();	
		$("#preview").fadeIn();	
	}
   }, "json")
	return false;
}


/* Ads Manager */
function createad(classe){
	hideerror('errorbox');
	$("#create_ad").l2block("#ffffff", 35);	
	var jqxhr = $.post("index.php?view=account&page=createad&class="+classe+"&a=submit&",$("#create_ad").serialize(), function(data) {
	if(data.status == 0){
		showerror('errorbox', data.msg);
		$("#create_ad").l2unblock();
	}else{
		$("#create_ad").remove();
		$("#message_sent").show();
	}
   }, "json")
	return false;
}

/* Ad Validation */
	function ptcevolution_surfer(){
		if (top != self) {
			try { top.location = self.location; }
			catch (err) { self.location = '/FrameDenied.aspx'; }
		}
		$("#surfbar").html("<div class='adwait'>"+adwait+"</div>");
	}
	function vshowadbar(error){
		if(error == ''){
			$(".adwait").fadeOut(1000, function(){
				$("#surfbar").html('<div class="progressbar" id="progress"><div id="progressbar"></div></div>');
				$("#progressbar").link2progress(secs, function(){
					vendprogress('');
				});
			});
		}else{
			$(".adwait").fadeOut(1000, function(){
				$("#surfbar").html("<div class='errorbox'>"+error+"</div>");
				$(".errorbox").fadeIn(1000);
			});
		}
	}
	function vendprogress(masterkey){
	 if(masterkey==''){
		 $("#surfbar").fadeOut('slow', function(){
			$("#vnumbers").fadeIn('slow');										
		});  
		 return false;
	 }else{
		$("#vnumbers").fadeOut('slow', function(){
			$(this).remove();
			$("#surfbar").fadeIn('slow'); 
		});
		
	 }
	 $("#surfbar").html("Please wait...");
	 var dataString = 'action=verify&id='+adid+'&masterkey='+masterkey; 
			$.ajax({
				type: "POST",
				url: "index.php?view=account&page=validate&",
				data: dataString,
				success: function(msg){
					if(msg=='ok'){
						$("#surfbar").html("<div class='successbox'>"+adcredited+"</div>");
						$(".successbox").fadeIn('slow');
						window.opener.location.reload();
						return false;
					}else{
						 $("#surfbar").html("<div class='errorbox'>"+msg+"</div>");
						 $(".errorbox").fadeIn('slow');
					}
				}
			});
	}

/* Ads Page */
function hideAdminAdvertisement(){
	$("#admin_advertisement").remove();
	$(".blockthis").l2unblock();
}
function hideAdvertisement(id){
	$("#"+id).addClass('disabled');
}
/* Personal Settings */
function savechanges(){
	hideerror('errorbox');
	$("#settingsform").l2block("#ffffff", 35);	
	var jqxhr = $.post("index.php?view=account&page=settings",$("#settingsform").serialize(), function(data) {
	if(data.status == 0){
		showerror('errorbox', data.msg);
		$('html, body').animate({scrollTop:0}, 'slow');
		$("#settingsform").l2unblock();
	}else
	if(data.status == 1){
		$("#settingsform").remove();
		$("#message_sent").show();
	}else{
		location.href='index.php?view=account&page=settings';
	}
   }, "json")
	return false;
}
function updateemail(act){
	hideerror('errorbox');
	$("#settingsform").l2block("#ffffff", 35);
	var jqxhr = $.post("index.php?view=account&page=settings&a="+act,$("#settingsform").serialize(), function(data) {
	if(data.status == 0){
		showerror('errorbox', data.msg);
		$('html, body').animate({scrollTop:0}, 'slow');
		$("#settingsform").l2unblock();
	}else{
		$("#settingsform").remove();
		if(act == 'restore'){
			$("#message_sent2").show();
		}else{
			$("#message_sent").show();
		}
	}
   }, "json")
	return false;
}
/* Banners */
function setReferralBanners(reflink, bannerurl, bannerWidth, bannerHeight){
	$("#referral_link").html(reflink);
	$("#banner_url").html(bannerurl);
	$("#banner_html").html(banner2html(reflink, bannerurl, bannerWidth, bannerHeight));
	$("#banner_bbcode").html(banner2bbcode(reflink, bannerurl));
}
function banner2html(reflink, bannerurl, bannerWidth, bannerHeight){
	var bannercode = "&lt;a target=&quot;_blank&quot; href=&quot;"+reflink+"&quot;&gt;&lt;img src=&quot;"+bannerurl+"&quot; border=&quot;0&quot; width=&quot;"+bannerWidth+"&quot; height=&quot;"+bannerHeight+"&quot; /&gt;&lt;/a&gt;";
	return bannercode;
}
function banner2bbcode(reflink, bannerurl){
	var bannercode = "[url="+reflink+"][img]"+bannerurl+"[/img][/url]";
	return bannercode;
}
function showrefbanner(number){
	var current = eval($("#currentbanner").val());
	if(number == 0){
		var banner = current-1;
		if(banner < 0){
			banner = 0;
			setReferralBanners(reflink, bannerurl, bannerWidth, bannerHeight);
		}else{
			setReferralBanners(reflink, bannerList.banners[banner].url, bannerList.banners[banner].width, bannerList.banners[banner].height);
		}
	}else{
		var banner = current+1;
		if(banner < totalbanners){
			setReferralBanners(reflink, bannerList.banners[banner].url, bannerList.banners[banner].width, bannerList.banners[banner].height);
		}else{
			banner = totalbanners-1;
		}
	}
	$("#banner"+current).hide();
	$("#banner"+banner).show();
	$("#currentbanner").val(banner)
}

/* Manager Ads */
function setmanageads(){
	var page = $("#manage_ads").val();
	location.href='index.php?view=account&page=manageads&class='+page;
}
function adcontrol(ad, action, classe){
		hideerror('errorbox');
		$("#tbody"+ad).l2block("#ffffff", 35);
		var dataString = 'id='+ ad +'&action='+ action +'&class='+ classe;
		var jqxhr = $.post("index.php?view=account&page=adcontrol&a=submit&request=control&",dataString, function(data) {
		if(data.status == 0){
			showerror('errorbox', data.msg);
			$('html, body').animate({scrollTop:0}, 'slow');
			$("#tbody"+ad).l2unblock();
		}else{
			if(action == 'start'){
				$("#control"+ad).html("<a href=\"javascript:void(0);\" onclick=\"adcontrol('"+ad+"', 'pause', '"+classe+"');\">Pause</a>");
			}else if(action == 'pause'){
				$("#control"+ad).html("<a href=\"javascript:void(0);\" onclick=\"adcontrol('"+ad+"', 'start', '"+classe+"');\">Start</a>");
			}else if(action == 'delete'){
				$("#tbody"+ad).remove();
			}
			$("#tbody"+ad).l2unblock();
		}
	   }, "json")
		return false;
}
/* Allocate */
function allocatead(classe){
	hideerror('errorbox');
	$("#allocateform").l2block("#ffffff", 35);
		var jqxhr = $.post("index.php?view=account&page=allocate_credits&",$("#allocateform").serialize(), function(data) {
		if(data.status == 0){
			showerror('errorbox', data.msg);
			$('html, body').animate({scrollTop:0}, 'slow');
			$("#allocateform").l2unblock();
		}else{
			$("#allocateform").remove();
			$("#message_sent").show();
		}
	   }, "json")
		return false;
}
function calculatecredits(value){
	var newvalue = $("#allocate").val()*value;
	$("#creditcost").val(newvalue);	
}
function recalculatecredits(value){
	var newvalue = $("#creditcost").val()/value;
	$("#allocate").val(newvalue);		
}

/* PTSU Activation */
function ptsuadvaction(rid,adid,myaction){
	hideerror('errorbox');
	$("#details"+rid).toggle();
		var jqxhr = $.post("index.php?view=account&page=pending_ptsu&id="+adid+"&a="+myaction,$("#submitptsu"+rid).serialize(), function(data) {
		if(data.status == 0){
			showerror('errorbox', data.msg);
			$('html, body').animate({scrollTop:0}, 'slow');
			$("#details"+rid).toggle();
		}else{
			location.reload();
		}
	   }, "json")
		return false;

}

/* Forum */
function forum_openclosetopic(topicid){
	hideerror('errorbox');
	var jqxhr = $.post("forum.php?topic="+topicid,"openclosetopic=do", function(data) {
	if(data.status == 0){
		showerror('errorbox', data.msg);
	}else{
		location.reload();
	}
   }, "json")
	return false;
}
function forum_postdelete(postid){
	hideerror('errorbox');
	var jqxhr = $.post("forum.php?dopost=delete","post="+ postid, function(data) {
	if(data.status == 0){
		showerror('errorbox', data.msg);
	}else{
		$("#postid"+postid).fadeOut(function(){
			$(this).remove();								
		});
	}
   }, "json")
	return false;
}
function forum_movetopic(topicid){
	hideerror('errorbox');
	$("#moveforumform").l2block("#ffffff",35);
	var jqxhr = $.post("forum.php?movetopic="+topicid,$("#moveforumform").serialize(), function(data) {
	if(data.status == 0){
		showerror('errorbox', data.msg);
		$("#moveforumform").l2unblock();
	}else{
		location.href = 'forum.php?topic='+topicid;
	}
   }, "json")
	return false;
}
function forum_edit(){
	hideerror('errorbox');
	$("#massage_form").l2block("#ffffff",35);
	var topic = $("#topic").val();
	var post = $("#post").val();
	var jqxhr = $.post("forum.php?topic="+topic+"&do=edit&post="+post,$("#massage_form").serialize(), function(data) {
	if(data.status == 0){
		showerror('errorbox', data.msg);
		$("#massage_form").l2unblock();
	}else{
		location.href='forum.php?topic='+topic;
	}
   }, "json")
	return false;
}
function forum_topic(){
	hideerror('errorbox');
	$("#massage_form").l2block("#ffffff",35);
	var board = $("#board").val();
	var jqxhr = $.post("forum.php?board="+board+"&do=topic",$("#massage_form").serialize(), function(data) {
	if(data.status == 0){
		showerror('errorbox', data.msg);
		$("#massage_form").l2unblock();
	}else{
		location.href='forum.php?topic='+data.msg;
	}
   }, "json")
	return false;
}
function forum_post(){
	hideerror('errorbox');
	$("#massage_form").l2block("#ffffff",35);
	var topic = $("#topic").val();
	var jqxhr = $.post("forum.php?topic="+topic+"&do=reply",$("#massage_form").serialize(), function(data) {
	if(data.status == 0){
		showerror('errorbox', data.msg);
		$("#massage_form").l2unblock();
	}else{
		location.href='forum.php?topic='+topic;
	}
   }, "json")
	return false;
}


function showtemplatebar(){
	$("#current_tpl").hide();
	$("#tpl_selector").show();
}
function restored_template(){
	$("#current_tpl").show();
	$("#tpl_selector").hide();
}
function update_template(){
	var url = $("#tpllist").val();
	location.href = url;	
}

function showlangbar(){
	$("#current_lang").hide();
	$("#lang_selector").show();
}
function restored_language(){
	$("#current_lang").show();
	$("#lang_selector").hide();
}
function update_language(){
	var url = $("#langlist").val();
	location.href = url;
}


function captchareload(){}
