function pause(numberMillis)
{
	var now = new Date();
	var exitTime = now.getTime() + numberMillis;
	while (true)
	{
		now = new Date();
		if (now.getTime() > exitTime)
		return;
	}
} 
function dismiss()
{
	window.location.reload();
}
function followit(idea_id,user_id,truth_value)
{
	
	var http = false;
	
	if(navigator.appName == 'Microsoft Internet Explorer') 
	{
	 	http = new ActiveXObject('Microsoft.XMLHTTP');
	} 
	else 
	{
		http = new XMLHttpRequest();
	} 
	http.open('GET', '/ajax.php?idea='+idea_id+'&confirm='+truth_value+'&uid='+user_id, true);
  	http.onreadystatechange=function() 
  	{
    	if(http.readyState == 4) 
    	{
	    	
    		box=document.getElementById('confirmation');
    		box.innerHTML = http.responseText;
    		box.style.display='block';
    		box.style.position='absolute';
    		box.style.bgColor='white'
    		box.style.x=1000;
    		box.style.y=1000;
    		box.style.zIndex=1000;
    		box.style.height='100%';
    		box.style.width='100%';
    		map=document.getElementById('map_container');
    		map.style.display='none';
    		search=document.getElementById('search_and_browse_links');
    		search.style.display='none';
    		confirm=document.getElementById('follow_container');
    		confirm.style.display='none';
    		ind=document.getElementById('individual_details');
    		ind.style.display='none';
    	}
  	}
  	http.send(null);
}
/* This script and many more are available free online at
The JavaScript Source!! http://javascript.internet.com
Created by: Mr J | http://www.huntingground.net/ */

scrollStep=1

timerLeft=""
timerRight=""

function scrollDivLeft(id){
  document.getElementById(id).scrollLeft-=scrollStep
  timerRight=setTimeout('scrollDivLeft('+id+')',10)
}

function scrollDivRight(id){
  document.getElementById(id).scrollLeft+=scrollStep
  timerLeft=setTimeout("scrollDivRight("+id+")",10)
}


function stopMe(){
  clearTimeout(timerRight) 
  clearTimeout(timerLeft)
}

function switch_div(div_id,caller)
{
	if(div_id=='search')
	{
		document.search_form.search.focus();
	}
	div_ref=document.getElementById(div_id);
	if(caller!='')
	{
		caller_ref=document.getElementById(caller);
		class_name=caller_ref.getAttribute('class');
		if(class_name==null || class_name=='expand')
		{
			caller_ref.setAttribute('class','contract');
		}
		else
		{
			caller_ref.setAttribute('class','expand');
		}
	}
	if(div_ref.style.display=='none' || div_ref.style.display=='')
	{
		div_ref.style.display='block';
	}
	else
	{
		div_ref.style.display='none';
	}
}
function suggest() 
{
	var http = false;

	if(navigator.appName == 'Microsoft Internet Explorer') 
	{
	 	http = new ActiveXObject('Microsoft.XMLHTTP');
	} 
	else 
	{
		http = new XMLHttpRequest();
	} 

	var word=document.forms['idea_form'].category.value;
	http.open('GET', 'ajax.php?word='+word, true);
  	http.onreadystatechange=function() 
  	{
    	if(http.readyState == 4) 
    	{
      		document.getElementById('suggestion_box').innerHTML = http.responseText;
    	}
  	}
  	http.send(null);
}
function update_description()
{
	if(document.forms.category_form!=undefined)
	{
		var category_id=document.forms.category_form.category.value;
		category_description=document.getElementById('category_description');
		get_description=document.getElementById('category_'+category_id+' extensive_description');
		if(get_description!=null)
		{
			category_description.innerHTML=get_description.innerHTML;
			get_category=document.getElementById('category_description');
			get_category.style.height='200px';
			get_category.style.overflowY='scroll';
			get_category.style.marginBottom='5px';
		}
		else
		{
			category_description.style.display='none';
		}
	}
	else
	{
		var category_id=document.forms.file_management.category.value;
		category_description=document.getElementById('category_description');
		get_description=document.getElementById('category_'+category_id+' extensive_description');
		if(get_description!=null)
		{
			category_description.innerHTML=get_description.innerHTML;
			get_category=document.getElementById('category_description');
			get_category.style.height='200px';
			get_category.style.overflowY='scroll';
			get_category.style.marginBottom='5px';
		}
		else
		{
			category_description.style.display='none';
		}
	}
}
function limit(field, count, number) 
{
	if (field.value.length > number) 
	{
		field.value = field.value.substring(0, number);
	} 
	else 
	{
		count.value = number - field.value.length;
	}
}
// main function to process the fade request //
function colorFade(id,element,start,end,steps,speed) {
  var startrgb,endrgb,er,eg,eb,step,rint,gint,bint,step;
  var target = document.getElementById(id);
  steps = steps || 20;
  speed = speed || 20;
  clearInterval(target.timer);
  endrgb = colorConv(end);
  er = endrgb[0];
  eg = endrgb[1];
  eb = endrgb[2];
  if(!target.r) {
    startrgb = colorConv(start);
    r = startrgb[0];
    g = startrgb[1];
    b = startrgb[2];
    target.r = r;
    target.g = g;
    target.b = b;
  }
  rint = Math.round(Math.abs(target.r-er)/steps);
  gint = Math.round(Math.abs(target.g-eg)/steps);
  bint = Math.round(Math.abs(target.b-eb)/steps);
  if(rint == 0) { rint = 1 }
  if(gint == 0) { gint = 1 }
  if(bint == 0) { bint = 1 }
  target.step = 1;
  target.timer = setInterval( function() { animateColor(id,element,steps,er,eg,eb,rint,gint,bint) }, speed);
}

// incrementally close the gap between the two colors //
function animateColor(id,element,steps,er,eg,eb,rint,gint,bint) {
  var target = document.getElementById(id);
  var color;
  if(target.step <= steps) {
    var r = target.r;
    var g = target.g;
    var b = target.b;
    if(r >= er) {
      r = r - rint;
    } else {
      r = parseInt(r) + parseInt(rint);
    }
    if(g >= eg) {
      g = g - gint;
    } else {
      g = parseInt(g) + parseInt(gint);
    }
    if(b >= eb) {
      b = b - bint;
    } else {
      b = parseInt(b) + parseInt(bint);
    }
    color = "rgb(" + r + "," + g + "," + b + ")";
    if(element == "background") {
      target.style.backgroundColor = color;
    } else if(element == "border") {
      target.style.borderColor = color;
    } else {
      target.style.color = color;
    }
    target.r = r;
    target.g = g;
    target.b = b;
    target.step = target.step + 1;
  } else {
    clearInterval(target.timer);
    color = "rgb(" + er + "," + eg + "," + eb + ")";
    if(element == "background") {
      target.style.backgroundColor = color;
    } else if(element == "border") {
      target.style.borderColor = color;
    } else {
      target.style.color = color;
    }
  }
}

// convert the color to rgb from hex //
function colorConv(color) {
  var rgb = [parseInt(color.substring(0,2),16), 
    parseInt(color.substring(2,4),16), 
    parseInt(color.substring(4,6),16)];
  return rgb;
}

function fix_it(field_name,condition,error_message,error_div,matching_field)
{
	field=document.getElementById(field_name);
	if(matching_field!="")
	{
		match=document.getElementById(matching_field);
	}
	error=false;
	error_field=document.getElementById(error_div);
	
	if(condition=='empty')
	{	
		if(field.value=='')
		{
			error=true;
		}
	}
	if(condition=='match')
	{
		if(field.value!=match.value)
		{
			alert(field.value);
			alert(match.value);
			error=true;
		}
	}
	if(condition=="password")
	{
		pwd=field.value;
		if(pwd=="")
		{
			error=true;
		}
		if(pwd.length<4)
		{
			error=true;
		}
	}
	if(error==true)
	{
		error_field.style.backgroundColor='#66AA77';
		error_field.style.display='block';
		error_field.style.fontWeight='bold';
		error_field.style.fontSize='12px';
		error_field.style.width='50%';
		error_field.style.margin="5px";
		error_field.style.padding='4px';
		error_field.style.textAlign='center';
		error_field.innerHTML=error_message;
	}
	else
	{
		error_field.style.display='none';
	}
}
function custom_show(div_id)
{
	document.getElementById('main_idea_editor').style.display='none';
	document.getElementById('manage_files').style.display='none';
	document.getElementById('manage_advertising').style.display='none';
	var div_id=div_id;
	if(document.getElementById(div_id).style.display=='none' ||document.getElementById(div_id).style.display=='')
	{
		document.getElementById(div_id).style.display='block'
	}
	else
	{
		document.getElementById(div_id).style.display='none'
	}
}
function mark_read(idea_id,user_id)
{
	var http = false;

	if(navigator.appName == 'Microsoft Internet Explorer') 
	{
	 	http = new ActiveXObject('Microsoft.XMLHTTP');
	} 
	else 
	{
		http = new XMLHttpRequest();
	} 
	http.open('GET', '/ajax.php?idea_id='+idea_id+'&user_id='+user_id, true);
  	http.onreadystatechange=function() 
  	{
    	if(http.readyState == 4) 
    	{
    		document.getElementById('response').innerHTML = http.responseText;
    	}
  	}
  	http.send(null);
}