// Copyright Notice:
//				config.js v3.0.3
//			Copyright©2010-2011 - OpenSiteMobile
//				All rights reserved
// ==========================================================================
//			http://www.opensite.mobi
// ==========================================================================
// Contact Information:
//			Author: Dwight Vietzke
//			Email:  dwight_vietzke@yahoo.com

/*
	OpenSiteMobile common dojo configuration file
*/


// --------------------------
// Early error notification
// --------------------------

window.onerror = function (msg, url, line) {
    if (window.msos
     && window.msos.mobile)	{ msos.mobile.error_indicator(msg, url, line);  }
    else			{ alert(msg + ' -> ' + url + ' line: ' + line); }
}


// --------------------------
// Dojo Toolkit Configuration for MSOS
// --------------------------

var djConfig = {

    locale:'en',
    msos_audio:!!(document.createElement('audio').canPlayType),
    msos_boxshadow:false,
    msos_css_pseudoelement:false,
    msos_console:false,
    msos_debug:false,
    msos_doctype:'html5',
    msos_icon:'osm.ico',
    msos_popups_blocked:false,
    msos_pushstate:!!history.pushState,
    msos_run_ads:true,
    msos_scrolltop:false,
    msos_transform:false,
    msos_size:'pda_sml',
    msos_style:['reset.css', 'mobile.css'],
    msos_xml_write:true,

    msos_color:{
	bk : 'black',
	wh : 'white',
	dg : 'darkgrey',
	lg : 'lightgrey',
	sl : 'salmon',
	lb : 'lightblue',
	rd : 'red',
	be : 'beige'
    },
    msos_file:{
	'file':		(typeof window.File 		== "object"),
	'reader':	(typeof window.FileReader 	== "function"),
	'list':		(typeof window.FileList 	== "object"),
	'blob':		(typeof window.Blob		== "object")
    },
    msos_orientation:	(typeof window.orientation	== "object"),
    msos_pixel_ratio:	(typeof window.devicePixelRatio	== "number"),
    msos_storage:{
	'local':	(typeof window.localStorage 	== "object"),
	'session':	(typeof window.sessionStorage 	== "object"),
	'global':	(typeof window.globalStorage 	== "object"),
	'open_db':	(typeof window.openDatabase	== "function")
    },
    msos_touch:		(typeof Touch                   == "object"),
    msos_touch_end:	("ontouchend" in document),
    msos_websocket:	(typeof WebSocket               == "object"),
    msos_css_trans:	(typeof window.WebKitTransitionEvent == "object")
};

// --------------------------
// Parse query string
// --------------------------

var get_query_string = function() {
    var query_string = location.search ? location.search : '';

    if (query_string.charAt(0) == '?')	query_string = query_string.substring(1);
    if (query_string)			query_string = decodeURIComponent(query_string);
    return query_string;
}

var parse_query = function() {
    var result = new Object();
    var params = new Array();
    var query = get_query_string();

    var is_empty = function(v) {
        if (typeof(v) == 'undefined')	return true;
	if (v == null)			return true;
	if (v == '')			return true;
	return false;
    };

    if (query) {
        params = query.split(/[&;]/g) || params.push(query);

        for (var idx = 0; idx < params.length; idx++) {
            var parm = params[idx].split("=");
            if (!is_empty(parm[0])) {
                if (parm[1] == 'true')  parm[1] = true;
                if (parm[1] == 'false') parm[1] = false;
                result[parm[0]] = parm[1];
            }
        }
    }

    // MSOS uses underscores for language (ie zh_tw, see msos.i18n)
    if (result.locale) result.locale = result.locale.replace('_', '-');

    for (var parm in djConfig) { if (result[parm]) djConfig[parm] = result[parm]; }
    return result;
}

if (djConfig.msos_pixel_ratio) {
    djConfig.msos_pixel_ratio = window.devicePixelRatio;
}

djConfig.msos_query = parse_query();

