function loadBackground()
{
	$(".content-main-left-col").css("background", "url('"+siteurl+"images/left_bg.png') repeat scroll 0 0 #FFFFFF");
}

function show_confirm()
{
	var r=confirm("Are you sure you want to unregister for event?");
	if (r==true)
	{
		var alurl = siteurl+"includes/process.inc.php";
		var aldata = "action=unregister&eid="+eid;
		$.ajax({
		type: "GET",
		url: alurl,
		data: aldata,
		success: function(data){

			if(data != "ERROR")
			{
				window.location.href = data;				
			}
		}
	});	
		
		
		return true;
	}
	else
	{
		return false;
	}
}

function limitChars(text, limit) {
	var str = "";
	if(text.length <= limit) {
		str = text;
	} else {
		var arrT = text.split(" ");
		for( var i=0; i<arrT.length ; i++) {
			if(str.length < limit)
				str += " "+arrT[i];
		}
	}  
	return str;
} 

function startTwitter(){
	var obj = $("ul.twitter li:visible");
	//alert(obj.next().length);
	if(obj.next().length){
		obj.next().fadeIn();
		obj.fadeOut();
	} else {
		obj.fadeOut();
		$("ul.twitter li:first").fadeIn();
	}
}


function validate(form) {
  errors = {};
  if (form.phone != "123") {
    errors.phone = "You didn't type 123";
  }
  
  return errors;
}





$(function () {		
	$("#asura-layered-slider").AsuraLayeredSlider({transSpeed:500});		
});
	
	
function redirect(status)
{
	if(status == "OK")
	{
		//var url = "http://"+host+req_url;
		var url = "http://"+siteurl+"events/";
		window.location.href = url;	
	}
	
	if(status == "TEMP")
	{
		var url = siteurl+"account/change-password/";
		window.location.href = url;	
	}
}	

function showLoginFacebook(){
	FB.login(function(response) {fbuser();}, { scope:'email,publish_stream'});	
}


function fbuser()
{
	FB.getLoginStatus(function(response) {		
		if (!response.authResponse) {		
			showLoginFacebook();
		} else {						
			FB.api('/me', function(response) {
				//alert(JSON.stringify(response));
				var userCity = "";
				if(response.hometown) {
					if(response.hometown.name) {
						userCity = response.hometown.name;
					} else if (response.location.name){
						userCity = response.location.name;
					}
				}
				var url = siteurl+"includes/process.inc.php";				
				var dataString = "action=facebookUser&userName="+response.name+"&userEmail="+response.email+"&userCity="+userCity+"&fbID="+response.id+"&dob="+response.birthday+"&gender="+response.gender;								
				//alert(url+"?"+dataString);
				$.ajax({
					type: "GET",
					url: url,
					data: dataString,
					success: function(data){
						if(data=="NA") {
							alert("It seems you have already registered with us!\n Please check your inbox to confirm your registration.");
							return false;
						} else {
							window.location = data;
						}				
					}
				});								
			});
		}	
	});
	
}
	
function load_news_cat(catid)
{
	if(catid > 0)
	{
		var url = siteurl+"news/category/"+catid+"/";
		window.location.href = url;
	}
}	
	
$("document").ready(function(){
			
		loadBackground();
		$(".content-main-col").css("overflow", "hidden");
		var content_height = $(".content-main-col").height()+600;
		$(".content-main").css("height", content_height);
					
		$(".copyright").find("p:first").css("float", "left");
		
		$(".copyright").find("p:last").css("float", "right");
		
		
		$(".pagination").find(".current").next().css("background", "none");
		
		$(".pagination").find("a:first").css("background", "none");
		

		
		
		$(".nav-parent").mouseenter(function () {
			$(this).addClass("over");
			$(this).find(".nav-child-link").hide();
			$(this).find(".on-hover").css("display", "inline");
			$(this).find(".nav-child").css({ 'left': jQuery(this).position().left+4 });
			$(this).find(".nav-child").stop().fadeTo(200, 1, function () {
				$(this).css('filter', '');
			});			
		}).mouseleave(function () {
			$(this).find(".on-hover").css("display", "none");
			$(this).find(".nav-child-link").show();
			$(this).find(".nav-child").stop().hide();
			$(this).removeClass("over");
		});
		
		//left menu
		
		$(".left-col-menu ul li").hover(function(){
		
			$(this).find(".left-col-menu-link").addClass("current");
			$(this).find(".left-col-menu-link").find("a").addClass("currentLink");
			$(this).find(".trang").addClass("current_trang");
			
		}, function(){
			
			$(this).find(".left-col-menu-link").removeClass("current");
			$(this).find(".left-col-menu-link").find("a").removeClass("currentLink");
			$(this).find(".trang").removeClass("current_trang");
		})
		
		
		$.getJSON("http://twitter.com/status/user_timeline/IndiaPokerChamp.json?callback=?&count=4",function(data){	
			
			//alert(data);
			// $("ul.twitter").html("");
			 var fClass = ' class="nomargin"';
			 $.each(data, function(i, tweet) {
				// alert(tweet.created_at);
				//	var date_tweet = new Date(tweet.created_at);
				//var date_now   = new Date();
				//var date_diff  = date_now - date_tweet;
				//var tAgo = timeAgo((date_diff/1000),2);
				var arrUrl = tweet.text.split("...");
				var desc = limitChars(arrUrl[0],160);			 
				$("ul.twitter").append('<li'+fClass+'>'+$.trim(desc)+'...</li>');
				$("ul.twitter li:first").fadeIn();
				fClass = '';
				
				//alert(JSON.stringify(tweet));							
			 });
			 setInterval("startTwitter()",7000);		 
		});	
		
		
		$(".counter-num").countdown({
			date: nxt_evnt_date, //Counting TO a date
			htmlTemplate: '<div class="time1 time"><div class="timetext3">%{d}</div><div class="timetext timetextdate">DAYS</div></div><div class="timeseprator timeseprator1">:</div><div class="time2 time"><div class="timetext3">%{h}</div><div class="timetext timetexthours">HOURS</div></div><div class="timeseprator timeseprator2">:</div><div class="time3 time">  <div class="timetext3">%{m}</div><div class="timetext timetextmins">MINS</div></div><div class="timeseprator timeseprator3">:</div><div class="time4 time"><div class="timetext3">%{s}</div><div class="timetext timetextsecs">SECS</div></div>',
			//date: "july 1, 2011 19:24", //Counting TO a date
			onChange: function( event, timer ){},
			onComplete: function( event ){},
			leadingZero: true,
			direction: "down"
		});
		
		/*$("#dob").blur(function(){
			
			$(this).css("color", "#6c6868");

			if($(this).val() == "Eg.: DD/MM/YYYY")
			{
				$(this).val("");
			}
			
		});	
		
		$("#mnumber").blur(function(){			
				$(this).css("color", "#6c6868");
				if($(this).val() == "Will be kept confidential")
				{
					$(this).val("");
				}
		});	
			
		$("#dob").click(function(){
			
			$(this).css("color", "#6c6868");

			if($(this).val() == "Eg.: DD/MM/YYYY")
			{
				$(this).val("");
			}
			
		});	
		
		$("#mnumber").click(function(){
			$(this).css("color", "#6c6868");
			if($(this).val() == "Will be kept confidential")
			{
				$(this).val("");
			}
			
		});	*/
		
		
		
		$(".reg-form #submitRForm").submit(function(){

			var fname = $(".fname");
			var fnmsg = $(".fnmsg");
			var lname = $(".lname");
			var lnmsg = $(".lnmsg");
			var dob = $(".dob");
			var dobmsg = $(".dobmsg");
				var month_select = $("#month_select");
				var day_select = $("#day_select");
				var year_select = $("#year_select");
			var city = $(".city");
			var citymsg = $(".citymsg");
			var email = $(".email");
			var emailmsg = $(".emailmsg");
			var mnmsg = $(".mnmsg");
			var mnumber = $(".mnumber");
			

			if(validateName(fname, fnmsg, "We want names with more than 2 letters.") & validateName(lname, lnmsg, "We want names with more than 2 letters.") & validateDropDown(month_select, dobmsg, "Please select a birth date.")  & validateDropDown(day_select, dobmsg, "Please select a birth date.") & validateDropDown(year_select, dobmsg, "Please select a birth date.") & validateName(city, citymsg, "Please enter city.")  & validateMobileNumber(mnumber, mnmsg) & validateEmail(email, emailmsg) & events_validate()){
				$(".errorlist").prev().html("");
				return true;
			}
			else
			{				
				return false;
			}


		});
		
		
		$(".logInFormBlock #logInForm").submit(function(){
			
			var uemail = $(".uemail");
			
			var upass = $(".upass");
			
			$(".msgbox").html("<p>Please check the information you have entered.</p><ul><li class='first'></li></ul>");
			
			var errormsg = $(".msgbox");
			
			var errormsg2 = $(".msgbox").find(".last");

			if(validateEmail(uemail, errormsg, "Please check the login details you have entered.") & validateEmpty(upass, errormsg2, "Please Enter Password")){
				var puemail = uemail.val();
				var pupass = upass.val();
				var alurl = siteurl+"includes/process.inc.php";
				var aldata = "action=chklogin&puemail="+puemail+"&pupass="+pupass;
				$.ajax({
				type: "GET",
				url: alurl,
				data: aldata,
				success: function(data){
					if(data == "OK")
					{
						$(".msgbox").text("");
						return true;
					}
					
					if(data == "ERROR")
					{
						
						$(".msgbox").text("Please check the login details you have entered.");
						return false;

					}
				}
			});	
			}else{			
				return false;
			}

		});
		
		$(".loginbox").click(function(){			
			$(this).stop().animate({top:'0px'},{queue:false,duration:800,easing: 'easeOutBounce'});
			$(document).unbind('click');	
		});
		
		$(".loginbox").mouseleave(function(){			
			$(document).bind('click', function() {
				$(".loginbox").stop().animate({top:'-229px'},{queue:false,duration:800,easing: 'easeInBounce'});
			});		
		});
		
/*		$(".loginbox").click(function(){
			$(document).unbind('click');
		});*/
		
		$(document).click(function(){
			$(".loginbox").stop().animate({top:'-229px'},{queue:false,duration:800,easing: 'easeInBounce'});
		});
		
//		$(".logoutbox").unbind('click');
		
		$(".logoutbox").hover(function(){			
			$(this).stop().animate({top:'-16px'},{queue:false,duration:500,easing: 'easeOutBounce'});			
		},function(){			
			$(this).stop().animate({top:'-47px'},{queue:false,duration:800,easing: 'easeOutBounce'});			
		});
		
/*
		$(document).click(function(){
			
			$(".loginbox").stop().animate({top:'-210px'},{queue:false,duration:800,easing: 'easeInBounce'});		
		
		alert("test");
			
		});*/
		
		/*$(".loginbox").hover(function(){
			
			$(this).stop().animate({top:'0px'},{queue:false,duration:800,easing: 'easeOutBounce'});
				
		}, function(){
			
			$(this).stop().animate({top:'-210px'},{queue:false,duration:800,easing: 'easeInBounce'});
				
		});*/
		
		/*$(".logoutbox").hover(function(){
			
			$(this).stop().animate({top:'-9px'},{queue:false,duration:800,easing: 'easeOutBounce'});
				
		}, function(){
			
			$(this).stop().animate({top:'-47px'},{queue:false,duration:800,easing: 'easeInBounce'});
				
		});*/
		
		$("#puemail").click(function(){			
			$(this).css("color", "#8a8686");
		});
		
		$("#pupass").click(function(){			
			$(this).css("color", "#8a8686");
		});
		
		$("#puemail").blur(function(){			
			$(this).css("color", "#8a8686");
		});
		
		$("#pupass").blur(function(){			
			$(this).css("color", "#8a8686");
		});
		
		$(".pop_login_btn").click(function(){
			
			var puemail = $(".puemail").val();
			var pupass = $(".pupass").val();
			var alurl = siteurl+"includes/process.inc.php";
			var aldata = "action=chklogin&puemail="+puemail+"&pupass="+pupass;
			$.ajax({
				type: "GET",
				url: alurl,
				data: aldata,
				success: function(data){
					if(data == "OK")
					{
						$(".loginbox").unbind('hover');					
						$(".loginbox").stop().animate({top:'-229px'},{queue:false,duration:500,easing: 'easeInBounce'});																		
						setInterval(redirect(data), 800); 

					}
					
					
					if(data == "TEMP")
					{
						$(".loginbox").unbind('hover');					
						$(".loginbox").stop().animate({top:'-229px'},{queue:false,duration:500,easing: 'easeInBounce'});																		
						setInterval(redirect(data), 800); 

					}
					
					
					if(data == "ERROR")
					{
						$("#puemail").css("color", "red");
						$("#pupass").css("color", "red");
						$(".loginbox .top_filed_background").css("background", "url('"+siteurl+"images/login_error.png') repeat scroll 0 0 transparent");
						$("#puemail").effect("shake", { times:3, distance:7 }, 300);
						$("#pupass").effect("shake", { times:3, distance:7 }, 300);
					}
					
					
				}
			});	
			
		})
		
		
		var estatus = 0;
		$(".fb_reg_box #submitUForm").submit(function(){
			
			var fname = $(".fname");
			var fnmsg = $(".fnmsg");
			var lname = $(".lname");
			var lnmsg = $(".lnmsg");
			var email = $(".email");
			var emailmsg = $(".emailmsg");
			var city = $(".city");
			var citymsg = $(".citymsg");
			var gender = $(".gender");
			var gendermsg = $(".gendermsg");			
			var monthmsg = $(".monthmsg");
				var month_select = $("#month_select");
				var day_select = $("#day_select");
				var year_select = $("#year_select");
			var passmsg = $(".passmsg");
			var password = $(".password");
			var repass = $(".repassword");
			var repassword = $(".repassword");			
			var mnumbermsg = $(".mnumbermsg");
			var mnumber = $(".mnumber");
			var findmsg = $(".findmsg");
			var findfield = $(".find:checked");			
			var emailmsgtxt = "Please enter your email id in valid format.";
			

				/*var alurl = siteurl+"includes/process.inc.php";
				var aldata = "action=chkEmail&puemail="+email.val();
				$.ajax({
				type: "GET",
				url: alurl,
				data: aldata,
				success: function(data){
					alert(data);
						if(data == "OK")
						{							
							estatus = 2;	
						}
						
						if(data == "ERROR")
						{														
						  	estatus = 1;
						}
					}
				});	
				
				if(estatus == 1)
				{
					emailmsgtxt = "Please enter your email id in valid format.";
				}
				
				
			
				alert(estatus);*/
			 if(validateName(fname, fnmsg, "We want names with more than 2 letters.") & validateName(lname, lnmsg, "We want names with more than 2 letters.") & validateEmail(email, emailmsg, emailmsgtxt) & validateName(city, citymsg, "Please enter city.") & validateDropDown(gender, gendermsg, "Please select gender")  & validateDropDown(month_select, monthmsg, "Please select a birth date.")  & validateDropDown(day_select, monthmsg, "Please select a birth date.") & validateDropDown(year_select, monthmsg, "Please select a birth date.") & validatePassword(password, repass, passmsg) & validateMobileNumber(mnumber, mnumbermsg) & validateRadio(findfield, findmsg, "Please select referance.")){
				
				
				
				$(".errorlist").prev().html("");
				$(".uerrorbox").html("");
				
				return true;
			}
			else
			{
				/*if(estatus == 2)
				{
					email = "ttt";
					emailmsgtxt = "This email id already registered with us.";
					
					validateEmail(email, emailmsg, emailmsgtxt)
				}*/
				$(".uerrorbox").html("Please check the information you have entered.");	
				$('html, body').animate({scrollTop: '0px'}, 800);
				return false;
			}

		});
		
		
		
		
		$(".contactForm #submitCForm").submit(function(){
			
			var name = $(".name");
			var fnmsg = $(".fnmsg");
			var email = $(".email");
			var emailmsg = $(".emailmsg");
			var mnumbermsg = $(".mnumbermsg");
			var mnumber = $(".mnumber");
			var inquiry = $(".inquiry");
			var inquirymsg = $(".inquirymsg");			
			

			if(validateName(name, fnmsg, "Please enter your name.") & validateEmail(email, emailmsg, "Please enter your email id in valid format.") & validateMobileNumber(mnumber, mnumbermsg) & validateName(inquiry, inquirymsg, "Please enter your enquiry.")){
				
				$(".errorlist").prev().html("");
				
				return true;
			}
			else
			{			
				return false;
			}

		});
		
		
		
		$(".live-update-box").click(function(){			
			$(this).stop().animate({left:'0px'},{queue:false,duration:800,easing: 'easeOutBounce'});
			$(document).unbind('click');	
		});
		
		$(".live-update-box").mouseleave(function(){			
			$(document).bind('click', function() {
				$(".live-update-box").stop().animate({left:'-499px'},{queue:false,duration:800,easing: 'easeInBounce'});
			});		
		});
		
		
		$(document).click(function(){
			$(".live-update-box").stop().animate({left:'-499px'},{queue:false,duration:800,easing: 'easeInBounce'});
		});
		
		

	
});
