function limitList(){
	var str = $("#form_limit").serialize();
	window.location.href = "index.php?"+str;
}

function limitAjax(){
	var lim = $("#lim").val();
	var mod = $("#mod").val();
	var view = $("#view").val();
	var urlParams = { 
						view: view,
						lim: lim,
						orderBy: $("#orderBy").val(),
						dir: $("#dir").val()
					};
	loadContent(urlParams);
	//alert(str.vars);
}

function loadOrder(view,field,dir){
	var urlParams = { 
					view: view,
					orderBy: field,
					dir: dir,
					lim:  $("#lim").val()
				};
	loadContent(urlParams);
}


function loadPager(view,page){
	var urlParams = { 
					view: view,
					pag: page
				};
	loadContent(urlParams);
}

function loadContent(params){
	$.get("getHeader.php",{name: params.view},cargaHeader);
	
	$('#htmlContent').load('index.php',params,function(){
		if(params.view != 'videos' && params.view != 'images' ){
			initBox();
		}
		 $('#htmlLoginCont').load('loginUserContent.php');
		 if(params.view == 'contact' || params.view == 'register' ){
			loadCaptcha(); 
		 }
		 
		 }
	);	
	
}

function stopSound(){
	var myflash = document.player;
	myflash.stopPlayerJs();
	//$('#divPlayer').hide();
	$('#player').css('z-index','0');
	$('#player').addClass("hidden");
}

function showPlayer(){
	//$('#divPlayer').show();
	$('#player').css('z-index','100');	
	$("#player").removeClass('hidden');

}
function loadDiv(div, url){
	$('#'+div).load(url);			
}

function loadCaptcha(){
	$('#captchaimage').html('loading..');
	$.get("captcha.php",function(){	
							$('#captchaimage').html('<img src="images/cap.png?'+Math.random ( )+'" width="132" height="50" alt="Captcha image" />');
								 });
}

function sendForm(formSend){
	var str = $("#"+formSend).serialize();
	//$('#htmlContent').load('index.php?'+str);	
	//alert(str);		
	$.ajax({
		   type: "POST",
		   url: 'index.php',
		   data: str,
		   success: function(msg){
			   if( msg ){
					alert(msg);
			   }
				window.top.tb_remove(); 			   					
	   			loadHome();	
		   }
		   });
}

function download(media,id){
	/*var str = {
				mod: 'media',
				view: 'download',
				type: media,
				id: id
	};*/
	var str = "view=download&type="+media+"&id="+id+"&";
	
	$.get('index.php?'+str, function(msg){
	
						   if( parseInt(msg) == 1 ){
								alert('You must be logged to download this file');
						   }else if( parseInt(msg) == 2 ){
								alert('Error reading File');
								return (false);
						   }else{
							  window.location = 'index.php?view=download2&type='+media+'&id='+id; 
						   }
		  			 }
		   );
}

function callHeader(){
	$.get("getHeader.php",{name: 'home'},cargaHeader);
}

function cargaHeader(data){
	//alert(data);
	var myflash = document.player;
	myflash.sendHeader(data);
}
function loadHome(){
	$.get("getHeader.php",{name: 'home'},cargaHeader);
	$('#htmlContent').load('index.php?home=true&',function(){
	   initBox();
	   $('#htmlLoginCont').html('');
	});	
}

function showPast(){
	$('#htmlPast').load('homeLivePast.php',function(){
	   initBox();
	});	
}

function initBox(){
	tb_init('a.thickbox, area.thickbox, input.thickbox');
	$('.lightbox').lightBox();
}

function validateContact() {
	// validate the comment form when it is submitted
	$("#contactForm").validate({
		rules: {
			captcha: {
				required: true,
				remote: "captchaVerify.php"
			}
		},
		submitHandler: function(form) {
				sendForm('contactForm');
			}
	});
}


function validateRegister() {
	// validate the register form when it is submitted
	$("#form_register").validate({
		rules: {
			alias: {
				required: true,
				remote: "registerAliasVerify.php"
			},
			captcha: {
				required: true,
				remote: "captchaVerify.php"
			}
		},
		submitHandler: function(form) {
			sendForm('form_register');
		},
		messages: {
			alias: {
				required: "Please enter an alias",
				remote: jQuery.format("{0} is already in use, please enter a different alias.")	
			},
			email: {
				required: "Please enter an email.",
				email: "Please enter a valid email (username@company.com)"	
			}
		}
	});
}

function validateNewsletter() {
	// validate the register form when it is submitted
	$("#form_news").validate({
		rules: {
			email: {
				required: true,
				email: true
			}
		},
		submitHandler: function(form) {
			sendForm('form_news');
		},
		messages: {
			email: {
				required: "Please enter an email.",
				email: "Please enter a valid email (username@company.com)"	
			}
		}
	});
}

function validateUnsuscribe() {
	// validate the register form when it is submitted
	$("#form_unsuscribe").validate({
		rules: {
			email: {
				required: true,
				email: true
			}
		},
		submitHandler: function(form) {
			sendForm('form_unsuscribe');
		},
		messages: {
			email: {
				required: "Please enter an email.",
				email: "Please enter a valid email (username@company.com)"	
			}
		}
	});
}

function validateLogin() {
	$("#form_login").validate({
		submitHandler: function(form) {
				sendForm('form_login');
		}
	});
	
}

function validatePwd() {
	$("#form_forgot").validate({
		submitHandler: function(form) {
				sendForm('form_forgot');
		}
	});
}