function emptyEmailFields()
{
	document.getElementById('emailItTo').value='';
	document.getElementById('cnfrmEmail').value='';
}
//----------------- validate registeration Personel info function ---------------//
function validateSignup(){
		var i =0;
		if ($.trim($('#firstName').val())==""){
			alert("Please enter the first name.");
			$('#firstName').focus();
			i=1;
			return false;
		}		
		if($.trim($('#lastName').val())==""){
			alert("Please enter the Last name.");
			$('#lastName').focus();
			i=1;
			return false;
		}
		if ($.trim($('#emailSignUp').val())==""){
			alert("Please enter your email.");
			$('#emailSignUp').focus();
			i=1;
			return false;
		}else if($('#emailSignUp').val()){
			var ret = validEmail('emailSignUp');
			if( ret == false ){
				$('#emailSignUp').focus();
				i=1;
				return false;
			}
		}
		if ($.trim($('#emailSignUp').val())!=$.trim($('#confirmEmail').val())){
			alert("Your email addresses don't match, please correct this before proceeding.");
			$('#emailSignUp').focus();
			i=1;
			return false;
		}		
		if($('#duplicateEmail').val()=='1'){
			alert("Your email address already exists in our system.");
			$('#emailSignUp').focus();
			i=1;
			return false;
		
		}
		//chkEmailExist();
		if($.trim($('#password').val())==""){
			alert("Please enter the password.");
			$('#password').focus();
			i=1;
			return false;
		}else if($.trim($('#password').val())){
			var pswd=$('#password').val();
			var len=pswd.length;
			if(len<4){
				alert("Please enter at least 4 characters for a password.")
				$('#password').focus();
				i=1;
				return false;
			}
		}
		if($.trim($('#cnfrmPassword').val())==""){
			alert("Please retype the password.");
			$('#cnfrmPassword').focus();
			i=1;
			return false;
		}else if($.trim($('#cnfrmPassword').val()) != $.trim($('#password').val())){
			alert("Please retype the same password.");
			$('#cnfrmPassword').focus();
			i=1;
			return false;
		}
		if($('#chkAgree').attr('checked')==false){
			alert("Please agree to our terms and conditions.");
			$('#chkAgree').focus();
			i=1;
			return false;
		}
			if($.trim($('#emailSignUp').val())!=""){
			var ret = $.trim($('#emailSignUp').val());
			if( ret == '1' ){
				i=1;
				return false;
			}
		}
		
		if(i==0){
			return true;
		}
	}
//----------------- validate User Personel info function ---------------//
function validatePersonalInfo(){
		var i =0;
		if ($.trim($('#firstName').val())==""){
			alert("Please enter the first name.");
			$('#firstName').focus();
			i=1;
			return false;
		}		
		if($.trim($('#lastName').val())==""){
			alert("Please enter the Last name.");
			$('#lastName').focus();
			i=1;
			return false;
		}
		if ($.trim($('#emailUpdate').val())==""){
			alert("Please enter your email.");
			$('#emailUpdate').focus();
			i=1;
			return false;
		}else if($('#emailUpdate').val()){
			var ret = validEmail('emailUpdate');
			if( ret == false ){
				$('#emailUpdate').focus();
				i=1;
				return false;
			}
		}
		
		if($('#zipcode').val().length > 0){
			if(parseInt($('#zipcode').val()) != $('#zipcode').val()){
				alert("Please enter a valid zip code");
				$('#zipcode').focus();
				i=1;
				return false;
			}
			if((parseInt($('#zipcode').val()) + "").length < 5){
				alert("Your zip code is too short.  Please enter a valid zip code");
				$('#zipcode').focus();
				i=1;
				return false;
			}
		}

		/*
		if ($.trim($('#cellphone').val())==""){
			alert("Please enter the phone no.");
			$('#cellphone').focus();
			i=1;
			return false;
		}
		else if(isNaN($('#cellphone').val())){
			alert("Please enter phone no. in numeric format.");
				$('#cellphone').focus();
				i=1;
				return false;
		}
		if ($.trim($('#birthDate').val())){
			var ret = str2dt($('#birthDate').val());
			if( ret == false ){
				$('#birthDate').focus();
				i=1;
				return false;
			}
		}*/
		
		if(i==0){
			return true;
		}
	}
	
//----------------- validate Partner info function ---------------//
function validatePartners(){
	
	var i =0;
	if ($.trim($('#name').val())==""){
		alert("Please enter your name.");
		$('#name').focus();
		i=1;
		return false;
	}

	 if($.trim($('#email').val())==""){
		alert("Please enter your email address.");
		i=1;
		return false;
	}

	var ret =validEmail('email');
	if( ret == false ){
//		alert("Please enter a valid email address.");
		i=1;
		return false;
	}
		
	 if($.trim($('#phone').val())==""){
		alert("Please enter phone no. in numeric format.");
			$('#phone').focus();
			i=1;
			return false;
	}
	if($.trim($('#businessName').val())==""){
			alert("Please enter your business name.");
			$('#businessName').focus();
			i=1;
			return false;
	}
	
	if(i==0){
		return true;
	}
}
//----------------- validate Date function ---------------//
	function str2dt (str_datetime) {
	var reg = /^(\d{4})\-(0\d|1[0-2]|[1-9])\-([0-2]\d|3[0-1]|[1-9])$/;
	if(reg.test(str_datetime) == false) {
      alert('Invalid Date Format');
	  $('#birthDate').focus();
		i=1;
      	return false;
   }
   return true;
}


//----------------- validate URL function ---------------//
function isURL(url){
	var regexp	=	/http:\/\/[A-Za-z0-9\.-]{3,}\.[A-Za-z]{3}/;
	if(regexp.test(url)){
		return true;
	}else{
		return false;
	}
}
function validUrl(url){
	var regexp	=	/[A-Za-z0-9\.-]{1,}\.[A-Za-z]{3}/;
	if(regexp.test(url)){
		return true;
	}else{
		return false;
	}
}

//----------------- validate Change Password Info function ---------------//
function validateChangePassword(){
	var i =0;
	if ($.trim($('#newpassword').val())==""){
			alert("Please enter the New Password.");
			$('#newpassword').focus();
			i=1;
			return false;
	}else if ($.trim($('#newpassword').val())!=$.trim($('#confirmNewpassword').val())){
			alert("Your passwords do not match.");
			$('#newpassword').focus();
			i=1;
			return false;

	}else if($.trim($('#newpassword').val())){
			var pswd=$('#newpassword').val();
			var len=pswd.length;
			if(len<6){
				alert("Please enter password of minimum 6 characters.")
				$('#newpassword').focus();
				i=1;
				return false;
			}
		}
	if(i==0){
		return true;
	}
}
//----------------- validate Email Id function ---------------//
function validEmail(emailId){
	var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
   	var address = document.getElementById(emailId).value;
   	if(reg.test(address) == false) {
      alert('Invalid Email Address');
	  document.getElementById(emailId).focus();
		i=1;
      return false;
   }
   return true;
}
//----------------- Email Id  Exist function ---------------//
function chkEmailExist(email) {
		$.ajax({
			 type: "GET",
			 url:  'signup_frm.php?email='+email,
			 cache: false,
			 success: function(msg){
				$('#duplicateEmail').attr('value',msg);
			}
		});
}
//----------------- validate login info function ---------------//
function validateLogin(){
		var i =0;
		if ($.trim($('#txtEmail').val())==""){
			alert("Please enter your email.");
			$('#txtEmail').focus();
			i=1;
			return false;
		}else if($('#txtEmail').val()){
			var ret = validEmail('txtEmail');
			if( ret == false ){
				i=1;
				return false;
			}
		}
		if($.trim($('#txtPassword').val())==""){
			alert("Please enter the password.");
			$('#txtPassword').focus();
			i=1;
			return false;
		}
		if(i==0){
			return true;
		}
}
//----------------- validate comment info function ---------------//
function validateComment(){
	var i=0;
	var userid =$('#userid').val();
	if($.trim($('#userName').val())==""){
		alert("Please enter your name.");
		$('#userName').focus();
		i=1;
		return false;
	}
	if($.trim($('#userMeassage').val())==""){
		alert("Please enter your message.");
		$('#userMeassage').focus();
		i=1;
		return false;
	}
	if(i==0){
		var offerid=$('#hd_offer').val();
	
		$.ajax({
				 type: "GET",
				 url:  'index.php?userName='+$('#userName').val()+'&userid='+userid+'&message='+escape($('#userMeassage').val())+'&offerId='+offerid,
				 cache: false,
				 success: function(msg){					 
					 alert("Thank you!");
					 $('#userName').attr('value','');
					 $('#userMeassage').attr('value','');
					 $('.counter').html("240 characters left");
				}
			});
	}
}

//----------------- validate Email ID function ---------------//
function validateEmailId(){
var i=0;
if ($.trim($('#email').val())==""){
			alert("Please enter your email.");
			$('#email').focus();
			i=1;
			return false;
		}else{
			var ret = validateEmail($.trim($('#email').val()));
						if( ret == false ){
				i=1;
				return false;
			}
		}
}
//----------------- validate contact info function ---------------//
function validateContactUs(){
var i=0;
if ($.trim($('#name').val())==""){
			alert("Please enter your name.");
			$('#name').focus();
			i=1;
			return false;
		}

if ($.trim($('#email').val())==""){
			alert("Please enter your email.");
			$('#email').focus();
			i=1;
			return false;
		}else{
			var ret = validateEmail($.trim($('#email').val()));
						if( ret == false ){
				i=1;
				return false;
			}
		}
if ($.trim($('#message').val())==""){
			alert("Please enter the message.");
			$('#message').focus();
			i=1;
			return false;
		}
}

//----------------- validate Area function ---------------//
function validateArea(){
var i=0; 
if ($.trim($('#emailArea').val())==""){
			alert("Please enter your email.");
			$('#emailArea').focus();
			i=1;
			return false;
		}else if($('#emailArea').val()){
			var ret = validEmail('emailArea');
			if( ret == false ){
				i=1;
				return false;
			}
		}
		if($.trim($('#zipcode').val())==""){
		alert("Please enter your zipcode.");
		$('#zipcode').focus();
		i=1;
		return false;
	}else if($.trim($('#zipcode').val())){
			var zipcd=$('#zipcode').val();
			var len=zipcd.length;
			if(len<5){
				alert("Please enter zipcode of minimum 5 characters.")
				$('#zipcode').focus();
				i=1;
				return false;
			}
		}
}
function validateArea1(){
var i=0; 
if ($.trim($('#email').val())==""){
			alert("Please enter your email.");
			$('#email').focus();
			i=1;
			return false;
		}else{
			var ret = validateEmail($.trim($('#email').val()));
						if( ret == false ){
				i=1;
				return false;
			}
		}
		if($.trim($('#zipcode').val())==""){
		alert("Please enter your zipcode.");
		$('#zipcode').focus();
		i=1;
		return false;
	}else if($.trim($('#zipcode').val())){
			var zipcd=$('#zipcode').val();
			var len=zipcd.length;
			if(len<5){
				alert("Please enter zipcode of minimum 5 characters.")
				$('#zipcode').focus();
				i=1;
				return false;
			}
		}
		$.ajax({
		type: "POST",
		url:  'index.php',
		data: {submit: 1,
			   email: $('#email').val(),
			   zipcode: $('#zipcode').val()},
		cache: false,
		success: function(msg){
			$('#light').attr('innerHTML','<div>Got it.  We\'ll be in touch!</div><div class="closeBtn"><a href = "javascript:void(0)" onclick = "window.location.href=\'/\';">Close</a></div>');
			$('#light').show();
			$('#fade').show();
		}
	});
	
	return false;
 }
 function clearValue(){
 	if($('#subscribeemail').val()=="Enter your email address"){
		$('#subscribeemail').attr('value','');
	}
		
 }
 
//----------------- Email Subscribe function ---------------//
 function validateSubscription(){
	var i=0;
	if ($.trim($('#subscribeemail').val())=="" || $('#subscribeemail').val()=="Enter your email address"){
			alert("Please enter your email.");
			$('#subscribeemail').focus();
			i=1;
			return false;
	}else if($('#subscribeemail').val()){
		var ret = validEmail('subscribeemail');
		if( ret == false ){
			$('#subscribeemail').focus();
			i=1;
			return false;
		}
	}
	if($('#locationName').val()=="0"){
			alert("Please select the location name.");
			$('#locationName').focus();
			i=1;
			return false;
		}
		
	if(i==0){
		$.ajax({
		type: "GET",
		url:  'subscribe_email.php?email='+$('#subscribeemail').val()+'&locationName='+$('#locationName').val(),
		cache: false,
		success: function(msg){
			if(msg=='error'){
				$('#light').attr('innerHTML','<div>Oops! You\'re already signed up for this area.</div><div class="closeBtn"><a href = "javascript:void(0)" onclick = "$(\'#light\').hide();$(\'#fade\').hide();">Close</a></div>');
				$('#light').show();
				$('#fade').show();
			}else if(msg==1){
				$('#light').attr('innerHTML','<div>Thank you! We\'re glad you\'re with us. Please check your inbox (and other folders) for an email from us.</div><div class="closeBtn"><a href = "javascript:void(0)" onclick = "$(\'#light\').hide();$(\'#fade\').hide();">Close</a></div>');
				$('#light').show();
				$('#fade').show();
				$('#subscribeemail').attr('value','');
				$('#locationName').attr('value','0');			
			}	
		}
	});
		return false;
	   }else{
	   		return false;
	   }
}



//----------------- Email Validation function ---------------//
function validateEmail(emailId){
		atpos 	= emailId.indexOf("@");
		dotpos 	= emailId.lastIndexOf(".");
		len		= emailId.length;
		if (atpos < 1 || ( dotpos - atpos < 2 ) || ( len - dotpos < 3 ) || ( len - dotpos > 4 )) {
			alert("Please enter valid email address.");
		     $('#email').focus();
			return false;
		}
			return true;
	}
function validateEmailCheck(emailId){
		atpos = emailId.indexOf("@");
		dotpos = emailId.lastIndexOf(".");
		if (atpos < 1 || ( dotpos - atpos < 2 )) {
			alert("Please enter valid email address.");
		     $('#emailIdTo').focus();
			return false;
		}
			return true;
	}

function checkEmail(){
	var mail=document.frmcardDetails.emailPurchase.value;
	if(mail==''){
		alert("Please enter email address.");
		$('#emailPurchase').focus();
		i=1;
		return false;
	}else if($('#emailPurchase').val()){
			var ret = validEmail('emailPurchase');
			if( ret == false ){
				$('#emailPurchase').focus();
				i=1;
				return false;
			}
		}
	$.ajax({
			 type: "GET",
			 url:  'signup_frm.php?email='+mail,
			 cache: false,
			 success: function(msg){
				 if(msg=='1'){
				 alert("Your email address already exists in our system.");
				 $('#emailPurchase').focus();
				 i=1;
				 return false;
				 }else{
				 	alert(mail+'  '+ "is available.");
					i=1;
				 	return false;
				 }
			}
		});
}
function validEmail(emailId){
	var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
   	var address = document.getElementById(emailId).value;
   	if(reg.test(address) == false) {
      alert('Invalid Email Address');
	  document.getElementById(emailId).focus();
		i=1;
      return false;
   }
   return true;
}
var formatDate = function (formatDate, formatString) {
	if(formatDate instanceof Date) {
		var months = new Array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec");
		var yyyy = formatDate.getFullYear();
		var yy = yyyy.toString().substring(2);
		var m = formatDate.getMonth() + 1;
		var mm = m < 10 ? "0" + m : m;
		var mmm = months[m];
		var d = formatDate.getDate();
		var dd = d < 10 ? "0" + d : d;
		
		var h = formatDate.getHours();
		var hh = h < 10 ? "0" + h : h;
		var n = formatDate.getMinutes();
		var nn = n < 10 ? "0" + n : n;
		var s = formatDate.getSeconds();
		var ss = s < 10 ? "0" + s : s;

		formatString = formatString.replace(/yyyy/i, yyyy);
		formatString = formatString.replace(/yy/i, yy);
		formatString = formatString.replace(/mmm/i, mmm);
		formatString = formatString.replace(/mm/i, mm);
		formatString = formatString.replace(/m/i, m);
		formatString = formatString.replace(/dd/i, dd);
		formatString = formatString.replace(/d/i, d);
		formatString = formatString.replace(/hh/i, hh);
		formatString = formatString.replace(/h/i, h);
		formatString = formatString.replace(/nn/i, nn);
		formatString = formatString.replace(/n/i, n);
		formatString = formatString.replace(/ss/i, ss);
		formatString = formatString.replace(/s/i, s);

		return formatString;
	} else {
		return "";
	}
}

function chkPopupForm(){
	var recEmail    = $('#toMail').val();
	var senderEmail = $('#fromMail').val();
	var postedMsg   = $('#msg').val();
	var offerTitle	= $('#offerTitle').val();
	var msg 		= '';
	var i=0;
	if($.trim($('#toMail').val())==""){
		i=1;
		alert('Please enter the receipient\'s email address');
		$('#toMail').focus();
		return false;
	}
	if($.trim($('#fromMail').val())==""){
		i=1;
		alert('Please enter the sender\'s email address');
		$('#fromMail').focus();
		return false;
	}else if($('#fromMail').val()){
		var ret = validEmail('fromMail');
		if(ret == false ){
			$('#fromMail').focus();
			i=1;
			return false;
		}
	}
	if(i==1){
		return false;
	}else{
		$.ajax({
			 type: "GET",
			 url:  'invitation.php?recEmail='+escape(recEmail)+'&senderEmail='+escape(senderEmail)+'&postedMsg='+escape(postedMsg)+'&offerTitle='+escape(offerTitle),
			 cache: false,
			 success: function(msg){
				 alert('Your Email has been sent successfully.');
				 $('#emailDiv').css('display','none');
				 return false;
			 }
		});
	}
}

