var w = false;

function openIHCO2(theURL) { //v2.0
	var new_width	= 900;
	var new_height	= 605;
	if (navigator.appName.indexOf("Explorer") > -1)
	{
		new_width	= new_width+13;
		new_height	= new_height-4;
	}
	
	window.open(theURL,'editor','menubar=no,resizable=yes,scrollbars=yes,width='+new_width+',height='+new_height);
}

function openDates2009() {
	window.open('messetermine_2009.html', 'Fair_dates', 'menubar=no,scrollbars=yes,width=620,height=556');
}

function openDates2010() {
	window.open('messetermine_2010.html', 'Fair_dates', 'menubar=no,scrollbars=yes,width=620,height=556');
}

function checkForm() {
	required_fields = new Array('anzahl', 'name', 'vorname', 'firma', 'strasse', 'plz', 'ort', 'telefon');
	
	for(i=0; i<required_fields.length; i++)
	{
		if(isEmpty(document.forms['order'].elements[required_fields[i]].value))
		{
			alert(order_message);
			return false;
		}
	}
	
	return true;
}

function checkForm2()
{
	required_fields = new Array('sender_email', 'sender_name', 'recepient_email', 'recepient_name');
	
	for(i=0; i<required_fields.length; i++)
	{
		if(isEmpty(document.forms['sendpage'].elements[required_fields[i]].value))
		{
			alert(order_message);
			return false;
		}
	}
	
	document.sendpage.submit();
	
	return true;
}

function isEmpty(value) {
	
	value = trim(value);
	
	if ((value.length==0) || (value==null)) {
      return true;
   }
   
   return false;
}

function trim(value) {
	
	while (value.substring(0,1) == ' ') { //left trim
		value = value.substring(1, sString.length);
	}
	
	while (value.substring(value.length-1, value.length) == ' ') { //right trim
		value = value.substring(0,value.length-1);
	}
	
	return value;
}

function printPage(loc, lang) {
	window.open('../scripts/print.php?loc='+loc+'&lang='+lang, 'print', 'menubar=no,scrollbars=yes,width=620,height=556');
}

function sendPage(loc, lang) {
	
	if(w == false)
	{
		w = window.open('sendPage.html', 'send', 'menubar=no,scrollbars=yes,width=508,height=556,resizable=yes');
		w.loc = loc;
		w.lang = lang;
	}
	else if(w.closed)
	{
		w = null;
		w = window.open('sendPage.html', 'send', 'menubar=no,scrollbars=yes,width=508,height=556,resizable=yes');
		w.loc = loc;
		w.lang = lang;
	}
}

function feedback()
{
	window.open('feedback.html', 'send', 'menubar=no,scrollbars=yes,width=508,height=556,resizable=yes');
}

function displayLoading()
{
	document.getElementById('loading').style.visibility = 'visible';
}

function hideLoading()
{
	document.getElementById('loading').style.visibility = 'hidden';
}

function switch_img(from, to)
{
     document.getElementById(from).style.display = 'none';
     document.getElementById(to).style.display = 'block';
}

function maxWindow()
{
	window.moveTo(10,10);
	var old_width	= 900;
	var old_height	= 605;
	var ratio		= old_width/old_height;
	var max_size_r	= ((screen.availWidth/screen.availHeight) > ratio) ? ((screen.availHeight-100)/old_height) : ((screen.availWidth-100)/old_width);
	var new_width, new_height;
	
	if (navigator.appName.indexOf("Explorer") > -1)
	{
		if (navigator.appVersion.indexOf("MSIE 7.") > -1)
		{
			new_width	= old_width-878+old_width*max_size_r;
			new_height	= old_height-538+old_height*max_size_r;
		}
		else
		{
			new_width	= old_width-877+old_width*max_size_r;
			new_height	= old_height-550+old_height*max_size_r;
		}
		window.resizeTo(new_width, new_height);
	}
	else
	{
		new_width	= old_width*max_size_r;
		new_height	= old_height*max_size_r;
	
		self.innerWidth		= new_width;
		self.innerHeight	= new_height;

		//window.resizeTo(new_width,new_height);
	}
}
function minWindow()
{
	if (navigator.appName.indexOf("Explorer") > -1)
	{
		if (navigator.appVersion.indexOf("MSIE 7.") > -1)
		{
			window.resizeTo(900-878+900, 605-538+605);
		}
		else
		{
			window.resizeTo(900-877+900, 605-550+605);
		}
	}
	else
	{
		self.innerWidth		= 900;
		self.innerHeight	= 605;
	}
	window.moveTo(50,50);
}

function tellMe()
{
	//alert("hallo");
	//alert(window.innerHeight + " " + window.innerWidth);
	//alert(document.documentElement.clientHeight + " " + document.documentElement.clientWidth);
	
	var xx,yy;
	if (self.innerHeight) // all except Explorer
	{
		xx = self.innerWidth;
		yy = self.innerHeight;
	}
	else if (document.documentElement && document.documentElement.clientHeight)
		// Explorer 6 Strict Mode
	{
		xx = document.documentElement.clientWidth;
		yy = document.documentElement.clientHeight;
	}
	else if (document.body) // other Explorers
	{
		xx = document.body.clientWidth;
		yy = document.body.clientHeight;
	}
	else
	{
		alert("?");
	}
	alert(xx + " x " + yy);
}

function browserDetect() {
    var br = navigator.userAgent;
    if(br.indexOf('Opera') != -1 || br.indexOf('Safari') != -1) {
        document.getElementById('a_2008').style.display = 'none';
        document.getElementById('a_2007').style.display = 'none';
        document.getElementById('err_msg').style.display = 'block';
    }
}