/***************************************************************************************************
  Created By       : Digvijay Negi
  Modified By      : 
  Called From      : index.php
  Last Modified    : Oct 20, 2009
****************************************************************************************************/

$(document).ready(function() {
	$("#login").focus(function() {
		changeText(this, "User ID", "hide");
	});

	$("#login").blur(function() {
		changeText(this, "User ID", "show");
	});

	$("#txtPassword").focus(function() {
		$("#txtPassword").css("display", "none");
		$("#password").css("display", "");
		$("#password").focus();
	});

	$("#password").blur(function() {
		if(this.value=="")
		{
			$("#txtPassword").css("display", "");
			$("#password").css("display", "none");
		}
	});
	
	$("#search").focus(function() {
		changeText(this, "Quick Search", "hide");
	});

	$("#search").blur(function() {
		changeText(this, "Quick Search", "show");
	});
});


function changeText(obj, defaultText, action)
{
	if(obj.value==defaultText && action=="hide")
		obj.value="";		
	if(obj.value=="" && action=="show")
		obj.value=defaultText;	
}

function requirement(login)
{
	var frm = document.frmPostRequirement;
	var flag=0;

	if(document.getElementById('ptype_id2').value=='')
	{
		document.getElementById('spnPType1').innerHTML="<img src='images/cross1.gif' align='absmiddle' >&nbsp;Please Select Property Type";
		flag=1;
	}	
	if(frm.Email.value=='-- Email --')
	{
		document.getElementById('spnEmail').innerHTML="<img src='images/cross1.gif' align='absmiddle' >&nbsp;Please Enter Email Address";
		flag=1;
	}

	if(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(frm.Email.value))
	{		
		flag=0;
	}
	if(flag!=0 && frm.Email.value!='-- Email --')
	{
		document.getElementById('spnEmail').innerHTML="<img src='images/cross1.gif' align='absmiddle' >&nbsp;Invalid Email Address";
		flag=1;
	}
	
	if(frm.PhoneNo.value=='-- Phone No --')
	{
		document.getElementById('spnPhoneNo').innerHTML="<img src='images/cross1.gif' align='absmiddle' >&nbsp;Please Enter Phone No";
		flag=1;
	}
	if(flag==1)
	{
		return false;
	}
}

function advertise(login)
{
	var flag=0;
	var res_com='';
	var ptype='';
	var otype='';
	var ttype='';

	if(login=='')
	{
		window.location.href="login.php";
	}
	else
	{
		if(document.getElementById('PGroup').value=='')
		{
			document.getElementById('spnPGroup').innerHTML="<img src='images/cross1.gif' align='absmiddle' >&nbsp;Please Select Property Group";
			flag=1;
		}
		else
		{
			document.getElementById('spnPGroup').innerHTML="";	
		}
		
		if(document.getElementById('ptype_id').value=='')
		{
			document.getElementById('spnPType').innerHTML="<img src='images/cross1.gif' align='absmiddle' >&nbsp;Please Select Property Type";
			flag=1;
		}
		else
		{
			document.getElementById('spnPType').innerHTML="";	
		}
				
		if(document.getElementById('otype_id').value=='')
		{
			document.getElementById('spnOType').innerHTML="<img src='images/cross1.gif' align='absmiddle' >&nbsp;Please Select Ownership Type";
			flag=1;		
		}
		else
		{
			document.getElementById('spnOType').innerHTML="";	
		}
			
		if(document.getElementById('ttype_id').value=='')
		{
			document.getElementById('spnTType').innerHTML="<img src='images/cross1.gif' align='absmiddle' >&nbsp;Please Select Transaction Type";
			flag=1;		
		}
		else
		{
			document.getElementById('spnTType').innerHTML="";	
		}
		pgroup=document.getElementById('PGroup').value;		
		ptype=document.getElementById('ptype_id').value;
		otype=document.getElementById('otype_id').value;
		ttype=document.getElementById('ttype_id').value;
						
		if(flag==0)
			window.location.href="post_property.php?ptype="+ptype+"&otype="+otype+"&ttype="+ttype+"&res_com="+pgroup;
	}
}

function login_required()
{
	var flag=0;

	if(document.frmLogin.login.value=='')
	{
		document.getElementById('divLogin').style.display="block";
		document.getElementById('divLogin').innerHTML="<img src='images/cross1.gif' align='absmiddle' >&nbsp;Please Enter User Id";
		flag="1";
	}
	else
	{
		document.getElementById('divLogin').innerHTML="";
		document.getElementById('divLogin').style.display="none";		
	}

	if(document.frmLogin.password.value=='')
	{
		document.getElementById('divPassword').style.display="block";		
		document.getElementById('divPassword').innerHTML="<img src='images/cross1.gif' align='absmiddle' >&nbsp;Please Enter Password";
		flag="1";
	}
	else
	{
		document.getElementById('divPassword').innerHTML="";
		document.getElementById('divPassword').style.display="none";
	}

	if(flag==1)
		return false
}

function callAjax(val, param1, param2, param3)
{
	if(param1==undefined)
		param1='';
	if(param2==undefined)
		param2='';
	if(param3==undefined)
		param3='';
		
	if(val==1)
	{
		var utype = document.getElementById('UserType_id').value;
		var fname = document.getElementById('FName_id').value;
		var lname = document.getElementById('LName_id').value;
		var cname = document.getElementById('CompanyName_id').value;
		var mobile_no = document.getElementById('MobileNo_id').value;
		var email = document.getElementById('Email_id').value;
		var password = document.getElementById('Password_id').value;
			
		var str = email + '~' + password + '~' + utype + '~' + fname + '~' + lname + '~' + cname + '~' + mobile_no;
		showAjax('showCode', 'divPopUp', str);
	}
	else if(val==2)
	{
		document.getElementById('btnCode_id').value='Please Wait...'; 
		document.getElementById('btnCode_id').disabled=true; 
		str = document.getElementById('Code_id').value + '~' + document.getElementById('hidLoginId_id').value;
		showAjax('confirmCode', 'spnCode', str);
	}
	else if(val==3)
	{
		showAjax('invite', 'divPopUp', str);
	}
	else if(val==4)
	{
		if(document.getElementById('MobileNo_id').value!='')
		{			
			document.getElementById('btnCAccount_id').value="Please Wait...";
			document.getElementById('btnCAccount_id').disabled=true;		
			
			document.getElementById('MobileErrorDiv').innerHTML="<span style='margin-left:10px'><img src='images/spinner_grey.gif' align='absmiddle'>&nbsp;&nbsp;Please Wait.... Your Mobile Number is validating </span>";				
			document.getElementById('MobileErrorDiv').style.display='block';

			showAjax('MNocheck', 'MobileErrorDiv', document.getElementById('MobileNo_id').value);
		}
	}
	else if(val==5)
	{
		if(document.getElementById('Email_id').value!='')
		{
			document.getElementById('btnCAccount_id').value="Please Wait...";
			document.getElementById('btnCAccount_id').disabled=true;		

			document.getElementById('EmailErrorDiv').innerHTML="<span style='margin-left:10px'><img src='images/spinner_grey.gif' align='absmiddle'>&nbsp;&nbsp;Please Wait.... Your Email Address is validating </span>";	
			document.getElementById('EmailErrorDiv').style.display='block';
			showAjax('checkLogin', 'EmailErrorDiv', document.getElementById('Email_id').value);
		}
	}
	else if(val==6)
	{
		if(document.frmForgotPwd.Email.value!='')
		{
			alert("sdfsd");
			document.getElementById('btnFPwd_id').disabled=true;
			document.getElementById('btnFPwd_id').value="Please Wait..."
			document.getElementById('EmailErrorDiv').innerHTML="<span style='margin-left:10px'><img src='images/spinner_grey.gif' align='absmiddle'>&nbsp;&nbsp;Please Wait.... Your Email Address is validating </span>";
			document.getElementById('EmailErrorDiv').style.display='block';
			showAjax('checkEmailExist', 'EmailErrorDiv', document.frmForgotPwd.Email.value);
		}
	}
	else if(val==7)
	{
		document.getElementById('btnFPwd_id').disabled=true;
		document.getElementById('btnFPwd_id').value="Please Wait..."
		document.getElementById('EmailErrorDiv').innerHTML="<span style='margin-left:10px'><img src='images/spinner_grey.gif' align='absmiddle'>&nbsp;&nbsp;Please Wait.... Your Email Address is validating </span>";
		document.getElementById('EmailErrorDiv').style.display='block';
		showAjax('sendpwd', 'EmailErrorDiv', document.frmForgotPwd.Email.value);
	}
	else if(val==8)
	{
		showAjax('InviteFriend', 'Invitation_id', document.frmInvitation.Email.value + '~' + document.frmInvitation.Password.value);
	}
	else if(val==9)
	{
		var email = document.loginForm.username.value + "@" + document.loginForm.domain.value
		showAjax('InviteFriend', 'signupvalidation_id', email + '~' + document.loginForm.password.value);
	}
	else if(val==10)
	{
		if(document.getElementById('txtEmail_id').value!='')
		{
			document.getElementById('EmailErrorDiv').style.display="block";
			document.getElementById('EmailErrorDiv').innerHTML="<span style='margin-left:10px'><img src='images/spinner_grey.gif' align='absmiddle'>&nbsp;&nbsp;Please Wait.... Your Email Address is validating </span>";
			document.getElementById('PostProperty_id').disabled=true;
			showAjax('checkEmail', 'EmailErrorDiv', document.getElementById('txtEmail_id').value);
		}
	}
	else if(val==11)
	{
		document.getElementById(param2).innerHTML="<span style='margin-left:10px'><img src='images/spinner_grey.gif' align='absmiddle'>&nbsp;&nbsp;Please Wait.... </span>";
		showAjax(param1, param2, param3);		
	}
	else if(val==12)
	{		
		var str = document.getElementById('hidPCode_id').value + '~' + document.getElementById('EName_id').value + '~' + document.getElementById('EEmailId_id').value + '~' + document.getElementById('EMessage_id').value + '~' + document.getElementById('EPhoneNo_id').value;
		document.getElementById(param1).innerHTML="<span style='margin-left:10px'><img src='images/spinner_grey.gif' align='absmiddle'>&nbsp;&nbsp;Please Wait.... </span>";
		showAjax('sendPropertyEnquiryDetails', param1, str);		
	}
	else if(val==13)
	{
		if(document.getElementById('txtMobile1_id').value!='')
		{
			document.getElementById('MobileErrorDiv').style.display="block";
			document.getElementById('MobileErrorDiv').innerHTML="<span style='margin-left:10px'><img src='images/spinner_grey.gif' align='absmiddle'>&nbsp;&nbsp;Please Wait.... Your Mobile No is validating </span>";
			document.getElementById('PostProperty_id').disabled=true;
			showAjax('MNocheck1', 'MobileErrorDiv', document.getElementById('txtMobile1_id').value);
		}
	}
	else if(val==14)
	{
		if(document.getElementById('txtMobile1_id').value!='')
		{
			document.getElementById('MobileErrorDiv').style.display="block";
			document.getElementById('MobileErrorDiv').innerHTML="<span style='margin-left:10px'><img src='images/spinner_grey.gif' align='absmiddle'>&nbsp;&nbsp;Please Wait.... Your Mobile No is validating </span>";
			document.getElementById('PostProperty_id').disabled=true;
			showAjax('MNocheck1', 'MobileErrorDiv', document.getElementById('txtMobile1_id').value);
		}
	}
}

function signup_validation(step)
{
	var error='';
	var flag=0;
	var temp='';
	var error1='';
			
	if(step=='1')
	{
		
		if(document.getElementById('FName_id').value=='')
		{			
			error += "First Name";
			temp = ', ';
			flag=1;
		}

		if(document.getElementById('UserType_id').value!="O" && document.getElementById('CompanyName_id').value=='')
		{			
			error +=  temp + "Company Name";
			temp = ', ';
			flag=1;
		}

		if(document.getElementById('MobileNo_id').value=='')
		{
			error += temp + "Mobile No";
			temp = ', ';
			flag=1;
		}
		else if(document.getElementById('MobileNo_id').value.length<10 || document.getElementById('MobileNo_id').value.length>10)
		{
			error += temp + "Incorrect Mobile No";
			temp = ', ';
			flag=1;
		}
		
		if(document.getElementById('Email_id').value=='')
		{
			error += temp + "Email Address";
			temp = ', ';
			flag=1;
		}
		else if(email_validation(document.getElementById('Email_id').value)==false)
		{
			error += temp + "Incorrect Email Address";
			temp = ', ';
			flag=1;
		}
				
		if(document.getElementById('Password_id').value=='')
		{
			error += temp + "Password";
			temp = ', ';
			flag=1;
		}
		if(document.getElementById('RePassword_id').value=='')
		{
			error += temp + "Confirm Password";
			temp = ', ';
			flag=1;
		}
		if(document.getElementById('Password_id').value!='' && document.getElementById('RePassword_id').value!='' && document.getElementById('Password_id').value!=document.getElementById('RePassword_id').value)
		{
			error1 += "<b>* Please Verify Your Password Again <b>";
			flag=1;
		}
	}
	else if(step=='2')
	{	
		if(document.getElementById('Code_id').value=='')
		{
			error = "Verification Code";
			temp = ', ';
			flag=1;
		}		
	}
	else if(step=='3')
	{	
		if(document.loginForm.username.value=='')
		{
			error = "Email Address";
			temp = ', ';
			flag=1;
		}
		if(document.loginForm.password.value=='')
		{
			error += temp + "Password";
			temp = ', ';
			flag=1;
		}
	}

	if(flag==1)
	{
		error = "<b>* Required Field: <b><br>" + "<div style='margin-left:13px'>" + error + "</div>";
		document.getElementById('signupvalidation_id').style.display="block";
		document.getElementById('signupvalidation_id').innerHTML=error + error1;		
	}
	else
	{
		document.getElementById('signupvalidation_id').innerHTML="";		
		document.getElementById('signupvalidation_id').style.display="none";
		
		if(step == '1')
			callAjax('1');
		else if(step == '2')
		{
			callAjax('2');
		}
		else if(step == '3')
			callAjax('9');
	}
}
		
function pwdrecover_validation()
{
	if(document.frmForgotPwd.Email.value=='')
	{
		document.getElementById('ForgotPwd_id').style.display="block";
		document.getElementById('ForgotPwd_id').innerHTML="<b>* Required Field: <b><br><div style='margin-left:13px'>Email Address</div>";
	}
	else
	{
		document.getElementById('ForgotPwd_id').innerHTML="";
		document.getElementById('ForgotPwd_id').style.display="none";
		callAjax('7');
	}
}

function Invitation_validation()
{
	var error='';
	var temp='0';

	if(document.frmInvitation.Email.value=='')
	{
		error="<div style='margin-left:13px'>Email Address</div>";
	}

	if(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(document.frmInvitation.Email.value))
	{		
		temp=1;
	}
	if(temp==0 && document.frmInvitation.Email.value!='')
		error+="<div style='margin-left:13px'>Invalid Email Address</div>";

	if(document.frmInvitation.Password.value=='')
	{
		error+="<div style='margin-left:13px'>Password</div>";
	}

	if(temp==1)
	{
		var email_address = document.frmInvitation.Email.value;
		var domain = email_address.split("@");
		var fdomain = domain[1].split(".");
	
		if(fdomain[0]!="yahoo" && fdomain[0]!="gmail" && fdomain[0]!="indiatimes" && fdomain[0]!="rediffmail" && fdomain[0]!="rediff")
		{
			error+="<div style='margin-left:13px'>Only yahoo, gmail, indiatimes, aol and lycos are supported</div>";
		}
	}

	if(error!='')
	{
		error="<b>* Required Field"+error;
		document.getElementById('Invitation_id').style.display="block";
		document.getElementById('Invitation_id').innerHTML=error
	}	
	else
	{
		document.getElementById('Invitation_id').style.display="block";
		document.getElementById('Invitation_id').innerHTML="<span style='margin-left:10px'><img src='images/spinner_grey.gif' align='absmiddle'>&nbsp;&nbsp;Please Wait.... We are sending Invitation. </span>";
		document.frmInvitation.Email.disabled=true;
		document.frmInvitation.Password.disabled=true;
		document.getElementById('btnInvite_id').disabled=true;
		callAjax(8);
	}
}

function enquiryValidation(div, opt)
{
	var error='';
	var temp=0;

	if(document.getElementById('EName_id').value=='')
	{
		alert("Please Enter Name");
		document.getElementById('EName_id').focus();
		temp=1;
	}

	if(temp==0 && document.getElementById('EEmailId_id').value=='')
	{		
		alert("Please Enter Email Address");
		document.getElementById('EEmailId_id').focus();
		temp=1;
	}

	if(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(document.getElementById('EEmailId_id').value))
	{		
		temp=0;
	}
	if(temp!=0 && document.getElementById('EEmailId_id').value!='')
	{
		alert("Invalid Email Address");
		document.getElementById('EEmailId_id').focus();
		temp=1;
	}

	if(temp==0 && document.getElementById('EMessage_id').value=='')
	{
		alert("Please Enter Message.");
		document.getElementById('EMessage_id').focus();
		temp=1;
	}

	if(temp==0 && document.getElementById('EPhoneNo_id').value=='')
	{
		alert("Please Enter Phone Number.");
		document.getElementById('EPhoneNo_id').focus();
		temp=1;
	}

	if(temp==0 && isNaN(document.getElementById('EPhoneNo_id').value))
	{
		alert("Invalid Phone Number.");
		document.getElementById('EPhoneNo_id').focus();
		temp=1;
	}

	if(temp==0)
	{
		if(opt=="Property")
			callAjax('12', div);
		else if(opt=="AgentBuilder")
			callAjax('14', div);
	}
}

function EnquiryClose(div)
{
	document.getElementById(div).style.display="none";
}