var LastRequest = "";

//open section
//var AjaxMode = false; //global
/*
function OpenSection( Section, DivId, Params, onLoadScript)
{
	if(!AjaxMode)
	{
		return true;
	}
	if(Params == undefined)
	{
		Params = '';
	}
	
	//alert( "front.php?section="+unescape(Section)+"&"+Params);
	Sender = new AjaxSender("GET", "front.php?section="+unescape(Section)+"&lang="+Lang+"&"+Params);
	//set loading... picture
	document.getElementById(DivId).innerHTML = "<div align='center' valign='middle' class='Loading'><img src='images/loading.gif'></div>";
	Sender.Send(function()
	{
		if(Sender.Ajax.readyState == 4 && Sender.Ajax.status == 200)
		{
			var Response = Sender.Ajax.responseText;
			//alert(Response);
			document.getElementById(DivId).innerHTML = Response;
			if(onLoadScript != "")
			{
				//alert(onLoadScript);
				eval(onLoadScript);
			}
			LastRequest = "section="+Section;
			if(Params != "")
			{
				LastRequest += "&"+Params;
			}
			LastRequest = LastRequest.replace('&lang=arm', '');
			LastRequest = LastRequest.replace('&lang=eng', '');
			LastRequest = LastRequest.replace('&lang=rus', '');
			
		}
	});
	return false;
}
function SetLang(Lang)
{
	if(LastRequest != '')
	{
		var url = LastRequest + "&lang=" + Lang;
	}
	else
	{
		var url = "lang=" + Lang;
	}	 	

	document.location = "?"+url;
	return false;
}
function Init(QueryString)
{
	QueryString = QueryString.replace('&lang=arm', '');
	QueryString = QueryString.replace('&lang=eng', '');
	QueryString = QueryString.replace('&lang=rus', '');
	QueryString = QueryString.replace('lang=arm',  '');
	QueryString = QueryString.replace('lang=eng',  '');
	QueryString = QueryString.replace('lang=rus',  '');
	LastRequest = QueryString;
	
	
}
function Startup(command)
{
	switch(command)
	{
		case 'setup_calendar':
		{
			SetupCalendar('Date','cal_button');
			break;
		}
		case 'setup_calendar0':
		{
			SetupCalendar('Date','cal_button0');
			break;
		}
		case 'setup_calendar2':
		{
			SetupCalendar('StartDate','cal_button'); 
			SetupCalendar('EndDate','cal_button2');
			break;
		}
		case 'init_lytebox':
		{
			initLytebox();
			break;
		}
		case 'flow_player':
		{
			RunFlowPlayer();
			break;
		}
		
	}
}
function SetupCalendar(Field, Button)
{
	Calendar.setup({
		inputField    : 	Field,
		ifFormat       :    "%d.%m.%Y",
		showsTime      :    false,
		timeFormat     :    24,
		button         : 	Button,
		firstDay       :    1,
		weekNumbers    :    false,
		cache          :    true,
		singleClick    :    true,
		getDateToolTip :	false
	});
}
function SetupFlatCalendar(ContainerID)
{
	Calendar.setup
	(
			{
			flat : ContainerID, // ID of the parent element
			flatCallback : dateChanged // our callback function
			}
	);
}
function SelectEventDate(Calendar)
{
	//alert("calendar callback");
}
function SetLeftBlocks()
{
	document.getElementById("LeftBlock").innerHTML = '<div id="ArmNewsBlock">'+
		'</div>'+
		'<div id="ForignNewsBlock">'+		
		'</div>';
}
function ShowHideFederation(DivID)
{
	var	objImageIDOff = new Image()	;
	objImageIDOff.src = "images/minus.gif";
	var objImageIDOn = new Image();
	objImageIDOn.src = "images/plus.gif";
	if (document.getElementById(DivID).style.display == 'none')
	{
		document.getElementById(DivID).style.display="block";
		document.getElementById(DivID).style.visibility="visible";		
		document.getElementById('Icon_'+DivID).src=objImageIDOff.src;		
	}
	else
	{
		document.getElementById(DivID).style.display="none";
		document.getElementById(DivID).style.visibility="hidden";
		document.getElementById('Icon_'+DivID).src=objImageIDOn.src;		
	}
}
function ShowHideEventDetail(DivID)
{
	if (document.getElementById(DivID).style.display == 'none')
	{
		document.getElementById(DivID).style.display="block";
		document.getElementById(DivID).style.visibility="visible";		
		
	}
	else
	{
		document.getElementById(DivID).style.display="none";
		document.getElementById(DivID).style.visibility="hidden";
				
	}
}
function CalendarSearch()
{
	//alert("SDSd");
	ParamStr = "SearchCalendar=1";
	form = document.CalendarSearchForm;
	if(form.SearchText.value != "")
	{
		ParamStr += "&SearchText=" + form.SearchText.value;
	}
	//Date
	if(form.StartDate.value != "")
	{
		ParamStr += "&StartDate=" + form.StartDate.value;
	}
	if(form.EndDate.value != "")
	{
		ParamStr += "&EndDate=" + form.EndDate.value;
	}
	
	if(form.FederationID.options[form.FederationID.options.selectedIndex].value != 0)
	{
		ParamStr += "&Federation=" + form.FederationID.options[form.FederationID.options.selectedIndex].value;
	}
	else if(form.SportTypeID.options[form.SportTypeID.options.selectedIndex].value != 0)
	{
		ParamStr += "&SportType=" +form.SportTypeID.options[form.SportTypeID.options.selectedIndex].value;
	}
	
	
	if(AjaxMode)
	{
		OpenSection("calendar", "RightContentBlock", ParamStr, "SetupCalendar('StartDate','cal_button'); SetupCalendar('EndDate','cal_button2');");
	}
	else
	{
		document.location = "?section=calendar&"+ParamStr+"&startup=setup_calendar";
	}
	//SetupCalendar('StartDate','cal_button');
	///SetupCalendar('EndDate','cal_button2');
	//StartCal();
	return true;
}
function NewsSearch()
{
	//alert("SDSd");
	ParamStr = "SearchCalendar=1";
	form = document.NewsSearchForm;
	if(form.Type.value == "arm")
	{
		ParamStr += "&events_type=arm";
		
	}
	else
	{
		ParamStr += "&events_type=forign";
		
	}
	BlockName = "LeftBlock";
	if(form.SearchText.value != "")
	{
		ParamStr += "&SearchText=" + form.SearchText.value;
	}
	
	if(form.SportTypeID.options[form.SportTypeID.options.selectedIndex].value != 0)
	{
		ParamStr += "&SportType=" +form.SportTypeID.options[form.SportTypeID.options.selectedIndex].value;
	}
	
	if(form.Date.value != "")
	{
		ParamStr += "&Date=" + form.Date.value;
	}	
	
	if(AjaxMode)
	{
		OpenSection("news", BlockName, ParamStr, 'SetupCalendar(\'Date\',\'cal_button0\')');
	}
	else
	{
		document.location="?section=news&"+ParamStr+"&startup=setup_calendar0";
	}
	
	return true;
}
function VideosSearch()
{
	//alert("SDSd");
	//ParamStr = "SearchCalendar=1";
	ParamStr = "";
	form = document.VideosSearchForm;
	
	BlockName = "LeftBlock";
	if(form.SearchText.value != "")
	{
		ParamStr += "&SearchText=" + form.SearchText.value;
	}
	if(form.SportTypeID.options[form.SportTypeID.options.selectedIndex].value != 0)
	{
		ParamStr += "&SportTypeID=" +form.SportTypeID.options[form.SportTypeID.options.selectedIndex].value;
	}
	/*
	if(form.StartDate.value != "")
	{
		ParamStr += "&StartDate=" + form.StartDate.value;
	}	
	
	if(AjaxMode)
	{
		OpenSection("Videos", "RightContentBlock", ParamStr);
	}
	else
	{
		document.location = "?section=Videos&"+ParamStr;
	}
	
	return true;
}
function ReferenceSearch()
{
	ParamStr = "SearchReference";
	form = document.ReferenceSearchForm;
	if(form.Keyword.value != "")
	{
		ParamStr += "&Keyword=" + form.Keyword.value;
	}
	if(form.SportTypeID.options[form.SportTypeID.options.selectedIndex].value != 0)
	{
		ParamStr += "&SportTypeID=" +form.SportTypeID.options[form.SportTypeID.options.selectedIndex].value;
	}
	if(form.CategoryID.options[form.CategoryID.options.selectedIndex].value != 0)
	{
		ParamStr += "&CategoryID=" + form.CategoryID.options[form.CategoryID.options.selectedIndex].value;
	}
	//alert(ParamStr);
	//ParamStr = ParamStr.substring(1, ParamStr.length);
	//alert(ParamStr);
	if(AjaxMode)
	{
		OpenSection("reference", "RightContentBlock", ParamStr);
	}
	else
	{
		document.location = "?section=reference&"+ParamStr;	
	}
	return true;

}
function SendMail(Msg1, Msg2, Msg3)
{
	
	form = document.EmailForm;
	/*
	if(!frmvalidator.form_submit_handler())
	{
		return false;
	}
	
	
	if(form.FullName.value.length == 0)
	{
		alert(Msg1);
		return false;
	}
	if(form.Email.value.length == 0)
	{
		alert(Msg2);
		return false;
	}
	if(form.Message.value.length ==0)
	{
		alert(Msg3);
		return false;
	}
	
	var	ParamStr = "action=send_msg&Name="+form.FullName.value+"&Email="+form.Email.value+"&Message="+form.Message.value;
	if(AjaxMode)
	{
		OpenSection("contacts", "LeftBlock", ParamStr);
	}
	else
	{
		document.location = "?section=contacts&"+ParamStr;
	}
	return true;
}
function SetImage(PhotoID)
{
	var Photo = new Image();
	var OldImage = document.getElementById("photo").src;
	while(document.getElementById("photo").src == OldImage)
	{
		Photo.src = document.getElementById(PhotoID).getAttribute('original');	
		document.getElementById("photo").src = Photo.src;
	}
	//document.getElementById("photo").src = Photo.src;
}
function MenuHover(DivId)
{
	
	document.getElementById(DivId).style.backgroundColor = "#26699E";
}
function MenuOut(DivId)
{	
	document.getElementById(DivId).style.backgroundColor = "";
}
var frmvalidator;
function InitEmailValidator()
{
	
	frmvalidator = new Validator("EmailForm");
	frmvalidator.addValidation("FullName", "alpha", "{L_VALID_NAME}");
	frmvalidator.addValidation("FullName", "req");

	
	frmvalidator.addValidation("Email", "email");
	frmvalidator.addValidation("Email", "req");	
	
	
	frmvalidator.addValidation("Message", "req");
	

}
*/
function RunFlowPlayer()
{
	
	flowplayer("player", "js/flowplayer/flowplayer-3.1.1.swf", {
			clip:{
				autoPlay: false,			
				autoBuffering: true
				
			}
		}	    	
	);
}
function Init(QueryString)
{
    QueryString = QueryString.replace('&lang=arm', '');
    QueryString = QueryString.replace('&lang=eng', '');
    QueryString = QueryString.replace('&lang=rus', '');
    QueryString = QueryString.replace('lang=arm',  '');
    QueryString = QueryString.replace('lang=eng',  '');
    QueryString = QueryString.replace('lang=rus',  '');
    LastRequest = QueryString;
    
    
}
