<!--
/**
 * framework.js
 *
 * This file is the main file to load when you need framework capabilities inside a project. It will include several other files.
 *
 * @package Jscripts
 * @author Webline BVBA <info@webline.be>
 * @copyright Webline BVBA
 * @link http://www.webline.be/  www.webline.be
 * @uses includeJS()
 */

/**
 * Function to include other javascript files
 *
 * @param string Path to the javascript file (relative or fullpath)
 * @access public
 * @return void
 */
function includeJS(jsPath, callback) {

	var script = document.createElement("script");
	script.setAttribute("type", "text/javascript");
	
	if(typeof(callback)!="undefined") {	
	
		script.onreadystatechange=function () {

			if(this.readyState=="complete" || this.readyState=="loaded") callback();

		} // end readystate
		
		script.onload= callback;
		
	} // end if
		
	script.setAttribute("src", jsPath);
	document.getElementsByTagName("head")[0].appendChild(script);

} // end function

/**
 * Function to include other css files
 *
 * @param string Path to the css file (relative or fullpath)
 * @access public
 * @return void
 */
function includeCSS(cssPath) {

	var css = document.createElement("link");
	
	css.setAttribute("rel", "stylesheet");
	css.setAttribute("type", "text/css");
	css.setAttribute("href", cssPath);
	
	document.getElementsByTagName("head")[0].appendChild(css);

} // end function

/**
 * Debug wrapper for debugging to the Firebug console
 *
 * @param string The message you want to display in the console
 * @access public
 * @return void
 */
function weblineDebugConsole(value) {

	if(typeof(console) != "undefined") {
	
		console.log(value);
	
	} // end if

} // end function

if(typeof(console) != "undefined") {

	WeblineConsole = console;
	
	if(typeof(console.groupEnd)=="undefined") {
	
		console.groupEnd = function(){};
	
	} // end if
	
	if(typeof(console.group)=="undefined") {
	
		console.group = function(){};
	
	} // end if
	
	if(typeof(console.groupCollapsed)=="undefined") {
	
		console.groupCollapsed = function(){};
	
	} // end if

}else{

	WeblineConsole = new Object();
	WeblineConsole.log = function(){};
	WeblineConsole.info = function(){};
	WeblineConsole.error = function(){};
	WeblineConsole.warn = function(){};
	WeblineConsole.log = function(){};
	WeblineConsole.assert = function(){};
	WeblineConsole.dir = function(){};
	WeblineConsole.dirxml = function(){};
	WeblineConsole.trace = function(){};
	WeblineConsole.group = function(){};
	WeblineConsole.groupCollapsed = function(){};
	WeblineConsole.groupEnd = function(){};
	WeblineConsole.time = function(){};
	WeblineConsole.timeEnd = function(){};
	WeblineConsole.profile = function(){};
	WeblineConsole.profileEnd = function(){};
	WeblineConsole.count = function(){};
	WeblineConsole.debug = function(){};

} // end if

/**
 * Placeholder for the checkForm function. To override this function, just place it in another file. Since framework.js is the first one to load, any definition in another file will override this one.
 *
 * @access public
 * @return void
 */
function checkForm() {

} // end function

var weblineJsFiles = [
	"/includes/framework/jscripts/ajax.js",
	"/includes/framework/jscripts/validate.js",
	"/includes/framework/jscripts/util.js",
	"/includes/framework/jscripts/help.js",
	"/includes/framework/jscripts/drag.js",
	"/includes/framework/jscripts/swfobject.js",
	"/includes/framework/jscripts/datepicker.js",
	"/includes/framework/jscripts/notify.js"
];

/**
 * @private
 */
function initFramework() {
	
	includeJS("/includes/framework/jscripts/browser_detect.js",function() {
		
		var regexpOS = new RegExp("Windows","i");
		var regexpBrowser = new RegExp("Explorer","i");
		var regexpVersion = new RegExp("6","i");
		
		var thisOS = BrowserDetect.OS.toString();
		var thisBrowser = BrowserDetect.browser.toString();
		var thisVersion = BrowserDetect.version.toString();
		
		if(thisOS.match(regexpOS) && thisBrowser.match(regexpBrowser) && thisVersion.match(regexpVersion)) {
		
			browserUnsuported(thisOS,thisBrowser,thisVersion);
		
		}else{
		
			includeJSRecursive();
		
		} // end if
	
	}); // end includeJS

} // end function

/**
 *
 * @private
 */
function includeJSRecursive() {

	var file = weblineJsFiles.shift();
	
	if(file) {
	
		includeJS(file,includeJSRecursive);
		
	}else{
	
		// All files loaded
		
		if(typeof(weblineFormInit)!="undefined") {
	
			weblineFormInit();
	
		} // end if
	
		if(typeof(weblineNotifyLoad)!="undefined") {
	
			weblineNotifyLoad();
	
		} // end if
		
	} // end if

} // end function

function browserUnsuported(os,browser,version) {
	
	// Clear the body
		
	$("body").html("");
	
	// Remove CSS files

	var aCss = document.getElementsByTagName("link");
	
	for(var i=aCss.length; i>=0; i--) {
	
		if(aCss[i]) aCss[i].parentNode.removeChild(aCss[i]);
	
	} // end for
	
	// Remove JS files

	var aJscript = document.getElementsByTagName("script");
	
	for(var i=aJscript.length; i>=0; i--) {
	
		if(aJscript[i]) aJscript[i].parentNode.removeChild(aJscript[i]);
	
	} // end for
	
	// Show browser choice
	
	var divContainer = $('<div id="browserError"></div>');
	divContainer.css("display","block");
	divContainer.css("position","absolute");
	divContainer.css("left","50%");
	divContainer.css("top","100px");
	divContainer.css("margin-left","-270px");
	divContainer.css("width","540px");
	divContainer.css("font-family","Verdana,Arial,Sans");
	divContainer.css("font-size","10pt");
	divContainer.css("border","1px solid #999999");
	divContainer.css("padding","10px");
	
	var divTitle = $('<div>Your browser is not supported!</div>');
	divTitle.css("display","block");
	divTitle.css("text-align","center");
	divTitle.css("font-weight","bold");
	
	var divInfo = $('<div><table cellpadding="0" cellspacing="4" border="0" align="center"><tr><td>OS:</td><td>'+os+'</td></tr><tr><td>Browser:</td><td>'+browser+'</td></tr><tr><td>Version:</td><td>'+version+'</td></tr></table></div>');
	divInfo.css("display","block");
	divInfo.find("td").css("font-family","Verdana,Arial,Sans");
	divInfo.find("td").css("font-size","8pt");
	
	var divUpgrade = $('<div>Please install one of the supported browser using these links:<br /><table cellpadding="0" cellspacing="4" border="0" width="100%" align="center" style="margin-top:8px;"><tr><td><a href="http://getfirefox.com/" target="_blank" title="Download Firefox"><img src="/includes/framework/images/browser/firefox.png" width="160" height="60" border="0" alt="Firefox"></a></td><td style="padding-left:4px; padding-right:4px;"><a href="http://www.apple.com/safari/download/" target="_blank" title="Download Safari"><img src="/includes/framework/images/browser/safari.png" width="160" height="60" border="0" alt="Safari"></a></td><td><a href="http://www.opera.com/products/desktop/" target="_blank" title="Download Opera"><img src="/includes/framework/images/browser/opera.png" width="160" height="60" border="0" alt="Opera"></a></td></tr></table><table cellpadding="0" cellspacing="4" border="0" align="center"><tr><td><a href="http://www.google.com/chrome/" target="_blank" title="Download Chrome"><img src="/includes/framework/images/browser/chrome.png" width="160" height="60" border="0" alt="Chrome"></a></td><td style="padding-left:4px;"><a href="http://www.microsoft.com/windows/downloads/ie/getitnow.mspx" target="_blank" title="Download Internet Explorer"><img src="/includes/framework/images/browser/ie.png" width="160" height="60" border="0" alt="Internet Explorer"></a></td></tr></table></div>');
	divUpgrade.css("display","block");
	divUpgrade.css("text-align","center");
	
	divContainer.append(divTitle);
	divContainer.append(divInfo);
	divContainer.append(divUpgrade);
	
	$("body").append(divContainer);
			
} // end function

window.onload=initFramework;

//-->

