function if_popUp(width, height, valign, halign, options, file){
    if (options == "") {
        options = "dependent=yes, scrollbars=1, hotkeys=no, resizable=yes, ";
        
    }
    options += "width=" + width + ", ";
    options += "height=" + height + ", ";
    switch (valign) {
        case "left":
            valign = 0;
            break;
        case "center":
            valign = ((screen.availWidth / 2) - (width / 2));
            break;
        case "right":
            valign = (screen.availWidth - width);
            break;
        default:
            valign = valign;
            break;
    }
    options += "left=" + valign + ", ";
    switch (halign) {
        case "top":
            halign = 0;
            break;
        case "middle":
            halign = ((screen.availHeight / 2) - (height / 2));
            break;
        case "bottom":
            halign = (screen.availHeight - height);
            break;
        default:
            halign = halign;
            break;
    }
    options += "top=" + halign;
    popUpwin = window.open(file, "popUpWin", options);
    
}


function func(obj){
    var val = "";
    var hide = "";
    var sect = "";
    if (obj.id == "id_head") {
        val = "val_head";
        hide = "hide_head";
        sect = "head_sect";
    }
    if (obj.id == "id_short") {
        val = "val_short";
        hide = "hide_short";
        sect = "short_sect";
    }
    if (obj.id == "id_long") {
        val = "val_long";
        hide = "hide_long";
        sect = "long_sect";
    }
    
    var text = document.getElementById(obj.id).innerHTML;
    //text = text.substring(0, (text.length - 5));
    document.getElementById(val).value = text;
    if (document.getElementById(hide).value == "") 
        document.getElementById(hide).value = document.getElementById(val).value;
    document.getElementById(val).style.display = "";
    document.getElementById(sect).style.display = "";
    //var txt=document.getElementById(obj.id).innerHTML;
    var str1 = '<table border="0" cellpadding="5" cellspacing="0">';
    str1 += '	<tr>';
    str1 += '		<td>&nbsp;&nbsp;</td>';
    str1 += '		<td><img src="../../portal/system/v130/images/save.png" alt="Save" onClick=aj("' + obj.id + '","' + val + '","' + hide + '","' + sect + '");></td>';
    str1 += '		<td><img src="../../portal/system/v130/images/cancel.png" alt="Cancel" onclick=canl("' + obj.id + '","' + val + '","' + hide + '","' + sect + '");></td>';
    str1 += '		<td><a href="../../portal/system/v130/frames.dtx" target="_new"><img src="../../portal/system/v130/images/dt0.png" border="0"></a></td>';
    str1 += '	</tr>';
    str1 += '</table>';
    //<input type='Button' value='Save' class='button' onClick=aj('"+obj.id+"','"+val+"','"+hide+"');><input type='Button' value='Cancel'  class='button' onclick=canl('"+obj.id+"','"+val+"','"+hide+"');><a href='igatex.dtx' onClick=\"if_popUp('800', '250', 'center', 'middle', '', 'frames.dtx');\">
    //var str=txt.replace(txt," ");
    document.getElementById(obj.id).innerHTML = "";
    //alert(str1);
    document.getElementById(sect).innerHTML = str1;
}


function createRequestObject(){
    var ro;
    var browser = navigator.appName;
    if (browser == "Microsoft Internet Explorer") {
        ro = new ActiveXObject("Microsoft.XMLHTTP");
    }
    else {
        ro = new XMLHttpRequest();
    }
    return ro;
}


function aj(id, val, hide, sect){
    var source_id = document.getElementById("source_id").value;
    var content = document.getElementById(val).value;
    document.getElementById(sect).style.display = "none";
    var url = "../../portal/system/v130/task.dtx?type=" + id + "&id=" + source_id + "&content=" + content;
    var http = createRequestObject();
    http.open("GET", url, true);
    http.onreadystatechange = function(){
        if (http.readyState == 4) {
            document.getElementById(hide).value = content;
            document.getElementById(id).innerHTML = content;
            document.getElementById(val).style.display = "none";
            
        }
    }
    http.send(null);
}


function canl(id, val, hide, sect){
    document.getElementById(id).innerHTML = document.getElementById(hide).value;
    document.getElementById(val).style.display = "none";
    document.getElementById(sect).style.display = "none";
    return;
}


//--- Check forms in ipos ---
function formCheckIPO(){
    if(document.getElementById('formCheck')) {
    	var params = document.getElementById('formCheck').value;
        if(params != "") {
	        if (params.indexOf("&") != -1) {
	            var paramsArr = params.split('&');
	            for (var i = 0; i < paramsArr.length; i++) {
	                var s = paramsArr[i].split('=');
	                //alert(s[0]);
	                if (document.getElementById(s[0]).value == "") {
	                    alert("Bitte geben Sie eine/n " + s[1] + " ein!");
	                    document.getElementById(s[0]).focus();
	                    return false;
	                }
	            }
	        }
	        else {
	            var s = params.split('=');
	            if (document.getElementById(s[0]).value == "") {
	                alert("Bitte geben Sie eine/n " + s[1] + " ein!");
	                document.getElementById(s[0]).focus();
	                return false;
	            }
	        }
		}
        return true;
    }
    else {
    	return true;
    }
}



/**
 @desc: show human-readable information about variable
 @param: expr- variable - user variable
 */
function format_r(expr){
    var dim = 0;
    var padVal = '\xA0\xA0\xA0\xA0\xA0';
    
    switch (typeof expr) {
        case 'string':
        case 'number':
            retVal = expr;
            break;
        case 'object':
            retVal = 'Array\n{\n' + outputFormat(expr, dim) + '\n}';
            break;
        default:
            retVal = false;
    }
    
    function pad(dim){
        padding = '';
        for (i = 0; i < dim; i++) {
            padding += padVal;
        }
        return padding;
    }
    
    function outputFormat(expr, dim){
        var retVal = '';
        for (var key in expr) {
            if (typeof expr[key] == 'object' && expr[key].constructor == Array) {
                retVal += padVal + pad(dim) + '[' + key + '] => Array\n' +
                padVal +
                pad(dim) +
                '{\n' +
                outputFormat(expr[key], dim + 1) +
                padVal +
                pad(dim) +
                '}\n';
            }
            else 
                if (expr[key].constructor == Function) {
                    continue;
                }
                else {
                    retVal = retVal + padVal + pad(dim) + '[' + key + '] => ' + expr[key] + '\n';
                }
        }
        return retVal;
    }
    return retVal;
}




/**
 @desc: shows human-readable contents of variable in alert box
 @param: expr- variable - contents
 */
function alert_r(expr){
    alert(format_r(expr))
}


function getHTTPObject(){
    http_request = false;
    if (window.XMLHttpRequest) { // Mozilla, Safari,...
        http_request = new XMLHttpRequest();
        if (http_request.overrideMimeType) {
            // set type accordingly to anticipated content type
            //http_request.overrideMimeType('text/xml');
            http_request.overrideMimeType('text/html');
        }
    }
    else 
        if (window.ActiveXObject) { // IE
            try {
                http_request = new ActiveXObject("Msxml2.XMLHTTP");
            } 
            catch (e) {
                try {
                    http_request = new ActiveXObject("Microsoft.XMLHTTP");
                } 
                catch (e) {
                }
            }
        }
    if (!http_request) {
        alert('Cannot create XMLHTTP instance');
        return false;
    }
    return http_request;
}


function wAjax(url, func, idleId){
    if (idleId) 
        wWindows[idleId].disable();
    
    var http = getHTTPObject();
    var s = url.split('?');
    var u = s[0];
    var params = s[1];
    
    http.open('POST', u, true);
    http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    http.setRequestHeader("Content-length", params.length);
    http.setRequestHeader("Connection", "close");
    http.onreadystatechange = function(){
        if (http.readyState == 4) {
            if (idleId) 
                wWindows[idleId].enable();
            if (func) 
                func(http.responseText);
        }
    }
    http.send(params);
}


// public method for url decoding
function decodeUTF(utftext){
    var string = "";
    var i = 0;
    var c = c1 = c2 = 0;
    
    while (i < utftext.length) {
    
        c = utftext.charCodeAt(i);
        
        if (c < 128) {
            string += String.fromCharCode(c);
            i++;
        }
        else {
            if ((c > 191) && (c < 224)) {
                c2 = utftext.charCodeAt(i + 1);
                string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
                i += 2;
            }
            else {
                c2 = utftext.charCodeAt(i + 1);
                c3 = utftext.charCodeAt(i + 2);
                string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
                i += 3;
            }
        }
    }
    
    return string;
}


// public method for url encoding
function encodeUTF(string){
    string = string.replace(/\r\n/g, "\n");
    var utftext = "";
    
    for (var n = 0; n < string.length; n++) {
    
        var c = string.charCodeAt(n);
        
        if (c < 128) {
            utftext += String.fromCharCode(c);
        }
        else {
            if ((c > 127) && (c < 2048)) {
                utftext += String.fromCharCode((c >> 6) | 192);
                utftext += String.fromCharCode((c & 63) | 128);
            }
            else {
                utftext += String.fromCharCode((c >> 12) | 224);
                utftext += String.fromCharCode(((c >> 6) & 63) | 128);
                utftext += String.fromCharCode((c & 63) | 128);
            }
        }
    }
    
    return utftext;
}


//--- Set cursor  on first input-filed ---
function setCursor() {
	if (document.forms.length > 0) {
		var field = document.forms[0];
		for (i = 0; i < field.length; i++) {
			if ((field.elements[i].type == "text") || (field.elements[i].type == "textarea") || (field.elements[i].type.toString().charAt(0) == "s")) {
				document.forms[0].elements[i].focus();
				break;
			}
		}
	}
}


