﻿var Ontos = window.Ontos || {};
var ontos = window.ontos || {};
ontos.widgets = ontos.widgets || {};

if (!Ontos.bootstap_done) {
	
	Ontos.bootstap_scripts = Ontos.bootstap_scripts || [
	    ["json2.js", "json2"]
	    ,["ext-base-debug.js", "base"]
	    ,["ext-all-debug.js", "ext"]
	    ,["widgets-lib.js", "widgets"]
	    ,["widgets.js", "widgets"]
	];
	
	Ontos.bootstap_styles = Ontos.bootstap_styles || [
	 	["css/ext-all.css", "ext"]
	 	,["css/widgets.css", "widgets"]
	];
	
	try { if(_ontos_url){}; }catch(e){ _ontos_url = "http://62.117.115.98:6622/inews/";}
	try { if(_ontos_api_url){}; }catch(e){ _ontos_api_url = _ontos_url + "api/";}
	try { if(_path_prefix){}; }catch(e){ _path_prefix = _ontos_url + "widgets/";}
	try { if(_custom_widgets_path_prefix){}; }catch(e){ custom_widgets_path_prefix = _path_prefix;}
	try { if(_ontos_blank_image_url){}; }catch(e){ _ontos_blank_image_url = _path_prefix + "images/default/s.gif";}
	try { if(_history){}; }catch(e){ _history = false;}
	try { if(_cache){}; }catch(e){ _cache = "ON";}
	try { if(_ontology){}; }catch(e){ _ontology = "Common.English";}
	try { if(_period){}; }catch(e){ _period = 24;}
	try { if(_igoogle){}; }catch(e){ _igoogle = false;}
	
	var head = document.getElementsByTagName("head")[0];
	
	for (var i = 0; i < Ontos.bootstap_styles.length; ++i) {
		var item = Ontos.bootstap_styles[i];
		document.write('<link rel="stylesheet" type="text/css" href="' + _path_prefix + item[0] + '">');
	}
	
	for (var i = 0; i < Ontos.bootstap_scripts.length; ++i) {
		var item = Ontos.bootstap_scripts[i];
		document.write('<script type="text/javascript" src="' + _path_prefix + item[0] + '"></script>');
	}
	
	if (_igoogle) {
		var x = location.hostname.indexOf('.')+1;
	    if (x>0) document.domain = location.hostname.substring(x);
	}
	/*
	if (_history) {
		document.write('<form id="history-form" class="x-hidden">' +
				'<input type="hidden" id="x-history-field" />' +
				'<iframe id="x-history-frame"></iframe>' +
				'</form>');
	}
*/
	/*function checkTimeZone() {
		   var rightNow = new Date();
		   var date1 = new Date(rightNow.getFullYear(), 0, 1, 0, 0, 0, 0);
		   var date2 = new Date(rightNow.getFullYear(), 6, 1, 0, 0, 0, 0);
		   var temp = date1.toGMTString();
		   var date3 = new Date(temp.substring(0, temp.lastIndexOf(" ")-1));
		   var temp = date2.toGMTString();
		   var date4 = new Date(temp.substring(0, temp.lastIndexOf(" ")-1));
		   var hoursDiffStdTime = (date1 - date3) / (1000 * 60 * 60);
		   var hoursDiffDaylightTime = (date2 - date4) / (1000 * 60 * 60);
		   if (hoursDiffDaylightTime == hoursDiffStdTime) { 
			   return hoursDiffStdTime*60*60*1000;
 		      //alert("Time zone is GMT " + hoursDiffStdTime + ".\nDaylight Saving Time is NOT observed here.");
		   } else {
		      //alert("Time zone is GMT " + hoursDiffStdTime + ".\nDaylight Saving Time is observed here.");
		      return (hoursDiffStdTime+1)*60*60*1000;
		   }
		}*/
	function checkTimeZone() {
	    var gmtstr = new Date().getGMTOffset(true);
	    var hours = 60*60*1000;
	    var hh = gmtstr.split(":");
	    var offsetL = parseInt(hh[0].substr(1,3));
	    var offsetR = parseInt(hh[1].substr(0,2));
	    var sign = hh[0].substr(0,1);
	    var offset = (offsetL+offsetR)*hours;
	    if (sign == "+") return offset;
	        else {
	        return -offset;    
	    }
	}
	Ontos.bootstap_done = true;
}

