/**
 * Output the stars based on the layout 
 * default widht is 80px
 * @param {} rate
 */
function outputStar(rate){
    
	var rate = parseFloat(rate);
	var width = 80 * rate / 5;
	
	return width;
}

/**
 * parse the address and remove useless integer in the front
 * for example: 11431 40 Ave NW Edmonton -> will be parsed to 40 Ave NW Edmonton
 */
function parseaddress(address){
	
	if (address != undefined){
	   var pattern = /(\d+ )\d+ ./g
	   var m = address.match(pattern);

       if (m != null){
    	 m2 = m[0].split(' ');
    	 return address.replace(m2[0], '');
    }
    else return address;
	}
    else return "";
}

/**
 * shorten the url if too long.
 * This is a duplication of outputnames, will be removed later
 * @param {} url
 * @return {}
 */
function outputurl(url){
	if (url != undefined){
	   if (url.length > 25){
	   	   url = url.substring(0, 22) + '...';
	   }
	   
	   return url;
	}
	else return "";
}

function outputnames(name, size){

	if (size == undefined)
	   size = 25;

	if (name != undefined){
	   if (name.length > size){
	   	   name = name.substring(0, size - 3) + '...';
	   }
	   
	   return name;
	}
	else return "";
}
/**
 * replace data and insert dash
 * @param {} data
 * @return {}
 */
function replaceDash(data){
	return data.replace(/\s/g, '-');
}

function addslashes(str) {
   str=str.replace(/\'/g,'\\\'');
   str=str.replace(/\"/g,'\\"');
   str=str.replace(/\\/g,'\\\\');
   str=str.replace(/\0/g,'\\0');
   return str;
}

function stripslashes(str) {
   str=str.replace(/\\'/g,'\'');
   str=str.replace(/\\"/g,'"');
   str=str.replace(/\\\\/g,'\\');
   str=str.replace(/\\0/g,'\0');
   return str;
}

