/**
 * Useful functions
 * 
 */
fiwe={
	/**
	 * Image replacement function
	 * By PLN@Fiwe 2010-04-16
	 */
	fixImage:function(source, width, height)
	{
		var fuling = 'http://fiwe.scene7.com/is/image/Fiwe/noimage?wid='+width+'&hei='+height+'&resMode=sharp2&op_sharpen=0&op_usm=0.8,0.8,1,0&qlt=82';
/*		var parameters = {};
		parameters.image = 'noimage';
		parameters.width = width;
		parameters.height = height;	
	
		dojo.xhrPost({
			url: getAbsoluteURL() + "s7",				
			handleAs: "json-comment-filtered",
			content: parameters,
			service: this,
			load: function(data){
				console.debug("Replacement Image URL: " + data.image.url);
				source.src = data.image.url; 
			},
			error: function(errObj,ioArgs) {
				console.debug("fiwe.fixImage: Unexpected error occurred during an xhrPost request. Reason: " + errObj);
			}
		});		
*/
		source.src = fuling;
		source.onerror = ""; // prevent endless loop
		return true;
	},
	
	
	signupValidate:function(){
		var id = document.signup.email.id;
		var email = trim(document.signup.email.value);
		reWhiteSpace = new RegExp(/^\s+$/);
		
		if(email == "" || reWhiteSpace.test(email)){
			MessageHelper.formErrorHandleClient(id, MessageHelper.messages["ERROR_EmailEmpty"]);
			return false;
		}
		if(!MessageHelper.isValidUTF8length( email, 256) ){ 
			MessageHelper.formErrorHandleClient(id, MessageHelper.messages["ERROR_EmailTooLong"]);
			return false;
		}
		if(!MessageHelper.isValidEmail(email)){
			MessageHelper.formErrorHandleClient(id, MessageHelper.messages["ERROR_INVALIDEMAILFORMAT"]);
			return false;
		}
	
		document.signup.submit();
	},
	
	/**
	 * PLN/FIWE - Simple ajax pager function (universal!)
	 * Parameters:
	 *   ctx: 			render context
	 *   id: 			id of the control that invoked this function
	 *   beginIndex: 	wich page to load (offset in the listing/result)
	 *   url: 			the url to be loaded (product listing, search result etc..) 
	 */
	ajaxPager:function(ctx, id, beginIndex, url){
		setCurrentId(id);
		wc.render.getContextById(ctx).properties['beginIndex'] = beginIndex; 
		categoryDisplayJS.loadContentURL(url);
	},
	
	CategoryPager:function(id, beginIndex, url) {
		setCurrentId(id);
		wc.render.getContextById('CategoryDisplay_Context').properties['beginIndex'] = beginIndex; 
		categoryDisplayJS.loadContentURL(url);
	},
	
	SearchPager:function(id, beginIndex, url) {
		setCurrentId(id);
		wc.render.getContextById('catalogSearchResultDisplay_Context').properties['searchResultsPageNum'] = beginIndex;
		CatalogSearchDisplayJS.goToResultPage(url);		
	}
}
