var sSubmittedForm = '';
function disableMultipleSubmit( sForm ){

	if ( '' == sSubmittedForm ){
        sSubmittedForm = sForm;return true;
    }
    return false;
}

function jump(){
    sSelectedMonth = document.calendar.calendar_month.options[ document.calendar.calendar_month.selectedIndex ].value;
    sSelectedYear = document.calendar.calendar_year.options[document.calendar.calendar_year.selectedIndex].value
    window.location = sRoot+ 'arhiva/stiri/?c=m&v=' + sSelectedYear + '-' + sSelectedMonth;
}



function bookmarksite(title, url) {
		if (document.all)
			window.external.AddFavorite(url, title);
		else if (window.sidebar)
			window.sidebar.addPanel(title, url, "");
	}

function createTooltip( sId, sTitle, sText, sStyle ) {

 			new Tip( sId , sText , {
				title: sTitle,
				style: sStyle,
				fixed: true,
				//hideOn: { element: 'tip', event: 'mouseout' },
				hideOn: false, // disable the normal hide event, because we only want to use the hideAfter option
				hideAfter: 0.2,
				hideOthers : true,
				hook: { target: 'bottomRight', tip: 'topLeft' }
			});


}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

function parseTT( sTableId, sTabContainer ){

	if ( !/tt_table/i.test( sTableId ) ) return;
	oTableElement = document.getElementById( sTableId );
	if ( null == oTableElement ) return;
	if ( null == sTabContainer ) sTabContainer = "li";
	oTTable = new TTable( oTableElement, sTabContainer );
	return;

}

function TTable( oElement, sTabContainer ){

    this.sId = oElement.id.substr( 9 );
    aTds = oElement.getElementsByTagName(sTabContainer);
    this.aTabs= new Array();
	for (var i = 0; i < aTds.length; i++) {
	    if ( /tt_tab/i.test( aTds[i].id ) ){
	        this.aTabs.push( new TTab( aTds[i] ) );
	    }
	}

	var _o = this;
	for (var i = 0; i < this.aTabs.length; i++) {
        this.aTabs[i].oElement.onclick = function() {
            _o.show(this); return false;
		}
	}

}

TTable.prototype.show = function( oTrigger ) {

    oTab = null;
    iTabIndex = null;

    for (var i = 0; i < this.aTabs.length; i++) {
        if ( oTrigger.id == this.aTabs[i].oElement.id ){
            oTab = this.aTabs[i];
            iTabIndex = i;
            break;
        }
    }

    if ( oTab==null ) return false;

	for (var i = 0; i < this.aTabs.length; i++) {
		if ( 0 == i ){
			this.aTabs[i].oElement.className='first';
		}else if ( i == ( this.aTabs.length - 1 ) ){
			this.aTabs[i].oElement.className='last';
		}else{
			this.aTabs[i].oElement.className='';
		}
	}
    this.aTabs[iTabIndex].oElement.className = ( ''==this.aTabs[iTabIndex].oElement.className ? 'curent' : this.aTabs[iTabIndex].oElement.className + ' curent');

    this.hideAll();
    document.getElementById( 'tt_content_'+this.aTabs[iTabIndex].sId ).style.display="block";

}

TTable.prototype.hideAll = function() {
    for (var i = 0; i < this.aTabs.length; i++) {
        document.getElementById( 'tt_content_'+this.aTabs[i].sId ).style.display="none";
    }
}

function TTab( oElement ){
    this.sId = oElement.id.substr( 7 );
    this.oElement   = oElement;
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

function swPollView( iPollId, _embed ){

	_embed  = ( _embed ? true : false );
	_prefix = ( _embed ? "embed_polls" : "polls");

    oFCont = document.getElementById( _prefix + iPollId + "_form" );
    if ( oFCont == null ) return;
    oVCont = document.getElementById( _prefix + iPollId + "_view" );

    if ( 'block'==oFCont.style.display){
        oFCont.style.display = 'none';
        oVCont.style.display = 'block';
        if ( ''==oVCont.innerHTML ){ xajax_pollfetch( iPollId, _embed ) };
    }else{
        oFCont.style.display = 'block';
        oVCont.style.display = 'none';
    }

}

function pollvote( iPollId, _embed ){

	_embed  = ( _embed ? true : false );
	_prefix = ( _embed ? "embed_polls" : "polls");

    oForm = document.getElementsByName( _prefix + iPollId )[0];
    iOptionId = getpolloption( oForm );
    if ( iOptionId==null ) return;
    xajax_pollvote( iPollId, iOptionId, _embed );


}

function getpolloption( oForm ){
    for(var i=0; i<oForm.poll_option.length; i++){
        if ( oForm.poll_option[i].checked ) return oForm.poll_option[i].value;
    }
    return null;
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////


function FPGallery( sId ){
	this.sId = sId;
	this.aItems = new Array();
	this.oCurrent = null;
}

FPGallery.prototype.add = function( sType, sId, sContent, sDescription ){
	this.aItems.push( new FPGalleryItem( sType, sId, sContent, sDescription ) );
}

FPGallery.prototype.load = function( sId ){

	if ( this.oCurrent!=null && this.oCurrent.sId==sId ) return;

	document.getElementById( this.sId + '_player' ).style.display = 'none';
	for (var i = 0; i < this.aItems.length; i++){
		if ( 'image'== this.aItems[i].sType ) document.getElementById( 'c_' + this.aItems[i].sId ).style.display = 'none';
		document.getElementById( 'i_' + this.aItems[i].sId ).className = document.getElementById( 'i_' + this.aItems[i].sId ).className.replace("selected", "");
		if ( sId==this.aItems[i].sId ) this.oCurrent = this.aItems[i];
	}

	document.getElementById( 'i_' + this.oCurrent.sId ).className+=" selected";
	if ( 'video'==this.oCurrent.sType ){
		document.getElementById( this.sId + '_player' ).innerHTML = this.oCurrent.sContent;
		document.getElementById( this.sId + '_player' ).style.display = 'inline';
	}else if ( 'image'==this.oCurrent.sType ){
		oContainer = document.getElementById( 'c_' + this.oCurrent.sId );
		oImage = oContainer.getElementsByTagName('img')[0];
		oImage.src = this.oCurrent.sContent;
		oContainer.style.display = 'inline';
	}

	document.getElementById( this.sId + '_description' ).innerHTML = this.oCurrent.sDescription;

}

function FPGalleryItem( sType, sId, sContent, sDescription ){
	this.sType = sType;
	this.sId = sId;
    this.sContent = sContent;
    this.sDescription = sDescription;
}

function MidnightCaller(){
	this.aCalls = new Array();
}

MidnightCaller.prototype.add = function ( sFunc, sArgs ){
	this.aCalls.push( new Array( sFunc, sArgs ) );
}

MidnightCaller.prototype.callall = function (){
	for (var i = 0; i < this.aCalls.length; i++){
		_aCall = this.aCalls[i];
		eval( _aCall[0] + "(" + _aCall[1] + ")" );
	}
}

var oMidnightMan = new MidnightCaller();



function rank_over( iRank, iId ){
	for(i=1;i<=iRank;i++){
		document.images['star' + iId + '_' + i].src = _preload.src;
	}
}

function rank_out( iCurrentRank, iId ){
	for(i=1;i<=iMaxRank;i++){
		document.images['star' + iId + '_' + i].src = ( i<=iCurrentRank ? sStarOn : sStarOff );
	}
}

function rank_it( sModule, iId, iRank ){
	//alert ( sModule );
	//document.getElementById('stars'+iId).innerHTML = "<img src='" + sLoadingImage + "'>";
	xajax_rank( sModule, iId, iRank );
}

//imc

function imc_calcul(masa, inaltime) {

    imcIndex=masa/eval(inaltime*inaltime);
    return imcIndex;
}

function imc_curatare(form) {

    form.b_inaltime.value = "";
    form.b_masa.value = "";
    form.b_imc.value = "";
    form.b_semnificatie.value = "";

}

function imc_validare(form) {

    if(form.b_masa.value==null||form.b_masa.value.length==0 || form.b_inaltime.value==null||form.b_inaltime.value.length==0) {
        alert("\nCompletati formularul");
        return false;
    }

    else if(parseFloat(form.b_inaltime.value) <= 0||parseFloat(form.b_inaltime.value) >= 500||parseFloat(form.b_masa.value) <= 0||parseFloat(form.b_masa.value) >= 500) {
       alert("\nValorile introduse sunt gresite");
       imc_curatare(form);
       return false;
    }
    return true;

}

function imc_interpretare(form) {

    if(imc_validare(form)) {

       imcIndex=Math.round(imc_calcul(form.b_masa.value, form.b_inaltime.value/100)*100)/100;
       form.b_imc.value=imcIndex;

       if(imcIndex >40.00) {
          descriere="Obezitate morbida";
       }
       else if(imcIndex >35.00 && imcIndex <=39.99) {
          descriere="Obezitate (gradul II)";
       }
       else if(imcIndex >=30.00 && imcIndex <=34.99) {
          descriere="Obezitate (gradul I)";
       }
       else if(imcIndex >=25.00 && imcIndex <=29.99) {
          descriere="Supraponderal";
       }
       else if(imcIndex >=18.50 && imcIndex <=24.99) {
          descriere="Greutate normala";
       }
       else if(imcIndex <18.49) {
          descriere="Subponderal";
       }

       form.b_semnificatie.value=descriere;
	   document.getElementById('rez').style.display = 'block';
       document.getElementById('imc').innerHTML = 'IMC: '+imcIndex;
       document.getElementById('semnificatie').innerHTML = 'Semnificatie: '+descriere;
    }


    return;
}

function startArticoleBox(){

	$(document).ready(function() {
	    $('#carousel-articole').jcarousel({
			auto : 5,
			scroll : 2,
			wrap: 'last'
	    });
	});

}

function FPRotator( sId, sSelectedClass, iDelay ){
	this.sId = sId;
	this.aItems = new Array();
	this.iCurrent = 0;
	this.isRunning = false;
	this.sSelectedClass = sSelectedClass;
	this.iDelay = iDelay;
}

FPRotator.prototype.add = function( sId ){
	this.aItems.push( sId );
}

FPRotator.prototype.start = function(){

	this.isRunning = true;
	var _owner = this;
	this.timeout=setTimeout( function(){rotate(_owner)} , _owner.iDelay);

}

FPRotator.prototype.stop = function(){

	clearTimeout( this.timeout );
	this.isRunning = false;

}

FPRotator.prototype.show = function( iCurrent ){

	if ( iCurrent<0 || ( iCurrent>=this.aItems.length) ) iCurrent = 0;

	_item = document.getElementById( this.aItems[this.iCurrent] );
	if ( null != _item ){
		_item.style.display = 'none';
	}
	_item_index = document.getElementById( this.aItems[this.iCurrent] + '_index' );
	if ( null != _item_index ){
		_item_index.className='';
	}

	_item = document.getElementById( this.aItems[iCurrent ] );
	if ( null != _item ){
		_item.style.display = 'block';
	}
	_item_index = document.getElementById( this.aItems[iCurrent] + '_index' );
	if ( null != _item_index ){
		_item_index.className=this.sSelectedClass;
	}
	this.iCurrent = iCurrent;

}

FPRotator.prototype.go = function( iCurrent ){

	this.show( iCurrent );
	this.stop();

}

function rotate( _owner ){

	if ( !_owner.isRunning ) return;

	$iNewCurrent = _owner.iCurrent+1;
	if ( $iNewCurrent == _owner.aItems.length ) $iNewCurrent = 0;

	_owner.show( $iNewCurrent );

	clearTimeout( _owner.timeout );
	_owner.timeout=setTimeout( function(){rotate(_owner)} , _owner.iDelay );

}