function toggleTextOut(e,txtval) {
	if(e.value=="") e.value = txtval;

}
function toggleTextIn(e,txtval) {
	if(e.value==txtval) e.value="";
	else e.select();
}

$(document).ready(function(){
	$(".swap").hover(
			function(){
				if($(this).attr("src").indexOf("-on") == -1) {
				var newSrc = $(this).attr("src").replace(".gif","-on.gif");
				$(this).attr("src",newSrc);
				}},
				function(){
				if($(this).attr("src").indexOf(".gif") != -1) {
				var oldSrc = $(this).attr("src").replace("-on.gif",".gif");
				$(this).attr("src",oldSrc);
				}
				});
	
});
$(document).ready(function(){
	$(".swap2").hover(
			function(){
				if($(this).attr("src").indexOf("-on") == -1) {
				var newSrc = $(this).attr("src").replace(".png","-on.png");
				$(this).attr("src",newSrc);
				}},
				function(){
				if($(this).attr("src").indexOf(".png") != -1) {
				var oldSrc = $(this).attr("src").replace("-on.png",".png");
				$(this).attr("src",oldSrc);
				}
				});
	
});
$(document).ready(function(){
	$(".swap3").hover(
			function(){
				if($(this).attr("src").indexOf("-on") == -1) {
				var newSrc = $(this).attr("src").replace(".jpg","-on.jpg");
				$(this).attr("src",newSrc);
				}},
				function(){
				if($(this).attr("src").indexOf(".jpg") != -1) {
				var oldSrc = $(this).attr("src").replace("-on.jpg",".jpg");
				$(this).attr("src",oldSrc);
				}
				});
	
});

$(document).ready(function(){
    $("#main-navigation  li").hover(
        function(){ $("ul", this).fadeIn("fast"); }, 
        function() { $("ul", this).fadeOut("fast");  } 
    );
    if (document.all) {
        $("#main-navigation li").hoverClass ("sfHover");
    }
});

$.fn.hoverClass = function(c) {
    return this.each(function(){
        $(this).hover( 
            function() { $(this).addClass(c);  },
            function() { $(this).removeClass(c); }
        );
    });
};  


function searchboxValidate(){
	sb = document.getElementById('txtSearchBox').value;
	sb=trimAll(sb);
	if (sb=="Search your keyword" || sb=="" || sb=="Enter a search query") {
		document.getElementById('txtSearchBox').value = "Enter a search query";
		return false;
	}
	return true;
}

function trimAll(sString) {
		while (sString.substring(0,1) == ' ') {
			sString = sString.substring(1, sString.length);
		}
		while (sString.substring(sString.length-1, sString.length) == ' ') {
			sString = sString.substring(0,sString.length-1);
		}
	return sString;
}
function newsletterValidate(){
	sb = document.getElementById('txtNewsletter').value;
	var flag;
	sb=trimAll(sb);
	if (sb=="Enter your email address" || sb == "" ) {
		document.getElementById('txtNewsletter').value = "Enter your email address";
		return false;
	} 
	if(!IsValidEmail(sb)) {
		document.getElementById('txtNewsletter').value = "Enter valid email address";
		return false;
	}
	postURL = 'checkNewsletter.php?action=Newsletter';
	$.post(postURL, { emailID:sb  },
	function(data) {
		if( data == 'exists') {
			document.getElementById('txtNewsletter').value = "Email already exists";
			return false; 
		} else { 
			document.getElementById('txtNewsletter').value = "Successfully saved...";
			return false; 
		}
	});
	return false;
}
function ajaxCheck(sb) {
	postURL = 'checkNewsletter.php?action=Newsletter';
	$.post(postURL, { emailID:sb  },
	function(data) { //alert(data);
		if(data == 'exists')
			return true;
		else 
			return false;
	});	
}

function membershipValidate() {
	email = trimAll(document.getElementById('txtMemEmail').value);  
	password = document.getElementById('txtMemPassword').value;
	if (email=="Enter email address" || email == "" ) {
		document.getElementById('txtMemEmail').value = "Enter email address";
		return false;
	} 
	if(!IsValidEmail(email)) {
		//document.getElementById('txtMemEmail').value = "Enter valid email address";
		alert('Enter valid email address');
		document.getElementById('txtMemEmail').focus();
		//$("#show-message").html("Enter valid email address");
		//$("#show-message").show("slow");
		return false;
	}
	if (password =="Enter password" || password == "" ) {
		//document.getElementById('txtMemPassword').value = "Enter password";
		//$("#show-message").html("Enter password");
		//$("#show-message").show("slow");
		
		alert('Enter password');
		document.getElementById('txtMemPassword').focus();
		return false;
	} 
	$.post('checkNewsletter.php?action=Memeber', { emailID:email, pass:password },
	function(data) { 
		if( data == 'exists') {
			document.frmMembership.submit();
			return false; 
		} else {
			alert('Invalid User!!');
			document.getElementById('txtMemEmail').focus();
			//$("#show-message").html("Invalid User!!");
			//$("#show-message").show("slow");
		}
	});
	return false;
}

function AllowOnly(e,type,allow_space) {
	if (allow_space==null) allow_space=false; else allow_space=true;
	if(e.charCode==0) return true;
	var unicode=e.charCode? e.charCode : e.keyCode;
	if(unicode==13) return true;
	if(allow_space && unicode==32)
	return true;
	switch(type) {
		case 'NUM_ONLY':
		if(unicode < 48 || unicode > 57) return false; else return true;
		case 'MOBILE_NUM_ONLY':
		if(unicode < 39 || unicode > 57 ) return false; else return true;
		case 'ALPHA_ONLY':
		if(unicode <65 || unicode >90)
		if(!(unicode >= 97 && unicode <=122))
		return false;
		else
		return true;
		case 'ALPHA_NUM_ONLY':
		if(unicode >= 65 && unicode <= 90)
		return true;
		if(unicode >= 97 && unicode <= 120)
		return true;
		if(unicode >= 48 && unicode <= 57)
		return true;
		else
		return false;

	}
}
function IsValidEmail(value) {
	var emailFilter=/^.+@.+\..{2,3}$/;
	return(emailFilter.test(value));
}


$( document ).ready( function () {
$('#upcoming-tournaments li:first').addClass( 'first' );
$('#news-listing li:first').addClass( 'first' );
$('ul.listing li:last').addClass( 'last' );
});


