// url: page that returns xml construct
// ID : id to swap content
var ID2Change;
var prev_character = "";
function getContentFromServer(url, ID, help_special_ajax) {
    ID2Change = ID;
    http_request = false;

    if (window.XMLHttpRequest) { // Mozilla, Safari,...
        http_request = new XMLHttpRequest();
        if (http_request.overrideMimeType) {
            http_request.overrideMimeType('text/xml');
        }
    } else if (window.ActiveXObject) { // IE
        try {
            http_request = new ActiveXObject("MSXML2.XMLHTTP.3.0");
        } catch (e) {
            try {
                http_request = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e) {}
        }
    }

    if (!http_request) {
        //alert('Giving up :( Cannot create an XMLHTTP instance');
        return false;
    }

    if (help_special_ajax != null) {
    	http_request.onreadystatechange = getContents4PageHelp;
    } else {
    	http_request.onreadystatechange = getContents4Page;
    }
	

    http_request.open('POST', url, true);
    http_request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    var postText = 'ID2change=' + ID2Change + '&';
    var postTextValue = '';
    for (var i = 0; i < document.forms[0].elements.length; ++i) {
        if (document.forms[0].elements[i].type == "checkbox" || document.forms[0].elements[i].type == 'radio' ) {
            if (document.forms[0].elements[i].checked) {
                postText = postText + '&' + document.forms[0].elements[i].name +'='+document.forms[0].elements[i].value;
            }
        } else if(document.forms[0].elements[i].value != null) {
        	postTextValue = document.forms[0].elements[i].value;
        	postTextValue = postTextValue.replace(/#/g,'_#_');
        	postTextValue = postTextValue.replace(/&/g,'##');
            postText = postText + '&'  + document.forms[0].elements[i].name +'='+postTextValue;
        }
    }

    http_request.send(postText);
}

/*
var g_base64_table = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';


	function base64_decode(encStr)
	{
	    var bits;
	    var decOut = '';
	    var i = 0;


	    for(; i < encStr.length; i += 4)
	    {
	        bits = (g_base64_table.indexOf(encStr.charAt(i))     & 0xFF) << 18 |
	        (g_base64_table.indexOf(encStr.charAt(i + 1)) & 0xFF) << 12 |
	        (g_base64_table.indexOf(encStr.charAt(i + 2)) & 0xFF) <<  6 |
	        (g_base64_table.indexOf(encStr.charAt(i + 3)) & 0xFF);

	        decOut += String.fromCharCode((bits & 0xFF0000) >> 16, (bits & 0xFF00) >> 8, bits & 0xFF);
	    }

	    if(encStr.charCodeAt(i - 2) == 61)
	      return(decOut.substring(0, decOut.length - 2));
	    else if(encStr.charCodeAt(i - 1) == 61)
	      return(decOut.substring(0, decOut.length - 1));
	    else
	      return(decOut);
	}
*/

var Base64 = {
    // private property
    _keyStr : "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",

    // public method for encoding
    encode : function (input) {
        var output = "";
        var chr1, chr2, chr3, enc1, enc2, enc3, enc4;
        var i = 0;

        input = Base64._utf8_encode(input);

        while (i < input.length) {

            chr1 = input.charCodeAt(i++);
            chr2 = input.charCodeAt(i++);
            chr3 = input.charCodeAt(i++);

            enc1 = chr1 >> 2;
            enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
            enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
            enc4 = chr3 & 63;

            if (isNaN(chr2)) {
                enc3 = enc4 = 64;
            } else if (isNaN(chr3)) {
                enc4 = 64;
            }

            output = output +
            this._keyStr.charAt(enc1) + this._keyStr.charAt(enc2) +
            this._keyStr.charAt(enc3) + this._keyStr.charAt(enc4);

        }

        return output;
    },

    // public method for decoding
    decode : function (input) {
        var output = "";
        var chr1, chr2, chr3;
        var enc1, enc2, enc3, enc4;
        var i = 0;

        input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");

        while (i < input.length) {

            enc1 = this._keyStr.indexOf(input.charAt(i++));
            enc2 = this._keyStr.indexOf(input.charAt(i++));
            enc3 = this._keyStr.indexOf(input.charAt(i++));
            enc4 = this._keyStr.indexOf(input.charAt(i++));

            chr1 = (enc1 << 2) | (enc2 >> 4);
            chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
            chr3 = ((enc3 & 3) << 6) | enc4;

            output = output + String.fromCharCode(chr1);

            if (enc3 != 64) {
                output = output + String.fromCharCode(chr2);
            }
            if (enc4 != 64) {
                output = output + String.fromCharCode(chr3);
            }

        }

        output = Base64._utf8_decode(output);

        return output;

    },

    // private method for UTF-8 encoding
    _utf8_encode : function (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;
    },

    // private method for UTF-8 decoding
    _utf8_decode : function (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;
    }
}

function base64_encode(txt) {
	return Base64.encode(txt);
}

function base64_decode(txt) {
	return Base64.decode(txt);
}


function checkAll(nameElemente) {
   for (var i = 0; i < document.forms[0].elements.length; i++) {
	   if( document.forms[0].elements[i].name.indexOf(nameElemente) == 0 ) {
		   document.forms[0].elements[i].checked = true;
	   }
   }
}

function nmbOfCheckedItems(nameElemente) {
   var nmb = 0;
   for (var i = 0; i < document.forms[0].elements.length; i++) {
	   if( document.forms[0].elements[i].name.indexOf(nameElemente) == 0 ) {
		   if(document.forms[0].elements[i].checked == true){
		   	nmb++;
		   }
	   }
   }
   return nmb;
}

function inverse(nameElemente) {
   for (var i = 0; i < document.forms[0].elements.length; i++) {
	   if( document.forms[0].elements[i].name.indexOf(nameElemente) == 0 ) {
		   document.forms[0].elements[i].checked = !(document.forms[0].elements[i].checked);
	   }
   }
}
function unCheckAll(nameElemente) {
   checkAll(nameElemente);
   inverse(nameElemente);
}

function checkUncheckInvert()
{
	if (document.getElementById('checkboxSelects').value == 'all') {
		checkAll('checkedItem');
	} else if(document.getElementById('checkboxSelects').value == 'none') {
		unCheckAll('checkedItem');
	} else if(document.getElementById('checkboxSelects').value == 'inverse') {
		inverse('checkedItem');
	}
	try {
		document.getElementById('checkboxSelects').selectedIndex=0;
	}
	catch(e){}
}

function checkUncheckInvertElements(selectionListElementId, checkboxElementId)
{
	if (document.getElementById(selectionListElementId).value == 'all') {
		checkAll(checkboxElementId);
	} else if(document.getElementById(selectionListElementId).value == 'none') {
		unCheckAll(checkboxElementId);
	} else if(document.getElementById(selectionListElementId).value == 'inverse') {
		inverse(checkboxElementId);
	}
}

function changeCssCheckbox(checkboxName) {
	if(document.getElementById(checkboxName).value == '1') {
		document.getElementById("icon_"+checkboxName).className = 'chbxIcon0';
		document.getElementById(checkboxName).value = '0';
	} else {
		document.getElementById("icon_"+checkboxName).className = 'chbxIcon1';
		document.getElementById(checkboxName).value = '1'
	}
}

function go2url(url) {
	document.forms[0].target="_self";
	document.forms[0].action=url;
	document.forms[0].submit();
}

function speichern() {
	document.forms[0].target="_self";
	document.forms[0].saveData.value="1";
	document.forms[0].action=document.URL;
	document.forms[0].submit();
}

function getInfo() {
	document.forms[0].target="_self";
	document.forms[0].action=document.URL;
	document.forms[0].submit();
}

function showPage(pagename, url) {
	document.forms[0].target=pagename;
	document.forms[0].action=url;
	document.forms[0].submit();
}

function change_lang(lang) {
	document.forms[0].target="_self";
	document.forms[0].action=document.URL;
	document.forms[0].plangcode.value=lang;
	document.forms[0].submit();
}

function change_lang4photographer(lang, url2go) {
	document.forms[0].target="_self";
	document.forms[0].action=url2go;
	document.forms[0].plangcode.value=lang;
	document.forms[0].submit();
}

function startSearch() {
	document.forms[0].target="_self";
	document.forms[0].page.value=0;
	document.forms[0].action="./result.php";
	document.forms[0].submit();

}
function checkEnter4Searchkey(e) {
	var characterCode;
	if (!e) var e = window.event;
	if (e.keyCode) characterCode = e.keyCode;
	else if (e.which) characterCode = e.which;
	//alert(characterCode+' '+prev_character);
	if(characterCode == 13 && prev_character!=40 && prev_character!=38) {
		startSearch();
		return false;
	} else {
		prev_character = characterCode;
		return true;
	}

}
function checkEnter4Startsearch(e) {
	var characterCode;
	if (!e) var e = window.event;
	if (e.keyCode) characterCode = e.keyCode;
	else if (e.which) characterCode = e.which;
	//alert(characterCode+' '+prev_character);
	if(characterCode == 13 && prev_character!=40 && prev_character!=38) {
		view(0);
		return false;
	} else {
		prev_character = characterCode;
		return true;
	}

}

function checkEnter4Key(e) {
    var characterCode;
	 if(e && e.which){
		 e = e
		 characterCode = e.which
	 } else {
		 e = event
		 characterCode = e.keyCode
	 }

	 if(characterCode == 13) {
		return false;
	 } else {
		return true;
	 }
}
function checkEnter4Email(e) {
    var characterCode;
	 if(e && e.which){
		 e = e
		 characterCode = e.which
	 } else {
		 e = event
		 characterCode = e.keyCode
	 }

	 if(characterCode == 13) {
		return false;
	 } else {
		return true;
	 }

}
function checkEnter4Password(e) {
    var characterCode;
	 if(e && e.which){
		 e = e
		 characterCode = e.which
	 } else {
		 e = event
		 characterCode = e.keyCode
	 }

	 if(characterCode == 13) {
	     doLogin();
		return false;
	 } else {
		return true;
	 }
}

function changeCheckedStatus(itemToChange) {
	if (document.getElementById(itemToChange).checked == 1) {
		document.getElementById(itemToChange).checked = 0;
	} else {
	   	document.getElementById(itemToChange).checked = 1;
	}
}

function showHideObj(whichObject) {
	/*
	if (document.getElementById(whichObject).style.display == "block") {
		document.getElementById(whichObject).style.display = 'none';
	} else {
		document.getElementById(whichObject).style.display = 'block';
	}
	*/
	try {
		Effect.toggle(whichObject, 'blind', { duration: 0.8, transition: Effect.Transitions.sinoidal });
	} catch(e) {
		if (document.getElementById(whichObject).style.display == "block") {
			document.getElementById(whichObject).style.display = 'none';
		} else {
			document.getElementById(whichObject).style.display = 'block';
		}
	}
}

function showObj(whichObject) {
	document.getElementById(whichObject).style.display = 'block';
}

function hideObj(whichObject) {
	document.getElementById(whichObject).style.display = 'none';
}

function displayRegistrationWindow() {
	if (typeof Applicationfenster == 'undefined' || Applicationfenster.closed == true) {
		Applicationfenster = window.open('/registration.php','Application','scrollbars=yes,menubar=no,toolbar=no,status=yes,directories=no,location=no,width=900,height=520,top=200,left=200,resizable=yes');
		Applicationfenster.window.focus();
	 } else {
	 	Applicationfenster.window.focus();
	 }
	 if (parseInt(navigator.appVersion) >= 4) { Applicationfenster.window.focus(); }
}

function openLoginWindow() {
	if (typeof LoginWindow == 'undefined' || LoginWindow.closed == true) {
		LoginWindow = window.open('/login.php','Application','scrollbars=yes,menubar=no,toolbar=no,status=yes,directories=no,location=no,width=400,height=250,top=50,left=50,resizable=yes');
		LoginWindow.window.focus();
	 } else {
	 	LoginWindow.window.focus();
	 }
	 if (parseInt(navigator.appVersion) >= 4) { LoginWindow.window.focus(); }
}

function doLogin() {
    getContentFromServer4Login("/ajax/a_login.php", "loginW");
}


function openPixFinder() {
	if (typeof PixFinderWindow == 'undefined' || PixFinderWindow.closed == true) {
		PixFinderWindow = window.open('/pixfinder.php','Application','scrollbars=yes,menubar=no,toolbar=no,status=yes,directories=no,location=no,width=450,height=550,top=50,left=50,resizable=yes');
		PixFinderWindow.window.focus();
	 } else {
	 	PixFinderWindow.window.focus();
	 }
	 if (parseInt(navigator.appVersion) >= 4) { PixFinderWindow.window.focus(); }
}

function openFeedbackTool() {
	if (typeof FeedbackWindow == 'undefined' || FeedbackWindow.closed == true) {
		PixFinderWindow = window.open('/feedback.php','Application','scrollbars=yes,menubar=no,toolbar=no,status=yes,directories=no,location=no,width=450,height=480,top=50,left=50,resizable=yes');
		PixFinderWindow.window.focus();
	 } else {
	 	PixFinderWindow.window.focus();
	 }
	 if (parseInt(navigator.appVersion) >= 4) { PixFinderWindow.window.focus(); }
}

function validate_email(field) {
	with (field) {
		apos=value.indexOf("@")
		dotpos=value.lastIndexOf(".")
		if (apos<1||dotpos-apos<2) {
			return false
		} else {
			return true
		}
	}
}

function wpreview(pic_id) {
	     var width = 770;
	     var height = 650;
	     var winl = (screen.width - width) / 2;
	     var wint = (screen.height - height) / 2;
	     if (typeof fenster == 'undefined' || fenster.closed == true) {
		     fenster = window.open('detail.php?pic_id='+pic_id,'Sodapix | Bildagentur','scrollbars=yes,menubar=no,toolbar=no,status=yes,directories=no,location=no,width='+width+',height='+height+',top='+wint+',left='+winl+',resizable=yes');
		 } else {
		     fenster.close();
		     fenster = window.open('detail.php?pic_id='+pic_id,'Sodapix | Bildagentur','scrollbars=yes,menubar=no,toolbar=no,status=yes,directories=no,location=no,width=770,height=650,top='+wint+',left='+winl+',resizable=yes');
	    }
	    if (parseInt(navigator.appVersion) >= 4) { fenster.window.focus(); }
	 }

function wpreviewSingleOld(pic_id) {
	     var width = 770;
	     var height = 650;
	     var winl = (screen.width - width) / 2;
	     var wint = (screen.height - height) / 2;
	     if (typeof fenster == 'undefined' || fenster.closed == true) {
		     fenster = window.open('detail_base.php?pic_id='+pic_id,'Sodapix | Bildagentur','scrollbars=yes,menubar=no,toolbar=no,status=yes,directories=no,location=no,width='+width+',height='+height+',top='+wint+',left='+winl+',resizable=yes');
		 } else {
		     fenster.close();
		     fenster = window.open('detail_base.php?pic_id='+pic_id,'Sodapix | Bildagentur','scrollbars=yes,menubar=no,toolbar=no,status=yes,directories=no,location=no,width=770,height=650,top='+wint+',left='+winl+',resizable=yes');
	    }
	    if (parseInt(navigator.appVersion) >= 4) { fenster.window.focus(); }
	 }

function wpreviewSingle(url) {
	    var width = 770;
	    var height = 650;
	    var winl = (screen.width - width) / 2;
	    var wint = (screen.height - height) / 2;
	    var target_url = url;

	    if (typeof fenster == 'undefined' || fenster.closed == true) {
	        fenster = window.open(target_url,'Sodapix','scrollbars=yes,menubar=no,toolbar=no,status=yes,directories=no,location=no,width='+width+',height='+height+',top='+wint+',left='+winl+',resizable=yes');
	    } else {
	        fenster.focus();
	        fenster = window.open(target_url,'Sodapix','scrollbars=yes,menubar=no,toolbar=no,status=yes,directories=no,location=no,width='+width+',height='+height+',resizable=yes');
	    }
	    if (parseInt(navigator.appVersion) >= 4) { fenster.window.focus(); }
	}

function showDemoCalculator() {
		 var width = 770;
	     var height = 650;
	     var winl = (screen.width - width) / 2;
	     var wint = (screen.height - height) / 2;
	     if (typeof fenster == 'undefined' || fenster.closed == true) {
		     fenster = window.open('rm_calculator.php','Sodapix | Bildagentur','scrollbars=yes,menubar=no,toolbar=no,status=yes,directories=no,location=no,width='+width+',height='+height+',top='+wint+',left='+winl+',resizable=yes');
		 } else {
		     fenster.close();
		     fenster = window.open('rm_calculator','Sodapix | Bildagentur','scrollbars=yes,menubar=no,toolbar=no,status=yes,directories=no,location=no,width=770,height=650,top='+wint+',left='+winl+',resizable=yes');
	    }
	    if (parseInt(navigator.appVersion) >= 4) { fenster.window.focus(); }
	}

function openRMcalculator(url) {
	    var width = 770;
	    var height = 650;
	    var winl = (screen.width - width) / 2;
	    var wint = (screen.height - height) / 2;
	    var target_url = url;

	    if (typeof fenster == 'undefined' || fenster.closed == true) {
	        fenster = window.open(target_url,'Sodapix','scrollbars=yes,menubar=no,toolbar=no,status=yes,directories=no,location=no,width='+width+',height='+height+',top='+wint+',left='+winl+',resizable=yes');
	    } else {
	        fenster.focus();
	        fenster = window.open(target_url,'Sodapix','scrollbars=yes,menubar=no,toolbar=no,status=yes,directories=no,location=no,width='+width+',height='+height+',resizable=yes');
	    }
	    if (parseInt(navigator.appVersion) >= 4) { fenster.window.focus(); }
	}

function openRMcalculatorOld(pic_id, article_id) {
	var width = 770;
	     var height = 500;
	     var winl = (screen.width - width) / 2;
	     var wint = (screen.height - height) / 2;
	     if (typeof fenster == 'undefined' || fenster.closed == true) {
		     fenster = window.open('rm_calculator.php?pic_id='+pic_id+'&article_id='+article_id,'Sodapix | Bildagentur','scrollbars=yes,menubar=no,toolbar=no,status=yes,directories=no,location=no,width='+width+',height='+height+',top='+wint+',left='+winl+',resizable=yes');
		 } else {
		     fenster.close();
		     fenster = window.open('rm_calculator.php?pic_id='+pic_id+'&article_id='+article_id,'Sodapix | Bildagentur','scrollbars=yes,menubar=no,toolbar=no,status=yes,directories=no,location=no,width=770,height=650,top='+wint+',left='+winl+',resizable=yes');
	    }
	    if (parseInt(navigator.appVersion) >= 4) { fenster.window.focus(); }
	}
function getContentFromServer4Login(url, ID) {
    ID2Change = ID;
    http_request = false;

    if (window.XMLHttpRequest) { // Mozilla, Safari,...
        http_request = new XMLHttpRequest();
        if (http_request.overrideMimeType) {
            http_request.overrideMimeType('text/xml');
        }
    } else if (window.ActiveXObject) { // IE
        try {
            http_request = new ActiveXObject("MSXML2.XMLHTTP.3.0");
        } catch (e) {
            try {
                http_request = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e) {}
        }
    }

    if (!http_request) {
        //alert('Giving up :( Cannot create an XMLHTTP instance');
        return false;
    }


	http_request.onreadystatechange = getContents4Page4Login;


    http_request.open('POST', url, true);
    http_request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    var postText = 'ID2change=' + ID2Change + '&';
    for (var i = 0; i < document.forms[0].elements.length; ++i) {
        if (document.forms[0].elements[i].type == "checkbox" || document.forms[0].elements[i].type == 'radio' ) {
            if (document.forms[0].elements[i].checked) {
                postText = postText + '&' + document.forms[0].elements[i].name +'='+document.forms[0].elements[i].value;
            }
        } else {
            postText = postText + '&'  + document.forms[0].elements[i].name +'='+document.forms[0].elements[i].value;
        }
    }

    http_request.send(postText);
}

function getContents4Page4Login() {

		if (http_request.readyState == 4) {
            if (http_request.status == 200) {
                var xmldoc = http_request.responseXML;
                var nodes = xmldoc.getElementsByTagName("root").item(0);
                switch (ID2Change) {
                    case 'loginW':
                        var error_msg = base64_decode(nodes.getElementsByTagName("error_msg")[0].firstChild.data);
                        if (error_msg == 'none') {
                            var userLoginInfoContent = base64_decode(nodes.getElementsByTagName("userLoginInfo")[0].firstChild.data);
                            //document.getElementById("userLoginInfo").innerHTML = userLoginInfoContent;
                            var loginWContent = base64_decode(nodes.getElementsByTagName("loginWInfo")[0].firstChild.data);
                            document.getElementById("login_logout").innerHTML = loginWContent;
                            document.getElementById('loginW').style.display = 'none';
                            document.getElementById('customerNavigation').style.display = 'block';
                            document.getElementById("error_msg").innerHTML = '&nbsp;';
                        } else {
                            document.getElementById("error_msg").innerHTML = error_msg;
                            document.forms[0].login_passwort.value = "";
                        }
                        break;
                }
            } else {
            	alert('Es ist ein Verbindungsproblem aufgetreten ('+http_request.status+'). Bitte versuchen Sie es erneut....');
            }
		}
}

function veil() {
	$('veil').style.display='block';
}

function veil_close(id) {
	if(!id) {
		$('veil').fade({duration: 0.6});
	} else {
		new Effect.Parallel(
		[
		new Effect.Fade('dialog_'+id, {sync: true}),
		new Effect.Fade('veil', {sync: true})
		], {duration: 0.6});
	}
}

function center(eleid) {
	object = $(eleid);
	ml = parseInt((document.viewport.getWidth() - object.getWidth()) / 2) + 'px';
	mt = parseInt((document.viewport.getHeight() - object.getHeight()) / 2) + 'px';
	
	
	if( mt > document.viewport.getWidth()-object.getWidth() ) {
		mt	= document.viewport.getWidth()-object.getWidth();
	}
	if( mt < 0 ) {
		mt	= 0;
	}
	
	if( ml > document.viewport.getHeight()-object.getHeight() ) {
		ml	= document.viewport.getHeight()-object.getHeight();
	}
	if( ml < 0 ) {
		ml	= 0;
	}
	
	object.setStyle({
	  'top': mt,
	  'left': ml
	});
}

function showDraggableWindow(id,veilblock,nocenter) {
	var object = $('dialog_'+id);
	if( object.getHeight() > document.viewport.getHeight() ) {
		object.style.height	= (document.viewport.getHeight() - 10) + "px";
		object.getElementsBySelector('.shadowcontent')[0].style.height	= (document.viewport.getHeight() - 10) + "px";
		$('dialogcontent_'+ id).style.height	= (document.viewport.getHeight() - 10 - 40) + "px";
	}
	
	if( object.getWidth() > document.viewport.getWidth() ) {
		object.style.width	= (document.viewport.getWidth() - 10) + "px";
		object.getElementsBySelector('.shadowcontent')[0].style.width	= (document.viewport.getWidth() - 10) + "px";
		$('dialogcontent_'+ id).style.width	= (document.viewport.getWidth() - 10 - 20) + "px";
	}
	
	if(!veilblock) veil();
	$('dialog_'+id).appear({duration: 0.3});
	new Draggable('dialog_'+id,{scroll:window,handle:'dialogmenu_'+id,starteffect:null, endeffect:null});
	//$('dialog_'+id).style.top = (((document.viewport.getHeight()/2)+document.viewport.getScrollOffsets().top))-parseInt($('dialog_'+id).style.height)/4+'px';
	if (!nocenter) center('dialog_'+id);
}
