/**
 * Taazoo ViewPort
 *
 * Main script.
 */

var conf = {
    'cont_gen': 'landing.php', 		/* Where to pull data from. */
    'base_path': '', 		   		/* Base path to 'cont_gen'. */
    'home_page': 'Home',	  		/* The name of your home page. ('Home', 'About, 'Contact' etc.) */
	'clock_div': 'clock', 			/* What div to place current time into */
	'session_name' : 'FCMS-LoggedIn',
	'session_timeout' : '600000',
	'session_exp_page' : 'landing.php?mod=session_exp&pane=session'
};

var def_pane_opts = {
	'width': '600px', 		/* Default width */
	'height': '700px', 		/* Default pane height */
	'url' : 'landing.php', 	/* Bunk/Default request page (Will default to "Home") */
	'top' : '100px', 		/* Top aspect orientation */
	'left' : '100px', 		/* Left Orientation */
	'z-index' : 3, 			/* Default z-index (This shouldnt be overwritten) */
	'loading' : '<center><strong>Loading</strong><br /><img src="./imgs/loading.gif" alt="Loading" /></center>' /* Loading display */
};

//session timeout configuration
var _session_name = "FCMS-LoggedIn";       //what cookie are we looking for 
										   //Note SESSION will set a cookie on 
										   //page view (Even if they are not logged in)
var  sess_exp_page = "?mod=session_exp";   //What page will we redirect to when session is about to expire.
var _timeout = 600000;					   //session timeout (In mili-seconds


var sess_time = new Date().getTime();

function init_view_port()
{

	load_script('config', './viewport/config.js');
	load_script('ajax',    './viewport/src/ajax.js');
    load_script('panes',   './viewport/src/panes.js');
	load_css('style', './viewport/style.css');
	
	setTimeout("initialize()", 500); //allow time (500mili seconds) to load other scripts 
}

function initialize()
{
	updateClock();
	setInterval('updateClock()', 1000);
	
	init_drag_drop();
	//init();
	parseURL();
        window.setInterval(function(){parseURL();},200);
}

function load_css(name, src)
{
	var script = document.createElement('link');
	script.setAttribute('rel', "stylesheet");
	script.setAttribute('type', "text/css");
	script.setAttribute('id', name);
        script.setAttribute('href',src);
        document.getElementsByTagName('head')[0].appendChild(script);
	return script;
}


function load_script(name, src)
{
	var script = document.createElement('script');
	script.setAttribute('id', name);
        script.setAttribute('src',src);
        document.getElementsByTagName('head')[0].appendChild(script);
	return script;
}
	
function readConf (str) {  return (typeof(conf[str])!="undefined"?conf[str]:false); }
	

function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}


function updateClock ( )
{
	//clock by LouisT http://ltdev.us
     	 sdate = new Date();
         var h = sdate.getHours(), m = sdate.getMinutes(), s = sdate.getSeconds(), ap = 'AM';
         if (h > 12) { h = h-12; ap = 'PM'; }
         var time = (h==0?"12":(h>9?h:"0"+h))+":"+(m>9?m:"0"+m)+":"+(s>9?s:"0"+s);
         if ((timeLoc = document.getElementById(readConf('clock_div'))) != null) {
            timeLoc.innerHTML = "<strong>"+time+" "+ap+"</strong>";
         }
}

	

