/*
	miscellaneous scripts. to change images, hide/show html elements etc.
*/

var satelliteActualView="push";
var maxYear;
var imgPath="assets/images/";
var parent;//the parent window wich is supossosed to be reloaded after the session is updated

//add the HTTP:// prefix, when the radio URL is selected
function addHttp(){
	var address=document.getElementById("address").value;
	if (address.substring(0, 7) != "http://") {		
		document.getElementById("address").value = "http://" + address;
	}
	
	document.getElementById("rowaddress").style.display="";
	
	document.getElementById("address").style.backgroundColor="#FFFFFF";
	document.getElementById("address").focus();
	setNocheckAddres(false);
}

//remove the HTTP:// prefix, when the radio URL is NOT selected
function clearHttp(){
	document.getElementById("rowaddress").style.height="0px"
	document.getElementById("addresserror").innerHTML="";
	
	document.getElementById("rowaddress").style.display="none";

	
	var address=document.getElementById("address").value;
	if(address.substring(0,7)=="http://"){
		document.getElementById("address").value="";
	}
	setNocheckAddres(true);
}

//show or hide the extended field of the main input form
function toogleExtendedField(id,language){
	var extendedDiv=document.getElementById(id);
	var extendedDivStyle=extendedDiv.style.display;
	if(extendedDivStyle=='none'){
		extendedDiv.style.display='block';
		switch(language){
			case "eng":
				document.getElementById("hidandshowlink").innerHTML="Just the required information";
			break;
			case "ger":
				document.getElementById("hidandshowlink").innerHTML="Nur Basis-Infos eintragen";
			break;
		}
	}else{
		extendedDiv.style.display='none';
		switch(language){
			case "eng":
				document.getElementById("hidandshowlink").innerHTML="Got more information?";
			break;
			case "ger":
				document.getElementById("hidandshowlink").innerHTML="Haben Sie mehr Infos?";
			break;
		}
	}
}

//set the max year to be showed in the "Bis/to" field
function setmaxYear(year){
	maxYear=year;
}

//by reloading of the main input form this field MUST be cleaned
function getThePageready(){
	document.getElementById("categoriesIds").value="";
}

//close the suggestions divs, and show the country select
function closeSuggestions(){
	if(document.getElementById('search_suggest')){
		document.getElementById('search_suggest').innerHTML = '';		
		document.getElementById('search_suggest').style.display = 'none';		
	}
	if(document.getElementById('search_suggest_cities')){
		document.getElementById('search_suggest_cities').innerHTML = '';	
		document.getElementById('search_suggest_cities').style.display = 'none';		
	}
	document.getElementById('country').style.display="block";
}

/*
	update the contens of the select "until" acording to the new selection of the
	select from
*/
function actionFrom(){
	select=document.getElementById("from");
	if(select.options[select.selectedIndex].value!="-1"){//activate the other select field
		document.getElementById("until").style.display="inline";
		document.getElementById("untilword").style.display="inline";
		document.getElementById("until").options.length=0;//clear the select Box
		//re populate the select
		document.getElementById("until").options[0]=new Option("Until", "-1", false, true);
		document.getElementById("until").options[1]=new Option(unescape("still active"), "0", false, false);
		var selectIndex=2;
		for(i=select.options[select.selectedIndex].value;i<=maxYear;i++){
			document.getElementById("until").options[selectIndex]=new Option(i,i, false, false);		
			selectIndex++;
		}
	}
}

/*
	update the contens of the select "until" acording to the new selection of the
	select from
*/

function actionFromEng(){
	select=document.getElementById("from");
	if(select.options[select.selectedIndex].value!="-1"){//activate the other select field
		document.getElementById("until").options.length=0;//clear the select Box
		//re populate the select
		document.getElementById("until").options[0]=new Option(unescape("Any"), "-1", false, true);
		document.getElementById("until").options[1]=new Option("Present", "0", false, false);
		var selectIndex=2;
		for(i=select.options[select.selectedIndex].value;i<=maxYear;i++){
			document.getElementById("until").options[selectIndex]=new Option(i,i, false, false);		
			selectIndex++;
		}
	}
}

//cliar the city textfield
function clearCityInput(){
	document.getElementById("city").value="";
}

function submitForm(formname){
	document.getElementById(formname).submit();
}

//shows/hides the extended fields of an especific search result 
function toogleExtendedSearchView(id){
	if(document.getElementById("server"+id).style.display=="none"){
		document.getElementById("server"+id).style.display="";
		document.getElementById("company"+id).style.display="";
		document.getElementById("imgBig"+id).style.display="";
		document.getElementById("imgSmall"+id).style.display="none";
		document.getElementById("icon"+id).src=imgPath+"less.gif";
		
	}else{
		document.getElementById("server"+id).style.display="none";
		document.getElementById("company"+id).style.display="none";
		document.getElementById("imgBig"+id).style.display="none";
		document.getElementById("imgSmall"+id).style.display="";
		document.getElementById("icon"+id).src=imgPath+"more.gif";
		
	}
}

//hides the extended fields of all the search results
function collapseResults(idArray){
	if(idArray.substring(idArray.length-1,idArray.length)==","){//remove a possible comma at the end
		idArray=idArray.slice(0,idArray.length-1);
	}
	var ids=idArray.split(',');
	for(i=0;i<ids.length;i++){
		if(document.getElementById("server"+ids[i]))
			document.getElementById("server"+ids[i]).style.display="none";
		if(document.getElementById("company"+ids[i]))
			document.getElementById("company"+ids[i]).style.display="none";
		if(document.getElementById("imgBig"+ids[i]))
			document.getElementById("imgBig"+ids[i]).style.display="none";
		if(document.getElementById("imgSmall"+ids[i]))
			document.getElementById("imgSmall"+ids[i]).style.display="";
		if(document.getElementById("icon"+ids[i]))
			document.getElementById("icon"+ids[i]).src=imgPath+"more.gif";
	}
	document.getElementById("linkexpand").style.display="inline";
	document.getElementById("linkcollapse").style.display="none";

	extendedFields=false;
}

//shows the extended fields of all the search results
function expandResults(idArray){
	if(idArray.substring(idArray.length-1,idArray.length)==","){//remove a possible comma at the end
		idArray=idArray.slice(0,idArray.length-1);
	}
	var ids=idArray.split(',');
	for(i=0;i<ids.length;i++){
		if(document.getElementById("server"+ids[i]))
			document.getElementById("server"+ids[i]).style.display="";
		if(document.getElementById("company"+ids[i]))
			document.getElementById("company"+ids[i]).style.display="";
		if(document.getElementById("imgSmall"+ids[i]))
			document.getElementById("imgSmall"+ids[i]).style.display="none";
		if(document.getElementById("imgBig"+ids[i]))
			document.getElementById("imgBig"+ids[i]).style.display="";
		if(document.getElementById("icon"+ids[i]))
			document.getElementById("icon"+ids[i]).src=imgPath+"less.gif";
	}
	document.getElementById("linkexpand").style.display="none";
	document.getElementById("linkcollapse").style.display="inline";
	extendedFields=true;
}

/*
	used for the pupus, every time a select box is chossen in any popup this
	method is called it checks the state fo the checkbox, and acording to it 
	adds/removes its id from the the text filds wich contains the ids of the 
	selecte items (Categories, Server, Countries)
*/
function addOrRemoveFromIdList(id, idname){
	if(!document.getElementById(id).checked){//if true the select Box is selected, so add it to the list
		var textInput=document.getElementById(""+idname);
		var array=textInput.value.split(",");
		var overwrite=false;
		for(i=0;i<array.length;i++){
			if(array[i]==id){
				overwrite=true;				
			}
			if(overwrite){
				array[i]=array[i+1];
			}
		}
		array.length--;
		textInput.value="";
		for(i=0;i<array.length;i++) {
			var inputText=document.getElementById(""+idname);
			if(inputText.value==""){
				document.getElementById(""+idname).value+=array[i];			
			}else{
				document.getElementById(""+idname).value+=","+array[i];
			}
		}
	}else{
		var inputText=document.getElementById(""+idname);
		if(inputText.value==""){
			document.getElementById(""+idname).value+=id;			
		}else{
			document.getElementById(""+idname).value+=","+id;
		}
	}
}
/*
function addOrRemoveFromIdList(id){
	if(!document.getElementById(id).checked){//if true the select Box is selected, so add it to the list
		var textInput=document.getElementById("ids");
		var array=textInput.value.split(",");
		var overwrite=false;
		for(i=0;i<array.length;i++){
			if(array[i]==id){
				overwrite=true;				
			}
			if(overwrite){
				array[i]=array[i+1];
			}
		}
		array.length--;
		textInput.value="";
		for(i=0;i<array.length;i++) {
			var inputText=document.getElementById("ids");
			if(inputText.value==""){
				document.getElementById("ids").value+=array[i];			
			}else{
				document.getElementById("ids").value+=","+array[i];
			}
		}
	}else{
		var inputText=document.getElementById("ids");
		if(inputText.value==""){
			document.getElementById("ids").value+=id;			
		}else{
			document.getElementById("ids").value+=","+id;
		}
	}
}
*/


function showCitiesInput(){
	document.getElementById("Cities").style.display="";
}

function redirectTo(url){
	window.location.href=url;
}

function goToText(toHide,toShow){
	document.getElementById(toHide).style.display="none";
	document.getElementById(toShow).style.display="";
}


//sometimes (after pressing the back button) these selects are not on their first option avoid it
function resetQuickSearchSelects(){
	document.getElementById("searchserver").selectedIndex=0;
	document.getElementById("searchcategory").selectedIndex=0;
	document.getElementById("searchcountry").selectedIndex=0;
}

//check if the returnbutton has been hit
function qickSearchCheckReturn(e,type,selectBox,url)
{
	if(e.keyCode == 13)
	{
		redirectToSearch(type,selectBox,url);
	}		
}

//redirect the user to the search page accordig to what he selected
function redirectToSearch(type,selectBox,url){
	
	if (type == "server" || type == "category" || type == "country") {
		if (selectBox.options[selectBox.selectedIndex].value != "none") {
			if (type == "server") {
				window.location = url + "&reset=yes&filterserver=" + selectBox.options[selectBox.selectedIndex].value;
			}
			if (type == "category") {
				window.location = url + "&reset=yes&filtercategory=" + selectBox.options[selectBox.selectedIndex].value;
			}
			if (type == "country") {
				window.location = url + "&reset=yes&filterland=" + selectBox.options[selectBox.selectedIndex].value;
			}
			
		}
	}	
	else if (type == "searchname") {
		window.location = url+"&reset=yes&searchname="+selectBox.value;
	}
}

function changeClass(id,aCssClass){
	document.getElementById(id).className=aCssClass;
}

//switch beetween the tag cloud and the G-Maps
function toogleCloudMaps(toShow, imagepath){
	if(toShow=="tags"){
		document.getElementById("tagclouddiv").style.display="";
		document.getElementById("map").style.display="none";	
		document.getElementById("mapbutton").style.background="transparent url("+imagepath+"map_menu_back.png) no-repeat";
		document.getElementById("tagbutton").style.background="transparent url("+imagepath+"map_menu.png) no-repeat";
	}else{
		document.getElementById("tagclouddiv").style.display="none";
		document.getElementById("map").style.display="";
		document.getElementById("mapbutton").style.background="transparent url("+imagepath+"map_menu.png) no-repeat";
		document.getElementById("tagbutton").style.background="transparent url("+imagepath+"map_menu_back.png) no-repeat";
	}
}
function resizeTables(numberOfTables){
	var newHeight=280/(numberOfTables+1)
	for(i=0;i<numberOfTables;i++){
		var id="tagcloudtable"+i;
		document.getElementById(id).style.height=newHeight;
	}
}

function resizeTablesClicked(numberOfTables){
	var newHeight=280/(numberOfTables+1)
	for(i=0;i<numberOfTables;i++){
		var id="tagcloudtableclicked"+i;
		document.getElementById(id).style.height=newHeight;
	}
}

//Show the popups for search
function industries_popup(){
	document.getElementById('industries_popup').style.display='block';
}
function servers_popup(){
	document.getElementById('servers_popup').style.display='block';
}
function countries_popup(){
	document.getElementById('countries_popup').style.display='block';
}

function industries_popup_hide(){
	document.getElementById('industries_popup').style.display='none';
}
function servers_popup_hide(){
	document.getElementById('servers_popup').style.display='none';
}
function countries_popup_hide(){
	document.getElementById('countries_popup').style.display='none';
}

function setFeedbackSubject(subject)
{
	document.getElementById('fbsubject').value="["+subject+"] ";
}

function resetFormular(){

	
	
	document.getElementById('companyname').value="";
	document.getElementById('sitename').value="";
	document.getElementById('address').value="";
	document.getElementById('city').value="";
	document.getElementById('description').value="";
	document.getElementById('tags').value="";
	document.getElementById('streetadress').value="";
	// mra 2008-12-23 captcha entfernt	
	//document.getElementById('captchainput').value="";
		
	document.getElementById('selectcategories').options[0].selected=true; 
	document.getElementById('selectserver').options[0].selected=true;
	document.getElementById('country').options[0].selected=true;
	document.getElementById('from').options[0].selected=true;
	document.getElementById('until').options[0].selected=true;


		document.getElementById('cell11').innerHTML="-";
		document.getElementById('cell12').innerHTML="-";
		document.getElementById('cell13').innerHTML="-";
		document.getElementById('cell14').innerHTML="-";
		document.getElementById('cell15').innerHTML="-";
		document.getElementById('cell16').innerHTML="-";
		document.getElementById('cell17').innerHTML="-";
		document.getElementById('cell18').innerHTML="-";
		document.getElementById('cell19').innerHTML="-";
		document.getElementById('cell110').innerHTML="-";
		document.getElementById('cell111').innerHTML="-";
		document.getElementById('cell112').innerHTML="-";
		document.getElementById('cell113').innerHTML="-";
		document.getElementById('cell114').innerHTML="-";
		document.getElementById('cell115').innerHTML="-";
		document.getElementById('cell116').innerHTML="-";
		document.getElementById('cell117').innerHTML="-";
		document.getElementById('cell118').innerHTML="-";
		document.getElementById('cell119').innerHTML="-";
		document.getElementById('cell120').innerHTML="-";
		document.getElementById('cell121').innerHTML="-";
		document.getElementById('cell122').innerHTML="-";
		document.getElementById('cell123').innerHTML="-";
		document.getElementById('cell124').innerHTML="-";


		
		document.getElementById('cell11').style.display="none";
		document.getElementById('cell12').style.display="none";
		document.getElementById('cell13').style.display="none";
		document.getElementById('cell14').style.display="none";
		document.getElementById('cell15').style.display="none";
		document.getElementById('cell16').style.display="none";
		document.getElementById('cell17').style.display="none";
		document.getElementById('cell18').style.display="none";
		document.getElementById('cell19').style.display="none";
		document.getElementById('cell110').style.display="none";
		document.getElementById('cell111').style.display="none";
		document.getElementById('cell112').style.display="none";
		document.getElementById('cell113').style.display="none";
		document.getElementById('cell114').style.display="none";
		document.getElementById('cell115').style.display="none";
		document.getElementById('cell116').style.display="none";
		document.getElementById('cell117').style.display="none";
		document.getElementById('cell118').style.display="none";
		document.getElementById('cell119').style.display="none";
		document.getElementById('cell120').style.display="none";
		document.getElementById('cell121').style.display="none";
		document.getElementById('cell122').style.display="none";
		document.getElementById('cell123').style.display="none";
		document.getElementById('cell124').style.display="none";
}


function setSearchBackgroundBlank(object){
	document.getElementById(object).className='inputWithOutBG';
}

function setSearchBackground(object){
	document.getElementById(object).className='inputWithBG';
}

function changeSearchBackground(object){
	var tempclass = document.getElementById(object).className;
	if(document.getElementById(object).value == ""){
		setSearchBackground(object);
	}
	else{
		setSearchBackgroundBlank(object);
	}
	
}

function ismaxlength(obj){
	var mlength=obj.getAttribute? parseInt(obj.getAttribute("maxlength")) : ""
	if (obj.getAttribute && obj.value.length>mlength)
	{
		obj.value=obj.value.substring(0,mlength);
	}
			
}

function doMostClicked(){	
	document.getElementById('tagcloudClicked').style.display='block';
	document.getElementById('tagcloudUsed').style.display='none';
	document.getElementById('mostUsed').style.textDecoration ='none';
	document.getElementById('mostClicked').style.textDecoration ='underline';	
}
	
function doMostUsed(){	
	document.getElementById('tagcloudClicked').style.display='none';
	document.getElementById('tagcloudUsed').style.display='block';
	document.getElementById('mostUsed').style.textDecoration ='underline';
	document.getElementById('mostClicked').style.textDecoration ='none';	
}

function hideAllPopups(){
	document.getElementById('countries_popup').style.display='none';
	document.getElementById('industries_popup').style.display='none';
	document.getElementById('servers_popup').style.display='none';
}


