var selected_search = 3;
var art_selected = 1;


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

function change_time()
{	
	div = fetch_object("time");
	if((mint + 1 ) % 60 == 0)
	{
		hour = (hour + 1 ) % 24;
	}
	mint = (mint + 1 ) % 60;
	h = (hour >= 10) ? hour : "0" + hour;
	m = (mint >= 10) ? mint : "0" + mint;
	div.innerHTML = "" + h + ":" + m;
	setTimeout("change_time()", 60000);
}

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

function change_art(bar_obj, id)
{
	div = fetch_object("art" + art_selected);
	div.style.display = "none";
	
	div = fetch_object("art" + id);
	div.style.display = "block";
	
	obj = fetch_object("bar" + art_selected);
	obj.className = "arts_bar_item_unselected";
	
	bar_obj.className = "arts_bar_item_selected";
	
	art_selected = id;
}

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

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 input_set_background(obj, x, y)
{	
	if(obj.value == '')
	{
		obj.style.backgroundPosition = x + "px " + y + "px";
	}
}

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

function set_background(id, cat)
{	
	obj = fetch_object("search" + selected_search);
	obj.style.backgroundPosition = "0px -34px";
	
	obj = fetch_object("search" + id);
	obj.style.backgroundPosition = "0px -0px";
	
	obj = fetch_object("serach_in");
	t = (parseInt(id) - 1) * 24;
	obj.style.backgroundPosition = "5px -" + t + "px";
	obj = fetch_object("search_cat");
	
	obj.value = cat;
	
	selected_search = id;
}

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

function brows_action()
{
	browse_sh = fetch_object("browse_sh");
        if(browse_sh.value == 3)
        {
                return false;
        }
	browse_cat = fetch_object("browse_cat");
	var url = '';
	if(browse_cat.value == 1)
	{
		url = "fatawash" + browse_sh.value + ".html";
	}
	if(browse_cat.value == 2)
	{
		url = "artssh" + browse_sh.value + ".html";
	}
	if(browse_cat.value == 3)
	{
		url = "soundssh" + browse_sh.value + ".html";
	}
	if(browse_cat.value == 4)
	{
		url = "bookssh" + browse_sh.value + ".html";
	}
	window.location = url;
	return false;
}

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

function chang_bar_item_top()
{
	var obj = fetch_object("bar_item" + current_in_bar);
	var obj_top = parseInt(obj.style.top) - 1;
	obj.style.top = "" + obj_top + "px";
	obj.style.display = "block";
	if (obj_top > 22)
	{
		setTimeout("chang_bar_item_top()", 1);
	}
}

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

function change_news_bar()
{
	obj = fetch_object("bar_item" + current_in_bar);
	//alert(obj)
	if(obj != null)
	{
		obj.style.display = "none";
		obj.style.top = "25px";
	}
	current_in_bar = current_in_bar + 1;
	new_obj = fetch_object("bar_item" + current_in_bar);
	if(new_obj == null)
	{
		current_in_bar = 1;
		new_obj = fetch_object("bar_item" + current_in_bar);
	}
	new_obj.style.display = "block";
	chang_bar_item_top();
	setTimeout("change_news_bar()", 3000)
}

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

function echeck(str) 
{
	var at="@";
	var dot=".";
	var lat=str.indexOf(at);
	var lstr=str.length;
	var ldot=str.indexOf(dot);
	if (str.indexOf(at) == -1)
	{
	   return false
	}

	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr)
	{
	   return false
	}

	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr)
	{
	    return false
	}

	 if (str.indexOf(at,(lat+1))!=-1)
	 {
	    return false
	 }

	 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot)
	 {
	    return false
	 }
	 if (str.indexOf(dot,(lat+2))==-1)
	 {
	    return false
	 }
	 if (str.indexOf(" ")!=-1)
	 {
	    return false
	 }
		 return true					
}

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

function check_form()
{
	obj = fetch_object("name");
	message = "";
	if(obj.value == "")
	{
		message += alert_name;
	}

	obj = fetch_object("email");
	if(!echeck(obj.value))
	{
		message += alert_email;
	}

	obj = fetch_object("subject");
	if(obj.value == "")
	{
		message += alert_subject;
	}

	obj = fetch_object("country");
	if(obj.value == "")
	{
		message += alert_country;
	}

	obj = fetch_object("comment");
	if(obj.value == "")
	{
		message += alert_comment;
	}
	if(message != "")
	{
		alert(message);
		return false;
	}
	return true;
}

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

function update_visitors()
{
	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null)
	{
		return false;
	}
	var url="update.html";
	xmlHttp.onreadystatechange=stateChanged;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
	setTimeout("update_visitors();", 120000);
}

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

function stateChanged()
{
	if (xmlHttp.readyState==4)
	{
		response=xmlHttp.responseText;
		obj = fetch_object("counter");
		obj.innerHTML = response;
	}
}

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

function GetXmlHttpObject()
{
	var xmlHttp=null;
	try
	{
		xmlHttp=new XMLHttpRequest();
	}
	catch (e)
	{
		try
		{
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e)
		{
			xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
	}
	return xmlHttp;
}

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

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;
	}
}
