function openWindow( URL) 
{ msgWindow=window.open(URL,"displayWindow","menubar=yes,scrollbars=yes,resizable=yes,width=450,height=430")}

function open_window( URL, name, width, height) 
{ msgWindow=window.open(URL,name,'menubar=yes,scrollbars=yes,resizable=yes,width='+ width+',height='+ height)}

function print_window( URL) 
{ msgWindow=window.open(URL,"displayWindow","toolbar=yes,width=750,height=500,directories=no,status=no,scrollbars=yes,resizable=yes,menubar=yes") }





function verify(message, url)
{ if(confirm(message)) location.href = url; }

function updateParent(newURL) {  opener.document.location = newURL  }

function formatCurrency(num) {
	num = num.toString().replace(/\$|\,/g,'');
	if(isNaN(num) ){
		num = "0";
	     //return(num);
	}
	pos_sign = (num == (num = Math.abs(num)));
	num = Math.floor(num*100+0.50000000001);
	cents = num%100;
	num = Math.floor(num/100).toString();
	if(cents<10)
	cents = "0" + cents;
	for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
	num = num.substring(0,num.length-(4*i+3))+','+
	num.substring(num.length-(4*i+3));
	//if(num>0 && cents>0)
		return (((pos_sign)?'':'-')  + num + '.' + cents);
	//else return('');
}

function stripChar(input,chars) {  // strip all characters in 'chars' from input

    //var newstr = null;
    //var re2 = new RegExp (char, 'gi');
    //newstr = newstr.replace(re2, '');
    //return;

    var output = "";  // initialise output string
    for (var i=0; i < input.length; i++)
      if (chars.indexOf(input.charAt(i)) == -1)
        output += input.charAt(i);
    return parseFloat(output);
  }



function swapImgRestore() { //v3.0
  var i,x,a=document.sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.p) d.p=new Array();
    var i,j=d.p.length,a=preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.p[j]=new Image; d.p[j++].src=a[i];}}
}

function findObj(n, d) { //v3.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=findObj(n,d.layers[i].document); return x;
}

function swapImage() { //v3.0
  var i,j=0,x,a=swapImage.arguments; document.sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=findObj(a[i]))!=null){document.sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}



// ---- C O O K I E   F U N C T I O N S  --------------------------

function setCookie(name, value, expires, path, domain, secure) {
    document.cookie= name + "=" + escape(value) +
        ((expires) ? "; expires=" + expires.toGMTString() : "") +
        ((path) ? "; path=" + path : "") +
        ((domain) ? "; domain=" + domain : "") +
        ((secure) ? "; secure" : "");
}

function getCookie(name) {
    var dc = document.cookie;
    var prefix = name + "=";
    var begin = dc.indexOf("; " + prefix);
    if (begin == -1) {
        begin = dc.indexOf(prefix);
        if (begin != 0) return null;
    } else {
        begin += 2;
    }
    var end = document.cookie.indexOf(";", begin);
    if (end == -1) {
        end = dc.length;
    }
    return unescape(dc.substring(begin + prefix.length, end));
}

function deleteCookie(name, path, domain) {
    if (getCookie(name)) {
        document.cookie = name + "=" +
            ((path) ? "; path=" + path : "") +
            ((domain) ? "; domain=" + domain : "") +
            "; expires=Thu, 01-Jan-70 00:00:01 GMT";
    }
}



// --------- D R O P   L I S T   F U N C T I O N S  ----------------


//--- S A M P L E :  -- UpdateDropList(document.myform.main_id, document.myform.sub_id,'<?=$sub_selected_id?>',SubNames,SubIDs);

function ClearDropList(OptionList) {
    OptionList.length = 1;
}

function LoadDropList(Index,sub_select, selected_value,NameArray,ValueArray) {
	if (Index > 0){	
	        var CurrentName = NameArray[Index - 1].split('||');
		var CurrentValue = ValueArray[Index - 1].split('||');
		for (var i=0; i<CurrentName.length; i++){
		  sub_select.options[i+1] = new Option(CurrentName[i], CurrentValue[i], false, false);
		  if(CurrentValue[i] == selected_value) {  sub_select.options[i+1].selected = true;  }
		}
	}
}

function UpdateDropList(main_select, sub_select,selected_value,NameArray,ValueArray) {
	var CurrSub = sub_select.selectedIndex;
	ClearDropList(sub_select);
	LoadDropList(main_select.selectedIndex, sub_select,selected_value,NameArray,ValueArray);
}


//var marked_row = new Array;

theLastRow = null;
theLastRowNum = null;

function setLast(theRow, theRowNum, theAction, theDefaultColor, thePointerColor, theMarkColor){
	theLastRow = theRow;
	theLastRowNum = theRowNum;
	theLastAction = theAction;
	theLastDefaultColor = theDefaultColor;
	theLastPointerColor = thePointerColor;
	theLastMarkColor = theMarkColor;
	//alert(theLastRowNum)
}

function resetRows(){
	if(theLastRow != null){
		 setPointer(theLastRow, theLastRowNum, theLastAction, theLastDefaultColor, theLastPointerColor, theLastMarkColor);
		 //alert(theLastRow+ theLastRowNum+ theLastAction+ theLastDefaultColor+ theLastPointerColor+ theLastMarkColor);
	}
}





stars = new Array();

function setStars(imgid, x,y)
{
	//eval("if( (" imgid + "locked) == 1) return;");
	//eval( "var "+imgid+" =null;");
	//eval( "if("+imgid+"=='xxxx') return;");
	if(stars[imgid] == 'LOCKED') return;

	for(yellow=1;yellow<=x;yellow++)
	{
	  document.getElementById(imgid+yellow).src = "/images/icons/star_yellow.gif";
	  //document[imgid+''+yellow].src = "/images/icons/star_yellow.gif";
	}

	for(white=1;white<=y;white++)
	{
	  cnt = 6 - white;
	  document.getElementById(imgid+cnt).src = "/images/icons/star_white.gif";
	  //document[imgid+''+yellow].src = "/images/icons/star_white.gif";
	}

}



function setStarsLocked(imgid, x,y)
{
	//eval("stars['"+imgid+"'] = 'LOCKED';");
	stars[imgid] = 'LOCKED';
	setStars(imgid, x,y);

}


//var marked_row = new Array;

   theLastRow = null;
   theLastRowNum = null;

   function setLast(theRow, theRowNum, theAction, theDefaultColor, thePointerColor, theMarkColor){
      theLastRow = theRow;
      theLastRowNum = theRowNum;
      theLastAction = theAction;
      theLastDefaultColor = theDefaultColor;
      theLastPointerColor = thePointerColor;
      theLastMarkColor = theMarkColor;
      //alert(theLastRowNum)
   }

   function resetRows(){
      if(theLastRow != null){
         setPointer(theLastRow, theLastRowNum, theLastAction, theLastDefaultColor, theLastPointerColor, theLastMarkColor);
         //alert(theLastRow+ theLastRowNum+ theLastAction+ theLastDefaultColor+ theLastPointerColor+ theLastMarkColor);
      }
   }



var marked_row = new Array;

function setPointer2(theRow, theRowNum, theAction, theDefaultColor, thePointerColor, theMarkColor)
{
    var theCells = null;

    // 1. Pointer and mark feature are disabled or the browser can't get the
    //    row -> exits
    if ((thePointerColor == '' && theMarkColor == '')
        || typeof(theRow.style) == 'undefined') {
        return false;
    }

    // 2. Gets the current row and exits if the browser can't get it
    if (typeof(document.getElementsByTagName) != 'undefined') {
        theCells = theRow.getElementsByTagName('td');
    }
    else if (typeof(theRow.cells) != 'undefined') {
        theCells = theRow.cells;
    }
    else {
        return false;
    }

    // 3. Gets the current color...
    var rowCellsCnt  = theCells.length;
    var domDetect    = null;
    var currentColor = null;
    var newColor     = null;
    // 3.1 ... with DOM compatible browsers except Opera that does not return
    //         valid values with "getAttribute"
    if (typeof(window.opera) == 'undefined'
        && typeof(theCells[0].getAttribute) != 'undefined') {
        currentColor = theCells[0].getAttribute('bgcolor');
        domDetect    = true;
    }
    // 3.2 ... with other browsers
    else {
        currentColor = theCells[0].style.backgroundColor;
        domDetect    = false;
    } // end 3

    // 3.3 ... Opera changes colors set via HTML to rgb(r,g,b) format so fix it
    if (currentColor.indexOf("rgb") >= 0)
    {
        var rgbStr = currentColor.slice(currentColor.indexOf('(') + 1,
                                     currentColor.indexOf(')'));
        var rgbValues = rgbStr.split(",");
        currentColor = "#";
        var hexChars = "0123456789ABCDEF";
        for (var i = 0; i < 3; i++)
        {
            var v = rgbValues[i].valueOf();
            currentColor += hexChars.charAt(v/16) + hexChars.charAt(v%16);
        }
    }

    // 4. Defines the new color
    // 4.1 Current color is the default one
    if (currentColor == ''
        || currentColor.toLowerCase() == theDefaultColor.toLowerCase()) {
        if (theAction == 'over' && thePointerColor != '') {
            newColor              = thePointerColor;
        }
        else if (theAction == 'click' && theMarkColor != '') {
            newColor              = theMarkColor;
            marked_row[theRowNum] = true;
            // Garvin: deactivated onclick marking of the checkbox because it's also executed
            // when an action (like edit/delete) on a single item is performed. Then the checkbox
            // would get deactived, even though we need it activated. Maybe there is a way
            // to detect if the row was clicked, and not an item therein...
            // document.getElementById('id_rows_to_delete' + theRowNum).checked = true;
        }
    }
    // 4.1.2 Current color is the pointer one
    else if (currentColor.toLowerCase() == thePointerColor.toLowerCase()
             && (typeof(marked_row[theRowNum]) == 'undefined' || !marked_row[theRowNum])) {
        if (theAction == 'out') {
            newColor              = theDefaultColor;
        }
        else if (theAction == 'click' && theMarkColor != '') {
            newColor              = theMarkColor;
            marked_row[theRowNum] = true;
            // document.getElementById('id_rows_to_delete' + theRowNum).checked = true;
        }
    }
    // 4.1.3 Current color is the marker one
    else if (currentColor.toLowerCase() == theMarkColor.toLowerCase()) {
        if (theAction == 'click') {
            newColor              = (thePointerColor != '')
                                  ? thePointerColor
                                  : theDefaultColor;
            marked_row[theRowNum] = (typeof(marked_row[theRowNum]) == 'undefined' || !marked_row[theRowNum])
                                  ? true
                                  : null;
            // document.getElementById('id_rows_to_delete' + theRowNum).checked = false;
        }
    } // end 4

    // 5. Sets the new color...
    if (newColor) {
        var c = null;
        // 5.1 ... with DOM compatible browsers except Opera
        if (domDetect) {
            for (c = 0; c < rowCellsCnt; c++) {
                theCells[c].setAttribute('bgcolor', newColor, 0);
            } // end for
        }
        // 5.2 ... with other browsers
        else {
            for (c = 0; c < rowCellsCnt; c++) {
                theCells[c].style.backgroundColor = newColor;
            }
        }
    } // end 5

    return true;
} // end of the 'setPointer()' function









function setPointer(theRow, theRowNum, theAction, theDefaultColor, thePointerColor, theMarkColor)
{
    var theCells = null;

    // ---- O V E R H E A D ----------------------------------------------
    // 1. Pointer and mark feature are disabled or the browser can't get the
    if ((thePointerColor == '' && theMarkColor == '')
        || typeof(theRow.style) == 'undefined') {
        return false;
    }

    // 2. Gets the current row and exits if the browser can't get it
    if (typeof(document.getElementsByTagName) != 'undefined') {
        theCells = theRow.getElementsByTagName('td');
    }
    else if (typeof(theRow.cells) != 'undefined') {
        theCells = theRow.cells;
    }
    else {
        return false;
    }






    // ---- G E T   C U R R E N T   C O L O R -----------------------------
    // 3. Gets the current color...
    var rowCellsCnt  = theCells.length;
    var domDetect    = null;
    var currentColor = null;
    var newColor     = null;
    // 3.1 ... with DOM compatible browsers except Opera that does not return
    //         valid values with "getAttribute"
    if (typeof(window.opera) == 'undefined'
        && typeof(theCells[0].getAttribute) != 'undefined') {
        currentColor = theCells[0].getAttribute('bgcolor');
        domDetect    = true;
    }
    // 3.2 ... with other browsers
    else {
        currentColor = theCells[0].style.backgroundColor;
        domDetect    = false;
    } // end 3

    // 3.3 ... Opera changes colors set via HTML to rgb(r,g,b) format so fix it
    if (currentColor.indexOf("rgb") >= 0) 
    {
        var rgbStr = currentColor.slice(currentColor.indexOf('(') + 1,
                                     currentColor.indexOf(')'));
        var rgbValues = rgbStr.split(",");
        currentColor = "#";
        var hexChars = "0123456789ABCDEF";
        for (var i = 0; i < 3; i++)
        {
            var v = rgbValues[i].valueOf();
            currentColor += hexChars.charAt(v/16) + hexChars.charAt(v%16);
        }
    }

	if (theAction == 'click' && theMarkColor != '') { newColor = theMarkColor; }
	else if (theAction == 'over' && thePointerColor != '') { newColor = thePointerColor; }
	else if (theAction == 'out') {
	    if(theLastRowNum == theRowNum)
		  newColor              = theMarkColor;
	    if(theLastRowNum != theRowNum)
		  newColor              = theDefaultColor;
	}
	else if(theAction == 'reset') {
	    newColor              = theDefaultColor;
	}


    // ---- S E T   N E W   C O L O R  -----------------------------------------
    if (newColor) {
        var c = null;
        // 5.1 ... with DOM compatible browsers except Opera
        if (domDetect) {
            for (c = 0; c < rowCellsCnt; c++) {
                theCells[c].setAttribute('bgcolor', newColor, 0);
            } // end for
        }
        // 5.2 ... with other browsers
        else {
            for (c = 0; c < rowCellsCnt; c++) {
                theCells[c].style.backgroundColor = newColor;
            }
        }
        //alert('New Color: '+ newColor);
    } // end 5

    return true;
}

// ---- R O W  -  T O G G L I N G ------------------------------------
closeallvalue = null;

var ns4=(document.layers);
var ie=(document.all);
var w3=(document.getElementById && !ie);

function initialize_toggle(){
  for(x in CAT) {
	  tmp   = CAT[x].split('-');
	  xstart = parseInt(tmp[0]);
	  xend   = parseInt(tmp[1]);
	  set_row(xstart, xend,'','1'); // bycookie
   }
}

function toggle(catid,img){
     if(catid=='main_all'){
	  closeallvalue = (closeallvalue=='2')?'1':'2'; // 1=show, 2=hide
	  for(x in CAT) {
		  tmp   = CAT[x].split('-');
		  xstart = parseInt(tmp[0]);
		  xend   = parseInt(tmp[1]);
		  return_display_all = set_row(xstart, xend,closeallvalue, ''); // by value

		  //if(closeallvalue==2) document.getElementById(img).src="images/plus_white.gif";
		  //else document.getElementById(img).src="images/minus_white.gif";
		  tmpx   = x.split('_');
		  cat_id = tmpx[1];

		  if(closeallvalue==2) document.images['img_'+ cat_id].src="images/plus.gif";
		  else document.images['img_'+ cat_id].src="images/minus.gif";

		  
		  //toggle_image_white(img);
		  //document.all.mydiv.innerHTML += xstart +'-'+xend+"<br>";
	   }		  
	if(return_display_all=='none') img.src="images/plus_white.gif";
	else img.src="images/minus_white.gif";
     }
     else {
	  tmp   = CAT[catid].split('-');
	  xstart = parseInt(tmp[0]);
	  xend   = parseInt(tmp[1]);
	  return_display = set_row(xstart, xend,'',''); // by toggle

	  if(return_display=='none') img.src="images/plus.gif";
	  else img.src="images/minus.gif";

	  //toggle_image(img);
     }
}

function set_row(start, end, closeall, bycookie){
	if(end=='' ||  end<start) return;//end = start;
	for(cnt=start;cnt<=end;cnt++)
	{
		if(!ns4 && !ie && !w3) return;
		if( document.getElementById('row_' + cnt)== null ) continue;
		if(ie) thisrow=eval('document.all.row_' + cnt + '.style');
		else if(ns4) thisrow=eval('document.layers["row_' + cnt +'"]');
		else if(w3) thisrow=eval('document.getElementById("row_' + cnt + '").style');

		if(closeall=='1'|| closeall=='2') {
			thisrow.display = (closeall=='1')?'':'none';
			if (thisrow.display == "none")	{
				//setCookie("my_task_hide_row_"+cnt, "");
				//deleteCookie("my_task_hide_row_"+cnt);
			}
			else  {
				//setCookie("my_task_hide_row_"+cnt, "1");
			}

		}
		else if(bycookie==''){
			if (thisrow.display == "none")	{
				thisrow.display="";
				//setCookie("my_task_hide_row_"+cnt, "");
				//deleteCookie("my_task_hide_row_"+cnt);
			}
			else  {
				thisrow.display ="none";
				//setCookie("my_task_hide_row_"+cnt, "1");
			}
		}
		else {
			row_cookie = getCookie("my_task_hide_row_"+cnt);
			//document.all.mydiv.innerHTML += "my_task_hide_row_"+cnt + "="+row_cookie +"<br>";
			if(row_cookie=='' || row_cookie==null){
				thisrow.display = '';
			 }
			else{
				thisrow.display = 'none';
			}
		}
	}

       return(thisrow.display);

}

function toggle_image_white(img) {
  if(img.src=='http://www.silverbreakout.com/images/minus_white.gif')  img.src='images/plus_white.gif';
  else  img.src='images/minus_white.gif';
}

function toggle_image(img) {
  if(img.src=='http://www.silverbreakout.com/images/minus.gif')  img.src='images/plus.gif';
  else  img.src='images/minus.gif';
}