//JavaScript Document

function hide(whichItem){
	document.getElementById(whichItem).style.display="none";
	}

function hideAll(whichPage){

	document.getElementById('icons').style.display="none";
	document.getElementById('screens').style.display="none";
	document.getElementById('ads').style.display="none";
	
		
	if(whichPage == 'wobble02'){
		document.getElementById('hotWobbles').style.display="none";
		}else{}
		
	}




function show(whichItem, whichPage){
	hideAll(whichPage);
	document.getElementById(whichItem).style.display="";	
	}
	
	
function showOne(whichItem){
	document.getElementById(whichItem).style.display="";
	}
	
function hideAllOn(whichPage){
	
	if(whichPage == 'home'){
		document.getElementById('signup').style.display="none";
		document.getElementById('loginError').style.display="none";
		document.getElementById('wobbleList').style.display="none";
		}else{}
	
	}
	

function toggle(whichItem){
	target = document.getElementById(whichItem);
	if (target.style.display == "none"){target.style.display = "";}else{target.style.display="none";}
	}
	
	
function ClearInput(value, id){ 
	var input = document.getElementById(id); 
	
	if(value == input.value){
		input.value = '';
	}else{ 
		input.value = input.value;
	}
} 


function setId(element, value)
{
	document.getElementById(element).value=value;
}

function change (whichItem, newClass){
	
	document.getElementById(whichItem).className = newClass;
	
	}

function onFocus(input)
{
   if (!input.hasAttribute('changed'))
     input.value = "";	
}

function onBlur(input, caption)
{
	if (input.value == "")
	{
		input.value = caption;
		input.removeAttribute('changed');
	}
}

function onChange(input)
{
	input.setAttribute('changed', 'true');
}

function reportWobble(wobble_id)
{
	if (confirm("Would you like to report this wobble as unsafe?"))
	{
	   document.getElementById(wobble_id).innerHTML = "<strong>Reported</strong>";
	   $.get('/index/reportwobble?id=' +wobble_id );
	}
}

function searchChange(state)
{
    st = getCookie('searchState');
	
    if (st == 'safe'){
      if (!confirm('Are you sure you would like to disable Safe Search?'))
      {
    	 elem = document.getElementById('safe'); 
       	 elem.checked=true;
       	 return;
      }
    }  
    
    redirect(state); 
    
	
	return true;
}

function redirect(state)
{
	window.location = '/home/index?search=' + state;
}

function getCookie(c_name)
{
	if (document.cookie.length>0)
	{
	  c_start=document.cookie.indexOf(c_name + "=");
	  if (c_start!=-1)
	    {
	    c_start=c_start + c_name.length+1;
	    c_end=document.cookie.indexOf(";",c_start);
	    if (c_end==-1) c_end=document.cookie.length;
	    return unescape(document.cookie.substring(c_start,c_end));
	  }
	}
	return "";
}