var currentComment = 0;
var commentOpen = false;

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"));

function flashMovie(movieName) {
	if (navigator.appName.indexOf("Microsoft") != -1) {
		return window[movieName];
	} else {
		return document[movieName];
	}
}

function checkReady() {				
	return true;
}

function getScreenWidth() {			
	return window.innerWidth != null ? window.innerWidth : document.documentElement && document.documentElement.clientWidth ? document.documentElement.clientWidth : document.body != null ? document.body.clientWidth : null;		
}

function getScreenHeight() {			
	return  window.innerHeight != null ? window.innerHeight : document.documentElement && document.documentElement.clientHeight ? document.documentElement.clientHeight : document.body != null ? document.body.clientHeight : null;				
}

function resizeScreen( objID, size ) {
	var flashMovie = document.getElementById( 'flash_index' );
	var flashEmbed = document.getElementById( 'flash_index_embed' );
	if( size == "100%" || size > 400 ) {
		flashMovie.setAttribute( 'height', size );
		flashEmbed.setAttribute( 'height', size );		
	}
}

function getProtocol() {	
	var loc = window.location.toString();
	var locArray = loc.split('://');
	if( locArray.length == 2 ) {
		return locArray[0] + "://";
	}	
	return 'http://';
}

function getDomain() {	
	var protocol = getProtocol();
	var loc = window.location.toString();
	loc = loc.replace(protocol,'');
	var locArray = loc.split('/');
	if( locArray.length > 1 ) {
		return locArray[0];
	}
	return '';
}

function getPath() {
	var protocol = getProtocol();
	var loc = window.location.toString();
	var newLoc = loc.split('#');
	if( newLoc.length > 1 ) {
		loc = newLoc[0];
	}
	loc = loc.replace(protocol,'');
	var locArray = loc.split('/');
	var path = '/';
	for( var i = 1; i < locArray.length; i++ ) {
		if( i != locArray.length-1 ) {
			path += locArray[i] + "/";
		}
	}
	return path;
}

function getParamList() {
	var loc = window.location.toString();
	var locArray = loc.split('#');
	if( locArray.length > 1 ) {
		return locArray[1];
	}
	return '';
}

function getURL() {
	return window.location.toString();
}

function getReferrer() {
	return document.referrer;
}

function deepLink( url ) {
	var locSplit = window.location.toString().split( "#" );
	window.location = locSplit[0] + "#" + url;
	try {
		var pageTracker = _gat._getTracker("UA-611666-26");
		pageTracker._trackPageview();
	} catch(err) {
		
	}
}

function popUp( url, name, opts ) {
	window.open( url, name, opts );
}

function changeTitle( title ) {
	if( title ) {
		document.title = title;
	}
}

function createPrompt( text ) {
	var commentDiv = document.getElementById("comment_block");
	if( commentDiv ) {
		var comments = document.getElementById("comments_holder");
		var newDiv = document.createElement( "div" );
		newDiv.style.margin = "10px";
		newDiv.setAttribute( "id", "comment" + currentComment );
		var newtext = document.createTextNode( text );
		newDiv.appendChild( newtext );
		var lastComment = document.getElementById( "comment" + (currentComment-1) );
		comments.insertBefore( newDiv, lastComment );
		commentDiv.style.right = "10px";
		commentDiv.style.bottom = "10px";
		currentComment++;
	}
}

function closeComment() {	
	var commentDiv = document.getElementById( "comment_block" );
	if( commentOpen ) {
		commentDiv.style.height = "40px";
		commentDiv.style.width = "80px";
		commentDiv.style.right = "10px";
		commentDiv.style.bottom = "10px";
		commentOpen = false;
	} else {
		commentDiv.style.height = "400px";
		commentDiv.style.width = "400px";
		commentDiv.style.right = "10px";
		commentDiv.style.bottom = "10px";
		commentOpen = true;
	}
}

function scrollToTop() {
	window.scroll(0,0);
	window.scrollY = 0;
}

function pageEnd() {
	var cookieEnabled = (navigator.cookieEnabled) ? true : false;
	if (typeof navigator.cookieEnabled == "undefined" && !cookieEnabled) { 
		document.cookie="testcookie";
		cookieEnabled = (document.cookie.indexOf("testcookie") != -1) ? true : false;
	}
	if( !cookieEnabled ) {
		alert( "This site requires that you have cookies enabled, and it appears that you do not.  This may cause adverse affects on your browsing experience, and many parts of the site may not work properly." );
	}
}

function pageOffset() {
	if( document.body.scrollTop ) {
		return document.body.scrollTop;
	} else if( window.pageYOffset ) {
		return window.pageYOffset;
	} else {
		return 0;
	}
}

function getAJAX() {
	if (window.XMLHttpRequest) {
		// code for IE7+, Firefox, Chrome, Opera, Safari
		return new XMLHttpRequest();
	}
	if (window.ActiveXObject) {
		// code for IE6, IE5
		return new ActiveXObject("Microsoft.XMLHTTP");
	}
	return null;
}

function trackSession() {
	newAJAX = getAJAX();
	if( newAJAX ) {
		params = getParamList();
		varSplit = params.split( "&" );
		paramList = "";
		for( i = 0; i < varSplit.length; i++ ) {
			newSplit = varSplit[i].split( "=" );
			if( newSplit[0] == "section" ) {
				if( paramList.length > 0 ) {
					paramList += "&";	
				}
				paramList += "session_module=" + newSplit[1];
			} else if( newSplit[0] == "action" ) {
				actionSplit = varSplit[i].split( "?" );
				if( !actionSplit[1] ) {
					actionSplit[1] = "";
				}
				if( paramList.length > 0 ) {
					paramList += "&";	
				}
				paramList += "session_action=initialize";
				paramList += "&session_variables=" + escape( actionSplit[1] + "&" + actionSplit[0] );
			}
		}
		if( paramList.length > 0 ) {
			paramList += "&";
		}

		paramList += "session_url=" + urlencode(window.location.toString()) + "&session_referrer=" + urlencode( document.referrer ) + "&module=tracking&action=capture_session_history&format=xml";
		newAJAX.open( "GET", "index.php?" + paramList, true );
		newAJAX.onreadystatechange = function() {
			if( newAJAX.readyState == 4 && newAJAX.status == 200 ) {
				//alert( newAJAX.responseText );	
			} else {
				//alert( newAJAX.readyState );
			}
		}
		newAJAX.send( null );
	} else {
		alert( "AJAX Not Supported!" );
	}	
}

function urlencode (str) {
    // http://kevin.vanzonneveld.net
    // +   original by: Philip Peterson
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +      input by: AJ
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: Brett Zamir (http://brett-zamir.me)
    // +   bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +      input by: travc
    // +      input by: Brett Zamir (http://brett-zamir.me)
    // +   bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: Lars Fischer
    // +      input by: Ratheous
    // %          note 1: info on what encoding functions to use from: http://xkr.us/articles/javascript/encode-compare/
    // *     example 1: urlencode('Kevin van Zonneveld!');
    // *     returns 1: 'Kevin+van+Zonneveld%21'
    // *     example 2: urlencode('http://kevin.vanzonneveld.net/');
    // *     returns 2: 'http%3A%2F%2Fkevin.vanzonneveld.net%2F'
    // *     example 3: urlencode('http://www.google.nl/search?q=php.js&ie=utf-8&oe=utf-8&aq=t&rls=com.ubuntu:en-US:unofficial&client=firefox-a');
    // *     returns 3: 'http%3A%2F%2Fwww.google.nl%2Fsearch%3Fq%3Dphp.js%26ie%3Dutf-8%26oe%3Dutf-8%26aq%3Dt%26rls%3Dcom.ubuntu%3Aen-US%3Aunofficial%26client%3Dfirefox-a'
                             
    var hash_map = {}, unicodeStr='', hexEscStr='';
    var ret = (str+'').toString();
    
    var replacer = function (search, replace, str) {
        var tmp_arr = [];
        tmp_arr = str.split(search);
        return tmp_arr.join(replace);
    };
    
    // The hash_map is identical to the one in urldecode.
    hash_map["'"]   = '%27';
    hash_map['(']   = '%28';
    hash_map[')']   = '%29';
    hash_map['*']   = '%2A';
    hash_map['~']   = '%7E';
    hash_map['!']   = '%21';
    hash_map['%20'] = '+';
    hash_map['\u00DC'] = '%DC';
    hash_map['\u00FC'] = '%FC';
    hash_map['\u00C4'] = '%D4';
    hash_map['\u00E4'] = '%E4';
    hash_map['\u00D6'] = '%D6';
    hash_map['\u00F6'] = '%F6';
    hash_map['\u00DF'] = '%DF';
    hash_map['\u20AC'] = '%80';
    hash_map['\u0081'] = '%81';
    hash_map['\u201A'] = '%82';
    hash_map['\u0192'] = '%83';
    hash_map['\u201E'] = '%84';
    hash_map['\u2026'] = '%85';
    hash_map['\u2020'] = '%86';
    hash_map['\u2021'] = '%87';
    hash_map['\u02C6'] = '%88';
    hash_map['\u2030'] = '%89';
    hash_map['\u0160'] = '%8A';
    hash_map['\u2039'] = '%8B';
    hash_map['\u0152'] = '%8C';
    hash_map['\u008D'] = '%8D';
    hash_map['\u017D'] = '%8E';
    hash_map['\u008F'] = '%8F';
    hash_map['\u0090'] = '%90';
    hash_map['\u2018'] = '%91';
    hash_map['\u2019'] = '%92';
    hash_map['\u201C'] = '%93';
    hash_map['\u201D'] = '%94';
    hash_map['\u2022'] = '%95';
    hash_map['\u2013'] = '%96';
    hash_map['\u2014'] = '%97';
    hash_map['\u02DC'] = '%98';
    hash_map['\u2122'] = '%99';
    hash_map['\u0161'] = '%9A';
    hash_map['\u203A'] = '%9B';
    hash_map['\u0153'] = '%9C';
    hash_map['\u009D'] = '%9D';
    hash_map['\u017E'] = '%9E';
    hash_map['\u0178'] = '%9F';
    
    // Begin with encodeURIComponent, which most resembles PHP's encoding functions
    ret = encodeURIComponent(ret);
 
    for (unicodeStr in hash_map) {
        hexEscStr = hash_map[unicodeStr];
        ret = replacer(unicodeStr, hexEscStr, ret); // Custom replace. No regexing
    }
    
    // Uppercase for full PHP compatibility
    return ret.replace(/(\%([a-z0-9]{2}))/g, function (full, m1, m2) {
        return "%"+m2.toUpperCase();
    });
}