/**************************************************************
 * $Id: common.js, Sep 08, 2005 $                             *
 **************************************************************/

/**
 * function switchInfo() - version 1.2
 * Switcher for the infos in the photo-list
 *
 * @param   obj      the a-tag object, usaly 'this'
 *
 * @return  boolean  false
 *
 * @access  public
 *
 * @author  MARTES NEW MEDIA <dev@martes.de>
 */
function switchInfo (obj) {
	var parentObj = obj.parentNode.parentNode;
	var divObj    = false;
	for (var i=0; i<parentObj.childNodes.length; i++) {
	  if (parentObj.childNodes[i].tagName == 'DIV') {
			var divObj = parentObj.childNodes[i];
			break;
	  }
	}

	if (divObj) {
    divObj.style.display = (divObj.style.display == 'none' ? 'block': 'none');
  }
  return false;
} // end of 'switchInfo()' function


/**
 * function fitWindow() - version 1.0
 * Fits the windows of the image-popup to the image-size
 *
 * @access  public
 *
 * @author  MARTES NEW MEDIA <dev@martes.de>
 */
function fitWindow () {
  var NS = (navigator.appName == "Netscape" ? true: false);
  var IE = (document.all ? true: false);
  var iWidth = (NS) ? window.innerWidth: (IE) ? document.documentElement.clientWidth: document.body.clientWidth;
  var iHeight = (NS) ? window.innerHeight: (IE) ? document.documentElement.clientHeight: document.body.clientHeight;
  iWidth = imageWidth - iWidth;
  iHeight = imageHeight - iHeight;
  window.resizeBy(iWidth, iHeight);
} // end of 'fitWindow()' function

/**
 * function popup() - version 1.0
 * Fits the windows of the image-popup to the image-size
 *
 * @access  public
 *
 * @author  MARTES NEW MEDIA <dev@martes.de>
 */
function popup (url) {
  window.open(url, "popupWindow", "width=300, height=300, top=100, left=100, resizable=no, scrollbars=no, menubar=no, toolbar=no, status=no, location=no");
} // end of 'fitWindow()' function


/**
 * function empty() - version 1.0
 * Checks if a variable is empty
 *
 * @access  public
 *
 * @author  MARTES NEW MEDIA <dev@martes.de>
 */
function empty (s) {
  while ((s.substring(0,1) == ' ') || (s.substring(0,1) == '\n') || (s.substring(0,1) == '\r')) s = s.substring(1,s.length);
  while ((s.substring(s.length-1,s.length) == ' ') || (s.substring(s.length-1,s.length) == '\n') || (s.substring(s.length-1,s.length) == '\r')) s = s.substring(0,s.length-1);

  return (s == '' || s == false || s == null || s == undefined ? true: false)
} // end of 'empty()' function


/**
 * function isEmail() - version 1.0
 * Verifies an email
 *
 * @access  public
 *
 * @author  MARTES NEW MEDIA <dev@martes.de>
 */
function isEmail (str) {
  var supported = 0;
  if (window.RegExp) {
    var tempStr = "a";
    var tempReg = new RegExp(tempStr);
    if (tempReg.test(tempStr)) supported = 1;
  }

  if (!supported) return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);

  var r1 = new RegExp("(@.*@)|(\\.\\.)|(@\\.)|(^\\.)");
  var r2 = new RegExp("^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,4}|[0-9]{1,3})(\\]?)$");

  return (!r1.test(str) && r2.test(str));
} // end of 'isEmail()' function


/**
 * function printSpan() - version 1.0
 * Prints the content of a span
 *
 * @access  public
 *
 * @author  MARTES NEW MEDIA <dev@martes.de>
 */
function printSpan (id) {
  var span  = document.getElementById(id);
  var frame = document.getElementById('printFrame');

  var content = span.innerHTML;

  var html = '<html>'
           + '<head>'
           + '<title>Druckversion</title>'
           + '</head>'
           + '<body onload="self.focus(); self.print();">'
           + content
           + '</body>';

  if (frame.contentWindow.document)
    var win = frame.contentWindow.document;
  else
    var win = frame.document;

  win.open('text/html', 'replace');
  win.write(html);
  win.close();
} // end of 'printSpan()' function

function confirmLink (theLink, theMsg) {
  if (typeof(window.opera) != 'undefined') return true;
  var is_confirmed = confirm(theMsg);
  if (is_confirmed) theLink.href += '&is_js_confirmed=1';
  return is_confirmed;
}

function buy_over (num) {
  document.getElementById('buy_'+num+'_1').style.color = '#00bb00';

  document.getElementById('buy_'+num+'_1').style.backgroundColor = '#e5e5e5';
  document.getElementById('buy_'+num+'_2').style.backgroundColor = '#e5e5e5';
  document.getElementById('buy_'+num+'_3').style.backgroundColor = '#e5e5e5';
  document.getElementById('buy_'+num+'_4').style.backgroundColor = '#e5e5e5';
}

function buy_out (num) {
  document.getElementById('buy_'+num+'_1').style.color = '#000000';

  document.getElementById('buy_'+num+'_1').style.backgroundColor = '#d9d9d9';
  document.getElementById('buy_'+num+'_2').style.backgroundColor = '#d9d9d9';
  document.getElementById('buy_'+num+'_3').style.backgroundColor = '#d9d9d9';
  document.getElementById('buy_'+num+'_4').style.backgroundColor = '#d9d9d9';
}

function switch_format_details () {
  var new_status = document.getElementById('format_details_0').style.display == 'inline' ? 'none': 'inline';
  var new_src    = document.getElementById('format_details_0').style.display == 'inline' ? 'plus': 'minus';

  for (var i=0; i<=3; i++) {
    var set = document.getElementById('format_plus_' + i);
    if (set != null) set.src = 'images/icons/' + new_src + '.gif';
  }

  for (var i=0; i<=4; i++) {
    var set = document.getElementById('format_details_' + i);
    if (set != null) set.style.display = new_status;
  }
}

function wa_alert (str) {
  if (document.all) document.getElementById('inactive_site_ie_6').style.display = 'block';
  document.getElementById('inactive_site').style.display = 'block';

  document.getElementById('alert_text').innerHTML = str;
  document.getElementById('alert').style.display = 'block';

  if (document.all) {
    var innerwidth = document.body.clientWidth;
  } else {
    var innerwidth = window.innerWidth;
  }

  document.getElementById('alert').style.left = Math.round(parseInt(innerwidth) / 2 - parseInt(document.getElementById('alert').offsetWidth) / 2) + 'px';
}

function wa_close_alert () {
  if (document.all) document.getElementById('inactive_site_ie_6').style.display = 'none';
  document.getElementById('inactive_site').style.display = 'none';

  document.getElementById('alert').style.display = 'none';
}