/******* BROWSER RECOGNITION *******/
function oBrowser() {
	this.win = (navigator.platform=="Win32");
	this.mac = (navigator.platform=="MacPPC"||navigator.platform=="MacIntel");
	this.ver = navigator.appVersion;
	this.ua = navigator.userAgent;
	this.dom = document.getElementById;
	this.safari = (window.addEventListener && navigator.vendor == "Apple Computer, Inc.");
	this.ie7 = (this.ver.indexOf("MSIE 7")!=-1 && this.dom);
	this.ie6 = (this.ver.indexOf("MSIE 6")!=-1 && this.dom);
	this.ie5 = (this.ver.indexOf("MSIE 5")!=-1 && this.dom);
	this.ie4 = (document.all && !this.dom);
	this.ie = (this.ie5 || this.ie4 || this.ie6 ||this.ie7);
	this.ns7 = (this.ua.indexOf('Netscape/7')!=-1);
	this.ns6 = (this.dom && parseInt(this.ver)>=5);
	this.ns4 = (document.layers && !this.dom);
	this.ns = (this.ns4 || this.ns6 || this.ns7);
	this.op = window.opera || false;
	this.bw = (this.ie5 || this.ie4 || this.ns4 || this.ns6 || this.ns7);
	this.bx = (this.ie5 || this.ns6 || this.ie6 || this.ns7);
	this.iWidth = 0;
	this.iHeight = 0;
	this.pLoaded = false;
	return this;
}
var browser = new oBrowser();
/******* END BROWSER RECOGNITION *******/


/******* SHORTCUTS *******/
var d = document;
var gE = function(e){
	return d.getElementById(e);
};
var getFirstParentByTagName = function(el,tagName){
   var parent = el;
   while (parent && parent.tagName && parent.tagName.toLowerCase() != tagName.toLowerCase()) {
      // no such tag exists - exit
      if (parent.tagName.toLowerCase() == "html") {
         return null;
      }
      parent = parent.parentNode;
   }
   return parent;
};
try {
   document.execCommand('BackgroundImageCache', false, true);
} catch(e) {}
/******* END SHORTCUTS *******/


/******* ONLOAD STACKER *******/
var evt_load = function(fn){
	var oldOnload = window.onload;
	if(typeof(window.onload) != "function") {
		window.onload = function() {
			if(typeof fn == "function") {
				fn();
			}
		};
	} else {
		window.onload = function() {
			oldOnload();
			if(typeof fn == "function") {
				fn();
			}
		};
	}
};
/******* END ONLOAD STACKER *******/


/******* COOKIES *******/
var sC = function(n, v, dy) {
	var s = "";
	if(dy) {
   		var dt = new Date();
   		dt.setTime(dt.getTime() +(dy*24*60*60*1000));
   		s = "; expires="+dt.toGMTString();
	}
	d.cookie = n+"="+v+s+"; path=/";
};
var gC = function(n) {
	var nEQ = n+"=";
	var aC = d.cookie.split(';');
	for(var i=0;i < aC.length;i++) {
		var c = aC[i];
		while(c.charAt(0)==' ') {c = c.substring(1,c.length);}
		if(c.indexOf(nEQ)===0) {return c.substring(nEQ.length,c.length);}
	}
	return null;
};
var eC = function(n) {
	sC(n,"",-1);
};
/******* END COOKIES *******/


/******* FORM VALIDATION *******/
var oFormVal = function(sName , spanID){
	this.active = true;
	this.checkboxes = [];
	this.checkboxesm = [];
	this.radios = [];
	this.radiosm = [];
	this.mails = [];
	this.mailsm = [];
	this.longer = [];
	this.longerm = [];
	this.nr = [];
	this.either = [];
	this.dateText = [];
	this.passwords = [];
	this.passwordsm = [];
	this.sName = sName;
};
oFormVal.prototype.addPassword = function(sName, sName2, sMessage) {
	this.passwords.push(sName, sName2);
	this.passwordsm.push(sMessage);
};
oFormVal.prototype.addRequiredCheckBox = function(sName, sMessage) {
	this.checkboxes.push(sName);
	this.checkboxesm.push(sMessage);
};
oFormVal.prototype.addRequiredRadio = function(sName, sMessage) {
	this.radios.push(sName);
	this.radiosm.push(sMessage);
};
oFormVal.prototype.addMail = function(sName,sMessage) {
	this.mails.push(sName);
	this.mailsm.push(sMessage);
};
oFormVal.prototype.addEither = function(sName1,sName2,sMessage){
   this.either.push( [sName1,sName2,sMessage] );
   this.nr[sName1] = true;
   this.nr[sName2] = true;
};
oFormVal.prototype.addDate = function(sName,sMessage) {
   this.dateText.push( [sName, sMessage] );
};
oFormVal.prototype.addLonger = function(sName,sMessage) {
	this.longer.push(sName);
	this.longerm.push(sMessage);
};
oFormVal.prototype.notRequired = function(sName) {
	this.nr[sName] = true;
};
oFormVal.prototype.isCheckBox = function(o) {
	return (typeof o.nodeName == "string" && o.type == "checkbox");
};
oFormVal.prototype.isRadio = function(o) {
	return (o.type == "radio");
};
oFormVal.prototype.outputMessage = function( s ){
	alert( s );
};
oFormVal.prototype.validate = function(s) {
	var f = d.forms[this.sName].elements;
	s = s || 'Sorry, please complete all details.';
	for(var i=0; f[i]; i++) {
		if(f[i].tagName !== "FIELDSET"){
			if(!this.nr[f[i].name] && f[i].name.length > 0 && !fieldHasValue(f[i]) && !this.isCheckBox(f[i]) && !this.isRadio(f[i])) {
				this.outputMessage(s);
				f[i].focus();
				return false;
			}
		}
	}
	if(this.passwords.length > 0){
		if(f[this.passwords[0]].value != f[this.passwords[1]].value){
			this.outputMessage(this.passwordsm[0]);
			f[this.passwords[0]].focus();
			return false;
		}
	}
	for(i=0; this.either[i]; i++) {
	   if( (f[this.either[i][0]].value.length+f[this.either[i][1]].value.length) == 0 )
	   {
	      this.outputMessage(this.either[i][ 2 ]);
	      f[this.either[i][0]].focus();
	      return false;
	   }
	}
	for(i=0; this.dateText[i]; i++) {
	   if(!/^(0[1-9]|[12]\d|3[01])\/(0[1-9]|1[0-2])\/19[4-9]\d/.test(f[this.dateText[i][0]].value)) {
	      this.outputMessage(this.dateText[i][1]);
	      f[this.dateText[i][0]].focus();
	      return false;
	   }
	}
	for(i=0; this.checkboxes[i]; i++) {
		if(!f[this.checkboxes[i]].checked) {
			this.outputMessage(this.checkboxesm[i]);
			return false;
		}
	}
	for(i=0; this.radios[i]; i++) {
		var radioChecked = false;
		for(var p=0; f[this.radios[i]][p]; p++) {
			if(f[this.radios[i]][p].checked) {
				radioChecked = true;
			}
		}
		if(!radioChecked) {
			this.outputMessage(this.radiosm[i]);
			return false;
		}
	}
	for(i=0; this.mails[i]; i++) {
		if(!/^.+\@[A-Za-z0-9][A-Za-z0-9\-]+\..+[A-Za-z]$/.test(f[this.mails[i]].value)) {
			this.outputMessage(this.mailsm[i]);
			f[this.mails[i]].focus();
			return false;
		}
	}
	for(i=0; this.longer[i]; i++) {
		if(f[this.longer[i]].value.length < 2) {
			this.outputMessage(this.longerm[i]);
			f[this.longer[i]].focus();
			return false;
		}
	}
	return true;
};
var fieldHasValue = function(o) {
	return (o.getAttribute("type") == "hidden" || (o.value !== "" && o.value != o.defaultValue));
};
var clearField = function(o){
	if(o.value == o.defaultValue) {
		o.value = "";
	}
};
/******* END FORM VALIDATION *******/


/******* AJAX OBJECT *******/
var AJAX = function(url, fn) {
	var rand = "ajax_"+Math.round(Math.random()*5000);
	while(typeof window[rand] != "undefined") {
		rand = "ajax_"+Math.round(Math.random()*5000);
	}
	
	if(browser.ie) {
		try {
			window[rand] = new ActiveXObject("Msxml2.XMLHTTP");
		} catch(e) {
			try {
				window[rand] = new ActiveXObject("Microsoft.XMLHTTP");
			} catch(E) {
				window[rand] = false;
			}
		}
	} else if(typeof XMLHttpRequest != "undefined") {
		window[rand] = new XMLHttpRequest();
	}
	
	if(window[rand]) {
		window[rand].open("GET", url, true);
		window[rand].onreadystatechange = function() {
			if(window[rand].readyState == 4 && window[rand].status == 200) { 
				fn(window[rand].responseText);
			} else if(window[rand].readyState == 4 && window[rand].status == 404) { 
				fn("AJAX Error "+window[rand].status+": Page not found"); 
			} else if(window[rand].readyState == 4 && parseInt(window[rand].status) == 5) {
				fn("AJAX error "+window[rand].status+": Internal server error");
			}
		};
		window[rand].send(null);
		
		return window[rand];
	} else {
		return null;
	}
};
/******* END AJAX OBJECT *******/


/******* MACROMEDIA FLASH FUNCTIONS *******/
// Flash Player Version Detection - Rev 1.6
// Detect Client Browser type
// Copyright(c) 2005-2006 Adobe Macromedia Software, LLC. All rights reserved.
var isIE  = (navigator.appVersion.indexOf("MSIE") != -1) ? true : false;
var isWin = (navigator.appVersion.toLowerCase().indexOf("win") != -1) ? true : false;
var isOpera = (navigator.userAgent.indexOf("Opera") != -1) ? true : false;

function ControlVersion()
{
	var version;
	var axo;
	var e;

	// NOTE : new ActiveXObject(strFoo) throws an exception if strFoo isn't in the registry

	try {
		// version will be set for 7.X or greater players
		axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.7");
		version = axo.GetVariable("$version");
	} catch (e) {
	}

	if (!version)
	{
		try {
			// version will be set for 6.X players only
			axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.6");
			
			// installed player is some revision of 6.0
			// GetVariable("$version") crashes for versions 6.0.22 through 6.0.29,
			// so we have to be careful. 
			
			// default to the first public version
			version = "WIN 6,0,21,0";

			// throws if AllowScripAccess does not exist (introduced in 6.0r47)		
			axo.AllowScriptAccess = "always";

			// safe to call for 6.0r47 or greater
			version = axo.GetVariable("$version");

		} catch (e) {
		}
	}

	if (!version)
	{
		try {
			// version will be set for 4.X or 5.X player
			axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.3");
			version = axo.GetVariable("$version");
		} catch (e) {
		}
	}

	if (!version)
	{
		try {
			// version will be set for 3.X player
			axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.3");
			version = "WIN 3,0,18,0";
		} catch (e) {
		}
	}

	if (!version)
	{
		try {
			// version will be set for 2.X player
			axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash");
			version = "WIN 2,0,0,11";
		} catch (e) {
			version = -1;
		}
	}
	
	return version;
}

// JavaScript helper required to detect Flash Player PlugIn version information
function GetSwfVer(){
	// NS/Opera version >= 3 check for Flash plugin in plugin array
	var flashVer = -1;
	
	if (navigator.plugins !== null && navigator.plugins.length > 0) {
		if (navigator.plugins["Shockwave Flash 2.0"] || navigator.plugins["Shockwave Flash"]) {
			var swVer2 = navigator.plugins["Shockwave Flash 2.0"] ? " 2.0" : "";
			var flashDescription = navigator.plugins["Shockwave Flash" + swVer2].description;
			var descArray = flashDescription.split(" ");
			var tempArrayMajor = descArray[2].split(".");			
			var versionMajor = tempArrayMajor[0];
			var versionMinor = tempArrayMajor[1];
			var versionRevision = descArray[3];
			if (versionRevision === "") {
				versionRevision = descArray[4];
			}
			if (versionRevision[0] == "d") {
				versionRevision = versionRevision.substring(1);
			} else if (versionRevision[0] == "r") {
				versionRevision = versionRevision.substring(1);
				if (versionRevision.indexOf("d") > 0) {
					versionRevision = versionRevision.substring(0, versionRevision.indexOf("d"));
				}
			}
			flashVer = versionMajor + "." + versionMinor + "." + versionRevision;
		}
	} else if (navigator.userAgent.toLowerCase().indexOf("webtv/2.6") != -1){
      flashVer = 4;
   } else if (navigator.userAgent.toLowerCase().indexOf("webtv/2.5") != -1){
      flashVer = 3;
   } else if (navigator.userAgent.toLowerCase().indexOf("webtv") != -1){
      flashVer = 2;
   } else if ( isIE && isWin && !isOpera ){
		flashVer = ControlVersion();
	}	
	return flashVer;
}
// When called with reqMajorVer, reqMinorVer, reqRevision returns true if that version or greater is available
function DetectFlashVer(reqMajorVer, reqMinorVer, reqRevision)
{
	var versionStr = GetSwfVer();
	if (versionStr == -1 ) {
		return false;
	} else if (versionStr !== 0) {
		if(isIE && isWin && !isOpera) {
			// Given "WIN 2,0,0,11"
			var tempArray         = versionStr.split(" "); 	// ["WIN", "2,0,0,11"]
			var tempString        = tempArray[1];			// "2,0,0,11"
			var versionArray      = tempString.split(",");	// ['2', '0', '0', '11']
		} else {
			var versionArray      = versionStr.split(".");
		}
		var versionMajor      = versionArray[0];
		var versionMinor      = versionArray[1];
		var versionRevision   = versionArray[2];

        	// is the major.revision >= requested major.revision AND the minor version >= requested minor
		if (versionMajor > parseFloat(reqMajorVer)) {
			return true;
		} else if (versionMajor == parseFloat(reqMajorVer)) {
			if (versionMinor > parseFloat(reqMinorVer)){
				return true;
			} else if (versionMinor == parseFloat(reqMinorVer)) {
				if (versionRevision >= parseFloat(reqRevision)){
					return true;
            }
			}
		}
		return false;
	}
}
var bFlash = (DetectFlashVer(8, 0, 0));
function detectFlash() {
	return bFlash;
}
/* End Flash Detection */

function insertFlash(movie, w, h, mode, bg, vars, target, replacementIMG, replacementURL) {
	if(bFlash) {
		var a = [["movie", movie], ["wmode", mode], ["bgcolor", bg], ["flashvars", vars]];
			
		var str = '<object type="application/x-shockwave-flash" data="'+ movie +'" width="' +w +'" height="'+ h +'">';
		for(var i=0; a[i]; i++) {
			if(a[i][1]) {
				str += '<param name="'+a[i][0]+'" value="'+a[i][1]+'" />';
			}
		}
		str += '</object>';
		
		if(!target || target == "undefined") { 
			d.write(str);
		} else if(target == "return string") { 
			return str;
		} else if(typeof target == "string") { 
			if(gE(target)) {
				gE(target).innerHTML = str;
			}
		} else if(typeof target == "object") { 
			target.innerHTML = str;
		}
	} else {
      if(replacementIMG && replacementURL){
         d.write("<a href="+ replacementURL +"><img src=\""+ replacementIMG +"\" width="+ w +" height="+ h +" border='0'></a>");
      }
   }
}
/******* END MACROMEDIA FLASH FUNCTIONS *******/
