var baseurl="http://www.novensys.com/";
var lasts=0;
var filecount=1;

function CreateBookmarkLink(title,url) {
	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 expandmenu(id) {
	var submenu=document.getElementById('submenu_'+id);
	if (!submenu) return;
	if (submenu.style.display!="none") {
		submenu.style.display="none"; 
		document.getElementById('menu_'+id).className="menuitem-plus";
	} else {
		submenu.style.display="block";
		document.getElementById('menu_'+id).className="menuitem-minus";
	}
}

function enterinput(e,s) {
	if (e.value==s) e.value="";
}

function leaveinput(e,s) {
	if (e.value=="") e.value=s;
}

function solgen(v) {
	//alert(v);
	document.getElementById('ind_'+lasts).style.display="none";
	document.getElementById('ind_'+v).style.display="block";
	lasts=v;
	
}

function switchlang(l) {
	if (l=="ro") {
		document.getElementById('tablang-ro').className="tab-active";
		document.getElementById('panel-ro').style.display="block";
		document.getElementById('tablang-en').className="tab-inactive";
		document.getElementById('panel-en').style.display="none";
	} else
	if (l=="en") {
		document.getElementById('tablang-en').className="tab-active";
		document.getElementById('panel-en').style.display="block";
		document.getElementById('tablang-ro').className="tab-inactive";		
		document.getElementById('panel-ro').style.display="none";		
	}
}

function switchtree(id) {
	
	
	
	if (document.getElementById('tree_'+id)) {
		var growDiv = new Fx.Style($('tree_'+id), 'width', {duration: 1000});
		
		if (document.getElementById('tree_'+id).style.display=="block") {
			document.getElementById('tree_'+id).style.display="none";
			document.getElementById('expand_'+id).className="inline expand";
		} else {
			document.getElementById('tree_'+id).style.display="block";			
			document.getElementById('expand_'+id).className="inline contract";
			growDiv.start(200);
			
		}
		
		
	}
	
	
}

window.addEvent('domready', function(){
/*
	tinyMCE.init({
		theme : "simple",
		mode : "textareas",
		elements : "cv-ext"
	});
*/
	if (document.getElementById('pagina')) {
		var pagini = Math.ceil($$('#canale .canal').length / 2);
		$('pagina').style.width=(pagini*15)+'px';
		var next = $('next');
		var prev = $('prev');
	
		var page_width; // = 420;
		if (window.ie6) page_width=425; else page_width=425;
		var directie = "inainte";
		var pagina = 0;
		var offset = 0;
	
		$('canale').setStyles({
			'width': page_width * pagini + offset /** 2*/ + 'px',
			'padding-left': offset + 'px'
		});
	
		var tv = new Fx.Scroll('ecran', {duration: 450, transition: Fx.Transitions.Sine.easeOut});
	
		tv.addEvent('onStart', function(e){
				if(directie == "inainte"){
					pagina < pagini ? pagina++ : pagina = 1;
				}
				if(directie == "inapoi"){
					pagina > 1 ? pagina-- : pagina = 1;
				}
				//$('paginatie').className="pag"+pagina;
				$('paginatie').style.left = pagina * 15  - 15 + "px";
		});
	
		tv.scrollTo(offset, 0);
		$('paginatie').className="pag1";
	
		prev.addEvent('click', function(e){
			var e = new Event(e).stop();
			directie = "inapoi";
			pagina > 1 ? tv.scrollTo((pagina-2) * page_width + offset, 0) : tv.scrollTo(offset, 0);
		});
	
		next.addEvent('click', function(e){
			var e = new Event(e).stop();
			directie = "inainte";
			pagina < pagini ? tv.scrollTo(pagina * page_width + offset, 0) : tv.scrollTo(offset, 0);
		});
	}	

	/* Accordion */
	var accordion = new Accordion('a.atStart', 'ul.leftsubmenu', {
		opacity: false,
		display: default_accordion_id,
		onActive: function(toggler, element){
			toggler.className='menuitem-minus';
		},
		
		onBackground: function(toggler, element){
			toggler.className='menuitem-plus';
		}
	}, $('navigation'));

	if (document.getElementById('menu_10')) {
		document.getElementById('menu_10').onmouseover=function(){ accordion.display(0); };
		document.getElementById('menu_11').onmouseover=function(){ accordion.display(1); };
		document.getElementById('menu_0').onmouseover=function(){ accordion.display(2); };
		document.getElementById('menu_1').onmouseover=function(){ accordion.display(3); };
		document.getElementById('menu_2').onmouseover=function(){ accordion.display(4); };
		document.getElementById('menu_3').onmouseover=function(){ accordion.display(5); }; 
		document.getElementById('menu_4').onmouseover=function(){ accordion.display(6); };
	} else	
	if (document.getElementById('menu_1')) {
		document.getElementById('menu_0').onmouseover=function(){ accordion.display(0); };
		document.getElementById('menu_1').onmouseover=function(){ accordion.display(1); };
		document.getElementById('menu_2').onmouseover=function(){ accordion.display(2); };
		document.getElementById('menu_3').onmouseover=function(){ accordion.display(3); }; 
		document.getElementById('menu_4').onmouseover=function(){ accordion.display(4); };
	}
	
	/* sIFR replacement calls. Please see documentation for more information. */
	if(typeof sIFR == "function"){
		sIFR.replaceElement(named({sSelector:"h1", sFlashSrc:baseurl+"sifr.swf", sColor:"#018DE9", sLinkColor:"#000000", sHoverColor:"#CCCCCC", sWmode: "transparent", sFlashVars:"textalign=left&offsetTop=0"}));
		sIFR.replaceElement(named({sSelector:"h2", sFlashSrc:baseurl+"sifr.swf", sColor:"#018DE9", sLinkColor:"#000000", sHoverColor:"#CCCCCC", sWmode: "transparent", sFlashVars:"textalign=left&offsetTop=0"}));
		sIFR.replaceElement(named({sSelector:"h3", sFlashSrc:baseurl+"sifr.swf", sColor:"#777F87", sLinkColor:"#000000", sHoverColor:"#CCCCCC", sWmode: "transparent", sFlashVars:"textalign=left&offsetTop=0"}));
		sIFR.replaceElement(named({sSelector:"span.subtitle", sFlashSrc:baseurl+"sifr.swf", sColor:"#018DE9", sLinkColor:"#000000", sHoverColor:"#CCCCCC", sWmode: "transparent", sFlashVars:"textalign=left&offsetTop=0"}));
		sIFR.replaceElement(named({sSelector:"em", sFlashSrc:baseurl+"sifr.swf", sColor:"#018DE9", sLinkColor:"#000000", sHoverColor:"#CCCCCC", sWmode: "transparent", sFlashVars:"textalign=left&offsetTop=0"}));
		//sIFR.replaceElement(named({sSelector:"#menu li a", sFlashSrc:baseurl+"sifr.swf", sColor:"#018DE9", sLinkColor:"#000000", sHoverColor:"#CCCCCC", sWmode: "transparent", sFlashVars:"textalign=left&offsetTop=0"}));
	};

});

function delete_fileinput(id) {
	var element = document.getElementById("filecontainer_"+id);
	var marginChange = new Fx.Style("filecontainer_"+id, 'margin-left', {duration:400, onComplete:function() {element.parentNode.removeChild(element);}});
	marginChange.start(0, -800);
}

function delete_file(id) {
	document.getElementById('deleted-files').innerHTML+='<input type="hidden" name="deleted[]" value="'+id+'" />';	
	var element=document.getElementById('resursa_'+id);
	var marginChange = new Fx.Style('resursa_'+id, 'margin-left', {duration:400, onComplete:function() {element.parentNode.removeChild(element);}});
	marginChange.start(0, -500);
}

function toggle_sendform() {
	var el=document.getElementById("trimite-produs");
	var marginChange = new Fx.Style('trimite-produs', 'margin-top', {duration:400});
	
	if (el.style.marginTop=='-10px') {
		marginChange.start(-10, -131);	
	} else {
		marginChange.start(-131, -10);	
	}
}

function sendtofriend() {
	toggle_sendform();
	document.getElementById('send-button').href=document.getElementById('baseurl').value+document.getElementById('send_nume1').value+'/'+document.getElementById('send_nume2').value+'/'+document.getElementById('send_email').value+'/';
	//document.getElementById('xxx').innerHTML=document.getElementById('send-button').href;
}

function newfile(id) {
	var filearray=document.getElementById('file_'+id).value.split("\\");
	if (filearray.length==1) filearray=document.getElementById('file_'+id).value.split("/");
	var filename=filearray[filearray.length-1].split(".");
	var fileext=filename[filename.length-1];
	filename.splice(filename.length-1,1);
	filename=filename.join(".");
	document.getElementById('filename_'+id).value=filename.replace(/_/g," ");
	document.getElementById('filename_'+id).className="text2 activated";

	document.getElementById('filedelete_'+id).style.display="inline";

	if (id==filecount) {
		filecount++;
		var newspan = document.createElement('span');
		newspan.setAttribute('id','filecontainer_'+filecount);
		newspan.className="block";
		var html='<input name="filename_'+filecount+'" id="filename_'+filecount+'" class="text2 deactivated" type="text" value="Titlu document" /> <input type="file" class="fileinput" name="file_'+filecount+'" size="40" id="file_'+filecount+'" onchange="newfile('+filecount+');"/> <a href="#delete" onclick="delete_fileinput('+filecount+')" id="filedelete_'+filecount+'" class="delete-file">&nbsp;</a>';
		newspan.innerHTML=html;
		document.getElementById('filepool').appendChild(newspan);
	}
}

function rate_article(value) {
	$('current_rating').style.width=(20*value)+'%';
	$('rating_input').value=value;
	$('rating_ajax').value="1";
	$('rating_ajax_2').value="1";
	$('additional_comments').style.display="block";
	$('rate_form').send({onComplete: function(r) {
		//alert(r);
		$('comment_id').value=r;
		$('rate_form').style.display="none";
		$('rate_thankyou').style.display="block";
	}});
}

function vote_form() {
	$('eroare_submit').style.display="none";
	$('additional_comments').send({onComplete: function(r) {
		if (r=="ok") {
			$('additional_comments').style.display="none";
			$('rate_thankyou').style.display="none";
			$('comment_thankyou').style.display="block";
		} else {
			$('eroare_submit_field').innerHTML=r;
			$('eroare_submit').style.display="block";

		}
	}});
	return false;
}