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

if(!function_exists('getCurrentMerchantId'))
{
    /**
    *@desc Returns Merchant Row ID of the current merchant
    */
    function getCurrentMerchantId()
    {
        $merchantRowID = isset($_SESSION['userId']) ? $_SESSION['userId'] : 0;

        return $merchantRowID ? $merchantRowID : (isset($_SESSION['ship_user_logged_in']) && $_SESSION['merchant_row_id'] ? $_SESSION['merchant_row_id'] : 0);
    }
}

if(!function_exists('isHTTPS'))
{
    /**
    *@desc Checks if the request is made using HTTPS or not
    */
    function isHTTPS()
    {
		if(isset($_SERVER['HTTPS']))
		{
        	return strtolower($_SERVER['HTTPS'])  == 'on';
		}
		return false;
    }
}

if(!function_exists('showToolTipIcon'))
{
    /**
    *@desc Shows tooltips icon with tooltip
    */
    function showToolTipIcon($text) {
        $varUrl = isHTTPS() ? base_url() : non_secure_base_url();
        echo '<img style="vertical-align:middle;" src="'.$varUrl.'images/tooltip_help.gif" width="14" height="14" onmouseover="ddrivetip(\'' . addslashes($text) . '\')" align="top" onmouseout="hideddrivetip()" />';
    }
}

if(!function_exists('showToolTipIconPrivacy'))
{
    function showToolTipIconPrivacy($text) {
        $varUrl = isHTTPS() ? base_url() : non_secure_base_url();
        echo '<img src="'.$varUrl.'images/tooltip.gif" width="44" height="40" onmouseover="ddrivetip(\'' . addslashes($text) . '\')" align="absmiddle" onmouseout="hideddrivetip()" />';
    }
}

if(!function_exists('showToolTipText'))
{
    function showToolTipText($text, $visibleText) {
        echo '<a href="#" onmouseover="ddrivetip(\'' . addslashes($text) . '\')" onmouseout="hideddrivetip()">' . $visibleText . '</a>';
    }
}

if(!function_exists('showToolTipTextOnMouseOver'))
{
    function showToolTipTextOnMouseOver($img, $text)
    {
        $varUrl = isHTTPS() ? base_url() : non_secure_base_url();
        echo '<img src="'.$varUrl.'images/'.$img.'" onmouseover="ddrivetip(\'' . addslashes($text) . '\')" align="top" onmouseout="hideddrivetip()" />';
    }
}

if(!function_exists('showTestMeImage'))
{
	function showTestMeImage()
	{
		$varUrl = isHTTPS() ? base_url() : non_secure_base_url();
		//echo '<img src="' . $varUrl . 'images/product_link/test_me.png" width="76" height="30" alt="Test Me" hspace="5" border="0" align="top" onmouseover="this.src=\''.$varUrl.'images/product_link/test_me_hover.png\';" onmouseout="this.src=\''.$varUrl.'images/product_link/test_me.png\';" />';
        echo '<img src="' . $varUrl . 'images/product_link/test_me.png" width="76" height="30" alt="Test Me" hspace="5" border="0" align="top" onmouseover="this.src=\''.$varUrl.'images/product_link/test_me.png\';" onmouseout="this.src=\''.$varUrl.'images/product_link/test_me.png\';" />';
	}
}

if(!function_exists('isPostBack'))
{
    function isPostBack()
    {
        return $_SERVER['REQUEST_METHOD'] == 'POST';
    }
}

if(!function_exists('message'))
{
    /**
    *@desc Shows a success message
    */
    function message($message)
    {
        $_SESSION['message'] = $message;
    }
}

if(!function_exists('exception'))
{
    /**
    *@desc Shows an error message
    */
    function exception($message)
    {
        $_SESSION['exception'] = $message;
    }
}

if(!function_exists('unsetException'))
{
    /**
    *@desc Unsets the exception message
    */
    function unsetException()
    {
        unset($_SESSION['exception']);
    }
}

if(!function_exists('notification'))
{
    function notification($message)
    {
        $_SESSION['notification'] = $message;
    }
}

if(!function_exists('dumpVar'))
{
    function dumpVar($data, $exit = true, $isXML = false)
    {
        $data = print_r($data, true);

        if($isXML)
        {
            header('Content-type: text/xml');
            echo $data;
        }
        else
        {
            echo '<pre>' . $data . '</pre>';
        }

        if($exit)
        {
            exit();
        }
    }
}

if(!function_exists('divCalendarDependencies'))
{
    function divCalendarDependencies($url)
	{
		echo '<script language="JavaScript" src="' . $url . 'scripts/tigra_calendar/calendar_us.js"></script>
		<link rel="stylesheet" href="' . $url . 'scripts/tigra_calendar/calendar.css">';
	}
}

if(!function_exists('divCalendar'))
{
    function divCalendar($formName, $controlName, $attributes = '')
    {
        echo '<input type="text" name="' . $controlName . '" '  . $attributes . ' maxlength="10" />
			<script language="JavaScript">
            new tcal ({
                \'formname\': \'' . $formName . '\',
                \'controlname\': \'' . $controlName . '\'
            });
			</script>';
    }
}

if(!function_exists('convertUSDateToDBDate'))
{
    //recieve date in mm-dd-yyyy format and output yyyy-mm-dd
    function convertUSDateToDBDate($date)
    {
        if($date)
        {
            $date = substr($date,6,4) . '-' . substr($date,0,2) . '-' . substr($date,3,2);
        }
        else
        {
            $date = '0000-00-00';
        }

        return $date;
    }
}

if(!function_exists('setFormattedDate'))
{
    function setFormattedDate($date)
    {
        //recieve date in dd-mm-yyyy format and output yyyy-mm-dd
        $fdate = substr($date,6,4) . '-' . substr($date,3,2) . '-' . substr($date,0,2);
        return $fdate;
    }
}

if(!function_exists('getFormattedDate'))
{
    function getFormattedDate($date)
    {
        //recieve date in yyyy-mm-dd format and output dd-mm-yyyy
        $fdate = substr($date,8,2) . '-' . substr($date,5,2) . '-' . substr($date,0,4);
        return $fdate;
    }
}

if(!function_exists('getPreviousMonths'))
{
    function getPreviousMonths($name_of_the_month, $number)
    {
        $return_array=array();        //Return Month Specific list
        $aMonth=array("January", "February", "March", "April", "May", "June",
                     "July", "August", "September", "October", "November", "December",
                     "January", "February", "March", "April", "May", "June",
                     "July", "August", "September", "October", "November", "December");// Contain All month formate
        for ($i=12; $i<=24; $i++)
        {
            if($aMonth[$i]==$name_of_the_month)
            {
                $end_index=$i;
                break;
            }
        }
        $start_index=$end_index-$number;
		$j = 0;
        for($i=$start_index;$i<$end_index;$i++,$j++)
        {
            $return_array[$j]=$aMonth[$i];
        }
        return $return_array;
    }
}

if(!function_exists('getNextMonths'))
{
    function getNextMonths($name_of_the_month, $number, $includeCurrentMonth = false)
    {
        $return_array=array();        //Return Month Specific list
        $aMonth=array("January", "February", "March", "April", "May", "June",
                     "July", "August", "September", "October", "November", "December",
                     "January", "February", "March", "April", "May", "June",
                     "July", "August", "September", "October", "November", "December");// Contain All month formate



        for ($i=1; $i<=12; $i++)
        {
            if($aMonth[$i] == $name_of_the_month)
            {
                if($includeCurrentMonth)
                {
                    $start_index = $i;
                }
                else
                {
                    $start_index = $i+1;
                }
                $end_index = $start_index  + $number;
                break;
            }
        }

        $j = 0;
        for($i=$start_index;$i<$end_index;$i++,$j++)
        {
            $return_array[$j]=$aMonth[$i];
        }
        return $return_array;
    }
}

if(!function_exists('getCountryList'))
{
    function getCountryList()
    {
        return array(   'US' => 'United States',
                        'GB' => 'United Kingdom',
                        'CA' => 'Canada',
                        'AU' => 'Australia',
                        'AL' => 'Albania',
                        'DZ' => 'Algeria',
                        'AS' => 'American Samoa',
                        'AD' => 'Andorra',
                        'AO' => 'Angola',
                        'AI' => 'Anguilla',
                        'AQ' => 'Antarctica',
                        'AG' => 'Antigua And Barbuda',
                        'AR' => 'Argentina',
                        'AM' => 'Armenia',
                        'AW' => 'Aruba',
                        'AT' => 'Austria',
                        'AZ' => 'Azerbaijan',
                        'BS' => 'Bahamas',
                        'BH' => 'Bahrain',
                        'BD' => 'Bangladesh',
                        'BB' => 'Barbados',
                        'BY' => 'Belarus',
                        'BE' => 'Belgium',
                        'BZ' => 'Belize',
                        'BJ' => 'Benin',
                        'BM' => 'Bermuda',
                        'BT' => 'Bhutan',
                        'BO' => 'Bolivia',
                        'BA' => 'Bosnia And Herzegovina',
                        'BW' => 'Botswana',
                        'BV' => 'Bouvet Island',
                        'BR' => 'Brazil',
                        'IO' => 'British Indian Ocean Territory',
                        'BN' => 'Brunei Darussalam',
                        'BG' => 'Bulgaria',
                        'BF' => 'Burkina Faso',
                        'BI' => 'Burundi',
                        'KH' => 'Cambodia',
                        'CM' => 'Cameroon',
                        'CV' => 'Cape Verde',
                        'KY' => 'Cayman Islands',
                        'CF' => 'Central African Republic',
                        'TD' => 'Chad',
                        'CL' => 'Chile',
                        'CN' => 'China',
                        'CX' => 'Christmas Island',
                        'CC' => 'Cocos (Keeling) Islands',
                        'CO' => 'Colombia',
                        'KM' => 'Comoros',
                        'CG' => 'Congo',
                        'CD' => 'Congo ; The Dem. Rep. Of The',
                        'CK' => 'Cook Islands',
                        'CR' => 'Costa Rica',
                        'CI' => 'Cote D\'ivoire',
                        'HR' => 'Croatia',
                        'CY' => 'Cyprus',
                        'CZ' => 'Czech Republic',
                        'DK' => 'Denmark',
                        'DJ' => 'Djibouti',
                        'DM' => 'Dominica',
                        'DO' => 'Dominican Republic',
                        'TP' => 'East Timor',
                        'EC' => 'Ecuador',
                        'EG' => 'Egypt',
                        'SV' => 'El Salvador',
                        'GQ' => 'Equatorial Guinea',
                        'ER' => 'Eritrea',
                        'EE' => 'Estonia',
                        'ET' => 'Ethiopia',
                        'FK' => 'Falkland Islands (Malvinas)',
                        'FO' => 'Faroe Islands',
                        'FJ' => 'Fiji',
                        'FI' => 'Finland',
                        'FR' => 'France',
                        'GF' => 'French Guiana',
                        'PF' => 'French Polynesia',
                        'TF' => 'French Southern Territories',
                        'GA' => 'Gabon',
                        'GM' => 'Gambia',
                        'GE' => 'Georgia',
                        'DE' => 'Germany',
                        'GH' => 'Ghana',
                        'GI' => 'Gibraltar',
                        'GR' => 'Greece',
                        'GL' => 'Greenland',
                        'GD' => 'Grenada',
                        'GP' => 'Guadeloupe',
                        'GU' => 'Guam',
                        'GT' => 'Guatemala',
                        'GN' => 'Guinea',
                        'GW' => 'Guinea-Bissau',
                        'GY' => 'Guyana',
                        'HT' => 'Haiti',
                        'HM' => 'Heard Island And Mcdonald Islands',
                        'VA' => 'Holy See (Vatican City State)',
                        'HN' => 'Honduras',
                        'HK' => 'Hong Kong',
                        'HU' => 'Hungary',
                        'IS' => 'Iceland',
                        'IN' => 'India',
                        'ID' => 'Indonesia',
                        'IE' => 'Ireland',
                        'IL' => 'Israel',
                        'IT' => 'Italy',
                        'JM' => 'Jamaica',
                        'JP' => 'Japan',
                        'JO' => 'Jordan',
                        'KZ' => 'Kazakstan',
                        'KE' => 'Kenya',
                        'KI' => 'Kiribati',
                        'KW' => 'Kuwait',
                        'KG' => 'Kyrgyzstan',
                        'LA' => 'Lao People\'s Democratic Republic',
                        'LV' => 'Latvia',
                        'LB' => 'Lebanon',
                        'LS' => 'Lesotho',
                        'LY' => 'Libya',
                        'LI' => 'Liechtenstein',
                        'LT' => 'Lithuania',
                        'LU' => 'Luxembourg',
                        'MO' => 'Macau',
                        'MK' => 'Macedonia',
                        'MG' => 'Madagascar',
                        'MW' => 'Malawi',
                        'MY' => 'Malaysia',
                        'MV' => 'Maldives',
                        'ML' => 'Mali',
                        'MT' => 'Malta',
                        'MH' => 'Marshall Islands',
                        'MQ' => 'Martinique',
                        'MR' => 'Mauritania',
                        'MU' => 'Mauritius',
                        'YT' => 'Mayotte',
                        'MX' => 'Mexico',
                        'FM' => 'Micronesia; Federated States Of',
                        'MD' => 'Moldova; Republic Of',
                        'MC' => 'Monaco',
                        'MN' => 'Mongolia',
                        'MS' => 'Montserrat',
                        'MA' => 'Morocco',
                        'MZ' => 'Mozambique',
                        'NA' => 'Namibia',
                        'NR' => 'Nauru',
                        'NP' => 'Nepal',
                        'NL' => 'Netherlands',
                        'AN' => 'Netherlands Antilles',
                        'NC' => 'New Caledonia',
                        'NZ' => 'New Zealand',
                        'NI' => 'Nicaragua',
                        'NE' => 'Niger',
                        'NG' => 'Nigeria',
                        'NU' => 'Niue',
                        'NF' => 'Norfolk Island',
						'KP' => 'North Korea',
                        'MP' => 'Northern Mariana Islands',
                        'NO' => 'Norway',
                        'OM' => 'Oman',
                        'PK' => 'Pakistan',
                        'PW' => 'Palau',
                        'PS' => 'Palestinian Territory; Occupied',
                        'PA' => 'Panama',
                        'PG' => 'Papua New Guinea',
                        'PY' => 'Paraguay',
                        'PE' => 'Peru',
                        'PH' => 'Philippines',
                        'PN' => 'Pitcairn',
                        'PL' => 'Poland',
                        'PT' => 'Portugal',
                        'PR' => 'Puerto Rico',
                        'QA' => 'Qatar',
                        'RE' => 'Reunion',
                        'RO' => 'Romania',
                        'RU' => 'Russian Federation',
                        'RW' => 'Rwanda',
                        'SH' => 'Saint Helena',
                        'KN' => 'Saint Kitts And Nevis',
                        'LC' => 'Saint Lucia',
                        'PM' => 'Saint Pierre And Miquelon',
                        'VC' => 'Saint Vincent And The Grenadines',
                        'WS' => 'Samoa',
                        'SM' => 'San Marino',
                        'ST' => 'Sao Tome And Principe',
                        'SA' => 'Saudi Arabia',
                        'SN' => 'Senegal',
                        'SC' => 'Seychelles',
                        'SG' => 'Singapore',
                        'SK' => 'Slovakia',
                        'SI' => 'Slovenia',
                        'SB' => 'Solomon Islands',
                        'SO' => 'Somalia',
                        'ZA' => 'South Africa',
                        'GS' => 'South Georgia / South Sandwich Islands',
						'KR' => 'South Korea',
                        'ES' => 'Spain',
                        'LK' => 'Sri Lanka',
                        'SR' => 'Suriname',
                        'SJ' => 'Svalbard And Jan Mayen',
                        'SZ' => 'Swaziland',
                        'SE' => 'Sweden',
                        'CH' => 'Switzerland',
                        'SY' => 'Syrian Arab Republic',
                        'TW' => 'Taiwan',
                        'TJ' => 'Tajikistan',
                        'TZ' => 'Tanzania; United Republic Of',
                        'TH' => 'Thailand',
                        'TG' => 'Togo',
                        'TK' => 'Tokelau',
                        'TO' => 'Tonga',
                        'TT' => 'Trinidad And Tobago',
                        'TN' => 'Tunisia',
                        'TR' => 'Turkey',
                        'TM' => 'Turkmenistan',
                        'TC' => 'Turks And Caicos Islands',
                        'TV' => 'Tuvalu',
                        'UG' => 'Uganda',
                        'UA' => 'Ukraine',
                        'AE' => 'United Arab Emirates',
                        'UM' => 'United States Minor Outlying Islands',
                        'UY' => 'Uruguay',
                        'UZ' => 'Uzbekistan',
                        'VU' => 'Vanuatu',
                        'VE' => 'Venezuela',
                        'VN' => 'Viet Nam',
                        'VG' => 'Virgin Islands; British',
                        'VI' => 'Virgin Islands; U.S.',
                        'WF' => 'Wallis And Futuna',
                        'EH' => 'Western Sahara',
                        'YE' => 'Yemen',
                        'YU' => 'Yugoslavia',
                        'ZM' => 'Zambia'
                    );

    }
}

if(!function_exists('getStateList'))
{
    function getStateList($country = 'US')
    {

			if ($country == 'CA'){

        return array(   'AB' => 'Alberta',
                        'BC' => 'British Columbia',
                        'MB' => 'Manitoba',
                        'NB' => 'New Brunswick',
                        'NL' => 'Newfoundland and Labrador',
                        'NT' => 'Northwest Territories',
                        'NS' => 'Nova Scotia',
                        'NU' => 'Nunavut',
                        'ON' => 'Ontario',
                        'PE' => 'Prince Edward Island',
                        'QC' => 'Quebec',
                        'SK' => 'Saskatchewan',
                        'YT' => 'Yukon');

			} else { // default = USA

        return array(   'AL' => 'Alabama',
                        'AK' => 'Alaska',
                        'AS' => 'American Samoa',
                        'AZ' => 'Arizona',
                        'AR' => 'Arkansas',
                        'CA' => 'California',
                        'CO' => 'Colorado',
                        'CT' => 'Connecticut',
                        'DE' => 'Delaware',
                        'DC' => 'District of Columbia',
                        'FM' => 'Federated States of Micronesia',
                        'FL' => 'Florida',
                        'GA' => 'Georgia',
                        'GU' => 'Guam',
                        'HI' => 'Hawaii',
                        'ID' => 'Idaho',
                        'IL' => 'Illinois',
                        'IN' => 'Indiana',
                        'IA' => 'Iowa',
                        'KS' => 'Kansas',
                        'KY' => 'Kentucky',
                        'LA' => 'Louisiana',
                        'ME' => 'Maine',
                        'MH' => 'Marshall Islands',
                        'MD' => 'Maryland',
                        'MA' => 'Massachusetts',
                        'MI' => 'Michigan',
                        'MN' => 'Minnesota',
                        'MS' => 'Mississippi',
                        'MO' => 'Missouri',
                        'MT' => 'Montana',
                        'NE' => 'Nebraska',
                        'NV' => 'Nevada',
                        'NH' => 'New Hampshire',
                        'NJ' => 'New Jersey',
                        'NM' => 'New Mexico',
                        'NY' => 'New York',
                        'NC' => 'North Carolina',
                        'ND' => 'North Dakota',
                        'MP' => 'Northern Mariana Islands',
                        'OH' => 'Ohio',
                        'OK' => 'Oklahoma',
                        'OR' => 'Oregon',
                        'PW' => 'Palau',
                        'PA' => 'Pennsylvania',
                        'PR' => 'Puerto Rico',
                        'RI' => 'Rhode Island',
                        'SC' => 'South Carolina',
                        'SD' => 'South Dakota',
                        'TN' => 'Tennessee',
                        'TX' => 'Texas',
                        'UT' => 'Utah',
                        'VT' => 'Vermont',
                        'VI' => 'Virgin Islands',
                        'VA' => 'Virginia',
                        'WA' => 'Washington',
                        'WV' => 'West Virginia',
                        'WI' => 'Wisconsin',
                        'WY' => 'Wyoming');
   		} // else
    }
}

if(!function_exists('getCountryFullName'))
{
    function getCountryFullName($abbr)
    {
        if(strlen($abbr) == 2)
        {
            $countries = getCountryList();

            return isset($countries[$abbr]) ? $countries[$abbr] : '';
        }
        return $abbr;
    }
}

if(!function_exists('getStateFullName'))
{
    function getStateFullName($abbr, $country='US')
    {
		if(strlen($abbr) == 2)
		{
			$abbr = strtoupper($abbr);
        	$states = getStateList($country);

	        return isset($states[$abbr]) ? $states[$abbr] : '';
		}
		return $abbr;
    }
}

if(!function_exists('getDateFormat'))
{
    function getDateFormat($format)
    {
        $CI = get_instance();
        switch($format)
        {
            case '1':
                return $CI->config->item('mer_date_format_1');
            case '2':
                return $CI->config->item('mer_date_format_2');
            case '3':
                return $CI->config->item('mer_date_format_3');
            case '4':
                return $CI->config->item('mer_date_format_4');
            case '5':
                return $CI->config->item('mer_date_format_5');
            case '6':
                return $CI->config->item('mer_date_format_6');
            case '7':
                return $CI->config->item('mer_date_format_7');
            case '8':
                return $CI->config->item('mer_date_format_8');
            default:
                return $CI->config->item('show_mysql_timestamp_fmt');
        }
    }
}

if(!function_exists('getGatewayName'))
{
    function getGatewayName($gatewayId)
    {
        $CI =& get_instance();

        switch($gatewayId)
        {
            case $CI->config->item('payment_gateway_paypal'):
                return 'PayPal Standard';
            case $CI->config->item('payment_gateway_authorize_dot_net'):
                return 'Authorize.net';
            case $CI->config->item('payment_gateway_paypal_website_payment_pro'):
                return 'PayPal Website Payment Pro';
            case $CI->config->item('payment_gateway_first_data'):
                return 'First Data';
        }
    }
}

if(!function_exists('getJSDateFormat'))
{
    function getJSDateFormat($format)
    {
        $CI = get_instance();
        switch($format)
        {
            case $CI->config->item('mer_date_format_1'):
            case $CI->config->item('mer_date_format_3'):
                 return  'mm-dd-yy';
            case $CI->config->item('mer_date_format_2'):
            case $CI->config->item('mer_date_format_4'):
                 return 'dd-mm-yy';
            case $CI->config->item('mer_date_format_5'):
            case $CI->config->item('mer_date_format_7'):
                return 'mm/dd/yy';
            case $CI->config->item('mer_date_format_6'):
            case $CI->config->item('mer_date_format_8'):
                return 'dd/mm/yy';
        }
        return 'mm-dd-yy';
    }
}

if(!function_exists('getPHPDateFormat'))
{
    function getPHPDateFormat($format)
    {
        $CI = get_instance();
        switch($format)
        {
            case $CI->config->item('mer_date_format_1'):
            case $CI->config->item('mer_date_format_3'):
                 return  'm-d-Y';
            case $CI->config->item('mer_date_format_2'):
            case $CI->config->item('mer_date_format_4'):
                 return 'd-m-Y';
            case $CI->config->item('mer_date_format_5'):
            case $CI->config->item('mer_date_format_7'):
                return 'm/d/Y';
            case $CI->config->item('mer_date_format_6'):
            case $CI->config->item('mer_date_format_8'):
                return 'd/m/Y';
        }
        return 'm-d-Y';
    }
}

if(!function_exists('commonDateFormat'))
{
    function commonDateFormat($date, $dateFormat)
    {
        if($date && $dateFormat)
        {
            switch($dateFormat)
            {
                case 'mm-dd-yy':
                  //mm-dd-yy to yy-mm-dd
                  $date = substr($date,6,4) . '-' . substr($date,0,2) . '-' . substr($date,3,2);
                  break;
                case 'dd-mm-yy':
                  //dd-mm-yy to yy-mm-dd
                  $date = substr($date,6,4) . '-' . substr($date,3,2) . '-' . substr($date,0,2);
                  break;
                case 'mm/dd/yy':
                  //mm/dd/yy to yy-mm-dd
                  $date = substr($date,6,4) . '-' . substr($date,0,2) . '-' . substr($date,3,2);
                  break;
                case 'dd/mm/yy':
                  //dd/mm/yy to yy-mm-dd
                  $date = substr($date,6,4) . '-' . substr($date,3,2) . '-' . substr($date,0,2);
            }
        }
        else
        {
            $date = '';
        }
        return $date;
    }
}

if(!function_exists('basicDateFormat'))
{
    function basicDateFormat($format)
    {
        $CI = get_instance();
        switch($format)
        {
            case $CI->config->item('mer_date_format_1'):
            case $CI->config->item('mer_date_format_3'):
                 return  '%m-%d-%Y';
            case $CI->config->item('mer_date_format_2'):
            case $CI->config->item('mer_date_format_4'):
                 return '%d-%m-%Y';
            case $CI->config->item('mer_date_format_5'):
            case $CI->config->item('mer_date_format_7'):
                return '%m/%d/%Y';
            case $CI->config->item('mer_date_format_6'):
            case $CI->config->item('mer_date_format_8'):
                return '%d/%m/%Y';
        }
        return '%m-%d-%Y';

    }
}

if(!function_exists('generateProductCheckoutCss'))
{
    /**
     * Product Look And Feel CSS generation for Checkout Page
     * author Tania Noor
     */
    function generateProductCheckoutCss($data)
    {
        $cssText = '';
        if($data['background_color'])
        {
            $cssText .= 'background-color:#'. $data['background_color'] .';';
        }
        if($data['font_family'])
        {
            $cssText .= 'font-family:'. $data['font_family'].';';
        }
        if($data['font_color'])
        {
            $cssText .= 'color:#'. $data['font_color'].';';
        }

        if($data['background_image'])
        {
            $cssText .= 'background-image:url('. (isHTTPS() ? BASEURL : NONSECUREBASEURL).$data['background_image'] . ');';
        }
        if($cssText != '')
        {
            $return = 'body{ font-size:11px;'.$cssText . '}';
        }
        else
        {
            $return = '';
        }
        return $return;
    }
}

if(!function_exists('getHTTPReferer'))
{
    /**
    *@desc Returns the referer URL
    */
    function getHTTPReferer()
    {
		return isset($_SERVER['HTTP_REFERER']) ? trim($_SERVER['HTTP_REFERER']) : '';
	}
}

if(!function_exists('assignVariables'))
{
    function assignVariables($dataArray, $varArray)
    {
        if(is_array($dataArray))
        {
            if(is_array($varArray) && count($varArray))
            {
                foreach($varArray as $var)
                {
                    if(!isset($dataArray[$var]))
                    {
                        $dataArray[$var] = '';
                    }
                }
            }
        }
        return $dataArray;
    }
}

if(!function_exists('assignProperties'))
{
    function assignProperties($object, $varArray)
    {
        if(is_array($varArray) && count($varArray))
        {
            foreach($varArray as $var)
            {
                if(!isset($object->$var))
                {
                    $object->$var = '';
                }
            }
        }

        return $object;
    }
}

if(!function_exists('assignObjects'))
{
    function assignObjects($dataArray, $varArray)
    {
        if(is_array($dataArray))
        {
            if(is_array($varArray) && count($varArray))
            {
                foreach($varArray as $var)
                {
                    if(!(isset($dataArray[$var]) && is_object($dataArray[$var])))
                    {
                        $dataArray[$var] = new stdClass();
                    }
                }
            }
        }
        return $dataArray;
    }
}

if(!function_exists('assignIndices'))
{
    function assignIndices($dataArray, $arrayName, $varArray)
    {
        if($arrayName)
        {
            if(is_array($varArray) && count($varArray))
            {
                foreach($varArray as $var)
                {
                    if(!isset($dataArray[$arrayName][$var]))
                    {
                        $dataArray[$arrayName][$var] = '';
                    }
                }
            }
        }

        return $dataArray;
    }
}

if(!function_exists('captchaOutput'))
{
    /**
    *@desc This function uses Rapyds captcha library and outputs a captcha field
    */
    function captchaOutput()
    {
        $CI = get_instance();
        $CI->load->library('rapyd');
        $CI->rapyd->load ( "fields" );
        $captcha = new captchaField ( 'Verification text', 'v_text' );
        $captcha->required = "1";
        $captcha->maxlength = "4";
        $captcha->minlength = "4";
        $captcha->err = "Please enter the characters from the displayed image";
        $captcha->status = 'create';
        $captcha->build ();
        return $captcha->output;
    }
}

if(!function_exists('showVideoIcon'))
{
    function showVideoIcon($link, $top, $left, $isSmall = false, $secure = true)
    {
        $vidImageId = 'vidImage'.rand(111, 999);
        $url = ($secure ? BASEURL : NONSECUREBASEURL) . 'images/';
        $img =  $url . ($isSmall ? 'ico-video.gif' : 'vid_icon_n.png');
        $imgHover = $url . ($isSmall ? 'ico-video-h.gif' : 'vid_icon_h.png');

        $style = $top || $left ? 'style="font-family: Arial, Helvetica, sans-serif; font-size: 13px; color: #0063A9; position:absolute; top:' . $top . 'px;left:'.$left.'px;"' : '';

        echo '<script language="javascript">$("document").ready(function(){MM_preloadImages("'.$imgHover.'");});</script>';
        echo '<a href="'.$link.'" '.$style.' title="See this step - Click Here" target="_blank" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage(\''.$vidImageId.'\',\'\',\''.$imgHover.'\',1)"><img id="'.$vidImageId.'" src="'.$img.'" border="0" style="vertical-align:middle; margin-top:-5px" /> Click Here</a>';
    }
}

if(!function_exists('getCurrentAdminId'))
{
    function getCurrentAdminId()
    {
        return isset($_SESSION['adminUserId']) ? $_SESSION['adminUserId'] : 0;
    }
}

if(!function_exists('processThankYouUrl'))
{
    function processThankYouUrl($thank_you_url, $order_id, $affiliate_id = 0)
    {
        log_general('PROCESS URl: ' . $thank_you_url);

        $isUrlToSecureInfoSSL = (bool) strpos($thank_you_url, 'secureinfossl');
        $isUrlToPWCMembers = (bool) strpos($thank_you_url, 'pwcmembers.com');

        //check whether this is secureinfossl thank you url
        if($isUrlToSecureInfoSSL || $isUrlToPWCMembers)
        {
            if($isUrlToPWCMembers)
            {
                $CI = get_instance();
                $CI->load->model('merchant/Merchant_model', '', true);
                $merchant_id = $CI->Merchant_model->getMerchantIDByOrderRowID($order_id);
                $url = $thank_you_url.'/'.$order_id.'/'.$merchant_id;
                //If you want to send to member pro
                /*
                if($affiliate_id)
                    $url .= '/'.$affiliate_id;
                */
            }
            else
            {
                $url = $thank_you_url . '/'.$order_id;
                if($affiliate_id)
                    $url .= '/' . $affiliate_id;
            }
        }
        else if(strpos($thank_you_url,'?'))
        {
            $url = $thank_you_url . '&oid=' . $order_id;

            $counter = 1;
            if(isset($_SESSION['processed_order']))
            {
                foreach($_SESSION['processed_order'] as $oid)
                {
                    $url .= '&oid' . $counter . '=' . $oid;
                    $counter++;
                }
            }
            if($affiliate_id)
                $url .= '&aid=' . $affiliate_id;
        }
        else
        {
            $url = $thank_you_url . '?oid=' . $order_id;

            $counter = 1;
            if(isset($_SESSION['processed_order']))
            {
                foreach($_SESSION['processed_order'] as $oid)
                {
                    $url .= '&oid' . $counter . '=' . $oid;
                    $counter++;
                }
            }
            if($affiliate_id)
                $url .= '&aid=' . $affiliate_id;
        }
        log_general('PROCESSED URl: ' . $url);
        return $url;
    }
}

if(!function_exists('getCurrencySymbol'))
{
	function getCurrencySymbol()
	{
		return isset($_SESSION['currency_symbol']) ? $_SESSION['currency_symbol'] : '';
	}
}

if(!function_exists('uploadImageIcon'))
{
    function uploadImageIcon($imagerPath,$secure = true)
    {
        $url = ($secure ? BASEURL : NONSECUREBASEURL);
        $img =  $url . $imagerPath;
		echo '<img border=0 src="'.$img .'" alt=""/>';
    }
}

if(!function_exists('getCurrentDateTimeForDB'))
{
    function getCurrentDateTimeForDB()
    {
        return date('Y-m-d H:i:s');
    }
}

if(!function_exists('generateSaltedHashString'))
{
    function generateSaltedHashString ($hashstring, $apikey) {
        $len = strlen($apikey);
        $saltedhashstring = substr($apikey, 0, round($len/2)) . $hashstring . substr($apikey, round($len/2),$len);
        return $saltedhashstring;
    }
}

if(!function_exists('show_pwc_error'))
{
    function show_pwc_error($message){
        $error = load_class('Exceptions');
        echo $error->show_error('', $message);
        exit;
    }
}

if(!function_exists('redirect_invalid_url'))
{
    function redirect_invalid_url()
    {
        exception('The URL you are trying to access is invalid.');
        redirect('welcome');
    }
}
?>