current_selected_news = 1;

function change_opcity(obj, type)
{
	if(type == 1)
	{
		op = Math.round((parseFloat(im.style.opacity) + 0.1) * 100) / 100;
		im.style.opacity = op;
		im.style.filter = 'alpha(opacity=' + op * 100 + ')';
		if(op < 1)
		{
			setTimeout("change_opcity(obj, 1)", 50);
		}
	}
	else
	{
		op = Math.round((parseFloat(im.style.opacity) - 0.1) * 100) / 100;
		im.style.opacity = op;
		im.style.filter = 'alpha(opacity=' + op * 100 + ')';
		if(op > 0)
		{
			setTimeout("change_opcity(obj, 0)", 50);
		}
	}
}

//#################################################################################
//#################################################################################

function change_main_news(n)
{
	im = fetch_object("image" + current_selected_news);
	change_opcity(im, 0);
	if(im.style.opacity > 0)
	{
		setTimeout("change_main_news(" + n + ")", 50);
		return;
	}
	for(i = 1; i < 6; i++)
	{
		obj = fetch_object("story" + i);
		obj2 = fetch_object("main_title" + i);
		
		if(i == n)
		{
			current_selected_news = i;
			obj.className = "showed_story";
			obj2.className = "selectd_story";
		}
		else
		{
			obj.className = "unshowed_story";
			obj2.className = "unselectd_story";
		}
	}
	im = fetch_object("image" + n);
	change_opcity(im, 1);
}

//#################################################################################
//#################################################################################

function change_last(n)
{
	obj = fetch_object("last1");
	obj2 = fetch_object("last2");
	obj3 = fetch_object("last_body_1");
	obj4 = fetch_object("last_body_2");
	if(n == 1)
	{
		obj.className = "last_news_header_selected";
		obj2.className = "most_comment_header";
		obj3.className = "last_body_1";
		obj4.className = "last_body_2_hidden";
	}
	else
	{
		obj.className = "last_news_header";
		obj2.className = "most_comment_header_selected";
		obj3.className = "last_body_1_hidden";
		obj4.className = "last_body_2";
	}
}

//#################################################################################
//#################################################################################

function show_cat(n)
{
	for(i = 1; i < 5; i++)
	{
		obj = fetch_object("cat_name" + i);
		obj2 = fetch_object("cat_body" + i);
		if(i == n)
		{
			obj.className = "selected_cat_name";
			obj2.className = "showed_cat";
		}
		else
		{
			obj.className = "cat_name";
			obj2.className = "unshowed_cat";
		}
	}
}

//#################################################################################
//#################################################################################

function check_comment_form()
{
	name = fetch_object("name");
	if(name.value == "")
	{
		alert("الرجاء عدم ترك الأسم فارغاً");
		return false;
	}
	subject = fetch_object("subject");
	if(subject.value == "")
	{
		alert("الرجاء عدم ترك الموضوع فارغاً");
		return false;
	}
	text = fetch_object("text");
	if(text.value == "")
	{
		alert("الرجاء عدم ترك النص فارغاً");
		return false;
	}
	return true;
}

//#################################################################################
//#################################################################################

function auto_select_news()
{
	i = current_selected_news + 1;
	if(i > 5)
	{
		i = 1;
	}
	change_main_news(i)
	setTimeout("auto_select_news()", 10000);
}

//#################################################################################
//#################################################################################

function fetch_object(idname)
{
	if (document.getElementById)
	{
		return document.getElementById(idname);
	}
	else if (document.all)
	{
		return document.all[idname];
	}
	else if (document.layers)
	{
		return document.layers[idname];
	}
	else
	{
		return null;
	}
}

//#################################################################################
//#################################################################################

function bookMark()
{
	var title; 
	var url;
	title= document.title;
	url=window.location;

	if (window.sidebar)
	{
		window.sidebar.addPanel(title, url,"");
	}
	else if( window.external )
	{
		window.external.AddFavorite( url, title);
	}
	else if(window.opera && window.print)
	{
		return true;
	}

}

//#################################################################################
//#################################################################################

function vote()
{
	obj = fetch_object("poll_id");
	id = obj.value;
	option = null;
	for (s = 0; ; s++)
	{
		obj = fetch_object("poll_option" + s);
		if(!obj)
		{
			break;
		}
		if(obj.checked)
		{
			option = obj.value;
		}
	}

	if (option != null)
	{
		window.open("polls.php?actn=vote&id=" + id + "&option="+option, "poll", "height=400, width=622")
	}
	else
	{
		alert('الرجاء تحديد أحد الخيارات')
	}
	return false;
}

//#################################################################################
//#################################################################################

function result()
{
	obj = fetch_object("poll_id");
	id = obj.value;
	window.open("polls.php?actn=result&id=" + id , "poll", "height=400, width=622")
	return false;
}
