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.login = 
{
	type:"dwr",
		
	arguments:
	["userlogin_email", "userlogin_password", "userlogin_autologin"],
	
	validators:
	[dojo.validate.isEmailAddress, dojo.validate.isText, 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)
			{
				Controller.executeAction("closeFloatingForm");
				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();	
					
				}
				window.location.reload();		
			}
			else
			{
				var passwordfield = ActionCommons.getElement("userlogin_password");
				if(passwordfield != null)
				{
					passwordfield.value = "";
				}
				
				throw user.message;
	  		}
	  	}
		else
		{
			throw "login error";
		}	
	}
};

Controller.actions.keepalive = 
{
	type:"dwr",
		
	dwr_handler:
	AdministrationHandler.keepAlive,

	dwr_callback:
	function()
	{  			
		
	}
};

/*
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.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,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 + 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
		{
	    	throw message;
	  	}
	}
};

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)
		{
	    	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();
		//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  =  document.getElementById('superTagTypeIds_all');
		}else {
			element  =  document.getElementById('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.getElementById(document.currentSuperTagDivId))
				ActionCommons.hideDiv(document.currentSuperTagDivId);
		}
		ActionCommons.showDiv(divId);
		document.currentSuperTagDivId = divId;
	}
}

Controller.actions.hideallsupertagsdiv=
{
	type:"js",
	
	js_handler:
	function(divId)
	{
		if(document.getElementById(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  =  document.getElementById('superTagTypeIds_all');
		}else {
			element  =  document.getElementById('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)
	{
		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){
			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
		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(document.getElementById(divId)));
	}
};

Controller.actions.upload = 
{
	type:"js",
	
	js_handler:
	function()
	{
		ActionCommons.showDiv("upload_progress");
		ActionCommons.hideDiv("upload_form");
		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;
						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(document.getElementById('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;
				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);
					}
					document.getElementById('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{
					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;
				}
			}
			else
			{
				throw collection.message;
	  		}
	  	}
		else
		{
			throw "unable to create a new collection";
		}
	}
};

Controller.actions.addComment = 
{
	type:"dwr",
		
	arguments:
	["review_id", "comment_text"], 
	
	validators:
	[undefined, dojo.validate.isText],
	
	error_messages:
	[undefined, "Enter Comment"],
	
	error_target:
	"floating_form_err_txt",
	
	dwr_handler:
	ReviewHandler.addComment,
	
	dwr_callback:
	function(message)
	{
		Controller.executeAction("closeFloatingForm");
		ActionCommons.refreshDojoDiv("productreviewhome_reviewcomments");
	}
};

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;	
				loc.href = loc.protocol + "//" + loc.host + loc.pathname + loc.search + "&status=1";				
			}
			else
			{
				throw collection.message;
	  		}
	  	}
		else
		{
			throw "unable to edit the collection";
		}
	}
};

Controller.actions.addProductToCollection = 
{
	type:"dwr",
		
	arguments:
	["product_id","productcollectionid","review_text","hdn_rating","saveproduct_comment"], 
	
	validators:
	[undefined,undefined, validateReviewText, validateAddProductToCollection,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)
			{

				//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(document.getElementById('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(document.getElementById('addproduct_tags').value)).length > 0){
						window.location.reload();
					}
				}
				
				*/


				if( (dojo.string.trim(reviewText)).length > 0){
					if(document.getElementById("productdetail_addreview")){
						ActionCommons.hideDiv("productdetail_addreview");
					}
					if(document.getElementById("review_section")){
						ActionCommons.hideDiv("review_section");
					}
				}
				//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");
				document.getElementById('test_save_button').innerHTML = '<a href="#">SAVED</a>';
			}
			else
			{
				throw product.message;
	  		}
	  	}
		else
		{
			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;
	}
};

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.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 = document.getElementById("sm_hdn_previousmessageid");
				//if(element){
					//if(element.value.length > 0){
						window.location.reload();
					//}
				//}
				
			}			else
			{
			throw message.message;
	  		}
	  	}
		else
		{
			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;
		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{
			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;			
				//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 = document.getElementById("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 = document.getElementById("alertCount");
					if(element){
						element.innerHTML = "(" + val + " alerts)";
					}
				}else {
					var element = document.getElementById("alertCount");
					if(element){
						element.parentNode.removeChild(element);
					}
				}
				
			}
	  	}
	  	
	}
};

Controller.actions.submitSearchForm = 
{
	type:"js",
	
	js_handler:
	function(frm, txt, stat)
	{
		if(!ActionCommons.validateSearchForm(frm, txt, stat))
		{
			throw "Enter Search String";
		}

		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);
		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.edituserprofile = 
{
	type:"dwr",
		
	arguments:
	["user_name","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"],
	
	validators:
	[dojo.validate.isText,"",dojo.validate.isEmailAddress,validateShoppingFavoritesText,undefined,undefined,undefined,undefined,undefined,undefined,validateInterestsText,undefined,validateAboutMeText,checkValidUrl,checkValidUrl,checkValidUrl,checkValidUrl,checkValidUrl,checkValidUrl,checkValidUrl],

	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)
			{
				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)
		{
	  		
				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.sendInvitation = 
{
	type:"dwr",
		
	arguments:
	["email_txtbx", "invite_body"],
	
	validators:
	[validateEmailArray, 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 = document.getElementById("sm_success_msg");
	  		
	  		//if(element)
	  		//{
	  		//	element.innerHTML = message;
	  		//}
	  		element = document.getElementById("email_txtbx");
	  		if(element)
	  		{
	  			element.value = "";
	  		}
	  		element = document.getElementById("floating_form_err_txt");
	  		$('floating_form_err_txt').style.visibility='visible';
	  		if(element)
	  		{
	  			element.innerHTML = message;
	  		}
	  	}
	  	//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"], 
	
	error_target:
	"err_text",
	
	dwr_handler:
	ProductHandler.addProductAndReviewViaUrl,
	
	dwr_callback:
	function(product)
	{
		if(product.error)
		{
	    	var anc = document.getElementById('btnSaveTop');
	    	if(anc){
	    		anc.innerHTML = 'Failed.';
	    	}
	    	anc = document.getElementById('btnSaveBottom');
	    	if(anc){
	    		anc.innerHTML = 'Failed.';
	    	}
	    	throw product.message;
	  	}else{
	  		var element = document.getElementById("productId");
	  		if(element) {
	  			var productId = parseInt(element.value);
	  			if(productId > 0) {
	  				var loc = window.location;	
	  				var url = '?contentaction=productdetails&productId=' + productId + '&p1=0';
					loc.href = loc.protocol + "//" + loc.host + loc.pathname +  url; 
	  			}else {
			  		var collectionId = document.getElementById("collectionId").value;
			  		var userId = document.getElementById("userId").value;
			  		Controller.executeAction("showSubContent",  "listcollectiondetails.action?success=1&amp;id=" + collectionId + "&amp;userId=" + userId + "&mymenu=yes", true);
	  			}
	  		}
	  		else {
		  		var collectionId = document.getElementById("collectionId").value;
		  		var userId = document.getElementById("userId").value;
		  		Controller.executeAction("showSubContent",  "listcollectiondetails.action?success=1&amp;id=" + collectionId + "&amp;userId=" + userId + "&mymenu=yes", 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, checkProductPrice,  undefined, undefined, undefined, undefined, undefined, undefined,undefined],
	
	error_messages:
	["Enter a product title.", "Enter Product Description","Enter Product Minimum Price","","","","", "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(document.getElementById('addproduct_desc').value, f)){
  		//	document.getElementById('addproduct_err_text').innerHTML = "Please reduce the product description to 1000 characters";
  		//	return;
  		//}
  		if(!dojo.validate.isText(document.getElementById('choosephoto_hidden').value) && !dojo.validate.isText(document.getElementById('addproduct_photo_hidden').value) && !dojo.validate.isText(document.getElementById('addproduct_photobyurl_hidden').value)){
  			document.getElementById('addproduct_err_text').innerHTML = "Choose or upload at least one product image!";
  			document.getElementById('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 = document.getElementById("category");
  		if(cat) {
	  		var topCategoryId = cat.options[cat.selectedIndex].value;
  		}else {
	  		var topCategoryId = -1;
  		}


  		//added by sarvjeet on august 27 to submit the form
  		
  		document.getElementById('productTitle').value = document.getElementById("addproduct_title").value;
  		document.getElementById('productDescription').value = document.getElementById("addproduct_desc").value;
  		document.getElementById('collectionId').value = collectionId;
		document.getElementById('collectionName').value = collectionName;
		document.getElementById('topCategoryId').value = topCategoryId;
		document.getElementById('price').value = document.getElementById("addproduct_price").value;
		
		document.getElementById('choosePhoto').value = document.getElementById("choosephoto_hidden").value;
		document.getElementById('uploadPhoto').value = document.getElementById("addproduct_photo_hidden").value;
		document.getElementById('photoName').value = document.getElementById("addproduct_photo").value;
		document.getElementById('productUrl').value = document.getElementById("product_url").value;
		document.getElementById('tags').value = document.getElementById("addproduct_tags").value;
		if(document.getElementById('productComment') != null && document.getElementById('addproduct_comment') != null) {
			document.getElementById('productComment').value = document.getElementById("addproduct_comment").value;
		}
		document.getElementById('imageUploadByUrl').value = document.getElementById('addproduct_photobyurl_hidden').value;
		
		if(document.getElementById('displayUrl') != null && document.getElementById('addproduct_displayurl') != null) {
			document.getElementById('displayUrl').value = document.getElementById("addproduct_displayurl").value;
		}
		
  		var frm = document.getElementById("addproductreview");
  		frm.action = "index.action";
  		frm.method = "post";
  		frm.submit();

		
		return;
  		var url = "addproductreview.action?";
  		url = url + "product=" + escape(document.getElementById("addproduct_title").value) ;
  		url = url + "&amp;productDescription=" + escape(document.getElementById("addproduct_desc").value.replace("\n","<br/>"));
  		url = url + "&amp;collectionId=" + collectionId;
  		url = url + "&amp;collectionName=" + collectionName;
  		url = url + "&amp;categoryId=" + document.getElementById("categoryId").value;
  		url = url + "&amp;topCategoryId=" + topCategoryId;
  		url = url + "&amp;imageUrls=" + escape(document.getElementById("imageUrls").value);
  		url = url + "&amp;price=" + document.getElementById("addproduct_price").value;
  		url = url + "&amp;choosePhoto=" + document.getElementById("choosephoto_hidden").value;
  		url = url + "&amp;uploadPhoto=" + document.getElementById("addproduct_photo_hidden").value;
  		url = url + "&amp;photoName=" + document.getElementById("addproduct_photo").value;
  		url = url + "&amp;productUrl=" + escape(document.getElementById("product_url").value);
  		url = url + "&amp;tags=" + document.getElementById("addproduct_tags").value;
  		url = url + "&amp;reviewText=" + escape(document.getElementById("reviewText").value);
  		url = url + "&amp;reviewRating=" + document.getElementById("reviewRating").value;
  		url = url + "&amp;noReview=" + document.getElementById("noReview").value;
  		Controller.executeAction("showSubContent",  url, true);
	}
};

Controller.actions.addPhotoByUrl = 
{
	type:"js",
		
	error_target:
	"image_uploadbyurl_error",
	
	js_handler:
	function()
	{
		var imageUrl = document.getElementById('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:
	"addproduct_err_text",
	
	dwr_handler:
	ProductHandler.uploadPhotoViaUrl,
	
	dwr_callback:
	function(photo)
	{
		if(photo.error)
		{
	    	throw photo.message;
	  	}else{
	  		showImage(photo.photoUrl, 'uploadedImageByUrlHolder');
	  		setSelectedImage(document.getElementById('uploadedImageByUrlHolder'));
	  		document.getElementById('addproduct_photobyurl_hidden').value = photo.photoUrl;
	  		var link = document.getElementById('lnkAddFile');
	  		if(link) {
	  			link.innerHTML = "Add Image";
	  			link.onclick = function (){executeAction('addPhotoByUrl');};
	  		}
	  	}
	}
};


Controller.actions.productPreview = 
{
	type:"js",
		
	js_handler:
	function()
	{
  		var noReview = document.getElementById("addreview_saveornot0").value;
  		var reviewText = document.getElementById("review_text").value;
  		if(noReview != 'true'){
  			var tempRating = document.getElementById('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 = document.getElementById("productpreview");
  		frm.action = "index.action";
  		frm.method = "post";
  		document.getElementById('reviewText').value = document.getElementById("review_text").value;
  		document.getElementById('reviewRating').value = document.getElementById("hdn_rating").value;
  		document.getElementById('noReview').value = document.getElementById("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(document.getElementById("product").value) ;
  		url = url + "&amp;productDescription=" + escape(document.getElementById("productDescription").value) ;
  		url = url + "&amp;collectionId=" + document.getElementById("collectionId").value ;
  		url = url + "&amp;categoryId=" + document.getElementById("categoryId").value;
  		url = url + "&amp;topCategoryId=" + document.getElementById("topCategoryId").value;
  		url = url + "&amp;imageUrls=" + escape(document.getElementById("imageUrls").value);;
  		url = url + "&amp;price=" + document.getElementById("price").value;
  		url = url + "&amp;choosePhoto=" + document.getElementById("choosePhoto").value;
  		url = url + "&amp;uploadPhoto=" + document.getElementById("uploadPhoto").value;
  		url = url + "&amp;photoName=" + document.getElementById("photoName").value;
  		url = url + "&amp;productUrl=" + escape(document.getElementById("productUrl").value);
  		url = url + "&amp;tags=" + document.getElementById("tags").value;
  		url = url + "&amp;reviewText=" + escape(document.getElementById("review_text").value);
  		url = url + "&amp;reviewRating=" + document.getElementById("hdn_rating").value;
  		url = url + "&amp;noReview=" + document.getElementById("addreview_saveornot0").value;
  		url = url + "&amp;collectionName=" + document.getElementById("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 = document.getElementById("productUrl").value;
  		var userId = document.getElementById("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 = document.getElementById("editproduct");
  		frm.action = "index.action";
  		frm.method = "post";
  		frm.submit();
  		return;
  		
  		var collectionId= document.getElementById("collectionId").value;
  		var collectionName=document.getElementById("collectionName").value;
  		var topCategoryId = document.getElementById("topCategoryId").value;
  		var url = "backToMainPage.action?";
  		url = url + "productTitle=" + escape(document.getElementById("productTitle").value) ;
  		url = url + "&amp;productDescription=" + escape(document.getElementById("productDescription").value.replace("\n","<br/>"));
  		url = url + "&amp;collectionId=" + collectionId;
  		url = url + "&amp;collectionName=" + collectionName;
  		url = url + "&amp;categoryId=" + document.getElementById("categoryId").value;
  		url = url + "&amp;topCategoryId=" + topCategoryId;
  		url = url + "&amp;imageUrls=" + escape(document.getElementById("imageUrls").value);;
  		url = url + "&amp;price=" + document.getElementById("price").value;
  		url = url + "&amp;choosePhoto=" + document.getElementById("choosePhoto").value;
  		url = url + "&amp;uploadPhoto=" + document.getElementById("uploadPhoto").value;
  		url = url + "&amp;photoName=" + document.getElementById("photoName").value;
  		url = url + "&amp;productUrl=" + escape(document.getElementById("productUrl").value);
  		url = url + "&amp;tags=" + document.getElementById("tags").value;
  		url = url + "&amp;reviewText=" + escape(document.getElementById("reviewText").value);
  		url = url + "&amp;reviewRating=" + document.getElementById("reviewRating").value;
  		url = url + "&amp;noReview=" + document.getElementById("noReview").value;
  		Controller.executeAction("showSubContent",  url, true);


		/*
  		var productUrl = document.getElementById("productUrl").value;
  		var userId = document.getElementById("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 = document.getElementById("productpreview");
  		frm.action = "index.action";
  		frm.method = "post";
  		//contentaction is different here
  		document.getElementById('productpreview_contentaction').value = 'backToMainPage';
  		document.getElementById('reviewText').value = document.getElementById("review_text").value;
  		document.getElementById('reviewRating').value = document.getElementById("hdn_rating").value;
  		document.getElementById('noReview').value = document.getElementById("addreview_saveornot0").value;
  		
  		frm.submit();
  		return;


  		var collectionId= document.getElementById("collectionId").value;
  		var collectionName=document.getElementById("collection_name").value;
  		var topCategoryId = document.getElementById("topCategoryId").value;
  		var url = "backToMainPage.action?";
  		url = url + "productTitle=" + escape(document.getElementById("product").value) ;
  		url = url + "&amp;productDescription=" + escape(document.getElementById("productDescription").value.replace("\n","<br/>"));
  		url = url + "&amp;collectionId=" + collectionId;
  		url = url + "&amp;collectionName=" + collectionName;
  		url = url + "&amp;categoryId=" + document.getElementById("categoryId").value;
  		url = url + "&amp;topCategoryId=" + topCategoryId;
  		url = url + "&amp;imageUrls=" + escape(document.getElementById("imageUrls").value);;
  		url = url + "&amp;price=" + document.getElementById("price").value;
  		url = url + "&amp;choosePhoto=" + document.getElementById("choosePhoto").value;
  		url = url + "&amp;uploadPhoto=" + document.getElementById("uploadPhoto").value;
  		url = url + "&amp;photoName=" + document.getElementById("photoName").value;
  		url = url + "&amp;productUrl=" + escape(document.getElementById("productUrl").value);
  		url = url + "&amp;tags=" + document.getElementById("tags").value;
  		url = url + "&amp;reviewText=" + escape(document.getElementById("review_text").value);
  		url = url + "&amp;reviewRating=" + document.getElementById("hdn_rating").value;
  		url = url + "&amp;noReview=" + document.getElementById("addreview_saveornot0").value;
  		Controller.executeAction("showSubContent",  url, true);


		/*
  		var productUrl = document.getElementById("productUrl").value;
  		var userId = document.getElementById("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 = document.getElementById("level");
	  		if(level.value == "1"){
	  			sel = document.getElementById("subCategory");
	  			header = "--Select Subcategory--";
	  		}else {
	  			sel = document.getElementById("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 = document.getElementById("hdnCurrentDivId");
		if(element){
				if(element.value != ""){
					var div = ActionCommons.getElement(element.value);
					if(div) {
						div.style.display = "none";
					}	
				}
		}
		var question = document.getElementById("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 = document.getElementById('floating_form_err_txt');
		var title = document.getElementById('discussion_title').value;
		var text = document.getElementById('discussion_desc').value;
		var msg = validateDiscussionTitle(title);
		if( msg != "" ){ 
			span.style.display = 'block';
			span.innerHTML = msg;
			return false;
		}
		msg = validateDiscussionText(text);
		if( msg != "" ){
			span.style.display = 'block';
			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 = document.getElementById('floating_form_err_txt');
		var text = document.getElementById('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 = document.getElementById('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 = document.getElementById('floating_form_err_txt');
		var failurePost= $('imagepost_failure');
		var successPost= $('imagepost_success');
		failurePost.innerHTML = '';
		successPost.innerHTML='';
		var text = document.getElementById('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(document.getElementById('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)
			{
				document.getElementById('btnAdd').onclick = function () {executeAction('validateCollectionComment')};
				document.getElementById('btnAdd').innerHTML = 'Post';
				//document.getElementById('floating_form_err_txt').style.visibility = 'hidden';
				//increment count
				//alert(document.getElementById('commentcount').value);
				var count = document.getElementById('commentcount').value;
				count = parseInt(count) + 1;
				document.getElementById('commentcount').value = count;
				$('collection_comment').value='Type your comment here...';
				//alert(document.getElementById('commentcount').value);
				document.getElementById('activities_comments_link').innerHTML = 'Comments (' + count + ')';
				Controller.executeAction("refreshDIVById", 'collection_entityactivityhome');				

			}
			else
			{
				/*var span = document.getElementById('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 = document.getElementById('floating_form_err_txt');
		var failurePost= $('imagepost_failure');
		var successPost= $('imagepost_success');
		failurePost.innerHTML = '';
		successPost.innerHTML='';
		var text = document.getElementById('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(document.getElementById('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)
			{
				
				document.getElementById('btnAdd').onclick = function () {executeAction('validateProductComment')};
				document.getElementById('btnAdd').innerHTML = 'Post';
				//document.getElementById('floating_form_err_txt').style.visibility = 'hidden';
				//increment count
				//alert(document.getElementById('commentcount').value);
				var count = document.getElementById('commentcount').value;
				count = parseInt(count) + 1;
				document.getElementById('commentcount').value = count;
				$('product_comment').value='Type your comment here...';
				//alert(document.getElementById('commentcount').value);
				//document.getElementById('activities_comments_link').innerHTML = 'Comments (' + count + ')';
				Controller.executeAction("refreshDIVById", 'collection_entityactivityhome');				

			}
			else
			{
				/*var span = document.getElementById('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 allActivityReload=false;
		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;
				}
				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;
				}	
				if(window.collection_activities_collection == false || !(window.collection_activities_collection) || window.collection_activities_all == undefined){
					window.collection_activities_collection = true;
					reload = true;
				}	
			}
			
		}
		var element = document.getElementById('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
		document.getElementById('collection_save_btn').onclick = null;
		document.getElementById('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)
			{
				document.getElementById('collection_save_btn').innerHTML = 'SAVED';
				var count = document.getElementById('savecount').value;
				count = parseInt(count) + 1;
				document.getElementById('activities_save_link').innerHTML = 'Saves (' + count + ')';
				Controller.executeAction("refreshDIVById", 'collection_entityactivityhome');
			}
			else
			{
				document.getElementById('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 = document.getElementById('floating_form_err_txt');
		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()
	{
		
		var failurePost= $('imagepost_failure');
		var successPost= $('imagepost_success');
		failurePost.innerHTML = '';
		successPost.innerHTML='';
		var text = document.getElementById('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(document.getElementById('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)
			{
				document.getElementById('btnAdd').onclick = function () {executeAction('validateCommunityPhotoComment')};
				document.getElementById('btnAdd').innerHTML = 'Post';
				//document.getElementById('floating_form_err_txt').style.visibility = 'hidden';
				//increment count
				//alert(document.getElementById('commentcount').value);
				//var count = document.getElementById('commentcount').value;
				//count = parseInt(count) + 1;
				//document.getElementById('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 = document.getElementById('floating_form_err_txt');
		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';
	  				}
	  				document.getElementById('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()
	{
		
		var failurePost= $('imagepost_failure');
		var successPost= $('imagepost_success');
		failurePost.innerHTML = '';
		successPost.innerHTML='';
		var text = document.getElementById('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(document.getElementById('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)
			{
				document.getElementById('btnAdd').onclick = function () {executeAction('validateCollectionPhotoComment')};
				document.getElementById('btnAdd').innerHTML = 'Post';
				//document.getElementById('floating_form_err_txt').style.visibility = 'hidden';
				//increment count
				//alert(document.getElementById('commentcount').value);
				//var count = document.getElementById('commentcount').value;
				//count = parseInt(count) + 1;
				//document.getElementById('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.session) {
	      // A user has logged in, and a new cookie has been saved
	      var uid = response.session.uid;
	      var access_token =response.session.access_token;
	      
	      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 {
	      // 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;
					var email = user.email;
					var name = user.userName;
					if(user.message.indexOf('new') != -1){
						//new user - for new registration
						var loc = window.location;	
						loc.href = loc.protocol + "//" + loc.host + loc.pathname + 
									"?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();	
						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.linkFaceBookAccount = 
{
	type:"dwr",
		
	arguments:
	["facebook_email","facebook_username","facebook_id","wanelo_email","wanelo_password"], 
	
	validators:
	[undefined,undefined,undefined,dojo.validate.isEmailAddress,dojo.validate.isText],
	
	error_messages:
	["","","","Enter Email","Enter Password"],
	
	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
			{
				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;
		var allActivitiesReload=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(allActivitiesReload)
				{
					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 = document.getElementById('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 = document.getElementById('floating_form_err_txt');
		var failurePost= $('imagepost_failure');
		var successPost= $('imagepost_success');
		failurePost.innerHTML = '';
		successPost.innerHTML='';
		var productUrl = document.getElementById('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 = document.getElementById("hdn_userid").value;
			var collectionId=document.getElementById("hdn_collectionid").value;
	  		var url = "?contentaction=addproductviaurl&userId=" + userId ;
	  		url = url + "&searchString=" + productUrl +"&collectionId="+collectionId;
			var loc = window.location;	
			loc.href = loc.protocol + "//" + loc.host + loc.pathname +  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)
	{		
			var ul = document.getElementById('catList');
			if(ul) {
				var anchors = ul.getElementsByTagName('a');
				if(anchors) {
					for (var i=0; i<anchors.length; i++) {
						var anchor = anchors[i];
						$(anchor).className = '';
						//$(anchor).onclick = '';
					}
				}
			}
			$('all_products').className = '';
			$(catId).className = 'current';
			//$(catId).onclick = null;
			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");
	}
}; 

Controller.actions.closeRegistrationVisit = 
{
	type:"js",
	
	js_handler:
	function()
	{
		$('topbar_productsearch_form').className='';
		ActionCommons.hideDiv("joininuser_welcome_overlay");
	}
};

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.";
		}	
	}
};
