/* Visit http://www.yaldex.com/ for full source code
and get more free JavaScript, CSS and DHTML scripts! */

var signup = false;
var is_public = false;

textCounter = function(field, countfield, maxlimit) {
	if (field.value.length > maxlimit){
		field.value = field.value.substring(0, maxlimit);
	}
	else{
		countfield.value = maxlimit - field.value.length;
	}
}



function hideElementWithAndShowSeparaterWithId(id){
	if(id != null){
		if(document.getElementById("controls_"+id) != null){
			document.getElementById("controls_"+id).style.display = 'none';
		}

		if(document.getElementById("seperater_"+id) != null){
			document.getElementById("seperater_"+id).style.display = '';
		}
		
		//document.getElementById("spacer").style.display = '';
		//document.getElementById("spacer-2").style.display = '';
		
	}
}

function showElementWithAndHideSeparaterWithId(id){
	if(id != null){
		if(document.getElementById("controls_"+id) != null){
			document.getElementById("controls_"+id).style.display = '';
		}

		if(document.getElementById("seperater_"+id) != null){
			document.getElementById("seperater_"+id).style.display = 'none';
		}
		
		//document.getElementById("spacer").style.display = 'none';
		//document.getElementById("spacer-2").style.display = '';
	}
}


function getNextIndex(what,which) {
		var numberOfElements = what.elements.length;
		var returnValue = -1;
		
    for (var i=0; (i < numberOfElements) && (returnValue == -1); i++)
        if (what.elements[i].id == which.id)
            returnValue =  i;

		returnValue++;
		
		if (returnValue >= numberOfElements){
			returnValue = 0;
		}
		
    return returnValue;
}

function handleKey(anEvent){
/*
	if(anEvent.keyCode == 9){
		anEvent.target.form.elements[getNextIndex(anEvent.target.form, anEvent.target)].focus();	
	}
	else if(anEvent.keyCode == 13){
		anEvent.target.form.submit();
	}
	*/
	return false;
}

function cleanData(){
  alert("test");
  return;
}

function reloadParentOnClose(){ 
  window.top.location.reload(); 
} 


function doNothing(){}


function display_messages(flash_active_record, flash_notice, session_notice){
    /*
    if(flash_active_record != null && flash_active_record != ''){
        alert(flash_active_record);
    }
    */
    if(flash_notice != null && flash_notice != ''){
        alert(flash_notice);
    }
    
    if(session_notice != null && session_notice != ''){
        alert(session_notice);
    }
    
}

function closeAndLoadSignup(){
    signup = true;
    
    GB_hide();
    
    if (is_public) {
        GB_showCenter('Sign Up!', "/join/create", 550, 600, loadPublic, false);
    }
    else{
        GB_showCenter('Sign Up!', "/join/create", 550, 600, loadOverview, false);
    }
}


function loadOverview(){
    
    if (!signup) {
        window.location = "/overview";
    }
    else{
        signup = false;
    }
	return false;
}

function loadNothing(){}

function loadPublic(){

    if (!signup) {
        window.location = PUBLIC;
    }
    else {
        signup = false;
    }
    return false;
}

function searchByUrl(searchString){	
	alert(searchString);
	return true;
}


