
/****************Function TO validate Email address*************************************/
function isValidEmail(str) 
{
	emailRe = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*\.(\w{2}|(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum))$/
	if (!emailRe.test(str))	
		return false	
	else
		return true		
}
function isValidnum(str) 
{
	phoneRe = /^((\+\d{1,3}(-| )?\(?\d\)?(-| )?\d{1,3})|(\(?\d{2,3}\)?))(-| )?(\d{3,4})(-| )?(\d{4})(( x| ext)\d{1,5}){0,1}$/
	//phoneRe = /^([9]{1})([234789]{1})([0-9]{8})$/
	if (!phoneRe.test(str))	
		return false	
	else
		return true		
}


function Trim(str) {	
    return str.replace(/(^\s+)([^\s]*)(\s+$)/, '$2');
}
function emptythis(id,vals) {	

	if($('#'+id).val() == vals)
		  $('#'+id).val('');
}
function fillthis(id,vals) {	

	if($('#'+id).val() == '')
		  $('#'+id).val(vals);
}
function sendinvite()
{
	str = $('#f_emailmob').val();
	if(isValidEmail(str))
	{
		$.post("/mails/sendinvitemail.php", {'email': str,'mobile': ''}, function(data) {
			alert(data);
			});
	}//if
	else if(isValidnum(str))
	{
//		if (str.length == 10)
//		{
			$.post("/mails/sendinvitemail.php", {'email': '','mobile': str}, function(data) {
					//$('#f_emailmob').val(data);
				alert(data);
				});
//		}
//		else
//			alert("Please enter 10 digit mobile number");
	}
	else
	{
		alert("please enter correct Email or Indian mobile No");
	}
}
function validateinvite()
{
	
	str = $('#f_redeem').val();

	if(Trim(str) != '')
	{
		
		$.post("/mails/activateinvitemail.php", {'keycode': str}, function(data) {
				//$('#f_redeem').val(data);
				//return data;
				//alert(data);
			if(data == 1)
			{
				$('#f_redeem').val("You have already activated your account");
				return data;
			}
			else if(data == 2)
			{
				$('#f_redeem').val("Please enter correct code");
				return data;
			}
			else
			{
				$('#inviteid').val(data);
				document.invite.submit();
				//$.post("/mails/registration.php", {'invite': data}, function(data) {
				//	 });
			}
		});
	}
	else
	{
		return "please enter correct code";
	}


}
function checkusername()
{
	username = $('#forgot1_email').val();
	$('#forgotpassstep2err').html('');
	$('#forgotpassstep2err').hide();
	

	$.post("/active18/mails/checkuserdetails.php", {'username': username}, function(data) {
					dataarr = data.split('|');
					if(dataarr.length>1)
					{
						
						if(dataarr[2] != '')
						{
							$('#forgot_altemail').val('');
							$('#forgotpassstep2email').show();
							$('#forgotpassstep2mobile').hide();
							$('#forgotpassstep2security').hide();
							altemailprovarr = dataarr[2].split("@");
							$('#emailprovider').html('@'+altemailprovarr[1]);
						}
						else if(dataarr[1] != '')
						{
							$('#forgot_mobile').val('');
							$('#forgotpassstep2mobile').show();
							$('#forgotpassstep2email').hide();
							$('#forgotpassstep2security').hide();
							
						}
						else if(dataarr[3] != '' && dataarr[4] != '' )
						{	
							$('#forgotpassstep2security').show();
							$('#forgotpassstep2mobile').hide();
							$('#forgotpassstep2email').hide();

							if (document.getElementById('forgot_un') != null)
								$('#forgot_un').val(username);
						}

					}
					else
					{
						$('#forgotpassstep2err').html(data);
						$('#forgotpassstep2err').show();
							$('#forgotpassstep2mobile').hide();
						$('#forgotpassstep2email').hide();
						$('#forgotpassstep2security').hide();
					}
	});
}
function validateinvitehome()
{
	
	str = $('#f_redeem').val();

	if(Trim(str) != '')
	{
		
		$.post("/mails/activateinvitemail.php", {'keycode': str}, function(data) {	
				if(data == 'Acount activated')
				{
					addsignup();
				}
				else
				{
					mailsend();
					alert('please enter correct code');
				}
			});
	}
	else
	{
		return "please enter correct code";
	}


}
/****************Function TO trim the string*************************************/
function sendforgot()
{
	str = $('#forgot_emailmob').val();
	email = $('#forgot_email').val();
	
	if (email != '' && email != 'Enter your IN.com Username, or invite mobile number / email address.')
	{
		//if(isValidEmail(email))
//		{
//			var emailid = "";
//			var mobile = "";
//
//			if(isValidEmail(str))
//			{
//				emailid = str;
//			}//if
//			else if(isValidnum(str))
//			{
//				mobile = str
//			}

//			$.post("/active18/sendforgotmail.php", {'email': emailid,'mobile': mobile, 'useremail': email}, function(data) {
			$.post("/active18/sendforgotmail.php", {'useremail': email}, function(data) {
				alert(data);
			});
	//	}//if
	//	else
	//	{
	//		alert("Please enter a valid in.com username");
	//	}
	}
//	else if (str != '' && str != 'Enter a valid email id or Indian Mobile No. on which you were sent an Invite')
//	{
//		if(isValidEmail(str))
//		{
//			$.post("/active18/sendforgotmail.php", {'email': str,'mobile': '', 'useremail': ''}, function(data) {
//				alert(data);
//				});
//		}//if
//		else if(isValidnum(str))
//		{
//			$.post("/active18/sendforgotmail.php", {'email': '','mobile': str, 'useremail': ''}, function(data) {
//					//$('#f_emailmob').val(data);
//				alert(data);
//				});
//		}
//	}	
	else
	{
		alert("Please enter your in.com username or correct Email or Indian mobile number on which you had recieved your Invite code.");
	}
}
function validateforgot(type)
{
	user_name = $('#forgot1_email').val();
	if(type=='mobile')
	{
		data_values = $('#forgot_mobile').val();
	}
	else if(type=='email')
	{
		data_values = $('#forgot_altemail').val();
	}
	else if(type=='security')
	{
		data_values = $('#securityq').val() +'|'+$('#securitya').val();		
	}
	$('#forgotpassstep2err').hide();
	$('#forgotpassstep2mobile').hide();
	$('#forgotpassstep2email').hide();
	$('#forgotpassstep2security').hide();

	$.post("/active18/validateforgotpass.php", {'type':type,'data_values':data_values,'user_name':user_name }, function(data) {
				if(data=='Success' && type=='security')
					{
						$.unblockUI();

						if (document.getElementById('forgot_un') != null)
							$('#forgot_un').val(username);

						newpassin();

						if (document.getElementById('forgot_un') != null)
							$('#forgot_un').val(username);
					}
					else if(data=='Success' && type=='email')
					{
						alert('Thanks, we\'ve sent a link to change your IN.com password to your '+type+' '+ data_values );
						$.unblockUI();
					}
					else if(data=='Success' && type=='mobile')
					{
						alert('Thanks for providing your mobile number, we\'ve sent you a temporary password by SMS. \nYou should get it within a few minutes. If you don\'t,contact IN.com customer service, and please do remember to provide an alternate email address.');
						$.unblockUI();
					}
					else
					{
						$('#forgotpassstep2err').show();
						$('#forgotpassstep2err').html(data);
						$('#forgotpassstep2mobile').hide();
						$('#forgotpassstep2email').hide();
						$('#forgotpassstep2security').hide();
					}	
			});
}
function displayfeedback()
{
	$.unblockUI();
	location.href='http://support.in.com/support/';
}
function checksecurity()
{
		
}
function validateforgotold()
{
	fredeem = $('#forgot_redeem').val();

	if (fredeem != '' && fredeem.length == 10 && fredeem != 'Enter your 10 Character redeem code')
	{
		$.post("/active18/verifypasscode.php", {'code': fredeem}, function(data) {
			if (data != "Error")
			{
				newpassin();
				$('#passkeycode').val(data);
			}
			else
				alert("Wrong password redeem code entered. Please enter the correct password redeem code.");
		});
	}
	else
		alert("Please enter your 10 Character redeem code");
}

function changepassword()
{
	username = $('#forgot_un').val();
	newpass = $('#newpass').val();
	newpass1 = $('#newpass1').val();

	if (newpass != '' && newpass != 'New Password' && newpass1 != '' && newpass1 != 'Retype new Password')
	{
		if (newpass.length < 6)
		{
			alert("Password should be of minimum 6 characters.");
		}
		else if (newpass == newpass1)
		{
			$.post("/active18/changepassword.php", {'newpass': newpass,'newpass1': newpass1,'username': username}, function(data) {
				$.unblockUI();
				alert(data);
			});
		}
		else
			alert("Please enter same passwords.");
	}
	else
		alert("Please enter both the passwords.");
}




function api_applogot(appname)
{
		$.post("/active18/mails/applogot.php", {'appname':appname}, function(data) {
			eval("api_display"+appname+"('reload');");
		});
}

function api_gmailapp_login() {
	var username = document.getElementById('username').value;
	var password = document.getElementById('password').value;;
	var rememberme = 0;
	var remembermep = 0;
	
	if (username == "")
	{
		alert("Please enter your Username");
		return;
	}
	if (password == "")
	{
		alert("Please enter your Password");
		return;
	}
	if (document.getElementById('grememberme').checked==true)
	{
		rememberme = 1;
	}
	if (document.getElementById('gremembermep').checked==true)
	{
		remembermep = 1;
	}


	var loadDiv = document.getElementById('divload');
	document.getElementById('loginbut').style.display = "none";
	loadDiv.style.display = "block";
	loadDiv.className = 'FL loader';
	$('#maildisplay').html('<div style="padding:65px 0px;" align="center"><img src="http://im.in.com/active18/mails/images/L.gif"></div>');
	$('#maildisplay').show();
	$('#maildisplay').load("/active18/mails/apps/api_gmail.php",{'username': username,'password': password, 'rememberme' : rememberme,'remembermep':remembermep},function(data){				
	});
}

function api_displaygmail(refgmail) {
	var firstload = 1;
	if(refgmail == 'reload' || firstload == '1') 
	{
		$('#maildisplay').html('<div style="padding:65px 0px;" align="center"><img src="http://im.in.com/active18/mails/images/L.gif"></div>');
		$('#maildisplay').show();
		$.post("/active18/mails/checkpassword.php", {'forsection':'gmail'}, function(data) {
			if (data.length > 0 && data != "undefined" && data != "<script>window.location='/login.php?err=0'</script>")
			{
				sp = data.split("|");
				username = sp[0];
				password = sp[1];	
				if(sp.length > 1)
				{
					$('#maildisplay').load("/active18/mails/apps/api_gmail.php",{'gusername': username,'gpassword': password},function(data){				
						$('#maildisplay').show();
					});
				}
				else
				{
					
					$('#maildisplay').load("/active18/mails/apps/api_gmail.html",'',function(data){				
						if(readCookie('ui') == null || readCookie('ui') == '' || readCookie('ui')== undefined ||  readCookie('ui')== 'deleted' )
						{
							$('#remcheck').hide();
						}
					});
				}
			}
			else
			{
				
				$('#maildisplay').load("/active18/mails/apps/api_gmail.html",'',function(data){				
					if(readCookie('ui') == null || readCookie('ui') == '' || readCookie('ui')== undefined ||  readCookie('ui')== 'deleted' )
					{
						$('#remcheck').hide();
					}
				});
			}
		});
	}
	
}//function


function api_yahooapp_login() {
	var username = document.getElementById('yusername').value;
	var password = document.getElementById('ypassword').value;;
	var rememberme = 0;
	
	if (username == "")
	{
		alert("Please enter your Username");
		return;
	}
	if (password == "")
	{
		alert("Please enter your Password");
		return;
	}
	if (document.getElementById('yrememberme').checked==true)
	{
		rememberme = 1;
	}


	var loadDiv = document.getElementById('divload');
	document.getElementById('loginbut').style.display = "none";
	loadDiv.style.display = "block";
	loadDiv.className = 'FL loader';
	$('#maildisplay').html('<div style="padding:65px 0px;" align="center"><img src="http://im.in.com/active18/mails/images/L.gif"></div>');
	$('#maildisplay').show();

	$('#maildisplay').load("/active18/mails/apps/api_yahoo.php",{'username': username,'password': password, 'rememberme' : rememberme},function(data){				
		$('#maildisplay').show();
	});
}


function api_displayyahoo(refyahoo) {
	var firstload = 1;
	if(refyahoo == 'reload' || firstload == '1') 
	{
				$('#maildisplay').html('<div style="padding:65px 0px;" align="center"><img src="http://im.in.com/active18/mails/images/L.gif"></div>');
		$('#maildisplay').show();
		$.post("/active18/mails/checkpassword.php", {'forsection':'yahoo'}, function(data) {
			if (data.length > 0 && data != "undefined" && data != "<script>window.location='/login.php?err=0'</script>")
			{
				sp = data.split("|");
				username = sp[0];
				password = sp[1];
				if(sp.length > 1)
				{
					$('#maildisplay').load("/active18/mails/apps/api_yahoo.php",{'yusername': username,'ypassword': password},function(data){									
					});
				}
				else
				{
	 
					$('#maildisplay').load("/active18/mails/apps/api_yahoo.html",'',function(data){				
						if(readCookie('ui') == null || readCookie('ui') == '' || readCookie('ui')== undefined ||  readCookie('ui')== 'deleted' )
						{
							$('#remcheck').hide();
						}
					});
				}
			}
			else
			{
 
				$('#maildisplay').load("/active18/mails/apps/api_yahoo.html",'',function(data){				
					if(readCookie('ui') == null || readCookie('ui') == '' || readCookie('ui')== undefined ||  readCookie('ui')== 'deleted' )
					{
						$('#remcheck').hide();
					}
				});
			}
		});
	}
}//function


function api_hotmailapp_login() {
	var username = document.getElementById('husername').value;
	var password = document.getElementById('hpassword').value;
	var domain = document.getElementById("dm").value;

	var rememberme = 0;
	
	if (username == "")
	{
		alert("Please enter your Username");
		return;
	}
	if (password == "")
	{
		alert("Please enter your Password");
		return;
	}
	if (document.getElementById('hrememberme').checked==true)
	{
		rememberme = 1;
	}


	var loadDiv = document.getElementById('divload');
	document.getElementById('loginbut').style.display = "none";
	loadDiv.style.display = "block";
	loadDiv.className = 'FL loader';
	$('#maildisplay').html('<div style="padding:65px 0px;" align="center"><img src="http://im.in.com/active18/mails/images/L.gif"></div>');
	$('#maildisplay').show();

	$('#maildisplay').load("/active18/mails/apps/api_hotmail.php",{'username': username,'password': password, 'rememberme' : rememberme, 'DomainField' : domain},function(data){				
		
	});
}


function api_displayhotmail(refhotmail) {
	var firstload = 1;
	
	if(refhotmail == 'reload' || firstload == '1') 
	{
			$('#maildisplay').html('<div style="padding:65px 0px;" align="center"><img src="http://im.in.com/active18/mails/images/L.gif"></div>');
		$('#maildisplay').show();
		$.post("/active18/mails/checkpassword.php", {'forsection':'hotmail'}, function(data) {
			if (data.length > 0 && data != "undefined" && data != "<script>window.location='/login.php?err=0'</script>")
			{
				sp = data.split("|");
				username = sp[0];
				password = sp[1];
				domain= sp[2];
				if(sp.length > 1)
				{
					$('#maildisplay').load("/active18/mails/apps/api_hotmail.php",{'husername': username,'hpassword': password, 'hDomainField' : domain},function(data){				
					});
				}
				else
				{
					
					$('#maildisplay').load("/active18/mails/apps/api_hotmail.html",'',function(data){				
						if(readCookie('ui') == null || readCookie('ui') == '' || readCookie('ui')== undefined ||  readCookie('ui')== 'deleted' )
						{
							$('#remcheck').hide();
						}
					});
				}
			}
			else
			{
				
				$('#maildisplay').load("/active18/mails/apps/api_hotmail.html",'',function(data){				
					if(readCookie('ui') == null || readCookie('ui') == '' || readCookie('ui')== undefined ||  readCookie('ui')== 'deleted' )
					{
						$('#remcheck').hide();
					}
				});
			}
		});
	}
}//function

function api_rediffapp_login() {
	var username = document.getElementById('rusername').value;
	var password = document.getElementById('rpassword').value;;
	var rememberme = 0;
	
	if (username == "")
	{
		alert("Please enter your Username");
		return;
	}
	if (password == "")
	{
		alert("Please enter your Password");
		return;
	}
	if (document.getElementById('rrememberme').checked==true)
	{
		rememberme = 1;
	}


	var loadDiv = document.getElementById('divload');
	document.getElementById('loginbut').style.display = "none";
	loadDiv.style.display = "block";
	loadDiv.className = 'FL loader';
	$('#maildisplay').html('<div style="padding:65px 0px;" align="center"><img src="http://im.in.com/active18/mails/images/L.gif"></div>');
	$('#maildisplay').show();

	$('#maildisplay').load("/active18/mails/apps/api_rediff.php",{'username': username,'password': password, 'rememberme' : rememberme},function(data){				
		
	});
}


function api_displayrediff(refrediff) {
	var firstload = 1;

	if(refrediff == 'reload' || firstload == '1') 
	{
		$('#maildisplay').html('<div style="padding:65px 0px;" align="center"><img src="http://im.in.com/active18/mails/images/L.gif"></div>');
		$('#maildisplay').show();
		$.post("/active18/mails/checkpassword.php", {'forsection':'rediff'}, function(data) {
			if (data.length > 0 && data != "undefined" && data != "<script>window.location='/login.php?err=0'</script>")
			{
				sp = data.split("|");
				username = sp[0];
				password = sp[1];
				if(sp.length > 1)
				{
					$('#maildisplay').load("/active18/mails/apps/api_rediff.php",{'rusername': username,'rpassword': password},function(data){				
						
					});
				}
				else
				{

					$('#maildisplay').load("/active18/mails/apps/api_rediff.html",'',function(data){				
						if(readCookie('ui') == null || readCookie('ui') == '' || readCookie('ui')== undefined ||  readCookie('ui')== 'deleted' )
						{
							$('#remcheck').hide();
						}
					});
				}
			}
			else
			{

				$('#maildisplay').load("/active18/mails/apps/api_rediff.html",'',function(data){				
					if(readCookie('ui') == null || readCookie('ui') == '' || readCookie('ui')== undefined ||  readCookie('ui')== 'deleted' )
					{
						$('#remcheck').hide();
					}
				});
			}
		});
	}
}//function

function displaydivlogin(divid,highdiv)
{
		
		$('#homesignin').hide();
		$('#maildisplay').hide();
		$('#'+divid).show();
		for(i=1;i<=5;i++)
		{
			if (eval("document.getElementById('rightlogintab"+i+"') != null"))
			{
					changeclass('rightlogintab'+i,'hloginn','hloginh');
			}
		}
		changeclass('rightlogintab'+highdiv,'hloginh','hloginn');
		 if(highdiv=='2')
		{
			 api_displaygmail('reload');
		}
		else if(highdiv=='3')
		{
			api_displayyahoo('reload');
		}
		else if(highdiv=='4')
		{
			api_displayrediff('reload');
		}
		else if(highdiv=='5')
		{
			api_displayhotmail('reload');
		}
		
		if(divid=='homesignin')
		{
			//alert($('#homesignin').html());
			$('#homesignin').show();	
		}


}
function changeclass(id,clas1,clas2)
{
	$('#'+id).addClass(clas1);
	$('#'+id).removeClass(clas2);
}

