var emailexpr=/\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/;

function daysBetween(y){

 

		var today = new Date();		

		currentyear=today.getFullYear();

		if (currentyear<y)

		{

			alert('Date of birth can not be in future year.');	

			return false

		}

} 



function singnupChkFront()

{

	if($F('first_name') ==  '')		

	{

		alert('Enter your first name.');

		$('first_name').focus();

		return false;

	}

	

	if($F('last_name') ==  '')		

	{

		alert('Enter you last name.');

		$('last_name').focus();

		return false;	

	}	

		

	if($F('email') == '')

	{

		alert('Enter Email Address.');

		$('email').focus();

		return false;

		

	}	

	

	if($F('email') != '')

	{		

		if(!emailexpr.test($F('email')))

		{

			alert('Please enter a valid email.');

			$('email').focus();

			return false;

		}

											

	}

	
   if($F('zip') == '')

	{

		alert('Enter the required field: Zip Code.');

		$('zip').focus();

		return false;

		

	}	
	

	if($F('password') == '')

	{

		alert('Enter password.');

		$('password').focus();

		return false;

		

	}

	

	if($F('password').length<4)

	{

		alert('Password length should not be less than 4 characters.');

		$('password').focus();

		return false;

		

	}

	

	if($F('cnf_password') == '')

	{

		alert('Enter the confirm password.');

		$('cnf_password').focus();

		return false;

		

	}

	

	if($F('password') != $F('cnf_password'))

	{

		alert('Password does not matches.');

		$('password').value ='';

		$('cnf_password').value ='';   

		$('password').focus();

		return false;

		

	}

	

	



	if($F('dob_month') ==  '')		

	{

		alert('Select month.');

		$('dob_month').focus();

		return false;	

			

	}

	

	if($F('dob_day') ==  '')		

	{

		alert('Select Date.');

		$('dob_day').focus();

		return false;		

	}

	

	if($F('dob_year') ==  '')		

	{

		alert('Select year.');

		$('dob_year').focus();

		return false;	

			

	}	

	

	if($F('dob_day') != '' && $F('dob_year') !=  '' && $F('dob_month') != '')		

	{

		var today = new Date();		

		currentyear=today.getFullYear();

		currentmonth=today.getMonth();

		currentday=today.getDate();		

		

		

		var selectdate = new Date();	

		selectdate.setFullYear($F('dob_year'),parseInt($F('dob_month'))-1,$F('dob_day'));

		

		if(selectdate>today)	

		{

			alert('Date of birth can not be in future date.');

			return false;	

		}		

		

	}	

	

	if($('tuneImage') != null)

	{

		 

		if($F('tuneImage') == '')

		{		

			alert('Enter your tuning number.');

			$('tuneImage').focus();

			return false;	

				

		}

	}

	

	if($('chkTermsAndConditions') != null)

	{

		if($('chkTermsAndConditions').checked == false)

		{

			

				alert('Plese check the terms and conditions box.');

				$('chkTermsAndConditions').focus();

				return false;	

			

		}

		

	}

	

	// out side of any IF

	new Ajax.Request('ajax-user-email-check.php', {

	parameters: { email : $F('email'), mode : $F('hdnProfileEdit'), user_id: $F('hdnUserId')},

	onSuccess: function(transport) { 		



			if(transport.responseText == 'Present')	

			{

				if($F('hdnProfileEdit') == 'edit_true')

				{

					alert('This Email Address exists, please try with another email address. !');						

				}

				else

				{

					alertBox('This Email Address exists, please try with another email address. !');				

				}

			}

			else					

				$('user_profile').submit();								

			

		}

	});

	// out side of any IF

	

}





function singnupChk()

{

		

	if($F('email') == '')

	{

		alert('Enter Email Address.');

		$('email').focus();

		return false;

		

	}	

	

	if($F('email') != '')

	{		

		if(!emailexpr.test($F('email')))

		{

			alert('Please enter a valid email.');

			$('email').focus();

			return false;

		}

											

	}

	

	if($F('hdnProfileEdit') != 'edit_true')

	{

		if($F('password') == '')

		{

			alert('Enter password.');

			$('password').focus();

			return false;

			

		}	

	}

	

	if($F('first_name') ==  '')		

	{

		alert('Enter your first name.');

		$('first_name').focus();

		return false;

	}

	

	if($F('last_name') ==  '')		

	{

		alert('Enter you last name.');

		$('last_name').focus();

		return false;	

	}	

	

	

	if($F('dob_month') ==  '')		

	{

		alert('Select month.');

		$('dob_month').focus();

		return false;	

			

	}

	

	if($F('dob_day') ==  '')		

	{

		alert('Select Date.');

		$('dob_day').focus();

		return false;		

	}

	

	if($F('dob_year') ==  '')		

	{

		alert('Select year.');

		$('dob_year').focus();

		return false;	

			

	}

	

	if($F('dob_day') != '' && $F('dob_year') !=  '' && $F('dob_month') != '')		

	{

		var today = new Date();		

		currentyear=today.getFullYear();

		currentmonth=today.getMonth();

		currentday=today.getDate();		

		

		

		var selectdate = new Date();	

		selectdate.setFullYear($F('dob_year'),parseInt($F('dob_month'))-1,$F('dob_day'));

		

		if(selectdate>today)	

		{

			alert('Date of birth can not be in future date.');

			return false;	

		}		

		

	}

	

	if($F('city') ==  '')		

	{

		alert('Enter your city.');

		$('city').focus();

		return false;	

			

	}

	

	if($F('state') ==  '')		

	{

		alert('Select state.');

		$('state').focus();

		return false;	

			

	}

	

	if($F('zip') ==  '')		

	{

		alert('Enter zip code.');

		$('zip').focus();

		return false;		

	}

	

	if($F('ethnicity') ==  '')		

	{

		alert('Enter Ethnicity.');

		$('ethnicity').focus();

		return false;		

	}

	

	

	if($F('user_picture') != '')

	{	

		

		if(!/(\.gif|\.jpg|\.jpeg)$/i.test($F('user_picture')))	

		{

			alert('Please select your image(GIF or JPG).');	

			return false;

		}	

			

	}

	

	if($('tuneImage') != null)

	{

		 

		if($F('tuneImage') == '')

		{		

			alert('Enter your tuning number.');

			$('tuneImage').focus();

			return false;	

				

		}

	}

	

	if($('chkTermsAndConditions') != null)

	{

		if($('chkTermsAndConditions').checked == false)

		{

			

				alert('Plese check the terms and conditions box.');

				$('chkTermsAndConditions').focus();

				return false;	

			

		}

		

	}

	

	// out side of any IF

	new Ajax.Request('ajax-user-email-check.php', {

	parameters: { email : $F('email'),mode : $F('hdnProfileEdit'),user_id:$F('hdnUserId')},

	onSuccess: function(transport) { 		



			if(transport.responseText == 'Present')	

			{

				if($F('hdnProfileEdit') == 'edit_true')

				{

					alert('This Email Address exists, please try with another email address. !');						

				}

				else

				{

					alertBox('This Email Address exists, please try with another email address. !');				

				}

			}

			else					

				$('user_profile').submit();								

			

		}

	});		

	// out side of any IF

	

}



function reviewChk()

{

	if($('hidRAtechk')!=null)

	{

		if($F('hidRAtechk') == '')

		{

			alert('Please put your rating.');

			return false;

			

		}

	}

	if($F('txtReview') == '')

	{

		alert('Please Enter Review.');

		$('txtReview').focus();

		return false;

		

	}

	

	else

	{

		return true;

	}

}



function chechAddEvent()

{

	if($F('txt_title') == '')

	{

		alert('Please enter event title.');

		//$('txt_title').focus();

		return false;

	}

	if($F('hdnResultId') == '')

	{

		alert('Please enter event venue.');

		//$('txt_venue').focus();

		return false;

	}

				

}



function chechAddEventVenue()

{

	if($F('txt_title') == '')

	{

		alert('Please enter event title.');

		$('txt_title').focus();

		return false;

	}	

	else

	{

		return true;	

	}	

}



function chechPhotoAdd()

{

	if(!/(\.gif|\.jpg)$/i.test($F('filephoto')))	

	{

		alert('Please select image(GIF or JPG).');

		return false;	

	}

	else

	{

		return true;

	}

}





function doSendMail()

{

	if($('hdnToUserId')!=null)

	{

		if($F('hdnToUserId') == '')

		{

			alert('Enter friend\'s name to send the mail.');		

			$('txtTo').focus();

			return false;

		}

	}

	

	if($F('txtMailSub') == '')

	{

		alert('Enter subject.');		

		$('txtMailSub').focus();

		return false;

	}

	

	if($F('txtMailBody') == '')

	{

		alert('Enter mailbody.');		

		$('txtMailBody').focus();

		return false;

	}

	

	//disable($('btnMsgSend'));

	

	$('btnMsgSend').disabled=true;

	new Ajax.Updater('dvmsgMail','ajax-private-mail.php', {

		parameters: { to : $F('hdnToUserId'),from : $F('hdnFromUserId'),subj:$F('txtMailSub'),mbody:$F('txtMailBody')},

		onSuccess: function(transport) { 

		if($('showcountSent')!=null)

		{

		var sentITEM=parseInt($('itemsend').value)+1;

		$('itemsend').value=sentITEM;

		$('showcountSent').innerHTML='Sent('+ sentITEM +')';

		}

        

$('btnMsgSend').disabled=false;

			$('txtMailSub').value='';

			$('txtMailBody').value='';

			if($('txtTo')!=null)

			{

				$('txtTo').value='';

				$('hdnToUserId').value='';

				

				if(ursChk != null)

				document.body.removeChild(ursChk);

				

			}else

			{

				removeLayer()	

				alertBox('Thank You. Your Message is Sent.');

			}

			

			

		}

		});		

	

}






function doSendMailNotAjax()

{

	if($('hdnToUserId')!=null)

	{

		if($F('hdnToUserId') == '')

		{

			alert('Enter friend\'s name to send the mail.');		

			$('txtTo').focus();

			return false;

		}

	}

	

	if($F('txtMailSub') == '')

	{

		alert('Enter subject.');		

		$('txtMailSub').focus();

		return false;

	}

	

	if($F('txtMailBody') == '')

	{

		alert('Enter mailbody.');		

		$('txtMailBody').focus();

		return false;

	}

	

	return true;

	

}





function doChk(type)

{

	if(type==0)	

	{

		if($('hdnToUserId')!=null)

		{

			if($F('hdnToUserId') == '')

			{

				alert('Enter friend\'s email address.');		

				$('hdnToUserId').focus();

				return false;

			}

		}

		if($F('hdnToUserId') != '')

		{		

			if(!emailexpr.test($F('hdnToUserId')))

			{

				alert('Please enter a valid email.');

				$('hdnToUserId').focus();

				return false;

			}

												

		}

		if($F('txtMailSub') == '')

		{

			alert('Enter subject.');		

			$('txtMailSub').focus();

			return false;

		}

	}

	else if(type==1)

	{

		if($('hdnToUserId')!=null)

		{

			if($F('hdnToUserId') == '')

			{

				alert('Enter friend\'s phone number to SMS this link.');		

				$('hdnToUserId').focus();

				return false;

			}

		}

	}

	if($F('txtMailBody') == '')

	{

		alert('Enter mailbody.');		

		$('txtMailBody').focus();

		return false;

	}

	 

	if($F('tuneImage') == '')

	{		

		alert('Enter your tuning number.');

		$('tuneImage').focus();

		return false;	

			

	}

		 

	if($F('tuneImage') != '')

	{		

		if($F('tuneImage') != $F('tuneHidImage'))

		{		

			alert('Enter correct tuning number.');

			$('tuneImage').focus();

			return false;	

				

		}

			

	}

	return true;

	

}





checked=false;

function checkedAll (frm1) {

	var aa= $(frm1);

	 if (checked == false)

          {

           checked = true

          }

        else

          {

          checked = false

          }

	for (var i =0; i < aa.elements.length; i++) 

	{

	 aa.elements[i].checked = checked;

	}

}





function submitInviteEvent()

{

	

	var flag=false;

	for (var i =0; i < $('inviteFrm').elements.length; i++) 

	{

	 if($('inviteFrm').elements[i].checked == true)

	 {

	 	flag=true;

		break;

	 }

	}

	

	if(!flag)

	{

		alert('Plesae select atleast one event.');	

		return false;

	}

	else

	{

		return true;

	}

	/*//$('bntInvite').disabled=true;

	new Ajax.Request('ajax-invite-event.php?'+$('inviteFrm').serialize(), {		

				onSuccess: function(transport) { 

  						  //hidePopWin(false)

						   var theBody = parent.document.getElementsByTagName("BODY")[0];

							theBody.style.overflow = "";

							parent.$('popupMask').style.display = "none";

						    parent.$('popupContainer').style.display = "none";

							parentArg=1; ///////// global var in alertbox.js file

						    alertBox("Thank you for inviting your friend.");

					}

				});	*/

}

function checkValidation(form)
{
	
	if(form.email.value != '')

	{		

		if(!emailexpr.test(form.email.value))

		{

			alert('Please enter a valid email.');

			form.email.focus();

			return false;

		}

											

	}

	if(form.category.value=='')
	{ 
	  alert('Please enter the category!');
	  form.category.focus();	
	  return false;
	}
	
	if(form.company_name.value=='')
	{ 
	  alert('Please enter the company name!');
	  form.company_name.focus();	
	  return false;
	}
	
	if(form.coupon_code.value=='')
	{ 
	  alert('Please enter the coupon code!');
	  form.coupon_code.focus();	
	  return false;
	}
}

function validate_required_fields(form)

{

	if(form.reason.value=='')

	{

		alert("Select a reason.");

		form.reason.focus();

		return false;

	}

	

	if(form.name.value == '')

	{

		alert("Please enter the required field: Name. ");

		form.name.focus();

		return false;

	}

	

	if(form.email.value == '')

	{

		alert("Please enter the required field: Email. ");

		form.email.focus();

		return false;

	}

	

	if(form.email.value != '')

	{		

		if(!emailexpr.test(form.email.value))

		{

			alert('Please enter a valid email.');

			form.email.focus();

			return false;

		}

											

	}

	

	if(form.subject.value == '')

	{

		alert("Please enter the required field: Subject. ");

		form.subject.focus();

		return false;

	}

	

	if(form.message.value == '')

	{

		alert("Please enter the required field: Message. ");

		form.message.focus();

		return false;

	}

	

}



function checkEmailIfExists(email)

{

	

	new Ajax.Request('ajax-user-email-check.php', {

	parameters: { email : $F('email'), mode : $F('hdnProfileEdit'), user_id: $F('hdnUserId')},

	onSuccess: function(transport) { 

	

			if(transport.responseText == 'Present')	

			{

				

					alertBox('This Email Address exists, please try with another email address. !');

					

					$('email').value='';

					$('email').focus();

				

			}

									

			

		}

	});

	

}


