// JavaScript Document

function checkUrl(str) {
	//made by dexterT on december 04, 2007 9:00am - 5:00pm
	//input is a string
	//this will check if the input string have a url this will automatically change it to make it clickable
	//output: string with href

	var temp = str.split(" "); //splitting the input into array so that it will be easy to check if the its a url.
	var urlExtension = /\.nl|\.com|\.net|\.org|\.lan/; //the extension that will be valid for checking
	var retVal = "";
	var newLineBr = /<br>/;
//	var newLineLn = "\n";
	var index;
	var extension; //container of the extension
	var tempDomain; //container of the Domain name in backwards
	var domainName; //container of the Domain name
	var fullUrl;
	var href;

	for(var i=0; i<temp.length; i++) {
		extension = "";
		tempDomain = "";
		domainName = "";

		index = temp[i].search(urlExtension); //check if it have the extension of a url. -1 if not valid

		if(index != -1) {
			if(temp[i].search(newLineBr) != -1) {

				for(var j=index; j<temp[i].length; j++) {
					if(temp[i].charAt(j) != "<")
						extension += temp[i].charAt(j); //getting the extension of the url
					else j = temp[i].length;
				}

				for(j=index-1; j>=0; j--) {
					if(temp[i].charAt(j) != ">")
						tempDomain += temp[i].charAt(j); //getting the domain name of the url (still reversed, you can see the value if you alert tempDomain)
					else j = -1;
				}
				for(j=tempDomain.length; j>=0; j--)
					domainName += tempDomain.charAt(j); //reversing the resversed url
				fullUrl = domainName + extension; //concatinating the domain name and the url extension

				if(fullUrl.search("http://") == -1)
					href = "<a href='http://"+ fullUrl + "' target=new>" + fullUrl + "</a>"
				else href = "<a href='"+ fullUrl + "' target=new>" + fullUrl + "</a>"

				temp[i] = temp[i].replace(fullUrl, href); //making the normal text to href

			} else {
				for(var j=index; j<temp[i].length; j++) {
					if(temp[i].charAt(j) != "<")
						extension += temp[i].charAt(j);
					else j = temp[i].length;
				}
				temp[i] = "<a href='http://"+ temp[i] + "' target=new>" + temp[i] + "</a>"; //making the normal text to href
			}
		}
	}

	for(i=0; i<temp.length; i++)
		retVal += " " + temp[i]; //concatinating again the arrayed string.

	return retVal;
}


function detectPlugin() {
    // allow for multiple checks in a single pass
    var daPlugins = detectPlugin.arguments;
    //we have to return true if browser is Explorer for now
    if(navigator.appName!="Netscape"){
    		return true;
    }    
    if (navigator.plugins && navigator.plugins.length > 0) {
    
	var pluginsArrayLength = navigator.plugins.length;
	// for each plugin...
		for (pluginsArrayCounter=0; pluginsArrayCounter < pluginsArrayLength; pluginsArrayCounter++ ) {	
	    // loop through all desired names and check each against the current plugin name
	    	var numFound = 0;
	    	for(namesCounter=0; namesCounter < daPlugins.length; namesCounter++) {
		// if desired plugin name is found in either plugin name or description
				if( (navigator.plugins[pluginsArrayCounter].name.indexOf(daPlugins[namesCounter]) >= 0) || 
		    		(navigator.plugins[pluginsArrayCounter].description.indexOf(daPlugins[namesCounter]) >= 0) ) {
		    // this name was found
		    		numFound++;
		    //we have to return true if we found either of the agruments
		    		return true;
				}   
	    	}
		}
    }
    return false; //we didn't find any plug in 
} // detectPlugin

function detectMimetypes(str){
var i, x, minetypes, str1;
	
	if(browserSnipper()){
		return true;
	}
		
	x=navigator.mimeTypes.length;
	
	for(i=0; i<x ; i++){
		str1=navigator.mimeTypes[i].type;
		
		if(str1.indexOf(str)!=-1){
			return true;
		}
	}
	
	return false;
}

function getFileType(filename) {

	var index, s, fileExtension;

    s=filename;
    index=s.lastIndexOf(".");
        // We have the last "."
    if (index!=-1) {
		s=s.substr(index);
        return s.toLowerCase();
    }
    else
		return "unknown";
}


var myRegion12345; // The strange name so it won't be mixed with other variables, don't know if Jscript supports static within function

var br1352; // Same as above

function browserInfo() {

// returns info about the browser

var temp;

if (typeof(br1352)=="object") {
	return br1352;
}
else {
	temp=detectBrowser();
	br1352=new Object();
	br1352.browserName=temp.name;
	br1352.browserVersion=temp.version;
	br1352.platform=navigator.platform;
	br1352.userAgent=navigator.userAgent;
	br1352.systemLanguage=navigator.systemLanguage;
	br1352.userLanguage=navigator.userLanguage;
	// Now we set the shortName
	switch (br1352.browserName) {
		case "Microsoft Internet Explorer": {
			br1352.browserShortName="IE";
			break;
		}
		case "Opera": {
			br1352.browserShortName="Opera";
			break;
		}
		case "Netscape": {
			if (br1352.userAgent.indexOf("Firefox")>0)
				br1352.browserShortName="Firefox";
			else {
				if (br1352.userAgent.indexOf("Netscape")>0)
					br1352.browserShortName="Netscape";
				else
					br1352.browserShortName="Unknown";
			}
			break;
		}
		default: {
			br1352.browserShortName="Unknown";
			break;
		}
	}
	// Now we check for the flashVersion
	
	if (br1352.browserShortName=="IE") {
		flashVersion=VBGetSwfVer(1); // This needs to be included in the Functions file, for now it has to be in the index.html
	}
	else
		flashVersion=JSGetSwfVer();
	if (flashVersion!=-1) {
		br1352.flashSupport=true;
		br1352.flashVersion=flashVersion;
	}
	else
		br1352.flashSupport=false;		
	
	// return the object
	return br1352;
}
}

function detectBrowser(){

var browserInfo=new Object;
        var useragent = navigator.userAgent;
        var Browser = (useragent.indexOf('Opera') > -1) ? 'Opera' : navigator.appName;
        var pos = useragent.indexOf('MSIE');

        if (pos > -1) {
                Version = useragent.substring(pos + 5);
                var pos = Version.indexOf(';');
                var Version = Version.substring(0,pos);
        }
        if (Browser == "Netscape") {
                var Version = useragent.substring(8);
                var pos = Version.indexOf(' ');
                var Version = Version.substring(0, pos);
        }
        var pos = useragent.indexOf('Opera');
        if (pos > -1) {
                Version = useragent.substring(pos + 6);
                var pos = Version.indexOf(' ');
                var Version = Version.substring(0, pos);
        }

        if (Browser == "Netscape" && parseInt(navigator.appVersion) >= 5) {
			var pos = useragent.lastIndexOf('/');
			var Version = useragent.substring(pos + 1);
        }
        browserInfo.version=Version;
        browserInfo.name=Browser;
        return browserInfo;
}


function browserSnipper(){ 

// Don't use anymore in new sites. Obsolete. Use browserInfo!

var IE;

        if(navigator.appName=="Microsoft Internet Explorer"){
                return true;
        }
        else{
                return false;
        }

}


function createCookie(name,value,days) {
        //if you set the days to -1 the cookie will delete
        //if 0 the cookie will delete when the user close the browser
        if (days)
        {
                var date = new Date();
                /*Now get the current Time (in milliseconds) and add the required number of days
                 *(in milliseconds). Set the Time of the date to this new value, so that it now
                 *contains the date in milliseconds that the cookie should expire.*/
                date.setTime(date.getTime()+(days*24*60*60*1000));
                /*Set the variable expires to this date in the UTC/GMT format
                 *required by cookies.*/
                var expires = "; expires="+date.toGMTString();
        }
        else var expires = "";
        //Finally write the new cookie intodocument.cookie in the correct syntax
        document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name)
{//We're going to search for the name of the cookie, followed by an "=".
//So create this new string and put it in nameEQ:
        var nameEQ = name + "=";
/*        Then split document.cookie on semicolons. "ca" becomes an array
containing all cookies that are set for this domain and path.*/
        var ca = document.cookie.split(';');
        /*Then we go through the array (so through all cookies)*/
        for(var i=0;i < ca.length;i++)
        {
                var c = ca[i];/*Set "c" to the cookie to be checked.*/
                /*If the first character is a space, remove it by using the
                substring() method. Continue doing this until
                the first character is not a space*/
                while (c.charAt(0)==' ') c = c.substring(1,c.length);
                //now we found what are looking for we have to return it
                if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
        }
        /*If, after having gone through all cookies, we haven't found the name we're
        looking for, the cookie is not present. We return null.*/
        return null;
}

function eraseCookie(name)
{
        //we have to call the createCookie function and supply negative value for the days
        //The browser, seeing that the expiry date has passed, immediately removes the cookie
        createCookie(name,"",-1);
}


function objectReady(obj) {
	if (typeof(obj.myReadyState)=="boolean")
		return obj.myReadyState;
	else {
        if (navigator.appName=="Microsoft Internet Explorer")
                return (obj.readyState=="complete");
        else {
            if (navigator.appName=="Netscape")
                   return obj.complete;
            else
                   window.alert("Browser not supported");
        }
    }
}


function readyFunction(object)
{
        if (object.readyState=="complete")
                writeStatus("Done");
        else
                writeStatus("Loading");
        return object;
}	

function waitForReady(object) {

        if (object.readyState!="complete")
                object.onreadystatechange=function anonymus() {readyFunction(object)};
        return object;
}

function writeStatus(str) {
        window.status=str;
}	


function showNavigator() {
        message("Navigator code name: "+navigator.appCodeName);
        message("Navigator name: "+navigator.appName);
        message("Navigator version: "+navigator.appVersion);
        message("Navigator user agent: "+navigator.userAgent);
        message("Navigator platform: "+navigator.platform);
}