var oldWBIndex = 0;
var pushed = 1;
history.go(1);

function open_help_win( win_location ) {
   var screen_width, screen_height;
   var win_top, win_left;
   var HelpWin;

   screen_height        = 0;     screen_width      = 0;
   win_top              = 0;     win_left          = 0;


   var help_win_width   = 315; // +20 while scrollbars = yes
   var help_win_height  = 270; // +20 while scrollbars = yes

   win_left = (screen.width) ? (screen.width-help_win_width)/2 : 0;
   win_top = (screen.height) ? (screen.height-help_win_height)/2 : 0;

   // scrollbars=auto do not work
   helpWin  = window.open(
               win_location,
               'PSHelpWin',
               'width='+help_win_width+',height='+help_win_height+',top='+win_top+',left='+win_left
   );               
   helpWin.focus();
}


function open_win( win_location ) {
   var screen_width, screen_height;
   var win_top, win_left;
   var HelpWin;

   screen_height        = 0;     screen_width      = 0;
   win_top              = 0;     win_left          = 0;


   var help_win_width   = 500; // +20 while scrollbars = yes
   var help_win_height  = 340; // +20 while scrollbars = yes

   win_left = (screen.width) ? (screen.width-help_win_width)/2 : 0;
   win_top = (screen.height) ? (screen.height-help_win_height)/2 : 0;

   // scrollbars=auto do not work
   helpWin  = window.open(
               win_location,
               'demo1',
               'scrollbars=yes,resizable=yes,width='+help_win_width+',height='+help_win_height+',top='+win_top+',left='+win_left
   );               
   helpWin.focus();
}



function logout() {
	self.close();
	return;
}

function changeFiles(index) {
   document.getElementById('filename_' + oldWBIndex).style.display = 'none';
   document.getElementById('preview_' + oldWBIndex).style.display = 'none';
   document.getElementById('price_' + oldWBIndex).style.display = 'none';
   document.getElementById('description_' + oldWBIndex).style.display = 'none';
   document.getElementById('tan_' + oldWBIndex).style.display = 'none';
   document.getElementById('reseller_' + oldWBIndex).style.display = 'none';
   oldWBIndex = index;
   document.getElementById('filename_' + index).style.display = '';
   document.getElementById('preview_' + index).style.display = '';
   document.getElementById('price_' + index).style.display = '';
   document.getElementById('description_' + index).style.display = '';
   document.getElementById('tan_' + index).style.display = '';
   document.getElementById('reseller_' + index).style.display = '';
}

function correctPrice(priceEuro) {
	var priceEuroS = ""+priceEuro;

	if (priceEuro == 0) { // 0
	   priceEuroS = "0.00";
	} else if (priceEuroS.indexOf(".") == -1) { // xxxx
		if (priceEuroS.length == 1) { // x
		   priceEuroS = "0.0" + priceEuroS; 
		} else if (priceEuroS.length == 2) { // xx 
		   priceEuroS = "0." + priceEuroS;
		} else { // xxxx
		   priceEuroS = priceEuroS.substring(0, priceEuroS.length - 2) + "." + priceEuroS.substring(priceEuroS.length - 2, priceEuroS.length);
		}
	} else { // x.x 
	   if (priceEuroS.indexOf(".") == priceEuroS.length - 2) {
	      priceEuroS = priceEuroS + "0";
	   }
	}
	return priceEuroS;
}

function round(x, n) {
  if (n < 1 || n > 14) return false;
  var e = Math.pow(10, n);
  var k = (Math.round(x * e) / e).toString();
  if (k.indexOf('.') == -1) k += '.';
  k += e.toString().substring(1);
  return k.substring(0, k.indexOf('.') + n+1);
}



function cutString(value, counter, highlight, noSize, noTime) {
	if (value.length + highlight.length > counter + 4 * noSize + 4 * noTime) {
	   result = value.substring(0,counter - 2 - highlight.length + 4 * noSize + 4 * noTime) + "...";
	} else {
	   result = value;
	}
   return result;
}	

	
function breakString(value, counter, highlight, noSize) {
	if (value.length > counter) {
	   result = value.substring(0,counter) + " ";
	   if (value.length + highlight.length > (2 * counter - 7 + 5 * noSize)) {
	      result = result + value.substring(counter, 2 * counter - 9 - highlight.length + 5 * noSize) + "...";
	   } else {
	      result = result + value.substring(counter, value.length);
	   }
	} else {
	   result = value;
	}
   return result;
}	
	
