if(!window.Controller)
{
	window.Controller = {};
}


dojo.require("dojo.widget.*");
dojo.require("dojo.lfx.*");
dojo.require("dojo.event.*");
dojo.require("dojo.html.*");

Controller.actions = {};

Controller.actions.validateLoginInfo = 
{
	type:"js",
		
	error_target:
	"floating_form_err_txt",
	
	js_handler:
	function()
	{
		//ActionCommons.hideDiv('availability_error');
		ActionCommons.showDiv('validation_msg');
		if(validateRegisterEmail(dojo.string.trim($('userlogin_email').value)) == false)
		{
			
			enableButton('linkUserLogin', 'SIGN IN', 'validateLoginInfo', true);
			throw "Please enter valid email address.";
		}
		if(validatePassword(dojo.string.trim($('userlogin_password').value)) == false)
		{
			enableButton('linkUserLogin', 'SIGN IN', 'validateLoginInfo', true);
			throw "Please enter a password";
		}
		// $('floating_form_err_txt').innerHTML='<b>Please wait...</b>';
		disableButton('linkUserLogin', 'wait...');
		executeAction('login');
		//enableButton('linkRegisteration', 'JOIN', 'addRegister', true);
	}
};


Controller.actions.login = 
{
	type:"dwr",
		
	arguments:
	["userlogin_email", "userlogin_password", "userlogin_autologin"],
	
	validators:
	[undefined, undefined, undefined],

	error_messages:
	["Enter Email", "Enter Password", ""],
	
	error_target:
	"floating_form_err_txt",
	
	dwr_handler:
	AdministrationHandler.login,

	dwr_callback:
	function(user)
	{  			
		if(user != null)
		{
	  		if(!user.error)
			{
			   
			    //$('floating_form_err_txt').style.visibility='visible';
				$('floating_form_err_txt').innerHTML='<b>Login Successful. Please wait....</b>';
				
				if(user.message != "")
				{
					//document.cookie = "wanelopp=" + user.message;
					var date = new Date();
					date.setTime(date.getTime() + 31536000000);
					document.cookie = "wanelopp=" + user.message + ";expires=" + date.toGMTString() + ";domain=wanelo.com";	
					
				}
				//Controller.executeAction("closeFloatingForm");
				window.location.reload();	
									
			}
			else
			{
				enableButton('linkUserLogin', 'SIGN IN', 'validateLoginInfo', true);
				/*var passwordfield = ActionCommons.getElement("userlogin_password");
				if(passwordfield != null)
				{
					passwordfield.value = "";
				}
				*/
				throw user.message;
	  		}
	  	}
		else
		{
			enableButton('linkUserLogin', 'SIGN IN', 'validateLoginInfo', true);
			throw "login error";
		}	
	}
};

Controller.actions.keepalive = 
{
	type:"dwr",
		
	dwr_handler:
	AdministrationHandler.keepAlive,

	dwr_callback:
	function()
	{  			
		clearInterval(setIntervalHolder);
	}
};

/*
Controller.actions.register = 
{
	type:"dwr",
		
	arguments:
	["registration_email", "registration_password", "registration_dispname","facebook_id","facebook_email"],
	
	validators:
	[dojo.validate.isEmailAddress, dojo.validate.isText, dojo.validate.isText,undefined,undefined],
	
	error_messages:
	["Enter Email", "Enter Password", "Display Name","",""],

	validator:
	function(args)
	{
		if(dojo.string.trim(args[1]) != dojo.string.trim(args[2]))
		{
			throw "Password Mismatch";
		}
	},
	
	
	error_target:
	"floating_form_err_txt",
	
	dwr_handler:
	AdministrationHandler.register,
	
	dwr_callback:
	function(message)
	{		  			    
	  	if(message == null)
		{
			//ActionCommons.refreshDojoDiv("floating_form", "registrationsuccess.action");
			executeAction('closeFloatingForm');
			var loc = window.location;
			loc.href = loc.protocol + "//" + loc.host + loc.pathname + "?contentaction=registrationsuccess";			
			//Controller.executeAction("showSubContent",  "registrationsuccess.action", true);
	  	}
		else
		{
	    	throw message;
	  	}
	}
};
*/

Controller.actions.validateRegistrationInfo = 
{
	type:"js",
		
	error_target:
	"floating_form_err_txt",
	
	js_handler:
	function()
	{
		//ActionCommons.hideDiv('availability_error');
		ActionCommons.showDiv('validation_msg');
		if(checkUserNameEntered(dojo.string.trim($('registration_dispname').value)) == false)
		{
			if(dojo.string.trim($('facebook_button_value').value=="NEXT"))
			{
				enableButton('linkRegisteration', 'CREATE ACCOUNT', 'validateRegistrationInfo', true);
			}
			else
			{
				enableButton('linkRegisteration', 'JOIN', 'validateRegistrationInfo', true);
			}
			throw "Please enter a display Name.";
		}
		if(validateRegisterEmail(dojo.string.trim($('registration_email').value)) == false)
		{
			if(dojo.string.trim($('facebook_button_value').value=="NEXT"))
			{
				enableButton('linkRegisteration', 'CREATE ACCOUNT', 'validateRegistrationInfo', true);
			}
			else
			{
				enableButton('linkRegisteration', 'JOIN', 'validateRegistrationInfo', true);
			}
			throw "Please enter valid email address.";
		}
		if(validatePassword(dojo.string.trim($('registration_password').value)) == false)
		{
			if(dojo.string.trim($('facebook_button_value').value=="NEXT"))
			{
				enableButton('linkRegisteration', 'CREATE ACCOUNT', 'validateRegistrationInfo', true);
			}
			else
			{
				enableButton('linkRegisteration', 'JOIN', 'validateRegistrationInfo', true);
			}
			throw "Please enter a password";
		}
		 
		// $('floating_form_err_txt').style.visibility='visible';
		 $('floating_form_err_txt').innerHTML='<b>Please wait...</b>';
		disableButton('linkRegisteration', 'wait...');
		executeAction('register');
		//enableButton('linkRegisteration', 'JOIN', 'addRegister', true);
	}
};

Controller.actions.register = 
{
	type:"dwr",
		
	arguments:
	["registration_email", "registration_password", "registration_dispname","facebook_id","facebook_email","username_change"],
	
	validators:
	[undefined, undefined, undefined,undefined,undefined,undefined],
	
	error_messages:
	["Enter Email", "Enter Password", "Display Name","","",""],
		
	error_target:
	"floating_form_err_txt",
	
	dwr_handler:
	AdministrationHandler.register,
	
	dwr_callback:
	function(message)
	{	
	  	var userId=parseInt(message);
	  	if(message!=null && userId >=0)
		{
			//ActionCommons.refreshDojoDiv("floating_form", "registrationsuccess.action");
			//executeAction('closeFloatingForm');
			var loc = window.location;
			//loc.href = loc.protocol + "//" + loc.host +"/index.action?contentaction=showbookmarklet&mode=registration";
			loc.href = loc.protocol + "//" + loc.host +"/index.action?contentaction=onboarduser";
			//loc.href = loc.protocol + "//" + loc.host + loc.pathname + "?contentaction=edituserprofile&userId="+userId+"&mode="+"registration";
			//loc.href = loc.protocol + "//" + loc.host + loc.pathname + "?contentaction=registrationsuccess";			
			//Controller.executeAction("showSubContent",  "registrationsuccess.action", true);
	  	}
		else
		{
			enableButton('linkRegisteration', 'CREATE ACCOUNT', 'validateRegistrationInfo', true);
	    	throw message;
	  	}
	}
};

Controller.actions.validatePasswordInfo = 
{
	type:"js",
		
	error_target:
	"floating_form_err_txt",
	
	js_handler:
	function()
	{
		
		if(validateRegisterEmail(dojo.string.trim($('sendpassword_email').value)) == false)
		{
			enableButton('linkPasswordInfo', 'SUBMIT', 'validatePasswordInfo', true);
			throw "Please enter a valid email address.";
		}
		
		disableButton('linkPasswordInfo', 'wait...');
		executeAction('sendPassword');
		//enableButton('linkRegisteration', 'JOIN', 'addRegister', true);
	}
};
Controller.actions.sendPassword = 
{
	type:"dwr",
		
	arguments:
	["sendpassword_email"],
	
	validators:
	[dojo.validate.isEmailAddress],
	
	error_messages:
	["Enter Email"],
	
	error_target:
	"floating_form_err_txt",
	
	dwr_handler:
	AdministrationHandler.sendPassword,
	
	dwr_callback:
	function(message)
	{		  			    
	  	if(message != null)
		{
			enableButton('linkPasswordInfo', 'SUBMIT', 'validatePasswordInfo', true);
	    	throw message;
	  	}
	}
};


Controller.actions.logout = 
{
	type:"dwr",
			
	dwr_handler:
	AdministrationHandler.logout,
	
	dwr_callback:
	function()
	{
		var date = new Date();
		date.setTime(date.getTime() - 1);
		document.cookie = "wanelopp=;expires=" + date.toGMTString();
		document.cookie = "wanelopp=;expires=" + date.toGMTString() + ";domain=wanelo.com";
		//if(FB) {
		//	FB.logout(function(response) {
  		//	// user is now logged out
		//	});
		//}	
		window.location.reload();		  			    
	}
};

Controller.actions.sortCollection =
{
	type:"js",
	
	js_handler:
	function(url)
	{
		var sel = ActionCommons.getElement("sortcollection");
		var sort = sel.options[sel.selectedIndex].value;
		url += "&sortingBy=" + sort;
		ActionCommons.refreshDojoDiv("mycollectionhome_listcollections", url, true);
	}
}

Controller.actions.resultperpagefr =
{
	type:"js",
	
	js_handler:
	function(div, url, elementId, textId)
	{
		var sel = ActionCommons.getElement(elementId);
		var number = sel.options[sel.selectedIndex].value;
		var numbertxt = ActionCommons.getElement(textId);
		numbertxt.value = number;
		ActionCommons.executeSearchfr(div, url);
	}
}

Controller.actions.searchViewChangedFr=
{
	type:"js",
	
	js_handler:
	function(div,url,elementId)
	{
		var sel = ActionCommons.getElement(elementId);
		var view = sel.options[sel.selectedIndex].value;
		var strView = "LIST";
		if(parseInt(view) == 1){
			strView = "GRID";
		}
		executeAction('searchviewfr', div, url, strView);
	}
}

Controller.actions.searchsortingfr =
{
	type:"js",
	
	js_handler:
	function(div,url,sorting)
	{
		var sortingtxt = ActionCommons.getElement("sorting_txt_fr");
		
		if(sortingtxt.value == "")
		{
			sortingtxt.value = 3;
		}

		var link = ActionCommons.getElement("sort_fr_" + sortingtxt.value);
		link.className = "";
		link.href = "javascript:executeAction('searchsortingfr','" + div + "','" + url + "'," + sortingtxt.value + ")";

		sortingtxt.value = sorting;
		
		var link = ActionCommons.getElement("sort_fr_" + sorting);
		link.className = "current_sortlink";
		link.href = "javascript:void(0)";

		ActionCommons.executeSearchfr(div, url.replace("+&+","+%26+"));
	}
}

Controller.actions.searchviewfr =
{
	type:"js",
	
	js_handler:
	function(div,url,view)
	{
		var viewtxt = ActionCommons.getElement("view_txt_fr");
		viewtxt.value = view;
		ActionCommons.executeSearchfr(div, url.replace("+&+","+%26+"));
		if(view=="GRID")
		{
			//ActionCommons.hideDiv("gridview_div_fr");
			//ActionCommons.showDiv("listview_div_fr");
			//ActionCommons.hideDiv("resultscount_select_fr_list");
			//ActionCommons.showDiv("resultscount_select_fr_grid");
		}
		else
		{
			//ActionCommons.hideDiv("listview_div_fr");
			//ActionCommons.showDiv("gridview_div_fr");
			//ActionCommons.hideDiv("resultscount_select_fr_grid");
			//ActionCommons.showDiv("resultscount_select_fr_list");
		}
	}
}

Controller.actions.searchpricefr=
{
	type:"js",
	
	js_handler:
	function(div,url)
	{
		ActionCommons.executeSearchfr(div, url);
	}
}

Controller.actions.resultperpageall=
{
	type:"js",
	
	js_handler:
	function(div,url,elementId,textId)
	{
		var sel = ActionCommons.getElement(elementId);
		var number = sel.options[sel.selectedIndex].value;
		var numbertxt = ActionCommons.getElement(textId);
		numbertxt.value=number;
		ActionCommons.executeSearchall(div, url);
	}
}

Controller.actions.searchViewChanged=
{
	type:"js",
	
	js_handler:
	function(div,url,elementId)
	{
		var sel = ActionCommons.getElement(elementId);
		var view = sel.options[sel.selectedIndex].value;
		var strView = "LIST";
		if(parseInt(view) == 1){
			strView = "GRID";
		}
		executeAction('searchviewall', div, url, strView);
	}
}

Controller.actions.sortproducts=
{
	type:"js",
	
	js_handler:
	function(div,url)
	{
		var sortingtxt = ActionCommons.getElement("sorting_txt_all");
		if(sortingtxt.value == "")
		{
			sortingtxt.value = 3;
		}
		var ddl = ActionCommons.getElement("ddlsortproducts");
		var sorting = ddl.options[ddl.selectedIndex].value;
		sortingtxt.value = sorting;
		ActionCommons.executeSearchall(div, url.replace("+&+","+%26+"));
	}
}

Controller.actions.filterbysupertagids_all=
{
	type:"js",
	
	js_handler:
	function(div,url, supertagtypeid, pagetype)
	{
		//changed on Dec 7, 2009 to include supertagtypeid in the query string
		var element;
		if(!pagetype || pagetype == 'undefined') {
			element  =  $('superTagTypeIds_all');
		}else {
			element  =  $('superTagTypeIds_fr');
		}
		
		if(element){
			if(element.value.length > 0){
				element.value = element.value + ',' ;
			}
			element.value = element.value + supertagtypeid;
			url += "&superTagTypeIds=" + element.value + "&sorting=5";
			ActionCommons.refreshDojoDiv(div, url.replace("+&+","+%26+"), true);
			return;
		}
		
		var sortingtxt = ActionCommons.getElement("sorting_txt_all");
		if(sortingtxt.value == "")
		{
			sortingtxt.value = 5;
		}
		
		
		var ddl = ActionCommons.getElement("ddlsortproducts");
		var sorting = ddl.options[ddl.selectedIndex].value;
		sortingtxt.value = sorting;
		ActionCommons.executeSearchall(div, url.replace("+&+","+%26+"));
	}
}

Controller.actions.showallsupertagsdiv=
{
	type:"js",
	
	js_handler:
	function(divId)
	{
		if(document.currentSuperTagDivId){
			if($(document.currentSuperTagDivId))
				ActionCommons.hideDiv(document.currentSuperTagDivId);
		}
		ActionCommons.showDiv(divId);
		document.currentSuperTagDivId = divId;
	}
}

Controller.actions.hideallsupertagsdiv=
{
	type:"js",
	
	js_handler:
	function(divId)
	{
		if($(divId))
			ActionCommons.hideDiv(divId);
		
		document.currentSuperTagDivId = null;
	}
}

Controller.actions.unselectsupertag=
{
	type:"js",
	
	js_handler:
	function(div, url, superTagId, pagetype)
	{
		//changed on Dec 7, 2009 to include supertagtypeid in the query string
		var element;
		if(!pagetype || pagetype == 'undefined') {
			element  =  $('superTagTypeIds_all');
		}else {
			element  =  $('superTagTypeIds_fr');
		}
		if(element){
			if(element.value.length > 0){
				var ar = element.value.split(",");
				var i = 0;
				var len = ar.length;
				if(ar[len - 1] == ""){
					len--;
				}
				for(i; i < len; i++){
					var fld = ar[i];
					if(parseInt(fld) == parseInt(superTagId)){
						ar.splice(i, 1);
						break;
					}
				}
				element.value = ar.join(',');
			}
			url += "&superTagTypeIds=" + element.value + "&sorting=5";
			ActionCommons.refreshDojoDiv(div, url.replace("+&+","+%26+"), true);
			return;
		}
		
	}
}
Controller.actions.searchsortingall=
{
	type:"js",
	
	js_handler:
	function(div,url,sorting)
	{
		var sortingtxt = ActionCommons.getElement("sorting_txt_all");
		
		if(sortingtxt.value == "")
		{
			sortingtxt.value = 3;
		}

		var link = ActionCommons.getElement("sort_all_" + sortingtxt.value);
		link.className = "";
		link.href = "javascript:executeAction('searchsortingall','" + div + "','" + url + "'," + sortingtxt.value + ")";

		sortingtxt.value = sorting;
		
		var link = ActionCommons.getElement("sort_all_" + sorting);
		link.className = "current_sortlink";
		link.href = "javascript:void(0)";
		
		ActionCommons.executeSearchall(div, url.replace("+&+","+%26+"));
	}
}

Controller.actions.searchviewall=
{
	type:"js",
	
	js_handler:
	function(div,url,view)
	{
		var viewtxt = ActionCommons.getElement("view_txt_all");
		viewtxt.value=view;
		ActionCommons.executeSearchall(div, url.replace("+&+","+%26+"));
		if(view=="GRID"){
			//ActionCommons.hideDiv("gridview_div_all");
			//ActionCommons.showDiv("listview_div_all");
			//ActionCommons.hideDiv("resultscount_select_all_list");
			//ActionCommons.showDiv("resultscount_select_all_grid");
		}else{
			//ActionCommons.hideDiv("listview_div_all");
			//ActionCommons.showDiv("gridview_div_all");
			//ActionCommons.hideDiv("resultscount_select_all_grid");
			//ActionCommons.showDiv("resultscount_select_all_list");
		}
	}
}
Controller.actions.searchpriceall=
{
	type:"js",
	
	js_handler:
	function(div,url)
	{
		Controller.executeAction("closeFloatingForm");
		ActionCommons.executeSearchall(div, url, true);
	}
}

Controller.actions.searchonlyreviewall=
{
	type:"js",
	
	js_handler:
	function(div,url,elementId)
	{
		var reviewcheckbox = ActionCommons.getElement("chk_reviewed");
		var reviewtxt = ActionCommons.getElement("onlyreview_txt_all");
		reviewtxt.value=reviewcheckbox.checked;
		ActionCommons.executeSearchall(div, url, true);
	}
}
Controller.actions.sortProduct=
{
	type:"js",
	
	js_handler:
	function(url)
	{
		var sel = ActionCommons.getElement("sortcollectionproducts");
		var sort = sel.options[sel.selectedIndex].value;
		url += "&sortingBy=" + sort;
		ActionCommons.refreshDojoDiv("collection_products", url, true);
	}
}

Controller.actions.showLoginbarForm = 
{
	type:"js",
			
	js_handler:
	function(url)
	{
		Controller.executeAction("showFloatingForm", url, undefined, "12em", "3.92em");
		if(url.indexOf('userlogin') >= 0 || url.indexOf('registration') >= 0){
			window.scrollTo(0, 0);
			//setTimeout ( "setFocusOnLoginForm()", 2000 );
		}
	}
}

Controller.actions.showFloatingFormRelative = 
{
	type:"js",
			
	js_handler:
	function(url, unescapeAMP)
	{
		var djevent = Controller.dojoEvent;
		//main replaced by topcontainer by sarvjeet on May 6, 2010
		var main = ActionCommons.getElement("topcontainer");
		
		var x = djevent.pageX - main.offsetLeft;
		var y = djevent.pageY - main.offsetTop;
		if(x + 424 > main.clientWidth)
		{
			x = main.clientWidth - 424;
		}

		if(y + 424 > main.clientHeight)
		{
			y = main.clientHeight - 424;
		}
		
		//added by Sarvjeet on April 6, 2010 to ensure that x and y are greater than zero
		if(x < 0)x = 0;
		if(y<0)y=0;

		Controller.executeAction("showFloatingForm", url, x + "px", undefined, y + "px", undefined, unescapeAMP);		
	}
};

Controller.actions.showFloatingFormCenter = 
{
	type:"js",
			
	js_handler:
	function(url, unescapeAMP)
	{
		var djevent = Controller.dojoEvent;
		//main replaced by topcontainer by sarvjeet on May 6, 2010
		var main = ActionCommons.getElement("topcontainer");
		
		var x = djevent.pageX - main.offsetLeft;
		var y = djevent.pageY - main.offsetTop;
		
		if(x + 424 > main.clientWidth)
		{
			x = main.clientWidth - 424;
		}

		if(y + 424 > main.clientHeight)
		{
			y = main.clientHeight - 424;
		}
		
		//added by Sarvjeet on April 6, 2010 to ensure that x and y are greater than zero
		if(x < 0)x = 0;
		if(y<0)y=0;

		x=-10000;
		//ActionCommons.refreshDojoDiv("floating_form", url, unescapeAMP);
		Controller.executeAction("showFloatingForm", url, x + "px", undefined, y + "px", undefined, unescapeAMP);		
	}
};

Controller.actions.showFloatingForm = 
{
	type:"js",
			
	js_handler:
	function(url, left, right, top, bottom, unescapeAMP)
	{
		var div = ActionCommons.getElement("floating_form");
		var style = div.style;
		style.left = style.right = style.top = style.bottom = "";
		if(left != undefined)
		{
			style.left = left;
		}
		
		if(right != undefined)
		{
			style.right = right;
		}

		if(top != undefined)
		{
			style.top = top;
		}
		
		if(bottom != undefined)
		{
			style.bottom = bottom;			
		}
		
		ActionCommons.showDiv("floating_form");
		ActionCommons.refreshDojoDiv("floating_form", url, unescapeAMP);
	}
};

Controller.actions.closeFloatingForm = 
{
	type:"js",
			
	js_handler:
	function()
	{
		ActionCommons.hideDiv("floating_form", true);
	}
};

Controller.actions.showSubContent = 
{
	type:"js",
	
	js_handler:
	function(url, unescapeAMP, unescape)
	{
		ActionCommons.refreshDojoDiv("contentarea_content", url, unescapeAMP, unescape);	
	}
};

Controller.actions.refreshDIVById = 
{
	type:"js",
	
	js_handler:
	function(divId, url, unescapeAMP, unescape, noScroll)
	{
		//added another parameter in the function by sarvjeet on May 6, 2010 so that 
		//if scrollTo is skipped if not needed. By default, windows will be scrolled
		//if the last parameter is not present
		Controller.executeAction("closeFloatingForm");
		ActionCommons.refreshDojoDiv(divId, url, unescapeAMP, unescape);	
		
		//added on Mar 10, 2010 by sarvjeet to set the scroll at the div being refreshed
		//if loop added on May 6, 2010
		if(!noScroll)
			window.scrollTo(0, findTop($(divId)));
		
		//added by sarvjeet on Feb 17, 2011 to track ajax based page loading
		if(pageTracker != null){
			pageTracker._trackPageview();
		}
	}
};

Controller.actions.upload = 
{
	type:"js",
	
	js_handler:
	function()
	{
		ActionCommons.showDiv("upload_progress");
		ActionCommons.hideDiv("upload_form");
		if($('upload_result_file').value=='addproduct_photo_hidden')
		{
			$('image_uploadbyurl_error').style.visibility='hidden';
		}	
		window.setTimeout("Controller.executeAction('refreshProgress')", 1000);
	}
};

Controller.actions.refreshProgress = 
{
	type:"dwr",

	dwr_handler:
	UploadMonitor.getUploadInfo,
	
	error_target:
	"upload_progress_text",
	
	dwr_callback:
	function(uploadInfo)
	{
		if(uploadInfo.complete)
		{
			if(uploadInfo.error)
			{
				throw uploadInfo.error;
			}
			else
			{
				var refresh = ActionCommons.getElement("upload_refresh");
				if(refresh.value != "")
				{
					if(refresh.value == "page")
					{
						window.location.reload();
						return;
					}else if (refresh.value == "redirect") {
						var loc = window.location;
						/*loc.href = loc.protocol + "//" + loc.host + loc.pathname + 
									"?contentaction=listcollectiondetails&userId=" + 
									ActionCommons.getElement("hdnUserId").value + "&id=" + ActionCommons.getElement("upload_form_collectionId").value;*/
						loc.href = loc.protocol + "//" + loc.host + "/" + ActionCommons.getElement("user_name").value + "/" + encodeURIComponent(ActionCommons.getElement("collection_name").value)+"-"+ActionCommons.getElement("upload_form_collectionId").value + "-g" + prettyUrlExtension;			
						return;
					}else if(refresh.value == "boardingpage")
					{
						//url="userphoto.action"
						//Controller.executeAction("onBoardingFilter",'onboard',url, true);	
						Controller.executeAction('onBoardingFilter', 'onboard', 'userphoto.action', true, 3);
						return;
					}
					ActionCommons.refreshDojoDiv(refresh.value);				
				}

				var resultFile = ActionCommons.getElement("upload_result_file");
				if(resultFile.value != "")
				{
					var target =  ActionCommons.getElement(resultFile.value);
					target.value = uploadInfo.fileName;
					showImage(uploadInfo.fileName, 'uploadedImageHolder');
					setSelectedImage($('uploadedImageHolder'));
				}

				var sourceFile = ActionCommons.getElement("upload_source_file");
				if(sourceFile.value != "")
				{
					var target =  ActionCommons.getElement(sourceFile.value);
					var file = ActionCommons.getElement("upload_file");
					target.value = file.value;
				}

				Controller.executeAction("closeFloatingForm");				
			}
		}
	
		var fill = ActionCommons.getElement("upload_progress_bar_fill");
		var bar = ActionCommons.getElement("upload_progress_bar");			
				  			    
		var progress = uploadInfo.percent;
			
		var text = ActionCommons.getElement("upload_progress_text");		
		fill.style.width = progress + "%";
		text.innerHTML = "upload in progress: " + progress + "%";

		window.setTimeout("Controller.executeAction('refreshProgress')", 1000);		
	}	
};

Controller.actions.addCollection = 
{
	type:"dwr",
		
	arguments:
	["addcollection_title", "addcollection_desc"], 
	
	validators:
	[dojo.validate.isText, validateCollectionText],
	
	error_messages:
	["Enter Collection Title", "Collection description is mandatory and limited to 1000 characters."],
	
	error_target:
	"floating_form_err_txt",
	
	dwr_handler:
	CollectionHandler.addCollection,
	
	dwr_callback:
	function(collection)
	{
		if(collection != null)
		{
	  		if(!collection.error)
			{
				var temp=ActionCommons.getElement("camefrom").value;
				var pId=ActionCommons.getElement("pId").value;
				var uId=ActionCommons.getElement("uId").value;
				var overstateId=ActionCommons.getElement("pr_overstate_id").value;
				if(temp==1){
					Controller.executeAction("closeFloatingForm");
					//alert(collection.productCollectionId);
					var element = ActionCommons.getElement("productcollectionid");
					if(element)
					{
						var opt = new Option(collection.collectionName, collection.productCollectionId, false, true);
						element.options.add(opt);
					}
					//ActionCommons.refreshDojoDiv("selectcollection_div");
				}else if (temp==2) {
					var element = ActionCommons.getElement("collectionId");
					if(element)
					{
						var opt = new Option(collection.collectionName, collection.productCollectionId, false, true);
						element.options.add(opt);
					}
					$('div_addcollection_title').style.display = 'none'; 
					//added by ashish for clearing error message after successfull submission
					var errorMsg=$('floating_form_err_txt');
					errorMsg.innerHTML='';
					
				}else if (temp==3) {
					Controller.executeAction("closeFloatingForm");
					url="usercollections.action?userId="+uId+"&productId="+pId+"&comeFrom="+temp;
					executeAction("showFloatingForm",url,undefined,"37.39em", "20.29em")
					
				}else if (temp==4) {
					Controller.executeAction("closeFloatingForm");
					url="usercollections.action?userId=" + uId + "&productId=" + pId + "&overStateIndex=" + overstateId + '&comeFrom=' + temp;
					var product_div = $('pr_' + overstateId);
					if(product_div){
						var left = product_div.offsetLeft + product_div.clientWidth + 'px';
						var top = product_div.offsetTop + product_div.clientHeight + 'px'; 
						executeAction("showFloatingForm",url,left,undefined, top);
					}else {
						executeAction("showFloatingForm",url,undefined,"37.39em", "20.29em");
					}
					//Controller.executeAction("showFloatingFormRelative", url,unescapeAMP);
				}else{
					Controller.executeAction("closeFloatingForm");
					//changed to goto collection detail page on 9/9/9
					//window.location.reload();
					var loc = window.location;
					//loc.href = loc.protocol + "//" + loc.host + loc.pathname + "?contentaction=listcollectiondetails&id=" + collection.productCollectionId + "&userId=" + collection.user.userId;
					var tempCollectionName;
					tempCollectionName=collection.collectionName;
					var intIndexOfMatch = tempCollectionName.indexOf("/");
					while (intIndexOfMatch != -1){
					  tempCollectionName = tempCollectionName.replace( "/", " ");
					  intIndexOfMatch = tempCollectionName.indexOf("/");
					}
					loc.href=loc.protocol + "//" + loc.host+ "/" + collection.user.userName + "/" + encodeURIComponent(tempCollectionName) + "-" + collection.productCollectionId + "-g" + prettyUrlExtension; 
				}
			}
			else
			{
				throw collection.message;
	  		}
	  	}
		else
		{
			throw "unable to create a new collection";
		}
	}
};

Controller.actions.validateReviewComment = 
{
	type:"js",
	
	error_target:
	"floating_form_err_txt",
	
	js_handler:
	function()
	{
		if(validateReviewCommentText(dojo.string.trim($('comment_text').value)) == false)
		{
			enableButton('submitcomment', 'submit', 'validateReviewComment', true);
			throw "Enter Comment.";
		}
		disableButton('submitcomment','Wait...');
		executeAction('addComment');
	}
};

Controller.actions.addComment = 
{
	type:"dwr",
		
	arguments:
	["review_id", "comment_text"], 
	
	validators:
	[undefined, undefined],
	
	error_messages:
	[undefined, "Enter Comment"],
	
	error_target:
	"floating_form_err_txt",
	
	dwr_handler:
	ReviewHandler.addComment,
	
	dwr_callback:
	function(message)
	{
		if(message!=null)
		{
			Controller.executeAction("closeFloatingForm");
			ActionCommons.refreshDojoDiv("productreviewhome_reviewcomments");
		}
		else
		{
			enableButton('submitcomment', 'submit', 'validateReviewComment', true);
		}
	}
};


Controller.actions.editCollection = 
{
	type:"dwr",
		
	arguments:
	["editcollection_id","editcollection_title", "editcollection_desc"], 
	
	validators:
	[dojo.validate.isText,dojo.validate.isText, validateCollectionText],
	
	error_messages:
	["Invalid Id","Enter Collection Title", "Collection description is mandatory and limited to 1000 characters."],
	
	error_target:
	"floating_form_err_txt",
	
	dwr_handler:
	CollectionHandler.editCollection,
	
	dwr_callback:
	function(collection)
	{
		if(collection != null)
		{
	  		if(!collection.error)
			{
				Controller.executeAction("closeFloatingForm");
				var loc = window.location;	
				var userId=$("user_id").value;
				var userName=$("user_name").value;
				//loc.href = loc.protocol + "//" + loc.host + loc.pathname + "?contentaction=listcollectiondetails&id="+collection.productCollectionId+"&userId="+userId+"&status=1";				
				//loc.href = loc.protocol + "//" + loc.host + loc.pathname;
				var temp;
				temp=collection.collectionName;
				var intIndexOfMatch = temp.indexOf("/");
				while (intIndexOfMatch != -1){
				  temp = temp.replace( "/", " ");
				  intIndexOfMatch = temp.indexOf("/");
				}
				loc.href=loc.protocol + "//" + loc.host+ "/" + userName + "/" + encodeURIComponent(temp) + "-" + collection.productCollectionId + "-g" + prettyUrlExtension; 
			}
			else
			{
				throw collection.message;
	  		}
	  	}
		else
		{
			throw "unable to edit the collection";
		}
	}
};

Controller.actions.validateAddProductToCollection = 
{
	type:"js",
	
	error_target:
	"floating_form_err_txt",
	
	js_handler:
	function()
	{
		if($('chkFacebook').checked)
				$('postToFacebook').value = 1;
			if($('chkTwitter').checked)
				$('postToTwitter').value = 1;
		disableButton('addProductToCollection','Wait...');
		executeAction('addProductToCollection');
	}
};

Controller.actions.addProductToCollection = 
{
	type:"dwr",
		
	arguments:
	["product_id","productcollectionid","review_text","hdn_rating","saveproduct_comment", "postToFacebook","postToTwitter","pr_overstate_id"], 
	
	validators:
	[undefined,undefined, validateReviewText, validateAddProductToCollection,undefined, undefined,undefined,undefined],
	
	error_messages:
	["","", "Enter Review Text", "Enter Review Rating","", "",""],
	
	error_target:
	"floating_form_err_txt",


	dwr_handler:
	ProductHandler.addProductToCollection,
	
	dwr_callback:
	function(product)
	{
		if(product != null)
		{
	  		if(!product.error)
			{

				if(product.message == 'noaction'){
					Controller.executeAction("closeFloatingForm");
					return;
				}
				//added by sarvjeet on august 30, 2009 to hide add review button, if
				//adding to product has also added the review too.
				var reviewText = "";
				if($('review_text')){
					reviewText = ActionCommons.getElement("review_text").value;
				}

				//added by sarvjeet on Oct 19, 2009 to refresh the page, if review or tags have been added
				//and the user is on product details page
				/*
				ashish added 13 aug
				if(ActionCommons.getElement("savediv_id").value == ""){
					if( (dojo.string.trim(reviewText)).length > 0 || (dojo.string.trim($('addproduct_tags').value)).length > 0){
						window.location.reload();
					}
				}
				
				*/


				if( (dojo.string.trim(reviewText)).length > 0){
					if($("productdetail_addreview")){
						ActionCommons.hideDiv("productdetail_addreview");
					}
					if($("review_section")){
						ActionCommons.hideDiv("review_section");
					}
				}
				//post to twitter, if allowed to post to twitter
				$('productTitle').value = product.productName;
				var overstate_Id=$('pr_overstate_id').value;
				if(overstate_Id && overstate_Id >= 0)
				{
					$('save_button_homepage_'+overstate_Id).className='blue_btn leftbtn';
					$('save_button_homepage_'+overstate_Id).innerHTML = '<a href="#">saved</a>'
					$('save_button_count_homepage_'+overstate_Id).className='save_num leftbtn';
					//commented by ashish on 13 april 2011
					$('save_button_count_homepage_'+overstate_Id).innerHTML ='<span><b>'+ product.message+'</b></span>';
					//$('save_button_count_homepage_'+overstate_Id).innerHTML ='<span><b>'+ product.numberSave+'</b></span>';
				}else{
					$('test_save_button').className='blue_btn txt_22 leftbtn';
					$('test_save_button').innerHTML = '<a href="#">SAVED</a>';
					//added by ashish on 23 sep 2010
					//commented by ashish on 13 april 2011
					var temp = $('save_product_counting').innerHTML;
					var append = "";
					if(temp.indexOf('saves') > -1 ){
						append = ' saves';
					}
					$('save_product_counting').innerHTML = product.message + append;
					//$('save_product_counting').innerHTML = product.numberSave + ' saves';
				}
				
				if($('postToTwitter').value == 1){
					sendToTwitter(product.productId, null);
				}else {
					//var temp=ActionCommons.getElement("savediv_id").value;
					//ActionCommons.getElement("floating_form_err_txt").innerHTML =  "Product has been added to your collection.";
					//Controller.executeAction("closeFloatingForm");
					//ActionCommons.hideDiv("savetomyproduct"+temp);
					//ActionCommons.showDiv("savedtomyproduct"+temp);
					//delayOverlayClose("Your product has been saved. Feels pretty good, doesn't it?");
					Controller.executeAction("closeFloatingForm");
				}
			}
			else
			{
				$('floating_form_err_txt').style.visibility='visible';
				enableButton('addProductToCollection', 'Done', 'validateAddProductToCollection', true);
				throw product.message;
	  		}
	  	}
		else
		{
			$('floating_form_err_txt').style.visibility='visible';
			enableButton('addProductToCollection', 'Done', 'validateAddProductToCollection', true);
			throw "unable to add product to the collection";
		}
	}
};

Controller.actions.showDeleteConfirmation = 
{
	type:"js",
	
	js_handler:
	function()
	{
		var ret = confirm('Do you really want to delete this collection?');
		if(ret){
			Controller.executeAction("deleteCollection");
		}
	}
};

Controller.actions.deleteCollection = 
{
	type:"dwr",
	
	authenticate:true,
		
	arguments:
	["collection_id"], 
	
	dwr_handler:
	CollectionHandler.deleteCollectionsById,
	
	dwr_callback:
	function(collection)
	{
		var msg = "";
		if(!collection.error) {
			//msg = "Collection has been deleted.";
			msg = 0;
		}else {
			msg = 1;
			//msg = "Collection could not be deleted. Collection may have products, discussions, comments or some other user might have saved it as favorite.";
		}
		var userid = dwr.util.getValue('user_id');
		var loc = window.location;	
		//loc.href = loc.protocol + "//" + loc.host + loc.pathname + "?contentaction=mycollectionshome&userId=" + userid + "&msg=" + msg;
		loc.href = loc.protocol + "//" + loc.host + "/index.action?contentaction=mycollectionshome&userId=" + userid + "&msg=" + msg;
	}
};

Controller.actions.rateReview = 
{
	type:"dwr",
		
	arguments:
	["review_id"], 
	
	dwr_handler:
	ReviewHandler.rateReview,
	
	dwr_callback:
	function(message)
	{		
		window.location.reload();
		//ActionCommons.refreshDojoDiv("productreviewhome_reviewdetail");
	}
};

Controller.actions.addMessage = 
{
	type:"js",
		
	error_target:
	"floating_form_err_txt",
	
	js_handler:
	function()
	{
		var checkFollow=$("checkFollowedCapsValue").value;
		var uId=$("sm_hdn_userid_to").value;
		if(checkFollow == 0)
		{
			disableButton('lnkFollowTopMember_'+uId, 'wait...');
		}
		else
		{
			disableButton('lnkFollowTopMember_'+uId, 'wait...');
		}	
		executeAction('saveMessage');
	}
};

Controller.actions.saveMessage = 
{
	type:"dwr",
		
	arguments:
	["sm_hdn_previousmessageid", "sm_hdn_messagetype","sm_hdn_userid_to", "sm_hdn_messagestatus", "sm_hdn_messagetitle", "sendmessage_body"], 
	
	validators:
	[undefined, dojo.validate.isText,dojo.validate.isText, dojo.validate.isText, dojo.validate.isText,dojo.validate.isText],
	
	error_messages:
	["", "Invalid Message Type","Enter Message Recipient", "Invalid Message Status", "Invalid Message Title", "Invalid Message Content"],
	
	error_target:
	"floating_form_err_txt",
	
	dwr_handler:
	MessageHandler.addMessage,
	
	dwr_callback:
	function(message)
	{
		if(message != null)
		{
	  		if(!message.error)
			{
				//ActionCommons.showDiv("sm_success_msg");
				//ActionCommons.hideDiv("sm_form");
				//ActionCommons.hideDiv("floating_form_header");
				//var element = $("sm_hdn_previousmessageid");
				//if(element){
					//if(element.value.length > 0){
					//	window.location.reload();
					//}
				//}
			
				var uId=$("sm_hdn_userid_to").value;
				var checkFollow=$("checkFollowedCapsValue").value;
				if(checkFollow == 0)
				{
					//$('useraddfriends_'+uId).className='useraddfriends';
					//$('useraddfriends_'+uId).innerHTML='<div class="blue_btn_inactive"><span><b>followed</b></span></div>';
					//$('useraddfriends_'+uId).className='blue_btn center_blue_btns';
					$('lnkFollowTopMember_'+uId).innerHTML='unfollow';
					$('lnkFollowTopMember_'+uId).onclick=function(e){$('sm_hdn_userid_to').value=uId;executeAction('validateRemoveFollower');};
				}
				else
				{	
					//$('useraddfriends_'+uId).className='useraddfriends';
					//$('useraddfriends_'+uId).innerHTML='<div class="blue_btn_inactive"><span><b>FOLLOWED</b></span></div>';
					//$('useraddfriends_'+uId).className='blue_btn center_blue_btns';
					$('lnkFollowTopMember_'+uId).innerHTML='UNFOLLOW';
					$('lnkFollowTopMember_'+uId).onclick=function(e){executeAction('validateRemoveFollower');};
				}	
			}
			else
			{	
				var checkFollow=$("checkFollowedCapsValue").value;
				var uId=$("sm_hdn_userid_to").value;
				if(checkFollow == 0)
				{
					$('floating_form_err_txt_'+uId).style.visibility='visible';
					$('useraddfriends_'+uId).style.visibility='hidden';
					$('floating_form_err_txt_'+uId).className='usererror_msg';
					$('floating_form_err_txt_'+uId).innerHTML='<b>'+message.message+'</b>';
				}
				else
				{
					$('floating_form_err_txt_'+uId).style.visibility='visible';
					$('useraddfriends_'+uId).style.visibility='hidden';
					$('floating_form_err_txt_'+uId).className='usererror_msg';
					$('floating_form_err_txt_'+uId).innerHTML='<b>'+message.message+'</b>';
					//throw message.message;
				}	
			 
	  		}
	  	}
		else
		{
				var uId=$("sm_hdn_userid_to").value;
				var checkFollow=$("checkFollowedCapsValue").value;
				if(checkFollow == 0)
				{
					$('floating_form_err_txt_'+uId).style.visibility='visible';
					$('useraddfriends_'+uId).style.visibility='hidden';
					$('floating_form_err_txt_'+uId).className='useraddfriends';
					$('floating_form_err_txt_'+uId).innerHTML='<b>unable to send the message</b>';
				}
				else
				{
					$('floating_form_err_txt_'+uId).style.visibility='visible';
					$('useraddfriends_'+uId).style.visibility='hidden';
					$('floating_form_err_txt_'+uId).className='useraddfriends';
					$('floating_form_err_txt_'+uId).innerHTML='<b>unable to send the message</b>';	
					//throw "unable to send the message"
				}	
		}
	}
};

Controller.actions.addReview = 
{
	type:"dwr",
		
	arguments:
	["product_id","collectionId","review_text","hdn_rating_review","addreview_saveornot0", "addproduct_tags"], 
	
	validators:
	[undefined, undefined, isReviewText,isReviewRated,undefined, undefined],
	
	error_messages:
	["", "", "Enter Review Text", "Enter Review Rating", "", ""],
	
	error_target:
	"imagepost_failure",
	
	dwr_handler:
	ProductHandler.addReview,
	
	dwr_callback:
	function(message)
	{
		dwr.util.setValue("imagepost_failure", "");
				  			    
	  	if(message != "")
		{
	    	throw message;
	  	}
		
		var temp=ActionCommons.getElement("reviewdiv_id").value;
		var productName=ActionCommons.getElement("product_name").value;
		var categoryName=ActionCommons.getElement("category_name").value
		if(temp==-2){
			var userid = ActionCommons.getElement("userId").value;
			var collectionId = ActionCommons.getElement("collectionId").value;
			var collectionname = ActionCommons.getElement("collection_name").value;
			var success = ActionCommons.getElement("success").value;
			var loc = window.location;	
			//loc.href = loc.protocol + "//" + loc.host + loc.pathname + "?contentaction=listcollectiondetails&id=" + collectionId + "&userId=" + userid + "&success=" + success;			
			loc.href = loc.protocol + "//" + loc.host + "/collection/" + collectionId;
		}else{
			var productId =  ActionCommons.getElement("product_id").value;
			Controller.executeAction("closeFloatingForm");		
			if(temp==-1){
				var loc = window.location;	
				//loc.href = loc.protocol + "//" + loc.host + loc.pathname + "?contentaction=productdetails&productId=" + productId;
				var tempProductName;
				tempProductName=productName;
				var intIndexOfMatch = tempProductName.indexOf("/");
				while (intIndexOfMatch != -1){
				 tempProductName = tempProductName.replace( "/", " ");
				  intIndexOfMatch = tempProductName.indexOf("/");
				}
				if(categoryName != 'all-products')
				{			
				  loc.href = loc.protocol + "//" + loc.host +"/" + categoryName + "/" + encodeURIComponent(tempProductName) + "-" + productId + prettyUrlExtension;
				}else{
				  loc.href = loc.protocol + "//" + loc.host +"/" + 'all-products' + "/" + encodeURIComponent(tempProductName) + "-" + productId + prettyUrlExtension;
				}
				//window.location.reload();
			}else{
				ActionCommons.refreshDojoDiv("all_listing_main");
			}
		}
	}
};

Controller.actions.editReview = 
{
	type:"dwr",
		
	arguments:
	["reviewid","review_text","hdn_rating", "hdn_previousrating"], 
	
	validators:
	[undefined, dojo.validate.isText,undefined, undefined],
	
	error_messages:
	["", "Enter Review Text", "", ""],
	
	error_target:
	"floating_form_err_txt",
	
	dwr_handler:
	ProductHandler.editReview,
	
	dwr_callback:
	function(message)
	{
		dwr.util.setValue("floating_form_err_txt", "");
				  			    
	  	if(message != "")
		{
	    	throw message;
	  	}else {
	  		//alert ("The review has been updated.");
			var temp=ActionCommons.getElement("reviewdiv_id").value;
			if(temp==-2){
				var userid = ActionCommons.getElement("userId").value;
				var productId = ActionCommons.getElement("productId").value;
				var reviewid = ActionCommons.getElement("reviewid").value;
				var loc = window.location;	
				Controller.executeAction("closeFloatingForm");
				loc.href = loc.protocol + "//" + loc.host + loc.pathname + "?contentaction=productreviewhome&productId=" + productId + "&userId=" + userid + "&reviewId=" + reviewid;			
			}else if (temp == -1){
				var userid = ActionCommons.getElement("userId").value;
				var loc = window.location;	
				Controller.executeAction("closeFloatingForm");
				loc.href = loc.protocol + "//" + loc.host + loc.pathname + "?contentaction=userproductreviews&userId=" + userid;			
			}else {
				window.location.reload();
			}	  		
	  		
	  	}
		
		/*
		var temp=ActionCommons.getElement("reviewdiv_id").value;
		if(temp==-2){
			var userid = ActionCommons.getElement("userId").value;
			var collectionId = ActionCommons.getElement("collectionId").value;
			var collectionname = ActionCommons.getElement("collection_name").value;
			var success = ActionCommons.getElement("success").value;
			var loc = window.location;	
			loc.href = loc.protocol + "//" + loc.host + loc.pathname + "?contentaction=listcollectiondetails&id=" + collectionId + "&userId=" + userid + "&success=" + success;			
		}else{
			Controller.executeAction("closeFloatingForm");		
			if(temp==-1){
				window.location.reload();
			}else{
				ActionCommons.refreshDojoDiv("all_listing_main");
			}
		}
		*/
	}
};


Controller.actions.updateInvite = 
{
	type:"dwr",
		
	dwr_handler:
	MessageHandler.setMessageStatus,
	
	dwr_callback:
	function(message)
	{
	  	if(message.error)
		{   
	    	if(message.messageId > 0) {
	    		if($('error_msg_' + message.messageId)) {
	    			$('error_msg_' + message.messageId).innerHTML = message.message;
	    		}
	    	}
	  	}else{
			//hack put in by sarvjeet
			//hack modified by sarvjeet on apr 7, 2010
			//var div = dojo.widget.byId("userhomepage_friendalerts");
			var div = dojo.widget.byId('pagedproductactivities');
			var url = "recentpendinginvites.action?callingpage=1&userId=";
			url += message.to.userId;
			if(!div){
				div = dojo.widget.byId("contentarea_content");
				div.href = url;
				ActionCommons.refreshDojoDiv("contentarea_content");
			}else {
				div.href = url + '&subcontent=1';
				ActionCommons.refreshDojoDiv("pagedproductactivities");
			}
		//	var temp = $("alert_success_msg");
			
			if(message.messageStatus.text == 'accept'){
				
			//	if(temp)temp.innerHTML = "<span>"+message.from.userName + " has been added to your friend list.</span>";
				
			}else {
			
			//	if(temp)temp.innerHTML = "";
			}
			//section added to update alertcount on the login bar
			var alertCount = message.message;
			
			if(message.message){
				var val = parseInt(message.message);
				if(val >= 0){
					var element = $("alertCount");
					if(element){
						//element.innerHTML = "(" + val + " alerts)";
						element.innerHTML = val;
					}
				}else {
					var element = $("alertCount");
					if(element){
						element.parentNode.removeChild(element);
					}
				}
				
			}
	  	}
	  	
	}
};

Controller.actions.submitSearchForm = 
{
	type:"js",
	
	js_handler:
	function(frm, txt, stat)
	{
		ActionCommons.validateSearchForm(frm, txt, stat)
		//if(!ActionCommons.validateSearchForm(frm, txt, stat))
		//{
			//throw "Enter Search String";
		//}
        //var searchfrm = document[frm];
		//var searchtxt = searchfrm[txt];
		//var loc = window.location;
		//loc.href = loc.protocol + "//" + loc.host + "/" + 'search/' + dojo.string.trim(searchtxt.value) + prettyUrlExtension; 
		//document[frm].submit();	
	}
};

Controller.actions.submitAddProductForm =
{
    type:"js",
   
    js_handler:
    function(frm, txt, stat)
    {
        var searchfrm = document[frm];
        var tbx = searchfrm[txt].value;
        //var tbx_length=tbx.trim().length;
        var tbx_length=dojo.string.trim(tbx).length;
        var tbx_subvalue=tbx.substring(tbx_length - 4 ,tbx_length);
        var invalidUrl = !checkValidUrl(tbx);
        var hdn_userId = document.getElementById('hdnUserId');
        if(hdn_userId.value.length <= 0) {
            executeAction('showLoginbarForm', 'userlogin.action');
            return false;
        }
        if(tbx_subvalue == ".com" || invalidUrl)
		{
			var url = "addproductoverlay.action?searchString="+tbx;
			if(invalidUrl) url+= "&msg=1";
			Controller.executeAction("showFloatingForm", url,undefined,"31.39em", "16.92em");
		}
		else if(ActionCommons.validateAddProductForm(frm, txt, stat) == true)
		{
			document[frm].submit();
		}
	}
};

Controller.actions.validateEditUserInfo = 
{
	type:"js",
		
	error_target:
	"floating_form_err_txt",
	
	js_handler:
	function()
	{
		//ActionCommons.hideDiv('availability_error');
		if(checkUserNameEntered(dojo.string.trim($('registration_dispname').value)) == false)
		{
			throw "Please enter a user name.";
		}
		executeAction('edituserprofile');
	}
};

// updated by Prashant on 2 JAN, 2012 to remove users favourite stores.
/*Controller.actions.edituserprofile = 
{
	type:"dwr",
		
	arguments:
	["registration_dispname","user_realname","user_email","user_shoppingFav","user_storesFav1","user_storesFav2","user_storesFav3","user_storesFav4","user_storesFav5","user_storesFav6","user_interests","user_location","user_aboutme","user_MySpace","user_Facebook","user_YouTube","user_Twitter","user_blog","user_bussiness","user_other","subscribe_email"],
	
	validators:
	[dojo.validate.isText,"",dojo.validate.isEmailAddress,validateShoppingFavoritesText,undefined,undefined,undefined,undefined,undefined,undefined,validateInterestsText,undefined,validateAboutMeText,checkValidUrl,checkValidUrl,checkValidUrl,checkValidUrl,checkValidUrl,checkValidUrl,checkValidUrl,undefined],

	error_messages:
	["Enter name","","Enter Email","Valid Shopping","","","","","","","Invalid Interests","", "Valid AboutMe","Valid Url","Valid Url","Valid Url","Valid Url","Valid Url","Valid Url","Valid Url",""],
	
	error_target:
	"floating_form_err_txt",
	
	dwr_handler:
	AdministrationHandler.editUser,

	dwr_callback:
	function(user)
	{  			
		if(user != null)
		{
	  		if(!user.error)
			{
				ActionCommons.hideDiv('availability_error');
				var loc = window.location;
				$('homepage_profileurl').href=loc.protocol + "//" + loc.host+"/"+user.userName;
				throw "profile edit successful";
			}
			else
			{
				throw user.message;
	  		}
	  	}
		else
		{
			throw "login error.";
		}	
	}
};*/



Controller.actions.edituserprofile = 
{
	type:"dwr",
		
	arguments:
	["registration_dispname","user_realname","user_email","user_shoppingFav","user_interests","user_location","user_aboutme","user_MySpace","user_Facebook","user_YouTube","user_Twitter","user_blog","user_bussiness","user_other","subscribe_email"],
	
	validators:
	[dojo.validate.isText,"",dojo.validate.isEmailAddress,validateShoppingFavoritesText,validateInterestsText,undefined,validateAboutMeText,checkValidUrl,checkValidUrl,checkValidUrl,checkValidUrl,checkValidUrl,checkValidUrl,checkValidUrl,undefined],

	error_messages:
	["Enter name","","Enter Email","Valid Shopping","Invalid Interests","", "Valid AboutMe","Valid Url","Valid Url","Valid Url","Valid Url","Valid Url","Valid Url","Valid Url",""],
	
	error_target:
	"floating_form_err_txt",
	
	dwr_handler:
	AdministrationHandler.editUser,

	dwr_callback:
	function(user)
	{  			
		if(user != null)
		{
	  		if(!user.error)
			{
				ActionCommons.hideDiv('availability_error');
				var loc = window.location;
				$('homepage_profileurl').href=loc.protocol + "//" + loc.host+"/"+user.userName;
				throw "profile edit successful";
			}
			else
			{
				throw user.message;
	  		}
	  	}
		else
		{
			throw "login error.";
		}	
	}
};

Controller.actions.changepassword = 
{
	type:"dwr",
		
	arguments:
	["user_id", "old_password","new_password","confirm_password"],
	
	validators:
	[undefined,dojo.validate.isText,dojo.validate.isText, dojo.validate.isText],
	
	validator:
	function(args)
	{
		if(dojo.string.trim(args[2]) != dojo.string.trim(args[3]))
		{
			throw "Password Mismatch";
		}
	},
	
	error_messages:
	["","Enter old password","Enter new password", "Confirm Password"],
	
	error_target:
	"floating_form_err_txt",
	
	dwr_handler:
	AdministrationHandler.changePassword,

	dwr_callback:
	function(message)
	{  			
		if(message == null)
		{
	  			delayOverlayPassword("Your password has been changed successfully.");
				//Controller.executeAction("closeFloatingForm");
		}
		else
		{
			throw message;
		}	
	}
};

Controller.actions.sendInvite = 
{
	type:"dwr",
		
	arguments:
	["invite_user_email", "email_txtbx","invite_body"],
	
	validators:
	[undefined,dojo.validate.isText,dojo.validate.isText],

	error_messages:
	["","Enter email addresses","Enter Email", "","","",""],
	
	error_target:
	"floating_form_err_txt",
	
	dwr_handler:
	AdministrationHandler.editUser,

	dwr_callback:
	function(user)
	{  			
		if(user != null)
		{
	  		if(!user.error)
			{
				throw "profile edit successful";
			}
			else
			{
				throw user.message;
	  		}
	  	}
		else
		{
			throw "login error.";
		}	
	}
};

Controller.actions.validateInvitationInfo = 
{
	type:"js",
		
	error_target:
	"floating_form_err_txt",
	
	js_handler:
	function()
	{
		
		if(validateEmailArray(dojo.string.trim($('email_txtbx').value)) == false)
		{
			enableButton('linkEmailArrayInfo', 'SEND', 'validateInvitationInfo', true);
			throw "Enter valid Email(s).";
		}
		
		disableButton('linkEmailArrayInfo', 'wait...');
		executeAction('sendInvitation');
		//enableButton('linkRegisteration', 'JOIN', 'addRegister', true);
	}
};

Controller.actions.sendInvitation = 
{
	type:"dwr",
		
	arguments:
	["email_txtbx", "invite_body"],
	
	validators:
	[undefined, undefined],
	
	error_messages:
	["Enter valid Email(s)", ""],

	error_target:
	"floating_form_err_txt",
	
	dwr_handler:
	AdministrationHandler.sendInvite,
	
	dwr_callback:
	function(message)
	{		  			    
	  	
	  	if(message)
	  	{
	  		var element;
	  		//element = $("sm_success_msg");
	  		
	  		//if(element)
	  		//{
	  		//	element.innerHTML = message;
	  		//}
	  		element = $("email_txtbx");
	  		if(element)
	  		{
	  			element.value = "";
	  		}
	  		element = $("floating_form_err_txt");
	  		$('floating_form_err_txt').style.visibility='visible';
	  		if(element)
	  		{
	  			element.innerHTML = message;
	  		}
	  		enableButton('linkEmailArrayInfo', 'SEND', 'validateInvitationInfo', true);
	  	}
	  	//commented by sarvjeet on aug 12, 2008
	  	//throw message;
	}
};

Controller.actions.sendInvitationDirect = 
{
	type:"dwr",
	
	authenticate:true,
		
	dwr_handler:
	MessageHandler.sendInvite,
	
	dwr_callback:
	function(message)
	{		
		if(message == "")
		{  			    
	  		ActionCommons.refreshDojoDiv("usercontactslist_div");
	  	}
	}
};

Controller.actions.addtofriend = 
{
	type:"dwr",
		
	authenticate:true,
		
	dwr_handler:
	MessageHandler.addToFriend,
	
	dwr_callback:
	function(message)
	{
		if(message==null){  			    
	  		ActionCommons.refreshDojoDiv("usercontactslist_div");
	  	}
	}
};

Controller.actions.addselectedfriend = 
{
	type:"dwr",
		
	authenticate:true,
		
	dwr_handler:
	MessageHandler.addSelectedFriend,
	
	dwr_callback:
	function(message)
	{
		if(message==""){
			Controller.executeAction("showFloatingForm", "addfriendconfirmation.action", undefined);
		}
	}
};

Controller.actions.addallfriend = 
{
	type:"js",
	
	js_handler:
	function(selected)
	{
		var totalUser = ActionCommons.getElement("totalUser").value;
		var args = new Array();
		for(var i=0;i<totalUser;i++){
			var checkbox=ActionCommons.getElement("chk_"+i);
			if(selected){
				if(checkbox.checked){
					var userid=checkbox.value;
					args.push(userid);
				}
			}else{
				checkbox.checked=true;
				var userid=checkbox.value;
				args.push(userid);
			}
		}	
		Controller.executeAction("addselectedfriend",args);
	}
};

Controller.actions.authenticate = 
{
	type:"dwr",
		
	dwr_handler:
	AdministrationHandler.isSessionActive,
	
	dwr_callback:
	function(user)
	{	
		if(Controller.execActionArgs != undefined)
		{
			if(user.message == "")
			{
				Controller.executeAction.apply(Controller, Controller.execActionArgs);	
			}
			else
			{
				Controller.execActionArgs = undefined;
				Controller.executeAction("showLoginbarForm", "userlogin.action");
			}
		}
	}
};
/*
Controller.actions.addProductViaUrl = 
{
	type:"dwr",
		
	arguments:
	["addproduct_title", "addproduct_desc","addproduct_price","choosephoto_hidden","addproduct_photo_hidden","collectionId","product_url", "categoryId", "addproduct_tags"], 
	
	validators:
	[dojo.validate.isText, undefined,dojo.validate.isText,  undefined, undefined, undefined, undefined, dojo.validate.isText, dojo.validate.isText],
	
	error_messages:
	["Enter Product Name", "Enter Product Description","Enter Product Minimum Price","","","","", "Please select a category", "Please enter tags separated by comma"],
	
	error_target:
	"addproduct_err_text",
	
	dwr_handler:
	ProductHandler.addProductViaUrl,
	
	dwr_callback:
	function(product)
	{
		if(product.error)
		{
	    	throw product.message;
	  	}else{
	  		var collection=ActionCommons.getElement("collectionId");
	  		var collectionId=collection.options[collection.selectedIndex].value;
	  		var collectionName=collection.options[collection.selectedIndex].text;
	  		Controller.executeAction("showSubContent",  "addproductreview.action?productid="+product.productId+"&amp;product="+product.productName+"&amp;collectionId="+collectionId+"&amp;collectionName="+collectionName, true);
	  	}
	}
};

*/


Controller.actions.addProductAndReviewViaUrl = 
{
	type:"dwr",
		
	arguments:
	["productTitle", "productDescription","price","choosePhoto","uploadPhoto","collectionId","productUrl", "categoryId", "tags", "reviewText", "reviewRating", "noReview", "productId","displayUrl", "imageType", "imageUploadByUrl","productComment", "postToFacebook"], 
	
	error_target:
	"err_text",
	
	dwr_handler:
	ProductHandler.addProductAndReviewViaUrl,
	
	dwr_callback:
	function(product)
	{
		if(product.error)
		{
	    	var anc = $('btnSaveTop');
	    	if(anc){
	    		anc.innerHTML = 'Failed.';
	    	}
	    	anc = $('btnSaveBottom');
	    	if(anc){
	    		anc.innerHTML = 'Failed.';
	    	}
	    	ActionCommons.hideDiv('posting_image');
	    	throw product.message;
	  	}else{
	  		var element = $("productId");
	  		if(element) {
	  			var pId = parseInt(element.value);
	  			if(pId > 0) {
	  				var loc = window.location;	
	  				var url = '?contentaction=productdetails&productId=' + pId + '&p1=0';
					loc.href = loc.protocol + "//" + loc.host + loc.pathname +  url; 
					//loc.href = loc.protocol + "//" + loc.host +"/product/"+pId;
	  			}else {
			  		//added by sarvjeet on Oct 22, 2010
			  		var productId = product.productId;
			  		var collectionId = $("collectionId").value;
			  		var userId = $("userId").value;
			  		var collectionUrl = "listcollectiondetails.action?success=1&amp;id=" + collectionId + "&amp;userId=" + userId + "&mymenu=yes";
			  		
			  		//alert(productId);
			  		var msg = $('productComment').value;
			  		if(msg == "it's optional...") {
			  			msg = "";
			  		}
			  		if(false && $('postToFacebook').value == 1) {
					  	$('err_text').innerHTML = "Posting on facebook....";
						var publish = {
						  method: 'stream.publish',
						  message: msg,
						  attachment: {
						    name: product.productName,
						    caption: '', //'http://wanelo.com/index.action?contentaction=productdetails&productId='+product.productId,
						    description: (
						      $('userName').value + ' just bookmarked ' + product.productName + ' on wanelo'
						    ),
						    href: 'http://wanelo.com/index.action?contentaction=productdetails&productId='+product.productId,
						    media: [
						      {
						        type: 'image',
						        href: 'http://wanelo.com/index.action?contentaction=productdetails&productId='+product.productId,
						        src: 'http://wanelo.com/resources/upload/' + product.photos[0].photoUrl
						      }
						    ]
						  },
						  action_links: [
						    { text: $('userName').value + ' on wanelo', href: 'http://wanelo.com/index.action?contentaction=profile&userId=' + $('currentUserId').value }
						  ],
						  user_prompt_message: 'bookmark your products on wanelo'
						};
						
						FB.api(publish, function(response){
							if(response == null){
							  	$('err_text').innerHTML = "Posting to facebook failed...";
							}else {
							  	$('err_text').innerHTML = "Successfully posted to facebook....";
							}
					  		sendToTwitter(product.productId, collectionUrl);
						});					  	
			  		}else {
			  			sendToTwitter(product.productId,collectionUrl);
			  		}
	  			}
	  		}
	  		else {
		  		Controller.executeAction("showSubContent", collectionUrl, true);
	  		}
	  	}
	}
};


Controller.actions.showReviewPage = 
{
	type:"js",
		
	arguments:
	["addproduct_title", "addproduct_desc","addproduct_price","choosephoto_hidden","addproduct_photo_hidden","collectionId","product_url", "categoryId", "addproduct_tags","addproduct_comment"], 
	
	validators:
	[checkProductTitle, undefined, undefined,  undefined, undefined, undefined, undefined, undefined, undefined,undefined],
	
	error_messages:
	["Enter a product title.", "Enter Product Description","","","","","", "Please select a category", "Please enter tags separated by comma",""],
	
	error_target:
	"addproduct_err_text",
	
	js_handler:
	function()
	{
  		//var f = { maxlength:1000};
  		
  		//if(!dojo.validate.isText($('addproduct_desc').value, f)){
  		//	$('addproduct_err_text').innerHTML = "Please reduce the product description to 1000 characters";
  		//	return;
  		//}
  		if(!dojo.validate.isText($('choosephoto_hidden').value) && !dojo.validate.isText($('addproduct_photo_hidden').value) && !dojo.validate.isText($('addproduct_photobyurl_hidden').value)){
  			$('addproduct_err_text').innerHTML = "Choose or upload at least one product image!";
  			$('addproduct_err_text').style.visibility = 'visible';
  			return;
  		}
  		
  		
  		
  		
  		
  		var collection=ActionCommons.getElement("productcollectionid");
  		var collectionId=collection.options[collection.selectedIndex].value;
  		var collectionName=collection.options[collection.selectedIndex].text;
  		var cat = $("category");
  		if(cat) {
	  		var topCategoryId = cat.options[cat.selectedIndex].value;
  		}else {
	  		var topCategoryId = -1;
  		}
  		var temp = parseInt($('categoryId').value);
  		if(isNaN(temp) || temp <= 0){
  			$('addproduct_err_text').innerHTML = "Please select a category!";
  			$('addproduct_err_text').style.visibility = 'visible';
  			return;
  		}

  		//added by sarvjeet on august 27 to submit the form
  		$('productTitle').value = $("addproduct_title").value;
  		$('productDescription').value = $("addproduct_desc").value;
  		$('collectionId').value = collectionId;
		$('collectionName').value = collectionName;
		$('topCategoryId').value = topCategoryId;
		if((($('addproduct_price').value).charAt(0)) == '.'){
			$('addproduct_price').value = '0'+($('addproduct_price').value);
		}
		if(!(dojo.validate.isRealNumber($('addproduct_price').value))){
			$('price').value = '0';
  		}else{
  			$('price').value = $("addproduct_price").value;
  		}
		
		
		$('choosePhoto').value = $("choosephoto_hidden").value;
		$('uploadPhoto').value = $("addproduct_photo_hidden").value;
		$('photoName').value = $("addproduct_photo").value;
		$('productUrl').value = $("product_url").value;
		$('tags').value = $("addproduct_tags").value;
		if($('productComment') != null && $('addproduct_comment') != null) {
			$('productComment').value = $("addproduct_comment").value;
		}
		$('imageUploadByUrl').value = $('addproduct_photobyurl_hidden').value;
		
		if($('displayUrl') != null && $('addproduct_displayurl') != null) {
			$('displayUrl').value = $("addproduct_displayurl").value;
		}
		
		//added by sarvjeet on Oct 22, 2010
		if($('hdnProductId') == null){
			//its a new product
			if($('chkFacebook').checked)
				$('postToFacebook').value = 1;
			if($('chkTwitter').checked)
				$('postToTwitter').value = 1;
		} 
		
  		var frm = $("addproductreview");
  		frm.action = "index.action";
  		frm.method = "post";
  		frm.submit();

		
		return;
  		var url = "addproductreview.action?";
  		url = url + "product=" + escape($("addproduct_title").value) ;
  		url = url + "&amp;productDescription=" + escape($("addproduct_desc").value.replace("\n","<br/>"));
  		url = url + "&amp;collectionId=" + collectionId;
  		url = url + "&amp;collectionName=" + collectionName;
  		url = url + "&amp;categoryId=" + $("categoryId").value;
  		url = url + "&amp;topCategoryId=" + topCategoryId;
  		url = url + "&amp;imageUrls=" + escape($("imageUrls").value);
  		url = url + "&amp;price=" + $("addproduct_price").value;
  		url = url + "&amp;choosePhoto=" + $("choosephoto_hidden").value;
  		url = url + "&amp;uploadPhoto=" + $("addproduct_photo_hidden").value;
  		url = url + "&amp;photoName=" + $("addproduct_photo").value;
  		url = url + "&amp;productUrl=" + escape($("product_url").value);
  		url = url + "&amp;tags=" + $("addproduct_tags").value;
  		url = url + "&amp;reviewText=" + escape($("reviewText").value);
  		url = url + "&amp;reviewRating=" + $("reviewRating").value;
  		url = url + "&amp;noReview=" + $("noReview").value;
  		Controller.executeAction("showSubContent",  url, true);
	}
};

Controller.actions.addPhotoByUrl = 
{
	type:"js",
		
	error_target:
	"image_uploadbyurl_error",
	
	js_handler:
	function()
	{
		$('image_uploadbyurl_error').style.visibility = 'hidden';
		//$('uploadedImageByUrlHolder').style.visibility = 'hidden';
		$('uploadedImageByUrlHolder_img').src='';
		ActionCommons.hideDiv("uploadedImageByUrlHolder");
		var imageUrl = $('addproduct_photobyurl').value;
		msg = validateProductImageUrl(imageUrl);
		if(msg != 'true'){
			throw msg;
			return;
		}
		disableButton('lnkAddFile', 'wait..');
		executeAction('uploadPhotoByUrl');
	}
};


Controller.actions.uploadPhotoByUrl = 
{
	type:"dwr",
		
	arguments:
	["addproduct_photobyurl"], 

	error_target:
	"image_uploadbyurl_error",
	
	dwr_handler:
	ProductHandler.uploadPhotoViaUrl,
	
	dwr_callback:
	function(photo)
	{
  		var link = $('lnkAddFile');
  		if(link) {
  			link.innerHTML = "Add Image";
  			link.onclick = function (){executeAction('addPhotoByUrl');};
  		}
		if(photo.error && photo.message=='images too small')
		{
	    	throw "Images uploaded is too small. Please upload a bigger image.";
	    }else if(photo.error){
	    	throw "Upload failed. Are you sure you used the right image URL? Try again.";
	  	}else{
	  		$('uploadedImageByUrlHolder').style.visibility = 'visible';
	  		showImage(photo.photoUrl, 'uploadedImageByUrlHolder');
	  		setSelectedImage($('uploadedImageByUrlHolder'));
	  		$('addproduct_photobyurl_hidden').value = photo.photoUrl;
	  	}

	}
};


Controller.actions.productPreview = 
{
	type:"js",
		
	js_handler:
	function()
	{
  		var noReview = $("addreview_saveornot0").value;
  		var reviewText = $("review_text").value;
  		if(noReview != 'true'){
  			var tempRating = $('hdn_rating');
  			if(tempRating){
  				if(tempRating.value == "" > 0 || parseInt(tempRating.value) <= 0){
  					Controller.showMessage("Enter Review Rating", "addreview_err_text");
  					return false;
  				}
  			}
  			var f = {maxlength:8000}
  			if(!dojo.validate.isText(reviewText, f)){
  				Controller.showMessage("Enter Review Text", "addreview_err_text");
  				return false;
  			}
  			
  		}
  		
  		var frm = $("productpreview");
  		frm.action = "index.action";
  		frm.method = "post";
  		$('reviewText').value = $("review_text").value;
  		$('reviewRating').value = $("hdn_rating").value;
  		$('noReview').value = $("addreview_saveornot0").value;
  		
  		
  		frm.submit();
  		return;
  		/*
		var frm = dojo.byId("productpreview");
		var targetDiv = dojo.byId("contentarea_content");
		var result = new dojo.io.FormBind(
		    {
		    	mimetype: "text/html",
		    	target:targetDiv,
		    	url: "productpreview.action",
		    	formNode: frm,
		    	load: function(type, data, evt){
		     		target.innerHTML = data;
		     	},
		     	error: function(t, e) {alert(e);}
		     	
	    	}
	    );
	    return;
	    */
  		var url = "productpreview.action?";
  		url = url + "productTitle=" + escape($("product").value) ;
  		url = url + "&amp;productDescription=" + escape($("productDescription").value) ;
  		url = url + "&amp;collectionId=" + $("collectionId").value ;
  		url = url + "&amp;categoryId=" + $("categoryId").value;
  		url = url + "&amp;topCategoryId=" + $("topCategoryId").value;
  		url = url + "&amp;imageUrls=" + escape($("imageUrls").value);;
  		url = url + "&amp;price=" + $("price").value;
  		url = url + "&amp;choosePhoto=" + $("choosePhoto").value;
  		url = url + "&amp;uploadPhoto=" + $("uploadPhoto").value;
  		url = url + "&amp;photoName=" + $("photoName").value;
  		url = url + "&amp;productUrl=" + escape($("productUrl").value);
  		url = url + "&amp;tags=" + $("tags").value;
  		url = url + "&amp;reviewText=" + escape($("review_text").value);
  		url = url + "&amp;reviewRating=" + $("hdn_rating").value;
  		url = url + "&amp;noReview=" + $("addreview_saveornot0").value;
  		url = url + "&amp;collectionName=" + $("collection_name").value;
  		Controller.executeAction("showSubContent",  url, true);
	}
};


Controller.actions.backToAddProduct = 
{
	type:"js",
		
	js_handler:
	function()
	{
  		var ret = confirm("Are you sure you want to start over? \n\nIf you do, any information you've entered thus far will be lost.  \n\nPress OK for START OVER \n\n");
  		if(!ret){
  			return;
  		}
  		var productUrl = $("productUrl").value;
  		var userId = $("userId").value;
  		var url = "?contentaction=addproductviaurl&userId=" + userId ;
  		url = url + "&searchString=" + productUrl ;
		var loc = window.location;	
		loc.href = loc.protocol + "//" + loc.host + loc.pathname +  url;  		
	}
};


Controller.actions.editProduct = 
{
	type:"js",
		
	js_handler:
	function()
	{
  		/*var ret = confirm("Are you sure you want to start over? \n\nIf you do, any information you've entered thus far will be lost.  \n\nPress OK for START OVER \n\n");
  		if(!ret){
  			return;
  		}*/
 		window.onbeforeunload = null;
 		var frm = $("editproduct");
  		frm.action = "index.action";
  		frm.method = "post";
  		frm.submit();
  		return;
  		
  		var collectionId= $("collectionId").value;
  		var collectionName=$("collectionName").value;
  		var topCategoryId = $("topCategoryId").value;
  		var url = "backToMainPage.action?";
  		url = url + "productTitle=" + escape($("productTitle").value) ;
  		url = url + "&amp;productDescription=" + escape($("productDescription").value.replace("\n","<br/>"));
  		url = url + "&amp;collectionId=" + collectionId;
  		url = url + "&amp;collectionName=" + collectionName;
  		url = url + "&amp;categoryId=" + $("categoryId").value;
  		url = url + "&amp;topCategoryId=" + topCategoryId;
  		url = url + "&amp;imageUrls=" + escape($("imageUrls").value);;
  		url = url + "&amp;price=" + $("price").value;
  		url = url + "&amp;choosePhoto=" + $("choosePhoto").value;
  		url = url + "&amp;uploadPhoto=" + $("uploadPhoto").value;
  		url = url + "&amp;photoName=" + $("photoName").value;
  		url = url + "&amp;productUrl=" + escape($("productUrl").value);
  		url = url + "&amp;tags=" + $("tags").value;
  		url = url + "&amp;reviewText=" + escape($("reviewText").value);
  		url = url + "&amp;reviewRating=" + $("reviewRating").value;
  		url = url + "&amp;noReview=" + $("noReview").value;
  		Controller.executeAction("showSubContent",  url, true);


		/*
  		var productUrl = $("productUrl").value;
  		var userId = $("userId").value;
  		var url = "?contentaction=addproductviaurl&userId=" + userId ;
  		url = url + "&searchString=" + productUrl ;
		var loc = window.location;	
		loc.href = loc.protocol + "//" + loc.host + loc.pathname +  url;  */		
	}
};



Controller.actions.backToAddNewProduct = 
{
	type:"js",
		
	js_handler:
	function()
	{
  		/*var ret = confirm("Are you sure you want to start over? \n\nIf you do, any information you've entered thus far will be lost.  \n\nPress OK for START OVER \n\n");
  		if(!ret){
  			return;
  		}*/
  		var frm = $("productpreview");
  		frm.action = "index.action";
  		frm.method = "post";
  		//contentaction is different here
  		$('productpreview_contentaction').value = 'backToMainPage';
  		$('reviewText').value = $("review_text").value;
  		$('reviewRating').value = $("hdn_rating").value;
  		$('noReview').value = $("addreview_saveornot0").value;
  		
  		frm.submit();
  		return;


  		var collectionId= $("collectionId").value;
  		var collectionName=$("collection_name").value;
  		var topCategoryId = $("topCategoryId").value;
  		var url = "backToMainPage.action?";
  		url = url + "productTitle=" + escape($("product").value) ;
  		url = url + "&amp;productDescription=" + escape($("productDescription").value.replace("\n","<br/>"));
  		url = url + "&amp;collectionId=" + collectionId;
  		url = url + "&amp;collectionName=" + collectionName;
  		url = url + "&amp;categoryId=" + $("categoryId").value;
  		url = url + "&amp;topCategoryId=" + topCategoryId;
  		url = url + "&amp;imageUrls=" + escape($("imageUrls").value);;
  		url = url + "&amp;price=" + $("price").value;
  		url = url + "&amp;choosePhoto=" + $("choosePhoto").value;
  		url = url + "&amp;uploadPhoto=" + $("uploadPhoto").value;
  		url = url + "&amp;photoName=" + $("photoName").value;
  		url = url + "&amp;productUrl=" + escape($("productUrl").value);
  		url = url + "&amp;tags=" + $("tags").value;
  		url = url + "&amp;reviewText=" + escape($("review_text").value);
  		url = url + "&amp;reviewRating=" + $("hdn_rating").value;
  		url = url + "&amp;noReview=" + $("addreview_saveornot0").value;
  		Controller.executeAction("showSubContent",  url, true);


		/*
  		var productUrl = $("productUrl").value;
  		var userId = $("userId").value;
  		var url = "?contentaction=addproductviaurl&userId=" + userId ;
  		url = url + "&searchString=" + productUrl ;
		var loc = window.location;	
		loc.href = loc.protocol + "//" + loc.host + loc.pathname +  url;  */		
	}
};


Controller.actions.getChildren = 
{
	type:"dwr",
		
	arguments:
	["categoryId"], 
	
	validators:
	[undefined],
	
	error_messages:
	[""],
	
	dwr_handler:
	CategoryHandler.getChildren,
	
	dwr_callback:
	function(categorylist)
	{
		if(categorylist.error)
		{
	    	throw categorylist.message;
	  	}else{
	  		var sel;
	  		var header = "";
	  		var level = $("level");
	  		if(level.value == "1"){
	  			sel = $("subCategory");
	  			header = "--Select Subcategory--";
	  		}else {
	  			sel = $("subSubCategory");
	  			header = "--Select Sub-sub-category--";
	  		}
	  		if(sel){
	  			clearOptions(sel);
	  			sel.options.add(new Option(header, "-1"));
	  			var cat;
	  			var list = categorylist.list;
		  		for(var i=0; i< list.size(); i++){
		  			var cat = list[i];
		  			sel.options.add(new Option(cat.categoryName, cat.categoryId));
		  		}
	  		}
	  		
	  	}
	}
};

Controller.actions.showAnswer = 
{
	type:"js",
	
	js_handler:
	function(questionId)
	{
		var element = $("hdnCurrentDivId");
		if(element){
				if(element.value != ""){
					var div = ActionCommons.getElement(element.value);
					if(div) {
						div.style.display = "none";
					}	
				}
		}
		var question = $("hdnCurrentQuestionId");
		if(question){
				if(question.value != ""){
					var link = ActionCommons.getElement(question.value);
					if(link) {
						link.style.fontSize = "0.86em";
					}	
				}
		}
		
		var div = ActionCommons.getElement("help_answers_" + questionId);
		if(div) {
			div.style.display = "block";
		}
		var newLink = ActionCommons.getElement("help_question_" + questionId);
		if(newLink){
			newLink.style.fontSize = "1em";
		}
		if(element){
			element.value = "help_answers_" + questionId;		
		}
		if(question){
			question.value = "help_question_" + questionId;
		}
	}
};

Controller.actions.showAuthSubContent = 
{
	type:"js",
	
	authenticate:true,
	
	js_handler:
	function(url, unescapeAMP, unescape)
	{
		ActionCommons.refreshDojoDiv("contentarea_content", url, unescapeAMP, unescape);	
	}
};

Controller.actions.refreshAuthDIVById = 
{
	type:"js",
	
	authenticate:true,
	
	js_handler:
	function(divId, url, unescapeAMP, unescape)
	{
		ActionCommons.refreshDojoDiv(divId, url, unescapeAMP, unescape);	
	}
};

Controller.actions.showAuthFloatingFormRelative = 
{
	type:"js",
	
	authenticate:true,
			
	js_handler:
	function(url, unescapeAMP)
	{
		Controller.executeAction("showFloatingFormRelative", url,unescapeAMP);		
	}
};

Controller.actions.validateNewDiscussion = 
{
	type:"js",
	
	js_handler:
	function()
	{
		var span = $('floating_form_err_txt');
		var title = $('discussion_title').value;
		var text = $('discussion_desc').value;
		var msg = validateDiscussionTitle(title);
		if( msg != "" ){ 
			span.style.visibility = 'visible';
			span.innerHTML = msg;
			return false;
		}
		msg = validateDiscussionText(text);
		if( msg != "" ){
			span.style.visibility = 'visible';
			span.innerHTML = msg;
			return false;
		}
		disableButton('btnAdd','Posting...');
		//validateDiscussionText
		Controller.executeAction("addDiscussion");		
	}
};

Controller.actions.addDiscussion = 
{
	type:"dwr",
		
	arguments:
	["categoryId","discussion_title","discussion_desc"], 
	
	validators:
	[undefined, dojo.validate.isText , dojo.validate.isText],
	
	error_messages:
	["", "Valid Discussion", "Valid Discussion"],
		
	error_target:
	"floating_form_err_txt",


	dwr_handler:
	DiscussionHandler.addDiscussion,
	
	dwr_callback:
	function(discussion)
	{
		if(discussion != null)
		{
	  		if(!discussion.error)
			{
				var url = "pagedcategorydiscussions.action?callingpage=1&categoryId=";
				url += discussion.category.categoryId;
				Controller.executeAction("closeFloatingForm");
				Controller.executeAction("refreshDIVById", "pagedcategoryactivities_discussions", url, true);
				//window.location.reload();
			}
			else
			{
				throw discussion.message;
	  		}
	  	}
		else
		{
			throw "unable to add discussion.";
		}
	}
};

Controller.actions.validateDiscussionComment = 
{
	type:"js",
	
	js_handler:
	function()
	{
		var span = $('floating_form_err_txt');
		var text = $('disc_comment').value;
		msg = validateDiscussionCommentText(text);
		if( msg != "" ){
			span.style.visibility = 'visible';
			span.innerHTML = msg;
			return false;
		}
		disableButton('btnAdd','Wait...');
		//validateDiscussionText
		Controller.executeAction("addDiscussionComment");		
	}
};

Controller.actions.addDiscussionComment = 
{
	type:"dwr",
		
	arguments:
	["hdn_discussionid","disc_comment"], 
	
	validators:
	[undefined, undefined],
	
	error_messages:
	["", ""],
		
	error_target:
	"floating_form_err_txt",


	dwr_handler:
	DiscussionHandler.addDiscussionComment,
	
	dwr_callback:
	function(discussionComment)
	{
		if(discussionComment != null)
		{
	  		if(!discussionComment.error)
			{
				var url="discussiondetails.action?categoryId=";
				url+=discussionComment.categoryDiscussion.category.categoryId;
				url+="&discussionId="
				url += discussionComment.categoryDiscussion.discussionId;
				Controller.executeAction("closeFloatingForm");
				Controller.executeAction("refreshDIVById", "pagedcategoryactivities_discussions", url, true);
				//window.location.reload();
			}
			else
			{
				var span = $('floating_form_err_txt');
				if(span){
					span.style.visibility = 'visible';
				}
				throw discussionComment.message;
	  		}
	  	}
		else
		{
			throw "unable to add comment.";
		}
	}
};

Controller.actions.bulkUpdateSuperTags = 
{
	type:"dwr",
	
	arguments:
	["categoryId","previousRecords"],
	
	validators:
	[dojo.validate.isText,undefined],
	
	error_messages:
	["Please choose a category .",""],
	
	error_target:
	"addproduct_err_text",
	
	dwr_handler:
	ProductHandler.getBulkUpdateProducts,
	
	dwr_callback:
	function(result)
	{
		if(result=='')
		{
			throw "All product super tags updated successfully.";
		}
		else
		{
			throw result;
		}
	}
	
};

// for adding comment to collection and product 23-02-2010
Controller.actions.validateCollectionComment = 
{
	type:"js",
	
	js_handler:
	function()
	{
		//var span = $('floating_form_err_txt');
		$('imagepost_failure').style.visibility = 'hidden';
		var failurePost= $('imagepost_failure');
		var successPost= $('imagepost_success');
		failurePost.innerHTML = '';
		successPost.innerHTML='';
		var text = $('collection_comment').value;
		msg = validateCollectionCommentText(text);
		if( msg != "" ){
			//span.style.visibility = 'visible';
			//span.innerHTML = msg;
			successPost.style.visibility = 'hidden';
			failurePost.style.visibility='visible';
			failurePost.innerHTML = msg;
			return false;
		}
		disableButton('btnAdd','Wait...');
		var count = parseInt($('commentcount').value);
		executeAction("addCollectionComment");
	}
};

Controller.actions.addCollectionComment = 
{
	type:"dwr",
		
	arguments:
	["hdn_collectionid","collection_comment"], 
	
	validators:
	[undefined, undefined],
	
	error_messages:
	["", ""],
		
	error_target:
	"floating_form_err_txt",


	dwr_handler:
	CollectionHandler.addCollectionComment,
	
	dwr_callback:
	function(collectionComment)
	{
		if(collectionComment != null)
		{
	  		if(!collectionComment.error)
			{
				$('btnAdd').onclick = function () {executeAction('validateCollectionComment')};
				$('btnAdd').innerHTML = 'Post';
				//$('floating_form_err_txt').style.visibility = 'hidden';
				//increment count
				//alert($('commentcount').value);
				var count = $('commentcount').value;
				count = parseInt(count) + 1;
				$('commentcount').value = count;
				$('collection_comment').value='Type your comment here...';
				//alert($('commentcount').value);
				//$('activities_comments_link').innerHTML = 'Comments (' + count + ')';
				Controller.executeAction("refreshDIVById", 'collection_entityactivityhome');				

			}
			else
			{
				/*var span = $('floating_form_err_txt');
				if(span){
					span.style.visibility = 'visible';
				}
				throw collectionComment.message;
				*/
				$('collection_comment').value='Type your comment here...';
				var successText = $('imagepost_success');
				var failureText=$('imagepost_failure');
				successText.innerHTML = '';
				failureText.innerHTML=''; 
				successText.style.visibility = 'hidden';
				$('btnAdd').innerHTML = 'Failed';
				failureText.innerHTML = collectionComment.message;
				$('btnAdd').onclick = function () {executeAction('validateCollectionComment')};
				failureText.style.visibility = 'visible';
	  		}
	  	}
		else
		{
			throw "unable to add comment.";
		}
	}
};

Controller.actions.validateProductComment = 
{
	type:"js",
	
	js_handler:
	function()
	{
		//var span = $('floating_form_err_txt');
		$('imagepost_failure').style.visibility = 'hidden';
		var failurePost= $('imagepost_failure');
		var successPost= $('imagepost_success');
		failurePost.innerHTML = '';
		successPost.innerHTML='';
		var text = $('product_comment').value;
		msg = validateCollectionCommentText(text);
		if( msg != "" ){
			//span.style.visibility = 'visible';
			//span.innerHTML = msg;
			successPost.style.visibility = 'hidden';
			failurePost.style.visibility='visible';
			failurePost.innerHTML = msg;
			return false;
		}
		disableButton('btnAdd','Wait...');
		var count = parseInt($('commentcount').value);
		executeAction("addProductComment");
	}
};

Controller.actions.addProductComment = 
{
	type:"dwr",
		
	arguments:
	["hdn_productid","product_comment"], 
	
	validators:
	[undefined, undefined],
	
	error_messages:
	["", ""],
		
	error_target:
	"imagepost_failure",


	dwr_handler:
	ProductHandler.addProductComment,
	
	dwr_callback:
	function(productComment)
	{
		if(productComment != null)
		{
	  		if(!productComment.error)
			{
				
				$('btnAdd').onclick = function () {executeAction('validateProductComment')};
				$('btnAdd').innerHTML = 'Post';
				//$('floating_form_err_txt').style.visibility = 'hidden';
				//increment count
				//alert($('commentcount').value);
				var count = $('commentcount').value;
				count = parseInt(count) + 1;
				$('commentcount').value = count;
				$('product_comment').value='Type your comment here...';
				//alert($('commentcount').value);
				//$('activities_comments_link').innerHTML = 'Comments (' + count + ')';
				Controller.executeAction("refreshDIVById", 'collection_entityactivityhome');				

			}
			else
			{
				/*var span = $('floating_form_err_txt');
				if(span){
					span.style.visibility = 'visible';
				}
				throw productComment.message;
				*/
				$('product_comment').value='Type your comment here...';
				var successText = $('imagepost_success');
				var failureText=$('imagepost_failure');
				successText.innerHTML = '';
				failureText.innerHTML=''; 
				successText.style.visibility = 'hidden';
				$('btnAdd').innerHTML = 'Failed';
				failureText.innerHTML = productComment.message;
				$('btnAdd').onclick = function () {executeAction('validateProductComment')};
				failureText.style.visibility = 'visible';
	  		}
	  	}
		else
		{
			throw "unable to add comment.";
		}
	}
};


Controller.actions.collectionActivities = 
{
	type:"js",
	
	js_handler:
	function(div, url, escapeUrl, filterType)
	{
		var reload = false;
		var checkForAllActivityReload=$('byPassActivityAll').value;
		if(checkForAllActivityReload == 0)
		{
			var allActivityReload=false;
		}else{
			var allActivityReload=true;
		}	
		if(filterType) {
			resetActivityLinks();
			if(filterType == 'all') {
				if($('anchor_all'))
				{
					ActionCommons.showDiv("collection_activities_all");
					$('anchor_all').className = 'current';
					$('anchor_all').onclick=null;
				}
				if(allActivityReload)
				{
					if(window.collection_activities_all == false || !(window.collection_activities_all) || window.collection_activities_all == undefined){
						window.collection_activities_all = true;
						reload = true;
					}	
				}
			}else if (filterType == 'comments') {
				if($('anchor_comments'))
				{
					ActionCommons.showDiv("collection_activities_comment");
					$('anchor_comments').className = 'current';
					$('anchor_comments').onclick=null;
				}
				var checkForAllCommentReload=$('byPassActivityComments').value;
				if(checkForAllCommentReload !=1)
				{
					if(window.collection_activities_comment == false || !(window.collection_activities_comment) || window.collection_activities_all == undefined){
						window.collection_activities_comment = true;
						reload = true;
					}	
				}
			}else if (filterType == 'saves') {
				if($('anchor_saves'))
				{
					ActionCommons.showDiv("collection_activities_save");
					$('anchor_saves').className = 'current';
					$('anchor_saves').onclick=null;
				}	
				if(window.collection_activities_save == false || !(window.collection_activities_save) || window.collection_activities_all == undefined){
					window.collection_activities_save = true;
					reload = true;
				}		
			}else if (filterType == 'reviews') {
				if($('anchor_reviews'))
				{
					ActionCommons.showDiv("collection_activities_review");
					$('anchor_reviews').className = 'current';
					$('anchor_reviews').onclick=null;
				}
				if(window.collection_activities_review == false || !(window.collection_activities_review) || window.collection_activities_all == undefined){
					window.collection_activities_review = true;
					reload = true;
				}	
			}else if (filterType == 'photos') {
				if($('anchor_photos'))
				{
					ActionCommons.showDiv("collection_activities_photo");
					$('anchor_photos').className= 'current';
					$('anchor_photos').onclick=null
				}	
				if(window.collection_activities_photo == false || !(window.collection_activities_photo) || window.collection_activities_all == undefined){
					window.collection_activities_photo = true;
					reload = true;
				}	
			}else if (filterType == 'collections') {
				if($('anchor_collections'))
				{
					ActionCommons.showDiv("collection_activities_collection");
					$('anchor_collections').className= 'current';
					$('anchor_collections').onclick=null;
				}	
				var checkForAllCollectionsReload=$('byPassActivityCollections').value;
				if(checkForAllCollectionsReload != 1)
				{
					if(window.collection_activities_collection == false || !(window.collection_activities_collection) || window.collection_activities_all == undefined){
						window.collection_activities_collection = true;
						reload = true;
					}
				}	
			}
			
		}
		var element = $('activity_box');
		if(reload){
			Controller.executeAction("refreshDIVById", div, url, escapeUrl);
			//window.scrollTo(0, findTop(element));
		}
	}
};

Controller.actions.homepageActivityFilter = 
{
	type:"js",
	
	js_handler:
	function(div, url, escapeUrl, filterType, notification)
	{
		var reload = setHomePageActivityLinks(filterType);
		if(reload)
			Controller.executeAction("refreshDIVById", div, url, escapeUrl, null, true);
	}
};

Controller.actions.addCollectionToFavorites = 
{
	type:"js",
	
	js_handler:
	function()
	{
		//disable button here
		$('collection_save_btn').onclick = null;
		$('collection_save_btn').innerHTML = 'Saving...';
		Controller.executeAction("addCollectionToUserFavoriteCollection");		
	}
};

/* for saving collection to user collection */

Controller.actions.addCollectionToUserFavoriteCollection = 
{

	type:"dwr",
		
	arguments:
	["productcollection_id"], 
	
	validators:
	[undefined],
	
	error_messages:
	[""],
	
	error_target:
	"floating_form_err_txt",


	dwr_handler:
	CollectionHandler.addCollectionToUserFavorite,
	
	dwr_callback:
	function(collection)
	{
		if(collection != null)
		{
	  		if(!collection.error)
			{
				$('collection_save_btn').innerHTML = 'SAVED';
				var count = $('savecount').value;
				count = parseInt(count) + 1;
				$('activities_save_link').innerHTML = 'Saves (' + count + ')';
				Controller.executeAction("refreshDIVById", 'collection_entityactivityhome');
			}
			else
			{
				$('collection_save_btn').innerHTML = 'Failed';
				throw collection.message;
	  		}
			$('btnCollectionSave').className = 'collection_green_btns_nohover';				
	  		
	  	}
		else
		{
			throw "unable to add collection to the favorite collection";
		}
	}
		
};

Controller.actions.validateCommunityPhoto = 
{
	type:"js",
	
	js_handler:
	function()
	{
		//var span = $('floating_form_err_txt');
		$('imagepost_failure').style.visibility = 'hidden';
		var failurePost= $('imagepost_failure');
		var successPost= $('imagepost_success');
		failurePost.innerHTML = '';
		successPost.innerHTML='';
		var textComment = $('communityphoto_comment').value;
		var imagePath=$('addcommunity_photo_hidden').value;
		msg = validateCommunityPhotoCommentText(textComment,imagePath);
		if( msg != "" ){
			successPost.style.visibility = 'hidden';
			failurePost.style.visibility='visible';
			failurePost.innerHTML = msg;
			return false;
		}
		disableButton('btnAdd','Wait...');
		executeAction("addCommunityPhoto");
	}
};

Controller.actions.addCommunityPhoto = 
{
	type:"dwr",
		
	arguments:
	["hdn_productid","addcommunity_photo_hidden","communityphoto_comment"], 
	
	validators:
	[undefined,undefined,undefined],
	
	error_messages:
	["", "",""],
		
	error_target:
	"imagepost_failure",


	dwr_handler:
	ProductHandler.addCommunityPhoto,
	
	dwr_callback:
	function(communityPhoto)
	{
		if(communityPhoto != null)
		{
	  		if(!communityPhoto.error)
			{
					$('btnAdd').onclick = function () {executeAction('validateCommunityPhoto')};
					$('btnAdd').innerHTML = 'Post';
					var count = $('communityphotocount').value;
					count = parseInt(count) + 1;
					$('communityphotocount').value = count;
					//$('activities_photos_link').innerHTML = 'view '+ count +' user photos';
					$('communityphoto_comment').value='Type your comment here... it\'s optional.';
					$('addcommunity_photo_hidden').value='';
					$('addcommunity_photo').value='select an image';
					var successText = $('imagepost_success');
					var failureText=$('imagepost_failure');
					successText.innerHTML = '';
					failureText.innerHTML='';
					if(successText)
					{
						successText.style.visibility = 'visible';
	  					successText.innerHTML = "Image posted. Good work. Add another?";
	  					failureText.style.visibility = 'hidden';
	  				}
					Controller.executeAction("refreshDIVById", 'collection_entityactivityhome');
			}
			else
			{
				$('communityphoto_comment').value='Type your comment here... it\'s optional.';
				$('addcommunity_photo_hidden').value='';
				$('addcommunity_photo').value='select an image';
				var successText = $('imagepost_success');
				var failureText=$('imagepost_failure');
				successText.innerHTML = '';
				failureText.innerHTML=''; 
				successText.style.visibility = 'hidden';
				$('btnAdd').innerHTML = 'Failed';
	  			failureText.innerHTML = communityPhoto.message;
	  			$('btnAdd').onclick = function () {executeAction('validateCommunityPhoto')};
	  			failureText.style.visibility = 'visible';
			}
	  	}
		else
		{
			throw "unable to add product photo.";
		}
	}
};

/* for adding comment to community photo*/

Controller.actions.validateCommunityPhotoComment = 
{
	type:"js",
	
	js_handler:
	function()
	{
		$('imagepost_failure').style.visibility = 'hidden';
		var failurePost= $('imagepost_failure');
		var successPost= $('imagepost_success');
		failurePost.innerHTML = '';
		successPost.innerHTML='';
		var text = $('community_photocomment').value;
		msg = validatePhotoCommentText(text);
		if( msg != "" ){
			successPost.style.visibility = 'hidden';
			failurePost.style.visibility='visible';
			failurePost.innerHTML = msg;
			return false;
		}
		disableButton('btnAdd','Wait...');
		//var count = parseInt($('commentcount').value);
		executeAction("addCommunityPhotoComment");
	}
};

Controller.actions.addCommunityPhotoComment = 
{
	type:"dwr",
		
	arguments:
	["hdn_communityphotoid","community_photocomment"], 
	
	validators:
	[undefined, undefined],
	
	error_messages:
	["", ""],
		
	error_target:
	"floating_form_err_txt",


	dwr_handler:
	ProductHandler.addCommunityPhotoComment,
	
	dwr_callback:
	function(communityPhotoComment)
	{
		if(communityPhotoComment != null)
		{
	  		if(!communityPhotoComment.error)
			{
				$('btnAdd').onclick = function () {executeAction('validateCommunityPhotoComment')};
				$('btnAdd').innerHTML = 'Post';
				//$('floating_form_err_txt').style.visibility = 'hidden';
				//increment count
				//alert($('commentcount').value);
				//var count = $('commentcount').value;
				//count = parseInt(count) + 1;
				//$('commentcount').value = count;
				$('community_photocomment').value='Type your comment here...';
				Controller.executeAction("refreshDIVById", 'collection_entityactivityhome');	
			}
			else
			{
				$('community_photocomment').value='Type your comment here...';
				var successText = $('imagepost_success');
				var failureText=$('imagepost_failure');
				successText.innerHTML = '';
				failureText.innerHTML=''; 
				successText.style.visibility = 'hidden';
				$('btnAdd').innerHTML = 'Failed';
				failureText.innerHTML = communityPhotoComment.message;
				$('btnAdd').onclick = function () {executeAction('validateCommunityPhotoComment')};
				failureText.style.visibility = 'visible';
	  		}
	  	}
		else
		{
			throw "unable to add comment.";
		}
	}
};

/* flag the product */

Controller.actions.validateFlagProduct = 
{
	type:"js",
	
	js_handler:
	function()
	{
		var postedMsg=$('flagPosted');
		postedMsg.className= 'flag_msg';
		postedMsg.innerHTML='Wait...';
		executeAction("flagProductAsOutdated");
	}
};


Controller.actions.flagProductAsOutdated = 
{
	type:"dwr",
		
	arguments:
	["product_id","product_title"], 
	
	validators:
	[undefined,undefined],
	
	error_messages:
	["",""],
	
	error_target:
	"floating_form_err_txt",


	dwr_handler:
	ProductHandler.flagProductAsOutdated,
	
	dwr_callback:
	function(result)
	{
		if(result=='')
		{
			var postedMsg=$('flagPosted');
			postedMsg.className= 'flag_msg';
			postedMsg.innerHTML='Thanks! We got it.';
		}
		else
		{
			throw result;
	  	}
	}
};

/* validate collection photo */

Controller.actions.validateCollectionPhoto = 
{
	type:"js",
	
	js_handler:
	function()
	{
		//var span = $('floating_form_err_txt');
		$('imagepost_failure').style.visibility = 'hidden';
		var failurePost= $('imagepost_failure');
		var successPost= $('imagepost_success');
		failurePost.innerHTML = '';
		successPost.innerHTML='';
		var textComment = $('communityphoto_comment').value;
		var imagePath=$('addcollection_photo_hidden').value;
		msg = validateCommunityPhotoCommentText(textComment,imagePath);
		if( msg != "" ){
			successPost.style.visibility = 'hidden';
			failurePost.style.visibility='visible';
			failurePost.innerHTML = msg;
			return false;
		}
		disableButton('btnAdd','Wait...');
		executeAction("addCollectionPhoto");
	}
};

Controller.actions.addCollectionPhoto = 
{
	type:"dwr",
		
	arguments:
	["hdn_collectionid","addcollection_photo_hidden","communityphoto_comment"], 
	
	validators:
	[undefined,undefined,undefined],
	
	error_messages:
	["", "",""],
		
	error_target:
	"imagepost_failure",


	dwr_handler:
	CollectionHandler.addCollectionPhoto,
	
	dwr_callback:
	function(collectionPhoto)
	{
		if(collectionPhoto != null)
		{
	  		if(!collectionPhoto.error)
			{
					$('btnAdd').onclick = function () {executeAction('validateCollectionPhoto')};
					$('btnAdd').innerHTML = 'Post';
					var count = $('collectionphotocount').value;
					count = parseInt(count) + 1;
					$('collectionphotocount').value = count;
					//$('activities_photos_link').innerHTML = 'view '+ count +' user photos';
					$('communityphoto_comment').value='Type your comment here... it\'s optional.';
					$('addcollection_photo_hidden').value='';
					$('addcollection_photo').value='select an image';
					var successText = $('imagepost_success');
					var failureText=$('imagepost_failure');
					successText.innerHTML = '';
					failureText.innerHTML='';
					if(successText)
					{
						successText.style.visibility = 'visible';
	  					successText.innerHTML = "Image posted. Good work. Add another?";
	  					failureText.style.visibility = 'hidden';
	  				}
	  				//$('activities_photos_link').innerHTML = 'Photos (' + count + ')';
					Controller.executeAction("refreshDIVById", 'collection_entityactivityhome');
			}
			else
			{
				$('communityphoto_comment').value='Type your comment here... it\'s optional.';
				$('addcollection_photo_hidden').value='';
				$('addcollection_photo').value='select an image';
				var successText = $('imagepost_success');
				var failureText=$('imagepost_failure');
				successText.innerHTML = '';
				failureText.innerHTML=''; 
				successText.style.visibility = 'hidden';
				$('btnAdd').innerHTML = 'Failed';
	  			failureText.innerHTML = communityPhoto.message;
	  			$('btnAdd').onclick = function () {executeAction('validateCollectionPhoto')};
	  			failureText.style.visibility = 'visible';
			}
	  	}
		else
		{
			throw "unable to add collection photo.";
		}
	}
};

/* for adding comment to collection photo on 20 april 2010   */

Controller.actions.validateCollectionPhotoComment = 
{
	type:"js",
	
	js_handler:
	function()
	{
		$('imagepost_failure').style.visibility = 'hidden';
		var failurePost= $('imagepost_failure');
		var successPost= $('imagepost_success');
		failurePost.innerHTML = '';
		successPost.innerHTML='';
		var text = $('community_photocomment').value;
		msg = validatePhotoCommentText(text);
		if( msg != "" ){
			successPost.style.visibility = 'hidden';
			failurePost.style.visibility='visible';
			failurePost.innerHTML = msg;
			return false;
		}
		disableButton('btnAdd','Wait...');
		//var count = parseInt($('commentcount').value);
		executeAction("addCollectionPhotoComment");
	}
};

Controller.actions.addCollectionPhotoComment = 
{
	type:"dwr",
		
	arguments:
	["hdn_collectionphotoid","community_photocomment"], 
	
	validators:
	[undefined, undefined],
	
	error_messages:
	["", ""],
		
	error_target:
	"floating_form_err_txt",


	dwr_handler:
	CollectionHandler.addCollectionPhotoComment,
	
	dwr_callback:
	function(communityPhotoComment)
	{
		if(communityPhotoComment != null)
		{
	  		if(!communityPhotoComment.error)
			{
				$('btnAdd').onclick = function () {executeAction('validateCollectionPhotoComment')};
				$('btnAdd').innerHTML = 'Post';
				//$('floating_form_err_txt').style.visibility = 'hidden';
				//increment count
				//alert($('commentcount').value);
				//var count = $('commentcount').value;
				//count = parseInt(count) + 1;
				//$('commentcount').value = count;
				$('community_photocomment').value='Type your comment here...';
				Controller.executeAction("refreshDIVById", 'collection_entityactivityhome');	
			}
			else
			{
				$('community_photocomment').value='Type your comment here...';
				var successText = $('imagepost_success');
				var failureText=$('imagepost_failure');
				successText.innerHTML = '';
				failureText.innerHTML=''; 
				successText.style.visibility = 'hidden';
				$('btnAdd').innerHTML = 'Failed';
				failureText.innerHTML = collectionPhotoComment.message;
				$('btnAdd').onclick = function () {executeAction('validateCollectionPhotoComment')};
				failureText.style.visibility = 'visible';
	  		}
	  	}
		else
		{
			throw "unable to add comment.";
		}
	}
	
};

Controller.actions.facebookLogin = 
{
	type:"js",
	
	js_handler:
	function(response)
	{
		 
		if (response.authResponse) {
	      // A user has logged in, and a new cookie has been saved
	      var uid = response.authResponse.userID;
	      var access_token = response.authResponse.accessToken;
	      
	      var url = "/me?fields=id,name,email,picture&access_token=" + access_token;
	      FB.api("/me",  function(userInfo) {
  			var email = userInfo.email;
  			var name = userInfo.name;
  			executeAction("userLoginByFacebook", uid, access_token, email, name);
		  });

	       
	    } else {
	      //changed by sarvjeet on Dec 6, 2011 to allow users to register without facebook also
	    	executeAction("userLoginByFacebook", '', '', '', '');
	    	// The user has logged out, and the cookie has been cleared
	      //executeAction("logout");
	    }
		
	}
};

Controller.actions.userLoginByFacebook = 
{
	type:"dwr",
		

		
	error_target:
	"floating_form_err_txt",


	dwr_handler:
	AdministrationHandler.loginByFaceBookId,
	
	dwr_callback:
	function(user)
	{  			
		if(user != null)
		{
	  		if(!user.error)
			{
				Controller.executeAction("closeFloatingForm");
			
				
				if(user.message != "")
				{
					var faceBookId = user.faceBookId != null?user.faceBookId:'';
					var email = '';
					if(user.email != null){
						if(validateEmailForFacebook(user.email))
						{
						  email = user.email;
						}else{
						   email='';
						}
					}
					
					var name = user.userName !=null?user.userName:'';
					if(user.message.indexOf('new') != -1){
						//new user - for new registration
						var loc = window.location;	
						loc.href = loc.protocol + "//" + loc.host +  
									"/index.action?contentaction=facebooknewaccount&email=" + email + "&faceBookId=" + faceBookId
									+ "&userName=" + name;
					}else if (user.message.indexOf('link') != -1) {
						var loc = window.location;
						loc.href = loc.protocol + "//" + loc.host + loc.pathname + 
									"?contentaction=facebooklinkaccount&email=" + email + "&faceBookId=" + faceBookId
									+ "&userName=" + name;
						//link accounts for older registration
					}else if (user.message.indexOf('skip') != -1) {
						//do not do anything
					}else {
						//document.cookie = "wanelopp=" + user.message;
						var date = new Date();
						date.setTime(date.getTime() + 31536000000);
						document.cookie = "wanelopp=" + user.message + ";expires=" + date.toGMTString() + ";domain=wanelo.com";	
						window.location.reload();	
					}
				}
				
			}
			else
			{
				var passwordfield = ActionCommons.getElement("userlogin_password");
				if(passwordfield != null)
				{
					passwordfield.value = "";
				}
				
				throw user.message;
	  		}
	  	}
		else
		{
			throw "login error";
		}	
	}

	
};

/* added by ashish on 05 may 2010 */

Controller.actions.validateLinkFaceBookAccountInfo = 
{
	type:"js",
		
	error_target:
	"floating_form_err_txt",
	
	js_handler:
	function()
	{
		
		if(validateRegisterEmail(dojo.string.trim($('wanelo_email').value)) == false)
		{
			enableButton('linkFaceBookAccount', 'DONE!', 'validateLinkFaceBookAccountInfo', true);
			throw "Enter Email.";
		}
		if(validatePassword(dojo.string.trim($('wanelo_password').value)) == false)
		{
			enableButton('linkFaceBookAccount', 'DONE!', 'validateLinkFaceBookAccountInfo', true);
			throw "Enter Password.";
		}
		
		disableButton('linkFaceBookAccount', 'wait...');
		executeAction('linkFaceBookAccount');
		//enableButton('linkRegisteration', 'JOIN', 'addRegister', true);
	}
};


Controller.actions.linkFaceBookAccount = 
{
	type:"dwr",
		
	arguments:
	["facebook_email","facebook_username","facebook_id","wanelo_email","wanelo_password"], 
	
	validators:
	[undefined,undefined,undefined,undefined,undefined],
	
	error_messages:
	["","","","",""],
	
	error_target:
	"floating_form_err_txt",


	dwr_handler:
	AdministrationHandler.linkFaceBookAccount,
	
	dwr_callback:
	function(user)
	{
		if(user != null)
		{
			if(!user.error)
			{
				var loc = window.location;
				loc.href = loc.protocol + "//" + loc.host + loc.pathname ;
			}
			else
			{
				enableButton('linkFaceBookAccount', 'DONE!', 'validateLinkFaceBookAccountInfo', true);
				throw user.message;
			}
		}
		else
		{
			throw "login error";
		}
	}
};

//added new by ashish on 13 may 2010
Controller.actions.homepageCategoryFilter = 
{
	type:"js",
	
	js_handler:
	function(div, url, escapeUrl, filterType)
	{
		var reload = false;
		if(filterType) {
			resetActivityCategoryLinks();
			if(filterType == 'all') {
				if($('anchor_all'))
				{
					ActionCommons.showDiv("pagedcategoryactivities_all");
					$('anchor_all').className = 'current';
					var info_text = 'Recent activity in this category:';
					$('anchor_all').onclick=null;
				}
				if(window.pagedcategoryactivities_all == false || !(window.pagedcategoryactivities_all)){
					window.pagedcategoryactivities_all = true;
					reload = true;
				}	
			}else if (filterType == 'collections') {
				if($('anchor_collections'))
				{
					ActionCommons.showDiv("pagedcategoryactivities_collections");
					$('anchor_collections').className= 'current';
					var info_text = 'The latest product collections in this category:';
					$('anchor_collections').onclick=null;
				}	
				if(window.pagedcategoryactivities_collections == false || !(window.pagedcategoryactivities_collections)){
					window.pagedcategoryactivities_collections = true;
					reload = true;
				}	
			}else if (filterType == 'discussions') {
				if($('anchor_discussions'))
				{
					ActionCommons.showDiv("pagedcategoryactivities_discussions");
					$('anchor_discussions').className= 'current';
					var info_text ='&nbsp;';
					$('anchor_discussions').onclick=null;
				}
				if(window.pagedcategoryactivities_discussions == false || !(window.pagedcategoryactivities_discussions)){
					window.pagedcategoryactivities_discussions = true;
					reload = true;
				}	
			}else if (filterType == 'products') {
				if($('anchor_reviews'))
				{
					ActionCommons.showDiv("pagedcategoryactivities_products");
					$('anchor_reviews').className= 'current';
					var info_text ='&nbsp;';
					$('anchor_reviews').onclick=null;
				}
				if(window.pagedcategoryactivities_products == false || !(window.pagedcategoryactivities_products)){
					window.pagedcategoryactivities_products = true;
					reload = true;
				}
			}else if (filterType == 'photos') {
				if($('anchor_photos'))
				{
					ActionCommons.showDiv("pagedcategoryactivities_photos");
					$('anchor_photos').className= 'current';
					var info_text = 'The latest user photos in this category:';
					$('anchor_photos').onclick=null;
				}
				if(window.pagedcategoryactivities_photos == false || !(window.pagedcategoryactivities_photos)){
					window.pagedcategoryactivities_photos = true;
					reload = true;
				}
			}
			
		}
		if($('info_text')) {
				$('info_text').innerHTML = info_text;
			}	
		//var element = $('activity_box');
		
		//Controller.executeAction("refreshDIVById", div, url, escapeUrl);
		//window.scrollTo(0, findTop(element));		
		if(reload){
			Controller.executeAction("refreshDIVById", div, url, escapeUrl);
			//window.scrollTo(0, findTop(element));
		}
	}
};

/* added by ashish on 31 may 2010 */
Controller.actions.validateCollectionProductPhoto = 
{
	type:"js",
	
	js_handler:
	function()
	{
		//var span = $('floating_form_err_txt');
		$('imagepost_failure').style.visibility = 'hidden';
		var failurePost= $('imagepost_failure');
		var successPost= $('imagepost_success');
		failurePost.innerHTML = '';
		successPost.innerHTML='';
		var productUrl = $('product_url').value;
		msg = validateCollectionProductPhotoUrl(productUrl);
		//var tbx_productUrl_length=productUrl.trim().length;
		var tbx_productUrl_length=dojo.string.trim(productUrl).length;
		var tbx_productUrl=productUrl.substring(tbx_productUrl_length - 4 ,tbx_productUrl_length);
		
		if(tbx_productUrl == ".com")
		{
			executeAction("showFloatingForm", "addproductoverlay.action?searchString="+productUrl,undefined,"18.39em", "75.92em");
			//executeAction("showFloatingFormRelative", "addproductoverlay.action?searchString="+productUrl,true);
		}
		else if( msg == "Please enter valid product Url." ){
			//span.style.visibility = 'visible';
			//span.innerHTML = msg;
			successPost.style.visibility = 'hidden';
			failurePost.style.visibility='visible';
			failurePost.innerHTML = "Please enter valid product Url.";
			return true;
		}
		else
		{
			disableButton('btnAdd','Wait...');
			var userId = $("hdn_userid").value;
			var collectionId=$("hdn_collectionid").value;
			// commented by ashish on 14 march 2010
	  		//var url = "/index.action?contentaction=addproductviaurl&userId=" + userId ;
	  		// commented by ashish on 15 march 2010
	  		//var url = "/index.action?contentaction=addproductviaurl";
	  		//url = url + "&searchString=" + productUrl +"&collectionId="+collectionId;
	  		var productString=dojo.string.trim(productUrl);
			var indexSearch =productString.indexOf('?');
			while (indexSearch != -1)
			{
				productString = productString.replace( "?", "%3F");
				indexSearch = productString.indexOf("?");
			} 
	  		var url = "/addproduct/" + productString + prettyUrlExtension;
	  		var loc = window.location;	
			loc.href = loc.protocol + "//" + loc.host + url; 
		}
		
	}
};



/* added by ashish on 16 june 2010 */
Controller.actions.removeCollectionProduct = 
{
	type:"dwr",
		
	arguments:
	["hdn_collectionId","hdn_productId"], 
	
	validators:
	[undefined,undefined],
	
	error_messages:
	["",""],
	
	error_target:
	"floating_form_err_txt",


	dwr_handler:
	CollectionHandler.removeProductFromCollection,
	
	dwr_callback:
	function(msg)
	{
		if(msg=='')
		{
			ActionCommons.refreshDojoDiv('collection_products');
		}
		else
		{
			throw msg;
		}
	}
};

/* added by ashish on 4 aug 2010 */
Controller.actions.homePageRootCategory = 
{
	type:"js",
	
	js_handler:
	function(div, url, escapeUrl,catId, sortingBy)
	{		
			resetLinksOnHomePage();
			if($(catId) != null){
				$(catId).className = 'current';
			}
			// upadated by Prashant on 27/12/2011
			/*
			if(sortingBy != undefined) {
				$('sortingBy').value = sortingBy;
			}else {
				url = url + "&sortingBy=" + $('sortingBy').value ;
			}*/
			
			sortingBy =  $('sortingBy').value
			url = url + "&sortingByForSession=" + sortingBy ;
			url = url + "&productTypeForSession=" + $('productType').value;
			url = url + "&currentPageForSession=1";
			if($('current_category') != null){
				$('current_category').innerHTML = "all products";
			}
			if($(catId) != null){
				$(catId).onclick = null;
			}
			Controller.executeAction("refreshDIVById",div,url,escapeUrl);
	}
};

Controller.actions.findProductsByFilters = 
{
	type:"js",
	
	js_handler:
	function(div, url, escapeUrl,catId, sortingBy, element, productType)
	{		
		
		//modified by sarvjeet/prasant on Dec 23, 2011
		// updated by Prashant on DEC 28, 2011
		if($('view_type') == null){
			return;
		}else if($('view_type').value == 'home'){
			resetFilters();
			url = url + "&categoryIdForSession=0"; //only all products filter
			url = url + "&sortingByForSession=" + sortingBy; //when productType is not zero, sorting by must come 
			$('sortingBy').value = sortingBy;
			if(productType != 0){
				url = url + "&productTypeForSession=" + productType;
				$('productType').value =productType;
			}else {
				url = url + "&productTypeForSession=0";
				$('productType').value = 0;
			}
			url = url + "&currentPageForSession=1";
			$(element.id).className = 'pinktext';
			//$(element.id).onclick = null;
			Controller.executeAction("refreshDIVById",div,url,escapeUrl, false, true);
		}else {
			if(catId != undefined){
				resetLinksOnHomePage();
				if(catId == 0){
					if($('all_products') != null){
						$('all_products').className = 'pinktext';
					}
					
				}else {
					if($('anchor_' +catId) != null){
						$('anchor_' +catId).className = 'pinktext';
					}
					
				}
				$('current_cat_id').value = catId;
				url = url + "&categoryIdForSession=" + catId;
				$('current_category').innerHTML = element.innerHTML;
				//for home page, onclick should not work, only href should work
				if(div == 'pagedproductactivities_product'){
					$('dv_categories').style.display = 'none';
					$('dv_filters').style.display = 'none';
					return;
				}
			}else {
				url = url + "&categoryIdForSession=" + $('current_cat_id').value;
				$(element.id).className = 'pinktext';
			}
			
			
			if(sortingBy != undefined) {
				resetFiltersDiv();
				$('sortingBy').value = sortingBy;
				$('filter_' + sortingBy).className = "pinktext";
				url = url + "&sortingByForSession=" + sortingBy;
				$('current_filter').innerHTML = element.innerHTML;
			}else {
				url = url + "&sortingByForSession=" + $('sortingBy').value ; 
				$(element.id).className = 'pinktext';
			}
			if(productType != undefined) {
				resetProductTypesDiv();
				$('productType').value = productType;
				var tempProductType = productType;
				if(productType == -1)tempProductType = 2; //(-1 is not a valid ID)
				$('producttype_' + tempProductType).className = "pinktext";
				url = url + "&productTypeForSession=" + productType;
				$('current_producttype').innerHTML = element.innerHTML;
			}else {
				url = url + "&productTypeForSession=" + $('productType').value ; 
				$(element.id).className = 'pinktext';
			}
	
			url = url + "&currentPageForSession=1";
			
			//$(catId).onclick = null;
			if($('dv_current_producttype') != null)$('dv_current_producttype').onclick = null;
			if($('dv_producttypes') != null)$('dv_producttypes').onmouseout = null;
			if($('dv_producttypes') != null)$('dv_producttypes').style.display = 'none';
	
			$('dv_current_filter').onclick = null;
			$('dv_filters').onmouseout = null;
			$('dv_filters').style.display = 'none';
			
			$('dv_categories').onmouseout = null;
			$('dv_categories').style.display = 'none';
			$('dv_current_category').onclick = null;
			
			Controller.executeAction("refreshDIVById",div,url,escapeUrl);
			
		}
	}
};

Controller.actions.findStoresByFilters = 
{
	type:"js",
	
	js_handler:
	function(div, url, escapeUrl, sortingBy, element)
	{		
		if(sortingBy != undefined) {
			resetFiltersDiv();
			$('sortingBy').value = sortingBy;
			$('filter_' + sortingBy).className = "pinktext";
			url = url + "&sortingBy=" + sortingBy;
			$('current_filter').innerHTML = element.innerHTML;
		}else {
			url = url + "&sortingBy=" + $('sortingBy').value ; 
			$(element.id).className = 'pinktext';
		}
		$('dv_current_filter').onclick = null;
		$('dv_filters').onmouseout = null;
		$('dv_filters').style.display = 'none';
		
		Controller.executeAction("refreshDIVById",div,url,escapeUrl);
		
	}
};


/* added by ashish on 7 aug 2010 */
 
Controller.actions.displayProductDescription = 
{
	type:"js",
	
	js_handler:
	function()
	{
		ActionCommons.showDiv("show_product_desc");
		
	}
};	

Controller.actions.closeProductDescription = 
{
	type:"js",
	
	js_handler:
	function()
	{
		ActionCommons.hideDiv("show_product_desc");
	}
};		

Controller.actions.firstProductVisit = 
{
	type:"js",
	
	js_handler:
	function()
	{
		ActionCommons.hideDiv("userfirstpage_product_overlay");
		//setTimeout("if(typeof(displaySaveOverlay) == 'function')displaySaveOverlay();",5000);
		
	}
}; 

Controller.actions.closeRegistrationVisit = 
{
	type:"js",
	
	js_handler:
	function()
	{
		$('topbar_productsearch_form').className='';
		ActionCommons.hideDiv("joininuser_welcome_overlay");
		Controller.executeAction('setSessionValue');
	}
};

Controller.actions.firstRegistrationVisit = 
{
	type:"js",
	
	js_handler:
	function()
	{
		
		var url = "?mode="+"registration" ;
		var loc = window.location;	
		loc.href = loc.protocol + "//" + loc.host + loc.pathname +  url;
	}
};

Controller.actions.addRegistrationInfo = 
{
	type:"dwr",
		
	arguments:
	["user_aboutme","user_storesFav1","user_storesFav2","user_storesFav3","user_storesFav4","user_storesFav5","user_storesFav6","user_location"],
	
	validators:
	[validateAboutMeText,undefined,undefined,undefined,undefined,undefined,undefined,undefined],

	error_messages:
	["Valid AboutMe","","","","","","",""],
	
	error_target:
	"floating_form_err_txt",
	
	dwr_handler:
	AdministrationHandler.addRegistrationInfo,

	dwr_callback:
	function(user)
	{  			
		if(user != null)
		{
	  		/*if(!user.error)
			{
				throw "profile edit successful";
			}
			else
			{
				throw user.message;
	  		}
	  		*/
	  		//$('topbar_productsearch_form_highlight').className='topbar_productsearch_form_default';
			var url = "?mode="+"registration" ;
			var loc = window.location;	
			loc.href = loc.protocol + "//" + loc.host + loc.pathname +  url;
	  	}
		else
		{
			throw "login error.";
		}	
	}
};

Controller.actions.setSessionValue = 
{
	type:"dwr",

	arguments:
	["attr_name", "attr_value", "attr_type"],
			
	dwr_handler:
	AdministrationHandler.setSessionValue,
	
	dwr_callback:
	function(newVal)
	{
				  			    
	}
};

//for passing parameters inline by the caller
Controller.actions.setSessionValueJS = 
{
	type:"dwr",

	dwr_handler:
	AdministrationHandler.setSessionValue,
	
	dwr_callback:
	function(newVal)
	{
				  			    
	}
};

Controller.actions.relatedCollection=
{
	type:"js",
	
	js_handler:
	function()
	{
		var loc = window.location;
		/*loc.href = loc.protocol + "//" + loc.host + loc.pathname + 
					"?contentaction=listcollectiondetails&userId=" + 
					ActionCommons.getElement("sm_hdn_userid").value + "&id=" + ActionCommons.getElement("sm_hdn_productCollectionId").value;*/
			loc.href=loc.protocol + "//" + loc.host+"/"+"collection"+"/"+ActionCommons.getElement("sm_hdn_productCollectionId").value;			
	}
}

Controller.actions.linkToUpdateFacebookId = 
{
	type:"dwr",
		
	dwr_handler:
	AdministrationHandler.updateUserFacebookId,
	
	dwr_callback:
	function(user)
	{
		if(user != null)
		{
	  		if(!user.error)
			{
				if($('showFaceBookMessage') != null) {
					$('showFaceBookMessage').innerHTML ='';
					ActionCommons.showDiv("showFaceBookMessage");
					$('showFaceBookMessage').innerHTML = "Thanks. We have linked your profile to wanelo.";
				}
				if($('find_facebook_friends') != null){
					Controller.executeAction("refreshDIVById", 'onboard', 'suggestedfriends.action', true, null, true);
				}
			}
			else
			{
				//$('showFaceBookMessage').style.visibility='visible';
				if($('showFaceBookMessage') != null) {
					$('showFaceBookMessage').innerHTML ='';
					ActionCommons.showDiv("showFaceBookMessage");
					$('showFaceBookMessage').innerHTML = "Linking your profile to facebook failed. Please try again.";
				}else {
					throw "facebook linking failed.";
				}
				$('chkFacebook').checked = false;
				
			}
		}	
		else
		{
			throw "facebook error.";
		}		
	}
}
/* added by sudhir on 16 nov 2010 */
Controller.actions.resetHomePageRootCategory = 
{
	type:"js",
	
	js_handler:
	function(div, url, escapeUrl,catId, sortingBy)
	{		
			resetLinksOnHomePage();
			if($(catId)!= null){
				$(catId).className = 'current';
			}
			
			if(sortingBy != undefined) {
				$('sortingBy').value = sortingBy;
			}else {
				url = url + "&sortingBy=" + $('sortingBy').value;
			}
			url = url + "&currentPageForSession=1" + "&sortingByForSession=" +0;
			//$(catId).onclick = null;
			Controller.executeAction("refreshDIVById",div,url,escapeUrl);
	}
};

/* added by ashish on 30 nov 2010 */

Controller.actions.validateUserNameUniqueness = 
{
	type:"js",
		
	error_target:
	"floating_form_err_txt",
	
	js_handler:
	function()
	{
		//ActionCommons.hideDiv('availability_error');
		//ActionCommons.hideDiv('error_highlight leftbtn');
		if(checkUserNameEntered(dojo.string.trim($('registration_dispname').value)) == false)
		{
			throw "Please enter a user name.";
		}
		executeAction('checkAvaliableUserName');
		//enableButton('linkRegisteration', 'JOIN', 'addRegister', true);
	}
};



Controller.actions.checkAvaliableUserName = 
{
	type:"dwr",
		
	arguments:
	["registration_dispname","check_for"], 
	
	validators:
	[undefined],
	
	error_messages:
	[""],
	
	error_target:
	"floating_form_err_txt",
	
	dwr_handler:
	AdministrationHandler.checkForUniqueUserName,
	
	dwr_callback:
	function(user)
	{
		if(user != null)
		{
	  		if(!user.error)
			{
				//$('floating_form_err_txt').style.visibility='visible';
				//$('floating_form_err_txt').innerHTML = "url changed successfully.";
				var loc = window.location;
				//$('homepage_profileurl').href=loc.protocol + "//" + loc.host+"/"+user.userName;
				loc.href=loc.protocol + "//" + loc.host+"/"+user.userName;
			}
			else
			{
				throw user.message;
			}
		}	
		else
		{
			throw "Changeurl error.";
		}		
	}
};

/* added by ashish on 3 dec 2010 to unFollow particular user */
Controller.actions.validateRemoveFollower = 
{
	type:"js",
		
	error_target:
	"floating_form_err_txt",
	
	js_handler:
	function()
	{
		var uId=$("sm_hdn_userid_to").value;
		$('lnkFollowTopMember_'+uId).innerHTML='wait...';
		$('lnkFollowTopMember_'+uId).onclick=null;
		executeAction('removeFollower');
	}
};

Controller.actions.removeFollower = 
{
	type:"dwr",
		
	arguments:
	["sm_hdn_userid_to"], 
		
	validators:
	[undefined],
	
	error_messages:
	[""],
	
	error_target:
	"floating_form_err_txt",
	
	dwr_handler:
	MessageHandler.removeFollower,
	
	dwr_callback:
	function(message)
	{
		if(message == null)
		{	
			var checkFollow=$("checkFollowedCapsValue").value;
			var uId=$("sm_hdn_userid_to").value;
			if(checkFollow == 0)
			{
	  			$('lnkFollowTopMember_'+uId).innerHTML='follow';
	  		}
	  		else
	  		{
	  			$('lnkFollowTopMember_'+uId).innerHTML='FOLLOW';
	  			//window.location.reload();
	  			
	  		}	
	  		if($('lnkFollowTopMember_'+uId).onclick==null)
	  		{
	  			$('lnkFollowTopMember_'+uId).onclick = function (){$('sm_hdn_userid_to').value=uId;executeAction('addMessage');};
	  		}
	  	}
		else
		{
			var uId=$("sm_hdn_userid_to").value;
			$('lnkFollowTopMember_'+uId).innerHTML = "Failed";
			if($('lnkFollowTopMember_'+uId).onclick==null)
	  		{
	  			$('lnkFollowTopMember_'+uId).onclick = function (){$('sm_hdn_userid_to').value=uId;executeAction('validateRemoveFollower');};
	  		}	
		}
	}
};

Controller.actions.onBoardingFilter = 
{
	type:"js",
	
	js_handler:
	function(div, url, escapeUrl, stepId)
	{
			resetBoardingSteps();
			Controller.executeAction("refreshDIVById", div, url, escapeUrl, null, true);
			if(stepId==1)
			{
				$('onboarding_topmembers').className='members_current';
				
				
				$('btn_prev').style.display = 'none';
				$('btn_skip_next').style.display = 'block';
				$('btn_done').style.display = 'none';
				
				$('anchor_skip').href = "javascript:executeAction('onBoardingFilter', 'onboard', 'suggestedfriends.action', true, 2);";
				$('anchor_next').href = "javascript:executeAction('onBoardingFilter', 'onboard', 'suggestedfriends.action', true, 2);";
				
			} else if(stepId== 2)
			{
				$('onboarding_friends').className='friends_current';
				
				$('btn_prev').style.display = 'block';
				$('btn_skip_next').style.display = 'block';
				$('btn_done').style.display = 'none';
				
				$('anchor_btn_prev').href = "javascript:executeAction('onBoardingFilter', 'onboard', 'topmembers.action?mode=onboarding', true, 1);";
				$('anchor_skip').href = "javascript:executeAction('onBoardingFilter', 'onboard', 'userphoto.action', true, 3);";
				$('anchor_next').href = "javascript:executeAction('onBoardingFilter', 'onboard', 'userphoto.action', true, 3);";
				
			}else if(stepId==3)
			{
				$('onboarding_uploadphoto').className='photo_current';
				
				$('btn_prev').style.display = 'block';
				$('btn_skip_next').style.display = 'block';
				$('btn_done').style.display = 'none';
				
				$('anchor_btn_prev').href = "javascript:executeAction('onBoardingFilter', 'onboard', 'suggestedfriends.action', true, 2);";
				$('anchor_skip').href = "javascript:executeAction('onBoardingFilter', 'onboard', 'showbookmarklet.action?viewType=onboard', true, 4);";
				$('anchor_next').href = "javascript:executeAction('onBoardingFilter', 'onboard', 'showbookmarklet.action?viewType=onboard', true, 4);";
			}else if(stepId==4)
			{
				$('onboarding_toolbar').className='toolbar_current';
				
				$('btn_prev').style.display = 'block';
				$('btn_skip_next').style.display = 'none';
				$('btn_done').style.display = 'block';

				$('anchor_btn_prev').href = "javascript:executeAction('onBoardingFilter', 'onboard', 'userphoto.action', true, 3);";
				$('anchor_done').href = "/";
			}
			
	}
};

/* added by ashish on 29 march 2010 */

Controller.actions.validateStoreFollower = 
{
	type:"js",
		
	error_target:
	"floating_form_err_txt",
	
	js_handler:
	function()
	{
		var storeId=$("sm_hdn_storeid").value;
		//$('lnkStoreFollower_'+storeId).innerHTML='wait...';
		//$('lnkStoreFollower_'+storeId).onclick=null;
		disableButton('lnkStoreFollower_'+storeId, 'wait...');
		executeAction('addStoreFollower');
	}
};

Controller.actions.addStoreFollower = 
{
	type:"dwr",
		
	arguments:
	["sm_hdn_storeid","sm_hdn_userid"], 
		
	dwr_handler:
	ProductHandler.addStoreFollower,
	
	dwr_callback:
	function(msg)
	{
		if(msg != null)
		{	
			var checkFollow=$("checkFollowedCapsValue").value;
			var storeId=$("sm_hdn_storeid").value;
			
			//var count=parseInt($("countFollower_"+storeId).value);
			//count = parseInt(count)+1;
			//alert(count);
			var count=parseInt($('followersCount_'+storeId).innerHTML);
			$('followersCount_'+storeId).innerHTML= parseInt(count+1);
			if(checkFollow == 0)
			{
	  			$('lnkStoreFollower_'+storeId).innerHTML='UNFOLLOW';
	  		}
	  		else
	  		{
	  			$('lnkStoreFollower_'+storeId).innerHTML='UNFOLLOW';
	  			//window.location.reload();
	  			
	  		}	
	  		if($('lnkStoreFollower_'+storeId).onclick==null)
	  		{
	  			$('lnkStoreFollower_'+storeId).onclick = function (){$('sm_hdn_storeid').value=storeId;executeAction('validateStoreRemoveFollower');};
	  		}
	  	}
		else
		{
			var storeId=$("sm_hdn_storeid").value;
			$('lnkStoreFollower_'+storeId).innerHTML = "Failed";
			if($('lnkStoreFollower_'+storeId).onclick==null)
	  		{
	  			$('lnkStoreFollower_'+storeId).onclick = function (){$('sm_hdn_storeid').value=storeId;executeAction('validateStoreFollower');};
	  		}	
		}
	}
};
 
Controller.actions.validateStoreRemoveFollower = 
{
	type:"js",
		
	error_target:
	"floating_form_err_txt",
	
	js_handler:
	function()
	{
		var storeId=$("sm_hdn_storeid").value;
		//$('lnkStoreFollower_'+storeId).innerHTML='wait...';
		//$('lnkStoreFollower_'+storeId).onclick=null;
		disableButton('lnkStoreFollower_'+storeId, 'wait...');
		executeAction('removeStoreFollower');
	}
};

Controller.actions.removeStoreFollower = 
{
	type:"dwr",
		
	arguments:
	["sm_hdn_storeid","sm_hdn_userid"], 
		
	dwr_handler:
	ProductHandler.removeStoreFollower,
	
	dwr_callback:
	function(msg)
	{
		if(msg != null)
		{	
			var checkFollow=$("checkFollowedCapsValue").value;
			var storeId=$("sm_hdn_storeid").value;
			var count=parseInt($('followersCount_'+storeId).innerHTML);
			if(count > 0)
			{
				$('followersCount_'+storeId).innerHTML= parseInt(count-1);
			}else{
				$('followersCount_'+storeId).innerHTML=parseInt(count);
			}
			if(checkFollow == 0)
			{
	  			$('lnkStoreFollower_'+storeId).innerHTML='FOLLOW';
	  		}
	  		else
	  		{
	  			$('lnkStoreFollower_'+storeId).innerHTML='FOLLOW';
	  			//window.location.reload();
	  			
	  		}	
	  		if($('lnkStoreFollower_'+storeId).onclick==null)
	  		{
	  			$('lnkStoreFollower_'+storeId).onclick = function (){$('sm_hdn_storeid').value=storeId;executeAction('validateStoreFollower');};
	  		}
	  	}
		else
		{
			var storeId=$("sm_hdn_storeid").value;
			$('lnkStoreFollower_'+storeId).innerHTML = "Failed";
			if($('lnkStoreFollower_'+storeId).onclick==null)
	  		{
	  			$('lnkStoreFollower_'+storeId).onclick = function (){$('sm_hdn_storeid').value=storeId;executeAction('validateStoreRemoveFollower');};
	  		}	
		}
	}
}; 

Controller.actions.validateSubscriber = 
{
	type:"js",
		
	error_target:
	"validation_msg",
	
	js_handler:
	function()
	{
		//ActionCommons.hideDiv('availability_error');
		if(validateRegisterEmail(dojo.string.trim($('txtEmail').value)) == false)
		{
			ActionCommons.showDiv('validation_msg');
			enableButton('lnkSubscribe', 'Subscribe', 'validateSubscriber', false);
			throw "Please enter valid email address.";
		}
		disableButton('lnkSubscribe', 'wait...');
		executeAction('subscribe');
	}
};


Controller.actions.subscribe = 
{
	type:"dwr",
		
	arguments:
	["txtEmail"],
	
	error_target:
	"validation_msg",
	
	dwr_handler:
	AdministrationHandler.addSubscriber,

	dwr_callback:
	function(msg)
	{  			
		ActionCommons.showDiv('validation_msg');
		enableButton('lnkSubscribe', 'Subscribe', 'validateSubscriber', false);
		if(msg != null){
			throw msg;
		}else {
			throw "thank you for subscribing.";
		}
		
	}
};

Controller.actions.toggleStoreType = 
{
	type:"dwr",
	
	error_target:
	"dv_msg",
		
	dwr_handler:
	ProductHandler.updateStoreType,

	dwr_callback:
	function(store)
	{  			
		if(store.error){
			throw store.message;
		}else {
			$('dv_msg').innerHTML = "Store Updated. Products affected:" + store.message;
			$('li_' + store.storeId).innerHTML = store.storeType == 0?'Image':'Store';
			$('a_' + store.storeId).href = "javascript:executeAction('toggleStoreType', " + store.storeId + ", '" + store.siteDomain + "', " + (store.storeType == 0?1:0) + ");";
		}
	}
};

Controller.actions.onsaleProduct = 
{
	type:"dwr",
		
	arguments:
	["onsale_id","onsale_purchaseprice", "onsale_mrp", "onsale_saleprice", "onsale_paypalid"], 
	
	validators:
	[undefined,undefined,undefined,undefined,undefined],
	
	error_messages:
	["","","","",""],
	
	error_target:
	"floating_form_err_txt",


	dwr_handler:
	ProductHandler.saveOnsale,
	
	dwr_callback:
	function(msg)
	{
		if(msg=='')
		{
			Controller.executeAction("closeFloatingForm");
			$('onsale_err_text').style.visibility = 'visible';
			$('onsale_err_text').innerHTML = 'Product has been set on sale.';
		}
		else
		{
			throw msg;
		}
	}
};

Controller.actions.removeOnsale = 
{
	type:"dwr",
		
	arguments:
	["onsale_product_id"], 
	
	validators:
	[undefined],
	
	error_messages:
	[""],
	
	error_target:
	"onsale_err_text",


	dwr_handler:
	ProductHandler.removeOnsale,
	
	dwr_callback:
	function(msg)
	{
		if(msg=='')
		{
			$('onsale_err_text').style.visibility = 'visible';
			$('onsale_err_text').innerHTML = 'Product has been set not on sale.';
		}
		else
		{
			throw msg;
		}
	}
};

Controller.actions.toggleSpammer = 
{
	type:"dwr",
		
	arguments:
	["spammer_user_id", "spammer_current_status"], 
	
	validators:
	[undefined],
	
	error_messages:
	[""],
	
	error_target:
	"onsale_err_text",


	dwr_handler:
	AdministrationHandler.toggleSpammer,
	
	dwr_callback:
	function(msg)
	{
		$('spammer_current_status').value = msg;
		if(msg == 0)
		{
			$('a_spammer').innerHTML = 'Mark as spammer.';
		}
		else
		{
			$('a_spammer').innerHTML = 'Un-mark as spammer.';
		}
	}
};
