/* 1.21.2 */

/**
  * Checks/unchecks all options of a <select> element
  *
  * @param   string   the form name
  * @param   string   the element name
  * @param   boolean  whether to check or to uncheck the element
  *
  * @return  boolean  always true
  */
function setSelectOptions(the_form, the_select, do_check) {
	var selectObject = document.forms[the_form].elements[the_select];
	var selectCount  = selectObject.length;

	for (var i = 0; i < selectCount; i++) {
		selectObject.options[i].selected = do_check;
	} // end for

	return true;
} // end of the 'setSelectOptions()' function

function SelectAllCheckboxes(frm, fieldName, checked) {
	if (typeof(frm.elements[fieldName])=='undefined') return false;
	var _obj=frm.elements[fieldName];
	for (var i=0;i<_obj.length;i++) {
		_obj[i].checked=checked;
	}
	return true;
}

function openPictureWindow_Fever(imageName,imageWidth,imageHeight,alt,posLeft,posTop) {
	newWindow = window.open("","newWindow","width="+imageWidth+",height="+imageHeight+",left="+posLeft+",top="+posTop);
	newWindow.document.open();
	newWindow.document.write('<html><title>'+alt+'</title><body bgcolor="#FFFFFF" leftmargin="0" topmargin="0" marginheight="0" marginwidth="0" onBlur="self.close()">');
	newWindow.document.write('<img src='+imageName+' width='+imageWidth+' height='+imageHeight+' alt='+alt+'>');
	newWindow.document.write('</body></html>');
	newWindow.document.close();
	newWindow.focus();
}

function openFlashWindow_Fever(imageName,imageWidth,imageHeight,alt,posLeft,posTop) {
	newWindow = window.open("","newWindow","width="+imageWidth+",height="+imageHeight+",left="+posLeft+",top="+posTop);
	newWindow.document.open();
	newWindow.document.write('<html><title>'+alt+'</title><body bgcolor="#FFFFFF" leftmargin="0" topmargin="0" marginheight="0" marginwidth="0" onBlur="self.close()">');
	newWindow.document.write('<OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" WIDTH='+imageWidth+' HEIGHT='+imageHeight+'>');
	newWindow.document.write('  <PARAM NAME=movie VALUE='+imageName+'>');
	newWindow.document.write('  <PARAM NAME=quality VALUE=high>');
//	newWindow.document.write('  <PARAM NAME=wmode VALUE=transparent>');
	newWindow.document.write('  <PARAM NAME=bgcolor VALUE=#FFFFFF>');
	newWindow.document.write('  <EMBED src='+imageName+' quality=high wmode=transparent bgcolor=#FFFFFF  WIDTH='+imageWidth+' HEIGHT='+imageHeight+' TYPE="application/x-shockwave-flash" PLUGINSPAGE="http://www.macromedia.com/go/getflashplayer"></EMBED>');
	newWindow.document.write('</OBJECT>');
	newWindow.document.write('</body></html>');
	newWindow.document.close();
	newWindow.focus();
}

function resizeWin(newLoc, newWidth, newHeight) {
	return newWin = open("",newLoc,"scrollbars=yes,resizable=no,status=no,left=100,top=100,height=" + newHeight + ",width=" + newWidth);
}

function MM_openBrWindow(theURL,winName,features) {
	window.open(theURL,winName,features);
}

//////////////
// showhide.js

function ShowHideDiv(div_id, span) {
  var _style=(span===true) ? 'inline' : 'block';
  var obj=document.getElementById(div_id);
  obj.style.display=(obj.style.display=='none') ? _style : 'none';
  return ((obj.style.display=='none') ? false : true);
}

function ShowDiv(div_id, span) {
  var _style=(span===true) ? 'inline' : 'block';
  document.getElementById(div_id).style.display=_style;
}

function HideDiv(div_id) {
  document.getElementById(div_id).style.display='none';
}

///////////////
// event.js

function attachEventListener(target, eventType, functionRef, capture) {
	if (typeof target.addEventListener != 'undefined') {
	   target.addEventListener(eventType, functionRef, capture);
	} else
	if (typeof target.attachEvent != 'undefined') {
	   target.attachEvent('on' + eventType, functionRef);
	} else {
	   return false;
	}
	return true;
}

function removeEventListener(target, eventType, functionRef, capture){
	if (target.removeEventListener){
	   target.removeEventListener(eventType, functionRef, capture);
	   return true;
	} else if (target.detachEvent){
	   var r = target.detachEvent("on"+eventType, functionRef);
	   return r;
	} else {
	   return false;
	}
}

///////////////////
// externallinks.js

function ExternalLinks() {
  if (!document.getElementsByTagName) return;
  var anchors = document.getElementsByTagName("a");
  for (var i=0;i<anchors.length;i++) {
    var anchor = anchors[i];
    if (anchor.getAttribute("href")&&anchor.getAttribute("rel")) {
       if (anchor.getAttribute("rel").match(/(external([a-zA-Z0-9_-]+))/i)) {
          var _target=anchor.getAttribute("rel").match(/(external([a-zA-Z0-9_-]+))/i);
          anchor.target = _target[2];
       }
    }
  }
}


/////////////
// cookie.js

function SetCookie(name,value,minutes) {
  if (minutes) {
    var date = new Date();
    date.setTime(date.getTime()+(minutes*60*1000));
    var expires = "; expires="+date.toGMTString();
  } else expires = "";
  document.cookie = name+"="+value+expires+"; path=/";
}

function DeleteAllCookies() {
  var cookies = document.cookie.split(";");
  for (var i = 0; i < cookies.length; i++) {
      var cookie = cookies[i];
      var eqPos = cookie.indexOf("=");
      var name = eqPos > -1 ? cookie.substr(0, eqPos) : cookie;
      document.cookie = name + "=;expires=Thu, 01 Jan 1970 00:00:00 GMT";
  }
}

//////////////
// bookmark.js

function SetBookmark(title,url) {
  // firefox
  if (window.sidebar) window.sidebar.addPanel(title, url, ""); else
  // opera
  if (window.opera && window.print) {
     var elem = document.createElement('a');
     elem.setAttribute('href',url);
     elem.setAttribute('title',title);
     elem.setAttribute('rel','sidebar');
     elem.click();
  } else
  // msie, wie
  if (document.all) window.external.AddFavorite(url, title);
}


///////////////
// inne funkcje

function CorrectHexColor(objValue) {
	return (objValue.replace(/[# ]+/g, ''));
}

function IsHexColor(objValue) {
	return (objValue.match(/^([0-9a-f]{3}|[0-9a-f]{6})$/i));
}

////////////////
// attach events

attachEventListener(window, "load", ExternalLinks, false);
