
function checkBrowserName(name){
	var agent = navigator.userAgent.toLowerCase();
	if (agent.indexOf(name.toLowerCase())>-1) {
		return true;
	}else{
		return false;
	}
}

function checkBrowserVersion(Version){
	var agent = navigator.appVersion.substring(0, 1);
	if (agent <= Version)
	{
		return true;
	}else{
		return false;
	}
}

function checkFlashDHTML() {
	//alert(FlashDetect.major+' '+FlashDetect.revision);
	addFile('/vweb/Flash/DHTML/dhtmlFlash.js?1', 'dhtmlFlash');
	if (FlashDetect.major>8 && FlashDetect.revision>5){
		addFile('/vweb/Js/swfobject.js', 'swfobject');
		if (document.getElementById('theFlashDiv')) {
			//window.setTimeout("startFlashDia()", 500);
		}
		if (document.Form_Destination) {
			window.setTimeout("startFlashMap()", 1000);
		}
	}

	if (document.getElementById('theFlashDiv')) {
		addFile('/vweb/Js/commonAjax.js', 'commonAjax');
		window.setTimeout("goAjax(1)", 500);
	}
}

function addFile(files, idElem) {
	if(!document.createElement) {
		return;
	}

	if (document.getElementById(idElem)) {
		document.getElementById(idElem).parentNode.removeChild(document.getElementById(idElem));
	}

	if(files!='') {
		var script=document.createElement('script');

		if(script) {
			script.setAttribute('type', 'text/javascript');
			script.setAttribute('src', files);
			script.setAttribute('id', idElem);
			script.setAttribute('language', 'JavaScript');
			script.setAttribute('charset', 'ISO-8859-1');
			var head=document.getElementsByTagName('head')[0];
			if(head) {
				head.appendChild(script);
			}
		}
	}
}

var FlashDetect = new function(){
	var self = this;
	self.installed = false;
	self.major = -1;
	self.minor = -1;
	self.revision = -1;
	self.revisionStr = "";
	self.activeXVersion = "";
	var activeXDetectRules = [
		{
			"name":"ShockwaveFlash.ShockwaveFlash.7",
			"version":function(obj){
				return getActiveXVersion(obj);
			}
		},
		{
			"name":"ShockwaveFlash.ShockwaveFlash.6",
			"version":function(obj){
				var version = "6,0,21";
				try{
					obj.AllowScriptAccess = "always";
					version = getActiveXVersion(obj);
				}catch(err){}
				return version;
			}
		},
		{
			"name":"ShockwaveFlash.ShockwaveFlash",
			"version":function(obj){
				return getActiveXVersion(obj);
			}
		}
	];
	var getActiveXVersion = function(activeXObj){
		var version = -1;
		try{
			version = activeXObj.GetVariable("$version");
		}catch(err){}
		return version;
	};
	var getActiveXObject = function(name){
		var obj = -1;
		try{
			obj = new ActiveXObject(name);
		}catch(err){}
		return obj;
	};
	var parseActiveXVersion = function(str){
		var versionArray = str.split(",");//replace with regex
		return {
			"major":parseInt(versionArray[0].split(" ")[1], 10),
			"minor":parseInt(versionArray[1], 10),
			"revision":parseInt(versionArray[2], 10),
			"revisionStr":versionArray[2]
		};
	};
	var parseRevisionStrToInt = function(str){
		return parseInt(str.replace(/[a-zA-Z]/g, ""), 10) || self.revision;
	};
	self.majorAtLeast = function(version){
		return self.major >= version;
	};
	self.FlashDetect = function(){
		if(navigator.plugins && navigator.plugins.length>0){
			var type = 'application/x-shockwave-flash';
			var mimeTypes = navigator.mimeTypes;
			if(mimeTypes && mimeTypes[type] && mimeTypes[type].enabledPlugin && mimeTypes[type].enabledPlugin.description){
				var desc = mimeTypes[type].enabledPlugin.description;
				var descParts = desc.split(' ');//replace with regex
				var majorMinor = descParts[2].split('.');
				self.major = parseInt(majorMinor[0], 10);
				self.minor = parseInt(majorMinor[1], 10); 
				if (descParts[3]!=''){
					self.revisionStr = descParts[3];
				}else if (descParts.length>4){
					self.revisionStr = descParts[4];
				}

				self.revision = parseRevisionStrToInt(self.revisionStr);
				self.installed = true;
			}
		}else if(navigator.appVersion.indexOf("Mac")==-1 && window.execScript){
			var version = -1;
			for(var i=0; i<activeXDetectRules.length && version==-1; i++){
				var obj = getActiveXObject(activeXDetectRules[i].name);
				if(typeof obj == "object"){
					self.installed = true;
					version = activeXDetectRules[i].version(obj);
					if(version!=-1){
						var versionObj = parseActiveXVersion(version);
						self.major = versionObj.major;
						self.minor = versionObj.minor; 
						self.revision = versionObj.revision;
						self.revisionStr = versionObj.revisionStr;
						self.activeXVersion = version;
					}
				}
			}
		}
	}();
};

FlashDetect.release = "1.0.2";