function confirmDelete(title, trigger)
{	
	// give confirmation alert
	var yes=confirm("Are you sure you want to delete «" + title + "»?");
	if(yes){		
		// set value in form before executing
		switchTrigger( trigger );
		
        return true;
	}
	else{
        return false;
	}
}

// switch the boolean value of an input field
function switchTrigger( trigger )
{
	trigger = document.getElementById(trigger);
	
	value = trigger.value;
	
	if (value == 'true') {
		trigger.value = 'false';
	} else if (value == 'false') {
		trigger.value = 'true';
	}
}

/**
 * Pop a variety of windows
 */
function winPop ( url, width, height, xpos, ypos, toolbar, scrollbar, resizable, name )
{
    var wspec = "width="  + width  + ",";
    var hspec = "height=" + height + ",";
    var xspec = "screenX=" + xpos + ",left=" + xpos + ",";
    var yspec = "screenY=" + ypos + ",top="  + ypos + ",";

    var toolspec   = (toolbar)   ? "toolbar=yes,"    : "toolbar=no,";
    var scrollspec = (scrollbar) ? "scrollbars=yes," : "scrollbars=no,";
    var resizspec  = (resizable) ? "resizable=yes,"  : "resizable=no,";

    var specs  = wspec + hspec + xspec + yspec;
    specs += toolspec + scrollspec + resizspec;
    specs += "status=no,titlebar=no,directories=no";

    var popper = window.open(url,name,specs);
    if (window.focus) popper.focus();
}


function popInputWindow ( url )
{
	winPop(url, 400, 500, 32, 32, false, true, false, 'inputwindow');
}

function insertRow ( tableid, cell0, cell1, cell2, cell3, cell4 )
{
	var num_rows = 1; // :TODO: do this automagically

    var x=document.getElementById(tableid).insertRow( num_rows );
    if ( cell0 ) { var y=x.insertCell(0); y.innerHTML=cell0; }
    if ( cell1 ) { var z=x.insertCell(1); z.innerHTML=cell1; }
    if ( cell2 ) { var a=x.insertCell(2); a.innerHTML=cell2; }
    if ( cell3 ) { var b=x.insertCell(3); b.innerHTML=cell3; }
    if ( cell4 ) { var c=x.insertCell(4); c.innerHTML=cell4; }
}


function addtag ( tag, textfield )
{
	var textfield = document.getElementById(textfield);
	
	textfield.value += tag + ' ';
}

 // this function is needed to work around 
 // a bug in IE related to element attributes
 function hasClass(obj) {
    var result = false;
    if (obj.getAttributeNode("class") != null) {
        result = obj.getAttributeNode("class").value;
    }
    return result;
 }   

/* 
Zebra Tables by David F. Miller from A List Apart
http://www.alistapart.com/articles/zebratables
*/
function zebraTables(id) {

   // the flag we'll use to keep track of 
   // whether the current row is odd or even
   var even = false;
 
   // if arguments are provided to specify the colours
   // of the even & odd rows, then use the them;
   // otherwise use the following defaults:
   var evenColor = arguments[1] ? arguments[1] : "#fff";
   var oddColor = arguments[2] ? arguments[2] : "#eee";
 
   // obtain a reference to the desired table
   // if no such table exists, abort
   var table = document.getElementById(id);
   if (! table) { return; }
   
   // by definition, tables can have more than one tbody
   // element, so we'll have to get the list of child
   // &lt;tbody&gt;s 
   var tbodies = table.getElementsByTagName("tbody");

   // and iterate through them...
   for (var h = 0; h < tbodies.length; h++) {
   
    // find all the &lt;tr&gt; elements... 
     var trs = tbodies[h].getElementsByTagName("tr");
     
     // ... and iterate through them
     for (var i = 0; i < trs.length; i++) {

       // avoid rows that have a class attribute
       // or backgroundColor style
       if (! hasClass(trs[i]) &&
           ! trs[i].style.backgroundColor) {
		  
         // get all the cells in this row...
         var tds = trs[i].getElementsByTagName("td");
       
         // and iterate through them...
         for (var j = 0; j < tds.length; j++) {
       
           var mytd = tds[j];

           // avoid cells that have a class attribute
           // or backgroundColor style
           if (! hasClass(mytd) &&
               ! mytd.style.backgroundColor) {
       
             mytd.style.backgroundColor =
               even ? evenColor : oddColor;
           
           }
         }
       }
       // flip from odd to even, or vice-versa
       even =  ! even;
     }
   }
 }

	var uid = new Date().getTime();

	var flashProxy = new FlashProxy(uid, '/gfx/JavaScriptFlashGateway.swf');

	var flashtag = new FlashTag('/gfx/player.swf', 1, 1); // last two arguments are height and width

	flashtag.setFlashvars('lcId='+uid);
	flashtag.write(document);


	/* Call player within Flash */
	function playMP3(file)
	{
		flashProxy.call('playMP3', file);
	}
	function stopMP3()
	{
		flashProxy.call('stopMP3');
	}

	
window.onload = function(){
	zebraTables('main_table');
}
