// 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: 0 // 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)
}

/*
To handle the fact that 
-This is the first JS script included on a page
-I want to be able to output debug messages to the console/file from methods here.
-The debug js file is not included until later and therefore showdebug will cause errors
I create a showdebug function here to store any messages in cache if no console is availble. Then when debug.js is loaded the showdebug function
is redefined and any cached messages are outputted.
*/
var debugCache = [];
if(Jobboard.ServerType=="dev"){
	if(typeof(window.console)=="undefined"){
		ShowDebug = function(msg){
			debugCache[debugCache.length] = msg; //store in cache until a console is loaded
		} 
	}else{
		ShowDebug = function(msg){
			console.log(msg);  //handle Safari,Firefox and output message staight to console
		}	
	}	
}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
var n=navigator,d=document;
Browser={
	userAgent:n.userAgent,
	name:null,
	gecko:false,  //moz based rendering engine firefox,firebird
	khtml:false,  //konqueror rendering engine
	trident:false, //IE rendering engine
	webkit:false, //Safari,OmniWeb
	presto:false, //Opera rendering engine
	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(){
			var a=this.userAgent;
			if(this.name===null){
				 if(/Opera/i.test(a) || window.opera){
					this.name = "Opera";
					this.presto = true;
				 }else if(/WebKit/i.test(a)){
					this.name = "Safari";
					this.webkit = true;
				 }else if(/msie/i.test(a)){
					this.name = "Internet Explorer";
					this.trident = 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;
					}
				 }	
			}
			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