<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

if ( ! function_exists('formatText'))
{
   function formatText($text)
        {
                $text=html_entity_decode($text, ENT_QUOTES, 'UTF-8');
        	$text=trim(strtolower($text)); 		// Remove spaces from begining and end
        	$text=str_replace(' ','-',$text);	// Replace spaces in between with '-'
        	$text=str_replace(',','-',$text);	// Remove comma from text
                $text=str_replace('&','and',$text);	// Replace & with and
                $text=str_replace(':','',$text);
                $text=str_replace('.','',$text);
                $text=str_replace('/','',$text);
		$text=str_replace('(','-',$text);	// Replace & with and
		$text=str_replace(')','-',$text);	// Replace & with and
                $text=str_replace('---','-',$text);	// Replace & with and
                $text=str_replace('--','-',$text);	// Replace & with and
		if(substr($text, -1)=='-'){ $text=rtrim($text, "-");}
		
     		return $text;
        } 
}
if ( ! function_exists('formatDate'))
{
   function formatDate($datetime)
        {
		$timestamp=strtotime($datetime);
		$day=date('d',$timestamp);
		$time=date('h:i A',$timestamp);
		if($day == date('d')){
			return 'Today,'.$time;
		}elseif($day==date('d',strtotime('-1 day'))){
			return 'Yesterday,'.$time;
		}else{
			return date('d M,Y',$timestamp);
		}	
		
        } 
}
function show_thumb($image_path,$height=100,$width=100,$extra=null,$is_lazyLoad=false) {
	// Get the CodeIgniter super object
    $CI =& get_instance();
    $pathtoimage='assets/adimages/';
    // Path to image thumbnail

    $image_thumb = $pathtoimage.$height . '_' . $width .'_'.$image_path;

    if( ! file_exists($image_thumb))
    {
        // LOAD LIBRARY
        $CI->load->library('image_lib');

        // CONFIGURE IMAGE LIBRARY
        $config['image_library']    = 'gd2';
        $config['source_image']     = $pathtoimage.$image_path;
        $config['new_image']        = $image_thumb;
        $config['maintain_ratio']   = TRUE;
        $config['height']           = $height;
        $config['width']            = $width;
		
        $CI->image_lib->initialize($config);
        $CI->image_lib->resize();
        $CI->image_lib->clear();
    }
	if($is_lazyLoad===true){
		return '<img class="lazy" src="' .base_url().'/assets/images/grey.gif" data-original="' .base_url().$image_thumb . '"  width="200" heigh="200"><noscript><img src="' .base_url().$image_thumb . '" width="200" heigh="200"></noscript>';
	}else{
		return '<img src="' .base_url().$image_thumb . '" '.$extra.'/>';		
	}
}
function generatePassword($length=7) {
            $allowable_characters = '23456789abcdefghjklmnopqrstuvwxyzABCDEFGHJKLMNPRSTUVWXYZ!@()*';
  
            $len = strlen($allowable_characters);
  
            mt_srand((double)microtime() * 1000000);
  
            $log = '';
  
            for ($i = 0; $i < $length; $i++) {
                $log .= $allowable_characters[mt_rand(0, $len - 1)];
            }
            return $log;
        }
function generateVerificationCode($length=7) {
            $allowable_characters = '23456789abcdefghjklmnopqrstuvwxyzABCDEFGHJKLMNPRSTUVWXYZ_-';
  
            $len = strlen($allowable_characters);
  
            mt_srand((double)microtime() * 1000000);
  
            $log = '';
  
            for ($i = 0; $i < $length; $i++) {
                $log .= $allowable_characters[mt_rand(0, $len - 1)];
            }
            return $log;
        }


 
