// JavaScript Document

var browser = navigator.appName;
var lastId;

AjaxLoader = function()
{
	if (window.XMLHttpRequest) 
	{ 
		req = new XMLHttpRequest(); 
	} else if (window.ActiveXObject) 
	{ 
		req = new ActiveXObject("Microsoft.XMLHTTP"); 
	}
	if(!req) 
	{
		return false;
	}
	return req;
}

function ajaxRequest(pid)
{
	myLoader = AjaxLoader();
	myLoader.onreadystatechange = function()
	{
		if (myLoader.readyState == 4) 
		{
			if (myLoader.status == 200) 
			{
				if(myLoader.responseText)
				{
					var myObject = eval('(' + myLoader.responseText + ')');
					if(myObject.logged == 'off')
					{
						clearInterval(loginTimer);
						alert('Sie haben seit 15 Minuten keine aktion mehr ausgeführt' + "\n" +
								'und wurden deshalb automatisch ausgeloggt!');
						window.location.reload();
					}
					
					if(myObject.logged == 'on')
					{
						document.getElementById('valuationsCount').innerHTML = '(' + myObject.valuations + ')';
						document.getElementById('valuationsCount').style.backgroundColor = '#FFF867';
						document.getElementById('usersCount').innerHTML = '(' + myObject.users + ')';
						document.getElementById('usersCount').style.backgroundColor = '#FFF867';
						
						var backgroundTimer = window.setInterval(
								function()
								{
									clearInterval(backgroundTimer);
									document.getElementById('valuationsCount').style.backgroundColor = '';
									document.getElementById('usersCount').style.backgroundColor = '';
								}, 
								5000
							);
							
							
					}
					return true;
				}
			}
		}
	}
	
	myLoader.open("POST", "ajaxGetValuationsCount.php?pid=" + pid, true);
	myLoader.send(null);
}

function neuesfenster(fenster, url, breite, hoehe) 
{
	var res = url.match(/http/);
	if (!res && url != 'goSro.html' && url != 'popup.php') 
	{
		url = 'http://www.srpa.de/html/de/' + url;
	}

	LeftPosition = (screen.width) ? (screen.width-breite)/2 : 0;
	TopPosition = (screen.height) ? (screen.height-hoehe)/2 : 0;
	
	settings ='height='+hoehe+',width='+breite+',top='+TopPosition+',left='+LeftPosition+',menubar=no,toolbar=no,location=no,status=no,resizable=yes,scrollbars=yes';
	win = window.open(url,fenster,settings);
	if(win.window.focus) 
	{
		win.window.focus();
	}
}

function resizeMSIEdummy(id) 
{
	var dummy    = document.getElementById( "MSIEdummy");
	var crs_menu = document.getElementById(id+"_div");
	if( crs_menu.style.display == "block") 
	{
		dummy.style.left   = crs_menu.offsetLeft;
		dummy.style.height = crs_menu.offsetHeight;
		dummy.style.width  = crs_menu.offsetWidth;
	}
}

function hideCRSMenu(id) 
{
	//document.getElementById(id).className = "";
	//document.getElementById(id + "_divhidden").style.display="none";
	document.getElementById(id+"_div").style.display='none';
}

function showCRSMenuHidden(id) 
{
	//document.getElementById( id + "_divhidden").style.display = "block";
	resizeMSIEdummy(id);
}

function showHideCRSMenu(id) 
{
	if (document.getElementById(id + '_div').style.display == 'block')
	{
		document.getElementById(id + '_div').style.display = 'none';
	} else
	{
		document.getElementById(id + '_div').style.display = 'block'
	}

/*
	var dummy    = document.getElementById( "MSIEdummy");
	var crs_menu = document.getElementById(id+"_div");
	var ids      = "home|partner|ueberuns|impressum"; // dynamisch erstellen 
	var buffer   = ids.split( "|");

	for( var idx = 0; idx < buffer.length; idx++) 
	{
		if( id != buffer[idx]) 
		{
			hideCRSMenu( buffer[ idx]);
		}
	}
	if( crs_menu.style.display != "block") 
	{
		var crs_menubar    = document.getElementById(id);
		var crs_menubar_ = document.getElementById(id + "_");
		crs_menubar.className  = "crsmenubar_selected";
		crs_menu.style.left    = crs_menubar_li.offsetLeft + "px";
		crs_menu.style.display = "block";
		dummy.style.display    = "block";
		resizeMSIEdummy( id);
	} else 
	{
		hideCRSMenu(id);
		dummy.style.display = "none";
	}
	*/
}

function showCRSMenuCheck(id) 
{
	var ids      = "home|partner|ueberuns|impressum"; /* dynamisch erstellen */
	var buffer = ids.split( "|");

	for( var idx = 0; idx < buffer.length; idx++) 
	{
		if( id != buffer[idx]) 
		{
			if(document.getElementById(buffer[idx]).className == "crsmenubar_selected") 
			{
				showHideCRSMenu(id);
				break;
			}
		}
	}
}

function changeCSSClass(id,cssclass) 
{
	document.getElementById(id).className = cssclass;
}

function openURI(uri,titel) 
{
	var i_height = getInnerHeight()/2;
	var msgtop  = i_height.toFixed(0) - 240;
	var i_width  = getInnerWidth()/2;
	var msgleft  = i_width.toFixed(0) - 320;
	var param = (titel == "Message") ?
	"left=" + msgleft + ",top=" + msgtop + ",height=480,width=640,dependent=no,location=no,toolbar=no,menubar=no,resizable=yes,status=no,scrollbars=yes" :
	"left=0,top=0,height=600,width=800,dependent=no,location=yes,toolbar=yes,menubar=yes,resizable=yes,status=yes,scrollbars=yes";
	var targetwindow = window.open( uri, titel, param);
	targetwindow.focus();
}

function getInnerHeight() 
{
	var result = 0;
	if( browser.indexOf('Microso') >= 0) 
	{
		try 
		{
			result = parseInt( document.body.clientHeight);
		} catch( e) 
		{
			result = parseInt( document.documentElement.clientHeight);
		}
	} else 
	{
		result = window.innerHeight;
	}
	return result;
}

function getInnerWidth() 
{
	var result = 0;
	if( browser.indexOf('Microso') >= 0)
	{
		try {
		result = document.body.clientWidth;
		} catch(e) 
		{
			result = document.documentElement.clientWidth;
		}
	} else 
	{
		result = window.innerWidth;
	}
	return result;
}


function openFeedback(id)
{
	if(lastId)
	{
		document.getElementById(lastId).style.display="none";
	}
	
	if(id != lastId)
	{
		if(document.all && !window.opera) 
		{
			document.getElementById(id).style.display="block";
		}else
		{
			document.getElementById(id).style.display="table-row";
		}
	 	lastId = id;
	}else 
	{
		lastId = 0;
	}
}
