/*
vim: set ts=2 sw=2 sts=2 et:
*/
function explode(inputstring, separators, includeEmpties) {
  inputstring = new String(inputstring);
  separators = new String(separators);

  if(separators == "undefined") {
    separators = " :;";
  }

  fixedExplode = new Array(1);
  currentElement = "";
  count = 0;

  for(x=0; x < inputstring.length; x++) {
    char = inputstring.charAt(x);
    if(separators.indexOf(char) != -1) {
      if ( ( (includeEmpties <= 0) || (includeEmpties == false)) && (currentElement == "")) { } 
      else {
        fixedExplode[count] = currentElement;
        count++;
        currentElement = ""; } }
    else { currentElement += char; }
  }

  if (( ! (includeEmpties <= 0) && (includeEmpties != false)) || (currentElement != "")) {
  fixedExplode[count] = currentElement; } 
  return fixedExplode;
}

function dynamic_popup_image(img_name, id, title, page) {

  img_prop = explode(img_name, ';', 0);
  
	if (!page)
		page = 1;

  max_x = parseInt(img_prop[1]);
  max_y = parseInt(img_prop[2]);

  max_x = (max_x < 1 || !isNaN(max_x)) ? max_x + 40 : 420;
	max_y = (max_y < 1 || !isNaN(max_y)) ? max_y + 40 : 420;

  var url = xcart_web_dir + '/dynamic_popup_image.php?name=' + img_prop[0] + '&id=' + id + '&title=' + title + '&area=' + current_area + '&page=' + page;

  var res = false;
	if (current_area == 'C' && window.popupOpen) {
		res = popupOpen(
      url,
      title,
      Math.max(Math.min(max_x, $(window).width() - 150), 420),
      Math.max(Math.min(max_y, $(window).height() - 150), 420)
    );
	}

  if (res)
    return true;

	return window.open(
    url,
		'images',
		'width=' + max_x + ',height=' + max_y + ',toolbar=no,status=no,scrollbars=yes,resizable=yes,menubar=no,location=no,direction=no'
	);
}

