// JavaScript Document
$(document).ready(function(){
	$('#formSearchHolder input').focus(function(){ $(this).css({'color':'#333'}); }).blur(function(){ $(this).css({'color':'#cecece'}); });
	$('#formLoginHolder input').focus(function(){ $(this).css({'color':'#333'}); }).blur(function(){ $(this).css({'color':'#cecece'}); });
	$('.passText').show();
	$('.passInput').hide();
	$('.passText').focus(function(){
		$(this).hide();
		$('.passInput').show().focus();
	});
	$('.passInput').blur(function(){
		if($(this).val()=='') {
			$('.passText').show().css({'color':'#cecece'});
			$(this).hide();
		}
	});
	// Centering Download Title
	if ($('.grTitle span.cnt').length) {
		$('.grTitle span.cnt').parent('span.r').css({ 'height':'40px', 'padding':'0px' });
		var darrWidth = $('span.cnt span.darr').width();
		var textWidth = $('span.cnt span.text').width();
		realWidth = darrWidth + textWidth;
		$('span.cnt').css({ 'width':realWidth, 'margin':'0 auto' });
	}


	if($.cookie('usersonline') && $.cookie('avdownspeed') && $.cookie('downloadstoday')){
		changestats_online();changestats_speed();changestats_downloads();
	}else{
		$.cookie('usersonline', $('#usersonline').html(), {expires: 1, path: '/'});
		$.cookie('avdownspeed', $('#avdownspeed').html(), {expires: 1, path: '/'});
		$.cookie('downloadstoday', $('#downloadstoday').html(), {expires: 1, path: '/'});
	}
		setInterval("changestats_online()", 3500);
		setInterval("changestats_speed()", 1800);
		setInterval("changestats_downloads()", 1300);

	if(pid.length){
		$('#checkout_button').attr('href', $('#checkout_button').attr('href')+'&pid='+pid);
	}
});

function changestats_online(){
	var $delimeter = '+';
	var $curspeed  = $.cookie('avdownspeed');
	var $rand = Math.floor((10)*Math.random()) + 5;
	if(Math.ceil(2*Math.random()) == '2' && $curspeed > 2000 || $curspeed > 7000){$delimeter = '-';}
	var $updateonline = eval($curspeed+$delimeter+$rand);
	$('#usersonline').html($updateonline);
	$.cookie('usersonline',$updateonline, {expires: 1, path: '/'});
}
	
function changestats_speed(){
	var $delimeter = '+';
	var $curspeed  = $.cookie('avdownspeed');
	var $rand = Math.floor((200)*Math.random()) + 50;
	if(Math.ceil(2*Math.random()) == '2' && $curspeed > 1500 || $curspeed > 5000){$delimeter = '-';}
	var $speedupdate = eval($curspeed+$delimeter+$rand);
	$('#avdownspeed').html($speedupdate);
	$.cookie('avdownspeed',$speedupdate, {expires: 1, path: '/'});
}
	
function changestats_downloads(){
	var $rand = Math.floor((10)*Math.random()) + 2;
	var $updatedownloads = eval($.cookie('downloadstoday')+'+'+$rand);
	$('#downloadstoday').html($updatedownloads);
	$.cookie('downloadstoday',$updatedownloads, {expires: 1, path: '/'});
}


function searchcheck(){	
	if($('#s').val().length < 2 || $('#s').val() == 'Enter Keyword...'){
		alert('-- Enter Query --');
		return false;
	}else{
		$('#formSearch').submit();
	}
}

function logincheck(){	

	if($('#login_email').val().length < 5 || $('#login_email').val() == 'E-MAIL...'){	
		alert('-- Enter Email --');
		return false;
	}
	if($('#login_password').val().length < 1 || $('#login_password').val() == 'PASSWORD...'){
		alert('-- Enter Password --');	
		return false;
	}

	$('#formLogin').submit();
}




function registrationcheck(){	
	if($('#regi_email').val().length < 5){	
		alert('-- Enter Email --');
		return false;
	}
	if($('#regi_password').val().length < 1){
		alert('-- Enter Password --');	
		return false;
	}

	$('#formRegistration').submit();
}




function testimonialcheck(){	
	if($('#testim_nick').val().length < 1 || $('#testim_body').val().length < 1 ){
		alert('-- Enter Name & Question --');
		return false;
	}else{
		$('#formTestimonial').submit();
	}
}

function supportcheck(){	
	if($('#ticket').val().length < 10){
		alert('-- Enter Your Question --');
		return false;
	}else{
		$('#formTestimonial').submit();
	}
}

function activationcheck(){	
	if($('#active_code').val().length < 1){
		alert('-- Enter Activation Code --');
		return false;
	}else{
		$('#formActivate').submit();
	}
}
