var HomeMagazineType=1;
var WWW = 'http://www.vipmagazin.md/';
//var WWW = 'http://localhost/vipmagazin.md/site/';

function CommentListingPage (Page)
{
	var CommentCount = GetIt ('CommentsCount').value;
	var CommentsPageLimit = GetIt ('CommentsPageLimit').value;
	var PagesCount = Math.ceil(CommentCount/CommentsPageLimit);
	
	for (i=1; i<=CommentCount; i++)
	{
		ShowState = (i>(Page-1)*CommentsPageLimit && i<=Page*CommentsPageLimit) ? 'block' : 'none';
		GetIt('CommentMessage'+i).style.display = ShowState;
	}
	for (i=1; i<=PagesCount; i++)
	{
		ShowState = (i==Page) ? 'ListingBoxLinkSelected' : 'ListingBoxLink';
		GetIt('CommentPage'+i).className = ShowState;
	}
}
function TopEditorial (id)
{
	for (i=1; i<=6; i++)
	{
		if (GetIt('editorial'+i)) GetIt('editorial'+i).style.display = (id==i) ? (GetIt('editorial'+i).style.display=='block'?'none':'block') : 'none';
	}
}
function HomeTopBlockOverAction (id, MinHeight, MaxHeight)
{
	for (i=0; i<=2; i++)
	{
		GetIt('TopVip'+i).style.height = ''+(i==id?MaxHeight:MinHeight)+'px';
		GetIt('TopVip'+i).style.overflow = 'hidden';
	}
}
function DoUpload ()
{
	var msg = '';
	if (IsEmpty(GetIt('Section'+GetIt('Section').value).value)) msg += '\"Categoria/Subcategoria\" nu este selectata\n';
	if (IsEmpty(GetIt('title').value)) msg += '\"Titlu\" lipseste\n';
	if (IsEmpty(GetIt('author').value)) msg += '\"Autor\" lipseste\n';
	//if (IsEmpty(GetIt('description').value)) msg += '\"Descriere\" lipseste\n';
	if (IsEmpty(GetIt('code').value)) msg += '\"Cod\" lipseste\n';
	if (IsEmpty(GetIt('ufile').value)) msg += '\"File\" lipseste\n';
	
	if (!IsEmpty(msg)) alert (msg);
	else GetIt('UploadForm').submit();
}
function IsEmpty(val)
{
	var a = '';
	for (i=0; i<val.length; i++) 
	{
		if (val[i]!=' ') a += val[i];
	}
	return a=='' ? 1 : 0;
}
function UploadSectionSelect(val)
{
	if (val != '') 
	{
		aSection = val=='Video' ? 'Video' : 'Foto';
		pSection = val=='Foto' ? 'Video' : 'Foto';
		aState = 'inline';
		pState = 'none';
	}
	else 
	{
		aState = 'none';
		pState = 'none';
	}
	
	GetIt('Section'+aSection).style.display = aState;
	GetIt('Section'+pSection).style.display = pState;

}
function VideoPlayer (width, height, video, image, id, title)
{
	var p = new SWFObject(WWW+'static/flash/Player.swf','mpl', width, height,'9');
	p.addParam ('allowfullscreen', 'true');
	p.addParam ('allowscriptaccess', 'always');
	p.addParam ('wmode', 'opaque');
	p.addVariable ('file', video);
	p.addVariable ('image', image);
	//p.addVariable ('playlistfile', ''.$_CONFIG['www'].'video/playlist/event.xml');
	//p.addVariable('playlist','bottom');
	p.addVariable('skin', WWW+'static/flash/PlayerSkin.swf');
	p.write('player'+id);
}
function PopupFlashMagazine (link)
{
	var FlashContent = '<html>';
		FlashContent += '<head>';
			FlashContent += '<title>VIP Magazin</title>';
		FlashContent += '</head>';
		FlashContent += '<body style="margin:0; padding:0; background:url('+WWW+'static/images/loader.gif) 50% 50% no-repeat;">';
			FlashContent += '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="1024" height="680" id="VipMagazin" align="middle">';
			FlashContent += '<param name="allowScriptAccess" value="sameDomain" />';
			FlashContent += '<param name="allowFullScreen" value="false" />';
			FlashContent += '<param name="movie" value="'+link+'" /><param name="quality" value="high" /><param name="wmode" value="transparent" />';
			FlashContent += '<embed src="'+link+'" quality="high" wmode="transparent" width="1024" height="680" name="VipMagazin" align="middle" allowScriptAccess="sameDomain" allowFullScreen="false" type="application/x-shockwave-flash" pluginspage="http://www.adobe.com/go/getflashplayer" />';
			FlashContent += '</object>';
		FlashContent += '</body>';
	FlashContent += '</html>';

	var win = window.open("","_blank", "toolbar=no,width=1024,height=680,directories=no,menubar=no,scrollbars=no,resizable=no");
	win.document.write(FlashContent);
	win.focus();
}
function Rating (State, Value, Target)
{
	var step = 26;
	
	if (State=='over') GetIt ('Rating').style.backgroundPosition = (-(10-Value)*step)+'px 0px';
	else if (State=='out') GetIt ('Rating').style.backgroundPosition = (-(10-Value)*step)+'px 0px';
	else if (State=='click') DoRequest ('RatingVote', Value, Target);
}
function SetPoll (value)
{
	document.forms['HomePoll']['PollAnswer'].value = value;
}
function PollStat ()
{
	for (i=0; i<20; i++)
	{
		if (GetIt('PollStat'+i))
		{
			GetIt('PollStat'+i).className = GetIt('PollStat'+i).className=='PollStat' ? 'nds' : 'PollStat';
			GetIt('PollAnswer'+i).style.fontWeight = GetIt('PollAnswer'+i).style.fontWeight=='bold' ? 'normal' : 'bold';
		}
	}
}
function ConvertRate (currency)
{
	var rate = new Array();
	var bs = parseFloat(GetIt('v'+currency).value);

	if (currency==0) mdl = bs;
	else mdl = bs * parseFloat(GetIt('hd_'+currency).value);

	for (var i=0; i<=5; i++)
	{
		rate[i] = Math.round(10000 * mdl / parseFloat(GetIt('hd_'+i).value)) / 10000;
		if (!isNaN(rate[i]) && currency != i) GetIt('v'+i).value = rate[i];
	}
}
function EscapeString (str)
{
	str = str.replace(/\n/g, escape("\n"));
	str = str.replace(/&/g, escape("&"));
	str = str.replace(/=/g, escape("="));
	
	return str;
}
function AddComment (id)
{
	var author = GetIt ('user').value;
	var message = GetIt ('message').value;
	var code = GetIt ('code').value;
	var option1 = 'id='+id+'&author='+EscapeString(author)+'&message='+EscapeString(message)+'&code='+EscapeString(code);
	DoRequest ('AddComment', option1);
}
function DoRequest (type, option1, option2)
{
	var URL = new GetURL(type, option1);
	var RequestURL = WWW+'AjaxRequest.php?';
	
	if (type=='Zodiac')
	{
		link = RequestURL+'&type='+type+'&id='+option1;
		URL.Get(link);
	}
	if (type=='PollVote')
	{
		link = RequestURL+'&type='+type+'&answer='+document.forms['HomePoll']['PollAnswer'].value;
		//alert (link);
		URL.Get(link);
	}
	else if (type=='PollVote2')
	{
		var GetOptions = '';
		for (i=1; i<=option2; i++)
		{
			if (GetIt('item'+i).checked) GetOptions += '&option_id'+i+'='+GetIt('itemVal'+i).value;
		}
		link = RequestURL+'&type='+type+'&id='+option1+GetOptions;
		//alert (link);
		//return;
		URL.Get(link);
	}
	else if (type=='HomeTopDataSet')
	{
		link = RequestURL+'&type='+type+'&page='+option2;
		URL.Get(link);
	}
	else if (type=='AddComment')
	{
		link = RequestURL+'&type='+type+'&'+option1;
		//alert (link);
		URL.Get(link);
	}
	else if (type=='RatingVote')
	{
		link = RequestURL+'&type='+type+'&value='+option1+'&id='+option2;
		//alert (link);
		URL.Get(link);
	}
	else if (type=='HomeMagazinSectionsDataSet')
	{
		link = RequestURL+'&type='+type+'&page='+option2+'&section='+option1;
		//alert(link);
		URL.Get(link);
	}
}
function SetRequestData (type, data, option)
{
	//alert (data);
	if (type=='Zodiac') GetIt ('SideBoxInfoZodiacContent').innerHTML = data;
	if (type=='PollVote') GetIt ('HomePollContent').innerHTML = data;
	if (type=='PollVote2') 
	{
		if (eval(data)) location.reload();
		//alert (data);
		//GetIt ('HomePollContent').innerHTML = data;
	}
	if (type=='HomeTopDataSet') GetIt ('HomeArticlesBox').innerHTML = data;
	if (type=='AddComment')
	{
		if (data == 'error1') alert ('Nu toate campurile marcate cu * au fost completate');
		else if (data == 'error2') 
		{
			GetIt ('CommentsImageCode').src = GetIt ('CommentsImageCodePath').value+'?'+ Math.random();
			alert ('Codul este gresit');			
		}
		else 
		{
			//alert (data);
			//GetIt ('CommentsList').innerHTML += data;
			GetIt('CommentsMessage').style.display = 'block';
			GetIt('CommentsMessage').style.width = GetIt('Comments').offsetWidth+'px';
			GetIt('CommentsMessage').style.height = GetIt('Comments').offsetHeight+'px';
			
			GetIt('CommentsMessage').innerHTML = '<div class="CloseButton" onClick="GetIt(\'CommentsMessage\').style.display=\'none\';">x</div><div class="PostMessage">Mesajul dvs este in curs de procesare</div>';
			GetIt ('message').value = '';
			GetIt ('code').value = '';
			GetIt ('CommentsImageCode').src = GetIt ('CommentsImageCodePath').value+'?'+ Math.random();
		}
	}
	if (type=='RatingVote' && data != '') GetIt ('RatingBox').innerHTML = data;
	if (type=='HomeMagazinSectionsDataSet') 
	{
		GetIt ('HomeMagazinBoxArticlesBoxContent').innerHTML = data;
		HomeMagazine (option);
	}
}
function GetURL (type, option)
{
	var xmlhttp, alerted;
	/*@cc_on @*/
	/*@if (@_jscript_version >= 5)
		try {
			xmlhttp=new ActiveXObject("Msxml2.XMLHTTP")
		} catch (e) {
			try {
				xmlhttp=new ActiveXObject("Microsoft.XMLHTTP")
			} catch (E) {
				alert("You must have Microsofts XML parsers available")
			}
		 }
	@else
		alert("You must have JScript version 5 or above.")
		xmlhttp=false
		alerted=true
	@end @*/

	if (!xmlhttp && !alerted) {
		try {
			xmlhttp = new XMLHttpRequest();
		} catch (e) {
			alert("You need a browser which supports an XMLHttpRequest Object.\nMozilla build 0.9.5 has this Object and IE5 and above, others may do, I don't know, any info jim@jibbering.com")
		}
	}
	function RSchange() {
		if (xmlhttp.readyState==4) {
			//alert(xmlhttp.responseText);
			SetRequestData (type, xmlhttp.responseText, option);
		}
	}
	this.Get = function (url){
		if (xmlhttp) { 
			xmlhttp.open("GET", url+'&rand='+ Math.random(), true);
			xmlhttp.onreadystatechange = RSchange;
			xmlhttp.send(null);
		}
	}
	this.Request = function (url){
		if (xmlhttp) { 
			xmlhttp.open("GET", url+'&rand='+ Math.random(), true);
			xmlhttp.send(null);
		}
	}
}
function CreateBookmarkLink()
{
	var title = document.title; 
	var url = window.location.href;
	
	if (window.sidebar)
	{	// Mozilla Firefox Bookmark
		window.sidebar.addPanel(title, url,"");
	}
	else if( window.external)
	{	// IE Favorite
		window.external.AddFavorite( url, title); 
	}
	else if (window.opera && window.print) 
	{	// Opera Hotlist
		return true;
	}
}
function HomeVideo (id, state)
{
	for (var i=1; i<=5; i++)
	{
		if (GetIt ('HomeVideoItemSelector'+i))
		{
			if (GetIt ('player'+i)) GetIt ('player'+i).style.display = (i==id) ? 'block' : 'none';
			if (GetIt ('list'+i)) GetIt ('list'+i).style.display = (i==id) ? 'block' : 'none';
			GetIt ('HomeVideoItemSelector'+i).className = (i==id) ? 'HomeVideoBoxBarItemSelector' : 'HomeVideoBoxBarItemSelector novisible';
			GetIt ('HomeVideoBoxItemLabel'+i).className = 'HomeVideoBoxBarItemLabel' + ' HomeVideoBoxBarItemLabelBorder'+i+id+state;
		}
	}
}
function SideBoxInfo (id)
{
	for (var i=1; i<=3; i++)
	{
		GetIt ('SideBoxInfoTab'+i).className = 'SideBoxInfoTab'+i + (i==id ? id : '0') + (i==id ? '0' : id);
		GetIt ('SideBoxInfoContent'+i).className = (i==id) ? 'SideBoxInfoContent'+i : 'hidden';
	}
	GetIt ('SideBoxInfoZodiacContent').innerHTML = '';
}
function HomeMagazineArticle (id)
{
	var type = HomeMagazineType;
	for (var i=1; i<=3; i++)
	{
		GetIt ('HomeMagazinBoxArticleSep'+i).className = (i==id) ? 'hidden' : 'HomeMagazinBoxArticleSep'+type;
		GetIt ('HomeMagazinBoxArticleImg'+i).className = (i==id) ? 'HomeMagazinBoxArticleImgPadding' : 'hidden';
		GetIt ('HomeMagazinBoxArticle'+i).className = 'HomeMagazinBoxArticle'+type;
	}
}
function HomeMagazine (id)
{
	HomeMagazineType = id;
	for (var i=1; i<=9; i++)	GetIt ('HomeMagazinBoxLabel'+i).className = (i==id) ? 'HomeMagazinBoxLabelSelected'+id : 'HomeMagazinBoxLabel'+i;
	GetIt ('HomeMagazinBoxData').className = 'HomeMagazinBoxData'+id;
	GetIt ('HomeMagazinBoxCornerTop').className = 'HomeMagazinBoxCornerTop'+id;
	GetIt ('HomeMagazinBoxCornerBottom').className = 'HomeMagazinBoxCornerBottom'+id;
//	GetIt ('HomeMagazinBoxPaging').className = 'HomeMagazinBoxPaging'+id;
		
	HomeMagazineArticle (1);
}
function HomeArticles (id)
{
	for (var i=1; i<=3; i++)
	{
		GetIt ('HomeArticlesBox'+i).className = (i==id) ? 'HomeArticlesBoxItemSelected' : 'HomeArticlesBoxItem'+i+id;
		GetIt ('HomeArticlesBoxImg'+i).className = (i==id) ? 'HomeArticlesBoxImg' : 'hidden';
		GetIt ('HomeArticlesBoxTitle'+i).className = (i==id) ? 'HomeArticlesBoxItemSelectedText' : 'HomeArticlesBoxItemText';
		GetIt ('HomeArticlesDescription'+i).className = (i==id) ? 'HomeArticlesBoxItemDescription' : 'hidden';
	}
}
function GetIt (id) { return document.getElementById (id); }
