
//toogles a checkbox
function toggleCheckbox(fieldElement) {
	jQuery(fieldElement).toggleClass("selected");
	
	if(!jQuery(fieldElement).hasClass("selected")) {
		jQuery(fieldElement).find("input").removeAttr("checked");
	} else {
		// set checkbox checked
		jQuery(fieldElement).find("input").attr("checked", "checked");
	}
}

// toggles an element (e.g. for the newslist)
function toggleElement(element_ID)
{
	$(element_ID).toggleClass("open");
}
 

function gototop()
{
	setTimeout("self.scrollTo(0,0)",1);
}


/**
 * 
 * @param elementsSelector JQuery selector.
 * @param showIndex Element at index will be become visible.
 * @param animate True if taggle should be animated (for future usage).
 * @return
 */
function toggleElementAndHideOthers(elementsSelector, showIndex, animate)
{
	//console.log(elementsSelector);
	var elements = $(elementsSelector);
	
	//console.log('anzahl elemente: '+elements.length);
	//console.log('sichtbares: '+showIndex);	
	
	if(elements.length >= showIndex && showIndex > -1) {
	
		// hide all elements
		for(i=0; i < elements.length; i++) {
			$('#'+elements[i].id).hide();
		}
		
		// show choosen element
		$('#'+elements[showIndex].id).show();
	}
}	

/**
 * Retrieves th current selected value of a checkbox.
 * 
 * @param selectboxId Id of the selectbox.
 * @return 
 */
function getSelectedValue(selectboxId) {
	var dropdown = $('#'+selectboxId)[0];
	
	for(i=0; i < dropdown.length; i++) {
		if(dropdown.options[i].selected == true && dropdown.options[i].value!='') {
			return dropdown.options[i].value;
		}
	}
	return -1;
}


function jumpToAnchor(selectboxId) {
	 //console.log(selectboxId);
	 var tempLocation = window.location.href.split("#");
	 var dropdown = $('#'+selectboxId)[0];
	 //console.log(dropdown);
	 
	 for(i=0; i < dropdown.length; i++)
	 {
		if(dropdown.options[i].selected == true)
		{
			window.location.href = tempLocation[0] + dropdown.options[i].value;
		}
	 }
}


function jumpToURL(selectboxId) {
	var dropdown = $('#'+selectboxId)[0];
	
	for(i=0; i < dropdown.length; i++)
	{
		if(dropdown.options[i].selected == true && dropdown.options[i].value!='')
		{
			window.location.href = dropdown.options[i].value;
		}
	}    
}

function SwapInputPWDisplay( o, b )
{
   try {
		
       o.removeAttribute('type');
     	 o.setAttribute( 'type', ( b ? 'text' : 'password' ) );
       o.focus;
   } catch ( exception ) {

  	 // ie
		   var newElement = null;
		   var tempStr = o.getAttribute("name");
		   try {					
			      newElement = document.createElement("<input class=\"text\" type=\"password\" name=\"" +tempStr+ "\">");
			      
		   } catch (e) {}
		   if (!newElement) {
		      newElement = document.createElement("input");
		      newElement.setAttribute("type", "password");
		      newElement.setAttribute("name", tempStr);
		      newElement.setAttribute("class", "text");			     			      
		   }			   
		   o.parentNode.replaceChild(newElement, o);
		   newElement.focus;            
		}         
}

	


