﻿// GONGOD (c) Sistrum 2007
// GONGOD2 (c) Sistrum 2008-2009
// GONGOD3 (c) Sistrum 2009-

/* reviews stars */
var StarsReview = function(containerId, resultId, storeId)
{
    this.container = document.getElementById(containerId);
    this.result = document.getElementById(resultId);
    this.store = document.getElementById(storeId);
}

StarsReview.prototype.SetBackground = function(star)
{
    this.container.style.backgroundImage = "url('assets/" + star + "stars.gif')";
}

StarsReview.prototype.Select = function(star)
{
    //this.store.value = star;
    this.result.innerHTML = star;
    this.SetBackground(star);
}

StarsReview.prototype.Validate = function()
{
    if(this.result.innerHTML.length > 0)
    {
        this.store.value = this.result.innerHTML;
        return true;
    }
    else
    {
        alert("Ocjenite trgovinu klikom na zvjezdice!");
        return false;
    }            
}
    
StarsReview.prototype.Reset = function()
{
    if(this.result.innerHTML.length > 0)
    {
        this.SetBackground(this.result.innerHTML);
    }
    else
    {        
        this.SetBackground("0");
    }            
}        
/* end review stars */        



/* start listmania */
var Listmania = function(html_editListName, html_editListDesc)
{
    this.LiteralListName = document.getElementById("html_listmaniaTitle");
    this.LiteralListDesc = document.getElementById("html_listmaniaDesc");
    this.TextBoxListName = document.getElementById(html_editListName);
    this.TextBoxListDesc = document.getElementById(html_editListDesc);
    this.ContainerListContent = document.getElementById("html_listContent");
    this.ContainerListEditor = document.getElementById("html_listEdit");
    this.SwapLink = document.getElementById("html_editLink");    
    
    this._ListName = "";
    this._ListDesc = "";
}

Listmania.prototype.Swap = function(action)
{
    ToggleVisibility(this.ContainerListContent.id)
    ToggleVisibility(this.ContainerListEditor.id)
        
    if(this.ContainerListContent.style.display == "block")
        this.SwapLink.innerHTML = "Uredi listu";
    else
        this.SwapLink.innerHTML = "Proizvodi";            
        
    if(action == "EDIT")
    {
        this._ListName = this.LiteralListName.innerHTML;
        this._ListDesc = this.LiteralListDesc.innerHTML;
    }
    else if(action = "CANCEL")
    {
        this.TextBoxListName.value = this.LiteralListName.innerHTML = this._ListName;
        this.TextBoxListDesc.value = this.LiteralListDesc.innerHTML = this._ListDesc;
    }        
}

Listmania.prototype.Update = function()
{
    this.LiteralListName.innerHTML = this.TextBoxListName.value.replace(/(<([^>]+)>)/ig,"");
    this.LiteralListDesc.innerHTML = this.TextBoxListDesc.value.replace(/(<([^>]+)>)/ig,"");
}

Listmania.prototype.SelectAll = function(id)
{
    var isChecked = document.getElementById(id).checked;
    document.getElementById("html_selectAllTop").checked = isChecked;
    document.getElementById("html_selectAllBottom").checked = isChecked;
    
    var elems = document.getElementsByTagName("input");
    
    for(var i = 0; i<elems.length; i++)
    {
        if(elems[i].id && elems[i].id.substring(0,8) == "product_")
        {
            elems[i].checked = isChecked;
        }
    }
}

Listmania.prototype.CopyItem = function(serverId, clientId)
{
    var dd = document.getElementById(clientId);
    var id = dd.options[dd.selectedIndex].value;
    
    if(id == "")
        return;
        
    if(id == "00000000-0000-0000-0000-000000000000")
    {
        var newListName = prompt("Odaberite ime nove liste:", "");
        if(!newListName || newListName == "")
        {
            dd.options[0].selected = true;
            return;        
        }
        document.getElementById("html_newListName").value = newListName;        
    }
    
    __doPostBack(serverId,"");
}


Listmania.prototype.ShowHelp = function()
{   
    document.getElementById("html_listmania_help").style.display = "block";
    var lnk = document.getElementById("html_listmania_toggle");
    lnk.innerHTML = "[zatvori]";
    lnk.href = "javascript:listmania.CloseHelp();";
}

Listmania.prototype.CloseHelp = function()
{
    document.getElementById("html_listmania_help").style.display = "none";
    var lnk = document.getElementById("html_listmania_toggle");
    lnk.innerHTML = "[otvori]";
    lnk.href = "javascript:listmania.ShowHelp();";    
}

/* end listmania */


function open_email(link_title, first_part, second_part)
{
	<!--
	if (link_title.indexOf("@@") > 0)
	{
		link_title = link_title.substring(0, link_title.indexOf("@@")) + "&#64;" + link_title.substring(link_title.indexOf("@@")+2);
		//alert(link_title);
	}
	document.write("<a href=" + "mail" + "to:" + first_part + "&#64;" + second_part + ">"+ link_title + "</a>")
	//-->
}




function InstallOpenSearchPlugin(hostAndFolder) 
{
    if (window.external && ("AddSearchProvider" in window.external) && hostAndFolder) 
    {    
        // Firefox 2 and IE 7, OpenSearch
        window.external.AddSearchProvider(hostAndFolder + "OpenSearchPlugin/moja-trgovina.xml");        
    } 
    else 
    {
        // No search engine support (IE 6, Opera, etc).
        alert("Vaš preglednik ne podržava OpenSearch plug-in format.");
    }
} 



// switch tabova na detaljim virtualnog proizvoda
function ActivateProductDetailsTab(idx)
{
    var tabCount = document.getElementById("productDetailsTabs").getElementsByTagName("li").length;
    
    for(var i = 0; i < tabCount; i++)
    {        
        var tab = document.getElementById("tab_" + i);
        var li = document.getElementById("li_" + i);
        
        if(!tab || !li) 
        {
            alert("Element nije pronađen!");
            continue;
        }
        
        if(i==idx)
        {
            tab.style.display = "block";
            li.className = "tab_active";
        }
        else
        {
            tab.style.display = "none";
            li.className = "tab_inactive";
        }
    }
}












