$(document).ready(function(){
	$(".newsletterIn").bind("focus",function(){
		var defVal = $(this).attr("alt");
		if($.trim($(this).val())==defVal){
			$(this).val("");
		}
	});
	$(".newsletterIn").bind("blur",function(){
		var defVal = $(this).attr("alt");
		if($.trim($(this).val())==""){
			$(this).val(defVal);
		}
	});				
	$("#NewsLetterBtn").bind("click",function(){
		var pVal 	= $(".newsletterIn").val();
		var defVal 	= $(".newsletterIn").attr("alt");
		if(pVal=='' || pVal==defVal)
		{
			alert("Please Enter Email Id");
			return false;
		}
	});
});
$(function() {
    $('.gallery a').lightBox();
});
function chkUserAuth(caseid,mailid,pwd)
{
	if(mailid == '' || pwd == '')
	{
		$("#errorDiv").show();
		$("#errorDiv").html("Please enter username and password.");
		return;
	}
	$("#errorDiv").html("LOADING.......");
	$.post(BASEURL+"pages/case-studies", {action:"chkAuth",cid:caseid,mailid:mailid,pwd:pwd}, function(data){
			if(data=="0")
			{
				$("#errorDiv").show();
				$("#errorDiv").html("Authentication failed. Please try again!!!");
			}
			else if(data == "limit exceeded")
			{
				$("#errorDiv").show();
				$("#errorDiv").html("This case-study is no longer available to you!!!");
			}
			else
			{
				$.modal.close();
				location.href= data;
				//window.open(data);
			}
		}, "text");
}
function chkSubscription(mailid)
{	
	if(isValidEmail(mailid))
	{
	$.post(BASEURL+"pages/case-studies", {action:"chkSubscription",mailid:mailid}, function(data){
			if(data=="0")
			{
				alert("A user with this Email Address already exists ...!!!");
			}
			else
			{
				alert("Your details are registered. We will get back to you soon ...!!!");
			}
		}, "text");
		$.modal.close();
	}
	else
	{
		$("#errorDiv").show();
		$("#errorDiv").html("Please enter valid email address.");
	}
}
function sendFeedback(name,mailid)
{	
	$.post(BASEURL+"pages/careers", {action:"feedback",name:name,email:mailid}, function(data){
			/*if(data=="0")
			{
				$("#errorDiv").show();
				$("#errorDiv").html("Authentication failed. Please try again!!!");
			}
			else
			{
				window.open(data);
			}*/
		}, "text");
}
function isValidEmail(email){
    var RegExp = /^((([a-z]|[0-9]|!|#|$|%|&|'|\*|\+|\-|\/|=|\?|\^|_|`|\{|\||\}|~)+(\.([a-z]|[0-9]|!|#|$|%|&|'|\*|\+|\-|\/|=|\?|\^|_|`|\{|\||\}|~)+)*)@((((([a-z]|[0-9])([a-z]|[0-9]|\-){0,61}([a-z]|[0-9])\.))*([a-z]|[0-9])([a-z]|[0-9]|\-){0,61}([a-z]|[0-9])\.)[\w]{2,4}|(((([0-9]){1,3}\.){3}([0-9]){1,3}))|(\[((([0-9]){1,3}\.){3}([0-9]){1,3})\])))$/
    if(RegExp.test(email)){
        return true;
    }else{
        return false;
    }
} 
