/* MISC JS FUNCTIONS */

function toggleDiv(name)
{
    var tmpvar = document.getElementById(name).style;
    if (tmpvar.display=="block") { tmpvar.display="none"; }
    else                         { tmpvar.display="block";}
}

function toggleDivOn(name)
{
    var tmpvar = document.getElementById(name).style;
    tmpvar.display="block";
}

function toggleCheckbox (id)
{
    var tmpvar = document.getElementById(id);
    if (tmpvar.checked)       { tmpvar.value=1; }
    else                      { tmpvar.value=0; tmpvar.checked=false; }
}


// For SEO urls
function jsGetSEO(type)
{
 if(location.href.match(type))
 { return location.href.split(type+',')[1].split('/')[0]; }
}
// For regular urls
function jsGet(type)
{
 if(location.href.match(type))
 { return location.href.split(type+'=')[1].split('&')[0]; }
}


/* AJAX FUNCTIONS */

function getProductData(id)
{
   var lang   = jsGetSEO('lang');
   var url = '/components/com_dfiprodukter/misc.php';

   $.post(url, { task: 'getProductsData', id: id, lang: lang },
   function(data)
   {
    tempar = data.split("|");
    for (var a=0;a<tempar.length;a++)
    {
      var tmpar = tempar[a].split("#");
      if (document.getElementById(tmpar[0]))
      {

        if (tmpar[0]=="productpic")
        {
          document.getElementById(tmpar[0]).src='/images/stories/products/'+tmpar[1]+'';
        }
        else
        {
		  $("div#"+tmpar[0]).html(tmpar[1]);
        }
      }
    }
    /* Jump to top */
    window.location.hash="top2";
   }
 );

}


function getProductData2(id)
{
   var lang   = jsGetSEO('lang');
   var url = '/components/com_dfiprodukter/misc.php';

   $.post(url, { task: 'getProductsData2', id: id, lang: lang },
   function(data)
   {
    tempar = data.split("|");
    for (var a=0;a<tempar.length;a++)
    {
      var tmpar = tempar[a].split("§");
      if (document.getElementById(tmpar[0]))
      {

        if (tmpar[0]=="productpicSink")
        {
          document.getElementById(tmpar[0]).src='/images/stories/products2/'+tmpar[1]+'';
        }
        else
        {
		  $("div#"+tmpar[0]).html(tmpar[1]);
        }
      }
    }
    /* Jump to top */
    window.location.hash="top2";
   }
 );

}


function togglePublished(id,state,table)
{
   var url = '/components/com_dfiprodukter/misc.php';

   $.post(url, { task: 'togglePublished', id: id, state: state, table: table },
   function(data)
   {

		if (data == "unpublished")
        {
            document.getElementById("img"+id).src="images/publish_x.png";
            document.getElementById("togglePublished"+id).value=1;

        }
        else if (data == "published")
        {
            document.getElementById("img"+id).src="images/publish_g.png";
            document.getElementById("togglePublished"+id).value=0;
        }
   }
 );
}

function deleteItem(id,table,titleid)
{
   var url = '/components/com_dfiprodukter/misc.php';

   $.post(url, { task: 'deleteItem', id: id, table: table },
   function(data)
   {
        if (data == 1)
        {
          document.getElementById('numinRow'+titleid).innerHTML=document.getElementById('numinRow'+titleid).innerHTML-1;
          document.getElementById('item'+id).style.display="none";
          document.getElementById('itembuttons'+id).style.display="none";
        }
   }

 );
}

function deleteItem2(id,table)
{
   var url = '/components/com_dfiprodukter/misc.php';

   $.post(url, { task: 'deleteItem', id: id, table: table },
   function(data)
   {
        if (data == 1)
        {
          document.getElementById('item'+id).style.display="none";
        }
   }
 );
}

function deleteItem3(id,table)
{
   var url = '/components/com_dfiprodukter/misc.php';

   $.post(url, { task: 'deleteItem2', id: id, table: table },
   function(data)
   {
        if (data == 1)
        {
          document.getElementById('item'+id).style.display="none";
        }
   }
 );
}

function deleteGroup(id)
{
   var url = '/components/com_dfiprodukter/misc.php';

   $.post(url, { task: 'deleteGroup', id: id },
   function(data)
   {
	   var msg = '';
	   switch(data)
	   {
			case 'OK': //success
				msg = 'Success';
				break;
				
			case 'NOT': //fail
				msg = "NotEmpty";
				break;	
	   }
	   window.location = "/administrator/index2.php?option=com_dwemployees&mosmsg="+msg;
   }
 );  
}
