// -------------------------------------------------------------------------------//
// GOOGLE ANALYTICS                                                               //
// -------------------------------------------------------------------------------//

if ((TrackingCode == undefined) || (TrackingCode == "")){
	var TrackingCode = "UA-15166699-1";
}

if ((ClientCode == undefined) || (ClientCode == "")){
	var ClientCode = "none";
}

var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
var hndl = window.setTimeout("StartTracking()", 100);

function StartTracking(){
if (typeof(_gat) == 'object')
{
window.clearTimeout(hndl);
	var firstTracker = _gat._getTracker(TrackingCode);
	firstTracker._initData();
	firstTracker._trackPageview();
	if(ClientCode != "none"){
		var secondTracker = _gat._getTracker(ClientCode);
		secondTracker._setDomainName("none");
		secondTracker._setAllowLinker(true);
		secondTracker._initData();
		secondTracker._trackPageview();
	}
} else {
hndl = window.setTimeout("StartTracking()", 1000);
}
}

// -------------------------------------------------------------------------------//
// READ MORE TOGGLE                                                               //
// -------------------------------------------------------------------------------//
function readmore(obj, objlink) {
	var readmore = document.getElementById(obj);
	var readmorelink = document.getElementById(objlink);
	if (readmore != null) {
		if (readmore.style.display != 'none') {
			readmore.style.display = 'none';
			readmorelink.innerHTML = 'click here';
		}
		else {
			readmore.style.display = 'block';
			readmorelink.innerHTML = 'click here (hide)';
		}
	}
}

// -------------------------------------------------------------------------------//
// PAGE FUNCTIONS                                                                 //
// -------------------------------------------------------------------------------//
function startpage(section) {	
	browserDetection();
	
	if(section != "lasso"){
		changeCSS();
	}
	
	if((section != null) && (section != "lasso")) {
		section(); //this will launch the relevant page functions
	}
}

// -------------------------------------------------------------------------------//
// MORE INFO                                                                      //
// -------------------------------------------------------------------------------//
function moreinfo(){
	readmore('readmore1','readmore1-link');
}

// -------------------------------------------------------------------------------//
// PNG TRANSPARENCY                                                               //
// -------------------------------------------------------------------------------//

var clear="includes/javascript/clear.gif" //path to clear.gif

pngfix=function(){var els=document.getElementsByTagName('*');var ip=/\.png/i;var i=els.length;while(i-- >0){var el=els[i];var es=el.style;if(el.src&&el.src.match(ip)&&!es.filter){es.height=el.height;es.width=el.width;es.filter="progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+el.src+"',sizingMethod='crop')";el.src=clear;}else{var elb=el.currentStyle.backgroundImage;if(elb.match(ip)){var path=elb.split('"');var rep=(el.currentStyle.backgroundRepeat=='no-repeat')?'crop':'scale';es.filter="progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+path[1]+"',sizingMethod='"+rep+"')";es.height=el.clientHeight+'px';es.backgroundImage='none';var elkids=el.getElementsByTagName('*');if (elkids){var j=elkids.length;if(el.currentStyle.position!="absolute")es.position='static';while (j-- >0)if(!elkids[j].style.position)elkids[j].style.position="relative";}}}}}
if (navigator.appVersion.indexOf("MSIE") != -1){
	window.attachEvent('onload',pngfix);
}

// -------------------------------------------------------------------------------//
// PAGE REDIRECT                                                                  //
// -------------------------------------------------------------------------------//

function pageRedirect(address){
	window.location = address;
}

// -------------------------------------------------------------------------------//
// CHANGE CSS                                                                     //
// -------------------------------------------------------------------------------//

function changeCSS() {	
	if (document.getElementById("stylesheet-opera")) {
		if (navigator.userAgent.toLowerCase().indexOf('opera/9') < 0) {
			// NOT USING OPERA 10 SO REMOVE STYLESHEET (ABOVE IS USER AGENT, BUT ACTUAL VERSION IS 10)
			document.getElementById("stylesheet-opera").href = "";
		}
	}
	
	if (navigator.userAgent.toLowerCase().indexOf('firefox/2') < 0) {
		// NOT USING FIREFOX 2 SO REMOVE BOTH STYLESHEETS
		document.getElementById("stylesheet-firefox2").href = "";
		document.getElementById("stylesheet-firefox2-mac").href = "";
	} else if (navigator.userAgent.toLowerCase().indexOf('firefox/2') > -1) {
		if (navigator.userAgent.toLowerCase().indexOf('macintosh') < 0) {
			// NOT USING FIREFOX2 FOR MAC SO REMOVE STYLESHEET
			document.getElementById("stylesheet-firefox2-mac").href = "";
		} else {
			// NOT USING FIREFOX2 FOR WINDOWS SO REMOVE STYLESHEET
			document.getElementById("stylesheet-firefox2").href = "";
		}
	}
	
	if (document.getElementById("stylesheet-ie6")) {
		if (navigator.userAgent.toLowerCase().indexOf('msie 6') < 0) {
			// NOT USING INTERNET EXPLORER 6 SO REMOVE STYLESHEET
			document.getElementById("stylesheet-ie6").href = "";
		}	
	}
	
	if (document.getElementById("stylesheet-ie7")) {
		if (navigator.userAgent.toLowerCase().indexOf('msie 7') < 0) {
			// NOT USING INTERNET EXPLORER 7 SO REMOVE STYLESHEET
			document.getElementById("stylesheet-ie7").href = "";
		}	
	}
}

// -------------------------------------------------------------------------------//
// BROWSER DETECTION                                                              //
// -------------------------------------------------------------------------------//

function browserDetection() {
	var BrowserDetect = {
		init: function () {
			this.browser = this.searchString(this.dataBrowser) || "Unknown";
			this.version = this.searchVersion(navigator.userAgent)
				|| this.searchVersion(navigator.appVersion)
				|| "0";
			this.OS = this.searchString(this.dataOS) || "Unknown";
		},
		searchString: function (data) {
			for (var i=0;i<data.length;i++)	{
				var dataString = data[i].string;
				var dataProp = data[i].prop;
				this.versionSearchString = data[i].versionSearch || data[i].identity;
				if (dataString) {
					if (dataString.indexOf(data[i].subString) != -1)
						return data[i].identity;
				}
				else if (dataProp)
					return data[i].identity;
			}
		},
		searchVersion: function (dataString) {
			var index = dataString.indexOf(this.versionSearchString);
			if (index == -1) return;
			return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
		},
		dataBrowser: [
			{
				string: navigator.userAgent,
				subString: "Chrome",
				identity: "Chrome"
			},
			{ 	string: navigator.userAgent,
				subString: "OmniWeb",
				versionSearch: "OmniWeb/",
				identity: "OmniWeb"
			},
			{
				string: navigator.userAgent,
				subString: "LittleSnapper",
				identity: "LittleSnapper"
			},
			{
				string: navigator.vendor,
				subString: "Apple",
				identity: "Safari",
				versionSearch: "Version"
			},
			{
				prop: window.opera,
				identity: "Opera"
			},
			{
				string: navigator.vendor,
				subString: "iCab",
				identity: "iCab"
			},
			{
				string: navigator.vendor,
				subString: "KDE",
				identity: "Konqueror"
			},
			{
				string: navigator.userAgent,
				subString: "Firefox",
				identity: "Firefox"
			},
			{
				string: navigator.vendor,
				subString: "Camino",
				identity: "Camino"
			},
			{		// for newer Netscapes (6+)
				string: navigator.userAgent,
				subString: "Netscape",
				identity: "Netscape"
			},
			{
				string: navigator.userAgent,
				subString: "MSIE",
				identity: "Explorer",
				versionSearch: "MSIE"
			},
			{
				string: navigator.userAgent,
				subString: "Gecko",
				identity: "Mozilla",
				versionSearch: "rv"
			},
			{ 		// for older Netscapes (4-)
				string: navigator.userAgent,
				subString: "Mozilla",
				identity: "Netscape",
				versionSearch: "Mozilla"
			}
		],
		dataOS : [
			{
				string: navigator.platform,
				subString: "Win",
				identity: "Windows"
			},
			{
				string: navigator.platform,
				subString: "Mac",
				identity: "Mac"
			},
			{
				   string: navigator.userAgent,
				   subString: "iPhone",
				   identity: "iPhone/iPod"
			},
			{
				string: navigator.platform,
				subString: "Linux",
				identity: "Linux"
			}
		]
	
	};
	BrowserDetect.init();

	//Increments by one on every occurance where the browser being used is not in the list of working browsers
	var redirectCount = 0;
	
	//An array containing all the working browsers
	var browsers = new Array('Firefox','Explorer','Chrome','Opera','Camino','Konqueror','Safari') ;
	var browserlowest = new Array('2','7','4','9','2','4','3') ;

	//For loop goes through the array and adds one to the counter everytime the browsers is not equal to the current array item
	for (i=0; i < browsers.length; i++) {
		if (BrowserDetect.browser != browsers[i]) {
			redirectCount++;
		} else if (BrowserDetect.version < browserlowest[i]) {
			window.location = 'http://www.i-studentenquiry.com/alert/english/website.html';
		}
	}
	
	//If the counter is not equal to the lenght of the array it means the browser being use is not permitted and will redirect
	if (redirectCount == browsers.length) {
		window.location = 'http://www.i-studentenquiry.com/alert/english/website.html';
	}
}

// -------------------------------------------------------------------------------//
// TOOL TIP FUNCTION                                                              //
// -------------------------------------------------------------------------------//

var tooltip=function(){
	var id = 'tt';
	var top = 12;
	var left = 3;
	var maxw = 300;
	var speed = 10;
	var timer = 20;
	var endalpha = 90;
	var alpha = 0;
	var tt,t,c,b,h;
	var ie = document.all ? true : false;
	return{
		show:function(v,w){
			if(tt == null){
				tt = document.createElement('div');
				tt.setAttribute('id',id);
				t = document.createElement('div');
				t.setAttribute('id',id + 'top');
				c = document.createElement('div');
				c.setAttribute('id',id + 'cont');
				b = document.createElement('div');
				b.setAttribute('id',id + 'bot');
				tt.appendChild(t);
				tt.appendChild(c);
				tt.appendChild(b);
				document.body.appendChild(tt);
				tt.style.opacity = 0;
				tt.style.filter = 'alpha(opacity=0)';
				document.onmousemove = this.pos;
			}
			tt.style.display = 'block';
			c.innerHTML = v;
			tt.style.width = w ? w + 'px' : 'auto';
			if(!w && ie){
				t.style.display = 'none';
				b.style.display = 'none';
				tt.style.width = tt.offsetWidth;
				t.style.display = 'block';
				b.style.display = 'block';
			}
			if(tt.offsetWidth > maxw){tt.style.width = maxw + 'px'}
			h = parseInt(tt.offsetHeight) + top;
			clearInterval(tt.timer);
			tt.timer = setInterval(function(){tooltip.fade(1)},timer);
		},
		pos:function(e){
			var u = ie ? event.clientY + document.documentElement.scrollTop : e.pageY;
			var l = ie ? event.clientX + document.documentElement.scrollLeft : e.pageX;
			tt.style.top = (u + top) + 'px';
			tt.style.left = (l + left) + 'px';
		},
		fade:function(d){
			var a = alpha;
			if((a != endalpha && d == 1) || (a != 0 && d == -1)){
				var i = speed;
				if(endalpha - a < speed && d == 1){
					i = endalpha - a;
				}else if(alpha < speed && d == -1){
					i = a;
				}
				alpha = a + (i * d);
				tt.style.opacity = alpha * .01;
				tt.style.filter = 'alpha(opacity=' + alpha + ')';
			}else{
				clearInterval(tt.timer);
				if(d == -1){tt.style.display = 'none'}
			}
		},
		hide:function(){
			clearInterval(tt.timer);
			tt.timer = setInterval(function(){tooltip.fade(-1)},timer);
		}
	};
}();

// -------------------------------------------------------------------------------//
// LAUNCHES POPUP WINDOWS IN FULL SCREEN WITH SCROLLBARS                          //
// -------------------------------------------------------------------------------//
function fullscreen(url,name) {
	if (window.name != "ug" && window.name != "pg" && window.name != "el") {
		window.open(url,name,'width='+screen.availWidth+',height='+screen.availHeight+',scrollbars=1,location=0,status=0,toolbar=0,menubar=0,top=0, left=0');
	} else {
		window.location.href = url;
	}
}

// -------------------------------------------------------------------------------//
// LIMIT TEXTAREA CHARACTERS							                          //
// -------------------------------------------------------------------------------//
function ismaxlength(obj) {
	var mlength = obj.getAttribute? parseInt(obj.getAttribute("maxlength")) : "";
	if (obj.getAttribute && obj.value.length>mlength) {
		obj.value=obj.value.substring(0,mlength);
	}
}