//onload auto
function WindowOnload(oNewOnloadFunction) {
    var oPreviousOnloadFunction = window.onload;
    window.onload = function() {
        if (oPreviousOnloadFunction) { oPreviousOnloadFunction(); }
        oNewOnloadFunction();
    }
}

/* submit form by id */
function SubmitForm(x) {
	formid = document.getElementById(x); 
	formid.submit(); 
}

/* submit form by id with uploadlayer*/
function SubmitFormL(x) {
	formid = document.getElementById(x); 
	formid.submit(); 
  	document.getElementById('uploadlayer').style.visibility = 'visible';
}

/* toggle class // id, class1, class2 */
function toggleClass(x, a, b) { 
	xid = document.getElementById(x); 
	xid.className = (xid.className == a) ? b : a; 
}

/* toggle visibility */
function togglevis(x) { 
	xid = document.getElementById(x); 
	xid.style.visibility = (xid.style.visibility=='visible') ? 'hidden' : 'visible';
}

/* toggle image // imgid // src a // src b*/
function toggleimg(x, a, b) { 
	xid = document.getElementById(x); 
	xid.src = (xid.src == a) ? b : a;
}

/*(de)select all //with img indicatior // imgid // src a // src b // f containerid */
function chkBoxesImg(x, a, b, f) { 
	xid = document.getElementById(x); 	
	docvar = document.getElementById(f);
	inputs = docvar.getElementsByTagName('input'); 
	if (xid.src == a) {	
		for (i = 0; i < inputs.length; i++) {		
			if (inputs[i].type == "checkbox") { 			
				spanid = "checkbox" + inputs[i].name;
				span = document.getElementById(spanid); 	
				span.style.backgroundPosition = "0 -" + 40 + "px";
				inputs[i].checked = true;		
			}
		}
		xid.src = b;
	} else { 
		for (i = 0; i < inputs.length; i++) { 
			if (inputs[i].type == "checkbox") { 						
				spanid = "checkbox" + inputs[i].name; 
				span = document.getElementById(spanid); 			
				span.style.backgroundPosition = "0 0";
				inputs[i].checked = false;
			}
		}
		xid.src = a;		
	}
}

/*deselect others //with img indicatior // imgid // src a // f containerid */
function chkBoxesImgReset(x, a, f) { 
	xid = document.getElementById(x);
	docvar = document.getElementById(f);
	inputs = docvar.getElementsByTagName('input');
	for (i = 0; i < inputs.length; i++) {  
		if (inputs[i].type == 'checkbox') { 							
			spanid = "checkbox" + inputs[i].name 
			span = document.getElementById(spanid); 			
			span.style.backgroundPosition = "0 0";
			inputs[i].checked = false;
		}
	}		
	xid.src = a;
} 

/*deselect checkboxes // like radiobutton // f containerid // elementnr // reset img indicatior imgid x into imgsrc a */
function chkBoxesDeselect(f, i, x, a) { 
	xid = document.getElementById(x); 
	docvar = document.getElementById(f);
	inputs = docvar.getElementsByTagName('input');
	for (j = 0; j < inputs.length; j++) {  
		if (inputs[j].type == 'checkbox' && j == i) { 							
			spanid = "checkbox" + inputs[j].name 
			span = document.getElementById(spanid); 			
			span.style.backgroundPosition = "0 0";
			inputs[j].checked = false;
		}
	}
	xid.src = a;
} 

/*make checkbox function like radiobutton // f containerid // i this elementnumber // n thiselement nameid // x show/hide nameid // c showhide classname */
function cboxTOradio(f, i, n, x, c) { 
	varf = document.getElementById(f);
	inputs = varf.getElementsByTagName('input');
	for (j = 0; j < inputs.length; j++) {  
		var exprelemid = /n/; 
		var elementid = n + i;
		if (inputs[j].type == 'checkbox' && inputs[j].name != elementid) { 				
			if (exprelemid.test(inputs[j].name)) { 
				spanid = "checkbox" + inputs[j].name;
				span = document.getElementById(spanid); 			
				span.style.backgroundPosition = "0 0";
				inputs[j].checked = false;				
				if (x != '' && c != '') { 
					var splitelemid = inputs[j].name.split(n);
					var elemid = splitelemid[1]; 
					var divid = x + elemid;
					var varx = document.getElementById(divid);
					varx.className = c;				
				}
			}
		}
	}
} 

/*show / hide stuff if checkbox or radiobutton is checked / unchecked // f containerid // i this elementname // x elementid to show / hide //  */
function btnShowHide(f, i) { 
	docvar = document.getElementById(f);
	inputs = docvar.getElementsByTagName('input');
	for (j = 0; j < inputs.length; j++) {  
		if (inputs[j].type == 'checkbox' && inputs[j].name != i) { 					
			spanid = "checkbox" + inputs[j].name 
			span = document.getElementById(spanid); 			
			span.style.backgroundPosition = "0 0";
			inputs[j].checked = false;
		}
	}
} 

/* Set img indicator if all checkboxes are checked // f containerid // imgid x into imgsrc a imgsrc b*/
function chkBoxesSetImg(f, x, a, b) { 
	xid = document.getElementById(x); 
	docvar = document.getElementById(f);
	inputs = docvar.getElementsByTagName('input');
	var y = 0; var t = 0;
	for (i = 0; i < inputs.length; i++) {  	
		if (inputs[i].type == 'checkbox' && inputs[i].readOnly == false) { t++; }
		if (inputs[i].type == 'checkbox' && inputs[i].checked == true) { y++; }
	}		
	if (y == t) { xid.src = b; } else { xid.src = a; } 
} 

function encodeUrl(url) {
	if (url.indexOf("?")>0) {
		encodedParams = "?";
 		parts = url.split("?");
 		params = parts[1].split("&");
 		for(i = 0; i < params.length; i++) {
			if (i > 0) { encodedParams += "&"; }
			if (params[i].indexOf("=")>0) { //Avoid null values
				p = params[i].split("=");
				encodedParams += (p[0] + "=" + escape(encodeURI(p[1])));
			} else { encodedParams += params[i]; }
		}
		url = parts[0] + encodedParams;
	}
	return url;
}

var myPopupWindow = ''; var menubar = 'no';  var toolbar = 'no';
function openPopupWindow(url, name, width, height, menubar, toolbar) {
	name = name.replace(/\/|\-|\./gi, "");
	var whitespace = new RegExp("\\s","g");
	name = name.replace(whitespace,"");
	var left  = (screen.width  - width)/2;
	var top  = (screen.height - height)/2;
	var params = 'width='+width+', height='+height;
	params += ', top='+top+', left='+left;
	params += ', directories=no';
	params += ', location=no';
	params += ', menubar=' + menubar;
	params += ', resizable=no';
	params += ', scrollbars=no';
	params += ', status=no';
	params += ', toolbar=' + toolbar;
	//If it is already open
	if (!myPopupWindow.closed && myPopupWindow.location)  {  myPopupWindow.location.href = encodeUrl(url); }
	else {
		myPopupWindow = window.open(encodeUrl(url), name, params);
		if (!myPopupWindow.opener) myPopupWindow.opener = self;
	}
     //If my main window has focus - set it to the popup
	if (window.focus) {myPopupWindow.focus()}


}


function createSimpleElement(type, id, value, appendid) {
	var newElement = document.createElement(type);
	newElement.setAttribute('id', id);
	document.getElementById(appendid).appendChild(newElement);
	document.getElementById(id).innerHTML = value;
}
function removeSimpleElement(id, appendid) {
	var removeElement = document.getElementById(id);
	document.getElementById(appendid).removeChild(removeElement);
}
/*http://www.interwebby.com/2006/02/04/3/ close a window also in firefox */
function closeWindow() {
	window.open('','_parent','');
	window.close();
}

function ClearOptions(OptionList) {	for (x = OptionList.length; x >= 0; x = x - 1) { OptionList[x] = null; }}
function AddToOptionList(OptionList, OptionValue, OptionText) { OptionList[OptionList.length] = new Option(OptionText, OptionValue); }