function selectCheckBox( boxID )
{
 if( boxID != "" )   
 {
    $(boxID).checked = true;
    $("hSelCheckBox").value = "";
 }
}

//listItems manipulation scripts
function moveUp( id )
{
    dd = document.getElementById(id);    
	//dd is declared in each page this function is used as the target listbox
	for (var i=0;i<dd.options.length;i++)
	{
		if (dd.options[i].selected==true)
		{
			if (i>0)
			{
				aux=dd.options[i].value;
				dd.options[i].value=dd.options[i-1].value;
				dd.options[i-1].value=aux;
				aux=dd.options[i].text;
				dd.options[i].text=dd.options[i-1].text
				dd.options[i-1].text=aux;
				dd.selectedIndex=i-1;							
			}
		}
	}		
}
function moveDown( id )
{
    dd = document.getElementById(id );
	//dd is declared in each page this function is used as the target listbox
	for (var i=dd.options.length-1;i>=0;i--)
	{
		if (dd.options[i].selected==true)
		{
			if (i<dd.options.length-1)
			{
				aux=dd.options[i].value;
				dd.options[i].value=dd.options[i+1].value;
				dd.options[i+1].value=aux;
				aux=dd.options[i].text;
				dd.options[i].text=dd.options[i+1].text
				dd.options[i+1].text=aux;
				dd.selectedIndex++;
		
			}
		}
	}
}

function FCKValue(id)
{
    var temp = document.createElement('txBuffer');
    temp.value = FCKeditorAPI.GetInstance(id).GetXHTML();
    return temp;
}

function $() {
        
	if (arguments.length>1) {
		return false;
	}
	if (arguments.length<1) {
		return false;
	}

	var element = arguments[0];

    if (typeof element == 'string') {
        if (document.getElementById) 
        {
            try 
            {
                element = FCKValue(element);
            }
            catch(err)
            {
                element = document.getElementById(element);            
            }

        } else if (document.all) {
            element = document.all[element];
        }
    }
    
	
	return element;
}

//general function for removing items -> lists, with confirmation and checked items verification
function removeItems(elems, alertMessage, confirmMessage, action)
{
    var checked = false;
    var ckItems = elems;
    var itemsNo = ckItems.length;
 
    if (isNaN(itemsNo) && ckItems.checked)
    {
        checked = true;
    }
    else
    {
        var i = ckItems.length;
        for (var j = 0; j < i; j++)
        {
            if (ckItems[j].checked)
            {
                checked = true;
                break;
            }
        }
    }
    
    if (checked)
    {
        if (confirm(confirmMessage))
        {
       
            $("hAction").value = action;
            $("frmMain").submit();
        }
    }
    else
    {
        alert(alertMessage);
    }
}

//general function for switching tabs in Detail pages (admin) with Globalization
function switchTabs(newTab, JSSaveFunction)
{
    $("hPreviousSelectedTab").value = $("hSelectedTab").value;
    $("hSelectedTab").value = newTab;
    if ($("hHasChanged").value != "0")
    {
        if (confirm("Doriti sa salvati modificarile din tabul curent?"))
        {
            eval(JSSaveFunction);
        }
        else
        {
            $("hAction").value = "";
            $("frmMain").submit();
        }            
    }
    else
    {
        $("hAction").value = "";
        $("frmMain").submit();
    }
}

//records changes in the current Form
function FormChanged()
{
    
    $("hHasChanged").value = "1";
}

//records changes in the current Form
function FormChanged()
{
    
    $("hHasChanged").value = "1";
}

function showDocumentsPopup(JSSaveFunction,PageCode,DocumentID,Locale)
{
    eval(JSSaveFunction);
    if($("hHasChanged").value!="0")
    {
        window.open('../popups/SelectareDocument.aspx?pc='+PageCode+'&dID='+DocumentID+'&cult='+Locale,'','width=488,height=493,status=yes,resizable=no');
    }
}

function showDocumentsNewsPopup(JSSaveFunction,NewsID,DocumentID,Locale)
{
    eval(JSSaveFunction);
    if($("hHasChanged").value!="0")
    {               
        window.open('../popups/SelectareDocumentNoutati.aspx?nID='+NewsID+'&dID='+DocumentID+'&cult='+Locale,'','width=488,height=493,status=yes,resizable=no');
    }
}
function showLinksNewsPopup(JSSaveFunction,NewsID,Locale,LinkID)
{
    eval(JSSaveFunction);
    if($("hHasChanged").value!="0")
    {
        window.open('../popups/SpecificareLinkNoutati.aspx?nID='+NewsID+'&cult='+Locale+'&lID='+LinkID,'','width=488,height=493,status=yes,resizable=no');
    }
}


function showDocumentsStatementsPopup(JSSaveFunction,StatementID,Locale,DocumentID)
{
    eval(JSSaveFunction);
    if($("hHasChanged").value!="0")
    {    

        window.open('../popups/SelectareDocumentComunicat.aspx?nID='+StatementID+'&cult='+Locale+'&pct='+DocumentID,'','width=488,height=493,status=yes,resizable=no');
    }
}

function showDocumentsArticlesPopup(ArticleID,Locale,DocumentID)
{ 
        window.open('../popups/SelectareDocumentArticolDePresa.aspx?aID='+ArticleID+'&cult='+Locale+'&pct='+DocumentID,'','width=488,height=493,status=yes,resizable=no'); 
}

function showLinksPopup(JSSaveFunction,PageCode,Locale,LinkID)
{
    //eval(JSSaveFunction);
    if($("hHasChanged").value!="0")
    {
        window.open('../popups/SpecificareLink.aspx?pc='+PageCode+'&cult='+Locale+'&lID='+LinkID,'','width=488,height=493,status=yes,resizable=no');
    }
}

function showLinksStatementsPopup(JSSaveFunction,StatementID,Locale,LinkID)
{
    eval(JSSaveFunction);
    if($("hHasChanged").value!="0")
    {
        window.open('../popups/SpecificareLinkComunicat.aspx?sid='+StatementID+'&cult='+Locale+'&lID='+LinkID,'','width=488,height=493,status=yes,resizable=no');
    }
}

function showLinksArticlesPopup(ArticleID,Locale,LinkID)
{
        window.open('../popups/SpecificareLinkArticolDePresa.aspx?aid='+ArticleID+'&cult='+Locale+'&lID='+LinkID,'','width=488,height=493,status=yes,resizable=no');
}

function showSideBarPopup(JSSaveFunction,Locale,PageCode)
{
    //eval(JSSaveFunction);
    if($("hHasChanged").value!="0")
    {
        window.open('../popups/SpecificareSideBar.aspx?pc='+PageCode+'&cult='+Locale,'','width=488,height=493,status=yes,resizable=no');
    }
}

function showImagesPopup(URL,JSSaveFunction)
{
    eval(JSSaveFunction);
    if($("hHasChanged").value!="0")
    {
        window.open(URL,'','width=488,height=493,status=yes,resizable=no');
    }
}

//Ordonare generica
function orderItems(ItemsTitle, ItemTableName, ItemDetailTableName, ItemsIDColumn, ItemDisplayColumn, ItemParentColumn, ItemParentID, Locale, BackPage)
{
    if(BackPage != "")
    {
        BackPage = BackPage.replace(/&/g,"|");
    }

    query = "iTitle="+ItemsTitle+"&iTbName="+ItemTableName+"&iDetailTb="+ItemDetailTableName+"&iDispCol="+ItemDisplayColumn+"&iPID="+ItemParentID+"&iPCol="+ItemParentColumn+"&iIDCol="+ItemsIDColumn+"&cult="+Locale+"&back="+BackPage;
    document.location.href = "/admstrv/gOrder.aspx?"+query;
}


function redirect(url)
{
    document.location = url;
}
