var confirmok = 0;

var BrowserDetect = {
	init: function () {
		this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
		this.version = this.searchVersion(navigator.userAgent)
			|| this.searchVersion(navigator.appVersion)
			|| "an unknown version";
		this.OS = this.searchString(this.dataOS) || "an unknown OS";
	},
	searchString: function (data) {
		for (var i=0;i<data.length;i++)	{
			var dataString = data[i].string;
			var dataProp = data[i].prop;
			this.versionSearchString = data[i].versionSearch || data[i].identity;
			if (dataString) {
				if (dataString.indexOf(data[i].subString) != -1)
					return data[i].identity;
			}
			else if (dataProp)
				return data[i].identity;
		}
	},
	searchVersion: function (dataString) {
		var index = dataString.indexOf(this.versionSearchString);
		if (index == -1) return;
		return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
	},
	dataBrowser: [
		{
			string: navigator.userAgent,
			subString: "Chrome",
			identity: "Chrome"
		},
		{ 	string: navigator.userAgent,
			subString: "OmniWeb",
			versionSearch: "OmniWeb/",
			identity: "OmniWeb"
		},
		{
			string: navigator.vendor,
			subString: "Apple",
			identity: "Safari",
			versionSearch: "Version"
		},
		{
			prop: window.opera,
			identity: "Opera"
		},
		{
			string: navigator.vendor,
			subString: "iCab",
			identity: "iCab"
		},
		{
			string: navigator.vendor,
			subString: "KDE",
			identity: "Konqueror"
		},
		{
			string: navigator.userAgent,
			subString: "Firefox",
			identity: "Firefox"
		},
		{
			string: navigator.vendor,
			subString: "Camino",
			identity: "Camino"
		},
		{		// for newer Netscapes (6+)
			string: navigator.userAgent,
			subString: "Netscape",
			identity: "Netscape"
		},
		{
			string: navigator.userAgent,
			subString: "MSIE",
			identity: "Explorer",
			versionSearch: "MSIE"
		},
		{
			string: navigator.userAgent,
			subString: "Gecko",
			identity: "Mozilla",
			versionSearch: "rv"
		},
		{ 		// for older Netscapes (4-)
			string: navigator.userAgent,
			subString: "Mozilla",
			identity: "Netscape",
			versionSearch: "Mozilla"
		}
	],
	dataOS : [
		{
			string: navigator.platform,
			subString: "Win",
			identity: "Windows"
		},
		{
			string: navigator.platform,
			subString: "Mac",
			identity: "Mac"
		},
		{
			   string: navigator.userAgent,
			   subString: "iPhone",
			   identity: "iPhone/iPod"
	    },
		{
			string: navigator.platform,
			subString: "Linux",
			identity: "Linux"
		}
	]

};
BrowserDetect.init();




function unloading(){
	if (confirmok != 1) { 
			return "WARNUNG: Sie haben Ihre Bewertungen und Kommentare noch nicht gespeichert! Die Änderungen gehen verloren, wenn Sie 'OK' klicken.";
	}
	
}

function goTopHead(goal)
{
	alert("test");
	top.location.href = goal;
}

function getFlashMovie(movieName) {
		var isIE = navigator.appName.indexOf("Microsoft") != -1;
		return (isIE) ? window[movieName] : document[movieName];
	}
function addCurve() {
	if (document.compCurve["companyCode"].value)
	{
		var id = document.compCurve["companyCode"].value
		getFlashMovie("curve").addCurve(id);
	}
}

function resetCruve(type) 
{
		var id = document.compCurve["companyId"].value
		getFlashMovie("curve").resetCruve(type);

}

function submitCompanySearch(type, value)
{
	if (type == 0)
	{
		var strRequest = "";
		var company ="";
		var city = "";
		var sectorId = document.companySearch["sectorId"].value;
		var cityId = document.companySearch["cityId"].value;
		company = encodeIndexWords(document.companySearch["company"].value);
		city = encodeIndexWords(document.companySearch["city"].value);
		
		
		if (sectorId) strRequest += "sectorId=" + sectorId + "&"; 
		if (city) strRequest += "city=" + city+ "&"; 
		if (company!="Firma") strRequest += "company=" + company;
		
		ajax_loadContent('searchResult','pages/findCompany.php?' + strRequest);
	}
	else if (type==1)
	{
		ajax_loadContent('searchResult','pages/findCompany.php?companyNameChar='+value);
	}
	else if (type==2)
	{
		ajax_loadContent('searchResult','pages/findCompany.php?feelingId='+value);
	}
}

function encodeIndexWords(word){
	var returnvalue = word.replace(/&/g,"_0026_");
	returnvalue = returnvalue.replace(/-/g,"_002d_");
	returnvalue = returnvalue.replace(/\+/g,"_002b_");
	returnvalue = returnvalue.replace(/:/g,"_003a_");
	returnvalue = returnvalue.replace(/\[/g,"_005b_");
	returnvalue = returnvalue.replace(/\]/g,"_005d_");
	returnvalue = returnvalue.replace(/\//g,"_002f_");
	returnvalue = returnvalue.replace(/@/g,"_0040_");
	returnvalue = returnvalue.replace(/#/g,"_0023_");
	returnvalue = returnvalue.replace(/\*/g,"_002a_");
	returnvalue = returnvalue.replace(/</g,"_003c_");
	returnvalue = returnvalue.replace(/>/g,"_003e_");
	returnvalue = returnvalue.replace(/\./g,"_002e_");
	returnvalue = returnvalue.replace(/'/g,"_0027_");
	returnvalue = returnvalue.replace(/`/g,"_0060_");
	return returnvalue;
}

function tab(tab)
{
	if (tab<3)
	{
		for (var i=1; i<3; i++)
		{
			if (tab!=i)
			{
			document.getElementById('block'+i).style.display = 'none';
			document.getElementById('tab'+i).style.borderBottom = '#cccccc 1px solid';
			document.getElementById('tab'+i).style.color = '#666';
			}
			else
			{
			document.getElementById('block'+i).style.display = 'block';
			document.getElementById('tab'+i).style.borderBottom = '#FFF 1px solid';
			document.getElementById('tab'+i).style.color = '#000';
			}
		}
			
	}
	else
	{
		for (var i=3; i<7; i++)
		{
			if (tab!=i)
			{
			document.getElementById('block'+i).style.display = 'none';
			document.getElementById('tab'+i).style.borderBottom = '#cccccc 1px solid';
			document.getElementById('tab'+i).style.color = '#666';
			}
			else
			{
			document.getElementById('block'+i).style.display = 'block';
			document.getElementById('tab'+i).style.borderBottom = '#FFF 1px solid';
			document.getElementById('tab'+i).style.color = '#000';
			}
		}
			
	}

}


function tabTopCompany(tab)
{
	for (var i=1; i<=2; i++)
	{
		if (tab!=i)
		{
		document.getElementById('blockTopCompany'+i).style.display = 'none';
		document.getElementById('tabTopCompany'+i).style.borderBottom = '#BBB 1px solid';
		document.getElementById('tabTopCompany'+i).style.color = '#666';
		}
		else
		{
		document.getElementById('blockTopCompany'+i).style.display = 'block';
		document.getElementById('tabTopCompany'+i).style.borderBottom = '#FFF 1px solid';
		document.getElementById('tabTopCompany'+i).style.color = '#000';
		}
	}
			

}



function selectFeeling(f1, f2)
{
		for (var i=0; i<document.formular[f1].length; i++) 
		{
			if(document.formular[f1][i].selected) document.formular[f2][i].selected = false;
		}
		

	
}

function showDetails(nb)
{
	for (var i=1; i<=4; i++) 
	{
		if (i == nb) {
			document.getElementById('details[' + i + ']').style.display = 'block';
			document.getElementById('tab_' + i).style.color = '#343434';
			document.getElementById('tab_' + i).style.borderBottom = '#FFF 1px solid';
			
		}
		else {
			document.getElementById('details[' + i + ']').style.display = 'none';
			document.getElementById('tab_' + i).style.color = '#CCCCCC';
			document.getElementById('tab_' + i).style.borderBottom = '#CCC 1px solid';
		}
	}
}

function pushdown(box1,box2,goal,goal2)
{

	document.formular[goal].value = "";
	var espace = "";
	var strOutput = "";
	counter = 0;
	var ob = document.formular[box1];
	document.formular[goal2].value = "";
	for (var i=0; i<ob.length;i++) {
		if (ob[i].selected) 
		{
			
			// textarea
			if (document.formular[goal].value!="") espace = ", "; else espace = "";
			document.formular[goal].value = document.formular[goal].value + espace + ob[i].label;
			strOutput = strOutput + "v["+counter+"]=" + ob[i].value + "&";
			
			// hidden Input
			if (document.formular[goal2].value != "") document.formular[goal2].value += ", ";
			document.formular[goal2].value += ob[i].value;
			
			counter++;
		}
		
		
	}

	if (box2 != "false") {
		var ob = document.formular[box2];

		for (var i = 0; i < ob.length; i++) {
			if (ob[i].selected) {
				if (document.formular[goal].value != "") 
					espace = ", ";
				else 
					espace = "";
				document.formular[goal].value = document.formular[goal].value + espace + ob[i].label;
				strOutput = strOutput + "v[" + counter + "]=" + ob[i].value + "&";
				
				// hidden Input
				if (document.formular[goal2].value != "") 
					document.formular[goal2].value += ", ";
				document.formular[goal2].value += ob[i].value;
				counter++;
			}
		}
	}
}

function pushup(goal,goal2)
{
	document.formular[goal].value = "";
	document.formular[goal2].value = "";
}


function setPoints(inputId, div2, pts,level1,level2)
{

    pts = pts-5; 
	document.formular[inputId].value=pts;
	evalId = document.formular[div2].value;
	var mainVal = 0;
	var nb = 0;
	//ajax_loadContent('evaluation_empty','pages/evaluationAddPoints.php?points='+pts+'&evaluationId='+evalId+'&init=1');
	


	if (level2 == 0)
	{
		for (var ii=1; ii<11; ii++)
		{
				var idname = "input[" + level1 + "][" + ii + "]";
				var idnamebckgrnd = "eval_flash[" + level1 + "][" + ii + "]";
			if (document.formular[idname])
			{
				document.formular[idname].value = "";
				changeBckgrnd(idnamebckgrnd, -1);
			}
		}
	} 
	else
	{
		for (var ii=1; ii<11; ii++)
		{
				var idname = "input[" + level1 + "][" + ii + "]";
				var idnamebckgrnd = "eval_flash[" + level1 + "][" + ii + "]";
			if (document.formular[idname])
			{
				if (document.formular[idname].value != "") {
					mainVal -= -document.formular[idname].value;
					nb++;
				}
			}
		}
		
		idname = "input[" + level1 + "][0]";
		var idnamebckgrnd = "eval_flash[" + level1 + "][0]";

		var evnameId = "evaluationId[" + level1 + "][0]";
		
		var val = Math.round(mainVal/nb*10)/10;
		
		
		document.formular[idname].value = val;
	
		var valShow = 0;
		
		valShow = val+5;
		changeBckgrnd(idnamebckgrnd,valShow);
		evalId = document.formular[evnameId].value;
		ajax_loadContent('evaluation_empty','pages/evaluationAddPoints.php?points='+val+'&evaluationId='+evalId+'&init=0');
		
		
	}
	

	
	
	//ajax_loadContent('evaluation_empty','pages/evaluationAddPoints.php?points='+pts+'&evaluationId='+evalId); 
	//ajax_loadContent('evaluation_empty','pages/evaluationAddComments.php?comments='+comment+'&evaluationId='+evalId); 
	
}

function resetBckgrnd(div, div2)
{
	pts = document.formular[div2].value
	
	if (pts) {
		pts = pts - (-5);
		var position = Math.round(-pts - 1) * 23;
	}
	else
	{
		var position = 0;
	}
	document.getElementById(div).style.backgroundPosition="0px "+ position +"px";

}

function changeBckgrnd(div, pts)
{
	document.getElementById(div).style.backgroundPosition="0px "+ (Math.round(-pts-1)*23)+"px";
	//alert(pts*10);
}

function submitPoints(pointsId, val)
{

}

function changeVisibiltyMain(div,div2)
{


	if (document.getElementById(div).style.display != 'block')
	{
		document.getElementById(div).style.display = 'block';
		document.getElementById(div2).style.backgroundPosition = 'bottom';
	}
	else
	{
		document.getElementById(div).style.display = 'none';
		document.getElementById(div2).style.backgroundPosition = 'top';
	}

}
function changeVisibilty(div,div2)
{

//alert(BrowserDetect.browser+" - "+BrowserDetect.version);
//if ((BrowserDetect.browser=="Explorer")&& (BrowserDetect.version>6)){

	if (document.getElementById(div).style.display != 'block')
	{
		document.getElementById(div).style.display = 'block';
		document.getElementById(div2).style.backgroundPosition = 'bottom';
	}
	else
	{
		document.getElementById(div).style.display = 'none';
		document.getElementById(div2).style.backgroundPosition = 'top';
	}
//}
}

function showhints()
{
	document.getElementById("hinweis_content").style.display = 'block';

}

function hidehints()
{
	if (document.getElementById("bodyLeft640").style.width == '945px')
	{
	document.getElementById("hinweis_content").style.display = 'none';
	}
}

function viewComment(div)
{
		document.getElementById("hinweis_content").style.display = 'none';
		document.getElementById(div).style.display = 'block';
		document.getElementById("evaluationMain").style.width = '945px';
		document.getElementById("bodyLeft640").style.width = '945px';
		document.getElementById("yourremark").style.display = 'block';

}
function hideComment(div)
{
		document.getElementById("hinweis_content").style.display = 'block';
		document.getElementById(div).style.display = 'none';
		document.getElementById("evaluationMain").style.width = '645px';
		document.getElementById("bodyLeft640").style.width = '645px';
		document.getElementById("yourremark").style.display = 'none';
}

function markAllBoxes( container_id, value ) {
		
	var elem = document.getElementById(container_id).getElementsByTagName("div");
	
	for ( var i = 0; i < elem.length; i++ ) {
        checkbox = elem[i].getElementsByTagName( 'input' )[0];

        if ( checkbox && checkbox.type == 'checkbox' ) {
            unique_id = checkbox.name + checkbox.value;
       /*     if ( checkbox.disabled == false ) {
                checkbox.checked = true;
            }
         */   
            if(value){
            	checkbox.checked = true;
            }else{
            	checkbox.checked = false;
            }

        }
    }

    return true;
}

function registerSubmit(){

	alert ("ok")
}

function updateWMTT(m)
{
	
	
	
	
	 x = (document.all) ? window.event.x + 160 + document.body.scrollLeft : m.pageX;
	 y = (document.all) ? window.event.y + 160 +  document.body.scrollTop  : m.pageY;
//		x = m.clientX + document.body.scrollLeft;
//		y = m.clientY + document.body.scrollTop;
	
	if (wmtt2 != null)
	 {
	   wmtt2.style.left = (x+10) + "px";
	   wmtt2.style.top 	= (y+10) + "px";
	 }
}

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

}

function showMoveWMTT(id,content)
{
 wmtt2 = document.getElementById(id);
 wmtt2.style.display = "block";
 wmtt2.innerHTML= content;

}

function hideWMTT()
{
	 if(wmtt != null){
		 wmtt.style.display = "none";
	 }
	 if(wmtt2 != null){
		 wmtt2.style.display = "none";
	 }
}


