// JavaScript Document
// objectTOFade = the div   targetedOpacity (0 to 100), stepsSize(0 to 100) 

function format_as_currency(amount)
{
	if(amount.include(','))
	{
		return amount.substring(0,amount.indexOf(",")+3);
	}
	else
		return amount;
}

function stop_propagation(event)
{
	if(IE)
		event.cancelBubble=true;
	else
		event.stopPropagation(true);
}

function try_submit(e)
{
	if(main_function==null)
	{
		if( (current_window=="index")&&(selected_user.status==0) )
			main_function="log_me()";		
	}
	
	if(main_function!=null)
	{
		var keycode;
		if (IE) 
			keycode= window.event.keyCode;
		else  
			keycode= e.which;
	
		if ( (keycode == 13) )
		{
			eval(main_function);
			return false;
		}
		else
		   return true;
	}
	else
		return false;
}

function set_main_function(the_function)
{
	main_function	= the_function;
}


function buttonOn(type, id)
{
	var leftId=id+"_button_left";
	$(leftId).src =pathToImages+eval(type+"_leftImageOn");
	var rightId=id+"_button_right";
	$(rightId).src=pathToImages+eval(type+"_rightImageOn");
	var captionId=id+"_caption";
	$(captionId).className=type+"_button_on_mouse_over";
	buttonIsOn=true;
	return false;
}

function buttonOff(type, id)
{
	var leftId=id+"_button_left";
	$(leftId).src =pathToImages+eval(type+"_leftImage");
	var rightId=id+"_button_right";
	$(rightId).src=pathToImages+eval(type+"_rightImage");
	var captionId=id+"_caption";
	$(captionId).className=type+"_button_enabled";
	buttonIsOn=true;
	return false;
}

function fadeMe(objectToFade_ID, targetedOpacity, stepsSize)
{
	try{
	var fade_object = new function()
	{
		this.objectToFade_ID=objectToFade_ID;
		this.targetedOpacity=targetedOpacity;
		this.stepsSize=stepsSize;
		return this; 
	};
	var counter=0;
	var current_index = interval_effect_array.length;
	interval_effect_array.push(fade_object);
	
	var current_object = interval_effect_array[current_index];
	interval_effect_array[current_index]._interval = window.setInterval(
		function (){
			
			var objectToFade=$(current_object.objectToFade_ID);
			var currentOpacity;
			
			//Modifying value for IE
			if(IE)
			{
				try{currentOpacity = objectToFade.filters.alpha.opacity;}
				catch(exception){currentOpacity=0;}	
			}
			else
			{	
				if (objectToFade.style.opacity=="")
					currentOpacity = "0";
				else
					currentOpacity =  objectToFade.style.opacity*100;
			}
		
			
			if (((currentOpacity-current_object.stepsSize)<current_object.targetedOpacity)
					||(current_object.targetedOpacity==currentOpacity) )//do nothing 
			{
				if(IE)
					objectToFade.style.filter="alpha(opacity="+(current_object.targetedOpacity)+")";
				else
					objectToFade.style.opacity=current_object.targetedOpacity/100;
				
				window.clearInterval(current_object._interval);
				
				if(current_object.targetedOpacity==0)
					objectToFade.style.display="none";
				return;
				
			}
			else if (currentOpacity < current_object.targetedOpacity) 
			{
					if(IE)
					 	objectToFade.style.filter="alpha(opacity="+(currentOpacity+current_object.stepsSize)+")";
					else
						objectToFade.style.opacity=(currentOpacity+current_object.stepsSize)/100;	
		
			}
			else if (currentOpacity > current_object.targetedOpacity) 
			{
				if(IE)
			 		objectToFade.style.filter="alpha(opacity="+(parseInt(currentOpacity)-current_object.stepsSize)+")";
				else
					objectToFade.style.opacity=(currentOpacity-current_object.stepsSize)/100;
			}
		},10);
	}catch(e){alert("error in function fade_me(effects.js). Error:"+e.message)}
}

function maximizeMe(object_ID, targetedHeight, targetedWidth)
{
	var theObject=$(object_ID);
	var heightStepSize = parseInt(targetedHeight/10);

	var widthStepSize = parseInt(targetedWidth/10);
	theObject.style.height = theObject.getHeight()+"px";
	theObject.style.width= theObject.getWidth()+"px";
	theObject.style.display="block";
	setTimeout("maximize('" + object_ID + "'," + targetedHeight + "," + targetedWidth + ","+ heightStepSize+ ","+widthStepSize  + ")", 0);
}


function switch_images(the_object,image_a, image_b)
{
	if (the_object.src==pathToImages+image_a)
		the_object.src=pathToImages+image_b;
	else
		the_object.src=pathToImages+image_a;
}


function change_to_error_class(the_object)
{
	$(the_object.id+"_label").style.color="#CC0000";
	$(the_object.id).style.background="yellow";	
}

function remove_error_class()
{
	$$('span.form_field_label').each(function(el){el.style.color="#003300";$(el.getAttribute("my_child")).style.background="#ffffff";});
}

function start_moving_up(the_object)
{
	stop_moving_down();
	
		moving_up = window.setInterval(
			function (){
				
				if(the_object.getHeight()>(parseInt(the_object.style.top).abs()+list_container_height)-80)
					the_object.style.top =  parseInt(the_object.style.top)-5;
				else
					stop_moving_up();
			},20);
		
}

function stop_moving_up()
{
	window.clearInterval(moving_up);
}	

function start_moving_down(the_object)
{
	stop_moving_up();
	moving_down = window.setInterval(
		function (){
			if(parseInt(the_object.style.top)<0)
				the_object.style.top =  parseInt(the_object.style.top)+5;
			else
				stop_moving_down();
		},20);
}

function stop_moving_down()
{
	window.clearInterval(moving_down);
}	


function start_moving_right(the_object_name)
{
	
	var the_object = $(the_object_name);
	
	stop_moving_left();
	var max_right =0;
		moving_right = window.setInterval(
			function (){

				if(parseInt(the_object.style.left)<max_right)
					the_object.style.left =  parseInt(the_object.style.left)+5;
				else
				{
					the_object.style.left="0px";
					stop_moving_right();
				}
					
			},20);
		
}

function stop_moving_right()
{
	window.clearInterval(moving_right);
}	

function start_moving_left(the_object_name, the_container_name)
{
	var the_object = $(the_object_name);
	var the_container = $(the_container_name);

	if (the_object.getWidth() > $(the_container_name).getWidth()) {	
		stop_moving_right();

		var max_left = the_object.getWidth() - $(the_container_name).getWidth();

		moving_left = window.setInterval(function(){
			if (parseInt(the_object.style.left) > (0-max_left)) 
				the_object.style.left = parseInt(the_object.style.left) - 5;
			else {
				the_object.style.left = (0-max_left) + "px";
				stop_moving_left();
			}
		}, 20);
	}
}

function stop_moving_left()
{
	window.clearInterval(moving_left);
}

function create_shadow(the_object,the_color)
{
	var the_object_clone = the_object.cloneNode(true);
	the_object_clone.id = the_object.id+"_text_clone";
	the_object_clone.style.position="absolute";
	if(the_color==null)
		the_object_clone.style.color = "black";
	else
		the_object_clone.style.color = the_color;
	the_object_clone.style.paddingLeft = "1px";
	the_object_clone.style.paddingTop = "1px";
	Element.insert(the_object,{'before':the_object_clone});	
	create_shadow_up(the_object,the_color);
}

function create_shadow_up(the_object,the_color)
{
	var the_object_clone = the_object.cloneNode(true);
	the_object_clone.id = the_object.id+"_text_clone";
	the_object_clone.style.position="absolute";
	if(the_color==null)
		the_object_clone.style.color = "black";
	else
		the_object_clone.style.color = the_color;
	the_object_clone.style.left = Element.positionedOffset(the_object_clone).left-1;

	Element.insert(the_object,{'before':the_object_clone});	
}



