function loginUser() {
	$('#formError').html('&nbsp;');
	if (!$('#loginFld').val() || $('#loginFld').val() == $('#loginFld').data("defText")) {  
		$('#formError').html('The Login is required.'); $('#loginFld').focus();return false; 
	}
	if (!$('#passwordFld').val() || $('#passwordFld').val() == $('#passwordFld').data("defText")) { 
		$('#formError').html('The Password is required.'); $('#passwordFld').focus(); return false;  
	}
	$('#login-loading').show();

	//Login to EvoNames
	if ($('#radio-login-evoonames').attr('checked') == true) {
		$("#loginModalForm").attr('action','http://evonames.com/login');
		$("#loginModalForm").submit();
	}

	//Login to EvoOffers 
	if ($('#radio-login-evooffers').attr('checked') == true) {
		$('#passwordFld').attr('name', 'passwd');
		$("#loginModalForm").attr('action','http://login.affiliatecube.com/member/index.php');
		$("#loginModalForm").submit();
	}

	//Login to Publisher 
	if ($('#radio-login-publisher').attr('checked') == true) {
		var loginDir = 'publisher/';
		var redirectScript = 'publisher/statistics.php';
	}
	//Login to Adfertiser 
	if ($('#radio-login-evoplus').attr('checked') == true) {
		var loginDir = '';
		var redirectScript = 'stats_ads.php';
	}

	//Login to EvoPlus
	$.post(loginDir+"process.php?process=Users::loginModal", $("#loginModalForm").serialize(),
		function(data) {
			$('#login-loading').hide();
			if (data.error) {
				$('#formError').html(data.error_desc);
				return false;  
			} else {
				$('#nyroModalWrapper').hide();
				window.location.href=redirectScript;
	        }
 		}, "json"
	);
	return false;  
}


/* This file stores JS that is used in all pages */
jQuery(document).ready(function() {		
	/* Fix Contact Form Textarea Focus */
	jQuery(".textarea textarea")
		.focus(function() {jQuery(this).parents('.textarea').addClass("focus");})
		.blur(function() {jQuery(this).parents('.textarea').removeClass("focus");});
	
	/* Remove the scrolbars from textarea in Opeara  */	
	jQuery.each(jQuery.browser, function(i) {
		if($.browser.opera) $("textarea").css("overflow","hidden");
	});
		
	/* Start Portofolio Carousel */
	jQuery("#portofolioSlider .carousel").jcarousel({
		scroll: 4,
		animation: 1500,
		easing: 'easeOutExpo',
		initCallback:  portofolioCarouselInit,
		buttonNextCallback: portofolioCarouselNext,
		buttonPrevCallback: portofolioCarouselPrev,
		itemLoadCallback: {onAfterAnimation: portofolioCarouselCounter}
	});
});

/* Portofolio Carousel Callback Functions */
var itemP, itemN;
function portofolioCarouselInit(carousel) {
	jQuery('#portofolioSlider .jcarousel-next').bind('click', function() {
		carousel.next();
		return false;
	});	
	jQuery('#portofolioSlider .jcarousel-prev').bind('click', function() {
		carousel.prev();
		return false;
	});
};
function portofolioCarouselNext(carousel, button, enabled) {
	enabled ? jQuery('#portofolioSlider .jcarousel-next').removeClass("disabled") : jQuery('#portofolioSlider .jcarousel-next').addClass("disabled");
};
function portofolioCarouselPrev(carousel, button, enabled) {
	enabled ? jQuery('#portofolioSlider .jcarousel-prev').removeClass("disabled") : jQuery('#portofolioSlider .jcarousel-prev').addClass("disabled");
}; 
function portofolioCarouselCounter(carousel, state) {
	if(state == "init") {
			itemN = jQuery("#portofolioSlider .carousel ul li").size();
			itemN < 4 ? itemP = itemN : itemP = 4;
			jQuery("#portofolioSlider .counter").text(itemP+"/"+itemN);	
	}
	if(state == "next") {
		if(!jQuery(this).hasClass("disabled")){
			if(itemP + 4 > itemN) itemP += itemN-itemP;
			else itemP += 4;
			jQuery("#portofolioSlider .counter").text(itemP+"/"+itemN);	
		}
	}
	if(state == "prev") {
		if(!jQuery(this).hasClass("disabled")){
			if(itemP - 4 < 4) itemP -= itemP-4;
			else itemP -= 4;
			jQuery("#portofolioSlider .counter").text(itemP+"/"+itemN);	
		}
	}
}

jQuery(document).ready(function() {		
	/* Add a class for all the input fields that need a custom look */
	jQuery('.customRadioHere').addClass('customRadio');
	jQuery('.customCheckboxHere').addClass('customCheckbox');
	
	/* Using  customInput plugin make a custom looking radio and checkbox */
	jQuery('input').customInput();
	
	/* Hide the default looking radio and checkbox */
	jQuery('.customCheckboxHere input, .customRadioHere input').css({'left':'-9999px'});
	
	/* Lightbox Settings */		
	jQuery.nyroModalSettings({
		minWidth: 340,
		closeButton: '<a href="#" class="nyroModalClose" id="closeBut" title="close window"></a>',
		showBackground: function (elts, settings, callback) {
			elts.bg.css({opacity:0}).fadeTo(500, 0.5, callback);
		}
	});

	/* Login Lightbox */
	jQuery('.loginLightbox').nyroModal({
		width:340,
		endShowContent: function (elts, settings, callback) { }
	});
	
	/* Image Lightbox */
	jQuery('.imageLightbox').nyroModal({});
	
	/* Footer Contact Form Settings */
	var contactForm = $("#footerForm");  
	var inputName = contactForm.find(".name"); 
	var inputEmail = contactForm.find(".email");  
	var inputMessage = contactForm.find(".message");
	var loadingImage = contactForm.find('.loadingImage');	
	var responseText = contactForm.find(".responseText");

	// On Submitting  	
	contactForm.bind("submit", function(e){
		if(validateName(e, inputName) & validateEmail(e, inputEmail) & validateMessage(e, inputMessage)) { 
			ajaxSend(contactForm, responseText, loadingImage);
		};
		return false;
	});
		
	// On key press  
	inputName.bind("keyup", function(e){
		validateName(e,  inputName);
	});
	inputEmail.bind("keyup", function(e){
		validateEmail(e,  inputEmail);
	});
	inputMessage.bind("keyup", function(e){
		validateMessage(e,  inputMessage);
	});
	
	/* Using ToggleVal Plugin to make the text in textInput forms toggle */
	jQuery(".textInput").toggleVal();
});


/* Functions requierd by the contact forms */
function validateName(event, input){  
	if(input.val().length < 4 || input.val() == "your name"){
		if(event.type != "keyup") {
			input.addClass("error"); 
			input.parent().find('.errorText').slideDown(); 
		}
		return false;
	}else{input.removeClass("error"); input.parent().find('.errorText').slideUp(); return true;}  
}
function validateEmail(event, input){
	var a = input.val();
	var filter = /^[a-zA-Z0-9]+[a-zA-Z0-9_.-]+[a-zA-Z0-9_-]+@[a-zA-Z0-9]+[a-zA-Z0-9.-]+[a-zA-Z0-9]+.[a-z]{2,4}$/;
	
	if (filter.test(a)) {
		input.removeClass("error"); 
		input.parent().find('.errorText').slideUp(); 
		return true;
	} else {
		if(event.type != "keyup") {
			input.addClass("error"); 
			input.parent().find('.errorText').slideDown(); 
		}
		return false;
	}
} 
function validateMessage(event, input){  
	if(input.val().length < 10 || input.val() == "your message"){
		if(event.type != "keyup") {
			input.parent().addClass("error"); 
			input.parent().find('.errorText').slideDown(); 
		}
		return false;
	} else {
		input.parent().removeClass("error"); input.parent().find('.errorText').slideUp(); return true;
	}  
} 
function ajaxSend(form, response, loading){	
	loading.show();
	response.slideUp().animate({X:""} , 200, "linear", function(){
		response.html('<small class="grey">Please wait, your message is being processed.</small><br />').slideDown();		
	});
	
	// Make AJAX request 		
	$.post('process.php?process=index::sendMessage', form.serialize(), function(data){
		loading.hide(200);
		response.slideUp().animate({X:""} , 200, "linear", function(){
			if (data.error) {
				response.html(data.error_desc).slideDown();
			} else {
				form.slideUp("slow", function () {form.html(data.error_desc).slideDown()});
			}
		});
	},'json');
	//Cancel default action
	return false;
};


/* this file stores js only for contact page */
$(document).ready(function() {	

	// Make the custom select forms 
	jQuery(".selectForm").sexyCombo({
		showListCallback: function () {
			jQuery(".list-wrapper.visible").parent().addClass('showList');
		},
		hideListCallback: function () {
			jQuery(".list-wrapper.invisible").parent().removeClass('showList');
		}
	});
	
	// Contact Form
	var cForm = $("#contactForm");  
	var cinputName = cForm.find(".name"); 
	var cinputEmail = cForm.find(".email");  
	var cinputMessage = cForm.find(".message");
	var cinputCaptcha = cForm.find(".captcha");
	var cloadingImage = cForm.find('.loadingImage');	
	var cresponseText = cForm.find(".responseText");

	// On Submitting  	
	cForm.bind("submit", function(e){
		if(validateName(e, cinputName) & validateEmail(e, cinputEmail) & validateMessage(e, cinputMessage)  & validateName(e, cinputCaptcha) ) { 
			ajaxSend(cForm, cresponseText, cloadingImage);
		};
		return false;
	});
		
	// On key press  
	cinputName.bind("keyup", function(e){
		validateName(e,  cinputName);
	});
	cinputEmail.bind("keyup", function(e){
		validateEmail(e,  cinputEmail);
	});
	cinputMessage.bind("keyup", function(e){
		validateMessage(e,  cinputMessage);
	});
});


/* twitts */
$(document).ready(function() {
/*
	$(".tweet").tweet({
		username: "evoplus", 
		join_text: "auto", 
		avatar_size: 32,
		count: 3,
		auto_join_text_default: "we said,",
		auto_join_text_ed: "we",
		auto_join_text_ing: "we were",
		auto_join_text_reply: "we replied to",
		auto_join_text_url: "we were checking out",
		loading_text: "loading tweets..."
	});
*/
	/* Homepage Slider */	
	jQuery('#coda-slider-1').codaSlider({
		autoSlide: true, 
		autoSlideInterval: 15000,
		slideEaseDuration: 3000, 
		slideEaseFunction: 'easeInOutExpo', 
		dynamicTabsAlign: 'right',
		dynamicArrows: false, 
		crossLinking: false
	});	

});
