/*
Virtual E shopping project pop up box
*/
if( typeof(virtualE) == "undefined" ){virtualE = {};}
/* Javascript Class file for Virtual E Shopping Project  */
virtualE = {
	init:function(){/* Fancy Drop down - init*/ GG_Drop.Fancy.init();this.fetchUsers();},
	showBox:function(title,inlineId,width,height){tb_show(title,"?TB_inline=true&inlineId="+inlineId+"&width="+width+"&height="+height+"&modal=true");},
	
	/*  Hide Pop up box */
	hidebox:function(){tb_remove();},
	
	fetchUsers:function(){ //Modified to make autocomplete in invite friends popup; Dinesh; 04-Aug-09
		var path = baseurl+"friends/fetchusers/autocomplete";
			if (jQuery("#keyword")) {
				jQuery("#keyword").autocomplete(path);
				
				jQuery("#keyword").keydown(function(){jQuery(".ac_results").css("position","absolute");});
			}
			if (jQuery("#searchfriends")) {
				jQuery("#searchfriends").autocomplete(path);
				
				jQuery("#searchfriends").keydown(function(){jQuery(".ac_results").css("position","fixed");});
			}
		}
		

}

/*------------------------------ Caller functionss ------------------------------*/
/* Javascript Class file for Showbox */
function showbox(opt)
{ 
	switch(opt)
	{
		// Registration form
		case "registration" :{
			// added setTimeout function inorder to focus the first field in registration added on 08-Aug-09 by Padma
			setTimeout(function(){jQuery('#email').focus();},200);
			jQuery("#registertitle").html("Registration");
			// changed the width and height for the new register page added on 10-Aug-09 by padma
			virtualE.showBox("thickbox_popup","hidden_registration", 775, 620); 
			break;
		}
		// profile form	
		case "profile" :{
			jQuery("#registertitle").html("Edit Profile");
			// changed the width and height for the new register page added on 10-Aug-09 by padma
			virtualE.showBox("thickbox_popup","hidden_registration", 775, 620); 
			break;
		}
		// Forgot password form	
		case "forgotpassword" : { 
			// added setTimeout function inorder to focus the first field in forgot password added on 08-Aug-09 by Padma
			setTimeout(function(){jQuery('#forgotusername').focus();}, 200);
			jQuery("#forgot_password").html("Forgot Password");			
			virtualE.showBox("thickbox_popup","hidden_forgotpassword", 400, 100);
			break;
		}	
		// Shopper forgot login	form for footer link
		case "shopperforgotlogin" : { 
			// added setTimeout function inorder to focus the first field in forgot password added on 08-Aug-09 by Padma
			setTimeout(function(){jQuery('#forgotusername').focus();}, 200);
			jQuery("#forgot_password").html("Shopper Forgot Login");
			virtualE.showBox("thickbox_popup","hidden_forgotpassword", 400, 100);
			break;
		}	
		// Invite Friends Popup; Dinesh; 30-July-09
		case "invitefriends" : { 
			jQuery("#feon_submit").attr("style", "display:block");
			jQuery("#feon_loader").attr("style", "display:none");
			virtualE.showBox("invite_friends_popup","hidden_invitefriends",750,600);
			break;
		}		
		// Login validation message
		case "invalidemailpassword" : case "passwordvalidate" :case "emailvalidate" :  { 
			virtualE.showBox("thickbox_popup","hidden_emailvalidate",400,80);			
			break;
		}
	    // Register success		
		case "registersuccess" : {
			virtualE.showBox("thickbox_popup","hidden_informationpopup", 400, 80);			
			break;
		}	
		//profile success
		case "profile" : case "profilesuccess" : {
			virtualE.showBox("thickbox_popup","hidden_informationpopup", 400, 80);			
			break;
		}
		
		// My Dates to Remember Add events form for profile page -- Added 03-08-09 by Govind
		case "mydatestoremember" : {
			virtualE.showBox("thickbox_popup","hidden_mydatesremember",400,350);			
			break;
		}
		// Shoppers FAQ for FAQ button -- Added 04-08-09 by Govind
		case "shoppersfaq" : {
			jQuery(".faq_collapse img").attr("src", baseurl+"images/faq_offbut.gif");
			jQuery(".faq_answer").attr("style", "display:none");
			jQuery(".faq_pad li").attr("class", "");
			jQuery("#0").attr("class", "faq_licont2");
			virtualE.showBox("thickbox_popup","hidden_shoppers_faq",895,580);			
			break;
		}	
		case "friendsrequests" : {
			virtualE.showBox("friendsrequests_popup","myfav_popup1",700,600);			
			break;
		}
		// Choose other contacts popup for profile page invite friends -- Added 05-08-09 by Govind
		case "chooseothercontacts" : {
			virtualE.showBox("thickbox_popup","invite_othernetworks_choose_contacts",750,600);			
			break;
		}
		
		// My stuff popup added I want it / I got it
		
		case "addstuff" : {
			virtualE.showBox("thickbox_popup","hidden_mystuff",545,710);			
			break;
		}
		
		case "invitesuccesspopup" : {
			virtualE.showBox("thickbox_popup","invitesuccesspopup",545,710);			
			break;
		}
		
		// My Dates to Remember More delete form for profile dates more page -- Added 06-08-09 by Govind
		case "mydatestorememberdelete" : {
			virtualE.showBox("thickbox_popup","hidden_mydatesrememberdelete",400,80);			
			break;
		}
		
		//Popup for mystuff delete on stuff detail page - Ramesh
		case "deletestuff": {
			virtualE.showBox("thickbox_popup","hidden_mystuffdelete",400,80);			
			break;
		}

		// Mall dates for profile page -- Added 08-08-09 by Govind
		case "malldates" : {
			var url = baseurl+"profile/displaymalldates";
			loadMallDates(url);
			virtualE.showBox("thickbox_popup","hidden_mall_dates",560,580);			
			break;
		}
		
		// Mall invitation for profile page -- Added 12-08-09 by Govind
		case "mallinvitation" : {
			var url = baseurl+"profile/displaymallinvitation";
			loadMallInvitation(url);
			virtualE.showBox("thickbox_popup","hidden_mall_invitation",560,580);			
			break;
		}
		
		// Mall invitation for profile page -- Added 12-08-09 by Govind
		case "favouritestore" : {
			virtualE.showBox("thickbox_popup","myfav_popup", 600, 670);			
			break;
		}
		
		// Terms of Services footer link -- Added 12-08-09 by Govind
		case "termsofservice" : {
			virtualE.showBox("thickbox_popup","hidden_shoppers_terms",895,580);			
			break;
		}	
		
		//Show confirmation box for deletion in Shopping Tips
		case "confirmdelete" : {
			virtualE.showBox("shoppingtips","hidden_confirmdeletetip",895,580);			
			break;
		}
		
		//Show confirmation box for deletion in Shopping Tips AJAX
		case "confirmdeleteajax" : {
			virtualE.showBox("shoppingtips","hidden_confirmdeleteajax",895,580);			
			break;
		}
		
		//Show Contact list by Filter into mall
		
		case "choosecontactinvitemall" : {
			virtualE.showBox("thickbox_popup","invite_friends_into_mall",750,600);			
			break;
		}
		
		//Show Installation guide Popup
		
		case "installationguide" : {
			virtualE.showBox("thickbox_popup","install_guide",780, 600);			
			break;
		}
		// Show Privacy Policy
		case "privacypolicy" : {
			virtualE.showBox("thickbox_popup", "privacy_policy", 780, 220);			
			break;
		}
		
		// Advertiser Contact Us  -- Added 27-08-09 by Govind
		case "ad_contact" : {
			virtualE.showBox("thickbox_popup","hidden_advertiser_contact",895,580);			
			break;
		}	
	}
}

/* Hide the box */
function hidebox(parameter)
{	

	switch(parameter)
	{
		// Forgot password & Shopper forgot login	form	
		case "invitefriends" : {
			//Empty the Tab-4 schedule date
			
			jQuery("#date_schedule").val('');
			jQuery("#sh_time").val('');
			jQuery("#sh_du").val('AM');
			jQuery("#invite_contact_mall").val('');			
			jQuery("#sel_zone").val('1');
			jQuery("#filter_friends").val('');
			jQuery("#errSchedule").html('');
			jQuery("#invitebyemailtomallerrors").html("");
			jQuery("#filter").attr("disabled", true);
			
			jQuery("#AdditionalComments1").val('(maximum 200 characters with spaces.)');

			// Enable the fields
			jQuery("#date_schedule").attr("disabled", false);
			jQuery("#sh_time").attr("disabled", false);
			jQuery("#sh_du").attr("disabled", false);
			jQuery("#sel_zone").attr("disabled", false);
			jQuery(".tab4sch_date img").attr("style", "display:block");
			
		}
		// Invite friends
		case "filterinvitefriends" :{
			//Empty VirtualEShopping fields
			
			jQuery("#searchfriends").val("Search Friends");
			jQuery("#searchResults").html("");
			jQuery("#searchResultsmessage").html("");
			
			//Empty Invite By Email fields
			jQuery("#ToEmailAddresses").val("");
			jQuery("#AdditionalComments").val("(maximum 200 characters with spaces.)");
			jQuery("#invitebymailerrors").html("");
			jQuery("#characterLeft_Popup").html("200 Characters Left"); // Added Govind 180809
			
			// Find other email networks
			jQuery("#feon_email").val('');
			jQuery("#feon_password").val('');
			jQuery("#feon_other_mail_error_message").html('');
			jQuery("#feon_other_contacts").val('');
			jQuery("#feon_other_message").val('(maximum 200 characters with spaces.)');
			jQuery("#hidden_feon_other_error_message").attr("style", "display:none");
			jQuery("#feon_characterLeft").html("200 Characters Left");
			
			// See What you Send - Govind 14-08-09
			jQuery("#seewhatyousendthem_hide").attr("style", "display:none");
			jQuery(".seewhatyousendpopup").html('');			
			
			break;
		}	
	
		// Unsetting the registration form values
		case "register" : case "registersuccess" : {
			jQuery("#registererrormsg").html("");		
			jQuery("#successmsg").html('');
			jQuery("#hidden_informationpopup").hide();
			jQuery("#email").val(''); 
			jQuery("#firstname").val(''); 
			jQuery("#lastname").val('');
			jQuery("#gender").val(0);
			//jQuery("#age")[0].selectedIndex = 0;
			setFancyValue('age', 0);
			setFancyValue('maritalstatus', 0);
			setFancyValue('interestedin', 0);
			setFancyValue('interestedtype', 0);
			setFancyValue('profession', 0);
			setFancyValue('hobbies', 0);
			setFancyValue('country', 0);
			//setFancyValue('state', 0);
			jQuery("#city").val('');
			jQuery("#postalcode").val('');
			break;
		}	
		// profile and profilesuccess form	
		case "profile": case "profilesuccess" : {
			jQuery("#successmsg_register").html("");
			break;
		}			
		// Forgot password & Shopper forgot login	form	
		case "forgotpassword" : {
			jQuery('#forgotusername').val("");
			jQuery("#forgoterrormsg").html("");
			break;
		}
		// My Dates to Remember Add events form -- Added 03-08-09 by Govind
		case "mydatestoremember" : { 
			// Unsetting the input values and alert messages
			jQuery("#myDatesRememberSaveAlert").html("");
			jQuery("#mdr_other_name").val('');
			jQuery("#mdr_occassions")[0].selectedIndex = 0;
			jQuery("#mdr_stuff").val('');
			jQuery("#mdr_date").val('');
			jQuery("#hidden_mydatesremember_others").attr("style", "display:none");
			jQuery(".mdr_date_hide").attr("style", "display:block");
			break;
		}
		
		case "hidden_mystuff" : {
			jQuery("#userfile").val('');
			jQuery("#stuff_url").val('');
			jQuery("#stuff_dec").val('');
			break;
		}
		// Hide mall dates for profile page -- Added 08-08-09 by Govind
		case "malldates" : {
			//virtualE.showBox("thickbox_popup","hidden_mall_dates",400,80);			
			break;
		}
		// Hide mall invitation for profile page -- Added 12-08-09 by Govind
		case "mallinvitation" : {
			//virtualE.showBox("thickbox_popup","hidden_mall_invitation",400,80);			
			break;
		}
		
		case "confirmdelete" : {
			return true;
			break;
		}

		// Hide Shoppers FAQ for FAQ button -- Added 17-08-09 by Govind
		case "shoppersfaq" : {
			break;
		}	
		case "myfav_popup" : {
			jQuery("#myfavSaveAlert").html("");
			jQuery("#my_fav_upimage").html("");
			jQuery("#my_fav_upimage").css("display", "none");
			jQuery("#my_fav_file").val('');			
			jQuery("#weburl").val('(ex.:http://www.virtualeshopping.com)');
			jQuery("#webname").val('(ex.:Best Buy)');
			jQuery("#weburl").css("color", "grey");
			jQuery("#webname").css("color", "grey");
			break;
		}	
		// Advertiser Contact Us link -- Added 27-08-09 by Govind
		case "ad_contact" : {
			jQuery("#pertaining").val(1)
			jQuery(".adcontact").attr("style", "display:none");
			jQuery("#contact_ts").attr("style", "display:block");
			jQuery("#ad_contact_error").html("");

			jQuery("#name").val('');
			jQuery("#contact_email").val('');
			jQuery("#phone").val('');
			jQuery("#comments").val('');

			break;
		}	
	}
	virtualE.hidebox();
	// Reloading the parent window after updating the profile --- Added 04-08-09 by Padma
	if (parameter == "profilesuccess"){
		setTimeout('parent.location.reload();',300);
	}
}

/* Hide & show the hover div  for home page*/
function show_right(id,pos){
	jQuery("#"+id).css("left",pos.clientX-500)
	jQuery("#"+id).show();
}
function show_left(id,pos){
	jQuery("#"+id).css("left",pos.clientX+100)
	jQuery("#"+id).show();
}
function hide(id){
	jQuery("#"+id).hide();
}

/*Hover functionality for how to enter & re-enter into mall on profile page -- Ramesh*/




jQuery(document).ready(function(){
	jQuery('#username').focus();	
	/* login validation    */
	jQuery("#loginfrm").submit(function(){										
		var username = jQuery("#username").val();
		var pwd = jQuery("#password").val()
		//jQuery("#infotitle").html("Login Validation");
		if (jQuery("#username").val() == '') {
			showbox("emailvalidate");	
			jQuery("#errormsg").html('Please enter your username');			
			parent.jQuery("input#username").focus();
			return false;
		} else {
			if(jQuery.trim(jQuery("#username").val())!="") {
				var email_val=jQuery.trim(jQuery("#username").val());
				var email  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
				if (!email_val.match(email)) {
					showbox("emailvalidate");	
					jQuery("#errormsg").html('Please enter valid username');	
					parent.jQuery("input#username").focus();  
					return false;
				}
			}
      	}
		if (jQuery("#password").val() == '') {
			showbox("passwordvalidate");	
			jQuery("#errormsg").html('Please enter your password');
			parent.jQuery("input#password").focus();
			return false;
		}
		redirecturl = jQuery("#redirecturl").val();
		
		/* submitting the form in ajax for the login  */
		jQuery.ajax({
			type: "POST",	
			data :"username="+username+"&password="+pwd,
			url: baseurl+"login",
			async: false,
			cache: false,			
			success: function(msg){
				if (msg == "success") {
					location.href = baseurl+redirecturl;
				}
				if (msg == "failure") {					
					showbox("invalidemailpassword");
					jQuery("#errormsg").html('Please enter valid username and password');	
					parent.jQuery("#username").val("");
					parent.jQuery("#password").val("");
					parent.jQuery("input#username").focus();
				}
			}  
		});	
		return false;
	});
	
	/* Search for friends in invite friends on form submit; Dinesh; 30-July-09 */
	jQuery("#searchfriendsfrm").submit(function(){
		//Hide the autocomplete on submit
		jQuery(".ac_results").hide();
		var searchtext = jQuery("#searchfriends").val();
		var searchtext = jQuery.trim(searchtext);
		
		//Validate the entered keyword
		if (searchtext == "Search Friends" || searchtext == "") {
			jQuery("#searchfriends").val("Search Friends");
			return false;
		}
		
		//Initialize div as empty
		jQuery("#searchResults").html("");
		jQuery("#searchResultsmessage").html("");
		
		//Loading Message
		jQuery("#searchResults").html("Searching Friends... Please Wait!!!");
		jQuery("#searchResults").addClass("success_message");
		jQuery.ajax({
			type: "POST",	
			data :"keyword="+searchtext,
			url: baseurl+"invitefriends/searchfriends",
			async: false,
			cache: false,			
			success: function(msg){
				if (msg == "failure") {
					jQuery("input#searchfriends").focus();
					jQuery("#searchResults").html("");	
					jQuery("#searchResultsmessage").html("Sorry. No one matches your search criteria. <br>Please try another method to locate/invite this person as your friend.");
					jQuery("#searchResultsmessage").removeClass("tabinvite_searchhdtxt");
					jQuery("#searchResultsmessage").addClass("norecord_message");
				} else {
					jQuery("input#searchfriends").focus();
					jQuery("#searchResultsmessage").html("The following meet the search criteria you entered. Are you looking for:<br/>");
					jQuery("#searchResultsmessage").removeClass("norecord_message");
					jQuery("#searchResultsmessage").addClass("tabinvite_searchhdtxt");
					jQuery("#searchResults").html(msg);
					jQuery("#searchResults").removeClass("success_message");
				}
			}  
		});	
		
		return false;
	}); //Ends Here

	/*  forgot password  validation*/
	jQuery("#forgotpasswordfrm").submit(function(){
		jQuery("#forgoterrormsg").html('');
		if (jQuery("#forgotusername").val() == "") {
			jQuery("#forgoterrormsg").html('Please enter your email')
			jQuery("input#forgotusername").focus();
			return false;
		}else {
			if(jQuery.trim(jQuery("#forgotusername").val())!="") {
				var email_val=jQuery.trim(jQuery("#forgotusername").val());
				var email  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
				if (!email_val.match(email)) {
					jQuery("#forgoterrormsg").html('Please enter valid email');	
					jQuery("input#forgotusername").focus();  
					return false;
				}
			}
      	}
	
		/* submitting the form for forgot password */
		var forgotusername = jQuery("#forgotusername").val();	
		jQuery.ajax({
				type: "POST",	
				data :"forgotusername="+jQuery("#forgotusername").val(),
				url: baseurl+"forgotpassword",
				async: false,
				cache: false,			
				success: function(msg){
					if (msg == "success") {
						jQuery("#forgotusername").val("");
						jQuery("#forgoterrormsg").html('We have sent the password to your email id');	
					}
					if (msg == "failure") {					
						jQuery("#forgoterrormsg").html('We did not recognize the email you provided.');	
						jQuery("#forgotusername").val("");
						jQuery("input#forgotusername").focus();
					}
				}  
		});	
		
		return false;
	});

	/////////////////////////////////////////// Password Validation ////////////////////////////////////
	
	function validatePassword (pw, options) {
	// default options (allows any password)
	var o = {
		lower:    0,
		upper:    0,
		alpha:    0, /* lower + upper */
		numeric:  0,
		special:  0,
		length:   [0, Infinity],
		custom:   [ /* regexes and/or functions */ ],
		badWords: [],
		badSequenceLength: 0,
		noQwertySequences: false,
		noSequential:      false
	};

	for (var property in options)
		o[property] = options[property];

	var	re = {
			lower:   /[a-z]/g,
			upper:   /[A-Z]/g,
			alpha:   /[A-Z]/gi,
			numeric: /[0-9]/g,
			special: /[\W_]/g
		},
		rule, i;

	// enforce min/max length
	if (pw.length < o.length[0] || pw.length > o.length[1])
		return false;

	// enforce lower/upper/alpha/numeric/special rules
	for (rule in re) {
		if ((pw.match(re[rule]) || []).length < o[rule])
			return false;
	}

	// enforce word ban (case insensitive)
	for (i = 0; i < o.badWords.length; i++) {
		if (pw.toLowerCase().indexOf(o.badWords[i].toLowerCase()) > -1)
			return false;
	}

	// enforce the no sequential, identical characters rule
	if (o.noSequential && /([\S\s])\1/.test(pw))
		return false;

	// enforce alphanumeric/qwerty sequence ban rules
	if (o.badSequenceLength) {
		var	lower   = "abcdefghijklmnopqrstuvwxyz",
			upper   = lower.toUpperCase(),
			numbers = "0123456789",
			qwerty  = "qwertyuiopasdfghjklzxcvbnm",
			start   = o.badSequenceLength - 1,
			seq     = "_" + pw.slice(0, start);
		for (i = start; i < pw.length; i++) {
			seq = seq.slice(1) + pw.charAt(i);
			if (
				lower.indexOf(seq)   > -1 ||
				upper.indexOf(seq)   > -1 ||
				numbers.indexOf(seq) > -1 ||
				(o.noQwertySequences && qwerty.indexOf(seq) > -1)
			) {
				return false;
			}
		}
	}

	// enforce custom regex/function rules
	for (i = 0; i < o.custom.length; i++) {
		rule = o.custom[i];
		if (rule instanceof RegExp) {
			if (!rule.test(pw))
				return false;
		} else if (rule instanceof Function) {
			if (!rule(pw))
				return false;
		}
	}

	// great success!
	return true;
}

	
	
	//////////////////////////////////////////////////////////////////////////////////////////////


	/* registration validation    */
	// validation for the registration form
	jQuery("#registrationfrm").submit(function(){
		
	if (jQuery("#email").val() == '') {
			jQuery("#registererrormsg").html('Please enter your valid email');	
			jQuery("#email").addClass('regtexzt');	
			jQuery("input#email").focus();  					
			return false;
		} else 	if(jQuery.trim(jQuery("#email").val())!="") {
				var email_val=jQuery.trim(jQuery("#email").val());
				var email  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
				if (!email_val.match(email)) {
					jQuery("#registererrormsg").html('Please enter valid email');	
					jQuery("#email").addClass('regtexzt');						
					jQuery("input#email").focus();  
					return false;
				}
		}
	   if (jQuery("#reemail").val() == '') {
			jQuery("#registererrormsg").html('Please re-enter your email');	
			jQuery("#reemail").addClass('regtexzt');	
			jQuery("input#reemail").focus();  					
			return false;
		}
		if(jQuery.trim(jQuery("#reemail").val())!=jQuery.trim(jQuery("#email").val())) {
			jQuery("#registererrormsg").html('Email does not match');	
			jQuery("#reemail").addClass('regtexzt');	
			jQuery("input#reemail").focus();  					
			return false;
		}
		if(jQuery("#pass").val() == '(6 to 10 characters)' || jQuery("#pass").val()=='' ) {
			jQuery("#registererrormsg").html('Please enter a password');	
			jQuery("#reemail").addClass('regtexzt');	
			jQuery("input#pass").focus();  					
			return false;
		}
		
		var len = jQuery("#pass").val();
		
		if(len.length<6) {
			jQuery("#registererrormsg").html('Password must 6 to 10 character');	
			jQuery("#reemail").addClass('regtexzt');	
			jQuery("input#pass").focus();  					
			return false;
		}
		if (jQuery("#firstname").val() == '') {
			jQuery("#successmsg").html("");
			jQuery("#registererrormsg").html('Please enter your firstname');	
			jQuery("#email").addClass('regtexzt');	
			jQuery("input#firstname").focus();
			return false;
		}else if(isValidText(jQuery.trim(jQuery('#firstname').val()))){
				jQuery("#successmsg").html("");
				jQuery("#registererrormsg").html("Please enter valid first name");
				jQuery("input#firstname").focus();  
				return false;										 
		}else if (jQuery("#lastname").val() == '') {
			jQuery("#successmsg").html("");
			jQuery("#registererrormsg").html('Please enter your lastname');	
			jQuery("input#lastname").focus();
			return false;
		}else if(isValidText(jQuery.trim(jQuery('#lastname').val()))){
			jQuery("#successmsg").html("");
			jQuery("#registererrormsg").html("Please enter valid last name");
			jQuery("input#lastname").focus();  
			return false;										 
		} else if(jQuery.trim(jQuery('#timezone').val()) == ""){
			jQuery("#registererrormsg").html("Please select timezone");
			jQuery("#timezone").focus();  
			return false;
		}else if (jQuery("#country").val() > 0 && jQuery("#state").val() > 0) {
			jQuery("#successmsg").html("");
			jQuery("#registererrormsg").html('Please don\'t choose the US state');	
			jQuery("input#state").focus();
			return false;
		}else if(jQuery.trim(jQuery('#postalcode').val())!="" && (isValidText(jQuery.trim(jQuery('#postalcode').val())))) {
			if(jQuery("#successmsg").html() != ''){
				jQuery("#successmsg").html('');
			}
			jQuery("#registererrormsg").html("Please enter valid postal code");
			jQuery("#postalcode").focus();  
			return false;			
		} else if(jQuery.trim(jQuery('#postalcode').val())!="" && !isOnlySpecial(jQuery.trim(jQuery('#postalcode').val()))
				  || jQuery.trim(jQuery('#postalcode').val())!="" && !isNumeric(jQuery('#postalcode').val())){
			if(jQuery("#successmsg").html() != ''){
				jQuery("#successmsg").html('');
			}
			jQuery("#registererrormsg").html("Please enter valid postal code");
			jQuery("#postalCode").focus();  
			return false;
		}else {
			 jQuery("#registererrormsg").html('');
		}
		 var security = jQuery("input[@name='securitysetting']:checked").val();
		 var limitedval = new Array();
		 jQuery.each(jQuery("input[@name='limited[]']:checked"), function() {
		    limitedval.push(jQuery(this).val());
			
		});
		 if(security == 1 && limitedval == ''){
			 jQuery("#registererrormsg").html("Please Select One Limited To");
			 
			 return false;
		 }	
		
		/* submitting the form in ajax to enter the user information  */
		var gender = jQuery("input[id='gender']:checked").val();
		jQuery.ajax({
			type: "POST",	
			data :"email="+jQuery("#email").val()+"&passw="+jQuery("#pass").val()+"&firstname="+jQuery("#firstname").val()+"&lastname="+jQuery("#lastname").val()+"&gender="+gender+"&age="+jQuery("#age").val()+"&maritalstatus="+jQuery("#maritalstatus").val()+"&interestedin="+jQuery("#interestedin").val()+"&interestedtype="+jQuery("#interestedtype").val()+"&profession="+jQuery("#profession").val()+"&hobbies="+jQuery("#hobbies").val()+"&timezone="+jQuery("#timezone").val()+"&city="+jQuery("#city").val()+"&state="+jQuery("#state").val()+"&country="+jQuery("#country").val()+"&postalcode="+jQuery("#postalcode").val()+"&securitysetting="+security+"&limited="+limitedval,
			url: baseurl+"register/addUser",
			async: false,
			cache: false,			
			success: function(msg){	
				alert(msg)
				if (msg == "success") {
					jQuery("#registererrormsg").html("");
					hidebox('register');
					jQuery("#infotitle").html("Registration Information");
					jQuery("#successmsg_register").html("Please click the validation link in the email that will be sent to you complete your registration. If you do not receive the email within 5 minutes, please check your spam folder");
					setTimeout('showbox("registersuccess")',300);
				}
				else {					
					hidebox('register');
					jQuery("#infotitle").html("Information");
					jQuery("#successmsg_register").html("Please try again later to register");
					setTimeout('showbox("registersuccess")',300);	
				}
			} 			
		});	

		return false;

	});
	
	// Email validation	and checking whether the email id already exists or not
	
	jQuery("#email").blur(function(){	
		var emailid = jQuery("#email").val();
		if (jQuery("#email").val() == '') {
			jQuery("#registererrormsg").html('Please enter your email');	
			jQuery("#email").addClass('regtexztlite');						
			return false;
		} else {
			if(jQuery.trim(jQuery("#email").val())!="") {
				var email_val=jQuery.trim(jQuery("#email").val());
				var email  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
				if (!email_val.match(email)) {
					jQuery("#registererrormsg").html('Please enter valid email');	
					jQuery("input#email").focus();  
					return false;
				}
			}
      	}
		// calling the ajax page to check whether email id exists or not
		jQuery.ajax({
			type: "POST",	
			data :"emailid="+emailid,
			url: baseurl+"register",
			async: false,
			cache: false,			
			success: function(msg){
				if (msg == "success") {
					jQuery("#registererrormsg").html('Email Already exists.Please try different email');	
				}
				if (msg == "failure") {									
					jQuery("#registererrormsg").html('');	
					jQuery("#successmsg").html('Email is available');	
				}
			}  
		});
		return false;

	});
	// function to validate the update profile
	jQuery("#profilefrm").submit(function(){
										 
		var strpassword = jQuery('#password').val();
		if (jQuery("#password").val() == '') {
			jQuery("#registererrormsg").html('Please enter your password');	
			//jQuery("#password").addClass('regtexzt');	
			jQuery("input#password").focus();
			return false;
		}else if(strpassword.length < 6) {
				// changed the password error message on 12-08-09 by padma
				jQuery("#registererrormsg").html("Password must be 6 to 7 characters");
				jQuery("input#password").focus();  
				return false;										 
		}else if(isValidText(jQuery.trim(jQuery('#password').val()))) {
				jQuery("#registererrormsg").html("Please enter valid password");
				jQuery("input#password").focus();  
				return false;										 
		}					
		else if (jQuery("#firstname").val() == '') {
			jQuery("#registererrormsg").html('Please enter your firstname');	
			//jQuery("#email").addClass('regtexzt');	
			jQuery("input#firstname").focus();
			return false;
		}else if(isValidText(jQuery.trim(jQuery('#firstname').val()))) {
				jQuery("#registererrormsg").html("Please enter valid first name");
				jQuery("input#firstname").focus();  
				return false;										 
		}else if (jQuery("#lastname").val() == '') {
			jQuery("#registererrormsg").html('Please enter your lastname');	
			jQuery("input#lastname").focus();
			return false;
		}else if(isValidText(jQuery.trim(jQuery('#lastname').val()))) {
			jQuery("#registererrormsg").html("Please enter valid last name");
			jQuery("input#lastname").focus();  
			return false;										 
		}else if (jQuery("#country").val() > 0 && jQuery("#state").val() > 0) {
			jQuery("#registererrormsg").html('Please don\'t choose the US state');	
			jQuery("input#state").focus();
			return false;
		}else if(jQuery.trim(jQuery('#postalcode').val())!="" && (isValidText(jQuery.trim(jQuery('#postalcode').val())))) {
			if(jQuery("#successmsg").html() != ''){
				jQuery("#successmsg").html('');
			}
			jQuery("#registererrormsg").html("Please enter valid postal code");
			jQuery("#postalcode").focus();  
			return false;			
		} else if(jQuery.trim(jQuery('#postalcode').val())!="" && !isOnlySpecial(jQuery.trim(jQuery('#postalcode').val()))
				  || jQuery.trim(jQuery('#postalcode').val())!="" && !isNumeric(jQuery('#postalcode').val())){
			if(jQuery("#successmsg").html() != ''){
				jQuery("#successmsg").html('');
			}
			jQuery("#registererrormsg").html("Please enter valid postal code");
			jQuery("#postalCode").focus();  
			return false;
		}
		
		 var security = jQuery("input[@name='securitysetting']:checked").val();
		 var limitedval = new Array();
		 jQuery.each(jQuery("input[@name='limited[]']:checked"), function() {
		    limitedval.push(jQuery(this).val());
			
		});
		 if(security == 1 && limitedval == ''){
			 jQuery("#registererrormsg").html("Please Select One Limited To");
			 
			 return false;
		 }	
		 
		var gender = jQuery("input[id='gender']:checked").val();
		// ajax function to update the entered user information into the table
		// Added timezone field in edit profile page on 17-Aug-09 by Padma.
		jQuery.ajax({
			type: "POST",	
			data :"firstname="+jQuery("#firstname").val()+"&password="+jQuery("#password").val()+"&oldpassword="+jQuery("#oldpassword").val()+"&lastname="+jQuery("#lastname").val()+"&gender="+gender+"&age="+jQuery("#age").val()+"&maritalstatus="+jQuery("#maritalstatus").val()+"&interestedin="+jQuery("#interestedin").val()+"&interestedtype="+jQuery("#interestedtype").val()+"&profession="+jQuery("#profession").val()+"&hobbies="+jQuery("#hobbies").val()+"&timezone="+jQuery("#timezone").val()+"&city="+jQuery("#city").val()+"&state="+jQuery("#state").val()+"&country="+jQuery("#country").val()+"&postalcode="+jQuery("#postalcode").val()+"&securitysetting="+security+"&limited="+limitedval,
			url: baseurl+"profile/updateUser",
			async: false,
			cache: false,			
			success: function(msg){	
				// success					
				if (msg == "success") {
					jQuery("#registererrormsg").html("");
					hidebox('profile');
					jQuery("#infotitle").html("Information");
					// If the user changes the password. we need to display this msg and shud be logged out.
					if (jQuery("#password").val() != jQuery("#oldpassword").val()) {
						strPasswordsuccess = "\nSince you have changed your password, you will have to login again using the new password sent to you through e-mail.";
					}else{
						strPasswordsuccess = '';
					}
					jQuery("#successmsg_register").html("Your account has successfully been updated."+strPasswordsuccess);
					setTimeout('showbox("profilesuccess")',300);
					if (strPasswordsuccess != '') {
						jQuery(".information_mid_top h3 a").attr("href", baseurl+"login/logout");
					}
				}
				else {		
				// failure			
					hidebox('profile');
					jQuery("#infotitle").html("Information");
					jQuery("#successmsg_register").html("Failed to update the profile");
					setTimeout('showbox("profilesuccess")',300);
				}
			} 			
		});	
     return false;
	});

	/* Function added for how to enter & re-enter into mall on profile page -- Ramesh */
	
	    var sid;
	
		jQuery("#close_hover_mall").click(function(){
		   jQuery("#mall_tip").css("display","none");
		});

	    jQuery("#tip_hover").mouseover(function(){
		   jQuery("#mall_tip").css("display","block");
		});
		jQuery("#mall_tip").mouseover(function(){
		   clearTimeout(sid)									
		   jQuery("#mall_tip").css("display","block");
		});
		jQuery("#mall_tip").mouseout(function(){
		   jQuery("#mall_tip").css("display","none");
		});

		jQuery("#tip_hover").mouseout(function(){
			sid=setTimeout("jQuery(\"#mall_tip\").css(\"display\",\"none\")",5000);
		});
		
		

});


// Validation for special characters
function isValidText(str){

	var flag=false;
	var iChars = "!^+*|\:<>[]{}`\;@&$#%";	

	for (var i = 0; i < str.length; i++) {				
		if (iChars.indexOf(str.charAt(i)) != -1){	
			var flag=true;
		}
	}		
	
	return flag;
}

// validation to enter only alphabets
function isOnlySpecial(str){
	var flag=false;
	var iChars = "ABCDEFGHIJKLMNOPQRSTUVWXYSabcdefghijklmnopqrstuvwxyz0123456789";	
	for (var i = 0; i < str.length; i++) {				
		if (iChars.indexOf(str.charAt(i)) != -1){	
			var flag=true;
		}
	}		
	return flag;
}

/* Function to fadeout the alert message in popup */
function fadeOutMessage (uid) {
	jQuery("#invitesuccesspopup"+uid).fadeOut(3000);
}


/* Function to invite friends through AJAX; Dinesh; 30-July-09 */
function sendInvite (uid, event) {
	//Loading Message
	jQuery("#inviteText"+uid).html("Sending Invite... Please Wait!!!");
	jQuery("#inviteText"+uid).addClass("success_message");
	jQuery.ajax({
			type: "POST",	
			data :"friend_profile_id="+uid,
			url: baseurl+"invitefriends/sendinvite",
			async: false,
			cache: false,			
			success: function(msg){
				if (msg == "success") {
					jQuery("#inviteText"+uid).html("Invited");
					jQuery("#inviteText"+uid).addClass("success_message");
					jQuery("#invitesuccesspopup"+uid).css("top", event.pageY);
					jQuery("#invitesuccesspopup"+uid).show();
					fadeOutMessage(uid);
				} else {
					jQuery("#inviteText"+uid).html('<a href="javascript: void(0);" onclick="sendInvite('+uid+');">Invite</a>');
					jQuery("#inviteText"+uid).removeClass("success_message");
				}
			}  
	});	
	
	return false;
}

/* Function to toggle the invite friends popup tabs; Dinesh; 31-July-09 */
function changeDivInviteNewFriends (tab_id) {
	if (tab_id == "invite_virtualeshopping") {
		//hide/show tab contents
		jQuery('#invite_othernetworks').hide();
		jQuery('#invite_invitebymail').hide();
		jQuery('#invite_scheduledate').hide();
		jQuery('#invite_virtualeshopping').show();
		
		//enable/disable tab
		jQuery('#invite_virtualeshopping_tab_act').show();
		jQuery('#invite_virtualeshopping_tab_notact').hide();
		
		jQuery('#invite_othernetworks_tab_notact').show();
		jQuery('#invite_othernetworks_tab_act').hide();
		
		jQuery('#invite_invitebymail_tab_notact').show();
		jQuery('#invite_invitebymail_tab_act').hide();
		
		jQuery('#invite_scheduledate_tab_notact').show();
		jQuery('#invite_scheduledate_tab_act').hide();
		
		jQuery('#invite_virtualeshopping').show();
		
		// Clear the other networks values
		jQuery("#feon_other_mail_error_message").html('');
		jQuery("#hidden_feon_other_error_message").attr("style", "display:none");
		jQuery("#feon_email").val('');
		jQuery("#feon_password").val('');
		
		// See What You Send - Govind 14-08-09
		jQuery("#seewhatyousendthem_hide").attr("style", "display:none");
		jQuery(".seewhatyousendpopup").html('');

	} else if (tab_id == "invite_othernetworks") {
		//hide/show tab contents
		jQuery('#invite_virtualeshopping').hide();
		jQuery('#invite_invitebymail').hide();
		jQuery('#invite_scheduledate').hide();
		jQuery('#invite_othernetworks').show();
		
		//enable/disable tab
		jQuery('#invite_othernetworks_tab_act').show();
		jQuery('#invite_othernetworks_tab_notact').hide();

		jQuery('#invite_virtualeshopping_tab_notact').show();
		jQuery('#invite_virtualeshopping_tab_act').hide();
		
		jQuery('#invite_invitebymail_tab_notact').show();
		jQuery('#invite_invitebymail_tab_act').hide();
		
		jQuery('#invite_scheduledate_tab_notact').show();
		jQuery('#invite_scheduledate_tab_act').hide();
		
		jQuery('#invite_othernetworks').show();
		// Clear the other networks values
		jQuery("#feon_other_mail_error_message").html('');
		jQuery("#hidden_feon_other_error_message").attr("style", "display:none");
		jQuery("#feon_email").val('');
		jQuery("#feon_password").val('');
		// See What You Send - Govind 14-08-09
		jQuery("#seewhatyousendthem_hide").attr("style", "display:none");
		jQuery(".seewhatyousendpopup").html('');
	} else if (tab_id == "invite_invitebymail") {
		//hide/show tab contents
		jQuery('#invite_othernetworks').hide();
		jQuery('#invite_virtualeshopping').hide();
		jQuery('#invite_scheduledate').hide();
		jQuery('#invite_invitebymail').show();
		
		//enable/disable tab
		jQuery('#invite_invitebymail_tab_act').show();
		jQuery('#invite_invitebymail_tab_notact').hide();
		
		jQuery('#invite_othernetworks_tab_notact').show();
		jQuery('#invite_othernetworks_tab_act').hide();
		
		jQuery('#invite_virtualeshopping_tab_notact').show();
		jQuery('#invite_virtualeshopping_tab_act').hide();
		
		jQuery('#invite_scheduledate_tab_notact').show();
		jQuery('#invite_scheduledate_tab_act').hide();
		
		jQuery('#invite_invitebymail').show();
		// Clear the other networks values
		jQuery("#feon_other_mail_error_message").html('');
		jQuery("#hidden_feon_other_error_message").attr("style", "display:none");
		jQuery("#feon_email").val('');
		jQuery("#feon_password").val('');
		// See What You Send - Govind 14-08-09
		jQuery("#seewhatyousendthem_hide").attr("style", "display:none");
		jQuery(".seewhatyousendpopup").html('');
	} else if (tab_id == "invite_scheduledate") {
		//hide/show tab contents
		jQuery('#invite_othernetworks').hide();
		jQuery('#invite_invitebymail').hide();
		jQuery('#invite_virtualeshopping').hide();
		jQuery('#invite_scheduledate').show();
		
		//enable/disable tab
		jQuery('#invite_scheduledate_tab_act').show();
		jQuery('#invite_scheduledate_tab_notact').hide();
		
		jQuery('#invite_othernetworks_tab_notact').show();
		jQuery('#invite_othernetworks_tab_act').hide();
		
		jQuery('#invite_invitebymail_tab_notact').show();
		jQuery('#invite_invitebymail_tab_act').hide();
		
		jQuery('#invite_virtualeshopping_tab_notact').show();
		jQuery('#invite_virtualeshopping_tab_act').hide();
		
		jQuery('#invite_scheduledate').show();
		// Clear the other networks values
		jQuery("#feon_other_mail_error_message").html('');
		jQuery("#hidden_feon_other_error_message").attr("style", "display:none");
		jQuery("#feon_email").val('');
		jQuery("#feon_password").val('');
		// See What You Send - Govind 14-08-09
		jQuery("#seewhatyousendthem_hide").attr("style", "display:none");
		jQuery(".seewhatyousendpopup").html('');

		jQuery("#date_schedule").val('');
		jQuery("#sh_time").val('');
		jQuery("#sh_du").val("AM");
		jQuery("#sel_zone").val(1);
		jQuery("#AdditionalComments1").val("(maximum 200 characters with spaces.)");

		// Enable the fields
		jQuery("#date_schedule").attr("disabled", false);
		jQuery("#sh_time").attr("disabled", false);
		jQuery("#sh_du").attr("disabled", false);
		jQuery("#sel_zone").attr("disabled", false);
		jQuery(".tab4sch_date img").attr("style", "display:block");
		jQuery("#invitebyemailtomallerrors").html("");
		jQuery("#errSchedule").html("");
	}

	return false;
}


/* Function to delete a friend through AJAX; Gokul; 31-July-09 */
function deleteafriend(i, j, opt) {
	//Loading Message	
	switch(opt)
	{
		// delete alert box show box
		case "divshow" :{
			virtualE.showBox("delete_popup", "div-delete-friend", 240, 200);
			jQuery("#ival").val(i);
			jQuery("#jval").val(j);
			var friendname = jQuery("#friendname-"+i+"-"+j).val();
			jQuery("#delete-friend-name").html(friendname);
			break;
		}
		// delete function call	
		case "ok" :{
			var inew = jQuery("#ival").val();
			var jnew = jQuery("#jval").val();
			var friendid = jQuery("#friendid-"+inew+"-"+jnew).val();
			jQuery.ajax({
					type: "POST",	
					data :"friend_id="+friendid,
					url: baseurl+"friends/deleteafriend",
					async: false,
					cache: false,			
					success: function(msg){				
						if (msg == "success") {
							
							jQuery("#deletemsg").html("<font color='green'>Successfully Deleted</font>");
						}
						if (msg == "failure") {					
								jQuery("#deletemsg").html("<font color='green'>Not Deleted Successfully</font>");
							}
					}  
			});		
			window.location.reload();
			
			break;
		}
		// delete alert box hide box
		case "cancel" : { 
			virtualE.hidebox("div-delete-friend");
			break;
		}	
		
	}
	
	return false;
}

function isNumeric(value) {
  if (value == null || !value.toString().match(/^[-]?\d*\.?\d*$/)) return false;
  return true;
}
