﻿// JScript File
var browser = new browser();
function browser() {
    this.isIE = false;
    this.isFireFox = false;
    this.isOpera = false;
    this.version = parseFloat(navigator.appVersion);
    
    this.isWindows = false;
    this.isMac = false;
    this.isLinux = false;
    
    var sName = navigator.appName;
    if (sName == "Netscape" && this.version >= 5) {this.isFireFox = true};
    if (sName == "Microsoft Internet Explorer") {
        this.isIE = true;
        if((navigator.userAgent.indexOf("MSIE 3") != -1)) {this.version=3;}
        if((navigator.userAgent.indexOf("MSIE 4") != -1)) {this.version=4;}
        if((navigator.userAgent.indexOf("MSIE 5.0") != -1)) {this.version=5;}
        if((navigator.userAgent.indexOf("MSIE 5.5") != -1)) {this.version=5.5;}
        if((navigator.userAgent.indexOf("MSIE 6.0") != -1)) {this.version=6;}
        if((navigator.userAgent.indexOf("MSIE 7.0") != -1)) {this.version=7;}
    }
    
    this.isWindows = navigator.userAgent.indexOf("Win") != -1;
    this.isMac = navigator.userAgent.indexOf("Mac") != -1;
    this.isLinux = navigator.userAgent.indexOf("Lin") != -1;
}

function getRandomize(minValue, maxValue, currentValue) {
    var iValueNew = (Math.floor(Math.random() * (maxValue - minValue))) + minValue;
    while (currentValue != null && iValueNew == currentValue && maxValue > 1) {
        iValueNew = getRandomize(minValue, maxValue);
    }
    return iValueNew;
}

/************************************************************************************************/
/* BEGIN Controls */
/************************************************************************************************/
function Select_Contains(selectbox, value) {
	var bContains = false;
	try {
		for(var ii=0; ii< selectbox.options.length; ii++) {
			if(selectbox.options[ii].value == value) {bContains = true;}
		}
	} catch(ex) {
		LogError(ex, "Select_Contains");
	}
	return bContains;
}

function Select_Clear(selectbox) {
	try {
		for(var ii=selectbox.options.length; ii>0; ii--) {
			selectbox.remove(selectbox.options[ii]);
		}
	} catch(ex) {
		LogError(ex, "Select_Clear");
	}
}

function Select_Fill(selectbox, array) {
	try {
		for(var ii=0; ii<array.length; ii++) {
			Select_Add(selectbox, array[ii][0], array[ii][1]);
		}
	} catch(ex) {
		LogError(ex, "Select_Fill");
	}
}

function Select_Add(selectbox, value, text) {
	try {
		var option = new Option();
		option.value = value;
		option.text = text;
		try {
			selectbox.add(option, null); //w3c
		} catch(ex) {
			selectbox.add(option); //ie
		}
	} catch(ex) {
		LogError(ex, "Select_Add");
	}
}

function SetStatusRadioGroup(radioGroup, enabled)
{
	for(var jj=0;jj<radioGroup.length;jj++)
	{
		radioGroup[jj].disabled = !enabled;
	}
}

function GetValueRadioGroup(radioGroup)
{
	for(var jj=0;jj<radioGroup.length;jj++)
	{
		if(radioGroup[jj].checked==true){return radioGroup[jj].value;}
	}
}


/************************************************************************************************/
/* END Controls */
/************************************************************************************************/

/************************************************************************************************/
/* BEGIN styles */
/************************************************************************************************/
function setBackgroundColor(e, color) {
    e.style.backgroundColor = color;
}

function setClassname(e, className) {
    e.className = className;
}

function setVisibleHidden(e) {
    e.style.display == "none" ? e.style.display = "" : e.style.display = "none";
}

function setExpandCollapseBlock(blockId) {
    var e = document.getElementById(blockId);
    setVisibleHidden(e);
}

function setExpandBlock(blockId) {
    var e = document.getElementById(blockId);
    e.style.display = "";
}

function setCollapseBlock(blockId) {
    var e = document.getElementById(blockId);
    e.style.display = "none";
}

function setExpandCollapse(imageId, imageExpand, imageCollapse, blockId) {
    setExpandCollapseBlock(blockId);
    if (!imageId == null) {
        var e = document.getElementById(imageId);
        (e.src.length >= imageExpand.length && e.src.substring((e.src.length-imageExpand.length))) == imageExpand ? e.src = imageCollapse : e.src = imageExpand;
    }
}
/************************************************************************************************/
/* END styles */
/************************************************************************************************/

/************************************************************************************************/
/* BEGIN Array bewerkingen */
/************************************************************************************************/
function FindArrayValue(ar, value) {
    var bFound = false;
    for (var ii=0; ii<ar.length; ii++) {
        if(ar[ii] == value) {bFound = true;}
    }
    return bFound;
}

function AddArrayValue(ar, value) {
    var ar2 = new Array(ar.length);
    for (var ii=0; ii<ar.length; ii++) {
        ar2[ii] = ar[ii];
    }
    ar2[ii] = value;
    return ar2;
}

function RemoveArrayValue(ar, value) {
    if(FindArrayValue(ar, value)) {
        var ar2 = new Array(ar.length-1);
        var cor = 0;
       
        for (var ii=0; ii<ar.length; ii++) {
            if(ar[ii] != value) {
                ar2[ii+cor] = ar[ii];
            } else {
				cor--;
            }
        }
        return ar2;
    }
    return ar;
}

function GetArrayValue(ar, iID, iColumn) {
	for (var ii=0; ii<ar.length; ii++) {
		if(ar[ii][0] == iID) {
			return ar[ii][iColumn];
		}
	}
	return "";
}
/************************************************************************************************/
/* END Array bewerkingen */
/************************************************************************************************/

/************************************************************************************************/
/* BEGIN Popup */
/************************************************************************************************/
var arPopups = new Array();

function popup() {
	this.type = 1;
	this.url = "";
	this.name = "Popup_" + (arPopups.length + 1);
	this.html = "";

	this.parameters = new popup_parameters();

	this.show = popup_show;
	this.get_parameters = popup_get_parameters;
	this.window = null;
	
	arPopups[arPopups.length] = this;
	
	function popup_show() {
		switch(this.type) {
			case 1:
				this.window = window.open(this.url, this.name, this.get_parameters());
				break;
		}
		
	}
	
	function popup_get_parameters() {
		var sParams = "width={0},height={1}";
		sParams = sParams.replace("{0}", this.parameters.width);
		sParams = sParams.replace("{1}", this.parameters.height);
		if(this.parameters.left != null) {sParams += ",left="+this.parameters.left;}
		if(this.parameters.top != null) {sParams += ",top="+this.parameters.top;}
		if(this.parameters.channelmode != null) {sParams += ",channelmode="+(this.parameters.channelmode?"yes":"no");}
		if(this.parameters.directories != null) {sParams += ",directories="+(this.parameters.directories?"yes":"no");}
		if(this.parameters.fullscreen != null) {sParams += ",fullscreen="+(this.parameters.fullscreen?"yes":"no");}
		if(this.parameters.location != null) {sParams += ",location="+(this.parameters.location?"yes":"no");}
		if(this.parameters.menubar != null) {sParams += ",menubar="+(this.parameters.menubar?"yes":"no");}
		if(this.parameters.resizable != null) {sParams += ",resizable="+(this.parameters.resizable?"yes":"no");}
		if(this.parameters.scrollbars != null) {sParams += ",scrollbars="+(this.parameters.scrollbars?"yes":"no");}
		if(this.parameters.status != null) {sParams += ",status="+(this.parameters.status?"yes":"no");}
		if(this.parameters.titlebar != null) {sParams += ",titlebar="+(this.parameters.titlebar?"yes":"no");}
		if(this.parameters.toolbar != null) {sParams += ",toolbar="+(this.parameters.toolbar?"yes":"no");}
		return sParams;
	}
}

function popup_parameters() {
	this.width = 600;
	this.height = 400;
	this.left = null;
	this.top = null;
	this.channelmode = null;
	this.directories = null;
	this.fullscreen = null;
	this.location = null;
	this.menubar = null;
	this.resizable = null;
	this.scrollbars = null;
	this.status = null;
	this.titlebar = null;
	this.toolbar = null;
}
/************************************************************************************************/
/* END Popup */
/************************************************************************************************/

/************************************************************************************************/
/* BEGIN XML */
/************************************************************************************************/
function xml_firstChild(e) {
	e = e.firstChild;
	while (e.nodeType != 1) {e = e.nextSibling;}
	return e;
}
/************************************************************************************************/
/* END XML */
/************************************************************************************************/

/************************************************************************************************/
/* BEGIN XML document */
/************************************************************************************************/
/**
* Create a new Document object. If no arguments are specified,
* the document will be empty. If a root tag is specified, the document
* will contain that single root tag. If the root tag has a namespace
* prefix, the second argument must specify the URL that identifies the
* namespace.
*/
function XMLnewDocument(rootTagName, namespaceURL) { 
	if (!rootTagName) rootTagName = ""; 
	if (!namespaceURL) namespaceURL = ""; 
	if (document.implementation && document.implementation.createDocument) { 
		// This is the W3C standard way to do it 
		return document.implementation.createDocument(namespaceURL, rootTagName, null); 
	} else { // This is the IE way to do it 
		// Create an empty document as an ActiveX object 
		// If there is no root element, this is all we have to do 
		var doc = new ActiveXObject("MSXML2.DOMDocument"); 
		// If there is a root tag, initialize the document 
		if (rootTagName) { 
			// Look for a namespace prefix 
			var prefix = ""; 
			var tagname = rootTagName; 
			var p = rootTagName.indexOf(':'); 
			if (p != -1) { 
				prefix = rootTagName.substring(0, p); 
				tagname = rootTagName.substring(p+1); 
			} 
			// If we have a namespace, we must have a namespace prefix 
			// If we don't have a namespace, we discard any prefix 
			if (namespaceURL) { 
				if (!prefix) prefix = "a0"; // What Firefox uses 
			} else prefix = ""; 
			// Create the root element (with optional namespace) as a 
			// string of text 
			var text = "<" + (prefix?(prefix+":"):"") +  tagname + (namespaceURL ?(" xmlns:" + prefix + '="' + namespaceURL +'"') :"") + "/>"; 
			// And parse that text into the empty document 
			doc.loadXML(text); 
		}
		return doc;
	}
}

/**
* Synchronously load the XML document at the specified URL and
* return it as a Document object
*/ 
function XMLload(url) { 
	// Create a new document with the previously defined function 
	var xmldoc = XMLnewDocument(); 
	xmldoc.async = false;  // We want to load synchronously 
	xmldoc.load(url);      // Load and parse 
	return xmldoc;         // Return the document 
}

/**
* Parse the XML document contained in the string argument and return
* a Document object that represents it.
*/ 
function XMLparse(text) { 
	if (typeof DOMParser != "undefined") { 
	// Mozilla, Firefox, and related browsers 
		return (new DOMParser()).parseFromString(text, "application/xml"); 
	} else if (typeof ActiveXObject != "undefined") { 
		// Internet Explorer. 
		var doc = XMLnewDocument();  // Create an empty document 
		doc.loadXML(text);            // Parse text into it 
		return doc;                   // Return it 
	} else { 
		// As a last resort, try loading the document from a data: URL 
		// This is supposed to work in Safari. Thanks to Manos Batsis and 
		// his Sarissa library (sarissa.sourceforge.net) for this technique. 
		var url = "data:text/xml;charset=utf-8," + encodeURIComponent(text); 
		var request = new XMLHttpRequest(); 
		request.open("GET", url, false); 
		request.send(null); 
		return request.responseXML; 
	} 
}
/************************************************************************************************/
/* END XML document */
/************************************************************************************************/


