// Javascript Global Constants - FOR DEV SERVER ONLY
// Holds constants used by JS scripts so that we can use external script files without passing in ASP strings

Jobboard = {
	ProductName: "Jobweb", //name of product
	Version: 2, //current version of software
	Build: 4, //current build
	Company: "Strategies Group PLC",
	ServerType: "live",
	FirebugLite: "/jobboard/scripts/JS/firebug/", //path to my implementation of firebug lite
	VideoCVServer: "rtmp://arsenic.strategiesuk.net/simplevideostreaming/_definst_/", //path to the video CV server
	FlashPlayer: "/jobboard/flash/FlowPlayerDark.swf", //the flash player for the video CV
	LogJSErrors: false, //Log JS errors to file
	SuppressJSErrors: 2 // 0 = no dont suppress errors, 1 = suppress all, 2 suppress errs in old browsers (doms 0,1,3 0=none,1=old IE,3=old NN browsers)
}

var n=navigator,d=document;
var Debugger = {
	ready: false,
	debugCache: [],
	hasCache: false,
	debugCount: 0,
	debugInterval: null,
	forceFirebug: false, //if true for Safari/Chrome/Firefox we will use firebug lite for debug not their own console
	isFirefox: (/Firefox/i.test(n.userAgent))?true:false,
	debug: true,
	
	ClearCache: function(){		
		if(this.debugCache.length>0){
			for(var c=0;c<this.debugCache.length;c++){
				this.Log(this.debugCache[c]); //add all cached messages to debug console
			}
			this.debugCache.length=0;
			this.hasCache=false;
		}
	},

	FirebugReady: function(){		
		if(this.CheckFirebug()){
			this.ClearCache();
			clearInterval(this.debugInterval);
			this.debugInterval=null;
		}
	},

	CheckFirebug: function(){
		if(this.ready){
			return true;
		}else{
			if(this.forceFirebug && !this.isFirefox){				
				if((typeof(firebug)!="undefined") && firebug.env && firebug.env.init ){
					return this.ready = true;
				}else{
					return this.ready = false;
				}
			}else{
				return this.ready = (typeof(window.console)!="undefined");
			}
		}
	},

	Log: function(msg){
		if(this.forceFirebug && !this.isFirefox){
			firebug.d.console.cmd.log(msg);
		}else{
			console.log(msg);
		}
	}
}

if(Jobboard.ServerType=="dev"){		
	ShowDebug = function(msg){
		if(Debugger){
			if(!Debugger.debug)return;
			Debugger.debugCount++;
			var logMsg = Debugger.debugCount.toString()+": "+msg
			if(!Debugger.CheckFirebug()){
				Debugger.debugCache.push(logMsg); //store in cache until console is loaded
				Debugger.hasCache=true;
				if(Debugger.debugInterval==null){Debugger.debugInterval = setInterval(function(){Debugger.FirebugReady();},1000);}//check every second until bug is loaded
			}else{
				if(Debugger.hasCache){Debugger.ClearCache()};				
				Debugger.Log(logMsg);
			}
		}
	}	
}else{
	ShowDebug=function(){}//create empty function as unless all references are removed it will still get called even if its not outputting anything to console
}

//Create a browser wrapper object which does some basic sniffing for common browsers and also the dom type. Try to always use dom but in some cases
//sniffing has to be done as there is no other way (e.g ScriptOnDemand object Safari/Opera dont Script.onload / onreadystatechange

Browser={
	userAgent:n.userAgent,
	name:null,
	gecko:false,  //moz based rendering engine firefox,firebird
	khtml:false,  //konqueror rendering engine
	ie:false, //IE rendering engine
	webkit:false, //Safari,OmniWeb
	opera:false, //Opera rendering engine
	version:0, //browser version
	jscript:false,
	javascript:false,
	spoof:null,
	bot:null,
	dom:d.all?(d.getElementById?2:1):(d.getElementById?4:(d.layers?3:0)), //set the dom type for browser (0=none,1=old IE,2=new IE,3=old NN browsers,4 modern moz)
	w3cDOM: typeof d.getElementById != "undefined" && typeof d.getElementsByTagName != "undefined" && typeof d.createElement != "undefined", //check to see if browser is wc3 DOM enabled
	BrowserName: function(){
			ShowDebug("IN BrowserName")
			var a=this.userAgent;
			if(this.name===null){
				ShowDebug("test useragent " + a + " and window.opera = " + window.opera);
				 if(/Opera/i.test(a) || window.opera){
					ShowDebug("IS OPERA!!!")
					this.name = "Opera";
					this.opera = true;
				 }else if(/WebKit/i.test(a) || /Apple/i.test(a)){
					this.webkit = true;
					if(/Chrome/i.test(a)){
						this.name = "Chrome";
					}else if(/Apple.*Mobile.*Safari/i.test(a)){
						this.name = "Mobile Safari";
					}else{
						this.name = "Safari";
					}
				 }else if(/msie/i.test(a)){
					this.name = "Internet Explorer";
					this.ie = true;
				 }else if(/Firefox/i.test(a)||n.vendor=="Firebird"){
					this.name = "Firefox";
					this.gecko = true;
				 }else if(/Firebird/.test(a)||n.vendor=="Firebird"){
					this.name =  "Firebird";
					this.gecko = true;
				 }else if(/konqueror/i.test(a)){
					this.name = "Konqueror"	
					this.khtml = true;
				 }else{
					this.name = n.appName;
					// look for gecko engine
					if(n.product&&n.product.toLowerCase()=="gecko"&a.indexOf('gecko')!=-1){
						this.gecko = true;
					}else if(/webkit/i.test(a)){
						this.webkit = true;
					}
				 }
				 this.version = (a.match( /.+(?:ox|rv|ion|ra|ie|me)[\/: ]([\d.]+)/i ) || [])[1];	
			}
			ShowDebug("Set Browser.name = " + this.name);
			return this.name;
		},
	isSpoof: function(){
			if(this.spoof===null){
				if(/(?:spoof|spoofer|fake|ripper)/i.test(this.userAgent)){
					this.spoof = true;
				}else{ 
					this.spoof = false;
				}
			}
			return this.spoof;
		},
	isBot: function(){
			if(this.bot===null){
				if(/(?:robot|bot\W|mine|archive|spider|crawl|job|@|https?:\/{2})/i.test(this.userAgent)){
					this.bot = true;
				}else{ 
					this.bot = false;
				}
			}
			return this.bot;
		},
	ScriptTest: function(){
			/*@cc_on
				@if (@_jscript)
					this.jscript = true;
				@else */
					this.javascript = true;  /*
				@end
			@*/
		},
	SetUp: function(){
			this.BrowserName();
			this.isSpoof();
			this.isBot();
			this.ScriptTest();
		}
}
Browser.SetUp(); //run setup so any code can use this object