
var imageMaxWidth = 740;
var imageMaxHeight = 600;

function iframeloggedout(url){
	document.location.href = url;
}

function changeLang(){
	// Dropdown in sidebar:
	document.formChangeLang.submit();
}

function refreshForm(url){
	var ele = document.bbform.elements;
	document.bbform.action = url+"?formrefresh=true#focusform";
	document.bbform.submit();
	for (var i = 0; i < ele.length ;i++){
		ele[i].disabled = true;
	}
}

function gotoUhr(uhrid, suchid, lang, seite){
	document.location.href = "/"+lang+"/sales/offers/detail.php?id="+uhrid+"&suche="+suchid+"&pageNum_qListe="+seite;
	return true; // !!! somit funkt klick auf user
}

function gotoArchivUhr(uhrid, suchid, lang){
	document.location.href = "/"+lang+"/archive/sold/detail.php?id="+uhrid+"&suche="+suchid;
	return true; // !!! somit funkt klick auf user
}

function gotoUhrInvestor(uhrid, suchid, lang){
	top.document.location.href = "/"+lang+"/sales/offers/detail.php?id="+uhrid+"&suche="+suchid;
	return true; // !!! somit funkt klick auf user
}

function showMediumImg(bild){
	document.images['imgMedium'].src = bild;
	return false;
}

function recommend(uhrid){
	window.open("recommend.php?id="+uhrid, "bigbwnd", "width=430,height=400,left=100,top=200,scrollbars=yes");
	return false;
}

function showBigImg(){
	medium = document.images['imgMedium'].src;
	bigb = medium.replace(/medium/, "");
	window.open(bigb, "bigbwnd", "width=620,height=620,left=100,top=200");
	return false;
}

function previewAngebot(lang){
	actionAlt = document.bbform.action;
	document.bbform.action = "/"+lang+"/sales/offers/preview.php";
	document.bbform.target = "_blank";
	document.bbform.submit();
	document.bbform.action = actionAlt;
	document.bbform.target= "_self";
}

function checkVonBisZustand(aktivElement){
	// Wenn bis-Zustand-Wert auf egal -> dann umändern
	var vonSelect = document.getElementById('zustand_von');
	var bisSelect = document.getElementById('zustand_bis');
	if(aktivElement == 'von'){
		if (bisSelect.selectedIndex < vonSelect.selectedIndex) {
			bisSelect.selectedIndex = vonSelect.selectedIndex;
		}
	} else {
		if (bisSelect.selectedIndex < vonSelect.selectedIndex) {
			vonSelect.selectedIndex = bisSelect.selectedIndex;
		}
	}
}

function resizeImages() {
	var meinDiv = document.getElementById('divSuperDetail');
	
	if(meinDiv){
	var bilder = meinDiv.getElementsByTagName('img');
	
	for (var i = 0; i < bilder.length ;i++){
			var imageWidth = bilder[i].width;
			var imageHeight = bilder[i].height;
			
			if ((imageMaxWidth != 0 && imageWidth > imageMaxWidth) || (imageMaxHeight != 0 && imageHeight > imageMaxHeight)) {
				if (imageMaxWidth != 0) var div1 = imageMaxWidth / imageWidth;
				else var div1 = 1;
				if (imageMaxHeight != 0) var div2 = imageMaxHeight / imageHeight;
				else var div2 = 1;
							
				if (div1 < div2) {
					bilder[i].width = imageMaxWidth;
					bilder[i].height = Math.round(imageHeight * div1);
				} else {
					bilder[i].height = imageMaxHeight;
					bilder[i].width = Math.round(imageWidth * div2);
				}
			
			}
	} // for
	} // if meindiv
	
}


//-------------------- TOOLTIP --------------------
var ttX = 0;
var ttY = 8;
var wmtt = null;
////////////document.onmousemove = updateWMTT;

function updateWMTT(e) {
	x = (document.all) ? window.event.x + document.body.scrollLeft : e.pageX;
	y = (document.all) ? window.event.y + document.body.scrollTop  : e.pageY;
	if (wmtt != null) {
		wmtt.style.left = (x + ttX) + "px";
		wmtt.style.top 	= (y + ttY) + "px";
	}
}

function showWMTT(id, msg) {
	wmtt = document.getElementById(id);
	wmtt.innerHTML = msg;
	wmtt.style.display = "block";
}

function hideWMTT() {
	wmtt.style.display = "none";
	wmtt.innerHTML = "...";
	wmtt = null;
}


function hiliteRow(obj, msg){
	obj.className='hover';
	if(msg != ""){
		showWMTT('divToolTip',msg);
	}
}

function blurRow(obj){
	obj.className='';
	if(wmtt){
		hideWMTT();
	}
}

function iFrameHeight(id) {
  //find the height of the internal page
  var the_height = document.getElementById(id).contentWindow.document.body.scrollHeight;

  //change the height of the iframe
  document.getElementById(id).height = the_height+20;
  //alert(the_height);
}

function expandPopup(hoehe){
	// dient dazu, ein möglichst breites Popup anzuzeigen:
	window.resizeTo(screen.availWidth - 140, hoehe);
	window.moveTo(10, 10); 
}



//-------------------- Fade In-/out --------------------

function opacity(id, opacStart, opacEnd, millisec) { 
    //speed for each frame 
    var speed = Math.round(millisec / 100); 
    var timer = 0; 

    //determine the direction for the blending, if start and end are the same nothing happens 
    if(opacStart > opacEnd) { 
        for(i = opacStart; i >= opacEnd; i--) { 
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed)); 
            timer++; 
        } 
    } else if(opacStart < opacEnd) { 
        for(i = opacStart; i <= opacEnd; i++) 
            { 
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed)); 
            timer++; 
        } 
		document.getElementById(id).style.display = "none";
		changeOpac(100, id);
    } 
} 

//change the opacity for different browsers 
function changeOpac(opacity, id) { 
    var object = document.getElementById(id).style; 
    object.opacity = (opacity / 100); 
    object.MozOpacity = (opacity / 100); 
    object.KhtmlOpacity = (opacity / 100); 
    object.filter = "alpha(opacity=" + opacity + ")"; 
} 

//-------------------- AJAX --------------------

function doAjaxRequest(url, objStatus){
		status_anzeige = objStatus;
		changeOpac(100, objStatus);
		myObj = document.getElementById(objStatus);
		myObj.innerHTML = 'speichern ...';
		myObj.style.display = "block";
		
		//alert(url);
        http_request = false;

        if (window.XMLHttpRequest) { // Mozilla, Safari,...
            http_request = new XMLHttpRequest();
            if (http_request.overrideMimeType) {
                //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('Ende :( Kann keine XMLHTTP-Instanz erzeugen');
            return false;
        }
        http_request.onreadystatechange = returnInhalt;
        http_request.open('GET', url, true);
        http_request.send(null);
}

function resetStatus(obj){
	myObj = document.getElementById(obj);
	myObj.innerHTML = "";
	opacity(obj, 100, 0, 500);
}

function returnInhalt() {
	if (http_request.readyState == 4) {
            if (http_request.status == 200) {
				myObj = document.getElementById(status_anzeige);
				myObj.innerHTML = http_request.responseText;
				//myObj.style.display = "block";
            } else {
                alert('Bei dem Request ist ein Problem aufgetreten.');
            }
     }
	window.setTimeout("resetStatus('"+status_anzeige+"')", 3200);
}


